@mastra/server 1.81.0-alpha.2 → 1.82.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/{a2a-eUB3oDRN.cjs → a2a-CIq9dtbC.cjs} +3 -3
- package/dist/{a2a-eUB3oDRN.cjs.map → a2a-CIq9dtbC.cjs.map} +1 -1
- package/dist/{a2a-UYs7rzN2.js → a2a-DULF2hBd.js} +3 -3
- package/dist/{a2a-UYs7rzN2.js.map → a2a-DULF2hBd.js.map} +1 -1
- package/dist/{agent-builder-DwfHzUnt.cjs → agent-builder-CX7Rgay-.cjs} +4 -4
- package/dist/{agent-builder-DwfHzUnt.cjs.map → agent-builder-CX7Rgay-.cjs.map} +1 -1
- package/dist/{agent-builder-5dpawFJf.js → agent-builder-C_H7OUVX.js} +4 -4
- package/dist/{agent-builder-5dpawFJf.js.map → agent-builder-C_H7OUVX.js.map} +1 -1
- package/dist/{agents-BuI0JjjX.js → agents-NRBk4JAs.js} +4 -4
- package/dist/{agents-BuI0JjjX.js.map → agents-NRBk4JAs.js.map} +1 -1
- package/dist/{agents-BjdRPzyV.cjs → agents-SvkxJW48.cjs} +4 -4
- package/dist/{agents-BjdRPzyV.cjs.map → agents-SvkxJW48.cjs.map} +1 -1
- package/dist/{api-schema-manifest-GgyfF4dw.cjs → api-schema-manifest-BMJwl8fK.cjs} +2 -2
- package/dist/{api-schema-manifest-GgyfF4dw.cjs.map → api-schema-manifest-BMJwl8fK.cjs.map} +1 -1
- package/dist/{api-schema-manifest-DafznVYs.js → api-schema-manifest-CEMyoduN.js} +2 -2
- package/dist/{api-schema-manifest-DafznVYs.js.map → api-schema-manifest-CEMyoduN.js.map} +1 -1
- package/dist/{background-tasks-BkYNmUcf.js → background-tasks-DhQ6upHK.js} +2 -2
- package/dist/{background-tasks-BkYNmUcf.js.map → background-tasks-DhQ6upHK.js.map} +1 -1
- package/dist/{background-tasks-Civclnuq.cjs → background-tasks-Kcx2YtW0.cjs} +2 -2
- package/dist/{background-tasks-Civclnuq.cjs.map → background-tasks-Kcx2YtW0.cjs.map} +1 -1
- package/dist/{builder-registry-DHVK50Ba.js → builder-registry-6TFaV4oT.js} +2 -2
- package/dist/{builder-registry-DHVK50Ba.js.map → builder-registry-6TFaV4oT.js.map} +1 -1
- package/dist/{builder-registry-CamBJItc.cjs → builder-registry-CkPRx_vx.cjs} +2 -2
- package/dist/{builder-registry-CamBJItc.cjs.map → builder-registry-CkPRx_vx.cjs.map} +1 -1
- package/dist/{channels-EqvuQQbv.cjs → channels-Bfkp5vYI.cjs} +2 -2
- package/dist/{channels-EqvuQQbv.cjs.map → channels-Bfkp5vYI.cjs.map} +1 -1
- package/dist/{channels-LNR2QIkc.js → channels-hhQ3vD30.js} +2 -2
- package/dist/{channels-LNR2QIkc.js.map → channels-hhQ3vD30.js.map} +1 -1
- package/dist/{constants-ohUUT3Vg.js → constants-CXAvBYcz.js} +9 -2
- package/dist/constants-CXAvBYcz.js.map +1 -0
- package/dist/{constants-Co1XjPjd.cjs → constants-DMg8hUOR.cjs} +14 -1
- package/dist/constants-DMg8hUOR.cjs.map +1 -0
- package/dist/{conversations-fdXV9K0J.js → conversations-CVvZOu1K.js} +3 -3
- package/dist/{conversations-fdXV9K0J.js.map → conversations-CVvZOu1K.js.map} +1 -1
- package/dist/{conversations-ORTpTqBg.cjs → conversations-Ds6aiCMU.cjs} +3 -3
- package/dist/{conversations-ORTpTqBg.cjs.map → conversations-Ds6aiCMU.cjs.map} +1 -1
- package/dist/{dist-BEtxPxkM.cjs → dist-4RWkx1DC.cjs} +1 -1
- package/dist/dist-BOLBpPgs.js +1 -0
- package/dist/{dist-CR3PolEz.cjs → dist-CRO6e62N.cjs} +583 -3539
- package/dist/dist-CRO6e62N.cjs.map +1 -0
- package/dist/{dist-CmG4sN60.js → dist-DwXaR0sc.js} +585 -3541
- package/dist/dist-DwXaR0sc.js.map +1 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-studio-knowledge.md +81 -0
- package/dist/{editor-builder-DxGZ7IN5.js → editor-builder-BG38irXi.js} +2 -2
- package/dist/{editor-builder-DxGZ7IN5.js.map → editor-builder-BG38irXi.js.map} +1 -1
- package/dist/{editor-builder-6l27BFzD.cjs → editor-builder-CcSeAW18.cjs} +2 -2
- package/dist/{editor-builder-6l27BFzD.cjs.map → editor-builder-CcSeAW18.cjs.map} +1 -1
- package/dist/{helpers-CE1fJdLM.cjs → helpers-BKtUXhz2.cjs} +26 -3
- package/dist/helpers-BKtUXhz2.cjs.map +1 -0
- package/dist/{helpers-CMCXsowL.js → helpers-DNq3LtLq.js} +26 -3
- package/dist/helpers-DNq3LtLq.js.map +1 -0
- package/dist/knowledge-DykIi0wH.js +431 -0
- package/dist/knowledge-DykIi0wH.js.map +1 -0
- package/dist/knowledge-qu0om3W7.cjs +474 -0
- package/dist/knowledge-qu0om3W7.cjs.map +1 -0
- package/dist/{logs-BbaBP2LD.js → logs-B57_NKDn.js} +2 -2
- package/dist/{logs-BbaBP2LD.js.map → logs-B57_NKDn.js.map} +1 -1
- package/dist/{logs-DI-h9uHR.cjs → logs-BJN3M88A.cjs} +2 -2
- package/dist/{logs-DI-h9uHR.cjs.map → logs-BJN3M88A.cjs.map} +1 -1
- package/dist/{mcp-CMw0sq0y.cjs → mcp-B9BILfJP.cjs} +2 -2
- package/dist/{mcp-CMw0sq0y.cjs.map → mcp-B9BILfJP.cjs.map} +1 -1
- package/dist/{mcp-DN9mT9q4.js → mcp-BkmWZD6M.js} +2 -2
- package/dist/{mcp-DN9mT9q4.js.map → mcp-BkmWZD6M.js.map} +1 -1
- package/dist/{memory-Buhi6kZ-.cjs → memory-Dqod_AK9.cjs} +2 -2
- package/dist/{memory-Buhi6kZ-.cjs.map → memory-Dqod_AK9.cjs.map} +1 -1
- package/dist/{memory-BTR95ujT.js → memory-ipOCmg0C.js} +2 -2
- package/dist/{memory-BTR95ujT.js.map → memory-ipOCmg0C.js.map} +1 -1
- package/dist/{observability-pX3wmG8T.js → observability-CbJDt-WY.js} +2 -2
- package/dist/{observability-pX3wmG8T.js.map → observability-CbJDt-WY.js.map} +1 -1
- package/dist/{observability-new-endpoints-BrB2CKix.cjs → observability-new-endpoints-7KCQHib3.cjs} +2 -2
- package/dist/{observability-new-endpoints-BrB2CKix.cjs.map → observability-new-endpoints-7KCQHib3.cjs.map} +1 -1
- package/dist/{observability-new-endpoints-CQNVjYYq.js → observability-new-endpoints-DrDPcAjm.js} +2 -2
- package/dist/{observability-new-endpoints-CQNVjYYq.js.map → observability-new-endpoints-DrDPcAjm.js.map} +1 -1
- package/dist/{observability-DRbDeN1X.cjs → observability-wSQo-vXB.cjs} +2 -2
- package/dist/{observability-DRbDeN1X.cjs.map → observability-wSQo-vXB.cjs.map} +1 -1
- package/dist/{plans-D9BGMVkL.js → plans-BRf1-Sch.js} +3 -3
- package/dist/{plans-D9BGMVkL.js.map → plans-BRf1-Sch.js.map} +1 -1
- package/dist/{plans-BHQFsFRU.cjs → plans-Cq23qQ48.cjs} +3 -3
- package/dist/{plans-BHQFsFRU.cjs.map → plans-Cq23qQ48.cjs.map} +1 -1
- package/dist/{probe-image-size-BjNoJxWf.js → probe-image-size-BGSAADKy.js} +2 -2
- package/dist/{probe-image-size-BjNoJxWf.js.map → probe-image-size-BGSAADKy.js.map} +1 -1
- package/dist/{probe-image-size-jS0ECSlc.cjs → probe-image-size-CsYWL1Gs.cjs} +2 -2
- package/dist/{probe-image-size-jS0ECSlc.cjs.map → probe-image-size-CsYWL1Gs.cjs.map} +1 -1
- package/dist/{responses-Cb-9JV9A.js → responses-CGy87E_N.js} +3 -3
- package/dist/{responses-Cb-9JV9A.js.map → responses-CGy87E_N.js.map} +1 -1
- package/dist/{responses-4_RCBNJB.cjs → responses-CPTdr5VE.cjs} +3 -3
- package/dist/{responses-4_RCBNJB.cjs.map → responses-CPTdr5VE.cjs.map} +1 -1
- package/dist/{routes-BqWcvAcz.cjs → routes-BCpGBudO.cjs} +79 -22
- package/dist/routes-BCpGBudO.cjs.map +1 -0
- package/dist/{routes-4X2kSYEG.js → routes-DZgJrVh5.js} +62 -23
- package/dist/routes-DZgJrVh5.js.map +1 -0
- package/dist/{schedules-CQPodXrR.js → schedules-CGViSLZC.js} +2 -2
- package/dist/{schedules-CQPodXrR.js.map → schedules-CGViSLZC.js.map} +1 -1
- package/dist/{schedules-CL4IU7kS.cjs → schedules-D8ShgpY3.cjs} +2 -2
- package/dist/{schedules-CL4IU7kS.cjs.map → schedules-D8ShgpY3.cjs.map} +1 -1
- package/dist/{scores-DnEcBe2i.cjs → scores-BZ0Iz_0O.cjs} +2 -2
- package/dist/{scores-DnEcBe2i.cjs.map → scores-BZ0Iz_0O.cjs.map} +1 -1
- package/dist/{scores-DqImg-o-.js → scores-DqSDYRs0.js} +2 -2
- package/dist/{scores-DqImg-o-.js.map → scores-DqSDYRs0.js.map} +1 -1
- package/dist/server/auth/helpers.d.ts.map +1 -1
- package/dist/server/auth/index.cjs +2 -2
- package/dist/server/auth/index.js +2 -2
- package/dist/server/constants.d.ts +7 -1
- package/dist/server/constants.d.ts.map +1 -1
- package/dist/server/fga-permissions.d.ts.map +1 -1
- 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 +2 -2
- package/dist/server/handlers/agent-controller.js +2 -2
- package/dist/server/handlers/agent-versions.cjs +1 -1
- package/dist/server/handlers/agent-versions.js +1 -1
- package/dist/server/handlers/agents.cjs +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/auth.cjs +2 -2
- package/dist/server/handlers/auth.js +2 -2
- 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 +1 -1
- package/dist/server/handlers/datasets.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/knowledge.cjs +10 -0
- package/dist/server/handlers/knowledge.d.ts +237 -0
- package/dist/server/handlers/knowledge.d.ts.map +1 -0
- package/dist/server/handlers/knowledge.js +1 -0
- package/dist/server/handlers/logs.cjs +1 -1
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/mcp-client-versions.cjs +1 -1
- package/dist/server/handlers/mcp-client-versions.js +1 -1
- 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.js +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
- package/dist/server/handlers/observability-new-endpoints.js +1 -1
- 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/prompt-block-versions.cjs +1 -1
- package/dist/server/handlers/prompt-block-versions.js +1 -1
- 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 +1 -1
- package/dist/server/handlers/scorer-versions.js +1 -1
- package/dist/server/handlers/scores.cjs +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +2 -2
- package/dist/server/handlers/stored-agent-favorites.js +2 -2
- package/dist/server/handlers/stored-agents.cjs +2 -2
- package/dist/server/handlers/stored-agents.js +2 -2
- package/dist/server/handlers/stored-mcp-clients.cjs +1 -1
- package/dist/server/handlers/stored-mcp-clients.js +1 -1
- package/dist/server/handlers/stored-prompt-blocks.cjs +1 -1
- package/dist/server/handlers/stored-prompt-blocks.js +1 -1
- package/dist/server/handlers/stored-scorers.cjs +1 -1
- package/dist/server/handlers/stored-scorers.js +1 -1
- package/dist/server/handlers/stored-skill-favorites.cjs +2 -2
- package/dist/server/handlers/stored-skill-favorites.js +2 -2
- package/dist/server/handlers/stored-skills.cjs +2 -2
- package/dist/server/handlers/stored-skills.js +2 -2
- package/dist/server/handlers/stored-workspaces.cjs +1 -1
- package/dist/server/handlers/stored-workspaces.js +1 -1
- package/dist/server/handlers/system.cjs +1 -1
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers/tool-providers.cjs +1 -1
- package/dist/server/handlers/tool-providers.js +1 -1
- 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/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.js +1 -1
- package/dist/server/handlers/workspace.d.ts +23 -23
- package/dist/server/handlers.cjs +13 -13
- package/dist/server/handlers.js +13 -13
- package/dist/server/schemas/knowledge.d.ts +58 -0
- package/dist/server/schemas/knowledge.d.ts.map +1 -0
- package/dist/server/server-adapter/index.cjs +21 -6
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.d.ts +1 -1
- package/dist/server/server-adapter/index.d.ts.map +1 -1
- package/dist/server/server-adapter/index.js +18 -7
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/server/server-adapter/routes/fga-manifest.d.ts.map +1 -1
- package/dist/server/server-adapter/routes/index.d.ts +29 -0
- package/dist/server/server-adapter/routes/index.d.ts.map +1 -1
- package/dist/server/server-adapter/routes/knowledge.d.ts +231 -0
- package/dist/server/server-adapter/routes/knowledge.d.ts.map +1 -0
- package/dist/{tools-BFpuzQsz.js → tools-CtELrYsA.js} +4 -4
- package/dist/{tools-BFpuzQsz.js.map → tools-CtELrYsA.js.map} +1 -1
- package/dist/{tools-Dy_j6URC.cjs → tools-DtRHH9Hr.cjs} +4 -4
- package/dist/{tools-Dy_j6URC.cjs.map → tools-DtRHH9Hr.cjs.map} +1 -1
- package/dist/{utils-BbYUI6Yn.cjs → utils-9PRHHTGC.cjs} +7 -3
- package/dist/utils-9PRHHTGC.cjs.map +1 -0
- package/dist/{utils-DHxjw4Tn.js → utils-B15w-1hm.js} +7 -3
- package/dist/utils-B15w-1hm.js.map +1 -0
- package/dist/{utils-BnH77wPf.cjs → utils-bQ6Jhog6.cjs} +2 -2
- package/dist/{utils-BnH77wPf.cjs.map → utils-bQ6Jhog6.cjs.map} +1 -1
- package/dist/{utils-YEuwVEc2.js → utils-qaBKOShQ.js} +2 -2
- package/dist/{utils-YEuwVEc2.js.map → utils-qaBKOShQ.js.map} +1 -1
- package/dist/{workflow-builder--W9PMW13.js → workflow-builder-6I2HiKcF.js} +2 -2
- package/dist/{workflow-builder--W9PMW13.js.map → workflow-builder-6I2HiKcF.js.map} +1 -1
- package/dist/{workflow-builder-CT7JOoW6.cjs → workflow-builder-CQzvZvwC.cjs} +2 -2
- package/dist/{workflow-builder-CT7JOoW6.cjs.map → workflow-builder-CQzvZvwC.cjs.map} +1 -1
- package/dist/{workflows-DPIRVRN9.js → workflows-ClfVyB1p.js} +3 -3
- package/dist/{workflows-DPIRVRN9.js.map → workflows-ClfVyB1p.js.map} +1 -1
- package/dist/{workflows-BAOfWBkr.cjs → workflows-DgSo-eBG.cjs} +3 -3
- package/dist/{workflows-BAOfWBkr.cjs.map → workflows-DgSo-eBG.cjs.map} +1 -1
- package/package.json +9 -9
- package/dist/constants-Co1XjPjd.cjs.map +0 -1
- package/dist/constants-ohUUT3Vg.js.map +0 -1
- package/dist/dist-BQ1uFC_1.js +0 -1
- package/dist/dist-CR3PolEz.cjs.map +0 -1
- package/dist/dist-CmG4sN60.js.map +0 -1
- package/dist/helpers-CE1fJdLM.cjs.map +0 -1
- package/dist/helpers-CMCXsowL.js.map +0 -1
- package/dist/routes-4X2kSYEG.js.map +0 -1
- package/dist/routes-BqWcvAcz.cjs.map +0 -1
- package/dist/utils-BbYUI6Yn.cjs.map +0 -1
- package/dist/utils-DHxjw4Tn.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-EqvuQQbv.cjs","names":["z","coreFeatures","HTTPException","getCallerAuthorId","hasAdminBypass","hasScopedPermission","createRoute","handleError"],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n\nexport const reconcileChannelResponseSchema = channelInstallationInfoSchema\n .nullable()\n .describe('The reconciled installation, or null when the agent has none (or the platform does not reconcile)');\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n reconcileChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\n/**\n * Resolves the current channel providers. Prefers `resolveChannels()` so a\n * live resolver (e.g. `channels()` from @mastra/connect) is consulted —\n * connections added after boot are picked up without a restart. Falls back to\n * the static snapshot on older @mastra/core versions without the method.\n */\nasync function resolveChannelProviders(mastra: Mastra): Promise<ChannelProvider[]> {\n const resolveChannels = (mastra as Mastra & { resolveChannels?: () => Promise<Record<string, ChannelProvider>> })\n .resolveChannels;\n const record = typeof resolveChannels === 'function' ? await resolveChannels.call(mastra) : (mastra.channels ?? {});\n return Object.values(record);\n}\n\nasync function getChannelOrThrow(mastra: Mastra, platform: string): Promise<ChannelProvider> {\n const channels = await resolveChannelProviders(mastra);\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = await resolveChannelProviders(mastra);\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/reconcile - Reconcile an agent's installation\n *\n * The explicit write path for connect flows that complete out-of-band (e.g.\n * Discord's bot invite has no redirect back to the server). Listing stays a\n * pure read; Studio calls this on window focus while a connect is in flight.\n * Gated on the same write access as connect — reconciliation can activate the\n * agent's installation.\n */\nexport const RECONCILE_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/reconcile',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: reconcileChannelResponseSchema,\n summary: 'Reconcile channel installation',\n description:\n 'Checks a pending installation against platform state and activates it if its connect flow has completed. Returns the installation, or null when the agent has none or the platform does not support reconciliation.',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n // Resolve the agent (404 on unknown) and authorize the write before the\n // capability check so unknown agents never read as a successful no-op.\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n if (!channel.reconcileInstallation) {\n return null;\n }\n\n return await channel.reconcileInstallation(agentId);\n } catch (error) {\n return handleError(error, 'Error reconciling channel installation');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4BA,OAAAA,EAAE,OAAO,EAChD,UAAUA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyBA,OAAAA,EAAE,OAAO;CAC7C,UAAUA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAASA,OAAAA,EAAE,OAAO,CAAC,C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bfkp5vYI.cjs","names":["z","coreFeatures","HTTPException","getCallerAuthorId","hasAdminBypass","hasScopedPermission","createRoute","handleError"],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n\nexport const reconcileChannelResponseSchema = channelInstallationInfoSchema\n .nullable()\n .describe('The reconciled installation, or null when the agent has none (or the platform does not reconcile)');\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n reconcileChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\n/**\n * Resolves the current channel providers. Prefers `resolveChannels()` so a\n * live resolver (e.g. `channels()` from @mastra/connect) is consulted —\n * connections added after boot are picked up without a restart. Falls back to\n * the static snapshot on older @mastra/core versions without the method.\n */\nasync function resolveChannelProviders(mastra: Mastra): Promise<ChannelProvider[]> {\n const resolveChannels = (mastra as Mastra & { resolveChannels?: () => Promise<Record<string, ChannelProvider>> })\n .resolveChannels;\n const record = typeof resolveChannels === 'function' ? await resolveChannels.call(mastra) : (mastra.channels ?? {});\n return Object.values(record);\n}\n\nasync function getChannelOrThrow(mastra: Mastra, platform: string): Promise<ChannelProvider> {\n const channels = await resolveChannelProviders(mastra);\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = await resolveChannelProviders(mastra);\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/reconcile - Reconcile an agent's installation\n *\n * The explicit write path for connect flows that complete out-of-band (e.g.\n * Discord's bot invite has no redirect back to the server). Listing stays a\n * pure read; Studio calls this on window focus while a connect is in flight.\n * Gated on the same write access as connect — reconciliation can activate the\n * agent's installation.\n */\nexport const RECONCILE_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/reconcile',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: reconcileChannelResponseSchema,\n summary: 'Reconcile channel installation',\n description:\n 'Checks a pending installation against platform state and activates it if its connect flow has completed. Returns the installation, or null when the agent has none or the platform does not support reconciliation.',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n // Resolve the agent (404 on unknown) and authorize the write before the\n // capability check so unknown agents never read as a successful no-op.\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n if (!channel.reconcileInstallation) {\n return null;\n }\n\n return await channel.reconcileInstallation(agentId);\n } catch (error) {\n return handleError(error, 'Error reconciling channel installation');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4BA,OAAAA,EAAE,OAAO,EAChD,UAAUA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyBA,OAAAA,EAAE,OAAO;CAC7C,UAAUA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAASA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB;AACjD,CAAC;AAMD,MAAa,2BAA2BA,OAAAA,EAAE,OAAO;CAC/C,SAASA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,6BAA6B;CAC1D,SAASA,OAAAA,EAAE,OAAOA,OAAAA,EAAE,OAAO,GAAGA,OAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,sCAAsC;AACvG,CAAC;AAMD,MAAM,4BAA4BA,OAAAA,EAAE,OAAO;CACzC,IAAIA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,qBAAqB;CAC7C,MAAMA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;CACxD,cAAcA,OAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,iDAAiD;CACpF,sBAAsBA,OAAAA,EAAE,OAAOA,OAAAA,EAAE,OAAO,GAAGA,OAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC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CAAwC;EACpE;CACF;AACF,CAAC;;;;AAKD,MAAa,2BAA2BD,sBAAAA,YAAY;CAClD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,UAAU;CACjB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,gBAAgB,UAAU,cAAc;EAChE,wBAAwB;EACxB,IAAI;GACF,MAAM,UAAU,MAAM,kBAAkB,QAAQ,QAAQ;GAExD,IAAI,CAAC,QAAQ,YACX,MAAM,IAAIJ,uBAAAA,cAAc,KAAK,EAC3B,SAAS,YAAY,SAAS,+CAChC,CAAC;GAGH,MAAM,8BAA8B,QAAQ,gBAAgB,SAAS,YAAY;GAEjF,MAAM,QAAQ,WAAW,OAAO;GAChC,OAAO,EAAE,SAAS,KAAK;EACzB,SAAS,OAAO;GACd,OAAOK,8BAAAA,YAAY,OAAO,wCAAwC;EACpE;CACF;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as HTTPException } from "./http-exception-CzaWkxMl.js";
|
|
2
2
|
import { n as createRoute } from "./route-builder-BxPrwNog.js";
|
|
3
|
-
import "./constants-
|
|
3
|
+
import "./constants-CXAvBYcz.js";
|
|
4
4
|
import { handleError } from "./server/handlers/error.js";
|
|
5
5
|
import { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from "./server/handlers/authorship.js";
|
|
6
6
|
import { z } from "zod/v4";
|
|
@@ -248,4 +248,4 @@ const DISCONNECT_CHANNEL_ROUTE = createRoute({
|
|
|
248
248
|
});
|
|
249
249
|
export { RECONCILE_CHANNEL_ROUTE as a, LIST_CHANNEL_PLATFORMS_ROUTE as i, DISCONNECT_CHANNEL_ROUTE as n, LIST_CHANNEL_INSTALLATIONS_ROUTE as r, CONNECT_CHANNEL_ROUTE as t };
|
|
250
250
|
|
|
251
|
-
//# sourceMappingURL=channels-
|
|
251
|
+
//# sourceMappingURL=channels-hhQ3vD30.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channels-LNR2QIkc.js","names":[],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n\nexport const reconcileChannelResponseSchema = channelInstallationInfoSchema\n .nullable()\n .describe('The reconciled installation, or null when the agent has none (or the platform does not reconcile)');\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n reconcileChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\n/**\n * Resolves the current channel providers. Prefers `resolveChannels()` so a\n * live resolver (e.g. `channels()` from @mastra/connect) is consulted —\n * connections added after boot are picked up without a restart. Falls back to\n * the static snapshot on older @mastra/core versions without the method.\n */\nasync function resolveChannelProviders(mastra: Mastra): Promise<ChannelProvider[]> {\n const resolveChannels = (mastra as Mastra & { resolveChannels?: () => Promise<Record<string, ChannelProvider>> })\n .resolveChannels;\n const record = typeof resolveChannels === 'function' ? await resolveChannels.call(mastra) : (mastra.channels ?? {});\n return Object.values(record);\n}\n\nasync function getChannelOrThrow(mastra: Mastra, platform: string): Promise<ChannelProvider> {\n const channels = await resolveChannelProviders(mastra);\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = await resolveChannelProviders(mastra);\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/reconcile - Reconcile an agent's installation\n *\n * The explicit write path for connect flows that complete out-of-band (e.g.\n * Discord's bot invite has no redirect back to the server). Listing stays a\n * pure read; Studio calls this on window focus while a connect is in flight.\n * Gated on the same write access as connect — reconciliation can activate the\n * agent's installation.\n */\nexport const RECONCILE_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/reconcile',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: reconcileChannelResponseSchema,\n summary: 'Reconcile channel installation',\n description:\n 'Checks a pending installation against platform state and activates it if its connect flow has completed. Returns the installation, or null when the agent has none or the platform does not support reconciliation.',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n // Resolve the agent (404 on unknown) and authorize the write before the\n // capability check so unknown agents never read as a successful no-op.\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n if (!channel.reconcileInstallation) {\n return null;\n }\n\n return await channel.reconcileInstallation(agentId);\n } catch (error) {\n return handleError(error, 'Error reconciling channel installation');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4B,EAAE,OAAO,EAChD,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB;AACjD,CAAC;AAMD,MAAa,2BAA2B,EAAE,OAAO;CAC/C,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,6BAA6B;CAC1D,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,sCAAsC;AACvG,CAAC;AAMD,MAAM,4BAA4B,EAAE,OAAO;CACzC,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,qBAAqB;CAC7C,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;CACxD,cAAc,EAAE,QAAQ,CAAC,CAAC,SAAS,iDAAiD;CACpF,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,iCAAiC;AAC/G,CAAC;AAED,MAAM,gCAAgC,EAAE,OAAO;CAC7C,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,yBAAyB;CACjD,UA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KAAK;EACzB,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,wCAAwC;EACpE;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"channels-hhQ3vD30.js","names":[],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n\nexport const reconcileChannelResponseSchema = channelInstallationInfoSchema\n .nullable()\n .describe('The reconciled installation, or null when the agent has none (or the platform does not reconcile)');\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n reconcileChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\n/**\n * Resolves the current channel providers. Prefers `resolveChannels()` so a\n * live resolver (e.g. `channels()` from @mastra/connect) is consulted —\n * connections added after boot are picked up without a restart. Falls back to\n * the static snapshot on older @mastra/core versions without the method.\n */\nasync function resolveChannelProviders(mastra: Mastra): Promise<ChannelProvider[]> {\n const resolveChannels = (mastra as Mastra & { resolveChannels?: () => Promise<Record<string, ChannelProvider>> })\n .resolveChannels;\n const record = typeof resolveChannels === 'function' ? await resolveChannels.call(mastra) : (mastra.channels ?? {});\n return Object.values(record);\n}\n\nasync function getChannelOrThrow(mastra: Mastra, platform: string): Promise<ChannelProvider> {\n const channels = await resolveChannelProviders(mastra);\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = await resolveChannelProviders(mastra);\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/reconcile - Reconcile an agent's installation\n *\n * The explicit write path for connect flows that complete out-of-band (e.g.\n * Discord's bot invite has no redirect back to the server). Listing stays a\n * pure read; Studio calls this on window focus while a connect is in flight.\n * Gated on the same write access as connect — reconciliation can activate the\n * agent's installation.\n */\nexport const RECONCILE_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/reconcile',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: reconcileChannelResponseSchema,\n summary: 'Reconcile channel installation',\n description:\n 'Checks a pending installation against platform state and activates it if its connect flow has completed. Returns the installation, or null when the agent has none or the platform does not support reconciliation.',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n // Resolve the agent (404 on unknown) and authorize the write before the\n // capability check so unknown agents never read as a successful no-op.\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n if (!channel.reconcileInstallation) {\n return null;\n }\n\n return await channel.reconcileInstallation(agentId);\n } catch (error) {\n return handleError(error, 'Error reconciling channel installation');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = await getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4B,EAAE,OAAO,EAChD,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB;AACjD,CAAC;AAMD,MAAa,2BAA2B,EAAE,OAAO;CAC/C,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,6BAA6B;CAC1D,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,sCAAsC;AACvG,CAAC;AAMD,MAAM,4BAA4B,EAAE,OAAO;CACzC,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,qBAAqB;CAC7C,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;CACxD,cAAc,EAAE,QAAQ,CAAC,CAAC,SAAS,iDAAiD;CACpF,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,iCAAiC;AAC/G,CAAC;AAED,MAAM,gCAAgC,EAAE,OAAO;CAC7C,IAAI,EAAE,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AQ,WAAW,OAAO;GAChC,OAAO,EAAE,SAAS,KAAK;EACzB,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,wCAAwC;EACpE;CACF;AACF,CAAC"}
|
|
@@ -12,6 +12,12 @@ const MASTRA_THREAD_ID_KEY = "mastra__threadId";
|
|
|
12
12
|
* Agent scopes set by trusted middleware. Never accepted from a request body.
|
|
13
13
|
*/
|
|
14
14
|
const MASTRA_SCOPES_KEY = "mastra__scopes";
|
|
15
|
+
/**
|
|
16
|
+
* The Knowledge principals the signed-in caller holds, for the Studio Knowledge routes: a `string[]` of
|
|
17
|
+
* principal addresses, or `'all'` for an admin who may read the whole instance. Set it in
|
|
18
|
+
* `auth.authorize` (after authentication). With auth configured, a caller without it is refused.
|
|
19
|
+
*/
|
|
20
|
+
const MASTRA_KNOWLEDGE_PRINCIPALS_KEY = "mastra__knowledgePrincipals";
|
|
15
21
|
const MASTRA_USER_KEY = "mastra__user";
|
|
16
22
|
const MASTRA_USER_PERMISSIONS_KEY = "mastra__userPermissions";
|
|
17
23
|
const MASTRA_USER_ROLES_KEY = "mastra__userRoles";
|
|
@@ -49,6 +55,7 @@ const RESERVED_REQUEST_CONTEXT_KEYS = [
|
|
|
49
55
|
MASTRA_RESOURCE_ID_KEY,
|
|
50
56
|
MASTRA_THREAD_ID_KEY,
|
|
51
57
|
MASTRA_SCOPES_KEY,
|
|
58
|
+
MASTRA_KNOWLEDGE_PRINCIPALS_KEY,
|
|
52
59
|
MASTRA_USER_KEY,
|
|
53
60
|
MASTRA_USER_PERMISSIONS_KEY,
|
|
54
61
|
MASTRA_USER_ROLES_KEY,
|
|
@@ -127,6 +134,6 @@ async function resolveToolConfig(toolsConfig, toolName, context) {
|
|
|
127
134
|
requireReadBeforeWrite: requireReadBeforeWrite !== void 0 ? await resolveDynamicValue(requireReadBeforeWrite, context, true) : void 0
|
|
128
135
|
};
|
|
129
136
|
}
|
|
130
|
-
export {
|
|
137
|
+
export { resolveToolConfig as _, MASTRA_KNOWLEDGE_PRINCIPALS_KEY as a, MASTRA_STUDIO_CLIENT_TYPE as c, MASTRA_USER_PERMISSIONS_KEY as d, MASTRA_USER_ROLES_KEY as f, isStudioClientTypeHeader as g, isReservedRequestContextKey as h, MASTRA_IS_STUDIO_KEY as i, MASTRA_THREAD_ID_KEY as l, WORKSPACE_TOOLS as m, MASTRA_AUTH_TOKEN_KEY as n, MASTRA_PUBLIC_HOST_HEADER as o, RESERVED_REQUEST_CONTEXT_KEYS as p, MASTRA_CLIENT_TYPE_HEADER as r, MASTRA_RESOURCE_ID_KEY as s, MASTRA_AUTH_MODE_KEY as t, MASTRA_USER_KEY as u };
|
|
131
138
|
|
|
132
|
-
//# sourceMappingURL=constants-
|
|
139
|
+
//# sourceMappingURL=constants-CXAvBYcz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-CXAvBYcz.js","names":[],"sources":["../src/server/constants.ts"],"sourcesContent":["/**\n * Constants inlined from @mastra/core to avoid import compatibility\n * issues with older core versions that don't export them yet.\n *\n * - Reserved RequestContext keys are inlined from @mastra/core/request-context.\n * - Workspace tool constants are inlined from @mastra/core/workspace.\n */\n\nexport const MASTRA_RESOURCE_ID_KEY = 'mastra__resourceId';\n\nexport const MASTRA_THREAD_ID_KEY = 'mastra__threadId';\n\n/**\n * Agent scopes set by trusted middleware. Never accepted from a request body.\n */\nexport const MASTRA_SCOPES_KEY = 'mastra__scopes';\n\n/**\n * The Knowledge principals the signed-in caller holds, for the Studio Knowledge routes: a `string[]` of\n * principal addresses, or `'all'` for an admin who may read the whole instance. Set it in\n * `auth.authorize` (after authentication). With auth configured, a caller without it is refused.\n */\nexport const MASTRA_KNOWLEDGE_PRINCIPALS_KEY = 'mastra__knowledgePrincipals';\n\nexport const MASTRA_USER_KEY = 'mastra__user';\n\nexport const MASTRA_USER_PERMISSIONS_KEY = 'mastra__userPermissions';\n\nexport const MASTRA_USER_ROLES_KEY = 'mastra__userRoles';\n\nexport const MASTRA_AUTH_TOKEN_KEY = 'mastra__authToken';\n\nexport const MASTRA_IS_STUDIO_KEY = 'mastra__isStudio';\n\n/**\n * Carries a delegating agent's memory into a delegated sub-agent run. Set only\n * by the delegation path inside a single process.\n */\nexport const MASTRA_INHERITED_MEMORY_KEY = 'mastra__inheritedMemory';\n\n/**\n * Tracks which auth mode was used for the current request.\n * Set to 'studio' when studio auth was used, 'server' when server auth was used.\n * Used to determine which RBAC/FGA provider to use for permission checks.\n */\nexport const MASTRA_AUTH_MODE_KEY = 'mastra__authMode';\n\nexport type MastraAuthMode = 'studio' | 'server';\n\nexport const MASTRA_CLIENT_TYPE_HEADER = 'x-mastra-client-type';\n\n/**\n * Browser-facing host, set by a trusted proxy whose own `X-Forwarded-Host` does\n * not survive the hop to the app. Railway's gateway, for example, overwrites\n * `X-Forwarded-Host` with its internal domain, so an edge in front of it has no\n * other way to tell the app which hostname the user actually typed.\n *\n * Read by `getPublicOrigin()` ahead of `X-Forwarded-Host`. Carries the same\n * trust assumption as the other forwarded headers: meaningful only behind a\n * proxy that sets it, and it must be stripped from untrusted client requests.\n */\nexport const MASTRA_PUBLIC_HOST_HEADER = 'x-mastra-public-host';\n\nexport const MASTRA_STUDIO_CLIENT_TYPE = 'studio';\n\n/**\n * RequestContext keys only trusted server code may set. Request bodies and query\n * params can never supply them.\n */\nexport const RESERVED_REQUEST_CONTEXT_KEYS = [\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n // Agent scopes decide memory identity and what the agent acts as; only\n // server middleware may set them.\n MASTRA_SCOPES_KEY,\n MASTRA_KNOWLEDGE_PRINCIPALS_KEY,\n MASTRA_USER_KEY,\n MASTRA_USER_PERMISSIONS_KEY,\n MASTRA_USER_ROLES_KEY,\n MASTRA_AUTH_TOKEN_KEY,\n MASTRA_IS_STUDIO_KEY,\n MASTRA_AUTH_MODE_KEY,\n // Delegation stores a live memory instance here. A body-supplied value would\n // be handed to the agent as its memory and throw on the first memory call.\n MASTRA_INHERITED_MEMORY_KEY,\n // Factory stores the authoritative per-caller OM settings result here before\n // model-driven memory processors run. Client input must not spoof that result.\n 'mastra__factoryMemorySettings',\n // Tenant scope must be established server-side, never self-asserted by a\n // client. The trusted-actor FGA gate keys off `organizationId`, so a\n // body-supplied value must not be merged into the request context.\n 'organizationId',\n] as const;\n\nconst RESERVED_CONTEXT_KEYS: ReadonlySet<string> = new Set(RESERVED_REQUEST_CONTEXT_KEYS);\n\nexport function isReservedRequestContextKey(key: string): boolean {\n return RESERVED_CONTEXT_KEYS.has(key);\n}\n\nexport function isStudioClientTypeHeader(value: string | undefined): boolean {\n return value?.toLowerCase() === MASTRA_STUDIO_CLIENT_TYPE;\n}\n\nexport const WORKSPACE_TOOLS_PREFIX = 'mastra_workspace' as const;\n\nexport const WORKSPACE_TOOLS = {\n FILESYSTEM: {\n READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file` as const,\n WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file` as const,\n EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file` as const,\n LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files` as const,\n DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete` as const,\n FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat` as const,\n MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir` as const,\n GREP: `${WORKSPACE_TOOLS_PREFIX}_grep` as const,\n },\n SANDBOX: {\n EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command` as const,\n },\n SEARCH: {\n SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search` as const,\n INDEX: `${WORKSPACE_TOOLS_PREFIX}_index` as const,\n },\n} as const;\n\nexport type WorkspaceToolName =\n | (typeof WORKSPACE_TOOLS.FILESYSTEM)[keyof typeof WORKSPACE_TOOLS.FILESYSTEM]\n | (typeof WORKSPACE_TOOLS.SEARCH)[keyof typeof WORKSPACE_TOOLS.SEARCH]\n | (typeof WORKSPACE_TOOLS.SANDBOX)[keyof typeof WORKSPACE_TOOLS.SANDBOX];\n\n/**\n * A tool config value that may be a static boolean or a dynamic function.\n * Inlined from @mastra/core/workspace for compatibility.\n *\n * Uses `(...args: any[]) => any` for the function branch so it stays\n * assignable from all core context variants (ToolConfigContext,\n * ToolConfigWithArgsContext) without importing them.\n */\n\ntype DynamicToolConfigValue = boolean | ((...args: any[]) => any);\n\n/**\n * Configuration for a single workspace tool.\n */\nexport interface WorkspaceToolConfig {\n enabled?: DynamicToolConfigValue;\n requireApproval?: DynamicToolConfigValue;\n requireReadBeforeWrite?: DynamicToolConfigValue;\n}\n\n/**\n * Configuration for workspace tools.\n */\nexport type WorkspaceToolsConfig = {\n enabled?: DynamicToolConfigValue;\n requireApproval?: DynamicToolConfigValue;\n} & Partial<Record<WorkspaceToolName, WorkspaceToolConfig>>;\n\n/**\n * Safely resolve a dynamic config value (boolean or async function) to a boolean.\n * Falls back to `safeDefault` when no context is available or the function throws.\n */\nasync function resolveDynamicValue(\n value: DynamicToolConfigValue | undefined,\n context: { workspace: object; requestContext: Record<string, unknown> } | undefined,\n safeDefault: boolean,\n): Promise<boolean> {\n if (value === undefined) return safeDefault;\n if (typeof value === 'boolean') return value;\n if (!context) return safeDefault;\n try {\n return await value(context);\n } catch (error) {\n console.warn('[Workspace Tools] Dynamic config function threw, using safe default:', error);\n return safeDefault;\n }\n}\n\n/**\n * Resolve the effective configuration for a workspace tool.\n * Inlined from @mastra/core/workspace for compatibility.\n *\n * Dynamic function values are resolved by calling them with the provided\n * workspace and requestContext. If a function throws, safe defaults are used\n * (enabled → false, requireApproval → true, requireReadBeforeWrite → true).\n */\nexport async function resolveToolConfig(\n toolsConfig: WorkspaceToolsConfig | undefined,\n toolName: WorkspaceToolName,\n context?: { workspace: object; requestContext: Record<string, unknown> },\n): Promise<{ enabled: boolean; requireApproval: boolean; requireReadBeforeWrite?: boolean }> {\n let enabled: DynamicToolConfigValue = true;\n let requireApproval: DynamicToolConfigValue = false;\n let requireReadBeforeWrite: DynamicToolConfigValue | undefined;\n\n if (toolsConfig) {\n if (toolsConfig.enabled !== undefined) {\n enabled = toolsConfig.enabled;\n }\n if (toolsConfig.requireApproval !== undefined) {\n requireApproval = toolsConfig.requireApproval;\n }\n\n const perToolConfig = toolsConfig[toolName];\n if (perToolConfig) {\n if (perToolConfig.enabled !== undefined) {\n enabled = perToolConfig.enabled;\n }\n if (perToolConfig.requireApproval !== undefined) {\n requireApproval = perToolConfig.requireApproval;\n }\n if (perToolConfig.requireReadBeforeWrite !== undefined) {\n requireReadBeforeWrite = perToolConfig.requireReadBeforeWrite;\n }\n }\n }\n\n return {\n enabled: await resolveDynamicValue(enabled, context, false),\n requireApproval: await resolveDynamicValue(requireApproval, context, true),\n requireReadBeforeWrite:\n requireReadBeforeWrite !== undefined\n ? await resolveDynamicValue(requireReadBeforeWrite, context, true)\n : undefined,\n };\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,yBAAyB;AAEtC,MAAa,uBAAuB;;;;AAKpC,MAAa,oBAAoB;;;;;;AAOjC,MAAa,kCAAkC;AAE/C,MAAa,kBAAkB;AAE/B,MAAa,8BAA8B;AAE3C,MAAa,wBAAwB;AAErC,MAAa,wBAAwB;AAErC,MAAa,uBAAuB;;;;;AAMpC,MAAa,8BAA8B;;;;;;AAO3C,MAAa,uBAAuB;AAIpC,MAAa,4BAA4B;;;;;;;;;;;AAYzC,MAAa,4BAA4B;AAEzC,MAAa,4BAA4B;;;;;AAMzC,MAAa,gCAAgC;CAC3C;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;CAIA;AACF;AAEA,MAAM,wBAA6C,IAAI,IAAI,6BAA6B;AAExF,SAAgB,4BAA4B,KAAsB;CAChE,OAAO,sBAAsB,IAAI,GAAG;AACtC;AAEA,SAAgB,yBAAyB,OAAoC;CAC3E,OAAO,OAAO,YAAY,MAAM;AAClC;AAEA,MAAa,yBAAyB;AAEtC,MAAa,kBAA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KAAA;CACR;AACF"}
|
|
@@ -12,6 +12,12 @@ const MASTRA_THREAD_ID_KEY = "mastra__threadId";
|
|
|
12
12
|
* Agent scopes set by trusted middleware. Never accepted from a request body.
|
|
13
13
|
*/
|
|
14
14
|
const MASTRA_SCOPES_KEY = "mastra__scopes";
|
|
15
|
+
/**
|
|
16
|
+
* The Knowledge principals the signed-in caller holds, for the Studio Knowledge routes: a `string[]` of
|
|
17
|
+
* principal addresses, or `'all'` for an admin who may read the whole instance. Set it in
|
|
18
|
+
* `auth.authorize` (after authentication). With auth configured, a caller without it is refused.
|
|
19
|
+
*/
|
|
20
|
+
const MASTRA_KNOWLEDGE_PRINCIPALS_KEY = "mastra__knowledgePrincipals";
|
|
15
21
|
const MASTRA_USER_KEY = "mastra__user";
|
|
16
22
|
const MASTRA_USER_PERMISSIONS_KEY = "mastra__userPermissions";
|
|
17
23
|
const MASTRA_USER_ROLES_KEY = "mastra__userRoles";
|
|
@@ -49,6 +55,7 @@ const RESERVED_REQUEST_CONTEXT_KEYS = [
|
|
|
49
55
|
MASTRA_RESOURCE_ID_KEY,
|
|
50
56
|
MASTRA_THREAD_ID_KEY,
|
|
51
57
|
MASTRA_SCOPES_KEY,
|
|
58
|
+
MASTRA_KNOWLEDGE_PRINCIPALS_KEY,
|
|
52
59
|
MASTRA_USER_KEY,
|
|
53
60
|
MASTRA_USER_PERMISSIONS_KEY,
|
|
54
61
|
MASTRA_USER_ROLES_KEY,
|
|
@@ -151,6 +158,12 @@ Object.defineProperty(exports, "MASTRA_IS_STUDIO_KEY", {
|
|
|
151
158
|
return MASTRA_IS_STUDIO_KEY;
|
|
152
159
|
}
|
|
153
160
|
});
|
|
161
|
+
Object.defineProperty(exports, "MASTRA_KNOWLEDGE_PRINCIPALS_KEY", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function() {
|
|
164
|
+
return MASTRA_KNOWLEDGE_PRINCIPALS_KEY;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
154
167
|
Object.defineProperty(exports, "MASTRA_PUBLIC_HOST_HEADER", {
|
|
155
168
|
enumerable: true,
|
|
156
169
|
get: function() {
|
|
@@ -224,4 +237,4 @@ Object.defineProperty(exports, "resolveToolConfig", {
|
|
|
224
237
|
}
|
|
225
238
|
});
|
|
226
239
|
|
|
227
|
-
//# sourceMappingURL=constants-
|
|
240
|
+
//# sourceMappingURL=constants-DMg8hUOR.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants-DMg8hUOR.cjs","names":[],"sources":["../src/server/constants.ts"],"sourcesContent":["/**\n * Constants inlined from @mastra/core to avoid import compatibility\n * issues with older core versions that don't export them yet.\n *\n * - Reserved RequestContext keys are inlined from @mastra/core/request-context.\n * - Workspace tool constants are inlined from @mastra/core/workspace.\n */\n\nexport const MASTRA_RESOURCE_ID_KEY = 'mastra__resourceId';\n\nexport const MASTRA_THREAD_ID_KEY = 'mastra__threadId';\n\n/**\n * Agent scopes set by trusted middleware. Never accepted from a request body.\n */\nexport const MASTRA_SCOPES_KEY = 'mastra__scopes';\n\n/**\n * The Knowledge principals the signed-in caller holds, for the Studio Knowledge routes: a `string[]` of\n * principal addresses, or `'all'` for an admin who may read the whole instance. Set it in\n * `auth.authorize` (after authentication). With auth configured, a caller without it is refused.\n */\nexport const MASTRA_KNOWLEDGE_PRINCIPALS_KEY = 'mastra__knowledgePrincipals';\n\nexport const MASTRA_USER_KEY = 'mastra__user';\n\nexport const MASTRA_USER_PERMISSIONS_KEY = 'mastra__userPermissions';\n\nexport const MASTRA_USER_ROLES_KEY = 'mastra__userRoles';\n\nexport const MASTRA_AUTH_TOKEN_KEY = 'mastra__authToken';\n\nexport const MASTRA_IS_STUDIO_KEY = 'mastra__isStudio';\n\n/**\n * Carries a delegating agent's memory into a delegated sub-agent run. Set only\n * by the delegation path inside a single process.\n */\nexport const MASTRA_INHERITED_MEMORY_KEY = 'mastra__inheritedMemory';\n\n/**\n * Tracks which auth mode was used for the current request.\n * Set to 'studio' when studio auth was used, 'server' when server auth was used.\n * Used to determine which RBAC/FGA provider to use for permission checks.\n */\nexport const MASTRA_AUTH_MODE_KEY = 'mastra__authMode';\n\nexport type MastraAuthMode = 'studio' | 'server';\n\nexport const MASTRA_CLIENT_TYPE_HEADER = 'x-mastra-client-type';\n\n/**\n * Browser-facing host, set by a trusted proxy whose own `X-Forwarded-Host` does\n * not survive the hop to the app. Railway's gateway, for example, overwrites\n * `X-Forwarded-Host` with its internal domain, so an edge in front of it has no\n * other way to tell the app which hostname the user actually typed.\n *\n * Read by `getPublicOrigin()` ahead of `X-Forwarded-Host`. Carries the same\n * trust assumption as the other forwarded headers: meaningful only behind a\n * proxy that sets it, and it must be stripped from untrusted client requests.\n */\nexport const MASTRA_PUBLIC_HOST_HEADER = 'x-mastra-public-host';\n\nexport const MASTRA_STUDIO_CLIENT_TYPE = 'studio';\n\n/**\n * RequestContext keys only trusted server code may set. Request bodies and query\n * params can never supply them.\n */\nexport const RESERVED_REQUEST_CONTEXT_KEYS = [\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n // Agent scopes decide memory identity and what the agent acts as; only\n // server middleware may set them.\n MASTRA_SCOPES_KEY,\n MASTRA_KNOWLEDGE_PRINCIPALS_KEY,\n MASTRA_USER_KEY,\n MASTRA_USER_PERMISSIONS_KEY,\n MASTRA_USER_ROLES_KEY,\n MASTRA_AUTH_TOKEN_KEY,\n MASTRA_IS_STUDIO_KEY,\n MASTRA_AUTH_MODE_KEY,\n // Delegation stores a live memory instance here. A body-supplied value would\n // be handed to the agent as its memory and throw on the first memory call.\n MASTRA_INHERITED_MEMORY_KEY,\n // Factory stores the authoritative per-caller OM settings result here before\n // model-driven memory processors run. Client input must not spoof that result.\n 'mastra__factoryMemorySettings',\n // Tenant scope must be established server-side, never self-asserted by a\n // client. The trusted-actor FGA gate keys off `organizationId`, so a\n // body-supplied value must not be merged into the request context.\n 'organizationId',\n] as const;\n\nconst RESERVED_CONTEXT_KEYS: ReadonlySet<string> = new Set(RESERVED_REQUEST_CONTEXT_KEYS);\n\nexport function isReservedRequestContextKey(key: string): boolean {\n return RESERVED_CONTEXT_KEYS.has(key);\n}\n\nexport function isStudioClientTypeHeader(value: string | undefined): boolean {\n return value?.toLowerCase() === MASTRA_STUDIO_CLIENT_TYPE;\n}\n\nexport const WORKSPACE_TOOLS_PREFIX = 'mastra_workspace' as const;\n\nexport const WORKSPACE_TOOLS = {\n FILESYSTEM: {\n READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file` as const,\n WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file` as const,\n EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file` as const,\n LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files` as const,\n DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete` as const,\n FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat` as const,\n MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir` as const,\n GREP: `${WORKSPACE_TOOLS_PREFIX}_grep` as const,\n },\n SANDBOX: {\n EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command` as const,\n },\n SEARCH: {\n SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search` as const,\n INDEX: `${WORKSPACE_TOOLS_PREFIX}_index` as const,\n },\n} as const;\n\nexport type WorkspaceToolName =\n | (typeof WORKSPACE_TOOLS.FILESYSTEM)[keyof typeof WORKSPACE_TOOLS.FILESYSTEM]\n | (typeof WORKSPACE_TOOLS.SEARCH)[keyof typeof WORKSPACE_TOOLS.SEARCH]\n | (typeof WORKSPACE_TOOLS.SANDBOX)[keyof typeof WORKSPACE_TOOLS.SANDBOX];\n\n/**\n * A tool config value that may be a static boolean or a dynamic function.\n * Inlined from @mastra/core/workspace for compatibility.\n *\n * Uses `(...args: any[]) => any` for the function branch so it stays\n * assignable from all core context variants (ToolConfigContext,\n * ToolConfigWithArgsContext) without importing them.\n */\n\ntype DynamicToolConfigValue = boolean | ((...args: any[]) => any);\n\n/**\n * Configuration for a single workspace tool.\n */\nexport interface WorkspaceToolConfig {\n enabled?: DynamicToolConfigValue;\n requireApproval?: DynamicToolConfigValue;\n requireReadBeforeWrite?: DynamicToolConfigValue;\n}\n\n/**\n * Configuration for workspace tools.\n */\nexport type WorkspaceToolsConfig = {\n enabled?: DynamicToolConfigValue;\n requireApproval?: DynamicToolConfigValue;\n} & Partial<Record<WorkspaceToolName, WorkspaceToolConfig>>;\n\n/**\n * Safely resolve a dynamic config value (boolean or async function) to a boolean.\n * Falls back to `safeDefault` when no context is available or the function throws.\n */\nasync function resolveDynamicValue(\n value: DynamicToolConfigValue | undefined,\n context: { workspace: object; requestContext: Record<string, unknown> } | undefined,\n safeDefault: boolean,\n): Promise<boolean> {\n if (value === undefined) return safeDefault;\n if (typeof value === 'boolean') return value;\n if (!context) return safeDefault;\n try {\n return await value(context);\n } catch (error) {\n console.warn('[Workspace Tools] Dynamic config function threw, using safe default:', error);\n return safeDefault;\n }\n}\n\n/**\n * Resolve the effective configuration for a workspace tool.\n * Inlined from @mastra/core/workspace for compatibility.\n *\n * Dynamic function values are resolved by calling them with the provided\n * workspace and requestContext. If a function throws, safe defaults are used\n * (enabled → false, requireApproval → true, requireReadBeforeWrite → true).\n */\nexport async function resolveToolConfig(\n toolsConfig: WorkspaceToolsConfig | undefined,\n toolName: WorkspaceToolName,\n context?: { workspace: object; requestContext: Record<string, unknown> },\n): Promise<{ enabled: boolean; requireApproval: boolean; requireReadBeforeWrite?: boolean }> {\n let enabled: DynamicToolConfigValue = true;\n let requireApproval: DynamicToolConfigValue = false;\n let requireReadBeforeWrite: DynamicToolConfigValue | undefined;\n\n if (toolsConfig) {\n if (toolsConfig.enabled !== undefined) {\n enabled = toolsConfig.enabled;\n }\n if (toolsConfig.requireApproval !== undefined) {\n requireApproval = toolsConfig.requireApproval;\n }\n\n const perToolConfig = toolsConfig[toolName];\n if (perToolConfig) {\n if (perToolConfig.enabled !== undefined) {\n enabled = perToolConfig.enabled;\n }\n if (perToolConfig.requireApproval !== undefined) {\n requireApproval = perToolConfig.requireApproval;\n }\n if (perToolConfig.requireReadBeforeWrite !== undefined) {\n requireReadBeforeWrite = perToolConfig.requireReadBeforeWrite;\n }\n }\n }\n\n return {\n enabled: await resolveDynamicValue(enabled, context, false),\n requireApproval: await resolveDynamicValue(requireApproval, context, true),\n requireReadBeforeWrite:\n requireReadBeforeWrite !== undefined\n ? await resolveDynamicValue(requireReadBeforeWrite, context, true)\n : undefined,\n };\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,yBAAyB;AAEtC,MAAa,uBAAuB;;;;AAKpC,MAAa,oBAAoB;;;;;;AAOjC,MAAa,kCAAkC;AAE/C,MAAa,kBAAkB;AAE/B,MAAa,8BAA8B;AAE3C,MAAa,wBAAwB;AAErC,MAAa,wBAAwB;AAErC,MAAa,uBAAuB;;;;;AAMpC,MAAa,8BAA8B;;;;;;AAO3C,MAAa,uBAAuB;AAIpC,MAAa,4BAA4B;;;;;;;;;;;AAYzC,MAAa,4BAA4B;AAEzC,MAAa,4BAA4B;;;;;AAMzC,MAAa,gCAAgC;CAC3C;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;CAIA;AACF;AAEA,MAAM,wBAA6C,IAAI,IAAI,6BAA6B;AAExF,SAAgB,4BAA4B,KAAsB;CAChE,OAAO,sBAAsB,IAAI,GAAG;AACtC;AAEA,SAAgB,yBAAyB,OAAoC;CAC3E,OAAO,OAAO,YAAY,MAAM;AAClC;AAEA,MAAa,yBAAyB;AAEtC,MAAa,kBAAkB;CAC7B,YAAY;EACV,WAAW,GAAG,uBAAuB;EACrC,YAAY,GAAG,uBAAuB;EACtC,WAAW,GAAG,uBAAuB;EACrC,YAAY,GAAG,uBAAuB;EACtC,QAAQ,GAAG,uBAAuB;EAClC,WAAW,GAAG,uBAAuB;EACrC,OAAO,GAAG,uBAAuB;EACjC,MAAM,GAAG,uBAAuB;CAClC;CACA,SAAS,EACP,iBAAiB,GAAG,uBAAuB,kBAC7C;CACA,QAAQ;EACN,QAAQ,GAAG,uBAAuB;EAClC,OAAO,GAAG,uBAAuB;CACnC;AACF;;;;;AAuCA,eAAe,oBACb,OACA,SACA,aACkB;CAClB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,OAAO,UAAU,WAAW,OAAO;CACvC,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI;EACF,OAAO,MAAM,MAAM,OAAO;CAC5B,SAAS,OAAO;EACd,QAAQ,KAAK,wEAAwE,KAAK;EAC1F,OAAO;CACT;AACF;;;;;;;;;AAUA,eAAsB,kBACpB,aACA,UACA,SAC2F;CAC3F,IAAI,UAAkC;CACtC,IAAI,kBAA0C;CAC9C,IAAI;CAEJ,IAAI,aAAa;EACf,IAAI,YAAY,YAAY,KAAA,GAC1B,UAAU,YAAY;EAExB,IAAI,YAAY,oBAAoB,KAAA,GAClC,kBAAkB,YAAY;EAGhC,MAAM,gBAAgB,YAAY;EAClC,IAAI,eAAe;GACjB,IAAI,cAAc,YAAY,KAAA,GAC5B,UAAU,cAAc;GAE1B,IAAI,cAAc,oBAAoB,KAAA,GACpC,kBAAkB,cAAc;GAElC,IAAI,cAAc,2BAA2B,KAAA,GAC3C,yBAAyB,cAAc;EAE3C;CACF;CAEA,OAAO;EACL,SAAS,MAAM,oBAAoB,SAAS,SAAS,KAAK;EAC1D,iBAAiB,MAAM,oBAAoB,iBAAiB,SAAS,IAAI;EACzE,wBACE,2BAA2B,KAAA,IACvB,MAAM,oBAAoB,wBAAwB,SAAS,IAAI,IAC/D,KAAA;CACR;AACF"}
|
|
@@ -2,8 +2,8 @@ import { r as __exportAll } from "./rolldown-runtime-CQI-hT2b.js";
|
|
|
2
2
|
import { t as HTTPException } from "./http-exception-CzaWkxMl.js";
|
|
3
3
|
import { n as createRoute } from "./route-builder-BxPrwNog.js";
|
|
4
4
|
import { handleError } from "./server/handlers/error.js";
|
|
5
|
-
import { _ as MastraFGAPermissions, g as validateThreadOwnership, i as getEffectiveResourceId } from "./utils-
|
|
6
|
-
import { G as getAgentFromSystem } from "./agents-
|
|
5
|
+
import { _ as MastraFGAPermissions, g as validateThreadOwnership, i as getEffectiveResourceId } from "./utils-B15w-1hm.js";
|
|
6
|
+
import { G as getAgentFromSystem } from "./agents-NRBk4JAs.js";
|
|
7
7
|
import { a as createConversationBodySchema, i as conversationObjectSchema, n as conversationIdPathParams, r as conversationItemsListSchema, t as conversationDeletedSchema } from "./conversations-DHrKTI6x.js";
|
|
8
8
|
import { mapMastraMessagesToConversationItems } from "./server/handlers/responses.adapter.js";
|
|
9
9
|
import { findConversationThreadAcrossAgents, getAgentMemoryStore } from "./server/handlers/responses.storage.js";
|
|
@@ -161,4 +161,4 @@ const DELETE_CONVERSATION_ROUTE = createRoute({
|
|
|
161
161
|
});
|
|
162
162
|
export { conversations_exports as a, GET_CONVERSATION_ROUTE as i, DELETE_CONVERSATION_ROUTE as n, GET_CONVERSATION_ITEMS_ROUTE as r, CREATE_CONVERSATION_ROUTE as t };
|
|
163
163
|
|
|
164
|
-
//# sourceMappingURL=conversations-
|
|
164
|
+
//# sourceMappingURL=conversations-CVvZOu1K.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations-
|
|
1
|
+
{"version":3,"file":"conversations-CVvZOu1K.js","names":[],"sources":["../src/server/handlers/conversations.ts"],"sourcesContent":["import { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n conversationDeletedSchema,\n conversationIdPathParams,\n conversationItemsListSchema,\n conversationObjectSchema,\n createConversationBodySchema,\n} from '../schemas/conversations';\nimport type { ConversationDeleted, ConversationItemsList, ConversationObject } from '../schemas/conversations';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { mapMastraMessagesToConversationItems } from './responses.adapter';\nimport { findConversationThreadAcrossAgents, getAgentMemoryStore } from './responses.storage';\nimport { getEffectiveResourceId, validateThreadOwnership } from './utils';\n\nfunction buildConversationObject({ thread }: { thread: ConversationObject['thread'] }): ConversationObject {\n return {\n id: thread.id,\n object: 'conversation',\n thread,\n };\n}\n\nfunction buildConversationItemsList(items: ConversationItemsList['data']): ConversationItemsList {\n return {\n object: 'list',\n data: items,\n first_id: items[0]?.id ?? null,\n last_id: items.at(-1)?.id ?? null,\n has_more: false,\n };\n}\n\nfunction buildConversationDeleted(conversationId: string): ConversationDeleted {\n return {\n id: conversationId,\n object: 'conversation.deleted',\n deleted: true,\n };\n}\n\nexport const CREATE_CONVERSATION_ROUTE = createRoute({\n method: 'POST',\n path: '/v1/conversations',\n responseType: 'json',\n bodySchema: createConversationBodySchema,\n responseSchema: conversationObjectSchema,\n summary: 'Create a conversation',\n description: 'Creates a new thread-backed conversation for agent-backed Responses API requests',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_CREATE,\n handler: async ({ mastra, requestContext, agent_id, conversation_id, resource_id, title, metadata }) => {\n try {\n if (!mastra) {\n throw new HTTPException(500, { message: 'Mastra instance is required for conversations' });\n }\n\n const agent = await getAgentFromSystem({ mastra, agentId: agent_id });\n const memory = await agent.getMemory({ requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: `Agent \"${agent.id}\" does not have memory configured` });\n }\n if (!(await getAgentMemoryStore({ agent, requestContext }))) {\n throw new HTTPException(400, { message: `Memory storage is not configured for agent \"${agent.id}\"` });\n }\n\n const threadId = conversation_id ?? globalThis.crypto.randomUUID();\n const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;\n\n // Creating with an existing id upserts the thread, so validate ownership of any existing thread first\n if (conversation_id) {\n const existing = await memory.getThreadById({ threadId });\n await validateThreadOwnership(existing, getEffectiveResourceId(requestContext, undefined));\n }\n\n const thread = await memory.createThread({\n threadId,\n resourceId,\n title,\n metadata,\n });\n\n return buildConversationObject({ thread });\n } catch (error) {\n return handleError(error, 'Error creating conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationObjectSchema,\n summary: 'Retrieve a conversation',\n description: 'Returns a conversation object backed by a Mastra memory thread',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n return buildConversationObject({ thread: match.thread });\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ITEMS_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId/items',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationItemsListSchema,\n summary: 'List conversation items',\n description: 'Returns OpenAI-style conversation items derived from the stored thread messages',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n const { messages } = await match.memoryStore.listMessages({\n threadId: conversationId,\n page: 0,\n perPage: 1000,\n });\n\n return buildConversationItemsList(mapMastraMessagesToConversationItems(messages));\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const DELETE_CONVERSATION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationDeletedSchema,\n summary: 'Delete a conversation',\n description: 'Deletes a thread-backed conversation and its stored items',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_DELETE,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n await match.memoryStore.deleteThread({ threadId: conversationId });\n\n return buildConversationDeleted(conversationId);\n } catch (error) {\n return handleError(error, 'Error deleting conversation');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAS,wBAAwB,EAAE,UAAwE;CACzG,OAAO;EACL,IAAI,OAAO;EACX,QAAQ;EACR;CACF;AACF;AAEA,SAAS,2BAA2B,OAA6D;CAC/F,OAAO;EACL,QAAQ;EACR,MAAM;EACN,UAAU,MAAM,EAAE,EAAE,MAAM;EAC1B,SAAS,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM;EAC7B,UAAU;CACZ;AACF;AAEA,SAAS,yBAAyB,gBAA6C;CAC7E,OAAO;EACL,IAAI;EACJ,QAAQ;EACR,SAAS;CACX;AACF;AAEA,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,YAAY;CACZ,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,WAAW;CAClB,cAAc;CACd,oBAAoB,qBAAqB;CACzC,SAAS,OAAO,EAAE,QAAQ,gBAAgB,UAAU,iBAAiB,aAAa,OAAO,eAAe;EACtG,IAAI;GACF,IAAI,CAAC,QACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,gDAAgD,CAAC;GAG3F,MAAM,QAAQ,MAAM,mBAAmB;IAAE;IAAQ,SAAS;GAAS,CAAC;GACpE,MAAM,SAAS,MAAM,MAAM,UAAU,EAAE,eAAe,CAAC;GACvD,IAAI,CAAC,QACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,UAAU,MAAM,GAAG,mCAAmC,CAAC;GAEjG,IAAI,CAAE,MAAM,oBAAoB;IAAE;IAAO;GAAe,CAAC,GAC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AM,mCAAmC;IAAE;IAAQ;IAAgB;GAAe,CAAC;GACjG,IAAI,CAAC,OACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,gBAAgB,eAAe,gBAAgB,CAAC;GAG1F,MAAM,EAAE,aAAa,MAAM,MAAM,YAAY,aAAa;IACxD,UAAU;IACV,MAAM;IACN,SAAS;GACX,CAAC;GAED,OAAO,2BAA2B,qCAAqC,QAAQ,CAAC;EAClF,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,+BAA+B;EAC3D;CACF;AACF,CAAC;AAED,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,WAAW;CAClB,cAAc;CACd,oBAAoB,qBAAqB;CACzC,SAAS,OAAO,EAAE,QAAQ,gBAAgB,qBAAqB;EAC7D,IAAI;GACF,MAAM,QAAQ,MAAM,mCAAmC;IAAE;IAAQ;IAAgB;GAAe,CAAC;GACjG,IAAI,CAAC,OACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,gBAAgB,eAAe,gBAAgB,CAAC;GAG1F,MAAM,MAAM,YAAY,aAAa,EAAE,UAAU,eAAe,CAAC;GAEjE,OAAO,yBAAyB,cAAc;EAChD,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,6BAA6B;EACzD;CACF;AACF,CAAC"}
|
|
@@ -2,8 +2,8 @@ const require_rolldown_runtime = require("./rolldown-runtime-10nMEhjP.cjs");
|
|
|
2
2
|
const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
3
3
|
const require_route_builder = require("./route-builder-CvARmqnA.cjs");
|
|
4
4
|
const require_server_handlers_error = require("./server/handlers/error.cjs");
|
|
5
|
-
const require_utils = require("./utils-
|
|
6
|
-
const require_agents = require("./agents-
|
|
5
|
+
const require_utils = require("./utils-9PRHHTGC.cjs");
|
|
6
|
+
const require_agents = require("./agents-SvkxJW48.cjs");
|
|
7
7
|
const require_conversations = require("./conversations-BVj0Dk2Q.cjs");
|
|
8
8
|
const require_server_handlers_responses_adapter = require("./server/handlers/responses.adapter.cjs");
|
|
9
9
|
const require_server_handlers_responses_storage = require("./server/handlers/responses.storage.cjs");
|
|
@@ -190,4 +190,4 @@ Object.defineProperty(exports, "conversations_exports", {
|
|
|
190
190
|
}
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
//# sourceMappingURL=conversations-
|
|
193
|
+
//# sourceMappingURL=conversations-Ds6aiCMU.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversations-ORTpTqBg.cjs","names":["createRoute","createConversationBodySchema","conversationObjectSchema","MastraFGAPermissions","HTTPException","getAgentFromSystem","getAgentMemoryStore","getEffectiveResourceId","validateThreadOwnership","handleError","conversationIdPathParams","findConversationThreadAcrossAgents","conversationItemsListSchema","mapMastraMessagesToConversationItems","conversationDeletedSchema"],"sources":["../src/server/handlers/conversations.ts"],"sourcesContent":["import { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n conversationDeletedSchema,\n conversationIdPathParams,\n conversationItemsListSchema,\n conversationObjectSchema,\n createConversationBodySchema,\n} from '../schemas/conversations';\nimport type { ConversationDeleted, ConversationItemsList, ConversationObject } from '../schemas/conversations';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { mapMastraMessagesToConversationItems } from './responses.adapter';\nimport { findConversationThreadAcrossAgents, getAgentMemoryStore } from './responses.storage';\nimport { getEffectiveResourceId, validateThreadOwnership } from './utils';\n\nfunction buildConversationObject({ thread }: { thread: ConversationObject['thread'] }): ConversationObject {\n return {\n id: thread.id,\n object: 'conversation',\n thread,\n };\n}\n\nfunction buildConversationItemsList(items: ConversationItemsList['data']): ConversationItemsList {\n return {\n object: 'list',\n data: items,\n first_id: items[0]?.id ?? null,\n last_id: items.at(-1)?.id ?? null,\n has_more: false,\n };\n}\n\nfunction buildConversationDeleted(conversationId: string): ConversationDeleted {\n return {\n id: conversationId,\n object: 'conversation.deleted',\n deleted: true,\n };\n}\n\nexport const CREATE_CONVERSATION_ROUTE = createRoute({\n method: 'POST',\n path: '/v1/conversations',\n responseType: 'json',\n bodySchema: createConversationBodySchema,\n responseSchema: conversationObjectSchema,\n summary: 'Create a conversation',\n description: 'Creates a new thread-backed conversation for agent-backed Responses API requests',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_CREATE,\n handler: async ({ mastra, requestContext, agent_id, conversation_id, resource_id, title, metadata }) => {\n try {\n if (!mastra) {\n throw new HTTPException(500, { message: 'Mastra instance is required for conversations' });\n }\n\n const agent = await getAgentFromSystem({ mastra, agentId: agent_id });\n const memory = await agent.getMemory({ requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: `Agent \"${agent.id}\" does not have memory configured` });\n }\n if (!(await getAgentMemoryStore({ agent, requestContext }))) {\n throw new HTTPException(400, { message: `Memory storage is not configured for agent \"${agent.id}\"` });\n }\n\n const threadId = conversation_id ?? globalThis.crypto.randomUUID();\n const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;\n\n // Creating with an existing id upserts the thread, so validate ownership of any existing thread first\n if (conversation_id) {\n const existing = await memory.getThreadById({ threadId });\n await validateThreadOwnership(existing, getEffectiveResourceId(requestContext, undefined));\n }\n\n const thread = await memory.createThread({\n threadId,\n resourceId,\n title,\n metadata,\n });\n\n return buildConversationObject({ thread });\n } catch (error) {\n return handleError(error, 'Error creating conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationObjectSchema,\n summary: 'Retrieve a conversation',\n description: 'Returns a conversation object backed by a Mastra memory thread',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n return buildConversationObject({ thread: match.thread });\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ITEMS_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId/items',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationItemsListSchema,\n summary: 'List conversation items',\n description: 'Returns OpenAI-style conversation items derived from the stored thread messages',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n const { messages } = await match.memoryStore.listMessages({\n threadId: conversationId,\n page: 0,\n perPage: 1000,\n });\n\n return buildConversationItemsList(mapMastraMessagesToConversationItems(messages));\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const DELETE_CONVERSATION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationDeletedSchema,\n summary: 'Delete a conversation',\n description: 'Deletes a thread-backed conversation and its stored items',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_DELETE,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n await match.memoryStore.deleteThread({ threadId: conversationId });\n\n return buildConversationDeleted(conversationId);\n } catch (error) {\n return handleError(error, 'Error deleting conversation');\n }\n },\n});\n"],"mappings":";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CAAC;GACjG,IAAI,CAAC,OACH,MAAM,IAAIP,uBAAAA,cAAc,KAAK,EAAE,SAAS,gBAAgB,eAAe,gBAAgB,CAAC;GAG1F,MAAM,EAAE,aAAa,MAAM,MAAM,YAAY,aAAa;IACxD,UAAU;IACV,MAAM;IACN,SAAS;GACX,CAAC;GAED,OAAO,2BAA2BS,0CAAAA,qCAAqC,QAAQ,CAAC;EAClF,SAAS,OAAO;GACd,OAAOJ,8BAAAA,YAAY,OAAO,+BAA+B;EAC3D;CACF;AACF,CAAC;AAED,MAAa,4BAA4BT,sBAAAA,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiBU,sBAAAA;CACjB,gBAAgBI,sBAAAA;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,WAAW;CAClB,cAAc;CACd,oBAAoBX,cAAAA,qBAAqB;CACzC,SAAS,OAAO,EAAE,QAAQ,gBAAgB,qBAAqB;EAC7D,IAAI;GACF,MAAM,QAAQ,MAAMQ,0CAAAA,mCAAmC;IAAE;IAAQ;IAAgB;GAAe,CAAC;GACjG,IAAI,CAAC,OACH,MAAM,IAAIP,uBAAAA,cAAc,KAAK,EAAE,SAAS,gBAAgB,eAAe,gBAAgB,CAAC;GAG1F,MAAM,MAAM,YAAY,aAAa,EAAE,UAAU,eAAe,CAAC;GAEjE,OAAO,yBAAyB,cAAc;EAChD,SAAS,OAAO;GACd,OAAOK,8BAAAA,YAAY,OAAO,6BAA6B;EACzD;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"conversations-Ds6aiCMU.cjs","names":["createRoute","createConversationBodySchema","conversationObjectSchema","MastraFGAPermissions","HTTPException","getAgentFromSystem","getAgentMemoryStore","getEffectiveResourceId","validateThreadOwnership","handleError","conversationIdPathParams","findConversationThreadAcrossAgents","conversationItemsListSchema","mapMastraMessagesToConversationItems","conversationDeletedSchema"],"sources":["../src/server/handlers/conversations.ts"],"sourcesContent":["import { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\nimport {\n conversationDeletedSchema,\n conversationIdPathParams,\n conversationItemsListSchema,\n conversationObjectSchema,\n createConversationBodySchema,\n} from '../schemas/conversations';\nimport type { ConversationDeleted, ConversationItemsList, ConversationObject } from '../schemas/conversations';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { getAgentFromSystem } from './agents';\nimport { handleError } from './error';\nimport { mapMastraMessagesToConversationItems } from './responses.adapter';\nimport { findConversationThreadAcrossAgents, getAgentMemoryStore } from './responses.storage';\nimport { getEffectiveResourceId, validateThreadOwnership } from './utils';\n\nfunction buildConversationObject({ thread }: { thread: ConversationObject['thread'] }): ConversationObject {\n return {\n id: thread.id,\n object: 'conversation',\n thread,\n };\n}\n\nfunction buildConversationItemsList(items: ConversationItemsList['data']): ConversationItemsList {\n return {\n object: 'list',\n data: items,\n first_id: items[0]?.id ?? null,\n last_id: items.at(-1)?.id ?? null,\n has_more: false,\n };\n}\n\nfunction buildConversationDeleted(conversationId: string): ConversationDeleted {\n return {\n id: conversationId,\n object: 'conversation.deleted',\n deleted: true,\n };\n}\n\nexport const CREATE_CONVERSATION_ROUTE = createRoute({\n method: 'POST',\n path: '/v1/conversations',\n responseType: 'json',\n bodySchema: createConversationBodySchema,\n responseSchema: conversationObjectSchema,\n summary: 'Create a conversation',\n description: 'Creates a new thread-backed conversation for agent-backed Responses API requests',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_CREATE,\n handler: async ({ mastra, requestContext, agent_id, conversation_id, resource_id, title, metadata }) => {\n try {\n if (!mastra) {\n throw new HTTPException(500, { message: 'Mastra instance is required for conversations' });\n }\n\n const agent = await getAgentFromSystem({ mastra, agentId: agent_id });\n const memory = await agent.getMemory({ requestContext });\n if (!memory) {\n throw new HTTPException(400, { message: `Agent \"${agent.id}\" does not have memory configured` });\n }\n if (!(await getAgentMemoryStore({ agent, requestContext }))) {\n throw new HTTPException(400, { message: `Memory storage is not configured for agent \"${agent.id}\"` });\n }\n\n const threadId = conversation_id ?? globalThis.crypto.randomUUID();\n const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;\n\n // Creating with an existing id upserts the thread, so validate ownership of any existing thread first\n if (conversation_id) {\n const existing = await memory.getThreadById({ threadId });\n await validateThreadOwnership(existing, getEffectiveResourceId(requestContext, undefined));\n }\n\n const thread = await memory.createThread({\n threadId,\n resourceId,\n title,\n metadata,\n });\n\n return buildConversationObject({ thread });\n } catch (error) {\n return handleError(error, 'Error creating conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationObjectSchema,\n summary: 'Retrieve a conversation',\n description: 'Returns a conversation object backed by a Mastra memory thread',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n return buildConversationObject({ thread: match.thread });\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const GET_CONVERSATION_ITEMS_ROUTE = createRoute({\n method: 'GET',\n path: '/v1/conversations/:conversationId/items',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationItemsListSchema,\n summary: 'List conversation items',\n description: 'Returns OpenAI-style conversation items derived from the stored thread messages',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_READ,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n const { messages } = await match.memoryStore.listMessages({\n threadId: conversationId,\n page: 0,\n perPage: 1000,\n });\n\n return buildConversationItemsList(mapMastraMessagesToConversationItems(messages));\n } catch (error) {\n return handleError(error, 'Error retrieving conversation');\n }\n },\n});\n\nexport const DELETE_CONVERSATION_ROUTE = createRoute({\n method: 'DELETE',\n path: '/v1/conversations/:conversationId',\n responseType: 'json',\n pathParamSchema: conversationIdPathParams,\n responseSchema: conversationDeletedSchema,\n summary: 'Delete a conversation',\n description: 'Deletes a thread-backed conversation and its stored items',\n tags: ['Responses'],\n requiresAuth: true,\n requiresPermission: MastraFGAPermissions.AGENTS_DELETE,\n handler: async ({ mastra, requestContext, conversationId }) => {\n try {\n const match = await findConversationThreadAcrossAgents({ mastra, conversationId, requestContext });\n if (!match) {\n throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });\n }\n\n await match.memoryStore.deleteThread({ threadId: conversationId });\n\n return buildConversationDeleted(conversationId);\n } catch (error) {\n return handleError(error, 'Error deleting conversation');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAS,wBAAwB,EAAE,UAAwE;CACzG,OAAO;EACL,IAAI,OAAO;EACX,QAAQ;EACR;CACF;AACF;AAEA,SAAS,2BAA2B,OAA6D;CAC/F,OAAO;EACL,QAAQ;EACR,MAAM;EACN,UAAU,MAAM,EAAE,EAAE,MAAM;EAC1B,SAAS,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM;EAC7B,UAAU;CACZ;AACF;AAEA,SAAS,yBAAyB,gBAA6C;CAC7E,OAAO;EACL,IAAI;EACJ,QAAQ;EACR,SAAS;CACX;AACF;AAEA,MAAa,4BAA4BA,sBAAAA,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,YAAYC,sBAAAA;CACZ,gBAAgBC,sBAAAA;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,WAAW;CAClB,cAAc;CACd,oBAAoBC,cAAAA,qBAAqB;CACzC,SAAS,OAAO,EAAE,QAAQ,gBAAgB,UAAU,iBAAiB,aAAa,OAAO,eAAe;EACt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