@mastra/server 1.80.0-alpha.4 → 1.80.0-alpha.5
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-BUOtgjP-.cjs → a2a-BaRqCOUl.cjs} +2 -2
- package/dist/{a2a-BUOtgjP-.cjs.map → a2a-BaRqCOUl.cjs.map} +1 -1
- package/dist/{a2a-B2K45wEY.js → a2a-CApzjeDH.js} +2 -2
- package/dist/{a2a-B2K45wEY.js.map → a2a-CApzjeDH.js.map} +1 -1
- package/dist/{agent-builder-BEhoRLS_.js → agent-builder-Cv6X2dKZ.js} +3 -3
- package/dist/{agent-builder-BEhoRLS_.js.map → agent-builder-Cv6X2dKZ.js.map} +1 -1
- package/dist/{agent-builder-CTHPsm8d.cjs → agent-builder-DExL1jAO.cjs} +3 -3
- package/dist/{agent-builder-CTHPsm8d.cjs.map → agent-builder-DExL1jAO.cjs.map} +1 -1
- package/dist/{agents-I0TVb_TM.cjs → agents-BBaFtyAt.cjs} +9 -9
- package/dist/agents-BBaFtyAt.cjs.map +1 -0
- package/dist/{agents-DSZgApzs.js → agents-CGS0tE4p.js} +9 -9
- package/dist/agents-CGS0tE4p.js.map +1 -0
- package/dist/{api-schema-manifest-j2xurBb0.js → api-schema-manifest-BCIpcado.js} +2 -2
- package/dist/{api-schema-manifest-j2xurBb0.js.map → api-schema-manifest-BCIpcado.js.map} +1 -1
- package/dist/{api-schema-manifest-DCuGBEO0.cjs → api-schema-manifest-BRItYYlN.cjs} +2 -2
- package/dist/{api-schema-manifest-DCuGBEO0.cjs.map → api-schema-manifest-BRItYYlN.cjs.map} +1 -1
- package/dist/{background-tasks-BMVUFtVh.cjs → background-tasks-BMp9Q6SB.cjs} +2 -2
- package/dist/{background-tasks-BMVUFtVh.cjs.map → background-tasks-BMp9Q6SB.cjs.map} +1 -1
- package/dist/{background-tasks-CFkXHgyQ.js → background-tasks-DIpPsqVy.js} +2 -2
- package/dist/{background-tasks-CFkXHgyQ.js.map → background-tasks-DIpPsqVy.js.map} +1 -1
- package/dist/{conversations-BfBS1UwQ.js → conversations-B-s9MWRb.js} +3 -3
- package/dist/{conversations-BfBS1UwQ.js.map → conversations-B-s9MWRb.js.map} +1 -1
- package/dist/{conversations-BSYZlASE.cjs → conversations-DLuMXWot.cjs} +3 -3
- package/dist/{conversations-BSYZlASE.cjs.map → conversations-DLuMXWot.cjs.map} +1 -1
- package/dist/dist-C-L2kyKZ.js +1 -0
- package/dist/{dist-Cci9RRWj.cjs → dist-Clj7hRKz.cjs} +47 -69
- package/dist/dist-Clj7hRKz.cjs.map +1 -0
- package/dist/{dist-DJ3281Ve.cjs → dist-D6oS7RF1.cjs} +1 -1
- package/dist/{dist-bAoX6ick.js → dist-PlsLrwz8.js} +48 -70
- package/dist/dist-PlsLrwz8.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{editor-builder-BXT6F3Hl.cjs → editor-builder-DFqbiatl.cjs} +2 -2
- package/dist/{editor-builder-BXT6F3Hl.cjs.map → editor-builder-DFqbiatl.cjs.map} +1 -1
- package/dist/{editor-builder-Bywazgj1.js → editor-builder-qPFmAnZz.js} +2 -2
- package/dist/{editor-builder-Bywazgj1.js.map → editor-builder-qPFmAnZz.js.map} +1 -1
- package/dist/{logs-Cbq2PiQG.js → logs-DIBh_xCk.js} +2 -2
- package/dist/{logs-Cbq2PiQG.js.map → logs-DIBh_xCk.js.map} +1 -1
- package/dist/{logs-BqHVVZBm.cjs → logs-NNur5jkf.cjs} +2 -2
- package/dist/{logs-BqHVVZBm.cjs.map → logs-NNur5jkf.cjs.map} +1 -1
- package/dist/{memory-CtSwODLV.js → memory-DeZ1je-b.js} +5 -6
- package/dist/memory-DeZ1je-b.js.map +1 -0
- package/dist/{memory-dujCippo.cjs → memory-Pj9P9vsl.cjs} +5 -6
- package/dist/memory-Pj9P9vsl.cjs.map +1 -0
- package/dist/{plans-CSLB_JKn.cjs → plans-Dtt4D4-Y.cjs} +3 -3
- package/dist/{plans-CSLB_JKn.cjs.map → plans-Dtt4D4-Y.cjs.map} +1 -1
- package/dist/{plans-DToC_H5z.js → plans-YK-iaKqj.js} +3 -3
- package/dist/{plans-DToC_H5z.js.map → plans-YK-iaKqj.js.map} +1 -1
- package/dist/{probe-image-size-CTKFNI9H.cjs → probe-image-size-C0psF6WM.cjs} +2 -2
- package/dist/{probe-image-size-CTKFNI9H.cjs.map → probe-image-size-C0psF6WM.cjs.map} +1 -1
- package/dist/{probe-image-size-DnRk0ecb.js → probe-image-size-CpV7slsd.js} +2 -2
- package/dist/{probe-image-size-DnRk0ecb.js.map → probe-image-size-CpV7slsd.js.map} +1 -1
- package/dist/{responses-w6B0iv_t.js → responses-CaixIxi0.js} +3 -3
- package/dist/{responses-w6B0iv_t.js.map → responses-CaixIxi0.js.map} +1 -1
- package/dist/{responses-OoIIZ1g6.cjs → responses-Did1x3VK.cjs} +3 -3
- package/dist/{responses-OoIIZ1g6.cjs.map → responses-Did1x3VK.cjs.map} +1 -1
- package/dist/{routes-CIjXlRu7.js → routes-C434Lhz9.js} +16 -16
- package/dist/{routes-CIjXlRu7.js.map → routes-C434Lhz9.js.map} +1 -1
- package/dist/{routes-KTxoRutQ.cjs → routes-rU9Sku0f.cjs} +16 -16
- package/dist/{routes-KTxoRutQ.cjs.map → routes-rU9Sku0f.cjs.map} +1 -1
- package/dist/{schedules-CSkQFQwy.cjs → schedules-CL4IU7kS.cjs} +2 -2
- package/dist/{schedules-CSkQFQwy.cjs.map → schedules-CL4IU7kS.cjs.map} +1 -1
- package/dist/{schedules-DfelziYe.js → schedules-CQPodXrR.js} +2 -2
- package/dist/{schedules-DfelziYe.js.map → schedules-CQPodXrR.js.map} +1 -1
- package/dist/{scores-PdRDQNaC.js → scores-DHnw31S7.js} +2 -2
- package/dist/{scores-PdRDQNaC.js.map → scores-DHnw31S7.js.map} +1 -1
- package/dist/{scores-FzL-bpCC.cjs → scores-K78lAAwd.cjs} +2 -2
- package/dist/{scores-FzL-bpCC.cjs.map → scores-K78lAAwd.cjs.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 +14 -11
- package/dist/server/handlers/agent-controller.cjs.map +1 -1
- package/dist/server/handlers/agent-controller.d.ts +2 -0
- package/dist/server/handlers/agent-controller.d.ts.map +1 -1
- package/dist/server/handlers/agent-controller.js +14 -11
- package/dist/server/handlers/agent-controller.js.map +1 -1
- package/dist/server/handlers/agents.cjs +1 -1
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.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/conversations.cjs +1 -1
- package/dist/server/handlers/conversations.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/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/memory.cjs +1 -1
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability-new-endpoints.d.ts +2 -10
- package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
- 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 +1 -1
- package/dist/server/handlers/stored-agent-favorites.js +1 -1
- package/dist/server/handlers/stored-agents.cjs +1 -1
- package/dist/server/handlers/stored-agents.js +1 -1
- 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/system.cjs +1 -1
- package/dist/server/handlers/system.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 +2 -1
- package/dist/server/handlers/utils.d.ts +17 -2
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/workflow-builder.cjs +1 -1
- package/dist/server/handlers/workflow-builder.js +1 -1
- package/dist/server/handlers/workflows.cjs +1 -1
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +11 -11
- package/dist/server/handlers.js +11 -11
- package/dist/server/schemas/index.cjs +1 -1
- package/dist/server/schemas/index.js +1 -1
- package/dist/server/server-adapter/index.cjs +1 -1
- package/dist/server/server-adapter/index.js +1 -1
- package/dist/server/server-adapter/routes/observability.d.ts +1 -5
- package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
- package/dist/{tools-CottqeCZ.cjs → tools-CeVJwkPP.cjs} +4 -4
- package/dist/tools-CeVJwkPP.cjs.map +1 -0
- package/dist/{tools-tMPXGAUO.js → tools-hd_ZCJkE.js} +4 -4
- package/dist/tools-hd_ZCJkE.js.map +1 -0
- package/dist/{utils-1UlUJRyC.cjs → utils-BbYUI6Yn.cjs} +32 -7
- package/dist/utils-BbYUI6Yn.cjs.map +1 -0
- package/dist/{utils-DEwjGOpJ.js → utils-DHxjw4Tn.js} +27 -8
- package/dist/utils-DHxjw4Tn.js.map +1 -0
- package/dist/{workflow-builder-CJEajbkw.cjs → workflow-builder-B33pXjdu.cjs} +2 -2
- package/dist/{workflow-builder-CJEajbkw.cjs.map → workflow-builder-B33pXjdu.cjs.map} +1 -1
- package/dist/{workflow-builder-BcVfkods.js → workflow-builder-D4Po74yJ.js} +2 -2
- package/dist/{workflow-builder-BcVfkods.js.map → workflow-builder-D4Po74yJ.js.map} +1 -1
- package/dist/{workflows-CxPsDCnW.cjs → workflows-CiP6r_nw.cjs} +27 -27
- package/dist/workflows-CiP6r_nw.cjs.map +1 -0
- package/dist/{workflows-BjLruwQB.js → workflows-tk1Ixg8M.js} +27 -27
- package/dist/workflows-tk1Ixg8M.js.map +1 -0
- package/package.json +7 -7
- package/dist/agents-DSZgApzs.js.map +0 -1
- package/dist/agents-I0TVb_TM.cjs.map +0 -1
- package/dist/dist-Cci9RRWj.cjs.map +0 -1
- package/dist/dist-bAoX6ick.js.map +0 -1
- package/dist/dist-t_05BTrR.js +0 -1
- package/dist/memory-CtSwODLV.js.map +0 -1
- package/dist/memory-dujCippo.cjs.map +0 -1
- package/dist/tools-CottqeCZ.cjs.map +0 -1
- package/dist/tools-tMPXGAUO.js.map +0 -1
- package/dist/utils-1UlUJRyC.cjs.map +0 -1
- package/dist/utils-DEwjGOpJ.js.map +0 -1
- package/dist/workflows-BjLruwQB.js.map +0 -1
- package/dist/workflows-CxPsDCnW.cjs.map +0 -1
|
@@ -62,6 +62,24 @@ function getPublicWorkflowById(mastra, workflowId) {
|
|
|
62
62
|
const workflows = mastra.listWorkflows();
|
|
63
63
|
return Object.values(workflows).find((workflow) => workflow.id === workflowId) ?? (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : void 0);
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolves the FGA provider a handler should use for this request, following
|
|
67
|
+
* the same auth-mode-aware selection as the route-level checks: Studio auth
|
|
68
|
+
* requests use `studio.fga` when it is configured, and everything else uses
|
|
69
|
+
* `server.fga`.
|
|
70
|
+
*
|
|
71
|
+
* Returns `undefined` when FGA is not configured at all. When FGA is
|
|
72
|
+
* configured but no provider applies to this request (for example `studio.fga`
|
|
73
|
+
* is set and the request used server auth), the request is denied rather than
|
|
74
|
+
* treated as unrestricted.
|
|
75
|
+
*/
|
|
76
|
+
function getHandlerFGAProvider(mastra, requestContext) {
|
|
77
|
+
const studioFga = mastra?.getStudio?.()?.fga;
|
|
78
|
+
const serverFga = mastra?.getServer?.()?.fga;
|
|
79
|
+
if (requestContext?.get("mastra__authMode") === "studio" && studioFga) return studioFga;
|
|
80
|
+
if (serverFga) return serverFga;
|
|
81
|
+
if (studioFga) throw new require_http_exception.HTTPException(403, { message: "Access denied: no FGA provider is configured for this request" });
|
|
82
|
+
}
|
|
65
83
|
function validateBody(body) {
|
|
66
84
|
const errorResponse = Object.entries(body).reduce((acc, [key, value]) => {
|
|
67
85
|
if (!value) acc[key] = `Argument "${key}" is required`;
|
|
@@ -193,7 +211,8 @@ async function validateThreadOwnership(thread, effectiveResourceId) {
|
|
|
193
211
|
*/
|
|
194
212
|
async function enforceThreadAccess({ mastra, requestContext, threadId, thread, effectiveResourceId, permission = MastraFGAPermissions.MEMORY_READ }) {
|
|
195
213
|
await validateThreadOwnership(thread, effectiveResourceId);
|
|
196
|
-
|
|
214
|
+
const fgaProvider = getHandlerFGAProvider(mastra, requestContext);
|
|
215
|
+
if (!fgaProvider) return;
|
|
197
216
|
const user = requestContext?.get("user");
|
|
198
217
|
if (!user || typeof user !== "object") throw new require_http_exception.HTTPException(403, { message: "FGA authorization denied: authenticated user is required" });
|
|
199
218
|
await _mastra_core_memory.MastraMemory.checkThreadFGA({
|
|
@@ -202,7 +221,8 @@ async function enforceThreadAccess({ mastra, requestContext, threadId, thread, e
|
|
|
202
221
|
threadId,
|
|
203
222
|
resourceId: thread?.resourceId ?? effectiveResourceId,
|
|
204
223
|
requestContext,
|
|
205
|
-
permission
|
|
224
|
+
permission,
|
|
225
|
+
fgaProvider
|
|
206
226
|
});
|
|
207
227
|
}
|
|
208
228
|
/**
|
|
@@ -215,10 +235,9 @@ async function enforceThreadAccess({ mastra, requestContext, threadId, thread, e
|
|
|
215
235
|
* an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,
|
|
216
236
|
* as on the thread-transfer route.
|
|
217
237
|
*/
|
|
218
|
-
async function validateRunOwnership(run, effectiveResourceId, mastra) {
|
|
238
|
+
async function validateRunOwnership(run, effectiveResourceId, mastra, requestContext) {
|
|
219
239
|
if (!run) return;
|
|
220
|
-
|
|
221
|
-
if (!(typeof (server?.auth)?.mapUserToResourceId === "function")) {
|
|
240
|
+
if (!(typeof ((mastra?.getServer?.())?.auth)?.mapUserToResourceId === "function")) {
|
|
222
241
|
if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) throw new require_http_exception.HTTPException(403, { message: "Access denied: workflow run belongs to a different resource" });
|
|
223
242
|
return;
|
|
224
243
|
}
|
|
@@ -226,7 +245,7 @@ async function validateRunOwnership(run, effectiveResourceId, mastra) {
|
|
|
226
245
|
if (run.resourceId !== effectiveResourceId) throw new require_http_exception.HTTPException(403, { message: "Access denied: workflow run belongs to a different resource" });
|
|
227
246
|
return;
|
|
228
247
|
}
|
|
229
|
-
if (!
|
|
248
|
+
if (!getHandlerFGAProvider(mastra, requestContext)) throw new require_http_exception.HTTPException(403, { message: "Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access." });
|
|
230
249
|
}
|
|
231
250
|
Object.defineProperty(exports, "MastraFGAPermissions", {
|
|
232
251
|
enumerable: true,
|
|
@@ -264,6 +283,12 @@ Object.defineProperty(exports, "getEffectiveThreadId", {
|
|
|
264
283
|
return getEffectiveThreadId;
|
|
265
284
|
}
|
|
266
285
|
});
|
|
286
|
+
Object.defineProperty(exports, "getHandlerFGAProvider", {
|
|
287
|
+
enumerable: true,
|
|
288
|
+
get: function() {
|
|
289
|
+
return getHandlerFGAProvider;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
267
292
|
Object.defineProperty(exports, "getPublicWorkflowById", {
|
|
268
293
|
enumerable: true,
|
|
269
294
|
get: function() {
|
|
@@ -325,4 +350,4 @@ Object.defineProperty(exports, "validateThreadOwnership", {
|
|
|
325
350
|
}
|
|
326
351
|
});
|
|
327
352
|
|
|
328
|
-
//# sourceMappingURL=utils-
|
|
353
|
+
//# sourceMappingURL=utils-BbYUI6Yn.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BbYUI6Yn.cjs","names":["authEE","HTTPException","isReservedRequestContextKey","MASTRA_RESOURCE_ID_KEY","MastraMemory"],"sources":["../src/server/fga-permissions.ts","../src/server/handlers/utils.ts"],"sourcesContent":["/**\n * Safe re-export of `MastraFGAPermissions` from `@mastra/core/auth/ee`.\n *\n * Why this shim exists:\n * `MastraFGAPermissions` was introduced in `@mastra/core@1.32.0`. Earlier\n * versions of `@mastra/core` ship `@mastra/core/auth/ee` but do not export\n * this constant. A direct named import (`import { MastraFGAPermissions }\n * from '@mastra/core/auth/ee'`) fails at ESM link time when this version\n * of `@mastra/server` is paired with `@mastra/core < 1.32.0`, taking the\n * entire user bundle down before any code runs.\n *\n * A namespace import tolerates missing names — `ns.MissingExport` is just\n * `undefined`, no link-time error. We then expose the permission map.\n *\n * Fallback values:\n * If the consuming `@mastra/core` does not export `MastraFGAPermissions`,\n * we substitute a hardcoded map of the canonical permission strings used\n * by routes in `@mastra/server`. This preserves the explicit RBAC\n * permission overrides those routes already had as string literals in\n * `@mastra/server@1.31.0` (e.g. `requiresPermission: \"agents:execute\"`\n * on `/v1/responses`). Without this fallback, `requiresPermission` would\n * be `undefined` on old core and the auth layer would derive the wrong\n * permission from the route path (e.g. `v1:write` instead of\n * `agents:execute`), breaking RBAC users who upgrade `@mastra/server`\n * but stay on `@mastra/core@1.31.0`.\n *\n * Once the consuming `@mastra/core` is on `1.32.0+` the values are real\n * and behaviour is identical to a direct named import.\n */\n\nimport * as authEE from '@mastra/core/auth/ee';\n\n// Canonical strings for the FGA permission keys actually referenced by\n// `@mastra/server` source. Mirrors `MastraFGAPermissions` in\n// `@mastra/core@1.32.0+` for these specific keys, and matches the string\n// literals previously hardcoded on the same routes in `@mastra/server@1.31.0`.\nconst FALLBACK_PERMISSIONS = {\n AGENTS_CREATE: 'agents:create',\n AGENTS_DELETE: 'agents:delete',\n AGENTS_EXECUTE: 'agents:execute',\n AGENTS_READ: 'agents:read',\n MEMORY_DELETE: 'memory:delete',\n MEMORY_READ: 'memory:read',\n MEMORY_WRITE: 'memory:write',\n TOOLS_EXECUTE: 'tools:execute',\n TOOLS_READ: 'tools:read',\n STORED_WORKFLOWS_READ: 'stored-workflows:read',\n STORED_WORKFLOWS_WRITE: 'stored-workflows:write',\n WORKFLOWS_EXECUTE: 'workflows:execute',\n WORKFLOWS_READ: 'workflows:read',\n} as const;\n\nconst realPermissions = (authEE as any).MastraFGAPermissions;\n\n// Typed as `any` on purpose: consumers of `@mastra/server` may run their\n// typecheck against a `@mastra/core` that doesn't export `MastraFGAPermissions`\n// (anything < 1.32.0). Pinning to the real type would push that name into the\n// emitted `.d.ts` and break downstream typecheck. `any` lets the property\n// accesses (`MastraFGAPermissions.AGENTS_READ`) flow through cleanly on every\n// supported core.\nexport const MastraFGAPermissions: any =\n realPermissions && Object.keys(realPermissions).length > 0 ? realPermissions : FALLBACK_PERMISSIONS;\n","import type { Mastra } from '@mastra/core';\nimport type { IFGAProvider, MastraFGAPermissionInput } from '@mastra/core/auth/ee';\nimport type { RequestContext } from '@mastra/core/di';\nimport { MastraMemory } from '@mastra/core/memory';\nimport type { Workflow } from '@mastra/core/workflows';\nimport {\n MASTRA_AUTH_MODE_KEY,\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n isReservedRequestContextKey,\n} from '../constants';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\n\n/**\n * Resolves a workflow by id or registration key from the set Mastra exposes\n * publicly. Unlike `mastra.getWorkflowById`, this excludes hidden internal\n * workflows (e.g. a durable agent's backing loop), which must never be\n * runnable through HTTP routes.\n */\nexport function getPublicWorkflowById(mastra: Mastra, workflowId: string): Workflow | undefined {\n const workflows = mastra.listWorkflows();\n return (\n Object.values(workflows).find(workflow => workflow.id === workflowId) ??\n (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : undefined)\n );\n}\n\n/**\n * Resolves the FGA provider a handler should use for this request, following\n * the same auth-mode-aware selection as the route-level checks: Studio auth\n * requests use `studio.fga` when it is configured, and everything else uses\n * `server.fga`.\n *\n * Returns `undefined` when FGA is not configured at all. When FGA is\n * configured but no provider applies to this request (for example `studio.fga`\n * is set and the request used server auth), the request is denied rather than\n * treated as unrestricted.\n */\nexport function getHandlerFGAProvider(mastra: any, requestContext?: RequestContext): IFGAProvider | undefined {\n const studioFga = mastra?.getStudio?.()?.fga as IFGAProvider | undefined;\n const serverFga = mastra?.getServer?.()?.fga as IFGAProvider | undefined;\n\n if (requestContext?.get(MASTRA_AUTH_MODE_KEY) === 'studio' && studioFga) return studioFga;\n if (serverFga) return serverFga;\n if (studioFga) {\n throw new HTTPException(403, { message: 'Access denied: no FGA provider is configured for this request' });\n }\n return undefined;\n}\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n if (!value) {\n acc[key] = `Argument \"${key}\" is required`;\n }\n return acc;\n }, {});\n\n if (Object.keys(errorResponse).length > 0) {\n throw new HTTPException(400, { message: Object.values(errorResponse)[0] });\n }\n}\n\n/**\n * sanitizes the body by removing disallowed keys.\n * @param body body to sanitize\n * @param disallowedKeys keys to remove from the body\n */\nexport function sanitizeBody(body: Record<string, unknown>, disallowedKeys: string[]) {\n for (const key of disallowedKeys) {\n if (key in body) {\n delete body[key];\n }\n }\n}\n\nconst CREDENTIAL_HEADER_NAMES = new Set([\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'api-key',\n 'x-goog-api-key',\n 'cookie',\n]);\n\n/**\n * Removes credential-bearing headers from client-supplied `modelSettings.headers`\n * so a caller's own auth (e.g. the app's bearer token) can never override the\n * provider credential configured on the server. Non-credential headers are kept.\n */\nexport function stripClientCredentialHeaders(body: Record<string, unknown>) {\n const modelSettings = body.modelSettings;\n if (!modelSettings || typeof modelSettings !== 'object') return;\n const headers = (modelSettings as { headers?: unknown }).headers;\n if (!headers || typeof headers !== 'object') return;\n\n const kept = Object.fromEntries(\n Object.entries(headers).filter(([name]) => !CREDENTIAL_HEADER_NAMES.has(name.toLowerCase())),\n );\n body.modelSettings = { ...modelSettings, headers: kept };\n}\n\nexport function parsePerPage(\n value: string | undefined,\n defaultValue: number = 100,\n max: number = 1000,\n): number | false {\n const normalized = (value || '').trim().toLowerCase();\n // Handle explicit false to bypass pagination\n if (normalized === 'false') {\n return false;\n }\n const parsed = parseInt(value || String(defaultValue), 10);\n if (isNaN(parsed)) return defaultValue;\n return Math.min(max, Math.max(1, parsed));\n}\n\n/**\n * Parses filter query parameters into a key-value object.\n */\nexport function parseFilters(filters: string | string[] | undefined): Record<string, string> | undefined {\n if (!filters) return undefined;\n\n return Object.fromEntries(\n (Array.isArray(filters) ? filters : [filters]).map((attr: string) => {\n const [key, ...valueParts] = attr.split(':');\n const value = valueParts.join(':'); // ✅ Handles colons in values\n return [key, value];\n }),\n );\n}\n\n/**\n * Merges a body-supplied requestContext into the trusted server RequestContext.\n * The server context is authoritative: reserved keys are skipped and body values\n * only fill keys the server context has not already set.\n */\nexport function mergeBodyRequestContext(serverRequestContext: RequestContext, bodyRequestContext: unknown): void {\n if (!bodyRequestContext || typeof bodyRequestContext !== 'object') {\n return;\n }\n\n for (const [key, value] of Object.entries(bodyRequestContext)) {\n if (isReservedRequestContextKey(key)) continue;\n if (serverRequestContext.get(key) === undefined) {\n serverRequestContext.set(key, value);\n }\n }\n}\n\n// ============================================================================\n// Authorization Utilities\n// ============================================================================\n\n/**\n * Gets the effective resourceId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveResourceId(\n requestContext: RequestContext | undefined,\n clientResourceId: string | undefined,\n): string | undefined {\n const contextResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n return contextResourceId || clientResourceId;\n}\n\n/**\n * Returns the resource id resolved from the request context alone (set via\n * `mapUserToResourceId` or the `x-resource-id` header), ignoring any\n * client-provided value. Its presence indicates a resource-scoped caller;\n * its absence indicates a privileged/service context.\n */\nexport function getContextResourceId(requestContext: RequestContext | undefined): string | undefined {\n return requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n}\n\n/**\n * Ensures a memory request has a resolvable resource ID. The body's\n * `memory.resource` is optional so authenticated setups can rely on the\n * server-derived resource ID (MASTRA_RESOURCE_ID_KEY set via mapUserToResourceId).\n * When neither the body nor the request context provides one, reject with a\n * clear 400 instead of failing deep inside agent execution.\n */\nexport function requireEffectiveResourceId(\n effectiveResourceId: string | undefined,\n): asserts effectiveResourceId is string {\n if (!effectiveResourceId) {\n throw new HTTPException(400, {\n message:\n 'A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.',\n });\n }\n}\n\n/**\n * Gets the effective threadId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveThreadId(\n requestContext: RequestContext | undefined,\n clientThreadId: string | undefined,\n): string | undefined {\n const contextThreadId = requestContext?.get(MASTRA_THREAD_ID_KEY) as string | undefined;\n return contextThreadId || clientThreadId;\n}\n\n/**\n * Applies the effective threadId to a client memory thread option. Object\n * threads keep their other fields (metadata, title, ...) so they reach thread\n * creation; a client-supplied resourceId is dropped because the server decides\n * the resource.\n */\nexport function applyEffectiveThreadId<T extends string | { id: string } | undefined>(\n thread: T,\n effectiveThreadId: string | undefined,\n): T | string {\n if (!effectiveThreadId) return thread;\n if (thread && typeof thread === 'object') {\n const { resourceId: _resourceId, ...fields } = thread as { id: string; resourceId?: unknown };\n return { ...fields, id: effectiveThreadId } as T;\n }\n return effectiveThreadId;\n}\n\n/**\n * Validates that a thread belongs to the specified resourceId.\n * Throws 403 if the thread exists but belongs to a different resource.\n * Threads with no resourceId are accessible to all (shared threads).\n */\nexport async function validateThreadOwnership(\n thread: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n): Promise<void> {\n if (thread && effectiveResourceId && thread.resourceId && thread.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: thread belongs to a different resource' });\n }\n}\n\n/**\n * Validates both coarse resource ownership and fine-grained thread access.\n * FGA enforcement is a no-op when no FGA provider is configured.\n */\nexport async function enforceThreadAccess({\n mastra,\n requestContext,\n threadId,\n thread,\n effectiveResourceId,\n permission = MastraFGAPermissions.MEMORY_READ,\n}: {\n mastra: any;\n requestContext?: RequestContext;\n threadId: string;\n thread?: { resourceId?: string | null } | null;\n effectiveResourceId?: string;\n permission?: MastraFGAPermissionInput;\n}): Promise<void> {\n await validateThreadOwnership(thread, effectiveResourceId);\n\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n if (!fgaProvider) {\n return;\n }\n\n const user = requestContext?.get('user');\n if (!user || typeof user !== 'object') {\n throw new HTTPException(403, { message: 'FGA authorization denied: authenticated user is required' });\n }\n\n await MastraMemory.checkThreadFGA({\n mastra,\n user: user as { id: string; [key: string]: unknown },\n threadId,\n resourceId: thread?.resourceId ?? effectiveResourceId,\n requestContext,\n permission,\n fgaProvider,\n });\n}\n\n/**\n * Validates that a caller may act on a workflow run.\n *\n * Without `server.auth.mapUserToResourceId` there is no tenancy model, and only a mismatch\n * between two present resource ids is denied. With a mapper, a resource-scoped caller may only\n * act on runs it owns (an owner-less run is not its run). An unscoped caller is a\n * privileged/service context (see getContextResourceId), but that privilege is only granted when\n * an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,\n * as on the thread-transfer route.\n */\nexport async function validateRunOwnership(\n run: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n mastra?: {\n getServer?: () => { auth?: unknown; fga?: unknown } | undefined;\n getStudio?: () => { fga?: unknown } | undefined;\n },\n requestContext?: RequestContext,\n): Promise<void> {\n if (!run) return;\n const server = mastra?.getServer?.();\n const tenancy =\n typeof (server?.auth as { mapUserToResourceId?: unknown } | undefined)?.mapUserToResourceId === 'function';\n if (!tenancy) {\n if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (effectiveResourceId) {\n if (run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (!getHandlerFGAProvider(mastra, requestContext)) {\n throw new HTTPException(403, {\n message:\n 'Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access.',\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,uBAAuB;CAC3B,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,eAAe;CACf,aAAa;CACb,cAAc;CACd,eAAe;CACf,YAAY;CACZ,uBAAuB;CACvB,wBAAwB;CACxB,mBAAmB;CACnB,gBAAgB;AAClB;AAEA,MAAM,kBAAmBA,qBAAe;AAQxC,MAA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AAI,cAAc,IAAI,eAAe,qBAC9D,MAAM,IAAIH,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,qBAAqB;EACvB,IAAI,IAAI,eAAe,qBACrB,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,CAAC,sBAAsB,QAAQ,cAAc,GAC/C,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAC3B,SACE,6IACJ,CAAC;AAEL"}
|
|
@@ -60,6 +60,24 @@ function getPublicWorkflowById(mastra, workflowId) {
|
|
|
60
60
|
const workflows = mastra.listWorkflows();
|
|
61
61
|
return Object.values(workflows).find((workflow) => workflow.id === workflowId) ?? (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : void 0);
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the FGA provider a handler should use for this request, following
|
|
65
|
+
* the same auth-mode-aware selection as the route-level checks: Studio auth
|
|
66
|
+
* requests use `studio.fga` when it is configured, and everything else uses
|
|
67
|
+
* `server.fga`.
|
|
68
|
+
*
|
|
69
|
+
* Returns `undefined` when FGA is not configured at all. When FGA is
|
|
70
|
+
* configured but no provider applies to this request (for example `studio.fga`
|
|
71
|
+
* is set and the request used server auth), the request is denied rather than
|
|
72
|
+
* treated as unrestricted.
|
|
73
|
+
*/
|
|
74
|
+
function getHandlerFGAProvider(mastra, requestContext) {
|
|
75
|
+
const studioFga = mastra?.getStudio?.()?.fga;
|
|
76
|
+
const serverFga = mastra?.getServer?.()?.fga;
|
|
77
|
+
if (requestContext?.get("mastra__authMode") === "studio" && studioFga) return studioFga;
|
|
78
|
+
if (serverFga) return serverFga;
|
|
79
|
+
if (studioFga) throw new HTTPException(403, { message: "Access denied: no FGA provider is configured for this request" });
|
|
80
|
+
}
|
|
63
81
|
function validateBody(body) {
|
|
64
82
|
const errorResponse = Object.entries(body).reduce((acc, [key, value]) => {
|
|
65
83
|
if (!value) acc[key] = `Argument "${key}" is required`;
|
|
@@ -191,7 +209,8 @@ async function validateThreadOwnership(thread, effectiveResourceId) {
|
|
|
191
209
|
*/
|
|
192
210
|
async function enforceThreadAccess({ mastra, requestContext, threadId, thread, effectiveResourceId, permission = MastraFGAPermissions.MEMORY_READ }) {
|
|
193
211
|
await validateThreadOwnership(thread, effectiveResourceId);
|
|
194
|
-
|
|
212
|
+
const fgaProvider = getHandlerFGAProvider(mastra, requestContext);
|
|
213
|
+
if (!fgaProvider) return;
|
|
195
214
|
const user = requestContext?.get("user");
|
|
196
215
|
if (!user || typeof user !== "object") throw new HTTPException(403, { message: "FGA authorization denied: authenticated user is required" });
|
|
197
216
|
await MastraMemory.checkThreadFGA({
|
|
@@ -200,7 +219,8 @@ async function enforceThreadAccess({ mastra, requestContext, threadId, thread, e
|
|
|
200
219
|
threadId,
|
|
201
220
|
resourceId: thread?.resourceId ?? effectiveResourceId,
|
|
202
221
|
requestContext,
|
|
203
|
-
permission
|
|
222
|
+
permission,
|
|
223
|
+
fgaProvider
|
|
204
224
|
});
|
|
205
225
|
}
|
|
206
226
|
/**
|
|
@@ -213,10 +233,9 @@ async function enforceThreadAccess({ mastra, requestContext, threadId, thread, e
|
|
|
213
233
|
* an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,
|
|
214
234
|
* as on the thread-transfer route.
|
|
215
235
|
*/
|
|
216
|
-
async function validateRunOwnership(run, effectiveResourceId, mastra) {
|
|
236
|
+
async function validateRunOwnership(run, effectiveResourceId, mastra, requestContext) {
|
|
217
237
|
if (!run) return;
|
|
218
|
-
|
|
219
|
-
if (!(typeof (server?.auth)?.mapUserToResourceId === "function")) {
|
|
238
|
+
if (!(typeof ((mastra?.getServer?.())?.auth)?.mapUserToResourceId === "function")) {
|
|
220
239
|
if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) throw new HTTPException(403, { message: "Access denied: workflow run belongs to a different resource" });
|
|
221
240
|
return;
|
|
222
241
|
}
|
|
@@ -224,8 +243,8 @@ async function validateRunOwnership(run, effectiveResourceId, mastra) {
|
|
|
224
243
|
if (run.resourceId !== effectiveResourceId) throw new HTTPException(403, { message: "Access denied: workflow run belongs to a different resource" });
|
|
225
244
|
return;
|
|
226
245
|
}
|
|
227
|
-
if (!
|
|
246
|
+
if (!getHandlerFGAProvider(mastra, requestContext)) throw new HTTPException(403, { message: "Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access." });
|
|
228
247
|
}
|
|
229
|
-
export { getEffectiveThreadId as a,
|
|
248
|
+
export { MastraFGAPermissions as _, getEffectiveThreadId as a, mergeBodyRequestContext as c, requireEffectiveResourceId as d, sanitizeBody as f, validateThreadOwnership as g, validateRunOwnership as h, getEffectiveResourceId as i, parseFilters as l, validateBody as m, enforceThreadAccess as n, getHandlerFGAProvider as o, stripClientCredentialHeaders as p, getContextResourceId as r, getPublicWorkflowById as s, applyEffectiveThreadId as t, parsePerPage as u };
|
|
230
249
|
|
|
231
|
-
//# sourceMappingURL=utils-
|
|
250
|
+
//# sourceMappingURL=utils-DHxjw4Tn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DHxjw4Tn.js","names":[],"sources":["../src/server/fga-permissions.ts","../src/server/handlers/utils.ts"],"sourcesContent":["/**\n * Safe re-export of `MastraFGAPermissions` from `@mastra/core/auth/ee`.\n *\n * Why this shim exists:\n * `MastraFGAPermissions` was introduced in `@mastra/core@1.32.0`. Earlier\n * versions of `@mastra/core` ship `@mastra/core/auth/ee` but do not export\n * this constant. A direct named import (`import { MastraFGAPermissions }\n * from '@mastra/core/auth/ee'`) fails at ESM link time when this version\n * of `@mastra/server` is paired with `@mastra/core < 1.32.0`, taking the\n * entire user bundle down before any code runs.\n *\n * A namespace import tolerates missing names — `ns.MissingExport` is just\n * `undefined`, no link-time error. We then expose the permission map.\n *\n * Fallback values:\n * If the consuming `@mastra/core` does not export `MastraFGAPermissions`,\n * we substitute a hardcoded map of the canonical permission strings used\n * by routes in `@mastra/server`. This preserves the explicit RBAC\n * permission overrides those routes already had as string literals in\n * `@mastra/server@1.31.0` (e.g. `requiresPermission: \"agents:execute\"`\n * on `/v1/responses`). Without this fallback, `requiresPermission` would\n * be `undefined` on old core and the auth layer would derive the wrong\n * permission from the route path (e.g. `v1:write` instead of\n * `agents:execute`), breaking RBAC users who upgrade `@mastra/server`\n * but stay on `@mastra/core@1.31.0`.\n *\n * Once the consuming `@mastra/core` is on `1.32.0+` the values are real\n * and behaviour is identical to a direct named import.\n */\n\nimport * as authEE from '@mastra/core/auth/ee';\n\n// Canonical strings for the FGA permission keys actually referenced by\n// `@mastra/server` source. Mirrors `MastraFGAPermissions` in\n// `@mastra/core@1.32.0+` for these specific keys, and matches the string\n// literals previously hardcoded on the same routes in `@mastra/server@1.31.0`.\nconst FALLBACK_PERMISSIONS = {\n AGENTS_CREATE: 'agents:create',\n AGENTS_DELETE: 'agents:delete',\n AGENTS_EXECUTE: 'agents:execute',\n AGENTS_READ: 'agents:read',\n MEMORY_DELETE: 'memory:delete',\n MEMORY_READ: 'memory:read',\n MEMORY_WRITE: 'memory:write',\n TOOLS_EXECUTE: 'tools:execute',\n TOOLS_READ: 'tools:read',\n STORED_WORKFLOWS_READ: 'stored-workflows:read',\n STORED_WORKFLOWS_WRITE: 'stored-workflows:write',\n WORKFLOWS_EXECUTE: 'workflows:execute',\n WORKFLOWS_READ: 'workflows:read',\n} as const;\n\nconst realPermissions = (authEE as any).MastraFGAPermissions;\n\n// Typed as `any` on purpose: consumers of `@mastra/server` may run their\n// typecheck against a `@mastra/core` that doesn't export `MastraFGAPermissions`\n// (anything < 1.32.0). Pinning to the real type would push that name into the\n// emitted `.d.ts` and break downstream typecheck. `any` lets the property\n// accesses (`MastraFGAPermissions.AGENTS_READ`) flow through cleanly on every\n// supported core.\nexport const MastraFGAPermissions: any =\n realPermissions && Object.keys(realPermissions).length > 0 ? realPermissions : FALLBACK_PERMISSIONS;\n","import type { Mastra } from '@mastra/core';\nimport type { IFGAProvider, MastraFGAPermissionInput } from '@mastra/core/auth/ee';\nimport type { RequestContext } from '@mastra/core/di';\nimport { MastraMemory } from '@mastra/core/memory';\nimport type { Workflow } from '@mastra/core/workflows';\nimport {\n MASTRA_AUTH_MODE_KEY,\n MASTRA_RESOURCE_ID_KEY,\n MASTRA_THREAD_ID_KEY,\n isReservedRequestContextKey,\n} from '../constants';\nimport { MastraFGAPermissions } from '../fga-permissions';\nimport { HTTPException } from '../http-exception';\n\n/**\n * Resolves a workflow by id or registration key from the set Mastra exposes\n * publicly. Unlike `mastra.getWorkflowById`, this excludes hidden internal\n * workflows (e.g. a durable agent's backing loop), which must never be\n * runnable through HTTP routes.\n */\nexport function getPublicWorkflowById(mastra: Mastra, workflowId: string): Workflow | undefined {\n const workflows = mastra.listWorkflows();\n return (\n Object.values(workflows).find(workflow => workflow.id === workflowId) ??\n (Object.hasOwn(workflows, workflowId) ? workflows[workflowId] : undefined)\n );\n}\n\n/**\n * Resolves the FGA provider a handler should use for this request, following\n * the same auth-mode-aware selection as the route-level checks: Studio auth\n * requests use `studio.fga` when it is configured, and everything else uses\n * `server.fga`.\n *\n * Returns `undefined` when FGA is not configured at all. When FGA is\n * configured but no provider applies to this request (for example `studio.fga`\n * is set and the request used server auth), the request is denied rather than\n * treated as unrestricted.\n */\nexport function getHandlerFGAProvider(mastra: any, requestContext?: RequestContext): IFGAProvider | undefined {\n const studioFga = mastra?.getStudio?.()?.fga as IFGAProvider | undefined;\n const serverFga = mastra?.getServer?.()?.fga as IFGAProvider | undefined;\n\n if (requestContext?.get(MASTRA_AUTH_MODE_KEY) === 'studio' && studioFga) return studioFga;\n if (serverFga) return serverFga;\n if (studioFga) {\n throw new HTTPException(403, { message: 'Access denied: no FGA provider is configured for this request' });\n }\n return undefined;\n}\n\n// Validation helper\nexport function validateBody(body: Record<string, unknown>) {\n const errorResponse = Object.entries(body).reduce<Record<string, string>>((acc, [key, value]) => {\n if (!value) {\n acc[key] = `Argument \"${key}\" is required`;\n }\n return acc;\n }, {});\n\n if (Object.keys(errorResponse).length > 0) {\n throw new HTTPException(400, { message: Object.values(errorResponse)[0] });\n }\n}\n\n/**\n * sanitizes the body by removing disallowed keys.\n * @param body body to sanitize\n * @param disallowedKeys keys to remove from the body\n */\nexport function sanitizeBody(body: Record<string, unknown>, disallowedKeys: string[]) {\n for (const key of disallowedKeys) {\n if (key in body) {\n delete body[key];\n }\n }\n}\n\nconst CREDENTIAL_HEADER_NAMES = new Set([\n 'authorization',\n 'proxy-authorization',\n 'x-api-key',\n 'api-key',\n 'x-goog-api-key',\n 'cookie',\n]);\n\n/**\n * Removes credential-bearing headers from client-supplied `modelSettings.headers`\n * so a caller's own auth (e.g. the app's bearer token) can never override the\n * provider credential configured on the server. Non-credential headers are kept.\n */\nexport function stripClientCredentialHeaders(body: Record<string, unknown>) {\n const modelSettings = body.modelSettings;\n if (!modelSettings || typeof modelSettings !== 'object') return;\n const headers = (modelSettings as { headers?: unknown }).headers;\n if (!headers || typeof headers !== 'object') return;\n\n const kept = Object.fromEntries(\n Object.entries(headers).filter(([name]) => !CREDENTIAL_HEADER_NAMES.has(name.toLowerCase())),\n );\n body.modelSettings = { ...modelSettings, headers: kept };\n}\n\nexport function parsePerPage(\n value: string | undefined,\n defaultValue: number = 100,\n max: number = 1000,\n): number | false {\n const normalized = (value || '').trim().toLowerCase();\n // Handle explicit false to bypass pagination\n if (normalized === 'false') {\n return false;\n }\n const parsed = parseInt(value || String(defaultValue), 10);\n if (isNaN(parsed)) return defaultValue;\n return Math.min(max, Math.max(1, parsed));\n}\n\n/**\n * Parses filter query parameters into a key-value object.\n */\nexport function parseFilters(filters: string | string[] | undefined): Record<string, string> | undefined {\n if (!filters) return undefined;\n\n return Object.fromEntries(\n (Array.isArray(filters) ? filters : [filters]).map((attr: string) => {\n const [key, ...valueParts] = attr.split(':');\n const value = valueParts.join(':'); // ✅ Handles colons in values\n return [key, value];\n }),\n );\n}\n\n/**\n * Merges a body-supplied requestContext into the trusted server RequestContext.\n * The server context is authoritative: reserved keys are skipped and body values\n * only fill keys the server context has not already set.\n */\nexport function mergeBodyRequestContext(serverRequestContext: RequestContext, bodyRequestContext: unknown): void {\n if (!bodyRequestContext || typeof bodyRequestContext !== 'object') {\n return;\n }\n\n for (const [key, value] of Object.entries(bodyRequestContext)) {\n if (isReservedRequestContextKey(key)) continue;\n if (serverRequestContext.get(key) === undefined) {\n serverRequestContext.set(key, value);\n }\n }\n}\n\n// ============================================================================\n// Authorization Utilities\n// ============================================================================\n\n/**\n * Gets the effective resourceId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveResourceId(\n requestContext: RequestContext | undefined,\n clientResourceId: string | undefined,\n): string | undefined {\n const contextResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n return contextResourceId || clientResourceId;\n}\n\n/**\n * Returns the resource id resolved from the request context alone (set via\n * `mapUserToResourceId` or the `x-resource-id` header), ignoring any\n * client-provided value. Its presence indicates a resource-scoped caller;\n * its absence indicates a privileged/service context.\n */\nexport function getContextResourceId(requestContext: RequestContext | undefined): string | undefined {\n return requestContext?.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n}\n\n/**\n * Ensures a memory request has a resolvable resource ID. The body's\n * `memory.resource` is optional so authenticated setups can rely on the\n * server-derived resource ID (MASTRA_RESOURCE_ID_KEY set via mapUserToResourceId).\n * When neither the body nor the request context provides one, reject with a\n * clear 400 instead of failing deep inside agent execution.\n */\nexport function requireEffectiveResourceId(\n effectiveResourceId: string | undefined,\n): asserts effectiveResourceId is string {\n if (!effectiveResourceId) {\n throw new HTTPException(400, {\n message:\n 'A resource ID is required when using memory. Provide memory.resource in the request body, or configure server auth with mapUserToResourceId to derive it from the authenticated user.',\n });\n }\n}\n\n/**\n * Gets the effective threadId, preferring the reserved key from requestContext\n * over client-provided values for security.\n */\nexport function getEffectiveThreadId(\n requestContext: RequestContext | undefined,\n clientThreadId: string | undefined,\n): string | undefined {\n const contextThreadId = requestContext?.get(MASTRA_THREAD_ID_KEY) as string | undefined;\n return contextThreadId || clientThreadId;\n}\n\n/**\n * Applies the effective threadId to a client memory thread option. Object\n * threads keep their other fields (metadata, title, ...) so they reach thread\n * creation; a client-supplied resourceId is dropped because the server decides\n * the resource.\n */\nexport function applyEffectiveThreadId<T extends string | { id: string } | undefined>(\n thread: T,\n effectiveThreadId: string | undefined,\n): T | string {\n if (!effectiveThreadId) return thread;\n if (thread && typeof thread === 'object') {\n const { resourceId: _resourceId, ...fields } = thread as { id: string; resourceId?: unknown };\n return { ...fields, id: effectiveThreadId } as T;\n }\n return effectiveThreadId;\n}\n\n/**\n * Validates that a thread belongs to the specified resourceId.\n * Throws 403 if the thread exists but belongs to a different resource.\n * Threads with no resourceId are accessible to all (shared threads).\n */\nexport async function validateThreadOwnership(\n thread: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n): Promise<void> {\n if (thread && effectiveResourceId && thread.resourceId && thread.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: thread belongs to a different resource' });\n }\n}\n\n/**\n * Validates both coarse resource ownership and fine-grained thread access.\n * FGA enforcement is a no-op when no FGA provider is configured.\n */\nexport async function enforceThreadAccess({\n mastra,\n requestContext,\n threadId,\n thread,\n effectiveResourceId,\n permission = MastraFGAPermissions.MEMORY_READ,\n}: {\n mastra: any;\n requestContext?: RequestContext;\n threadId: string;\n thread?: { resourceId?: string | null } | null;\n effectiveResourceId?: string;\n permission?: MastraFGAPermissionInput;\n}): Promise<void> {\n await validateThreadOwnership(thread, effectiveResourceId);\n\n const fgaProvider = getHandlerFGAProvider(mastra, requestContext);\n if (!fgaProvider) {\n return;\n }\n\n const user = requestContext?.get('user');\n if (!user || typeof user !== 'object') {\n throw new HTTPException(403, { message: 'FGA authorization denied: authenticated user is required' });\n }\n\n await MastraMemory.checkThreadFGA({\n mastra,\n user: user as { id: string; [key: string]: unknown },\n threadId,\n resourceId: thread?.resourceId ?? effectiveResourceId,\n requestContext,\n permission,\n fgaProvider,\n });\n}\n\n/**\n * Validates that a caller may act on a workflow run.\n *\n * Without `server.auth.mapUserToResourceId` there is no tenancy model, and only a mismatch\n * between two present resource ids is denied. With a mapper, a resource-scoped caller may only\n * act on runs it owns (an owner-less run is not its run). An unscoped caller is a\n * privileged/service context (see getContextResourceId), but that privilege is only granted when\n * an FGA provider authorizes the route; otherwise it is refused rather than granted implicitly,\n * as on the thread-transfer route.\n */\nexport async function validateRunOwnership(\n run: { resourceId?: string | null } | null | undefined,\n effectiveResourceId: string | undefined,\n mastra?: {\n getServer?: () => { auth?: unknown; fga?: unknown } | undefined;\n getStudio?: () => { fga?: unknown } | undefined;\n },\n requestContext?: RequestContext,\n): Promise<void> {\n if (!run) return;\n const server = mastra?.getServer?.();\n const tenancy =\n typeof (server?.auth as { mapUserToResourceId?: unknown } | undefined)?.mapUserToResourceId === 'function';\n if (!tenancy) {\n if (effectiveResourceId && run.resourceId && run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (effectiveResourceId) {\n if (run.resourceId !== effectiveResourceId) {\n throw new HTTPException(403, { message: 'Access denied: workflow run belongs to a different resource' });\n }\n return;\n }\n if (!getHandlerFGAProvider(mastra, requestContext)) {\n throw new HTTPException(403, {\n message:\n 'Access denied: unscoped workflow run access requires explicit authorization. Configure an FGA provider to authorize privileged run access.',\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,uBAAuB;CAC3B,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,eAAe;CACf,aAAa;CACb,cAAc;CACd,eAAe;CACf,YAAY;CACZ,uBAAuB;CACvB,wBAAwB;CACxB,mBAAmB;CACnB,gBAAgB;AAClB;AAEA,MAAM,kBAAmB,OAAe;AAQxC,MAAa,uBACX,mBAAmB,OAAO,KAAK,eAAe,CAAC,CAAC,SA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AAI,eAAe,qBACrB,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,8DAA8D,CAAC;EAEzG;CACF;CACA,IAAI,CAAC,sBAAsB,QAAQ,cAAc,GAC/C,MAAM,IAAI,cAAc,KAAK,EAC3B,SACE,6IACJ,CAAC;AAEL"}
|
|
@@ -2,7 +2,7 @@ const require_http_exception = require("./http-exception-Co3MbFUf.cjs");
|
|
|
2
2
|
const require_agents = require("./agents-vFpMvK3w.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-
|
|
5
|
+
const require_utils = require("./utils-BbYUI6Yn.cjs");
|
|
6
6
|
const require_editor_builder = require("./editor-builder-8li-nXor.cjs");
|
|
7
7
|
let zod_v4 = require("zod/v4");
|
|
8
8
|
// src/server/schemas/workflow-builder.ts
|
|
@@ -110,4 +110,4 @@ Object.defineProperty(exports, "STREAM_WORKFLOW_BUILDER_ROUTE", {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
//# sourceMappingURL=workflow-builder-
|
|
113
|
+
//# sourceMappingURL=workflow-builder-B33pXjdu.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-builder-
|
|
1
|
+
{"version":3,"file":"workflow-builder-B33pXjdu.cjs","names":["z","builderModelPolicySchema","createRoute","handleError","agentExecutionBodySchema","streamResponseSchema","HTTPException","getEffectiveResourceId","getEffectiveThreadId","enforceThreadAccess","applyEffectiveThreadId"],"sources":["../src/server/schemas/workflow-builder.ts","../src/server/handlers/workflow-builder.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { builderModelPolicySchema } from './editor-builder';\n\nexport const workflowBuilderSettingsResponseSchema = z.object({\n enabled: z.boolean(),\n modelPolicy: builderModelPolicySchema.optional(),\n});\n\nexport type WorkflowBuilderSettingsResponse = z.infer<typeof workflowBuilderSettingsResponseSchema>;\n","import { HTTPException } from '../http-exception';\nimport { agentExecutionBodySchema, streamResponseSchema } from '../schemas/agents';\nimport { workflowBuilderSettingsResponseSchema } from '../schemas/workflow-builder';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\nimport {\n applyEffectiveThreadId,\n enforceThreadAccess,\n getEffectiveResourceId,\n getEffectiveThreadId,\n mergeBodyRequestContext,\n requireEffectiveResourceId,\n validateBody,\n} from './utils';\n\nexport const GET_WORKFLOW_BUILDER_SETTINGS_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/workflow-builder/settings',\n responseType: 'json',\n responseSchema: workflowBuilderSettingsResponseSchema,\n summary: 'Get persisted workflow builder settings',\n description: 'Returns whether the editor-owned persisted workflow builder is available',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-workflows:read',\n handler: async ({ mastra }) => {\n try {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveWorkflowBuilder !== 'function') return { enabled: false };\n if (!editor.hasEnabledWorkflowBuilderConfig?.()) return { enabled: false };\n\n const builder = await editor.resolveWorkflowBuilder();\n return {\n enabled: builder?.enabled === true,\n modelPolicy: builder?.getModelPolicy(),\n };\n } catch (error) {\n return handleError(error, 'Error getting workflow builder settings');\n }\n },\n});\n\nexport const STREAM_WORKFLOW_BUILDER_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/workflow-builder/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n bodySchema: agentExecutionBodySchema,\n responseSchema: streamResponseSchema,\n summary: 'Stream persisted workflow builder response',\n description: 'Streams from the hidden editor-owned workflow builder agent',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-workflows:write',\n handler: async ({ mastra, abortSignal, requestContext: serverRequestContext, ...params }) => {\n try {\n const editor = mastra.getEditor();\n if (!editor?.hasEnabledWorkflowBuilderConfig?.() || typeof editor.resolveWorkflowBuilder !== 'function') {\n throw new HTTPException(404, { message: 'Workflow builder is not enabled' });\n }\n\n const builder = await editor.resolveWorkflowBuilder();\n if (!builder?.enabled) throw new HTTPException(404, { message: 'Workflow builder is not enabled' });\n const agent = builder.getAgent();\n\n const { messages, memory: memoryOption, requestContext: bodyRequestContext, scopes: _scopes, ...rest } = params;\n validateBody({ messages });\n\n mergeBodyRequestContext(serverRequestContext, bodyRequestContext);\n\n let authorizedMemoryOption = memoryOption;\n if (memoryOption) {\n const clientThreadId = typeof memoryOption.thread === 'string' ? memoryOption.thread : memoryOption.thread?.id;\n const effectiveResourceId = getEffectiveResourceId(serverRequestContext, memoryOption.resource);\n requireEffectiveResourceId(effectiveResourceId);\n const effectiveThreadId = getEffectiveThreadId(serverRequestContext, clientThreadId);\n\n if (effectiveThreadId) {\n const memory = await agent.getMemory({ requestContext: serverRequestContext });\n const thread = await memory?.getThreadById({ threadId: effectiveThreadId });\n if (thread) {\n await enforceThreadAccess({\n mastra,\n requestContext: serverRequestContext,\n threadId: effectiveThreadId,\n thread,\n effectiveResourceId,\n permission: 'memory:write',\n });\n }\n }\n\n authorizedMemoryOption = {\n ...memoryOption,\n resource: effectiveResourceId ?? memoryOption.resource,\n thread: applyEffectiveThreadId(memoryOption.thread, effectiveThreadId),\n };\n }\n\n const { structuredOutput, ...streamOptions } = rest;\n const options: Record<string, any> = {\n ...streamOptions,\n requestContext: serverRequestContext,\n memory: authorizedMemoryOption,\n abortSignal,\n };\n const result = structuredOutput\n ? await agent.stream(messages, { ...options, structuredOutput })\n : await agent.stream(messages, options);\n return result.fullStream;\n } catch (error) {\n return handleError(error, 'Error streaming workflow builder response');\n }\n },\n});\n"],"mappings":";;;;;;;;AAGA,MAAa,wCAAwCA,OAAAA,EAAE,OAAO;CAC5D,SAASA,OAAAA,EAAE,QAAQ;CACnB,aAAaC,uBAAAA,yBAAyB,SAAS;AACjD,CAAC;;ACSD,MAAa,sCAAsCC,sBAAAA,YAAY;CAC7D,QAAQ;CACR,MAAM;CACN,cAAc;CACd,gBAAgB;CAChB,SAAS;CACT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,cAAc;IAChB,MAAM,iBAAiB,OAAO,aAAa,WAAW,WAAW,aAAa,SAAS,aAAa,QAAQ;IAC5G,MAAM,sBAAsBC,cAAAA,uBAAuB,sBAAsB,aAAa,QAAQ;IAC9F,cAAA,2BAA2B,mBAAmB;IAC9C,MAAM,oBAAoBC,cAAAA,qBAAqB,sBAAsB,cAAc;IAEnF,IAAI,mBAAmB;KAErB,MAAM,SAAS,OAAM,MADA,MAAM,UAAU,EAAE,gBAAgB,qBAAqB,CAAC,EAAA,EAChD,cAAc,EAAE,UAAU,kBAAkB,CAAC;KAC1E,IAAI,QACF,MAAMC,cAAAA,oBAAoB;MACxB;MACA,gBAAgB;MAChB,UAAU;MACV;MACA;MACA,YAAY;KACd,CAAC;IAEL;IAEA,yBAAyB;KACvB,GAAG;KACH,UAAU,uBAAuB,aAAa;KAC9C,QAAQC,cAAAA,uBAAuB,aAAa,QAAQ,iBAAiB;IACvE;GACF;GAEA,MAAM,EAAE,kBAAkB,GAAG,kBAAkB;GAC/C,MAAM,UAA+B;IACnC,GAAG;IACH,gBAAgB;IAChB,QAAQ;IACR;GACF;GAIA,QAHe,mBACX,MAAM,MAAM,OAAO,UAAU;IAAE,GAAG;IAAS;GAAiB,CAAC,IAC7D,MAAM,MAAM,OAAO,UAAU,OAAO,EAAA,CAC1B;EAChB,SAAS,OAAO;GACd,OAAOP,8BAAAA,YAAY,OAAO,2CAA2C;EACvE;CACF;AACF,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { t as HTTPException } from "./http-exception-CzaWkxMl.js";
|
|
|
2
2
|
import { X as streamResponseSchema, r as agentExecutionBodySchema } from "./agents-A-ahR0eQ.js";
|
|
3
3
|
import { n as createRoute } from "./route-builder-BxPrwNog.js";
|
|
4
4
|
import { handleError } from "./server/handlers/error.js";
|
|
5
|
-
import { a as getEffectiveThreadId,
|
|
5
|
+
import { a as getEffectiveThreadId, c as mergeBodyRequestContext, d as requireEffectiveResourceId, i as getEffectiveResourceId, m as validateBody, n as enforceThreadAccess, t as applyEffectiveThreadId } from "./utils-DHxjw4Tn.js";
|
|
6
6
|
import { a as builderModelPolicySchema } from "./editor-builder-BCZy1ZH1.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
// src/server/schemas/workflow-builder.ts
|
|
@@ -99,4 +99,4 @@ const STREAM_WORKFLOW_BUILDER_ROUTE = createRoute({
|
|
|
99
99
|
});
|
|
100
100
|
export { STREAM_WORKFLOW_BUILDER_ROUTE as n, GET_WORKFLOW_BUILDER_SETTINGS_ROUTE as t };
|
|
101
101
|
|
|
102
|
-
//# sourceMappingURL=workflow-builder-
|
|
102
|
+
//# sourceMappingURL=workflow-builder-D4Po74yJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-builder-
|
|
1
|
+
{"version":3,"file":"workflow-builder-D4Po74yJ.js","names":[],"sources":["../src/server/schemas/workflow-builder.ts","../src/server/handlers/workflow-builder.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { builderModelPolicySchema } from './editor-builder';\n\nexport const workflowBuilderSettingsResponseSchema = z.object({\n enabled: z.boolean(),\n modelPolicy: builderModelPolicySchema.optional(),\n});\n\nexport type WorkflowBuilderSettingsResponse = z.infer<typeof workflowBuilderSettingsResponseSchema>;\n","import { HTTPException } from '../http-exception';\nimport { agentExecutionBodySchema, streamResponseSchema } from '../schemas/agents';\nimport { workflowBuilderSettingsResponseSchema } from '../schemas/workflow-builder';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\nimport {\n applyEffectiveThreadId,\n enforceThreadAccess,\n getEffectiveResourceId,\n getEffectiveThreadId,\n mergeBodyRequestContext,\n requireEffectiveResourceId,\n validateBody,\n} from './utils';\n\nexport const GET_WORKFLOW_BUILDER_SETTINGS_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/workflow-builder/settings',\n responseType: 'json',\n responseSchema: workflowBuilderSettingsResponseSchema,\n summary: 'Get persisted workflow builder settings',\n description: 'Returns whether the editor-owned persisted workflow builder is available',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-workflows:read',\n handler: async ({ mastra }) => {\n try {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveWorkflowBuilder !== 'function') return { enabled: false };\n if (!editor.hasEnabledWorkflowBuilderConfig?.()) return { enabled: false };\n\n const builder = await editor.resolveWorkflowBuilder();\n return {\n enabled: builder?.enabled === true,\n modelPolicy: builder?.getModelPolicy(),\n };\n } catch (error) {\n return handleError(error, 'Error getting workflow builder settings');\n }\n },\n});\n\nexport const STREAM_WORKFLOW_BUILDER_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/workflow-builder/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n bodySchema: agentExecutionBodySchema,\n responseSchema: streamResponseSchema,\n summary: 'Stream persisted workflow builder response',\n description: 'Streams from the hidden editor-owned workflow builder agent',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-workflows:write',\n handler: async ({ mastra, abortSignal, requestContext: serverRequestContext, ...params }) => {\n try {\n const editor = mastra.getEditor();\n if (!editor?.hasEnabledWorkflowBuilderConfig?.() || typeof editor.resolveWorkflowBuilder !== 'function') {\n throw new HTTPException(404, { message: 'Workflow builder is not enabled' });\n }\n\n const builder = await editor.resolveWorkflowBuilder();\n if (!builder?.enabled) throw new HTTPException(404, { message: 'Workflow builder is not enabled' });\n const agent = builder.getAgent();\n\n const { messages, memory: memoryOption, requestContext: bodyRequestContext, scopes: _scopes, ...rest } = params;\n validateBody({ messages });\n\n mergeBodyRequestContext(serverRequestContext, bodyRequestContext);\n\n let authorizedMemoryOption = memoryOption;\n if (memoryOption) {\n const clientThreadId = typeof memoryOption.thread === 'string' ? memoryOption.thread : memoryOption.thread?.id;\n const effectiveResourceId = getEffectiveResourceId(serverRequestContext, memoryOption.resource);\n requireEffectiveResourceId(effectiveResourceId);\n const effectiveThreadId = getEffectiveThreadId(serverRequestContext, clientThreadId);\n\n if (effectiveThreadId) {\n const memory = await agent.getMemory({ requestContext: serverRequestContext });\n const thread = await memory?.getThreadById({ threadId: effectiveThreadId });\n if (thread) {\n await enforceThreadAccess({\n mastra,\n requestContext: serverRequestContext,\n threadId: effectiveThreadId,\n thread,\n effectiveResourceId,\n permission: 'memory:write',\n });\n }\n }\n\n authorizedMemoryOption = {\n ...memoryOption,\n resource: effectiveResourceId ?? memoryOption.resource,\n thread: applyEffectiveThreadId(memoryOption.thread, effectiveThreadId),\n };\n }\n\n const { structuredOutput, ...streamOptions } = rest;\n const options: Record<string, any> = {\n ...streamOptions,\n requestContext: serverRequestContext,\n memory: authorizedMemoryOption,\n abortSignal,\n };\n const result = structuredOutput\n ? await agent.stream(messages, { ...options, structuredOutput })\n : await agent.stream(messages, options);\n return result.fullStream;\n } catch (error) {\n return handleError(error, 'Error streaming workflow builder response');\n }\n },\n});\n"],"mappings":";;;;;;;;AAGA,MAAa,wCAAwC,EAAE,OAAO;CAC5D,SAAS,EAAE,QAAQ;CACnB,aAAa,yBAAyB,SAAS;AACjD,CAAC;;ACSD,MAAa,sCAAsC,YAAY;CAC7D,QAAQ;CACR,MAAM;CACN,cAAc;CACd,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,QAAQ;CACf,cAAc;CACd,oBAAoB;CACpB,SAAS,OAAO,EAAE,aAAa;EAC7B,IAAI;GACF,MAAM,SAAS,OAAO,UAAU;GAChC,IAAI,CAAC,UAAU,OAAO,OAAO,2BAA2B,YAAY,OAAO,EAAE,SAAS,MAAM;GAC5F,IAAI,CAAC,OAAO,kCAAkC,GAAG,OAAO,EAAE,SAAS,MAAM;GAEzE,MAAM,UAAU,MAAM,OAAO,uBAAuB;GACpD,OAAO;IACL,SAAS,SAAS,YAAY;IAC9B,aAAa,SAAS,eAAe;GACvC;EACF,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,yCAAyC;EACrE;CACF;AACF,CAAC;AAED,MAAa,gCAAgC,YAAY;CACvD,QAAQ;CACR,MA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AAE,kBAAkB,GAAG,kBAAkB;GAC/C,MAAM,UAA+B;IACnC,GAAG;IACH,gBAAgB;IAChB,QAAQ;IACR;GACF;GAIA,QAHe,mBACX,MAAM,MAAM,OAAO,UAAU;IAAE,GAAG;IAAS;GAAiB,CAAC,IAC7D,MAAM,MAAM,OAAO,UAAU,OAAO,EAAA,CAC1B;EAChB,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,2CAA2C;EACvE;CACF;AACF,CAAC"}
|
|
@@ -6,7 +6,7 @@ const require_agents = require("./agents-vFpMvK3w.cjs");
|
|
|
6
6
|
const require_route_builder = require("./route-builder-CvARmqnA.cjs");
|
|
7
7
|
const require_utils = require("./utils-BnH77wPf.cjs");
|
|
8
8
|
const require_server_handlers_error = require("./server/handlers/error.cjs");
|
|
9
|
-
const require_utils$1 = require("./utils-
|
|
9
|
+
const require_utils$1 = require("./utils-BbYUI6Yn.cjs");
|
|
10
10
|
let zod_v4 = require("zod/v4");
|
|
11
11
|
let _mastra_core_stream = require("@mastra/core/stream");
|
|
12
12
|
// src/server/handlers/workflows.ts
|
|
@@ -129,7 +129,7 @@ const LIST_WORKFLOWS_ROUTE = require_route_builder.createRoute({
|
|
|
129
129
|
acc[key] = require_utils.getWorkflowInfo(workflow, isPartial);
|
|
130
130
|
return acc;
|
|
131
131
|
}, {});
|
|
132
|
-
const fgaProvider =
|
|
132
|
+
const fgaProvider = require_utils$1.getHandlerFGAProvider(mastra, requestContext);
|
|
133
133
|
const user = requestContext?.get("user");
|
|
134
134
|
if (fgaProvider) {
|
|
135
135
|
if (!user) return {};
|
|
@@ -165,7 +165,7 @@ const LIST_WORKFLOW_RUN_COUNTS_ROUTE = require_route_builder.createRoute({
|
|
|
165
165
|
requiresAuth: true,
|
|
166
166
|
handler: (async ({ mastra, requestContext }) => {
|
|
167
167
|
try {
|
|
168
|
-
const fgaProvider =
|
|
168
|
+
const fgaProvider = require_utils$1.getHandlerFGAProvider(mastra, requestContext);
|
|
169
169
|
const user = requestContext?.get("user");
|
|
170
170
|
if (fgaProvider && !user) return {};
|
|
171
171
|
const workflows = mastra.listWorkflows({ serialized: false });
|
|
@@ -338,7 +338,7 @@ const GET_WORKFLOW_RUN_BY_ID_ROUTE = require_route_builder.createRoute({
|
|
|
338
338
|
fields: fieldList
|
|
339
339
|
});
|
|
340
340
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
341
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
341
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
342
342
|
return run;
|
|
343
343
|
} catch (error) {
|
|
344
344
|
return require_server_handlers_error.handleError(error, "Error getting workflow run");
|
|
@@ -367,7 +367,7 @@ const DELETE_WORKFLOW_RUN_BY_ID_ROUTE = require_route_builder.createRoute({
|
|
|
367
367
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
368
368
|
const run = await workflow.getWorkflowRunById(runId);
|
|
369
369
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
370
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
370
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
371
371
|
await workflow.deleteWorkflowRunById(runId);
|
|
372
372
|
return { message: "Workflow run deleted" };
|
|
373
373
|
} catch (error) {
|
|
@@ -399,7 +399,7 @@ const CREATE_WORKFLOW_RUN_ROUTE = require_route_builder.createRoute({
|
|
|
399
399
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
400
400
|
if (runId) {
|
|
401
401
|
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
402
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
402
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
403
403
|
}
|
|
404
404
|
return { runId: (await workflow.createRun({
|
|
405
405
|
runId,
|
|
@@ -433,7 +433,7 @@ const STREAM_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
433
433
|
});
|
|
434
434
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
435
435
|
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
436
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
436
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
437
437
|
if (existingRun && TERMINAL_RUN_STATUSES.includes(existingRun.status)) throw new require_http_exception.HTTPException(409, { message: `Workflow run ${runId} already finished with status "${existingRun.status}". Use /observe to read its stream back, or stream a new runId.` });
|
|
438
438
|
const serverCache = mastra.getServerCache();
|
|
439
439
|
const result = (await workflow.createRun({
|
|
@@ -478,7 +478,7 @@ const RESUME_STREAM_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
478
478
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
479
479
|
const run = await workflow.getWorkflowRunById(runId);
|
|
480
480
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
481
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
481
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
482
482
|
const _run = await workflow.createRun({
|
|
483
483
|
runId,
|
|
484
484
|
resourceId: run.resourceId
|
|
@@ -522,7 +522,7 @@ const START_ASYNC_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
522
522
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
523
523
|
if (runId) {
|
|
524
524
|
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
525
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
525
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
526
526
|
}
|
|
527
527
|
return await (await workflow.createRun({
|
|
528
528
|
runId,
|
|
@@ -560,7 +560,7 @@ const START_WORKFLOW_RUN_ROUTE = require_route_builder.createRoute({
|
|
|
560
560
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
561
561
|
const run = await workflow.getWorkflowRunById(runId);
|
|
562
562
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
563
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
563
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
564
564
|
(await workflow.createRun({
|
|
565
565
|
runId,
|
|
566
566
|
resourceId: run.resourceId
|
|
@@ -603,7 +603,7 @@ const OBSERVE_STREAM_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
603
603
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
604
604
|
const run = await workflow.getWorkflowRunById(runId);
|
|
605
605
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
606
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
606
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
607
607
|
const _run = await workflow.createRun({
|
|
608
608
|
runId,
|
|
609
609
|
resourceId: run.resourceId
|
|
@@ -646,7 +646,7 @@ const RESUME_ASYNC_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
646
646
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
647
647
|
const run = await workflow.getWorkflowRunById(runId);
|
|
648
648
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
649
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
649
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
650
650
|
return await (await workflow.createRun({
|
|
651
651
|
runId,
|
|
652
652
|
resourceId: run.resourceId
|
|
@@ -693,7 +693,7 @@ const RESUME_NO_WAIT_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
693
693
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
694
694
|
const run = await workflow.getWorkflowRunById(runId);
|
|
695
695
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
696
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
696
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
697
697
|
return await (await workflow.createRun({
|
|
698
698
|
runId,
|
|
699
699
|
resourceId: run.resourceId
|
|
@@ -730,7 +730,7 @@ const RESUME_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
730
730
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
731
731
|
const run = await workflow.getWorkflowRunById(runId);
|
|
732
732
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
733
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
733
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
734
734
|
(await workflow.createRun({
|
|
735
735
|
runId,
|
|
736
736
|
resourceId: run.resourceId
|
|
@@ -774,7 +774,7 @@ const RESTART_ASYNC_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
774
774
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
775
775
|
const run = await workflow.getWorkflowRunById(runId);
|
|
776
776
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
777
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
777
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
778
778
|
return await (await workflow.createRun({
|
|
779
779
|
runId,
|
|
780
780
|
resourceId: run.resourceId
|
|
@@ -811,7 +811,7 @@ const RESTART_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
811
811
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
812
812
|
const run = await workflow.getWorkflowRunById(runId);
|
|
813
813
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
814
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
814
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
815
815
|
(await workflow.createRun({
|
|
816
816
|
runId,
|
|
817
817
|
resourceId: run.resourceId
|
|
@@ -843,7 +843,7 @@ const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE = require_route_builder.creat
|
|
|
843
843
|
requiresAuth: true,
|
|
844
844
|
handler: async ({ mastra, workflowId, requestContext }) => {
|
|
845
845
|
try {
|
|
846
|
-
await require_utils$1.validateRunOwnership({ resourceId: null }, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
846
|
+
await require_utils$1.validateRunOwnership({ resourceId: null }, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
847
847
|
if (!workflowId) throw new require_http_exception.HTTPException(400, { message: "Workflow ID is required" });
|
|
848
848
|
const { workflow } = await listWorkflowsFromSystem({
|
|
849
849
|
mastra,
|
|
@@ -869,7 +869,7 @@ const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE = require_route_builder.createRoute
|
|
|
869
869
|
requiresAuth: true,
|
|
870
870
|
handler: async ({ mastra, workflowId, requestContext }) => {
|
|
871
871
|
try {
|
|
872
|
-
await require_utils$1.validateRunOwnership({ resourceId: null }, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
872
|
+
await require_utils$1.validateRunOwnership({ resourceId: null }, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
873
873
|
if (!workflowId) throw new require_http_exception.HTTPException(400, { message: "Workflow ID is required" });
|
|
874
874
|
const { workflow } = await listWorkflowsFromSystem({
|
|
875
875
|
mastra,
|
|
@@ -912,7 +912,7 @@ const TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
912
912
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
913
913
|
const run = await workflow.getWorkflowRunById(runId);
|
|
914
914
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
915
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
915
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
916
916
|
return await (await workflow.createRun({
|
|
917
917
|
runId,
|
|
918
918
|
resourceId: run.resourceId
|
|
@@ -949,7 +949,7 @@ const TIME_TRAVEL_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
949
949
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
950
950
|
const run = await workflow.getWorkflowRunById(runId);
|
|
951
951
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
952
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
952
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
953
953
|
(await workflow.createRun({
|
|
954
954
|
runId,
|
|
955
955
|
resourceId: run.resourceId
|
|
@@ -992,7 +992,7 @@ const TIME_TRAVEL_STREAM_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
992
992
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
993
993
|
const existingRun = await workflow.getWorkflowRunById(runId);
|
|
994
994
|
if (!existingRun) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
995
|
-
await require_utils$1.validateRunOwnership(existingRun, effectiveResourceId, mastra);
|
|
995
|
+
await require_utils$1.validateRunOwnership(existingRun, effectiveResourceId, mastra, requestContext);
|
|
996
996
|
const serverCache = mastra.getServerCache();
|
|
997
997
|
const result = (await workflow.createRun({
|
|
998
998
|
runId,
|
|
@@ -1034,7 +1034,7 @@ const CANCEL_WORKFLOW_RUN_ROUTE = require_route_builder.createRoute({
|
|
|
1034
1034
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
1035
1035
|
const run = await workflow.getWorkflowRunById(runId);
|
|
1036
1036
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
1037
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
1037
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
1038
1038
|
await (await workflow.createRun({
|
|
1039
1039
|
runId,
|
|
1040
1040
|
resourceId: run.resourceId
|
|
@@ -1070,7 +1070,7 @@ const STREAM_LEGACY_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
1070
1070
|
const serverCache = mastra.getServerCache();
|
|
1071
1071
|
if (runId) {
|
|
1072
1072
|
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
1073
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
1073
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
1074
1074
|
}
|
|
1075
1075
|
return (await workflow.createRun({
|
|
1076
1076
|
runId,
|
|
@@ -1113,7 +1113,7 @@ const OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE = require_route_builder.createRoute({
|
|
|
1113
1113
|
if (!workflow) throw new require_http_exception.HTTPException(404, { message: "Workflow not found" });
|
|
1114
1114
|
const run = await workflow.getWorkflowRunById(runId);
|
|
1115
1115
|
if (!run) throw new require_http_exception.HTTPException(404, { message: "Workflow run not found" });
|
|
1116
|
-
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra);
|
|
1116
|
+
await require_utils$1.validateRunOwnership(run, effectiveResourceId, mastra, requestContext);
|
|
1117
1117
|
const _run = await workflow.createRun({
|
|
1118
1118
|
runId,
|
|
1119
1119
|
resourceId: run.resourceId
|
|
@@ -1183,7 +1183,7 @@ const EXECUTE_WORKFLOW_STEP_ROUTE = require_route_builder.createRoute({
|
|
|
1183
1183
|
runId,
|
|
1184
1184
|
workflowName: workflowId
|
|
1185
1185
|
});
|
|
1186
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(serverRequestContext, void 0), mastra);
|
|
1186
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(serverRequestContext, void 0), mastra, serverRequestContext);
|
|
1187
1187
|
return await (await getStepStrategy(mastra)).executeStep({
|
|
1188
1188
|
workflowId,
|
|
1189
1189
|
runId,
|
|
@@ -1254,7 +1254,7 @@ const RECEIVE_WORKFLOW_EVENT_ROUTE = require_route_builder.createRoute({
|
|
|
1254
1254
|
runId: event.runId,
|
|
1255
1255
|
...typeof workflowName === "string" ? { workflowName } : {}
|
|
1256
1256
|
});
|
|
1257
|
-
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra);
|
|
1257
|
+
await require_utils$1.validateRunOwnership(existingRun, require_utils$1.getEffectiveResourceId(requestContext, void 0), mastra, requestContext);
|
|
1258
1258
|
const rawCreatedAt = event.createdAt;
|
|
1259
1259
|
const createdAt = rawCreatedAt instanceof Date ? rawCreatedAt : new Date(rawCreatedAt);
|
|
1260
1260
|
if (Number.isNaN(createdAt.getTime())) throw new require_http_exception.HTTPException(400, { message: "Invalid createdAt" });
|
|
@@ -1442,4 +1442,4 @@ Object.defineProperty(exports, "workflows_exports", {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
});
|
|
1444
1444
|
|
|
1445
|
-
//# sourceMappingURL=workflows-
|
|
1445
|
+
//# sourceMappingURL=workflows-CiP6r_nw.cjs.map
|