@mastra/server 1.82.0-alpha.3 → 1.83.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/@internal_core@0.1.4/dist/storage/index.d.ts +24 -2
- package/dist/_types/@mastra_schema-compat@1.3.17/dist/_types/{@internal_ai-v6@0.0.94 → @internal_ai-v6@0.0.95}/dist/index.d.ts +96 -15
- package/dist/_types/@mastra_schema-compat@1.3.17/dist/provider-compats/anthropic.d.ts +1 -1
- package/dist/_types/@mastra_schema-compat@1.3.17/dist/provider-compats/deepseek.d.ts +1 -1
- package/dist/_types/@mastra_schema-compat@1.3.17/dist/provider-compats/meta.d.ts +1 -1
- package/dist/_types/@mastra_schema-compat@1.3.17/dist/schema.types.d.ts +3 -3
- package/dist/{a2a-CoiG3TAj.js → a2a-DCpd3CTv.js} +4 -4
- package/dist/{a2a-CoiG3TAj.js.map → a2a-DCpd3CTv.js.map} +1 -1
- package/dist/{a2a-DvqRdny6.cjs → a2a-kz7NjjCg.cjs} +4 -4
- package/dist/{a2a-DvqRdny6.cjs.map → a2a-kz7NjjCg.cjs.map} +1 -1
- package/dist/{agent-builder-C_L1i2eE.js → agent-builder-CocfOSi8.js} +7 -7
- package/dist/{agent-builder-C_L1i2eE.js.map → agent-builder-CocfOSi8.js.map} +1 -1
- package/dist/{agent-builder-D0Up9Fw1.cjs → agent-builder-uDstZROq.cjs} +7 -7
- package/dist/{agent-builder-D0Up9Fw1.cjs.map → agent-builder-uDstZROq.cjs.map} +1 -1
- package/dist/{agents-CgcW6lHt.js → agents-BI8ez-FT.js} +7 -7
- package/dist/{agents-CgcW6lHt.js.map → agents-BI8ez-FT.js.map} +1 -1
- package/dist/{agents-DOHGWXDa.cjs → agents-DsfsDhIT.cjs} +7 -7
- package/dist/{agents-DOHGWXDa.cjs.map → agents-DsfsDhIT.cjs.map} +1 -1
- package/dist/{api-schema-manifest-Ci2qUYHc.js → api-schema-manifest-ChxbN16M.js} +3 -3
- package/dist/{api-schema-manifest-Ci2qUYHc.js.map → api-schema-manifest-ChxbN16M.js.map} +1 -1
- package/dist/{api-schema-manifest-DCHOlOuJ.cjs → api-schema-manifest-DtYTPvh9.cjs} +3 -3
- package/dist/{api-schema-manifest-DCHOlOuJ.cjs.map → api-schema-manifest-DtYTPvh9.cjs.map} +1 -1
- package/dist/{background-tasks-BHhn4YZA.js → background-tasks-BIuEr2of.js} +3 -3
- package/dist/{background-tasks-BHhn4YZA.js.map → background-tasks-BIuEr2of.js.map} +1 -1
- package/dist/{background-tasks-Ci2tlxJC.cjs → background-tasks-BXTIp0QV.cjs} +3 -3
- package/dist/{background-tasks-Ci2tlxJC.cjs.map → background-tasks-BXTIp0QV.cjs.map} +1 -1
- package/dist/{builder-registry-m_gHCe12.js → builder-registry-Dd7pbJ5A.js} +4 -4
- package/dist/{builder-registry-m_gHCe12.js.map → builder-registry-Dd7pbJ5A.js.map} +1 -1
- package/dist/{builder-registry-D1_hGKCJ.cjs → builder-registry-DrBUA6EZ.cjs} +4 -4
- package/dist/{builder-registry-D1_hGKCJ.cjs.map → builder-registry-DrBUA6EZ.cjs.map} +1 -1
- package/dist/{channels-hhQ3vD30.js → channels-B6hwVMbV.js} +4 -4
- package/dist/{channels-hhQ3vD30.js.map → channels-B6hwVMbV.js.map} +1 -1
- package/dist/{channels-Bfkp5vYI.cjs → channels-DbfSH5O2.cjs} +4 -4
- package/dist/{channels-Bfkp5vYI.cjs.map → channels-DbfSH5O2.cjs.map} +1 -1
- package/dist/{conversations-xS7yHuG1.js → conversations-BbZYXKIa.js} +5 -5
- package/dist/{conversations-xS7yHuG1.js.map → conversations-BbZYXKIa.js.map} +1 -1
- package/dist/{conversations-Ch_VuVwY.cjs → conversations-QuKJVEFe.cjs} +5 -5
- package/dist/{conversations-Ch_VuVwY.cjs.map → conversations-QuKJVEFe.cjs.map} +1 -1
- package/dist/{dist-BKNKucT9.cjs → dist-Ctfk9X6u.cjs} +208 -247
- package/dist/dist-Ctfk9X6u.cjs.map +1 -0
- package/dist/dist-DJjVMQiv.js +1 -0
- package/dist/{dist-CIYZuix4.js → dist-OKFDPspq.js} +208 -247
- package/dist/dist-OKFDPspq.js.map +1 -0
- package/dist/{dist-DgKeISkr.cjs → dist-ZYvqJK9p.cjs} +1 -1
- package/dist/docs/SKILL.md +3 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-knowledge-overview.md +106 -0
- package/dist/docs/references/docs-server-custom-adapters.md +4 -0
- package/dist/docs/references/docs-studio-knowledge.md +45 -24
- package/dist/docs/references/reference-server-invoke-route.md +86 -0
- package/dist/docs/references/reference-server-routes.md +63 -0
- package/dist/{dynamic-workflows-DDauBnDt.js → dynamic-workflows-CyaZLmHX.js} +2 -2
- package/dist/{dynamic-workflows-DDauBnDt.js.map → dynamic-workflows-CyaZLmHX.js.map} +1 -1
- package/dist/{dynamic-workflows-CpCkqM1g.cjs → dynamic-workflows-ZmzWJXxG.cjs} +2 -2
- package/dist/{dynamic-workflows-CpCkqM1g.cjs.map → dynamic-workflows-ZmzWJXxG.cjs.map} +1 -1
- package/dist/{editor-builder-Ceen28s8.js → editor-builder-CbfX5bvL.js} +4 -4
- package/dist/{editor-builder-Ceen28s8.js.map → editor-builder-CbfX5bvL.js.map} +1 -1
- package/dist/{editor-builder-CKfy5eZY.cjs → editor-builder-CjJlqR9a.cjs} +4 -4
- package/dist/{editor-builder-CKfy5eZY.cjs.map → editor-builder-CjJlqR9a.cjs.map} +1 -1
- package/dist/{helpers-DNq3LtLq.js → helpers-B29a1nM3.js} +51 -48
- package/dist/helpers-B29a1nM3.js.map +1 -0
- package/dist/{helpers-BKtUXhz2.cjs → helpers-CylvUIZm.cjs} +56 -47
- package/dist/helpers-CylvUIZm.cjs.map +1 -0
- package/dist/{knowledge-Ba74qr0v.js → knowledge-Cd2cCq-Y.js} +4 -4
- package/dist/{knowledge-Ba74qr0v.js.map → knowledge-Cd2cCq-Y.js.map} +1 -1
- package/dist/{knowledge-urR7FFG8.cjs → knowledge-Q_SCnD9m.cjs} +4 -4
- package/dist/{knowledge-urR7FFG8.cjs.map → knowledge-Q_SCnD9m.cjs.map} +1 -1
- package/dist/{logs-B57_NKDn.js → logs-C5L6gRGr.js} +4 -4
- package/dist/{logs-B57_NKDn.js.map → logs-C5L6gRGr.js.map} +1 -1
- package/dist/{logs-BJN3M88A.cjs → logs-DWIbFIw6.cjs} +4 -4
- package/dist/{logs-BJN3M88A.cjs.map → logs-DWIbFIw6.cjs.map} +1 -1
- package/dist/{mcp-B9BILfJP.cjs → mcp-CKvOVfHn.cjs} +3 -3
- package/dist/{mcp-B9BILfJP.cjs.map → mcp-CKvOVfHn.cjs.map} +1 -1
- package/dist/{mcp-BkmWZD6M.js → mcp-CntC59iU.js} +3 -3
- package/dist/{mcp-BkmWZD6M.js.map → mcp-CntC59iU.js.map} +1 -1
- package/dist/{memory-Dqod_AK9.cjs → memory-DIos0BE-.cjs} +57 -15
- package/dist/{memory-Dqod_AK9.cjs.map → memory-DIos0BE-.cjs.map} +1 -1
- package/dist/{memory-ipOCmg0C.js → memory-JzgWJevA.js} +57 -15
- package/dist/{memory-ipOCmg0C.js.map → memory-JzgWJevA.js.map} +1 -1
- package/dist/{observability-DBtyAJnb.js → observability-BCTkIhJT.js} +3 -3
- package/dist/{observability-DBtyAJnb.js.map → observability-BCTkIhJT.js.map} +1 -1
- package/dist/{observability-BtdW6mjq.cjs → observability-mnHHbnoc.cjs} +3 -3
- package/dist/{observability-BtdW6mjq.cjs.map → observability-mnHHbnoc.cjs.map} +1 -1
- package/dist/{observability-new-endpoints-jjCgXuTF.cjs → observability-new-endpoints-B6fo20v5.cjs} +129 -955
- package/dist/observability-new-endpoints-B6fo20v5.cjs.map +1 -0
- package/dist/{observability-new-endpoints-Di7m_-xc.js → observability-new-endpoints-DHn8uKyr.js} +51 -877
- package/dist/observability-new-endpoints-DHn8uKyr.js.map +1 -0
- package/dist/observability-signal-context-BYOFtbM_.cjs +1317 -0
- package/dist/observability-signal-context-BYOFtbM_.cjs.map +1 -0
- package/dist/observability-signal-context-CL5-rCWM.js +952 -0
- package/dist/observability-signal-context-CL5-rCWM.js.map +1 -0
- package/dist/{plans-nHOnlGzr.js → plans-9hdkc-t8.js} +4 -4
- package/dist/{plans-nHOnlGzr.js.map → plans-9hdkc-t8.js.map} +1 -1
- package/dist/{plans-Djcp3C0d.cjs → plans-DMs8SVBG.cjs} +4 -4
- package/dist/{plans-Djcp3C0d.cjs.map → plans-DMs8SVBG.cjs.map} +1 -1
- package/dist/{probe-image-size-DGTRKrgq.js → probe-image-size-Cxm5QtwO.js} +2 -2
- package/dist/{probe-image-size-DGTRKrgq.js.map → probe-image-size-Cxm5QtwO.js.map} +1 -1
- package/dist/{probe-image-size-BAwk1h6w.cjs → probe-image-size-bDuzMW0E.cjs} +2 -2
- package/dist/{probe-image-size-BAwk1h6w.cjs.map → probe-image-size-bDuzMW0E.cjs.map} +1 -1
- package/dist/{responses-CEet9y8G.js → responses-B5_syoSo.js} +5 -5
- package/dist/{responses-CEet9y8G.js.map → responses-B5_syoSo.js.map} +1 -1
- package/dist/{responses-BdOStKtX.cjs → responses-CNKJoC5a.cjs} +5 -5
- package/dist/{responses-BdOStKtX.cjs.map → responses-CNKJoC5a.cjs.map} +1 -1
- package/dist/{route-builder-BxPrwNog.js → route-builder-BKEzjw_M.js} +2 -2
- package/dist/{route-builder-BxPrwNog.js.map → route-builder-BKEzjw_M.js.map} +1 -1
- package/dist/{route-builder-CvARmqnA.cjs → route-builder-DHqDrSSy.cjs} +2 -2
- package/dist/{route-builder-CvARmqnA.cjs.map → route-builder-DHqDrSSy.cjs.map} +1 -1
- package/dist/{routes-DU_FlwJP.cjs → routes-BYQ38dFx.cjs} +32 -32
- package/dist/{routes-DU_FlwJP.cjs.map → routes-BYQ38dFx.cjs.map} +1 -1
- package/dist/{routes-5FpkkzND.js → routes-C0pgNcG-.js} +32 -32
- package/dist/{routes-5FpkkzND.js.map → routes-C0pgNcG-.js.map} +1 -1
- package/dist/{schedules-D8ShgpY3.cjs → schedules-CvWX2yKR.cjs} +3 -3
- package/dist/{schedules-D8ShgpY3.cjs.map → schedules-CvWX2yKR.cjs.map} +1 -1
- package/dist/{schedules-CGViSLZC.js → schedules-D9CKB18-.js} +3 -3
- package/dist/{schedules-CGViSLZC.js.map → schedules-D9CKB18-.js.map} +1 -1
- package/dist/{schema-Bf12g7KC-DBc4NSds.js → schema-Bf12g7KC-5EUrrnSf.js} +96 -96
- package/dist/{schema-Bf12g7KC-DBc4NSds.js.map → schema-Bf12g7KC-5EUrrnSf.js.map} +1 -1
- package/dist/{schema-Bf12g7KC-plP4Ir6h.cjs → schema-Bf12g7KC-C5XzpQxe.cjs} +96 -96
- package/dist/{schema-Bf12g7KC-plP4Ir6h.cjs.map → schema-Bf12g7KC-C5XzpQxe.cjs.map} +1 -1
- package/dist/{scores-BaDFGpmr.js → scores-B3mS6vqB.js} +4 -4
- package/dist/{scores-BaDFGpmr.js.map → scores-B3mS6vqB.js.map} +1 -1
- package/dist/{scores-Bw6Tuga5.cjs → scores-Dxa8dDfV.cjs} +4 -4
- package/dist/{scores-Bw6Tuga5.cjs.map → scores-Dxa8dDfV.cjs.map} +1 -1
- package/dist/server/auth/helpers.d.ts +20 -0
- package/dist/server/auth/helpers.d.ts.map +1 -1
- package/dist/server/auth/index.cjs +2 -1
- package/dist/server/auth/index.js +2 -2
- package/dist/server/handlers/a2a.cjs +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agent-controller.cjs +4 -4
- package/dist/server/handlers/agent-controller.js +4 -4
- package/dist/server/handlers/agent-versions.cjs +4 -4
- package/dist/server/handlers/agent-versions.js +4 -4
- package/dist/server/handlers/agents.cjs +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/auth.cjs +4 -4
- package/dist/server/handlers/auth.js +4 -4
- package/dist/server/handlers/authorship.cjs +1 -1
- package/dist/server/handlers/authorship.js +1 -1
- package/dist/server/handlers/background-tasks.cjs +1 -1
- package/dist/server/handlers/background-tasks.js +1 -1
- package/dist/server/handlers/builder-registry.cjs +1 -1
- package/dist/server/handlers/builder-registry.js +1 -1
- package/dist/server/handlers/channels.cjs +1 -1
- package/dist/server/handlers/channels.js +1 -1
- package/dist/server/handlers/conversations.cjs +1 -1
- package/dist/server/handlers/conversations.js +1 -1
- package/dist/server/handlers/datasets.cjs +3 -3
- package/dist/server/handlers/datasets.js +3 -3
- package/dist/server/handlers/dynamic-workflows.cjs +1 -1
- package/dist/server/handlers/dynamic-workflows.js +1 -1
- package/dist/server/handlers/editor-builder.cjs +1 -1
- package/dist/server/handlers/editor-builder.js +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +1 -1
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/gateway-memory-client.cjs +4 -1
- package/dist/server/handlers/gateway-memory-client.cjs.map +1 -1
- package/dist/server/handlers/gateway-memory-client.d.ts.map +1 -1
- package/dist/server/handlers/gateway-memory-client.js +4 -1
- package/dist/server/handlers/gateway-memory-client.js.map +1 -1
- package/dist/server/handlers/knowledge.cjs +1 -1
- package/dist/server/handlers/knowledge.js +1 -1
- package/dist/server/handlers/logs.cjs +1 -1
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/mcp-client-versions.cjs +3 -3
- package/dist/server/handlers/mcp-client-versions.js +3 -3
- package/dist/server/handlers/mcp.cjs +1 -1
- package/dist/server/handlers/mcp.js +1 -1
- package/dist/server/handlers/memory.cjs +1 -1
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
- package/dist/server/handlers/observability-new-endpoints.d.ts +84 -8
- package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
- package/dist/server/handlers/observability-new-endpoints.js +1 -1
- package/dist/server/handlers/observability-shared.cjs +1 -1
- package/dist/server/handlers/observability-shared.js +1 -1
- package/dist/server/handlers/observability-signal-context.cjs +4 -0
- package/dist/server/handlers/observability-signal-context.d.ts +42 -0
- package/dist/server/handlers/observability-signal-context.d.ts.map +1 -0
- package/dist/server/handlers/observability-signal-context.js +1 -0
- package/dist/server/handlers/observability.cjs +2 -2
- package/dist/server/handlers/observability.js +2 -2
- package/dist/server/handlers/plans.cjs +1 -1
- package/dist/server/handlers/plans.js +1 -1
- package/dist/server/handlers/processor-providers.cjs +2 -2
- package/dist/server/handlers/processor-providers.js +2 -2
- package/dist/server/handlers/processors.cjs +2 -2
- package/dist/server/handlers/processors.js +2 -2
- package/dist/server/handlers/prompt-block-versions.cjs +3 -3
- package/dist/server/handlers/prompt-block-versions.js +3 -3
- package/dist/server/handlers/responses.cjs +1 -1
- package/dist/server/handlers/responses.js +1 -1
- package/dist/server/handlers/responses.storage.cjs +1 -1
- package/dist/server/handlers/responses.storage.js +1 -1
- package/dist/server/handlers/schedules.cjs +1 -1
- package/dist/server/handlers/schedules.js +1 -1
- package/dist/server/handlers/scorer-versions.cjs +3 -3
- package/dist/server/handlers/scorer-versions.js +3 -3
- package/dist/server/handlers/scores.cjs +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +5 -5
- package/dist/server/handlers/stored-agent-favorites.js +5 -5
- package/dist/server/handlers/stored-agents.cjs +7 -7
- package/dist/server/handlers/stored-agents.js +7 -7
- package/dist/server/handlers/stored-mcp-clients.cjs +3 -3
- package/dist/server/handlers/stored-mcp-clients.js +3 -3
- package/dist/server/handlers/stored-prompt-blocks.cjs +3 -3
- package/dist/server/handlers/stored-prompt-blocks.js +3 -3
- package/dist/server/handlers/stored-scorers.cjs +3 -3
- package/dist/server/handlers/stored-scorers.js +3 -3
- package/dist/server/handlers/stored-skill-favorites.cjs +5 -5
- package/dist/server/handlers/stored-skill-favorites.js +5 -5
- package/dist/server/handlers/stored-skills.cjs +5 -5
- package/dist/server/handlers/stored-skills.js +5 -5
- package/dist/server/handlers/stored-workspaces.cjs +3 -3
- package/dist/server/handlers/stored-workspaces.js +3 -3
- package/dist/server/handlers/system.cjs +3 -3
- package/dist/server/handlers/system.js +3 -3
- package/dist/server/handlers/tool-providers.cjs +3 -3
- package/dist/server/handlers/tool-providers.js +3 -3
- package/dist/server/handlers/tools.cjs +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/validate-agent-instructions.cjs +1 -1
- package/dist/server/handlers/validate-agent-instructions.js +1 -1
- package/dist/server/handlers/vector.cjs +1 -1
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/workflow-builder.cjs +1 -1
- package/dist/server/handlers/workflow-builder.js +1 -1
- package/dist/server/handlers/workflows.cjs +1 -1
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers/workspace.cjs +1 -1
- package/dist/server/handlers/workspace.d.ts +23 -23
- package/dist/server/handlers/workspace.js +1 -1
- package/dist/server/handlers.cjs +16 -16
- package/dist/server/handlers.js +16 -16
- package/dist/server/schemas/agents.d.ts +1 -1
- package/dist/server/schemas/index.cjs +20 -20
- package/dist/server/schemas/index.js +20 -20
- package/dist/server/server-adapter/index.cjs +231 -61
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.d.ts +67 -1
- package/dist/server/server-adapter/index.d.ts.map +1 -1
- package/dist/server/server-adapter/index.js +226 -63
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/mcp-auth.d.ts +16 -1
- package/dist/server/server-adapter/mcp-auth.d.ts.map +1 -1
- package/dist/server/server-adapter/routes/observability.d.ts +42 -4
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
- package/dist/{tools-CI5oeJWT.cjs → tools-C9W7WvyI.cjs} +7 -7
- package/dist/{tools-CI5oeJWT.cjs.map → tools-C9W7WvyI.cjs.map} +1 -1
- package/dist/{tools-BAmCNGM5.js → tools-Ce7SFoT1.js} +7 -7
- package/dist/{tools-BAmCNGM5.js.map → tools-Ce7SFoT1.js.map} +1 -1
- package/dist/{utils-9PRHHTGC.cjs → utils-BXEJ6FZC.cjs} +2 -2
- package/dist/{utils-9PRHHTGC.cjs.map → utils-BXEJ6FZC.cjs.map} +1 -1
- package/dist/{utils-BhBJHsqX.cjs → utils-CL-m2SWZ.cjs} +3 -3
- package/dist/{utils-BhBJHsqX.cjs.map → utils-CL-m2SWZ.cjs.map} +1 -1
- package/dist/{utils-B15w-1hm.js → utils-CTYtskHa.js} +2 -2
- package/dist/{utils-B15w-1hm.js.map → utils-CTYtskHa.js.map} +1 -1
- package/dist/{utils-Dy_dQTlK.js → utils-y-cW3mQU.js} +3 -3
- package/dist/{utils-Dy_dQTlK.js.map → utils-y-cW3mQU.js.map} +1 -1
- package/dist/{vector-BZ1bKtwM.cjs → vector-6k7Ft7EX.cjs} +3 -3
- package/dist/{vector-BZ1bKtwM.cjs.map → vector-6k7Ft7EX.cjs.map} +1 -1
- package/dist/{vector-BAs5o6mH.js → vector-BWFSDXvg.js} +3 -3
- package/dist/{vector-BAs5o6mH.js.map → vector-BWFSDXvg.js.map} +1 -1
- package/dist/{workflow-builder-CaSfD6oL.js → workflow-builder-BNk301jl.js} +4 -4
- package/dist/{workflow-builder-CaSfD6oL.js.map → workflow-builder-BNk301jl.js.map} +1 -1
- package/dist/{workflow-builder-tr_D_ZDN.cjs → workflow-builder-CsOEskDo.cjs} +4 -4
- package/dist/{workflow-builder-tr_D_ZDN.cjs.map → workflow-builder-CsOEskDo.cjs.map} +1 -1
- package/dist/{workflows-BxXS5AfE.js → workflows-BAFGmHCW.js} +24 -13
- package/dist/workflows-BAFGmHCW.js.map +1 -0
- package/dist/{workflows-Cdi6w8JW.cjs → workflows-CJz5Eh0B.cjs} +76 -65
- package/dist/workflows-CJz5Eh0B.cjs.map +1 -0
- package/dist/{workspace-BU6sQpbV.cjs → workspace-C7PytFzz.cjs} +3 -3
- package/dist/{workspace-BU6sQpbV.cjs.map → workspace-C7PytFzz.cjs.map} +1 -1
- package/dist/{workspace-CS-GYTve.js → workspace-CYwDvH0G.js} +3 -3
- package/dist/{workspace-CS-GYTve.js.map → workspace-CYwDvH0G.js.map} +1 -1
- package/package.json +9 -9
- package/dist/dist-BKNKucT9.cjs.map +0 -1
- package/dist/dist-CIYZuix4.js.map +0 -1
- package/dist/dist-mNQb9_wX.js +0 -1
- package/dist/helpers-BKtUXhz2.cjs.map +0 -1
- package/dist/helpers-DNq3LtLq.js.map +0 -1
- package/dist/observability-new-endpoints-Di7m_-xc.js.map +0 -1
- package/dist/observability-new-endpoints-jjCgXuTF.cjs.map +0 -1
- package/dist/workflows-BxXS5AfE.js.map +0 -1
- package/dist/workflows-Cdi6w8JW.cjs.map +0 -1
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/@internal_core@0.1.4/dist/request-context/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/@internal_core@0.1.4/dist/routes/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/@internal_core@0.1.4/dist/types/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/checks.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/coerce.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/compat.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/deep-partial.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/errors.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/external.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/from-json-schema.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/in-out.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/iso.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/parse.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/classic/schemas.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/api.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/checks.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/compile.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/core.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/doc.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/errors.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/json-schema-generator.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/json-schema-processors.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/json-schema.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/memoizer.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/parse.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/regexes.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/registries.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/schemas.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/standard-schema.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/to-json-schema.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/util.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/core/versions.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/index.d.cts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ar.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/az.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/be.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/bg.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/bn.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ca.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ckb.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/cs.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/da.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/de.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/el.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/en.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/eo.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/es.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/fa.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/fi.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/fr-CA.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/fr.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/gu.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/he.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/hi.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/hr.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/hu.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/hy.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/id.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/is.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/it.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ja.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ka.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/kh.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/km.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/kn.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ko.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/lt.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/mk.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ms.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ne.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/nl.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/nn.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/no.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ota.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/pl.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ps.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/pt-BR.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/pt.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ro.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ru.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/sk.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/sl.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/sv.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ta.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/tg.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/th.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/tk.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/tr.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ua.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/uk.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/ur.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/uz.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/vi.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/yo.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/zh-CN.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/_types/zod@4.6.7/v4/locales/zh-TW.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/dist/routes/index.d.ts +0 -0
- /package/dist/_types/{@internal_voice@0.0.43 → @internal_voice@0.0.44}/package.json +0 -0
- /package/dist/_types/@mastra_schema-compat@1.3.17/dist/_types/{@internal_ai-sdk-v4@0.0.94 → @internal_ai-sdk-v4@0.0.95}/dist/index.d.ts +0 -0
- /package/dist/_types/@mastra_schema-compat@1.3.17/dist/_types/{@internal_ai-sdk-v5@0.0.94 → @internal_ai-sdk-v5@0.0.95}/dist/index.d.ts +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
/**
|
|
4
|
+
* Key under which `applyMcpRequestAuth` attaches the trusted request context to
|
|
5
|
+
* `req.auth`. `@mastra/mcp` reads the same registered symbol and copies the
|
|
6
|
+
* values into the request context its tools receive. A symbol cannot come out
|
|
7
|
+
* of a token or JSON payload, so only server code can supply it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MCP_TRUSTED_REQUEST_CONTEXT: unique symbol;
|
|
3
10
|
/**
|
|
4
11
|
* Shape the MCP SDK expects on `req.auth`.
|
|
5
12
|
*/
|
|
@@ -16,6 +23,11 @@ export interface McpAuthInfo {
|
|
|
16
23
|
* request context, which carries whatever server auth or your own middleware
|
|
17
24
|
* resolved for this request. Setting `req.auth` is the caller's job; leaving it
|
|
18
25
|
* unset is an explicit opt-out of the default bridge.
|
|
26
|
+
*
|
|
27
|
+
* The hook only owns `authInfo`. Whenever `req.auth` ends up set, the reserved
|
|
28
|
+
* request context values (user, permissions, roles, resource, organization)
|
|
29
|
+
* are still attached to it, so tools' `requestContext` reflects Mastra server
|
|
30
|
+
* auth even if the hook's `authInfo` names a different principal.
|
|
19
31
|
*/
|
|
20
32
|
export type SetMcpRequestAuth = (req: IncomingMessage, requestContext: RequestContext) => void | Promise<void>;
|
|
21
33
|
/**
|
|
@@ -30,10 +42,13 @@ export declare function buildMcpAuthInfoFromRequestContext(requestContext: Reque
|
|
|
30
42
|
* transport.
|
|
31
43
|
*
|
|
32
44
|
* Resolution order:
|
|
33
|
-
* 1. An already-set `req.auth`
|
|
45
|
+
* 1. An already-set `req.auth` keeps its identity.
|
|
34
46
|
* 2. A configured `setRequestAuth` hook runs and fully owns the result.
|
|
35
47
|
* 3. Otherwise the principal resolved by Mastra server auth is bridged from the
|
|
36
48
|
* request context using the default mapping.
|
|
49
|
+
*
|
|
50
|
+
* Whichever way `req.auth` is set, the trusted request context is attached to
|
|
51
|
+
* it so MCP tools see the same principal as Mastra routes.
|
|
37
52
|
*/
|
|
38
53
|
export declare function applyMcpRequestAuth({ req, requestContext, setRequestAuth, }: {
|
|
39
54
|
req: IncomingMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-auth.d.ts","sourceRoot":"","sources":["../../../src/server/server-adapter/mcp-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED
|
|
1
|
+
{"version":3,"file":"mcp-auth.d.ts","sourceRoot":"","sources":["../../../src/server/server-adapter/mcp-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,eAAiD,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAgB/G;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,cAAc,EAAE,cAAc,GAAG,WAAW,GAAG,SAAS,CAgB1G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,GAAG,EACH,cAAc,EACd,cAAc,GACf,EAAE;IACD,GAAG,EAAE,eAAe,CAAC;IACrB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhB"}
|
|
@@ -1817,6 +1817,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1817
1817
|
streamFormat?: 'sse' | 'stream';
|
|
1818
1818
|
sseFlushOnConnect?: boolean;
|
|
1819
1819
|
handler(params: {
|
|
1820
|
+
contextMode?: "provided" | "resolve" | undefined;
|
|
1820
1821
|
score: {
|
|
1821
1822
|
entityType?: import("../../../_types/@internal_core@0.1.4/dist/storage/index.js").EntityType | null | undefined;
|
|
1822
1823
|
entityId?: string | null | undefined;
|
|
@@ -1844,7 +1845,6 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1844
1845
|
executionSource?: string | null | undefined;
|
|
1845
1846
|
tags?: string[] | null | undefined;
|
|
1846
1847
|
scoreId?: string | null | undefined;
|
|
1847
|
-
traceId?: string | null | undefined;
|
|
1848
1848
|
spanId?: string | null | undefined;
|
|
1849
1849
|
scorerId: string;
|
|
1850
1850
|
scorerName?: string | null | undefined;
|
|
@@ -1855,9 +1855,17 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1855
1855
|
reason?: string | null | undefined;
|
|
1856
1856
|
scoreTraceId?: string | null | undefined;
|
|
1857
1857
|
metadata?: Record<string, unknown> | null | undefined;
|
|
1858
|
+
timestamp?: string | undefined;
|
|
1859
|
+
traceId: string;
|
|
1858
1860
|
};
|
|
1859
1861
|
} & import(".").ServerContext): Promise<{
|
|
1860
1862
|
success: boolean;
|
|
1863
|
+
data?: {
|
|
1864
|
+
scoreId: string;
|
|
1865
|
+
traceId: string;
|
|
1866
|
+
spanId: string | null;
|
|
1867
|
+
timestamp: string;
|
|
1868
|
+
} | undefined;
|
|
1861
1869
|
}>;
|
|
1862
1870
|
pathParamSchema?: import("zod").ZodSchema;
|
|
1863
1871
|
queryParamSchema?: import("zod").ZodSchema;
|
|
@@ -1870,6 +1878,10 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1870
1878
|
fga?: import("@mastra/core/auth").FGARouteConfig;
|
|
1871
1879
|
onValidationError?: import("@mastra/core/server").ValidationErrorHook;
|
|
1872
1880
|
readonly __schemas?: import(".").RouteSchemas<undefined, undefined, import("zod").ZodObject<{
|
|
1881
|
+
contextMode: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
1882
|
+
provided: "provided";
|
|
1883
|
+
resolve: "resolve";
|
|
1884
|
+
}>>;
|
|
1873
1885
|
score: import("zod").ZodObject<{
|
|
1874
1886
|
entityType: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodEnum<typeof import("../../../_types/@internal_core@0.1.4/dist/storage/index.js").EntityType>>>;
|
|
1875
1887
|
entityId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
@@ -1897,7 +1909,6 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1897
1909
|
executionSource: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1898
1910
|
tags: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodArray<import("zod").ZodString>>>;
|
|
1899
1911
|
scoreId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1900
|
-
traceId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1901
1912
|
spanId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1902
1913
|
scorerId: import("zod").ZodString;
|
|
1903
1914
|
scorerName: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
@@ -1908,9 +1919,17 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
1908
1919
|
reason: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1909
1920
|
scoreTraceId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
1910
1921
|
metadata: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>;
|
|
1922
|
+
timestamp: import("zod").ZodOptional<import("zod").ZodISODateTime>;
|
|
1923
|
+
traceId: import("zod").ZodString;
|
|
1911
1924
|
}, import("zod/v4/core").$strip>;
|
|
1912
1925
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
1913
1926
|
success: import("zod").ZodBoolean;
|
|
1927
|
+
data: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
1928
|
+
scoreId: import("zod").ZodString;
|
|
1929
|
+
traceId: import("zod").ZodString;
|
|
1930
|
+
spanId: import("zod").ZodNullable<import("zod").ZodString>;
|
|
1931
|
+
timestamp: import("zod").ZodISODateTime;
|
|
1932
|
+
}, import("zod/v4/core").$strip>>;
|
|
1914
1933
|
}, import("zod/v4/core").$strip>> | undefined;
|
|
1915
1934
|
} & {
|
|
1916
1935
|
readonly _mastraSchemaRoute: true;
|
|
@@ -2694,6 +2713,7 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2694
2713
|
streamFormat?: 'sse' | 'stream';
|
|
2695
2714
|
sseFlushOnConnect?: boolean;
|
|
2696
2715
|
handler(params: {
|
|
2716
|
+
contextMode?: "provided" | "resolve" | undefined;
|
|
2697
2717
|
feedback: {
|
|
2698
2718
|
entityType?: import("../../../_types/@internal_core@0.1.4/dist/storage/index.js").EntityType | null | undefined;
|
|
2699
2719
|
entityId?: string | null | undefined;
|
|
@@ -2721,7 +2741,6 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2721
2741
|
executionSource?: string | null | undefined;
|
|
2722
2742
|
tags?: string[] | null | undefined;
|
|
2723
2743
|
feedbackId?: string | null | undefined;
|
|
2724
|
-
traceId?: string | null | undefined;
|
|
2725
2744
|
spanId?: string | null | undefined;
|
|
2726
2745
|
feedbackSource?: string | null | undefined;
|
|
2727
2746
|
source?: string | null | undefined;
|
|
@@ -2732,9 +2751,17 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2732
2751
|
sourceId?: string | null | undefined;
|
|
2733
2752
|
metadata?: Record<string, unknown> | null | undefined;
|
|
2734
2753
|
reviewStatus?: "needs-review" | "reviewed" | undefined;
|
|
2754
|
+
timestamp?: string | undefined;
|
|
2755
|
+
traceId: string;
|
|
2735
2756
|
};
|
|
2736
2757
|
} & import(".").ServerContext): Promise<{
|
|
2737
2758
|
success: boolean;
|
|
2759
|
+
data?: {
|
|
2760
|
+
feedbackId: string;
|
|
2761
|
+
traceId: string;
|
|
2762
|
+
spanId: string | null;
|
|
2763
|
+
timestamp: string;
|
|
2764
|
+
} | undefined;
|
|
2738
2765
|
}>;
|
|
2739
2766
|
pathParamSchema?: import("zod").ZodSchema;
|
|
2740
2767
|
queryParamSchema?: import("zod").ZodSchema;
|
|
@@ -2747,6 +2774,10 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2747
2774
|
fga?: import("@mastra/core/auth").FGARouteConfig;
|
|
2748
2775
|
onValidationError?: import("@mastra/core/server").ValidationErrorHook;
|
|
2749
2776
|
readonly __schemas?: import(".").RouteSchemas<undefined, undefined, import("zod").ZodObject<{
|
|
2777
|
+
contextMode: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
2778
|
+
provided: "provided";
|
|
2779
|
+
resolve: "resolve";
|
|
2780
|
+
}>>;
|
|
2750
2781
|
feedback: import("zod").ZodObject<{
|
|
2751
2782
|
entityType: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodEnum<typeof import("../../../_types/@internal_core@0.1.4/dist/storage/index.js").EntityType>>>;
|
|
2752
2783
|
entityId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
@@ -2774,7 +2805,6 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2774
2805
|
executionSource: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
2775
2806
|
tags: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodArray<import("zod").ZodString>>>;
|
|
2776
2807
|
feedbackId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
2777
|
-
traceId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
2778
2808
|
spanId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
2779
2809
|
feedbackSource: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
2780
2810
|
source: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
@@ -2788,9 +2818,17 @@ export declare const OBSERVABILITY_ROUTES: readonly [import(".").ServerRoute, Om
|
|
|
2788
2818
|
"needs-review": "needs-review";
|
|
2789
2819
|
reviewed: "reviewed";
|
|
2790
2820
|
}>>;
|
|
2821
|
+
timestamp: import("zod").ZodOptional<import("zod").ZodISODateTime>;
|
|
2822
|
+
traceId: import("zod").ZodString;
|
|
2791
2823
|
}, import("zod/v4/core").$strip>;
|
|
2792
2824
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
2793
2825
|
success: import("zod").ZodBoolean;
|
|
2826
|
+
data: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
2827
|
+
feedbackId: import("zod").ZodString;
|
|
2828
|
+
traceId: import("zod").ZodString;
|
|
2829
|
+
spanId: import("zod").ZodNullable<import("zod").ZodString>;
|
|
2830
|
+
timestamp: import("zod").ZodISODateTime;
|
|
2831
|
+
}, import("zod/v4/core").$strip>>;
|
|
2794
2832
|
}, import("zod/v4/core").$strip>> | undefined;
|
|
2795
2833
|
} & {
|
|
2796
2834
|
readonly _mastraSchemaRoute: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../../../../src/server/server-adapter/routes/observability.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,oBAAoB
|
|
1
|
+
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../../../../src/server/server-adapter/routes/observability.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDvB,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-10nMEhjP.cjs");
|
|
2
|
+
const require_utils = require("./utils-CL-m2SWZ.cjs");
|
|
3
|
+
const require_utils$1 = require("./utils-BXEJ6FZC.cjs");
|
|
2
4
|
const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
3
|
-
const
|
|
5
|
+
const require_schema_Bf12g7KC = require("./schema-Bf12g7KC-C5XzpQxe.cjs");
|
|
4
6
|
const require_agents = require("./agents-DbnPZXIN.cjs");
|
|
5
|
-
const
|
|
6
|
-
const require_route_builder = require("./route-builder-
|
|
7
|
-
const
|
|
7
|
+
const require_common = require("./common-D5XxSuvu.cjs");
|
|
8
|
+
const require_route_builder = require("./route-builder-DHqDrSSy.cjs");
|
|
9
|
+
const require_agents$1 = require("./agents-DsfsDhIT.cjs");
|
|
8
10
|
const require_server_handlers_error = require("./server/handlers/error.cjs");
|
|
9
|
-
const require_utils$1 = require("./utils-9PRHHTGC.cjs");
|
|
10
|
-
const require_agents$1 = require("./agents-DOHGWXDa.cjs");
|
|
11
11
|
const require_server_handlers_tool_schema_overrides = require("./server/handlers/tool-schema-overrides.cjs");
|
|
12
12
|
let _mastra_core_tools = require("@mastra/core/tools");
|
|
13
13
|
// src/server/handlers/tools.ts
|
|
@@ -287,4 +287,4 @@ Object.defineProperty(exports, "tools_exports", {
|
|
|
287
287
|
}
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
-
//# sourceMappingURL=tools-
|
|
290
|
+
//# sourceMappingURL=tools-C9W7WvyI.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-CI5oeJWT.cjs","names":["standardSchemaToJSONSchema","toStandardSchema","stringify","stripInjectedToolOverrideFields","isProviderDefinedTool","createRoute","listToolsResponseSchema","getHandlerFGAProvider","MastraFGAPermissions","handleError","toolIdPathParams","serializedToolSchema","HTTPException","optionalRunIdSchema","executeToolContextBodySchema","executeToolResponseSchema","isVercelTool","agentToolPathParams","getAgentFromSystem","executeToolBodySchema"],"sources":["../src/server/handlers/tools.ts"],"sourcesContent":["import { isVercelTool, isProviderDefinedTool } from '@mastra/core/tools';\nimport { toStandardSchema, standardSchemaToJSONSchema } from '@mastra/schema-compat/schema';\nimport type { PublicSchema } from '@mastra/schema-compat/schema';\nimport { stringify } from 'superjson';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n executeToolContextBodySchema,\n executeToolResponseSchema,\n listToolsResponseSchema,\n serializedToolSchema,\n toolIdPathParams,\n agentToolPathParams,\n executeToolBodySchema,\n} from '../schemas/agents';\nimport { optionalRunIdSchema } from '../schemas/common';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { stripInjectedToolOverrideFields } from './tool-schema-overrides';\nimport { getHandlerFGAProvider, validateBody } from './utils';\n\n/**\n * Resolves a schema that may be a lazy function (e.g. AI SDK provider tools).\n * Recursively resolves until a non-function value is returned.\n * Skips functions that are themselves valid schemas (e.g. ArkType types are\n * callable but also implement StandardSchema via ~standard).\n */\nfunction resolveLazySchema(schema: unknown): unknown {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n return resolveLazySchema(schema());\n }\n return schema;\n}\n\nfunction schemaToJsonSchema(schema: PublicSchema<unknown> | undefined) {\n if (!schema) {\n return undefined;\n }\n\n return standardSchemaToJSONSchema(toStandardSchema(schema), { target: 'draft-2020-12' });\n}\n\nfunction serializeSchema(schema: unknown, options?: { stripInjectedOverrides?: boolean }): string | undefined {\n const jsonSchema = schemaToJsonSchema(resolveLazySchema(schema) as PublicSchema<unknown> | undefined);\n if (jsonSchema === undefined) return undefined;\n return stringify(options?.stripInjectedOverrides ? stripInjectedToolOverrideFields(jsonSchema) : jsonSchema);\n}\n\n/**\n * Searches dynamically-resolved agent tools (provided via `toolsResolver` /\n * function-based `tools`) for a tool with the given id. Used as a fallback\n * after the static tool registry (`registeredTools` + `mastra.getToolById`)\n * misses, so global tool routes can resolve tools that only exist on agents.\n *\n * Errors thrown by an individual agent's `listTools()` are logged and\n * skipped so a single broken resolver doesn't take down the whole lookup.\n */\nasync function findToolInAgents(mastra: any, toolId: string, requestContext: any): Promise<any | undefined> {\n const agents = mastra.listAgents() || {};\n for (const agent of Object.values(agents) as any[]) {\n try {\n const agentTools = await agent.listTools({ requestContext });\n const found = Object.values(agentTools || {}).find((t: any) => t.id === toolId);\n if (found) return found;\n } catch (error) {\n mastra.getLogger?.()?.warn?.('Failed to list tools for agent while resolving tool by id', {\n agentId: agent?.id,\n toolId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n return undefined;\n}\n\n/**\n * Serializes a tool for API responses, handling both regular tools (with Zod schemas)\n * and provider-defined tools (with AI SDK lazy schemas).\n */\nfunction serializeTool(tool: any): any {\n // Provider-defined tools (e.g. google.tools.googleSearch(), openai.tools.webSearch())\n // have lazy inputSchema functions that return AI SDK Schema objects, not Zod schemas.\n // We resolve them and use the jsonSchema property directly.\n if (isProviderDefinedTool(tool)) {\n const resolvedInput = resolveLazySchema(tool.inputSchema);\n const resolvedOutput = resolveLazySchema(tool.outputSchema);\n return {\n ...tool,\n inputSchema:\n resolvedInput && typeof resolvedInput === 'object' && 'jsonSchema' in resolvedInput\n ? stringify(resolvedInput.jsonSchema)\n : undefined,\n outputSchema:\n resolvedOutput && typeof resolvedOutput === 'object' && 'jsonSchema' in resolvedOutput\n ? stringify(resolvedOutput.jsonSchema)\n : undefined,\n };\n }\n\n return {\n ...tool,\n inputSchema: serializeSchema(tool.inputSchema, { stripInjectedOverrides: true }),\n outputSchema: serializeSchema(tool.outputSchema),\n requestContextSchema: serializeSchema(tool.requestContextSchema),\n };\n}\n\n// ============================================================================\n// Route Definitions (new pattern - handlers defined inline with createRoute)\n// ============================================================================\n\nexport const LIST_TOOLS_ROUTE = createRoute({\n method: 'GET',\n path: '/tools',\n responseType: 'json',\n responseSchema: listToolsResponseSchema,\n summary: 'List all tools',\n description: 'Returns a list of all available tools in the system',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, requestContext }) => {\n try {\n // Merge tools from two sources: mastra.listTools() includes dynamically created tools\n // (e.g. MCP tools, or agent tools registered by their intrinsic id), while registeredTools\n // includes tools discovered by the CLI bundler (keyed by export name).\n //\n // The same tool instance can appear in both maps under different keys (e.g. an agent\n // registers it by `tool.id` while the bundler registers it by export name). Dedupe by\n // `tool.id`, preferring the registeredTools (bundler) key, so each tool appears once.\n const registered = registeredTools && Object.keys(registeredTools).length > 0 ? registeredTools : {};\n\n const allTools: Record<string, any> = {};\n const seenToolIds = new Map<string, string>();\n\n // registeredTools first so their key wins for a given tool.id.\n for (const [key, tool] of Object.entries(registered)) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n for (const [key, tool] of Object.entries(mastra.listTools() ?? {})) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n // Skip if this exact tool.id was already registered (under any key) by registeredTools.\n if (toolId !== undefined && seenToolIds.has(toolId)) continue;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n const serializedTools = Object.entries(allTools).reduce<Record<string, any>>((acc, [id, _tool]) => {\n acc[id] = serializeTool(_tool);\n return acc;\n }, {});\n\n // Filter tools by FGA if configured\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n const user = requestContext?.get('user');\n if (fgaProvider && user) {\n const toolList = Object.entries(serializedTools).map(([id, t]) => ({ id, ...t }));\n const accessible = await fgaProvider.filterAccessible(user, toolList, 'tool', MastraFGAPermissions.TOOLS_READ);\n const accessibleSet = new Set(accessible.map((t: any) => t.id));\n for (const id of Object.keys(serializedTools)) {\n if (!accessibleSet.has(id)) {\n delete serializedTools[id];\n }\n }\n }\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n },\n});\n\nexport const GET_TOOL_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/tools/:toolId',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get tool by ID',\n description: 'Returns details for a specific tool including its schema and configuration',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, toolId, requestContext }) => {\n try {\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n },\n});\n\nexport const EXECUTE_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n queryParamSchema: optionalRunIdSchema,\n bodySchema: executeToolContextBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute tool',\n description: 'Executes a specific tool with the provided input data',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, runId, toolId, registeredTools, requestContext, ...bodyParams }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const { data } = bodyParams;\n\n validateBody({ data });\n\n let result;\n if (isVercelTool(tool)) {\n result = await (tool as any).execute(data);\n } else {\n result = await tool.execute(data!, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n ...(runId\n ? {\n workflow: {\n runId,\n suspend: async () => {},\n },\n }\n : {}),\n });\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n },\n});\n\n// ============================================================================\n// Agent Tool Routes\n// ============================================================================\n\nexport const GET_AGENT_TOOL_ROUTE = createRoute({\n method: 'GET',\n path: '/agents/:agentId/tools/:toolId',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get agent tool',\n description: 'Returns details for a specific tool assigned to the agent',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n },\n});\n\nexport const EXECUTE_AGENT_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/agents/:agentId/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n bodySchema: executeToolBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute agent tool',\n description: 'Executes a specific tool assigned to the agent with the provided input data',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, data, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const result = await tool.execute(data, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing agent tool');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,kBAAkB,QAA0B;CACnD,IAAI,OAAO,WAAW,cAAc,EAAE,eAAe,SACnD,OAAO,kBAAkB,OAAO,CAAC;CAEnC,OAAO;AACT;AAEA,SAAS,mBAAmB,QAA2C;CACr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KAAK,OAAO,MAAM;GAEnF,IAAI,CAAC,MACH,MAAM,IAAIN,uBAAAA,cAAc,KAAK,EAAE,SAAS,iBAAiB,CAAC;GAG5D,IAAI,CAAC,MAAM,SACT,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,yBAAyB,CAAC;GAUpE,OAAO,MAPc,KAAK,QAAQ,MAAM;IACtC;IACA;IAEA,gBAAgB,EAAE,aAAa,KAAA,EAAU;GAC3C,CAAC;EAGH,SAAS,OAAO;GACd,OAAOH,8BAAAA,YAAY,OAAO,4BAA4B;EACxD;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"tools-C9W7WvyI.cjs","names":["standardSchemaToJSONSchema","toStandardSchema","stringify","stripInjectedToolOverrideFields","isProviderDefinedTool","createRoute","listToolsResponseSchema","getHandlerFGAProvider","MastraFGAPermissions","handleError","toolIdPathParams","serializedToolSchema","HTTPException","optionalRunIdSchema","executeToolContextBodySchema","executeToolResponseSchema","isVercelTool","agentToolPathParams","getAgentFromSystem","executeToolBodySchema"],"sources":["../src/server/handlers/tools.ts"],"sourcesContent":["import { isVercelTool, isProviderDefinedTool } from '@mastra/core/tools';\nimport { toStandardSchema, standardSchemaToJSONSchema } from '@mastra/schema-compat/schema';\nimport type { PublicSchema } from '@mastra/schema-compat/schema';\nimport { stringify } from 'superjson';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n executeToolContextBodySchema,\n executeToolResponseSchema,\n listToolsResponseSchema,\n serializedToolSchema,\n toolIdPathParams,\n agentToolPathParams,\n executeToolBodySchema,\n} from '../schemas/agents';\nimport { optionalRunIdSchema } from '../schemas/common';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { stripInjectedToolOverrideFields } from './tool-schema-overrides';\nimport { getHandlerFGAProvider, validateBody } from './utils';\n\n/**\n * Resolves a schema that may be a lazy function (e.g. AI SDK provider tools).\n * Recursively resolves until a non-function value is returned.\n * Skips functions that are themselves valid schemas (e.g. ArkType types are\n * callable but also implement StandardSchema via ~standard).\n */\nfunction resolveLazySchema(schema: unknown): unknown {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n return resolveLazySchema(schema());\n }\n return schema;\n}\n\nfunction schemaToJsonSchema(schema: PublicSchema<unknown> | undefined) {\n if (!schema) {\n return undefined;\n }\n\n return standardSchemaToJSONSchema(toStandardSchema(schema), { target: 'draft-2020-12' });\n}\n\nfunction serializeSchema(schema: unknown, options?: { stripInjectedOverrides?: boolean }): string | undefined {\n const jsonSchema = schemaToJsonSchema(resolveLazySchema(schema) as PublicSchema<unknown> | undefined);\n if (jsonSchema === undefined) return undefined;\n return stringify(options?.stripInjectedOverrides ? stripInjectedToolOverrideFields(jsonSchema) : jsonSchema);\n}\n\n/**\n * Searches dynamically-resolved agent tools (provided via `toolsResolver` /\n * function-based `tools`) for a tool with the given id. Used as a fallback\n * after the static tool registry (`registeredTools` + `mastra.getToolById`)\n * misses, so global tool routes can resolve tools that only exist on agents.\n *\n * Errors thrown by an individual agent's `listTools()` are logged and\n * skipped so a single broken resolver doesn't take down the whole lookup.\n */\nasync function findToolInAgents(mastra: any, toolId: string, requestContext: any): Promise<any | undefined> {\n const agents = mastra.listAgents() || {};\n for (const agent of Object.values(agents) as any[]) {\n try {\n const agentTools = await agent.listTools({ requestContext });\n const found = Object.values(agentTools || {}).find((t: any) => t.id === toolId);\n if (found) return found;\n } catch (error) {\n mastra.getLogger?.()?.warn?.('Failed to list tools for agent while resolving tool by id', {\n agentId: agent?.id,\n toolId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n return undefined;\n}\n\n/**\n * Serializes a tool for API responses, handling both regular tools (with Zod schemas)\n * and provider-defined tools (with AI SDK lazy schemas).\n */\nfunction serializeTool(tool: any): any {\n // Provider-defined tools (e.g. google.tools.googleSearch(), openai.tools.webSearch())\n // have lazy inputSchema functions that return AI SDK Schema objects, not Zod schemas.\n // We resolve them and use the jsonSchema property directly.\n if (isProviderDefinedTool(tool)) {\n const resolvedInput = resolveLazySchema(tool.inputSchema);\n const resolvedOutput = resolveLazySchema(tool.outputSchema);\n return {\n ...tool,\n inputSchema:\n resolvedInput && typeof resolvedInput === 'object' && 'jsonSchema' in resolvedInput\n ? stringify(resolvedInput.jsonSchema)\n : undefined,\n outputSchema:\n resolvedOutput && typeof resolvedOutput === 'object' && 'jsonSchema' in resolvedOutput\n ? stringify(resolvedOutput.jsonSchema)\n : undefined,\n };\n }\n\n return {\n ...tool,\n inputSchema: serializeSchema(tool.inputSchema, { stripInjectedOverrides: true }),\n outputSchema: serializeSchema(tool.outputSchema),\n requestContextSchema: serializeSchema(tool.requestContextSchema),\n };\n}\n\n// ============================================================================\n// Route Definitions (new pattern - handlers defined inline with createRoute)\n// ============================================================================\n\nexport const LIST_TOOLS_ROUTE = createRoute({\n method: 'GET',\n path: '/tools',\n responseType: 'json',\n responseSchema: listToolsResponseSchema,\n summary: 'List all tools',\n description: 'Returns a list of all available tools in the system',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, requestContext }) => {\n try {\n // Merge tools from two sources: mastra.listTools() includes dynamically created tools\n // (e.g. MCP tools, or agent tools registered by their intrinsic id), while registeredTools\n // includes tools discovered by the CLI bundler (keyed by export name).\n //\n // The same tool instance can appear in both maps under different keys (e.g. an agent\n // registers it by `tool.id` while the bundler registers it by export name). Dedupe by\n // `tool.id`, preferring the registeredTools (bundler) key, so each tool appears once.\n const registered = registeredTools && Object.keys(registeredTools).length > 0 ? registeredTools : {};\n\n const allTools: Record<string, any> = {};\n const seenToolIds = new Map<string, string>();\n\n // registeredTools first so their key wins for a given tool.id.\n for (const [key, tool] of Object.entries(registered)) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n for (const [key, tool] of Object.entries(mastra.listTools() ?? {})) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n // Skip if this exact tool.id was already registered (under any key) by registeredTools.\n if (toolId !== undefined && seenToolIds.has(toolId)) continue;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n const serializedTools = Object.entries(allTools).reduce<Record<string, any>>((acc, [id, _tool]) => {\n acc[id] = serializeTool(_tool);\n return acc;\n }, {});\n\n // Filter tools by FGA if configured\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n const user = requestContext?.get('user');\n if (fgaProvider && user) {\n const toolList = Object.entries(serializedTools).map(([id, t]) => ({ id, ...t }));\n const accessible = await fgaProvider.filterAccessible(user, toolList, 'tool', MastraFGAPermissions.TOOLS_READ);\n const accessibleSet = new Set(accessible.map((t: any) => t.id));\n for (const id of Object.keys(serializedTools)) {\n if (!accessibleSet.has(id)) {\n delete serializedTools[id];\n }\n }\n }\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n },\n});\n\nexport const GET_TOOL_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/tools/:toolId',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get tool by ID',\n description: 'Returns details for a specific tool including its schema and configuration',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, toolId, requestContext }) => {\n try {\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n },\n});\n\nexport const EXECUTE_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n queryParamSchema: optionalRunIdSchema,\n bodySchema: executeToolContextBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute tool',\n description: 'Executes a specific tool with the provided input data',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, runId, toolId, registeredTools, requestContext, ...bodyParams }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const { data } = bodyParams;\n\n validateBody({ data });\n\n let result;\n if (isVercelTool(tool)) {\n result = await (tool as any).execute(data);\n } else {\n result = await tool.execute(data!, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n ...(runId\n ? {\n workflow: {\n runId,\n suspend: async () => {},\n },\n }\n : {}),\n });\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n },\n});\n\n// ============================================================================\n// Agent Tool Routes\n// ============================================================================\n\nexport const GET_AGENT_TOOL_ROUTE = createRoute({\n method: 'GET',\n path: '/agents/:agentId/tools/:toolId',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get agent tool',\n description: 'Returns details for a specific tool assigned to the agent',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n },\n});\n\nexport const EXECUTE_AGENT_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/agents/:agentId/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n bodySchema: executeToolBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute agent tool',\n description: 'Executes a specific tool assigned to the agent with the provided input data',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, data, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const result = await tool.execute(data, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing agent tool');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,kBAAkB,QAA0B;CACnD,IAAI,OAAO,WAAW,cAAc,EAAE,eAAe,SACnD,OAAO,kBAAkB,OAAO,CAAC;CAEnC,OAAO;AACT;AAEA,SAAS,mBAAmB,QAA2C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AAc,KAAK,OAAO,MAAM;GAEnF,IAAI,CAAC,MACH,MAAM,IAAIN,uBAAAA,cAAc,KAAK,EAAE,SAAS,iBAAiB,CAAC;GAG5D,IAAI,CAAC,MAAM,SACT,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,yBAAyB,CAAC;GAUpE,OAAO,MAPc,KAAK,QAAQ,MAAM;IACtC;IACA;IAEA,gBAAgB,EAAE,aAAa,KAAA,EAAU;GAC3C,CAAC;EAGH,SAAS,OAAO;GACd,OAAOH,8BAAAA,YAAY,OAAO,4BAA4B;EACxD;CACF;AACF,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { r as __exportAll } from "./rolldown-runtime-CQI-hT2b.js";
|
|
2
|
+
import { l as stringify } from "./utils-y-cW3mQU.js";
|
|
3
|
+
import { _ as MastraFGAPermissions, m as validateBody, o as getHandlerFGAProvider } from "./utils-CTYtskHa.js";
|
|
2
4
|
import { t as HTTPException } from "./http-exception-CzaWkxMl.js";
|
|
3
|
-
import {
|
|
5
|
+
import { n as standardSchemaToJSONSchema, r as toStandardSchema } from "./schema-Bf12g7KC-5EUrrnSf.js";
|
|
4
6
|
import { D as listToolsResponseSchema, J as serializedToolSchema, S as executeToolResponseSchema, b as executeToolBodySchema, et as toolIdPathParams, u as agentToolPathParams, x as executeToolContextBodySchema } from "./agents-BXqMKoOz.js";
|
|
5
|
-
import {
|
|
6
|
-
import { n as createRoute } from "./route-builder-
|
|
7
|
-
import {
|
|
7
|
+
import { o as optionalRunIdSchema } from "./common-J-yUnHk9.js";
|
|
8
|
+
import { n as createRoute } from "./route-builder-BKEzjw_M.js";
|
|
9
|
+
import { G as getAgentFromSystem } from "./agents-BI8ez-FT.js";
|
|
8
10
|
import { handleError } from "./server/handlers/error.js";
|
|
9
|
-
import { _ as MastraFGAPermissions, m as validateBody, o as getHandlerFGAProvider } from "./utils-B15w-1hm.js";
|
|
10
|
-
import { G as getAgentFromSystem } from "./agents-CgcW6lHt.js";
|
|
11
11
|
import { stripInjectedToolOverrideFields } from "./server/handlers/tool-schema-overrides.js";
|
|
12
12
|
import { isProviderDefinedTool, isVercelTool } from "@mastra/core/tools";
|
|
13
13
|
// src/server/handlers/tools.ts
|
|
@@ -252,4 +252,4 @@ const EXECUTE_AGENT_TOOL_ROUTE = createRoute({
|
|
|
252
252
|
});
|
|
253
253
|
export { LIST_TOOLS_ROUTE as a, GET_TOOL_BY_ID_ROUTE as i, EXECUTE_TOOL_ROUTE as n, tools_exports as o, GET_AGENT_TOOL_ROUTE as r, EXECUTE_AGENT_TOOL_ROUTE as t };
|
|
254
254
|
|
|
255
|
-
//# sourceMappingURL=tools-
|
|
255
|
+
//# sourceMappingURL=tools-Ce7SFoT1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-BAmCNGM5.js","names":[],"sources":["../src/server/handlers/tools.ts"],"sourcesContent":["import { isVercelTool, isProviderDefinedTool } from '@mastra/core/tools';\nimport { toStandardSchema, standardSchemaToJSONSchema } from '@mastra/schema-compat/schema';\nimport type { PublicSchema } from '@mastra/schema-compat/schema';\nimport { stringify } from 'superjson';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n executeToolContextBodySchema,\n executeToolResponseSchema,\n listToolsResponseSchema,\n serializedToolSchema,\n toolIdPathParams,\n agentToolPathParams,\n executeToolBodySchema,\n} from '../schemas/agents';\nimport { optionalRunIdSchema } from '../schemas/common';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { stripInjectedToolOverrideFields } from './tool-schema-overrides';\nimport { getHandlerFGAProvider, validateBody } from './utils';\n\n/**\n * Resolves a schema that may be a lazy function (e.g. AI SDK provider tools).\n * Recursively resolves until a non-function value is returned.\n * Skips functions that are themselves valid schemas (e.g. ArkType types are\n * callable but also implement StandardSchema via ~standard).\n */\nfunction resolveLazySchema(schema: unknown): unknown {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n return resolveLazySchema(schema());\n }\n return schema;\n}\n\nfunction schemaToJsonSchema(schema: PublicSchema<unknown> | undefined) {\n if (!schema) {\n return undefined;\n }\n\n return standardSchemaToJSONSchema(toStandardSchema(schema), { target: 'draft-2020-12' });\n}\n\nfunction serializeSchema(schema: unknown, options?: { stripInjectedOverrides?: boolean }): string | undefined {\n const jsonSchema = schemaToJsonSchema(resolveLazySchema(schema) as PublicSchema<unknown> | undefined);\n if (jsonSchema === undefined) return undefined;\n return stringify(options?.stripInjectedOverrides ? stripInjectedToolOverrideFields(jsonSchema) : jsonSchema);\n}\n\n/**\n * Searches dynamically-resolved agent tools (provided via `toolsResolver` /\n * function-based `tools`) for a tool with the given id. Used as a fallback\n * after the static tool registry (`registeredTools` + `mastra.getToolById`)\n * misses, so global tool routes can resolve tools that only exist on agents.\n *\n * Errors thrown by an individual agent's `listTools()` are logged and\n * skipped so a single broken resolver doesn't take down the whole lookup.\n */\nasync function findToolInAgents(mastra: any, toolId: string, requestContext: any): Promise<any | undefined> {\n const agents = mastra.listAgents() || {};\n for (const agent of Object.values(agents) as any[]) {\n try {\n const agentTools = await agent.listTools({ requestContext });\n const found = Object.values(agentTools || {}).find((t: any) => t.id === toolId);\n if (found) return found;\n } catch (error) {\n mastra.getLogger?.()?.warn?.('Failed to list tools for agent while resolving tool by id', {\n agentId: agent?.id,\n toolId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n return undefined;\n}\n\n/**\n * Serializes a tool for API responses, handling both regular tools (with Zod schemas)\n * and provider-defined tools (with AI SDK lazy schemas).\n */\nfunction serializeTool(tool: any): any {\n // Provider-defined tools (e.g. google.tools.googleSearch(), openai.tools.webSearch())\n // have lazy inputSchema functions that return AI SDK Schema objects, not Zod schemas.\n // We resolve them and use the jsonSchema property directly.\n if (isProviderDefinedTool(tool)) {\n const resolvedInput = resolveLazySchema(tool.inputSchema);\n const resolvedOutput = resolveLazySchema(tool.outputSchema);\n return {\n ...tool,\n inputSchema:\n resolvedInput && typeof resolvedInput === 'object' && 'jsonSchema' in resolvedInput\n ? stringify(resolvedInput.jsonSchema)\n : undefined,\n outputSchema:\n resolvedOutput && typeof resolvedOutput === 'object' && 'jsonSchema' in resolvedOutput\n ? stringify(resolvedOutput.jsonSchema)\n : undefined,\n };\n }\n\n return {\n ...tool,\n inputSchema: serializeSchema(tool.inputSchema, { stripInjectedOverrides: true }),\n outputSchema: serializeSchema(tool.outputSchema),\n requestContextSchema: serializeSchema(tool.requestContextSchema),\n };\n}\n\n// ============================================================================\n// Route Definitions (new pattern - handlers defined inline with createRoute)\n// ============================================================================\n\nexport const LIST_TOOLS_ROUTE = createRoute({\n method: 'GET',\n path: '/tools',\n responseType: 'json',\n responseSchema: listToolsResponseSchema,\n summary: 'List all tools',\n description: 'Returns a list of all available tools in the system',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, requestContext }) => {\n try {\n // Merge tools from two sources: mastra.listTools() includes dynamically created tools\n // (e.g. MCP tools, or agent tools registered by their intrinsic id), while registeredTools\n // includes tools discovered by the CLI bundler (keyed by export name).\n //\n // The same tool instance can appear in both maps under different keys (e.g. an agent\n // registers it by `tool.id` while the bundler registers it by export name). Dedupe by\n // `tool.id`, preferring the registeredTools (bundler) key, so each tool appears once.\n const registered = registeredTools && Object.keys(registeredTools).length > 0 ? registeredTools : {};\n\n const allTools: Record<string, any> = {};\n const seenToolIds = new Map<string, string>();\n\n // registeredTools first so their key wins for a given tool.id.\n for (const [key, tool] of Object.entries(registered)) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n for (const [key, tool] of Object.entries(mastra.listTools() ?? {})) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n // Skip if this exact tool.id was already registered (under any key) by registeredTools.\n if (toolId !== undefined && seenToolIds.has(toolId)) continue;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n const serializedTools = Object.entries(allTools).reduce<Record<string, any>>((acc, [id, _tool]) => {\n acc[id] = serializeTool(_tool);\n return acc;\n }, {});\n\n // Filter tools by FGA if configured\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n const user = requestContext?.get('user');\n if (fgaProvider && user) {\n const toolList = Object.entries(serializedTools).map(([id, t]) => ({ id, ...t }));\n const accessible = await fgaProvider.filterAccessible(user, toolList, 'tool', MastraFGAPermissions.TOOLS_READ);\n const accessibleSet = new Set(accessible.map((t: any) => t.id));\n for (const id of Object.keys(serializedTools)) {\n if (!accessibleSet.has(id)) {\n delete serializedTools[id];\n }\n }\n }\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n },\n});\n\nexport const GET_TOOL_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/tools/:toolId',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get tool by ID',\n description: 'Returns details for a specific tool including its schema and configuration',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, toolId, requestContext }) => {\n try {\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n },\n});\n\nexport const EXECUTE_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n queryParamSchema: optionalRunIdSchema,\n bodySchema: executeToolContextBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute tool',\n description: 'Executes a specific tool with the provided input data',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, runId, toolId, registeredTools, requestContext, ...bodyParams }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const { data } = bodyParams;\n\n validateBody({ data });\n\n let result;\n if (isVercelTool(tool)) {\n result = await (tool as any).execute(data);\n } else {\n result = await tool.execute(data!, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n ...(runId\n ? {\n workflow: {\n runId,\n suspend: async () => {},\n },\n }\n : {}),\n });\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n },\n});\n\n// ============================================================================\n// Agent Tool Routes\n// ============================================================================\n\nexport const GET_AGENT_TOOL_ROUTE = createRoute({\n method: 'GET',\n path: '/agents/:agentId/tools/:toolId',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get agent tool',\n description: 'Returns details for a specific tool assigned to the agent',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n },\n});\n\nexport const EXECUTE_AGENT_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/agents/:agentId/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n bodySchema: executeToolBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute agent tool',\n description: 'Executes a specific tool assigned to the agent with the provided input data',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, data, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const result = await tool.execute(data, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing agent tool');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,kBAAkB,QAA0B;CACnD,IAAI,OAAO,WAAW,cAAc,EAAE,eAAe,SACnD,OAAO,kBAAkB,OAAO,CAAC;CAEnC,OAAO;AACT;AAEA,SAAS,mBAAmB,QAA2C;CACrE,IAAI,CAAC,QACH;CAGF,OAAO,2BAA2B,iBAAiB,MAAM,GAAG,EAAE,QAAQ,gBAAgB,CAAC;AACzF;AAEA,SAAS,gBAAgB,Q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Ac,CAAC,CAAC,CAAC,CAAC,MAAM,SAAc,KAAK,OAAO,MAAM;GAEnF,IAAI,CAAC,MACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,iBAAiB,CAAC;GAG5D,OAAO,cAAc,IAAI;EAC3B,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,0BAA0B;EACtD;CACF;AACF,CAAC;AAED,MAAa,2BAA2B,YAAY;CAClD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,YAAY;CACZ,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,UAAU,OAAO;CACxB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,SAAS,QAAQ,MAAM,qBAAqB;EACpE,IAAI;GACF,IAAI,CAAC,SACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,uBAAuB,CAAC;GAIlE,MAAM,aAAa,OAAM,MAFL,mBAAmB;IAAE;IAAQ;GAAQ,CAAC,EAAA,CAE3B,UAAU,EAAE,eAAe,CAAC;GAE3D,MAAM,OAAO,OAAO,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,SAAc,KAAK,OAAO,MAAM;GAEnF,IAAI,CAAC,MACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,iBAAiB,CAAC;GAG5D,IAAI,CAAC,MAAM,SACT,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,yBAAyB,CAAC;GAUpE,OAAO,MAPc,KAAK,QAAQ,MAAM;IACtC;IACA;IAEA,gBAAgB,EAAE,aAAa,KAAA,EAAU;GAC3C,CAAC;EAGH,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,4BAA4B;EACxD;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"tools-Ce7SFoT1.js","names":[],"sources":["../src/server/handlers/tools.ts"],"sourcesContent":["import { isVercelTool, isProviderDefinedTool } from '@mastra/core/tools';\nimport { toStandardSchema, standardSchemaToJSONSchema } from '@mastra/schema-compat/schema';\nimport type { PublicSchema } from '@mastra/schema-compat/schema';\nimport { stringify } from 'superjson';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n executeToolContextBodySchema,\n executeToolResponseSchema,\n listToolsResponseSchema,\n serializedToolSchema,\n toolIdPathParams,\n agentToolPathParams,\n executeToolBodySchema,\n} from '../schemas/agents';\nimport { optionalRunIdSchema } from '../schemas/common';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { stripInjectedToolOverrideFields } from './tool-schema-overrides';\nimport { getHandlerFGAProvider, validateBody } from './utils';\n\n/**\n * Resolves a schema that may be a lazy function (e.g. AI SDK provider tools).\n * Recursively resolves until a non-function value is returned.\n * Skips functions that are themselves valid schemas (e.g. ArkType types are\n * callable but also implement StandardSchema via ~standard).\n */\nfunction resolveLazySchema(schema: unknown): unknown {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n return resolveLazySchema(schema());\n }\n return schema;\n}\n\nfunction schemaToJsonSchema(schema: PublicSchema<unknown> | undefined) {\n if (!schema) {\n return undefined;\n }\n\n return standardSchemaToJSONSchema(toStandardSchema(schema), { target: 'draft-2020-12' });\n}\n\nfunction serializeSchema(schema: unknown, options?: { stripInjectedOverrides?: boolean }): string | undefined {\n const jsonSchema = schemaToJsonSchema(resolveLazySchema(schema) as PublicSchema<unknown> | undefined);\n if (jsonSchema === undefined) return undefined;\n return stringify(options?.stripInjectedOverrides ? stripInjectedToolOverrideFields(jsonSchema) : jsonSchema);\n}\n\n/**\n * Searches dynamically-resolved agent tools (provided via `toolsResolver` /\n * function-based `tools`) for a tool with the given id. Used as a fallback\n * after the static tool registry (`registeredTools` + `mastra.getToolById`)\n * misses, so global tool routes can resolve tools that only exist on agents.\n *\n * Errors thrown by an individual agent's `listTools()` are logged and\n * skipped so a single broken resolver doesn't take down the whole lookup.\n */\nasync function findToolInAgents(mastra: any, toolId: string, requestContext: any): Promise<any | undefined> {\n const agents = mastra.listAgents() || {};\n for (const agent of Object.values(agents) as any[]) {\n try {\n const agentTools = await agent.listTools({ requestContext });\n const found = Object.values(agentTools || {}).find((t: any) => t.id === toolId);\n if (found) return found;\n } catch (error) {\n mastra.getLogger?.()?.warn?.('Failed to list tools for agent while resolving tool by id', {\n agentId: agent?.id,\n toolId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n return undefined;\n}\n\n/**\n * Serializes a tool for API responses, handling both regular tools (with Zod schemas)\n * and provider-defined tools (with AI SDK lazy schemas).\n */\nfunction serializeTool(tool: any): any {\n // Provider-defined tools (e.g. google.tools.googleSearch(), openai.tools.webSearch())\n // have lazy inputSchema functions that return AI SDK Schema objects, not Zod schemas.\n // We resolve them and use the jsonSchema property directly.\n if (isProviderDefinedTool(tool)) {\n const resolvedInput = resolveLazySchema(tool.inputSchema);\n const resolvedOutput = resolveLazySchema(tool.outputSchema);\n return {\n ...tool,\n inputSchema:\n resolvedInput && typeof resolvedInput === 'object' && 'jsonSchema' in resolvedInput\n ? stringify(resolvedInput.jsonSchema)\n : undefined,\n outputSchema:\n resolvedOutput && typeof resolvedOutput === 'object' && 'jsonSchema' in resolvedOutput\n ? stringify(resolvedOutput.jsonSchema)\n : undefined,\n };\n }\n\n return {\n ...tool,\n inputSchema: serializeSchema(tool.inputSchema, { stripInjectedOverrides: true }),\n outputSchema: serializeSchema(tool.outputSchema),\n requestContextSchema: serializeSchema(tool.requestContextSchema),\n };\n}\n\n// ============================================================================\n// Route Definitions (new pattern - handlers defined inline with createRoute)\n// ============================================================================\n\nexport const LIST_TOOLS_ROUTE = createRoute({\n method: 'GET',\n path: '/tools',\n responseType: 'json',\n responseSchema: listToolsResponseSchema,\n summary: 'List all tools',\n description: 'Returns a list of all available tools in the system',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, requestContext }) => {\n try {\n // Merge tools from two sources: mastra.listTools() includes dynamically created tools\n // (e.g. MCP tools, or agent tools registered by their intrinsic id), while registeredTools\n // includes tools discovered by the CLI bundler (keyed by export name).\n //\n // The same tool instance can appear in both maps under different keys (e.g. an agent\n // registers it by `tool.id` while the bundler registers it by export name). Dedupe by\n // `tool.id`, preferring the registeredTools (bundler) key, so each tool appears once.\n const registered = registeredTools && Object.keys(registeredTools).length > 0 ? registeredTools : {};\n\n const allTools: Record<string, any> = {};\n const seenToolIds = new Map<string, string>();\n\n // registeredTools first so their key wins for a given tool.id.\n for (const [key, tool] of Object.entries(registered)) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n for (const [key, tool] of Object.entries(mastra.listTools() ?? {})) {\n const toolId = typeof (tool as any)?.id === 'string' ? (tool as any).id : undefined;\n // Skip if this exact tool.id was already registered (under any key) by registeredTools.\n if (toolId !== undefined && seenToolIds.has(toolId)) continue;\n if (toolId !== undefined) seenToolIds.set(toolId, key);\n allTools[key] = tool;\n }\n\n const serializedTools = Object.entries(allTools).reduce<Record<string, any>>((acc, [id, _tool]) => {\n acc[id] = serializeTool(_tool);\n return acc;\n }, {});\n\n // Filter tools by FGA if configured\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n const user = requestContext?.get('user');\n if (fgaProvider && user) {\n const toolList = Object.entries(serializedTools).map(([id, t]) => ({ id, ...t }));\n const accessible = await fgaProvider.filterAccessible(user, toolList, 'tool', MastraFGAPermissions.TOOLS_READ);\n const accessibleSet = new Set(accessible.map((t: any) => t.id));\n for (const id of Object.keys(serializedTools)) {\n if (!accessibleSet.has(id)) {\n delete serializedTools[id];\n }\n }\n }\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n },\n});\n\nexport const GET_TOOL_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/tools/:toolId',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get tool by ID',\n description: 'Returns details for a specific tool including its schema and configuration',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, registeredTools, toolId, requestContext }) => {\n try {\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n },\n});\n\nexport const EXECUTE_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: toolIdPathParams,\n queryParamSchema: optionalRunIdSchema,\n bodySchema: executeToolContextBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute tool',\n description: 'Executes a specific tool with the provided input data',\n tags: ['Tools'],\n requiresAuth: true,\n handler: async ({ mastra, runId, toolId, registeredTools, requestContext, ...bodyParams }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n let tool: any;\n\n // Try explicit registeredTools first, then fallback to mastra\n if (registeredTools && Object.keys(registeredTools).length > 0) {\n tool = Object.values(registeredTools).find((t: any) => t.id === toolId);\n }\n if (!tool) {\n try {\n tool = mastra.getToolById(toolId);\n } catch {\n // tool not found in global registry, continue to agent fallback\n }\n }\n\n // Fallback: search dynamically-resolved agent tools (toolsResolver)\n if (!tool) {\n tool = await findToolInAgents(mastra, toolId, requestContext);\n }\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const { data } = bodyParams;\n\n validateBody({ data });\n\n let result;\n if (isVercelTool(tool)) {\n result = await (tool as any).execute(data);\n } else {\n result = await tool.execute(data!, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n ...(runId\n ? {\n workflow: {\n runId,\n suspend: async () => {},\n },\n }\n : {}),\n });\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n },\n});\n\n// ============================================================================\n// Agent Tool Routes\n// ============================================================================\n\nexport const GET_AGENT_TOOL_ROUTE = createRoute({\n method: 'GET',\n path: '/agents/:agentId/tools/:toolId',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n responseSchema: serializedToolSchema,\n summary: 'Get agent tool',\n description: 'Returns details for a specific tool assigned to the agent',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n return serializeTool(tool);\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n },\n});\n\nexport const EXECUTE_AGENT_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/agents/:agentId/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: agentToolPathParams,\n bodySchema: executeToolBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute agent tool',\n description: 'Executes a specific tool assigned to the agent with the provided input data',\n tags: ['Agents', 'Tools'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, toolId, data, requestContext }) => {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const agentTools = await agent.listTools({ requestContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n const result = await tool.execute(data, {\n mastra,\n requestContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing agent tool');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,kBAAkB,QAA0B;CACnD,IAAI,OAAO,WAAW,cAAc,EAAE,eAAe,SACnD,OAAO,kBAAkB,OAAO,CAAC;CAEnC,OAAO;AACT;AAEA,SAAS,mBAAmB,QAA2C;CACrE,IAAI,CAAC,QACH;CAGF,OAAO,2BAA2B,iBAAiB,MAAM,GAAG,EAAE,QAAQ,gBAAgB,CAAC;AACzF;AAEA,SAAS,gBAAgB,QAAiB,SAAoE;CAC5G,MAAM,aAAa,mBAAmB,kBAAkB,MAAM,CAAsC;CACpG,IAAI,eAAe,KAAA,GAAW,OAAO,KAAA;CACrC,OAAO,UAAU,SAAS,yBAAyB,gCAAgC,UAAU,IAAI,UAAU;AAC7G;;;;;;;;;;AAWA,eAAe,iBAAiB,QAAa,QAAgB,gBAA+C;CAC1G,MAAM,SAAS,OAAO,WAAW,KAAK,CAAC;CACvC,KAAK,MAAM,SAAS,OAAO,OAAO,MAAM,GACtC,IAAI;EACF,MAAM,aAAa,MAAM,MAAM,UAAU,EAAE,eAAe,CAAC;EAC3D,MAAM,QAAQ,OAAO,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,MAAW,EAAE,OAAO,MAAM;EAC9E,IAAI,OAAO,OAAO;CACpB,SAAS,OAAO;EACd,OAAO,YAAY,CAAC,EAAE,OAAO,6DAA6D;GACxF,SAAS,OAAO;GAChB;GACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC9D,CAAC;CACH;AAGJ;;;;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,OAAO,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,SAAc,KAAK,OAAO,MAAM;GAEnF,IAAI,CAAC,MACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,iBAAiB,CAAC;GAG5D,IAAI,CAAC,MAAM,SACT,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,yBAAyB,CAAC;GAUpE,OAAO,MAPc,KAAK,QAAQ,MAAM;IACtC;IACA;IAEA,gBAAgB,EAAE,aAAa,KAAA,EAAU;GAC3C,CAAC;EAGH,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,4BAA4B;EACxD;CACF;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-10nMEhjP.cjs");
|
|
2
|
-
const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
3
2
|
const require_constants = require("./constants-DMg8hUOR.cjs");
|
|
3
|
+
const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
4
4
|
let _mastra_core_auth_ee = require("@mastra/core/auth/ee");
|
|
5
5
|
_mastra_core_auth_ee = require_rolldown_runtime.__toESM(_mastra_core_auth_ee, 1);
|
|
6
6
|
let _mastra_core_memory = require("@mastra/core/memory");
|
|
@@ -354,4 +354,4 @@ Object.defineProperty(exports, "validateThreadOwnership", {
|
|
|
354
354
|
}
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
-
//# sourceMappingURL=utils-
|
|
357
|
+
//# sourceMappingURL=utils-BXEJ6FZC.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-9PRHHTGC.cjs","names":["authEE","HTTPException","isReservedRequestContextKey","MASTRA_RESOURCE_ID_KEY","MastraMemory"],"sources":["../src/server/fga-permissions.ts","../src/server/handlers/utils.ts"],"sourcesContent":["/**\n * Safe re-export of `MastraFGAPermissions` from `@mastra/core/auth/ee`.\n *\n * Why this shim exists:\n * `MastraFGAPermissions` was introduced in `@mastra/core@1.32.0`. Earlier\n * versions of `@mastra/core` ship `@mastra/core/auth/ee` but do not export\n * this constant. A direct named import (`import { MastraFGAPermissions }\n * from '@mastra/core/auth/ee'`) fails at ESM link time when this version\n * of `@mastra/server` is paired with `@mastra/core < 1.32.0`, taking the\n * entire user bundle down before any code runs.\n *\n * A namespace import tolerates missing names — `ns.MissingExport` is just\n * `undefined`, no link-time error. We then expose the permission map.\n *\n * Fallback values:\n * If the consuming `@mastra/core` does not export `MastraFGAPermissions`,\n * we substitute a hardcoded map of the canonical permission strings used\n * by routes in `@mastra/server`. This preserves the explicit RBAC\n * permission overrides those routes already had as string literals in\n * `@mastra/server@1.31.0` (e.g. `requiresPermission: \"agents:execute\"`\n * on `/v1/responses`). Without this fallback, `requiresPermission` would\n * be `undefined` on old core and the auth layer would derive the wrong\n * permission from the route path (e.g. `v1:write` instead of\n * `agents:execute`), breaking RBAC users who upgrade `@mastra/server`\n * but stay on `@mastra/core@1.31.0`.\n *\n * Once the consuming `@mastra/core` is on `1.32.0+` the values are real\n * and behaviour is identical to a direct named import.\n */\n\nimport * as authEE from '@mastra/core/auth/ee';\n\n// Canonical strings for the FGA permission keys actually referenced by\n// `@mastra/server` source. Mirrors `MastraFGAPermissions` in\n// `@mastra/core@1.32.0+` for these specific keys, and matches the string\n// literals previously hardcoded on the same routes in `@mastra/server@1.31.0`.\nconst FALLBACK_PERMISSIONS = {\n AGENTS_CREATE: 'agents:create',\n AGENTS_DELETE: 'agents:delete',\n AGENTS_EXECUTE: 'agents:execute',\n AGENTS_READ: 'agents:read',\n KNOWLEDGE_READ: 'knowledge:read',\n MEMORY_DELETE: 'memory:delete',\n MEMORY_READ: 'memory:read',\n MEMORY_WRITE: 'memory:write',\n TOOLS_EXECUTE: 'tools:execute',\n TOOLS_READ: 'tools:read',\n STORED_WORKFLOWS_READ: 'stored-workflows:read',\n STORED_WORKFLOWS_WRITE: 'stored-workflows:write',\n WORKFLOWS_EXECUTE: 'workflows:execute',\n WORKFLOWS_READ: 'workflows:read',\n} as const;\n\nconst realPermissions = (authEE as any).MastraFGAPermissions;\n\n// Typed as `any` on purpose: consumers of `@mastra/server` may run their\n// typecheck against a `@mastra/core` that doesn't export `MastraFGAPermissions`\n// (anything < 1.32.0). Pinning to the real type would push that name into the\n// emitted `.d.ts` and break downstream typecheck. `any` lets the property\n// accesses (`MastraFGAPermissions.AGENTS_READ`) flow through cleanly on every\n// supported core.\nexport const MastraFGAPermissions: any =\n // Merge so a core that exports the map without a newer key (older than this PR) still resolves it.\n { ...FALLBACK_PERMISSIONS, ...(realPermissions ?? {}) };\n","import type { Mastra } from '@mastra/core';\nimport type { IFGAProvider, MastraFGAPermissionInput } from '@mastra/core/auth/ee';\nimport type { RequestContext } from '@mastra/core/di';\nimport { MastraMemory } from '@mastra/core/memory';\nimport type { Workflow } from '@mastra/core/workflows';\nimport {\n MASTRA_AUTH_MODE_KEY,\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n isReservedRequestContextKey,\n} from '../constants';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\n\n/**\n * Resolves a workflow by id or registration key from the set Mastra exposes\n * publicly. Unlike `mastra.getWorkflowById`, this excludes hidden internal\n * workflows (e.g. a durable agent's backing loop), which must never be\n * runnable through HTTP routes.\n */\nexport function getPublicWorkflowById(mastra: Mastra, workflowId: string): Workflow | undefined {\n const workflows = mastra.listWorkflows();\n return (\n Object.values(workflows).find(workflow => workflow.id === workflowId) ??\n (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : undefined)\n );\n}\n\n/**\n * Resolves the FGA provider a handler should use for this request, following\n * the same auth-mode-aware selection as the route-level checks: Studio auth\n * requests use `studio.fga` when it is configured, and everything else uses\n * `server.fga`.\n *\n * Returns `undefined` when FGA is not configured at all. When FGA is\n * configured but no provider applies to this request (for example `studio.fga`\n * is set and the request used server auth), the request is denied rather than\n * treated as unrestricted.\n */\nexport function getHandlerFGAProvider(mastra: any, requestContext?: RequestContext): IFGAProvider | undefined {\n const studioFga = mastra?.getStudio?.()?.fga as IFGAProvider | undefined;\n const serverFga = mastra?.getServer?.()?.fga as IFGAProvider | undefined;\n\n if (requestContext?.get(MASTRA_AUTH_MODE_KEY) === 'studio' && studioFga) return studioFga;\n if (serverFga) return serverFga;\n if (studioFga) {\n throw new HTTPException(403, { message: 'Access denied: no FGA provider is configured for this request' });\n }\n return undefined;\n}\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n if (!value) {\n acc[key] = `Argument \"${key}\" is required`;\n }\n return acc;\n }, {});\n\n if (Object.keys(errorResponse).length > 0) {\n throw new HTTPException(400, { message: Object.values(errorResponse)[0] });\n }\n}\n\n/**\n * sanitizes the body by removing disallowed keys.\n * @param body body to sanitize\n * @param disallowedKeys keys to remove from the body\n */\nexport function sanitizeBody(body: Record<string, unknown>, disallowedKeys: string[]) {\n for (const key of disallowedKeys) {\n if (key in body) {\n delete body[key];\n }\n }\n}\n\nconst CREDENTIAL_HEADER_NAMES = new Set([\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'api-key',\n 'x-goog-api-key',\n 'cookie',\n]);\n\n/**\n * Removes credential-bearing headers from client-supplied `modelSettings.headers`\n * so a caller's own auth (e.g. the app's bearer token) can never override the\n * provider credential configured on the server. Non-credential headers are kept.\n */\nexport function stripClientCredentialHeaders(body: Record<string, unknown>) {\n const modelSettings = body.modelSettings;\n if (!modelSettings || typeof modelSettings !== 'object') return;\n const headers = (modelSettings as { headers?: unknown }).headers;\n if (!headers || typeof headers !== 'object') return;\n\n const kept = Object.fromEntries(\n Object.entries(headers).filter(([name]) => !CREDENTIAL_HEADER_NAMES.has(name.toLowerCase())),\n );\n body.modelSettings = { ...modelSettings, headers: kept };\n}\n\nexport function parsePerPage(\n value: string | undefined,\n defaultValue: number = 100,\n max: number = 1000,\n): number | false {\n const normalized = (value || '').trim().toLowerCase();\n // Handle explicit false to bypass pagination\n if (normalized === 'false') {\n return false;\n }\n const parsed = parseInt(value || String(defaultValue), 10);\n if (isNaN(parsed)) return defaultValue;\n return Math.min(max, Math.max(1, parsed));\n}\n\n/**\n * Parses filter query parameters into a key-value object.\n */\nexport function parseFilters(filters: string | string[] | undefined): Record<string, string> | undefined {\n if (!filters) return undefined;\n\n return Object.fromEntries(\n (Array.isArray(filters) ? filters : [filters]).map((attr: string) => {\n const [key, ...valueParts] = attr.split(':');\n const value = valueParts.join(':'); // ✅ Handles colons in values\n return [key, value];\n }),\n );\n}\n\n/**\n * Merges a body-supplied requestContext into the trusted server RequestContext.\n * The server context is authoritative: reserved keys are skipped and body values\n * only fill keys the server context has not already set.\n */\nexport function mergeBodyRequestContext(serverRequestContext: RequestContext, bodyRequestContext: unknown): void {\n if (!bodyRequestContext || typeof bodyRequestContext !== 'object') {\n return;\n }\n\n for (const [key, value] of Object.entries(bodyRequestContext)) {\n if (isReservedRequestContextKey(key)) continue;\n if (serverRequestContext.get(key) === undefined) {\n serverRequestContext.set(key, value);\n }\n }\n}\n\n// ============================================================================\n// Authorization Utilities\n// ============================================================================\n\n/**\n * Gets the effective resourceId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveResourceId(\n requestContext: RequestContext | undefined,\n clientResourceId: string | undefined,\n): string | undefined {\n const contextResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n return contextResourceId || clientResourceId;\n}\n\n/**\n * Returns the resource id resolved from the request context alone (set via\n * `mapUserToResourceId` or the `x-resource-id` header), ignoring any\n * client-provided value. Its presence indicates a resource-scoped caller;\n * its absence indicates a privileged/service context.\n */\nexport function getContextResourceId(requestContext: RequestContext | undefined): string | undefined {\n return requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n}\n\n/**\n * Ensures a memory request has a resolvable resource ID. The body's\n * `memory.resource` is optional so authenticated setups can rely on the\n * server-derived resource ID (MASTRA_RESOURCE_ID_KEY set via mapUserToResourceId).\n * When neither the body nor the request context provides one, reject with a\n * clear 400 instead of failing deep inside agent execution.\n */\nexport function requireEffectiveResourceId(\n effectiveResourceId: string | undefined,\n): asserts effectiveResourceId is string {\n if (!effectiveResourceId) {\n throw new HTTPException(400, {\n message:\n 'A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.',\n });\n }\n}\n\n/**\n * Gets the effective threadId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveThreadId(\n requestContext: RequestContext | undefined,\n clientThreadId: string | undefined,\n): string | undefined {\n const contextThreadId = requestContext?.get(MASTRA_THREAD_ID_KEY) as string | undefined;\n return contextThreadId || clientThreadId;\n}\n\n/**\n * Applies the effective threadId to a client memory thread option. Object\n * threads keep their other fields (metadata, title, ...) so they reach thread\n * creation; a client-supplied resourceId is dropped because the server decides\n * the resource.\n */\nexport function applyEffectiveThreadId<T extends string | { id: string } | undefined>(\n thread: T,\n effectiveThreadId: string | undefined,\n): T | string {\n if (!effectiveThreadId) return thread;\n if (thread && typeof thread === 'object') {\n const { resourceId: _resourceId, ...fields } = thread as { id: string; resourceId?: unknown };\n return { ...fields, id: effectiveThreadId } as T;\n }\n return effectiveThreadId;\n}\n\n/**\n * Validates that a thread belongs to the specified resourceId.\n * Throws 403 if the thread exists but belongs to a different resource.\n * Threads with no resourceId are accessible to all (shared threads).\n */\nexport async function validateThreadOwnership(\n thread: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n): Promise<void> {\n if (thread && effectiveResourceId && thread.resourceId && thread.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: thread belongs to a different resource' });\n }\n}\n\n/**\n * Validates both coarse resource ownership and fine-grained thread access.\n * FGA enforcement is a no-op when no FGA provider is configured.\n */\nexport async function enforceThreadAccess({\n mastra,\n requestContext,\n threadId,\n thread,\n effectiveResourceId,\n permission = MastraFGAPermissions.MEMORY_READ,\n}: {\n mastra: any;\n requestContext?: RequestContext;\n threadId: string;\n thread?: { resourceId?: string | null } | null;\n effectiveResourceId?: string;\n permission?: MastraFGAPermissionInput;\n}): Promise<void> {\n await validateThreadOwnership(thread, effectiveResourceId);\n\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n if (!fgaProvider) {\n return;\n }\n\n const user = requestContext?.get('user');\n if (!user || typeof user !== 'object') {\n throw new HTTPException(403, { message: 'FGA authorization denied: authenticated user is required' });\n }\n\n await MastraMemory.checkThreadFGA({\n mastra,\n user: user as { id: string; [key: string]: unknown },\n threadId,\n resourceId: thread?.resourceId ?? effectiveResourceId,\n requestContext,\n permission,\n fgaProvider,\n });\n}\n\n/**\n * Validates that a caller may act on a workflow run.\n *\n * Without `server.auth.mapUserToResourceId` there is no tenancy model, and only a mismatch\n * between two present resource ids is denied. With a mapper, a resource-scoped caller may only\n * act on runs it owns (an owner-less run is not its run). An unscoped caller is a\n * privileged/service context (see getContextResourceId), but that privilege is only granted when\n * an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,\n * as on the thread-transfer route.\n */\nexport async function validateRunOwnership(\n run: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n mastra?: {\n getServer?: () => { auth?: unknown; fga?: unknown } | undefined;\n getStudio?: () => { fga?: unknown } | undefined;\n },\n requestContext?: RequestContext,\n): Promise<void> {\n if (!run) return;\n const server = mastra?.getServer?.();\n const tenancy =\n typeof (server?.auth as { mapUserToResourceId?: unknown } | undefined)?.mapUserToResourceId === 'function';\n if (!tenancy) {\n if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (effectiveResourceId) {\n if (run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (!getHandlerFGAProvider(mastra, requestContext)) {\n throw new HTTPException(403, {\n message:\n 'Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access.',\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,uBAAuB;CAC3B,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,gBAAgB;CAChB,eAAe;CACf,aAAa;CACb,cAAc;CACd,eAAe;CACf,YAAY;CACZ,uBAAuB;CACvB,wBAAwB;CACxB,mBAAmB;CACnB,gBAAgB;AAClB;AAEA,MAAM,kBAAmBA,qBAAe;AAQxC,MAAa,uBAEX;CAAE,GAAG;CAAsB,GAAI,mBAAmB,CAAC;AAAG;;;;;;;;AC3CxD,SAAgB,sBAAsB,QAAgB,YAA0C;CAC9F,MAAM,YAAY,OAAO,cAAc;CACvC,OACE,OAAO,OAAO,SAAS,CAAC,CAAC,MAAK,aAAY,SAAS,OAAO,UAAU,MACnE,OAAO,OAAO,WAAW,UAAU,IAAI,UAAU,cAAc,KAAA;AAEpE;;;;;;;;;;;;AAaA,SAAgB,sBAAsB,QAAa,gBAA2D;CAC5G,MAAM,YAAY,QAAQ,YAAY,CAAC,EAAE;CACzC,MAAM,YAAY,QAAQ,YAAY,CAAC,EAAE;CAEzC,IAAI,gBAAgB,IAAA,kBAAwB,MAAM,YAAY,WAAW,OAAO;CAChF,IAAI,WAAW,OAAO;CACtB,IAAI,WACF,MAAM,IAAIC,uBAAAA,cAAc,KAAK,EAAE,SAAS,gEAAgE,CAAC;AAG7G;AAGA,SAAgB,aAAa,MAA+B;CAC1D,MAAM,gBAAgB,OAAO,QAAQ,IAAI,CAAC,CAAC,QAAgC,KAAK,CAAC,KAAK,WAAW;EAC/F,IAAI,CAAC,OACH,IAAI,OAAO,aAAa,IAAI;EAE9B,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,IAAI,OAAO,KAAK,aAAa,CAAC,CAAC,SAAS,GACtC,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,OAAO,OAAO,aAAa,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AAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,2DAA2D,CAAC;CAGtG,MAAMG,oBAAAA,aAAa,eAAe;EAChC;EACM;EACN;EACA,YAAY,QAAQ,cAAc;EAClC;EACA;EACA;CACF,CAAC;AACH;;;;;;;;;;;AAYA,eAAsB,qBACpB,KACA,qBACA,QAIA,gBACe;CACf,IAAI,CAAC,KAAK;CAIV,IAAI,EADF,SAFa,QAAQ,YAAY,EAAA,EAEjB,KAAA,EAAwD,wBAAwB,aACpF;EACZ,IAAI,uBAAuB,IAAI,cAAc,IAAI,eAAe,qBAC9D,MAAM,IAAIH,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,qBAAqB;EACvB,IAAI,IAAI,eAAe,qBACrB,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,CAAC,sBAAsB,QAAQ,cAAc,GAC/C,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAC3B,SACE,6IACJ,CAAC;AAEL"}
|
|
1
|
+
{"version":3,"file":"utils-BXEJ6FZC.cjs","names":["authEE","HTTPException","isReservedRequestContextKey","MASTRA_RESOURCE_ID_KEY","MastraMemory"],"sources":["../src/server/fga-permissions.ts","../src/server/handlers/utils.ts"],"sourcesContent":["/**\n * Safe re-export of `MastraFGAPermissions` from `@mastra/core/auth/ee`.\n *\n * Why this shim exists:\n * `MastraFGAPermissions` was introduced in `@mastra/core@1.32.0`. Earlier\n * versions of `@mastra/core` ship `@mastra/core/auth/ee` but do not export\n * this constant. A direct named import (`import { MastraFGAPermissions }\n * from '@mastra/core/auth/ee'`) fails at ESM link time when this version\n * of `@mastra/server` is paired with `@mastra/core < 1.32.0`, taking the\n * entire user bundle down before any code runs.\n *\n * A namespace import tolerates missing names — `ns.MissingExport` is just\n * `undefined`, no link-time error. We then expose the permission map.\n *\n * Fallback values:\n * If the consuming `@mastra/core` does not export `MastraFGAPermissions`,\n * we substitute a hardcoded map of the canonical permission strings used\n * by routes in `@mastra/server`. This preserves the explicit RBAC\n * permission overrides those routes already had as string literals in\n * `@mastra/server@1.31.0` (e.g. `requiresPermission: \"agents:execute\"`\n * on `/v1/responses`). Without this fallback, `requiresPermission` would\n * be `undefined` on old core and the auth layer would derive the wrong\n * permission from the route path (e.g. `v1:write` instead of\n * `agents:execute`), breaking RBAC users who upgrade `@mastra/server`\n * but stay on `@mastra/core@1.31.0`.\n *\n * Once the consuming `@mastra/core` is on `1.32.0+` the values are real\n * and behaviour is identical to a direct named import.\n */\n\nimport * as authEE from '@mastra/core/auth/ee';\n\n// Canonical strings for the FGA permission keys actually referenced by\n// `@mastra/server` source. Mirrors `MastraFGAPermissions` in\n// `@mastra/core@1.32.0+` for these specific keys, and matches the string\n// literals previously hardcoded on the same routes in `@mastra/server@1.31.0`.\nconst FALLBACK_PERMISSIONS = {\n AGENTS_CREATE: 'agents:create',\n AGENTS_DELETE: 'agents:delete',\n AGENTS_EXECUTE: 'agents:execute',\n AGENTS_READ: 'agents:read',\n KNOWLEDGE_READ: 'knowledge:read',\n MEMORY_DELETE: 'memory:delete',\n MEMORY_READ: 'memory:read',\n MEMORY_WRITE: 'memory:write',\n TOOLS_EXECUTE: 'tools:execute',\n TOOLS_READ: 'tools:read',\n STORED_WORKFLOWS_READ: 'stored-workflows:read',\n STORED_WORKFLOWS_WRITE: 'stored-workflows:write',\n WORKFLOWS_EXECUTE: 'workflows:execute',\n WORKFLOWS_READ: 'workflows:read',\n} as const;\n\nconst realPermissions = (authEE as any).MastraFGAPermissions;\n\n// Typed as `any` on purpose: consumers of `@mastra/server` may run their\n// typecheck against a `@mastra/core` that doesn't export `MastraFGAPermissions`\n// (anything < 1.32.0). Pinning to the real type would push that name into the\n// emitted `.d.ts` and break downstream typecheck. `any` lets the property\n// accesses (`MastraFGAPermissions.AGENTS_READ`) flow through cleanly on every\n// supported core.\nexport const MastraFGAPermissions: any =\n // Merge so a core that exports the map without a newer key (older than this PR) still resolves it.\n { ...FALLBACK_PERMISSIONS, ...(realPermissions ?? {}) };\n","import type { Mastra } from '@mastra/core';\nimport type { IFGAProvider, MastraFGAPermissionInput } from '@mastra/core/auth/ee';\nimport type { RequestContext } from '@mastra/core/di';\nimport { MastraMemory } from '@mastra/core/memory';\nimport type { Workflow } from '@mastra/core/workflows';\nimport {\n MASTRA_AUTH_MODE_KEY,\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n isReservedRequestContextKey,\n} from '../constants';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\n\n/**\n * Resolves a workflow by id or registration key from the set Mastra exposes\n * publicly. Unlike `mastra.getWorkflowById`, this excludes hidden internal\n * workflows (e.g. a durable agent's backing loop), which must never be\n * runnable through HTTP routes.\n */\nexport function getPublicWorkflowById(mastra: Mastra, workflowId: string): Workflow | undefined {\n const workflows = mastra.listWorkflows();\n return (\n Object.values(workflows).find(workflow => workflow.id === workflowId) ??\n (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : undefined)\n );\n}\n\n/**\n * Resolves the FGA provider a handler should use for this request, following\n * the same auth-mode-aware selection as the route-level checks: Studio auth\n * requests use `studio.fga` when it is configured, and everything else uses\n * `server.fga`.\n *\n * Returns `undefined` when FGA is not configured at all. When FGA is\n * configured but no provider applies to this request (for example `studio.fga`\n * is set and the request used server auth), the request is denied rather than\n * treated as unrestricted.\n */\nexport function getHandlerFGAProvider(mastra: any, requestContext?: RequestContext): IFGAProvider | undefined {\n const studioFga = mastra?.getStudio?.()?.fga as IFGAProvider | undefined;\n const serverFga = mastra?.getServer?.()?.fga as IFGAProvider | undefined;\n\n if (requestContext?.get(MASTRA_AUTH_MODE_KEY) === 'studio' && studioFga) return studioFga;\n if (serverFga) return serverFga;\n if (studioFga) {\n throw new HTTPException(403, { message: 'Access denied: no FGA provider is configured for this request' });\n }\n return undefined;\n}\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n if (!value) {\n acc[key] = `Argument \"${key}\" is required`;\n }\n return acc;\n }, {});\n\n if (Object.keys(errorResponse).length > 0) {\n throw new HTTPException(400, { message: Object.values(errorResponse)[0] });\n }\n}\n\n/**\n * sanitizes the body by removing disallowed keys.\n * @param body body to sanitize\n * @param disallowedKeys keys to remove from the body\n */\nexport function sanitizeBody(body: Record<string, unknown>, disallowedKeys: string[]) {\n for (const key of disallowedKeys) {\n if (key in body) {\n delete body[key];\n }\n }\n}\n\nconst CREDENTIAL_HEADER_NAMES = new Set([\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'api-key',\n 'x-goog-api-key',\n 'cookie',\n]);\n\n/**\n * Removes credential-bearing headers from client-supplied `modelSettings.headers`\n * so a caller's own auth (e.g. the app's bearer token) can never override the\n * provider credential configured on the server. Non-credential headers are kept.\n */\nexport function stripClientCredentialHeaders(body: Record<string, unknown>) {\n const modelSettings = body.modelSettings;\n if (!modelSettings || typeof modelSettings !== 'object') return;\n const headers = (modelSettings as { headers?: unknown }).headers;\n if (!headers || typeof headers !== 'object') return;\n\n const kept = Object.fromEntries(\n Object.entries(headers).filter(([name]) => !CREDENTIAL_HEADER_NAMES.has(name.toLowerCase())),\n );\n body.modelSettings = { ...modelSettings, headers: kept };\n}\n\nexport function parsePerPage(\n value: string | undefined,\n defaultValue: number = 100,\n max: number = 1000,\n): number | false {\n const normalized = (value || '').trim().toLowerCase();\n // Handle explicit false to bypass pagination\n if (normalized === 'false') {\n return false;\n }\n const parsed = parseInt(value || String(defaultValue), 10);\n if (isNaN(parsed)) return defaultValue;\n return Math.min(max, Math.max(1, parsed));\n}\n\n/**\n * Parses filter query parameters into a key-value object.\n */\nexport function parseFilters(filters: string | string[] | undefined): Record<string, string> | undefined {\n if (!filters) return undefined;\n\n return Object.fromEntries(\n (Array.isArray(filters) ? filters : [filters]).map((attr: string) => {\n const [key, ...valueParts] = attr.split(':');\n const value = valueParts.join(':'); // ✅ Handles colons in values\n return [key, value];\n }),\n );\n}\n\n/**\n * Merges a body-supplied requestContext into the trusted server RequestContext.\n * The server context is authoritative: reserved keys are skipped and body values\n * only fill keys the server context has not already set.\n */\nexport function mergeBodyRequestContext(serverRequestContext: RequestContext, bodyRequestContext: unknown): void {\n if (!bodyRequestContext || typeof bodyRequestContext !== 'object') {\n return;\n }\n\n for (const [key, value] of Object.entries(bodyRequestContext)) {\n if (isReservedRequestContextKey(key)) continue;\n if (serverRequestContext.get(key) === undefined) {\n serverRequestContext.set(key, value);\n }\n }\n}\n\n// ============================================================================\n// Authorization Utilities\n// ============================================================================\n\n/**\n * Gets the effective resourceId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveResourceId(\n requestContext: RequestContext | undefined,\n clientResourceId: string | undefined,\n): string | undefined {\n const contextResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n return contextResourceId || clientResourceId;\n}\n\n/**\n * Returns the resource id resolved from the request context alone (set via\n * `mapUserToResourceId` or the `x-resource-id` header), ignoring any\n * client-provided value. Its presence indicates a resource-scoped caller;\n * its absence indicates a privileged/service context.\n */\nexport function getContextResourceId(requestContext: RequestContext | undefined): string | undefined {\n return requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n}\n\n/**\n * Ensures a memory request has a resolvable resource ID. The body's\n * `memory.resource` is optional so authenticated setups can rely on the\n * server-derived resource ID (MASTRA_RESOURCE_ID_KEY set via mapUserToResourceId).\n * When neither the body nor the request context provides one, reject with a\n * clear 400 instead of failing deep inside agent execution.\n */\nexport function requireEffectiveResourceId(\n effectiveResourceId: string | undefined,\n): asserts effectiveResourceId is string {\n if (!effectiveResourceId) {\n throw new HTTPException(400, {\n message:\n 'A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.',\n });\n }\n}\n\n/**\n * Gets the effective threadId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveThreadId(\n requestContext: RequestContext | undefined,\n clientThreadId: string | undefined,\n): string | undefined {\n const contextThreadId = requestContext?.get(MASTRA_THREAD_ID_KEY) as string | undefined;\n return contextThreadId || clientThreadId;\n}\n\n/**\n * Applies the effective threadId to a client memory thread option. Object\n * threads keep their other fields (metadata, title, ...) so they reach thread\n * creation; a client-supplied resourceId is dropped because the server decides\n * the resource.\n */\nexport function applyEffectiveThreadId<T extends string | { id: string } | undefined>(\n thread: T,\n effectiveThreadId: string | undefined,\n): T | string {\n if (!effectiveThreadId) return thread;\n if (thread && typeof thread === 'object') {\n const { resourceId: _resourceId, ...fields } = thread as { id: string; resourceId?: unknown };\n return { ...fields, id: effectiveThreadId } as T;\n }\n return effectiveThreadId;\n}\n\n/**\n * Validates that a thread belongs to the specified resourceId.\n * Throws 403 if the thread exists but belongs to a different resource.\n * Threads with no resourceId are accessible to all (shared threads).\n */\nexport async function validateThreadOwnership(\n thread: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n): Promise<void> {\n if (thread && effectiveResourceId && thread.resourceId && thread.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: thread belongs to a different resource' });\n }\n}\n\n/**\n * Validates both coarse resource ownership and fine-grained thread access.\n * FGA enforcement is a no-op when no FGA provider is configured.\n */\nexport async function enforceThreadAccess({\n mastra,\n requestContext,\n threadId,\n thread,\n effectiveResourceId,\n permission = MastraFGAPermissions.MEMORY_READ,\n}: {\n mastra: any;\n requestContext?: RequestContext;\n threadId: string;\n thread?: { resourceId?: string | null } | null;\n effectiveResourceId?: string;\n permission?: MastraFGAPermissionInput;\n}): Promise<void> {\n await validateThreadOwnership(thread, effectiveResourceId);\n\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n if (!fgaProvider) {\n return;\n }\n\n const user = requestContext?.get('user');\n if (!user || typeof user !== 'object') {\n throw new HTTPException(403, { message: 'FGA authorization denied: authenticated user is required' });\n }\n\n await MastraMemory.checkThreadFGA({\n mastra,\n user: user as { id: string; [key: string]: unknown },\n threadId,\n resourceId: thread?.resourceId ?? effectiveResourceId,\n requestContext,\n permission,\n fgaProvider,\n });\n}\n\n/**\n * Validates that a caller may act on a workflow run.\n *\n * Without `server.auth.mapUserToResourceId` there is no tenancy model, and only a mismatch\n * between two present resource ids is denied. With a mapper, a resource-scoped caller may only\n * act on runs it owns (an owner-less run is not its run). An unscoped caller is a\n * privileged/service context (see getContextResourceId), but that privilege is only granted when\n * an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,\n * as on the thread-transfer route.\n */\nexport async function validateRunOwnership(\n run: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n mastra?: {\n getServer?: () => { auth?: unknown; fga?: unknown } | undefined;\n getStudio?: () => { fga?: unknown } | undefined;\n },\n requestContext?: RequestContext,\n): Promise<void> {\n if (!run) return;\n const server = mastra?.getServer?.();\n const tenancy =\n typeof (server?.auth as { mapUserToResourceId?: unknown } | undefined)?.mapUserToResourceId === 'function';\n if (!tenancy) {\n if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (effectiveResourceId) {\n if (run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (!getHandlerFGAProvider(mastra, requestContext)) {\n throw new HTTPException(403, {\n message:\n 'Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access.',\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,uBAAuB;CAC3B,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,gBAAgB;CAChB,eAAe;CACf,aAAa;CACb,cAAc;CACd,eAAe;CACf,YAAY;CACZ,uBAAuB;CACvB,wBAAwB;CACxB,mBAAmB;CACnB,gBAAgB;A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AwB,aACpF;EACZ,IAAI,uBAAuB,IAAI,cAAc,IAAI,eAAe,qBAC9D,MAAM,IAAIH,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,qBAAqB;EACvB,IAAI,IAAI,eAAe,qBACrB,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,CAAC,sBAAsB,QAAQ,cAAc,GAC/C,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAC3B,SACE,6IACJ,CAAC;AAEL"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_schema_Bf12g7KC = require("./schema-Bf12g7KC-plP4Ir6h.cjs");
|
|
1
|
+
const require_schema_Bf12g7KC = require("./schema-Bf12g7KC-C5XzpQxe.cjs");
|
|
3
2
|
const require_constants = require("./constants-DMg8hUOR.cjs");
|
|
3
|
+
const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
4
4
|
// ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/superjson/2.2.6/711cee35fda0e5a37276180e7a2ecc71bd8bb1528c27c34fa53791b52a3c4054/node_modules/superjson/dist/double-indexed-kv.js
|
|
5
5
|
var DoubleIndexedKV = class {
|
|
6
6
|
constructor() {
|
|
@@ -1002,4 +1002,4 @@ Object.defineProperty(exports, "toSlug", {
|
|
|
1002
1002
|
}
|
|
1003
1003
|
});
|
|
1004
1004
|
|
|
1005
|
-
//# sourceMappingURL=utils-
|
|
1005
|
+
//# sourceMappingURL=utils-CL-m2SWZ.cjs.map
|