@mastra/server 1.72.0 → 1.73.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.
Files changed (73) hide show
  1. package/dist/{a2a-D2BffGsK.js → a2a-Dyd6lbnr.js} +35 -23
  2. package/dist/a2a-Dyd6lbnr.js.map +1 -0
  3. package/dist/{a2a-CAQVpVxH.cjs → a2a-rSyYjbA3.cjs} +35 -24
  4. package/dist/a2a-rSyYjbA3.cjs.map +1 -0
  5. package/dist/{api-schema-manifest-CaZU5zVt.cjs → api-schema-manifest-azbFW2gh.cjs} +2 -2
  6. package/dist/{api-schema-manifest-CaZU5zVt.cjs.map → api-schema-manifest-azbFW2gh.cjs.map} +1 -1
  7. package/dist/{api-schema-manifest-wF1O8MCU.js → api-schema-manifest-btfn_x2G.js} +2 -2
  8. package/dist/{api-schema-manifest-wF1O8MCU.js.map → api-schema-manifest-btfn_x2G.js.map} +1 -1
  9. package/dist/{dist-CYk5xS3y.js → dist-B2EGPe0Y.js} +219 -42
  10. package/dist/dist-B2EGPe0Y.js.map +1 -0
  11. package/dist/{dist-CRMvLG_8.cjs → dist-BJfoL3Lt.cjs} +219 -43
  12. package/dist/dist-BJfoL3Lt.cjs.map +1 -0
  13. package/dist/docs/SKILL.md +2 -1
  14. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  15. package/dist/docs/references/docs-guides-mcp-authentication-authorization.md +136 -0
  16. package/dist/{processors-88oJ_4J-.js → processors-33IULT8X.js} +7 -4
  17. package/dist/processors-33IULT8X.js.map +1 -0
  18. package/dist/{processors-D6lRjS0e.cjs → processors-80HWq8nr.cjs} +7 -4
  19. package/dist/processors-80HWq8nr.cjs.map +1 -0
  20. package/dist/{routes-x4As7pym.cjs → routes-BaQVELB2.cjs} +2 -2
  21. package/dist/{routes-x4As7pym.cjs.map → routes-BaQVELB2.cjs.map} +1 -1
  22. package/dist/{routes-B6soWZap.js → routes-BqoNkLiT.js} +2 -2
  23. package/dist/{routes-B6soWZap.js.map → routes-BqoNkLiT.js.map} +1 -1
  24. package/dist/server/a2a/agent-card-signing.d.ts.map +1 -1
  25. package/dist/server/handlers/a2a.cjs +1 -1
  26. package/dist/server/handlers/a2a.js +1 -1
  27. package/dist/server/handlers/agent-builder.cjs +1 -1
  28. package/dist/server/handlers/agent-builder.js +1 -1
  29. package/dist/server/handlers/agents.cjs +2 -2
  30. package/dist/server/handlers/agents.cjs.map +1 -1
  31. package/dist/server/handlers/agents.d.ts.map +1 -1
  32. package/dist/server/handlers/agents.js +3 -3
  33. package/dist/server/handlers/agents.js.map +1 -1
  34. package/dist/server/handlers/conversations.cjs +1 -2
  35. package/dist/server/handlers/conversations.cjs.map +1 -1
  36. package/dist/server/handlers/conversations.d.ts.map +1 -1
  37. package/dist/server/handlers/conversations.js +1 -2
  38. package/dist/server/handlers/conversations.js.map +1 -1
  39. package/dist/server/handlers/processors.cjs +3 -1
  40. package/dist/server/handlers/processors.cjs.map +1 -1
  41. package/dist/server/handlers/processors.d.ts +6 -3
  42. package/dist/server/handlers/processors.d.ts.map +1 -1
  43. package/dist/server/handlers/processors.js +3 -1
  44. package/dist/server/handlers/processors.js.map +1 -1
  45. package/dist/server/handlers/responses.adapter.cjs +1 -2
  46. package/dist/server/handlers/responses.adapter.cjs.map +1 -1
  47. package/dist/server/handlers/responses.adapter.d.ts.map +1 -1
  48. package/dist/server/handlers/responses.adapter.js +1 -2
  49. package/dist/server/handlers/responses.adapter.js.map +1 -1
  50. package/dist/server/handlers/responses.cjs +1 -2
  51. package/dist/server/handlers/responses.cjs.map +1 -1
  52. package/dist/server/handlers/responses.d.ts.map +1 -1
  53. package/dist/server/handlers/responses.js +1 -2
  54. package/dist/server/handlers/responses.js.map +1 -1
  55. package/dist/server/handlers/system.cjs +1 -1
  56. package/dist/server/handlers/system.js +1 -1
  57. package/dist/server/handlers.cjs +1 -1
  58. package/dist/server/handlers.js +1 -1
  59. package/dist/server/schemas/index.cjs +1 -1
  60. package/dist/server/schemas/index.js +1 -1
  61. package/dist/server/schemas/processors.d.ts +4 -0
  62. package/dist/server/schemas/processors.d.ts.map +1 -1
  63. package/dist/server/server-adapter/index.cjs +1 -1
  64. package/dist/server/server-adapter/index.js +1 -1
  65. package/dist/server/server-adapter/routes/processors.d.ts +6 -3
  66. package/dist/server/server-adapter/routes/processors.d.ts.map +1 -1
  67. package/package.json +5 -5
  68. package/dist/a2a-CAQVpVxH.cjs.map +0 -1
  69. package/dist/a2a-D2BffGsK.js.map +0 -1
  70. package/dist/dist-CRMvLG_8.cjs.map +0 -1
  71. package/dist/dist-CYk5xS3y.js.map +0 -1
  72. package/dist/processors-88oJ_4J-.js.map +0 -1
  73. package/dist/processors-D6lRjS0e.cjs.map +0 -1
@@ -8,7 +8,6 @@ const require_server_handlers_agents = require("./agents.cjs");
8
8
  const require_conversations = require("../../conversations-DX7ATgEB.cjs");
9
9
  const require_server_handlers_responses_adapter = require("./responses.adapter.cjs");
10
10
  const require_server_handlers_responses_storage = require("./responses.storage.cjs");
11
- let crypto = require("crypto");
12
11
  //#region src/server/handlers/conversations.ts
13
12
  var conversations_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
14
13
  CREATE_CONVERSATION_ROUTE: () => CREATE_CONVERSATION_ROUTE,
@@ -63,7 +62,7 @@ const CREATE_CONVERSATION_ROUTE = require_route_builder.createRoute({
63
62
  agent,
64
63
  requestContext
65
64
  })) throw new require_http_exception.HTTPException(400, { message: `Memory storage is not configured for agent "${agent.id}"` });
66
- const threadId = conversation_id ?? (0, crypto.randomUUID)();
65
+ const threadId = conversation_id ?? globalThis.crypto.randomUUID();
67
66
  const resourceId = require_utils.getEffectiveResourceId(requestContext, resource_id) ?? threadId;
68
67
  return buildConversationObject({ thread: await memory.createThread({
69
68
  threadId,
@@ -1 +1 @@
1
- {"version":3,"file":"conversations.cjs","names":["createRoute","createConversationBodySchema","conversationObjectSchema","MastraFGAPermissions","HTTPException","getAgentFromSystem","getAgentMemoryStore","getEffectiveResourceId","handleError","conversationIdPathParams","findConversationThreadAcrossAgents","conversationItemsListSchema","mapMastraMessagesToConversationItems","conversationDeletedSchema"],"sources":["../../../src/server/handlers/conversations.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { 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 } 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 ?? randomUUID();\n const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;\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":";;;;;;;;;;;;;;;;;;AAkBA,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,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C;GAG1F,MAAM,MAAM,YAAY,aAAa,EAAE,UAAU,eAAe,CAAC;GAEjE,OAAO,yBAAyB,cAAc;EAChD,SAAS,OAAO;GACd,OAAOI,8BAAAA,YAAY,OAAO,6BAA6B;EACzD;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"conversations.cjs","names":["createRoute","createConversationBodySchema","conversationObjectSchema","MastraFGAPermissions","HTTPException","getAgentFromSystem","getAgentMemoryStore","getEffectiveResourceId","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 } 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 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;EAC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ACd,oBAAoBV,cAAAA,qBAAqB;CACzC,SAAS,OAAO,EAAE,QAAQ,gBAAgB,qBAAqB;EAC7D,IAAI;GACF,MAAM,QAAQ,MAAMO,0CAAAA,mCAAmC;IAAE;IAAQ;IAAgB;GAAe,CAAC;GACjG,IAAI,CAAC,OACH,MAAM,IAAIN,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,OAAOI,8BAAAA,YAAY,OAAO,6BAA6B;EACzD;CACF;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/conversations.ts"],"names":[],"mappings":"AA4CA,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCpC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBjC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BvC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpC,CAAC"}
1
+ {"version":3,"file":"conversations.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/conversations.ts"],"names":[],"mappings":"AA2CA,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCpC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBjC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BvC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpC,CAAC"}
@@ -7,7 +7,6 @@ import { getAgentFromSystem } from "./agents.js";
7
7
  import { a as createConversationBodySchema, i as conversationObjectSchema, n as conversationIdPathParams, r as conversationItemsListSchema, t as conversationDeletedSchema } from "../../conversations-U3fod5tw.js";
8
8
  import { mapMastraMessagesToConversationItems } from "./responses.adapter.js";
9
9
  import { findConversationThreadAcrossAgents, getAgentMemoryStore } from "./responses.storage.js";
10
- import { randomUUID } from "crypto";
11
10
  //#region src/server/handlers/conversations.ts
12
11
  var conversations_exports = /* @__PURE__ */ __exportAll({
13
12
  CREATE_CONVERSATION_ROUTE: () => CREATE_CONVERSATION_ROUTE,
@@ -62,7 +61,7 @@ const CREATE_CONVERSATION_ROUTE = createRoute({
62
61
  agent,
63
62
  requestContext
64
63
  })) throw new HTTPException(400, { message: `Memory storage is not configured for agent "${agent.id}"` });
65
- const threadId = conversation_id ?? randomUUID();
64
+ const threadId = conversation_id ?? globalThis.crypto.randomUUID();
66
65
  const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;
67
66
  return buildConversationObject({ thread: await memory.createThread({
68
67
  threadId,
@@ -1 +1 @@
1
- {"version":3,"file":"conversations.js","names":[],"sources":["../../../src/server/handlers/conversations.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { 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 } 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 ?? randomUUID();\n const resourceId = getEffectiveResourceId(requestContext, resource_id) ?? threadId;\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":";;;;;;;;;;;;;;;;;AAkBA,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,GACvD,MAAM,IAAI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AM,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"}
1
+ {"version":3,"file":"conversations.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 } 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 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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N,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"}
@@ -3,7 +3,7 @@ require("../../rolldown-runtime-Bd6kNlEP.cjs");
3
3
  const require_http_exception = require("../../http-exception-CKDHupKw.cjs");
4
4
  const require_route_builder = require("../../route-builder-2yrD15TL.cjs");
5
5
  const require_server_handlers_error = require("./error.cjs");
6
- const require_processors = require("../../processors-D6lRjS0e.cjs");
6
+ const require_processors = require("../../processors-80HWq8nr.cjs");
7
7
  let _mastra_core_agent = require("@mastra/core/agent");
8
8
  let _mastra_core_processors = require("@mastra/core/processors");
9
9
  //#region src/server/handlers/processors.ts
@@ -39,6 +39,7 @@ function detectProcessorPhases(processor) {
39
39
  if (typeof processor.processOutputResult === "function") phases.push("outputResult");
40
40
  if (typeof processor.processOutputStep === "function") phases.push("outputStep");
41
41
  if (typeof processor.processToolResult === "function") phases.push("toolResult");
42
+ if (typeof processor.processLLMRequest === "function") phases.push("llmRequest");
42
43
  return phases;
43
44
  }
44
45
  const LIST_PROCESSORS_ROUTE = require_route_builder.createRoute({
@@ -139,6 +140,7 @@ const EXECUTE_PROCESSOR_ROUTE = require_route_builder.createRoute({
139
140
  const { phase, messages } = bodyParams;
140
141
  if (!processorId) throw new require_http_exception.HTTPException(400, { message: "Processor ID is required" });
141
142
  if (!phase) throw new require_http_exception.HTTPException(400, { message: "Phase is required" });
143
+ if (phase === "llmRequest") throw new require_http_exception.HTTPException(400, { message: "llmRequest phase cannot be executed directly. It runs on the provider prompt during an agent call." });
142
144
  if (!messages || !Array.isArray(messages)) throw new require_http_exception.HTTPException(400, { message: "Messages array is required" });
143
145
  let processor;
144
146
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"processors.cjs","names":["createRoute","listProcessorsResponseSchema","handleError","processorIdPathParams","serializedProcessorDetailSchema","HTTPException","executeProcessorBodySchema","executeProcessorResponseSchema","MessageList"],"sources":["../../../src/server/handlers/processors.ts"],"sourcesContent":["import { MessageList } from '@mastra/core/agent';\nimport type { MessageInput } from '@mastra/core/agent/message-list';\nimport { isProcessorWorkflow } from '@mastra/core/processors';\nimport type { Processor, ProcessorWorkflow } from '@mastra/core/processors';\n\nimport { HTTPException } from '../http-exception';\nimport {\n listProcessorsResponseSchema,\n serializedProcessorDetailSchema,\n processorIdPathParams,\n executeProcessorBodySchema,\n executeProcessorResponseSchema,\n} from '../schemas/processors';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\ntype ProcessorPhase = 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult';\n\n/**\n * Helper to extract text from messages for outputStep testing.\n * In real usage, the `text` field contains the assistant's response text.\n */\nfunction extractTextFromMessages(messages: unknown[]): string {\n if (!messages || !Array.isArray(messages) || messages.length === 0) {\n return '';\n }\n const firstMessage = messages[0] as any;\n if (firstMessage?.content?.parts) {\n const textParts = firstMessage.content.parts\n .filter((part: any) => part?.type === 'text')\n .map((part: any) => part?.text || '');\n return textParts.join('');\n }\n return '';\n}\n\n/**\n * Helper to detect phases for a processor.\n * For individual processors, checks which methods are implemented.\n * For workflow processors, returns all phases since createStep handles each phase\n * and it's a no-op if the underlying processor doesn't implement it.\n */\nfunction detectProcessorPhases(processor: any): ProcessorPhase[] {\n // Check if it's a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Workflow processors can potentially handle all phases\n // The createStep in workflows handles each phase and it's a no-op if not implemented\n return ['input', 'inputStep', 'outputStream', 'outputResult', 'outputStep', 'toolResult'];\n }\n\n // For individual processors, detect by checking which methods exist\n const phases: ProcessorPhase[] = [];\n if (typeof processor.processInput === 'function') {\n phases.push('input');\n }\n if (typeof processor.processInputStep === 'function') {\n phases.push('inputStep');\n }\n if (typeof processor.processOutputStream === 'function') {\n phases.push('outputStream');\n }\n if (typeof processor.processOutputResult === 'function') {\n phases.push('outputResult');\n }\n if (typeof processor.processOutputStep === 'function') {\n phases.push('outputStep');\n }\n if (typeof processor.processToolResult === 'function') {\n phases.push('toolResult');\n }\n return phases;\n}\n\nexport const LIST_PROCESSORS_ROUTE = createRoute({\n method: 'GET',\n path: '/processors',\n responseType: 'json',\n responseSchema: listProcessorsResponseSchema,\n summary: 'List all processors',\n description: 'Returns a list of all available individual processors',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n try {\n const processors = mastra.listProcessors() || {};\n const processorConfigurations = mastra.listProcessorConfigurations();\n const result: Record<\n string,\n {\n id: string;\n name?: string;\n description?: string;\n phases: ProcessorPhase[];\n agentIds: string[];\n configurations: Array<{ agentId: string; type: 'input' | 'output' }>;\n isWorkflow: boolean;\n }\n > = {};\n\n // Iterate through all individual processors registered with Mastra\n for (const [processorKey, processorEntry] of Object.entries(processors)) {\n const processor = processorEntry as Processor | ProcessorWorkflow;\n const processorId = processor.id || processorKey;\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processor);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processor);\n\n // Get agent configurations for this processor\n const configs = processorConfigurations.get(processorId) || [];\n const agentIds = [...new Set(configs.map(c => c.agentId))];\n const configurations = configs.map(c => ({ agentId: c.agentId, type: c.type }));\n\n result[processorId] = {\n id: processorId,\n name: processor.name || processorId,\n description: processor.description,\n phases,\n agentIds,\n configurations,\n isWorkflow,\n };\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error getting processors');\n }\n },\n});\n\nexport const GET_PROCESSOR_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/processors/:processorId',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n responseSchema: serializedProcessorDetailSchema,\n summary: 'Get processor by ID',\n description: 'Returns details for a specific processor including its phases and configurations',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId }) => {\n try {\n // Get the processor from Mastra's registered processors\n let processorEntry: Processor | ProcessorWorkflow | undefined;\n try {\n processorEntry = mastra.getProcessorById(processorId) as Processor | ProcessorWorkflow;\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processorEntry = processors[processorId as keyof typeof processors] as Processor | ProcessorWorkflow;\n }\n\n if (!processorEntry) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processorEntry);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processorEntry);\n\n // Get agent configurations for this processor\n const configs = mastra.getProcessorConfigurations(processorId);\n const agents = mastra.listAgents() || {};\n const configurations = configs.map(c => ({\n agentId: c.agentId,\n agentName: agents[c.agentId]?.name || c.agentId,\n type: c.type,\n }));\n\n return {\n id: processorEntry.id,\n name: processorEntry.name || processorEntry.id,\n description: processorEntry.description,\n phases,\n configurations,\n isWorkflow,\n };\n } catch (error) {\n return handleError(error, 'Error getting processor');\n }\n },\n});\n\nexport const EXECUTE_PROCESSOR_ROUTE = createRoute({\n method: 'POST',\n path: '/processors/:processorId/execute',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n bodySchema: executeProcessorBodySchema,\n responseSchema: executeProcessorResponseSchema,\n summary: 'Execute processor',\n description: 'Executes a specific processor with the provided input data',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId, ...bodyParams }) => {\n try {\n const { phase, messages } = bodyParams;\n\n if (!processorId) {\n throw new HTTPException(400, { message: 'Processor ID is required' });\n }\n\n if (!phase) {\n throw new HTTPException(400, { message: 'Phase is required' });\n }\n\n if (!messages || !Array.isArray(messages)) {\n throw new HTTPException(400, { message: 'Messages array is required' });\n }\n\n // Get the processor from Mastra's registered processors\n let processor;\n try {\n processor = mastra.getProcessorById(processorId);\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processor = processors[processorId as keyof typeof processors];\n }\n\n if (!processor) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n const messageList = new MessageList();\n messageList.add(messages as unknown as MessageInput[], 'input');\n\n // Check if this is a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Execute workflow processor\n try {\n // Build inputData based on phase - each phase has different required fields\n const baseInputData = {\n phase: phase as 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult',\n messages: messageList.get.all.db(),\n messageList,\n retryCount: 0,\n };\n let inputData: typeof baseInputData & Record<string, unknown> = baseInputData;\n\n // Add phase-specific fields\n switch (phase) {\n case 'input':\n inputData = {\n ...inputData,\n systemMessages: [],\n };\n break;\n case 'inputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n model: '',\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n };\n break;\n case 'outputResult':\n inputData = {\n ...inputData,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n };\n break;\n case 'outputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n };\n break;\n case 'outputStream':\n inputData = {\n ...inputData,\n part: null,\n streamParts: [],\n state: {},\n };\n break;\n case 'toolResult':\n inputData = {\n ...inputData,\n stepNumber: 0,\n toolName: '',\n toolCallId: '',\n args: undefined,\n toolResultValue: undefined,\n providerExecuted: false,\n systemMessages: [],\n steps: [],\n };\n break;\n }\n\n const run = await processor.createRun();\n const result = await run.start({\n inputData,\n });\n\n // Check for tripwire status\n if (result.status === 'tripwire') {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: result.tripwire.reason || `Tripwire triggered in workflow ${processor.id}`,\n metadata: result.tripwire.metadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n\n // Check for execution failure\n if (result.status !== 'success') {\n throw new HTTPException(500, {\n message: `Processor workflow ${processor.id} failed with status: ${result.status}`,\n });\n }\n\n // Extract output from workflow result\n const output = result.result;\n let outputMessages = messages;\n\n if (output && typeof output === 'object') {\n if ('messages' in output && Array.isArray(output.messages)) {\n outputMessages = output.messages;\n } else if ('messageList' in output && output.messageList instanceof MessageList) {\n outputMessages = output.messageList.get.all.db();\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Re-throw HTTP exceptions\n if (error instanceof HTTPException) {\n throw error;\n }\n throw new HTTPException(500, {\n message: `Error executing processor workflow: ${error.message}`,\n });\n }\n }\n\n // Handle individual processor execution\n // Create the abort function for tripwire support\n let tripwireTriggered = false;\n let tripwireReason: string | undefined;\n let tripwireMetadata: unknown;\n\n const abort = (reason?: string, options?: { retry?: boolean; metadata?: unknown }) => {\n tripwireTriggered = true;\n tripwireReason = reason;\n tripwireMetadata = options?.metadata;\n throw new Error(`TRIPWIRE:${reason || 'Processor aborted'}`);\n };\n\n // Build the context based on phase\n const baseContext = {\n abort,\n retryCount: 0,\n messages: messageList.get.all.db(),\n messageList,\n state: {},\n };\n\n try {\n let result: any;\n\n // Execute the specific phase method on the individual processor\n switch (phase) {\n case 'input':\n if (!processor.processInput) {\n throw new HTTPException(400, { message: 'Processor does not support input phase' });\n }\n result = await processor.processInput({\n ...baseContext,\n systemMessages: [],\n });\n break;\n\n case 'inputStep':\n if (!processor.processInputStep) {\n throw new HTTPException(400, { message: 'Processor does not support inputStep phase' });\n }\n result = await processor.processInputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n // Pass empty/default values for all inputStep fields\n model: '' as any,\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n });\n break;\n\n case 'outputResult':\n if (!processor.processOutputResult) {\n throw new HTTPException(400, { message: 'Processor does not support outputResult phase' });\n }\n result = await processor.processOutputResult({\n ...baseContext,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n });\n break;\n\n case 'outputStep':\n if (!processor.processOutputStep) {\n throw new HTTPException(400, { message: 'Processor does not support outputStep phase' });\n }\n result = await processor.processOutputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },\n });\n break;\n\n case 'outputStream':\n // outputStream is for streaming chunks, not a simple execute\n throw new HTTPException(400, {\n message: 'outputStream phase cannot be executed directly. Use streaming instead.',\n });\n\n default:\n throw new HTTPException(400, { message: `Unknown phase: ${phase}` });\n }\n\n // Process the result\n let outputMessages = messages;\n if (result) {\n if (Array.isArray(result)) {\n outputMessages = result;\n } else if (result.get && result.get.all && typeof result.get.all.db === 'function') {\n // It's a MessageList\n outputMessages = result.get.all.db();\n } else if (result.messages) {\n outputMessages = result.messages;\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Check if it's a tripwire\n if (tripwireTriggered || error.message?.startsWith('TRIPWIRE:')) {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: tripwireReason || error.message?.replace('TRIPWIRE:', ''),\n metadata: tripwireMetadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n throw error;\n }\n } catch (error) {\n return handleError(error, 'Error executing processor');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAS,wBAAwB,UAA6B;CAC5D,IAAI,CAAC,YAAY,CAAC,MAAM,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAC/D,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,IAAI,cAAc,SAAS,OAIzB,OAHkB,aAAa,QAAQ,MACpC,QAAQ,SAAc,MAAM,SAAS,MAAM,CAAC,CAC5C,KAAK,SAAc,MAAM,QAAQ,EACrB,CAAC,CAAC,KAAK,EAAE;CAE1B,OAAO;AACT;;;;;;;AAQA,SAAS,sBAAsB,WAAkC;CAE/D,KAAA,GAAA,wBAAA,oBAAA,CAAwB,SAAS,GAG/B,OAAO;EAAC;EAAS;EAAa;EAAgB;EAAgB;EAAc;CAAY;CAI1F,MAAM,SAA2B,CAAC;CAClC,IAAI,OAAO,UAAU,iBAAiB,YACpC,OAAO,KAAK,OAAO;CAErB,IAAI,OAAO,UAAU,qBAAqB,YACxC,OAAO,KAAK,WAAW;CAEzB,IAAI,OAAO,UAAU,wBAAwB,YAC3C,OAAO,KAAK,cAAc;CAE5B,IAAI,OAAO,UAAU,wBAAwB,YAC3C,OAAO,KAAK,cAAc;CAE5B,IAAI,OAAO,UAAU,sBAAsB,YACzC,OAAO,KAAK,YAAY;CAE1B,IAAI,OAAO,UAAU,sBAAsB,YACzC,OAAO,KAAK,YAAY;CAE1B,OAAO;AACT;AAEA,MAAa,wBAAwBA,sBAAAA,YAAY;CAC/C,QAAQ;CACR,MAAM;CACN,cAAc;CACd,gBAAgBC,mBAAAA;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,YAAY;CACnB,cAAc;CACd,SAAS,OAAO,EAAE,aAAa;EAC7B,IAAI;GACF,MAAM,aAAa,OAAO,eA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IAAI,IAAI,GAAG;UAC9B,IAAI,OAAO,UAChB,iBAAiB,OAAO;IAAA;IAI5B,OAAO;KACL,SAAS;KACT;KACA,UAAU;KACV,aAAa,EACX,UAAU,eACZ;IACF;GACF,SAAS,OAAY;IAEnB,IAAI,qBAAqB,MAAM,SAAS,WAAW,WAAW,GAC5D,OAAO;KACL,SAAS;KACT;KACA,UAAU;MACR,WAAW;MACX,QAAQ,kBAAkB,MAAM,SAAS,QAAQ,aAAa,EAAE;MAChE,UAAU;KACZ;KACA;KACA,aAAa,EACX,SACF;IACF;IAEF,MAAM;GACR;EACF,SAAS,OAAO;GACd,OAAOH,8BAAAA,YAAY,OAAO,2BAA2B;EACvD;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"processors.cjs","names":["createRoute","listProcessorsResponseSchema","handleError","processorIdPathParams","serializedProcessorDetailSchema","HTTPException","executeProcessorBodySchema","executeProcessorResponseSchema","MessageList"],"sources":["../../../src/server/handlers/processors.ts"],"sourcesContent":["import { MessageList } from '@mastra/core/agent';\nimport type { MessageInput } from '@mastra/core/agent/message-list';\nimport { isProcessorWorkflow } from '@mastra/core/processors';\nimport type { Processor, ProcessorWorkflow } from '@mastra/core/processors';\n\nimport { HTTPException } from '../http-exception';\nimport {\n listProcessorsResponseSchema,\n serializedProcessorDetailSchema,\n processorIdPathParams,\n executeProcessorBodySchema,\n executeProcessorResponseSchema,\n} from '../schemas/processors';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\ntype ProcessorPhase =\n | 'input'\n | 'inputStep'\n | 'outputStream'\n | 'outputResult'\n | 'outputStep'\n | 'toolResult'\n | 'llmRequest';\n\n/**\n * Helper to extract text from messages for outputStep testing.\n * In real usage, the `text` field contains the assistant's response text.\n */\nfunction extractTextFromMessages(messages: unknown[]): string {\n if (!messages || !Array.isArray(messages) || messages.length === 0) {\n return '';\n }\n const firstMessage = messages[0] as any;\n if (firstMessage?.content?.parts) {\n const textParts = firstMessage.content.parts\n .filter((part: any) => part?.type === 'text')\n .map((part: any) => part?.text || '');\n return textParts.join('');\n }\n return '';\n}\n\n/**\n * Helper to detect phases for a processor.\n * For individual processors, checks which methods are implemented.\n * For workflow processors, returns all phases since createStep handles each phase\n * and it's a no-op if the underlying processor doesn't implement it.\n */\nfunction detectProcessorPhases(processor: any): ProcessorPhase[] {\n // Check if it's a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Workflow processors can potentially handle all phases\n // The createStep in workflows handles each phase and it's a no-op if not implemented\n return ['input', 'inputStep', 'outputStream', 'outputResult', 'outputStep', 'toolResult'];\n }\n\n // For individual processors, detect by checking which methods exist\n const phases: ProcessorPhase[] = [];\n if (typeof processor.processInput === 'function') {\n phases.push('input');\n }\n if (typeof processor.processInputStep === 'function') {\n phases.push('inputStep');\n }\n if (typeof processor.processOutputStream === 'function') {\n phases.push('outputStream');\n }\n if (typeof processor.processOutputResult === 'function') {\n phases.push('outputResult');\n }\n if (typeof processor.processOutputStep === 'function') {\n phases.push('outputStep');\n }\n if (typeof processor.processToolResult === 'function') {\n phases.push('toolResult');\n }\n if (typeof processor.processLLMRequest === 'function') {\n phases.push('llmRequest');\n }\n return phases;\n}\n\nexport const LIST_PROCESSORS_ROUTE = createRoute({\n method: 'GET',\n path: '/processors',\n responseType: 'json',\n responseSchema: listProcessorsResponseSchema,\n summary: 'List all processors',\n description: 'Returns a list of all available individual processors',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n try {\n const processors = mastra.listProcessors() || {};\n const processorConfigurations = mastra.listProcessorConfigurations();\n const result: Record<\n string,\n {\n id: string;\n name?: string;\n description?: string;\n phases: ProcessorPhase[];\n agentIds: string[];\n configurations: Array<{ agentId: string; type: 'input' | 'output' }>;\n isWorkflow: boolean;\n }\n > = {};\n\n // Iterate through all individual processors registered with Mastra\n for (const [processorKey, processorEntry] of Object.entries(processors)) {\n const processor = processorEntry as Processor | ProcessorWorkflow;\n const processorId = processor.id || processorKey;\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processor);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processor);\n\n // Get agent configurations for this processor\n const configs = processorConfigurations.get(processorId) || [];\n const agentIds = [...new Set(configs.map(c => c.agentId))];\n const configurations = configs.map(c => ({ agentId: c.agentId, type: c.type }));\n\n result[processorId] = {\n id: processorId,\n name: processor.name || processorId,\n description: processor.description,\n phases,\n agentIds,\n configurations,\n isWorkflow,\n };\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error getting processors');\n }\n },\n});\n\nexport const GET_PROCESSOR_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/processors/:processorId',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n responseSchema: serializedProcessorDetailSchema,\n summary: 'Get processor by ID',\n description: 'Returns details for a specific processor including its phases and configurations',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId }) => {\n try {\n // Get the processor from Mastra's registered processors\n let processorEntry: Processor | ProcessorWorkflow | undefined;\n try {\n processorEntry = mastra.getProcessorById(processorId) as Processor | ProcessorWorkflow;\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processorEntry = processors[processorId as keyof typeof processors] as Processor | ProcessorWorkflow;\n }\n\n if (!processorEntry) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processorEntry);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processorEntry);\n\n // Get agent configurations for this processor\n const configs = mastra.getProcessorConfigurations(processorId);\n const agents = mastra.listAgents() || {};\n const configurations = configs.map(c => ({\n agentId: c.agentId,\n agentName: agents[c.agentId]?.name || c.agentId,\n type: c.type,\n }));\n\n return {\n id: processorEntry.id,\n name: processorEntry.name || processorEntry.id,\n description: processorEntry.description,\n phases,\n configurations,\n isWorkflow,\n };\n } catch (error) {\n return handleError(error, 'Error getting processor');\n }\n },\n});\n\nexport const EXECUTE_PROCESSOR_ROUTE = createRoute({\n method: 'POST',\n path: '/processors/:processorId/execute',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n bodySchema: executeProcessorBodySchema,\n responseSchema: executeProcessorResponseSchema,\n summary: 'Execute processor',\n description: 'Executes a specific processor with the provided input data',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId, ...bodyParams }) => {\n try {\n const { phase, messages } = bodyParams;\n\n if (!processorId) {\n throw new HTTPException(400, { message: 'Processor ID is required' });\n }\n\n if (!phase) {\n throw new HTTPException(400, { message: 'Phase is required' });\n }\n\n if (phase === 'llmRequest') {\n // processLLMRequest operates on the provider prompt, not on messages\n throw new HTTPException(400, {\n message: 'llmRequest phase cannot be executed directly. It runs on the provider prompt during an agent call.',\n });\n }\n\n if (!messages || !Array.isArray(messages)) {\n throw new HTTPException(400, { message: 'Messages array is required' });\n }\n\n // Get the processor from Mastra's registered processors\n let processor;\n try {\n processor = mastra.getProcessorById(processorId);\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processor = processors[processorId as keyof typeof processors];\n }\n\n if (!processor) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n const messageList = new MessageList();\n messageList.add(messages as unknown as MessageInput[], 'input');\n\n // Check if this is a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Execute workflow processor\n try {\n // Build inputData based on phase - each phase has different required fields\n const baseInputData = {\n phase: phase as 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult',\n messages: messageList.get.all.db(),\n messageList,\n retryCount: 0,\n };\n let inputData: typeof baseInputData & Record<string, unknown> = baseInputData;\n\n // Add phase-specific fields\n switch (phase) {\n case 'input':\n inputData = {\n ...inputData,\n systemMessages: [],\n };\n break;\n case 'inputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n model: '',\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n };\n break;\n case 'outputResult':\n inputData = {\n ...inputData,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n };\n break;\n case 'outputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n };\n break;\n case 'outputStream':\n inputData = {\n ...inputData,\n part: null,\n streamParts: [],\n state: {},\n };\n break;\n case 'toolResult':\n inputData = {\n ...inputData,\n stepNumber: 0,\n toolName: '',\n toolCallId: '',\n args: undefined,\n toolResultValue: undefined,\n providerExecuted: false,\n systemMessages: [],\n steps: [],\n };\n break;\n }\n\n const run = await processor.createRun();\n const result = await run.start({\n inputData,\n });\n\n // Check for tripwire status\n if (result.status === 'tripwire') {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: result.tripwire.reason || `Tripwire triggered in workflow ${processor.id}`,\n metadata: result.tripwire.metadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n\n // Check for execution failure\n if (result.status !== 'success') {\n throw new HTTPException(500, {\n message: `Processor workflow ${processor.id} failed with status: ${result.status}`,\n });\n }\n\n // Extract output from workflow result\n const output = result.result;\n let outputMessages = messages;\n\n if (output && typeof output === 'object') {\n if ('messages' in output && Array.isArray(output.messages)) {\n outputMessages = output.messages;\n } else if ('messageList' in output && output.messageList instanceof MessageList) {\n outputMessages = output.messageList.get.all.db();\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Re-throw HTTP exceptions\n if (error instanceof HTTPException) {\n throw error;\n }\n throw new HTTPException(500, {\n message: `Error executing processor workflow: ${error.message}`,\n });\n }\n }\n\n // Handle individual processor execution\n // Create the abort function for tripwire support\n let tripwireTriggered = false;\n let tripwireReason: string | undefined;\n let tripwireMetadata: unknown;\n\n const abort = (reason?: string, options?: { retry?: boolean; metadata?: unknown }) => {\n tripwireTriggered = true;\n tripwireReason = reason;\n tripwireMetadata = options?.metadata;\n throw new Error(`TRIPWIRE:${reason || 'Processor aborted'}`);\n };\n\n // Build the context based on phase\n const baseContext = {\n abort,\n retryCount: 0,\n messages: messageList.get.all.db(),\n messageList,\n state: {},\n };\n\n try {\n let result: any;\n\n // Execute the specific phase method on the individual processor\n switch (phase) {\n case 'input':\n if (!processor.processInput) {\n throw new HTTPException(400, { message: 'Processor does not support input phase' });\n }\n result = await processor.processInput({\n ...baseContext,\n systemMessages: [],\n });\n break;\n\n case 'inputStep':\n if (!processor.processInputStep) {\n throw new HTTPException(400, { message: 'Processor does not support inputStep phase' });\n }\n result = await processor.processInputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n // Pass empty/default values for all inputStep fields\n model: '' as any,\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n });\n break;\n\n case 'outputResult':\n if (!processor.processOutputResult) {\n throw new HTTPException(400, { message: 'Processor does not support outputResult phase' });\n }\n result = await processor.processOutputResult({\n ...baseContext,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n });\n break;\n\n case 'outputStep':\n if (!processor.processOutputStep) {\n throw new HTTPException(400, { message: 'Processor does not support outputStep phase' });\n }\n result = await processor.processOutputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },\n });\n break;\n\n case 'outputStream':\n // outputStream is for streaming chunks, not a simple execute\n throw new HTTPException(400, {\n message: 'outputStream phase cannot be executed directly. Use streaming instead.',\n });\n\n default:\n throw new HTTPException(400, { message: `Unknown phase: ${phase}` });\n }\n\n // Process the result\n let outputMessages = messages;\n if (result) {\n if (Array.isArray(result)) {\n outputMessages = result;\n } else if (result.get && result.get.all && typeof result.get.all.db === 'function') {\n // It's a MessageList\n outputMessages = result.get.all.db();\n } else if (result.messages) {\n outputMessages = result.messages;\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Check if it's a tripwire\n if (tripwireTriggered || error.message?.startsWith('TRIPWIRE:')) {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: tripwireReason || error.message?.replace('TRIPWIRE:', ''),\n metadata: tripwireMetadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n throw error;\n }\n } catch (error) {\n return handleError(error, 'Error executing processor');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;AAiCA,SAAS,wBAAwB,UAA6B;CAC5D,IAAI,CAAC,YAAY,CAAC,MAAM,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAC/D,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,IAAI,cAAc,SAAS,OAIzB,OAHkB,aAAa,QAAQ,MACpC,QAAQ,SAAc,MAAM,SAAS,MAAM,CAAC,CAC5C,KAAK,SAAc,MAAM,QAAQ,EACrB,CAAC,CAAC,KAAK,EAAE;CAE1B,OAAO;AACT;;;;;;;AAQA,SAAS,sBAAsB,WAAkC;CAE/D,KAAA,GAAA,wBAAA,oBAAA,CAAwB,SAAS,GAG/B,OAAO;EAAC;EAAS;EAAa;EAAgB;EAAgB;EAAc;CAAY;CAI1F,MAAM,SAA2B,CAAC;CAClC,IAAI,OAAO,UAAU,iBAAiB,YACpC,OAAO,KAAK,OAAO;CAErB,IAAI,OAAO,UAAU,qBAAqB,YACxC,OAAO,KAAK,WAAW;CAEzB,IAAI,OAAO,UAAU,wBAAwB,YAC3C,OAAO,KAAK,cAAc;C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UAAU,kBAAkB;OACzC,GAAG;OACH,gBAAgB,CAAC;OACjB,YAAY;OACZ,OAAO,CAAC;OACR,cAAc;OACd,WAAW,CAAC;OACZ,MAAM,wBAAwB,QAAQ;OACtC,OAAO;QAAE,aAAa,KAAA;QAAW,cAAc,KAAA;QAAW,aAAa,KAAA;OAAU;MACnF,CAAC;MACD;KAEF,KAAK,gBAEH,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAC3B,SAAS,yEACX,CAAC;KAEH,SACE,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,kBAAkB,QAAQ,CAAC;IACvE;IAGA,IAAI,iBAAiB;IACrB,IAAI,QACE;SAAA,MAAM,QAAQ,MAAM,GACtB,iBAAiB;UACZ,IAAI,OAAO,OAAO,OAAO,IAAI,OAAO,OAAO,OAAO,IAAI,IAAI,OAAO,YAEtE,iBAAiB,OAAO,IAAI,IAAI,GAAG;UAC9B,IAAI,OAAO,UAChB,iBAAiB,OAAO;IAAA;IAI5B,OAAO;KACL,SAAS;KACT;KACA,UAAU;KACV,aAAa,EACX,UAAU,eACZ;IACF;GACF,SAAS,OAAY;IAEnB,IAAI,qBAAqB,MAAM,SAAS,WAAW,WAAW,GAC5D,OAAO;KACL,SAAS;KACT;KACA,UAAU;MACR,WAAW;MACX,QAAQ,kBAAkB,MAAM,SAAS,QAAQ,aAAa,EAAE;MAChE,UAAU;KACZ;KACA;KACA,aAAa,EACX,SACF;IACF;IAEF,MAAM;GACR;EACF,SAAS,OAAO;GACd,OAAOH,8BAAAA,YAAY,OAAO,2BAA2B;EACvD;CACF;AACF,CAAC"}
@@ -8,7 +8,7 @@ export declare const LIST_PROCESSORS_ROUTE: Omit<import("@mastra/core/server").A
8
8
  id: string;
9
9
  name?: string | undefined;
10
10
  description?: string | undefined;
11
- phases: ("input" | "inputStep" | "outputResult" | "outputStep" | "outputStream" | "toolResult")[];
11
+ phases: ("input" | "inputStep" | "llmRequest" | "outputResult" | "outputStep" | "outputStream" | "toolResult")[];
12
12
  agentIds: string[];
13
13
  configurations: {
14
14
  agentId: string;
@@ -33,6 +33,7 @@ export declare const LIST_PROCESSORS_ROUTE: Omit<import("@mastra/core/server").A
33
33
  phases: import("zod").ZodArray<import("zod").ZodEnum<{
34
34
  input: "input";
35
35
  inputStep: "inputStep";
36
+ llmRequest: "llmRequest";
36
37
  outputResult: "outputResult";
37
38
  outputStep: "outputStep";
38
39
  outputStream: "outputStream";
@@ -63,7 +64,7 @@ export declare const GET_PROCESSOR_BY_ID_ROUTE: Omit<import("@mastra/core/server
63
64
  id: string;
64
65
  name?: string | undefined;
65
66
  description?: string | undefined;
66
- phases: ("input" | "inputStep" | "outputResult" | "outputStep" | "outputStream" | "toolResult")[];
67
+ phases: ("input" | "inputStep" | "llmRequest" | "outputResult" | "outputStep" | "outputStream" | "toolResult")[];
67
68
  configurations: {
68
69
  agentId: string;
69
70
  agentName: string;
@@ -90,6 +91,7 @@ export declare const GET_PROCESSOR_BY_ID_ROUTE: Omit<import("@mastra/core/server
90
91
  phases: import("zod").ZodArray<import("zod").ZodEnum<{
91
92
  input: "input";
92
93
  inputStep: "inputStep";
94
+ llmRequest: "llmRequest";
93
95
  outputResult: "outputResult";
94
96
  outputStep: "outputStep";
95
97
  outputStream: "outputStream";
@@ -117,7 +119,7 @@ export declare const EXECUTE_PROCESSOR_ROUTE: Omit<import("@mastra/core/server")
117
119
  handler(params: {
118
120
  processorId: string;
119
121
  } & {
120
- phase: "input" | "inputStep" | "outputResult" | "outputStep" | "outputStream" | "toolResult";
122
+ phase: "input" | "inputStep" | "llmRequest" | "outputResult" | "outputStep" | "outputStream" | "toolResult";
121
123
  messages: {
122
124
  [x: string]: unknown;
123
125
  id: string;
@@ -184,6 +186,7 @@ export declare const EXECUTE_PROCESSOR_ROUTE: Omit<import("@mastra/core/server")
184
186
  phase: import("zod").ZodEnum<{
185
187
  input: "input";
186
188
  inputStep: "inputStep";
189
+ llmRequest: "llmRequest";
187
190
  outputResult: "outputResult";
188
191
  outputStep: "outputStep";
189
192
  outputStream: "outputStream";
@@ -1 +1 @@
1
- {"version":3,"file":"processors.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/processors.ts"],"names":[],"mappings":"AA6EA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DhC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDpC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyUlC,CAAC"}
1
+ {"version":3,"file":"processors.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/processors.ts"],"names":[],"mappings":"AAuFA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DhC,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDpC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgVlC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { t as HTTPException } from "../../http-exception-CyfxZB6W.js";
2
2
  import { n as createRoute } from "../../route-builder-lBil8Cvo.js";
3
3
  import { handleError } from "./error.js";
4
- import { a as processorIdPathParams, n as executeProcessorResponseSchema, o as serializedProcessorDetailSchema, r as listProcessorsResponseSchema, t as executeProcessorBodySchema } from "../../processors-88oJ_4J-.js";
4
+ import { a as processorIdPathParams, n as executeProcessorResponseSchema, o as serializedProcessorDetailSchema, r as listProcessorsResponseSchema, t as executeProcessorBodySchema } from "../../processors-33IULT8X.js";
5
5
  import { MessageList } from "@mastra/core/agent";
6
6
  import { isProcessorWorkflow } from "@mastra/core/processors";
7
7
  //#region src/server/handlers/processors.ts
@@ -37,6 +37,7 @@ function detectProcessorPhases(processor) {
37
37
  if (typeof processor.processOutputResult === "function") phases.push("outputResult");
38
38
  if (typeof processor.processOutputStep === "function") phases.push("outputStep");
39
39
  if (typeof processor.processToolResult === "function") phases.push("toolResult");
40
+ if (typeof processor.processLLMRequest === "function") phases.push("llmRequest");
40
41
  return phases;
41
42
  }
42
43
  const LIST_PROCESSORS_ROUTE = createRoute({
@@ -137,6 +138,7 @@ const EXECUTE_PROCESSOR_ROUTE = createRoute({
137
138
  const { phase, messages } = bodyParams;
138
139
  if (!processorId) throw new HTTPException(400, { message: "Processor ID is required" });
139
140
  if (!phase) throw new HTTPException(400, { message: "Phase is required" });
141
+ if (phase === "llmRequest") throw new HTTPException(400, { message: "llmRequest phase cannot be executed directly. It runs on the provider prompt during an agent call." });
140
142
  if (!messages || !Array.isArray(messages)) throw new HTTPException(400, { message: "Messages array is required" });
141
143
  let processor;
142
144
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"processors.js","names":[],"sources":["../../../src/server/handlers/processors.ts"],"sourcesContent":["import { MessageList } from '@mastra/core/agent';\nimport type { MessageInput } from '@mastra/core/agent/message-list';\nimport { isProcessorWorkflow } from '@mastra/core/processors';\nimport type { Processor, ProcessorWorkflow } from '@mastra/core/processors';\n\nimport { HTTPException } from '../http-exception';\nimport {\n listProcessorsResponseSchema,\n serializedProcessorDetailSchema,\n processorIdPathParams,\n executeProcessorBodySchema,\n executeProcessorResponseSchema,\n} from '../schemas/processors';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\ntype ProcessorPhase = 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult';\n\n/**\n * Helper to extract text from messages for outputStep testing.\n * In real usage, the `text` field contains the assistant's response text.\n */\nfunction extractTextFromMessages(messages: unknown[]): string {\n if (!messages || !Array.isArray(messages) || messages.length === 0) {\n return '';\n }\n const firstMessage = messages[0] as any;\n if (firstMessage?.content?.parts) {\n const textParts = firstMessage.content.parts\n .filter((part: any) => part?.type === 'text')\n .map((part: any) => part?.text || '');\n return textParts.join('');\n }\n return '';\n}\n\n/**\n * Helper to detect phases for a processor.\n * For individual processors, checks which methods are implemented.\n * For workflow processors, returns all phases since createStep handles each phase\n * and it's a no-op if the underlying processor doesn't implement it.\n */\nfunction detectProcessorPhases(processor: any): ProcessorPhase[] {\n // Check if it's a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Workflow processors can potentially handle all phases\n // The createStep in workflows handles each phase and it's a no-op if not implemented\n return ['input', 'inputStep', 'outputStream', 'outputResult', 'outputStep', 'toolResult'];\n }\n\n // For individual processors, detect by checking which methods exist\n const phases: ProcessorPhase[] = [];\n if (typeof processor.processInput === 'function') {\n phases.push('input');\n }\n if (typeof processor.processInputStep === 'function') {\n phases.push('inputStep');\n }\n if (typeof processor.processOutputStream === 'function') {\n phases.push('outputStream');\n }\n if (typeof processor.processOutputResult === 'function') {\n phases.push('outputResult');\n }\n if (typeof processor.processOutputStep === 'function') {\n phases.push('outputStep');\n }\n if (typeof processor.processToolResult === 'function') {\n phases.push('toolResult');\n }\n return phases;\n}\n\nexport const LIST_PROCESSORS_ROUTE = createRoute({\n method: 'GET',\n path: '/processors',\n responseType: 'json',\n responseSchema: listProcessorsResponseSchema,\n summary: 'List all processors',\n description: 'Returns a list of all available individual processors',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n try {\n const processors = mastra.listProcessors() || {};\n const processorConfigurations = mastra.listProcessorConfigurations();\n const result: Record<\n string,\n {\n id: string;\n name?: string;\n description?: string;\n phases: ProcessorPhase[];\n agentIds: string[];\n configurations: Array<{ agentId: string; type: 'input' | 'output' }>;\n isWorkflow: boolean;\n }\n > = {};\n\n // Iterate through all individual processors registered with Mastra\n for (const [processorKey, processorEntry] of Object.entries(processors)) {\n const processor = processorEntry as Processor | ProcessorWorkflow;\n const processorId = processor.id || processorKey;\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processor);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processor);\n\n // Get agent configurations for this processor\n const configs = processorConfigurations.get(processorId) || [];\n const agentIds = [...new Set(configs.map(c => c.agentId))];\n const configurations = configs.map(c => ({ agentId: c.agentId, type: c.type }));\n\n result[processorId] = {\n id: processorId,\n name: processor.name || processorId,\n description: processor.description,\n phases,\n agentIds,\n configurations,\n isWorkflow,\n };\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error getting processors');\n }\n },\n});\n\nexport const GET_PROCESSOR_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/processors/:processorId',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n responseSchema: serializedProcessorDetailSchema,\n summary: 'Get processor by ID',\n description: 'Returns details for a specific processor including its phases and configurations',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId }) => {\n try {\n // Get the processor from Mastra's registered processors\n let processorEntry: Processor | ProcessorWorkflow | undefined;\n try {\n processorEntry = mastra.getProcessorById(processorId) as Processor | ProcessorWorkflow;\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processorEntry = processors[processorId as keyof typeof processors] as Processor | ProcessorWorkflow;\n }\n\n if (!processorEntry) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processorEntry);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processorEntry);\n\n // Get agent configurations for this processor\n const configs = mastra.getProcessorConfigurations(processorId);\n const agents = mastra.listAgents() || {};\n const configurations = configs.map(c => ({\n agentId: c.agentId,\n agentName: agents[c.agentId]?.name || c.agentId,\n type: c.type,\n }));\n\n return {\n id: processorEntry.id,\n name: processorEntry.name || processorEntry.id,\n description: processorEntry.description,\n phases,\n configurations,\n isWorkflow,\n };\n } catch (error) {\n return handleError(error, 'Error getting processor');\n }\n },\n});\n\nexport const EXECUTE_PROCESSOR_ROUTE = createRoute({\n method: 'POST',\n path: '/processors/:processorId/execute',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n bodySchema: executeProcessorBodySchema,\n responseSchema: executeProcessorResponseSchema,\n summary: 'Execute processor',\n description: 'Executes a specific processor with the provided input data',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId, ...bodyParams }) => {\n try {\n const { phase, messages } = bodyParams;\n\n if (!processorId) {\n throw new HTTPException(400, { message: 'Processor ID is required' });\n }\n\n if (!phase) {\n throw new HTTPException(400, { message: 'Phase is required' });\n }\n\n if (!messages || !Array.isArray(messages)) {\n throw new HTTPException(400, { message: 'Messages array is required' });\n }\n\n // Get the processor from Mastra's registered processors\n let processor;\n try {\n processor = mastra.getProcessorById(processorId);\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processor = processors[processorId as keyof typeof processors];\n }\n\n if (!processor) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n const messageList = new MessageList();\n messageList.add(messages as unknown as MessageInput[], 'input');\n\n // Check if this is a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Execute workflow processor\n try {\n // Build inputData based on phase - each phase has different required fields\n const baseInputData = {\n phase: phase as 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult',\n messages: messageList.get.all.db(),\n messageList,\n retryCount: 0,\n };\n let inputData: typeof baseInputData & Record<string, unknown> = baseInputData;\n\n // Add phase-specific fields\n switch (phase) {\n case 'input':\n inputData = {\n ...inputData,\n systemMessages: [],\n };\n break;\n case 'inputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n model: '',\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n };\n break;\n case 'outputResult':\n inputData = {\n ...inputData,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n };\n break;\n case 'outputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n };\n break;\n case 'outputStream':\n inputData = {\n ...inputData,\n part: null,\n streamParts: [],\n state: {},\n };\n break;\n case 'toolResult':\n inputData = {\n ...inputData,\n stepNumber: 0,\n toolName: '',\n toolCallId: '',\n args: undefined,\n toolResultValue: undefined,\n providerExecuted: false,\n systemMessages: [],\n steps: [],\n };\n break;\n }\n\n const run = await processor.createRun();\n const result = await run.start({\n inputData,\n });\n\n // Check for tripwire status\n if (result.status === 'tripwire') {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: result.tripwire.reason || `Tripwire triggered in workflow ${processor.id}`,\n metadata: result.tripwire.metadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n\n // Check for execution failure\n if (result.status !== 'success') {\n throw new HTTPException(500, {\n message: `Processor workflow ${processor.id} failed with status: ${result.status}`,\n });\n }\n\n // Extract output from workflow result\n const output = result.result;\n let outputMessages = messages;\n\n if (output && typeof output === 'object') {\n if ('messages' in output && Array.isArray(output.messages)) {\n outputMessages = output.messages;\n } else if ('messageList' in output && output.messageList instanceof MessageList) {\n outputMessages = output.messageList.get.all.db();\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Re-throw HTTP exceptions\n if (error instanceof HTTPException) {\n throw error;\n }\n throw new HTTPException(500, {\n message: `Error executing processor workflow: ${error.message}`,\n });\n }\n }\n\n // Handle individual processor execution\n // Create the abort function for tripwire support\n let tripwireTriggered = false;\n let tripwireReason: string | undefined;\n let tripwireMetadata: unknown;\n\n const abort = (reason?: string, options?: { retry?: boolean; metadata?: unknown }) => {\n tripwireTriggered = true;\n tripwireReason = reason;\n tripwireMetadata = options?.metadata;\n throw new Error(`TRIPWIRE:${reason || 'Processor aborted'}`);\n };\n\n // Build the context based on phase\n const baseContext = {\n abort,\n retryCount: 0,\n messages: messageList.get.all.db(),\n messageList,\n state: {},\n };\n\n try {\n let result: any;\n\n // Execute the specific phase method on the individual processor\n switch (phase) {\n case 'input':\n if (!processor.processInput) {\n throw new HTTPException(400, { message: 'Processor does not support input phase' });\n }\n result = await processor.processInput({\n ...baseContext,\n systemMessages: [],\n });\n break;\n\n case 'inputStep':\n if (!processor.processInputStep) {\n throw new HTTPException(400, { message: 'Processor does not support inputStep phase' });\n }\n result = await processor.processInputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n // Pass empty/default values for all inputStep fields\n model: '' as any,\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n });\n break;\n\n case 'outputResult':\n if (!processor.processOutputResult) {\n throw new HTTPException(400, { message: 'Processor does not support outputResult phase' });\n }\n result = await processor.processOutputResult({\n ...baseContext,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n });\n break;\n\n case 'outputStep':\n if (!processor.processOutputStep) {\n throw new HTTPException(400, { message: 'Processor does not support outputStep phase' });\n }\n result = await processor.processOutputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },\n });\n break;\n\n case 'outputStream':\n // outputStream is for streaming chunks, not a simple execute\n throw new HTTPException(400, {\n message: 'outputStream phase cannot be executed directly. Use streaming instead.',\n });\n\n default:\n throw new HTTPException(400, { message: `Unknown phase: ${phase}` });\n }\n\n // Process the result\n let outputMessages = messages;\n if (result) {\n if (Array.isArray(result)) {\n outputMessages = result;\n } else if (result.get && result.get.all && typeof result.get.all.db === 'function') {\n // It's a MessageList\n outputMessages = result.get.all.db();\n } else if (result.messages) {\n outputMessages = result.messages;\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Check if it's a tripwire\n if (tripwireTriggered || error.message?.startsWith('TRIPWIRE:')) {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: tripwireReason || error.message?.replace('TRIPWIRE:', ''),\n metadata: tripwireMetadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n throw error;\n }\n } catch (error) {\n return handleError(error, 'Error executing processor');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;AA0BA,SAAS,wBAAwB,UAA6B;CAC5D,IAAI,CAAC,YAAY,CAAC,MAAM,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAC/D,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,IAAI,cAAc,SAAS,OAIzB,OAHkB,aAAa,QAAQ,MACpC,QAAQ,SAAc,MAAM,SAAS,MAAM,CAAC,CAC5C,KAAK,SAAc,MAAM,QAAQ,EACrB,CAAC,CAAC,KAAK,EAAE;CAE1B,OAAO;AACT;;;;;;;AAQA,SAAS,sBAAsB,WAAkC;CAE/D,IAAI,oBAAoB,SAAS,GAG/B,OAAO;EAAC;EAAS;EAAa;EAAgB;EAAgB;EAAc;CAAY;CAI1F,MAAM,SAA2B,CAAC;CAClC,IAAI,OAAO,UAAU,iBAAiB,YACpC,OAAO,KAAK,OAAO;CAErB,IAA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S,kBAAkB,QAAQ,CAAC;IACvE;IAGA,IAAI,iBAAiB;IACrB,IAAI,QACE;SAAA,MAAM,QAAQ,MAAM,GACtB,iBAAiB;UACZ,IAAI,OAAO,OAAO,OAAO,IAAI,OAAO,OAAO,OAAO,IAAI,IAAI,OAAO,YAEtE,iBAAiB,OAAO,IAAI,IAAI,GAAG;UAC9B,IAAI,OAAO,UAChB,iBAAiB,OAAO;IAAA;IAI5B,OAAO;KACL,SAAS;KACT;KACA,UAAU;KACV,aAAa,EACX,UAAU,eACZ;IACF;GACF,SAAS,OAAY;IAEnB,IAAI,qBAAqB,MAAM,SAAS,WAAW,WAAW,GAC5D,OAAO;KACL,SAAS;KACT;KACA,UAAU;MACR,WAAW;MACX,QAAQ,kBAAkB,MAAM,SAAS,QAAQ,aAAa,EAAE;MAChE,UAAU;KACZ;KACA;KACA,aAAa,EACX,SACF;IACF;IAEF,MAAM;GACR;EACF,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,2BAA2B;EACvD;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"processors.js","names":[],"sources":["../../../src/server/handlers/processors.ts"],"sourcesContent":["import { MessageList } from '@mastra/core/agent';\nimport type { MessageInput } from '@mastra/core/agent/message-list';\nimport { isProcessorWorkflow } from '@mastra/core/processors';\nimport type { Processor, ProcessorWorkflow } from '@mastra/core/processors';\n\nimport { HTTPException } from '../http-exception';\nimport {\n listProcessorsResponseSchema,\n serializedProcessorDetailSchema,\n processorIdPathParams,\n executeProcessorBodySchema,\n executeProcessorResponseSchema,\n} from '../schemas/processors';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { handleError } from './error';\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\ntype ProcessorPhase =\n | 'input'\n | 'inputStep'\n | 'outputStream'\n | 'outputResult'\n | 'outputStep'\n | 'toolResult'\n | 'llmRequest';\n\n/**\n * Helper to extract text from messages for outputStep testing.\n * In real usage, the `text` field contains the assistant's response text.\n */\nfunction extractTextFromMessages(messages: unknown[]): string {\n if (!messages || !Array.isArray(messages) || messages.length === 0) {\n return '';\n }\n const firstMessage = messages[0] as any;\n if (firstMessage?.content?.parts) {\n const textParts = firstMessage.content.parts\n .filter((part: any) => part?.type === 'text')\n .map((part: any) => part?.text || '');\n return textParts.join('');\n }\n return '';\n}\n\n/**\n * Helper to detect phases for a processor.\n * For individual processors, checks which methods are implemented.\n * For workflow processors, returns all phases since createStep handles each phase\n * and it's a no-op if the underlying processor doesn't implement it.\n */\nfunction detectProcessorPhases(processor: any): ProcessorPhase[] {\n // Check if it's a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Workflow processors can potentially handle all phases\n // The createStep in workflows handles each phase and it's a no-op if not implemented\n return ['input', 'inputStep', 'outputStream', 'outputResult', 'outputStep', 'toolResult'];\n }\n\n // For individual processors, detect by checking which methods exist\n const phases: ProcessorPhase[] = [];\n if (typeof processor.processInput === 'function') {\n phases.push('input');\n }\n if (typeof processor.processInputStep === 'function') {\n phases.push('inputStep');\n }\n if (typeof processor.processOutputStream === 'function') {\n phases.push('outputStream');\n }\n if (typeof processor.processOutputResult === 'function') {\n phases.push('outputResult');\n }\n if (typeof processor.processOutputStep === 'function') {\n phases.push('outputStep');\n }\n if (typeof processor.processToolResult === 'function') {\n phases.push('toolResult');\n }\n if (typeof processor.processLLMRequest === 'function') {\n phases.push('llmRequest');\n }\n return phases;\n}\n\nexport const LIST_PROCESSORS_ROUTE = createRoute({\n method: 'GET',\n path: '/processors',\n responseType: 'json',\n responseSchema: listProcessorsResponseSchema,\n summary: 'List all processors',\n description: 'Returns a list of all available individual processors',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n try {\n const processors = mastra.listProcessors() || {};\n const processorConfigurations = mastra.listProcessorConfigurations();\n const result: Record<\n string,\n {\n id: string;\n name?: string;\n description?: string;\n phases: ProcessorPhase[];\n agentIds: string[];\n configurations: Array<{ agentId: string; type: 'input' | 'output' }>;\n isWorkflow: boolean;\n }\n > = {};\n\n // Iterate through all individual processors registered with Mastra\n for (const [processorKey, processorEntry] of Object.entries(processors)) {\n const processor = processorEntry as Processor | ProcessorWorkflow;\n const processorId = processor.id || processorKey;\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processor);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processor);\n\n // Get agent configurations for this processor\n const configs = processorConfigurations.get(processorId) || [];\n const agentIds = [...new Set(configs.map(c => c.agentId))];\n const configurations = configs.map(c => ({ agentId: c.agentId, type: c.type }));\n\n result[processorId] = {\n id: processorId,\n name: processor.name || processorId,\n description: processor.description,\n phases,\n agentIds,\n configurations,\n isWorkflow,\n };\n }\n\n return result;\n } catch (error) {\n return handleError(error, 'Error getting processors');\n }\n },\n});\n\nexport const GET_PROCESSOR_BY_ID_ROUTE = createRoute({\n method: 'GET',\n path: '/processors/:processorId',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n responseSchema: serializedProcessorDetailSchema,\n summary: 'Get processor by ID',\n description: 'Returns details for a specific processor including its phases and configurations',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId }) => {\n try {\n // Get the processor from Mastra's registered processors\n let processorEntry: Processor | ProcessorWorkflow | undefined;\n try {\n processorEntry = mastra.getProcessorById(processorId) as Processor | ProcessorWorkflow;\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processorEntry = processors[processorId as keyof typeof processors] as Processor | ProcessorWorkflow;\n }\n\n if (!processorEntry) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n // Check if it's a workflow processor\n const isWorkflow = isProcessorWorkflow(processorEntry);\n\n // Detect phases (handles both individual processors and workflow processors)\n const phases = detectProcessorPhases(processorEntry);\n\n // Get agent configurations for this processor\n const configs = mastra.getProcessorConfigurations(processorId);\n const agents = mastra.listAgents() || {};\n const configurations = configs.map(c => ({\n agentId: c.agentId,\n agentName: agents[c.agentId]?.name || c.agentId,\n type: c.type,\n }));\n\n return {\n id: processorEntry.id,\n name: processorEntry.name || processorEntry.id,\n description: processorEntry.description,\n phases,\n configurations,\n isWorkflow,\n };\n } catch (error) {\n return handleError(error, 'Error getting processor');\n }\n },\n});\n\nexport const EXECUTE_PROCESSOR_ROUTE = createRoute({\n method: 'POST',\n path: '/processors/:processorId/execute',\n responseType: 'json',\n pathParamSchema: processorIdPathParams,\n bodySchema: executeProcessorBodySchema,\n responseSchema: executeProcessorResponseSchema,\n summary: 'Execute processor',\n description: 'Executes a specific processor with the provided input data',\n tags: ['Processors'],\n requiresAuth: true,\n handler: async ({ mastra, processorId, ...bodyParams }) => {\n try {\n const { phase, messages } = bodyParams;\n\n if (!processorId) {\n throw new HTTPException(400, { message: 'Processor ID is required' });\n }\n\n if (!phase) {\n throw new HTTPException(400, { message: 'Phase is required' });\n }\n\n if (phase === 'llmRequest') {\n // processLLMRequest operates on the provider prompt, not on messages\n throw new HTTPException(400, {\n message: 'llmRequest phase cannot be executed directly. It runs on the provider prompt during an agent call.',\n });\n }\n\n if (!messages || !Array.isArray(messages)) {\n throw new HTTPException(400, { message: 'Messages array is required' });\n }\n\n // Get the processor from Mastra's registered processors\n let processor;\n try {\n processor = mastra.getProcessorById(processorId);\n } catch {\n // getProcessorById throws if not found, try by key\n const processors = mastra.listProcessors() || {};\n processor = processors[processorId as keyof typeof processors];\n }\n\n if (!processor) {\n throw new HTTPException(404, { message: 'Processor not found' });\n }\n\n const messageList = new MessageList();\n messageList.add(messages as unknown as MessageInput[], 'input');\n\n // Check if this is a workflow processor\n if (isProcessorWorkflow(processor)) {\n // Execute workflow processor\n try {\n // Build inputData based on phase - each phase has different required fields\n const baseInputData = {\n phase: phase as 'input' | 'inputStep' | 'outputStream' | 'outputResult' | 'outputStep' | 'toolResult',\n messages: messageList.get.all.db(),\n messageList,\n retryCount: 0,\n };\n let inputData: typeof baseInputData & Record<string, unknown> = baseInputData;\n\n // Add phase-specific fields\n switch (phase) {\n case 'input':\n inputData = {\n ...inputData,\n systemMessages: [],\n };\n break;\n case 'inputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n model: '',\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n };\n break;\n case 'outputResult':\n inputData = {\n ...inputData,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n };\n break;\n case 'outputStep':\n inputData = {\n ...inputData,\n stepNumber: 0,\n systemMessages: [],\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n };\n break;\n case 'outputStream':\n inputData = {\n ...inputData,\n part: null,\n streamParts: [],\n state: {},\n };\n break;\n case 'toolResult':\n inputData = {\n ...inputData,\n stepNumber: 0,\n toolName: '',\n toolCallId: '',\n args: undefined,\n toolResultValue: undefined,\n providerExecuted: false,\n systemMessages: [],\n steps: [],\n };\n break;\n }\n\n const run = await processor.createRun();\n const result = await run.start({\n inputData,\n });\n\n // Check for tripwire status\n if (result.status === 'tripwire') {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: result.tripwire.reason || `Tripwire triggered in workflow ${processor.id}`,\n metadata: result.tripwire.metadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n\n // Check for execution failure\n if (result.status !== 'success') {\n throw new HTTPException(500, {\n message: `Processor workflow ${processor.id} failed with status: ${result.status}`,\n });\n }\n\n // Extract output from workflow result\n const output = result.result;\n let outputMessages = messages;\n\n if (output && typeof output === 'object') {\n if ('messages' in output && Array.isArray(output.messages)) {\n outputMessages = output.messages;\n } else if ('messageList' in output && output.messageList instanceof MessageList) {\n outputMessages = output.messageList.get.all.db();\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Re-throw HTTP exceptions\n if (error instanceof HTTPException) {\n throw error;\n }\n throw new HTTPException(500, {\n message: `Error executing processor workflow: ${error.message}`,\n });\n }\n }\n\n // Handle individual processor execution\n // Create the abort function for tripwire support\n let tripwireTriggered = false;\n let tripwireReason: string | undefined;\n let tripwireMetadata: unknown;\n\n const abort = (reason?: string, options?: { retry?: boolean; metadata?: unknown }) => {\n tripwireTriggered = true;\n tripwireReason = reason;\n tripwireMetadata = options?.metadata;\n throw new Error(`TRIPWIRE:${reason || 'Processor aborted'}`);\n };\n\n // Build the context based on phase\n const baseContext = {\n abort,\n retryCount: 0,\n messages: messageList.get.all.db(),\n messageList,\n state: {},\n };\n\n try {\n let result: any;\n\n // Execute the specific phase method on the individual processor\n switch (phase) {\n case 'input':\n if (!processor.processInput) {\n throw new HTTPException(400, { message: 'Processor does not support input phase' });\n }\n result = await processor.processInput({\n ...baseContext,\n systemMessages: [],\n });\n break;\n\n case 'inputStep':\n if (!processor.processInputStep) {\n throw new HTTPException(400, { message: 'Processor does not support inputStep phase' });\n }\n result = await processor.processInputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n // Pass empty/default values for all inputStep fields\n model: '' as any,\n tools: {},\n toolChoice: undefined,\n activeTools: [],\n providerOptions: undefined,\n modelSettings: undefined,\n structuredOutput: undefined,\n });\n break;\n\n case 'outputResult':\n if (!processor.processOutputResult) {\n throw new HTTPException(400, { message: 'Processor does not support outputResult phase' });\n }\n result = await processor.processOutputResult({\n ...baseContext,\n state: {},\n result: {\n text: extractTextFromMessages(messages),\n usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },\n finishReason: 'unknown',\n steps: [],\n },\n });\n break;\n\n case 'outputStep':\n if (!processor.processOutputStep) {\n throw new HTTPException(400, { message: 'Processor does not support outputStep phase' });\n }\n result = await processor.processOutputStep({\n ...baseContext,\n systemMessages: [],\n stepNumber: 0,\n steps: [],\n finishReason: 'stop',\n toolCalls: [],\n text: extractTextFromMessages(messages),\n usage: { inputTokens: undefined, outputTokens: undefined, totalTokens: undefined },\n });\n break;\n\n case 'outputStream':\n // outputStream is for streaming chunks, not a simple execute\n throw new HTTPException(400, {\n message: 'outputStream phase cannot be executed directly. Use streaming instead.',\n });\n\n default:\n throw new HTTPException(400, { message: `Unknown phase: ${phase}` });\n }\n\n // Process the result\n let outputMessages = messages;\n if (result) {\n if (Array.isArray(result)) {\n outputMessages = result;\n } else if (result.get && result.get.all && typeof result.get.all.db === 'function') {\n // It's a MessageList\n outputMessages = result.get.all.db();\n } else if (result.messages) {\n outputMessages = result.messages;\n }\n }\n\n return {\n success: true,\n phase,\n messages: outputMessages,\n messageList: {\n messages: outputMessages,\n },\n };\n } catch (error: any) {\n // Check if it's a tripwire\n if (tripwireTriggered || error.message?.startsWith('TRIPWIRE:')) {\n return {\n success: false,\n phase,\n tripwire: {\n triggered: true,\n reason: tripwireReason || error.message?.replace('TRIPWIRE:', ''),\n metadata: tripwireMetadata,\n },\n messages,\n messageList: {\n messages,\n },\n };\n }\n throw error;\n }\n } catch (error) {\n return handleError(error, 'Error executing processor');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;AAiCA,SAAS,wBAAwB,UAA6B;CAC5D,IAAI,CAAC,YAAY,CAAC,MAAM,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAC/D,OAAO;CAET,MAAM,eAAe,SAAS;CAC9B,IAAI,cAAc,SAAS,OAIzB,OAHkB,aAAa,QAAQ,MACpC,QAAQ,SAAc,MAAM,SAAS,MAAM,CAAC,CAC5C,KAAK,SAAc,MAAM,QAAQ,EACrB,CAAC,CAAC,KAAK,EAAE;CAE1B,OAAO;AACT;;;;;;;AAQA,SAAS,sBAAsB,WAAkC;CAE/D,IAAI,oBAAoB,SAAS,GAG/B,OAAO;EAAC;EAAS;EAAa;EAAgB;EAAgB;EAAc;CAAY;CAI1F,MAAM,SAA2B,CAAC;CAClC,IAAI,OAAO,UAAU,iBAAiB,YACpC,OAAO,KAAK,OAAO;CAErB,IAAI,OAAO,UAAU,qBAAqB,YACxC,OAAO,KA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,MAAM,IAAI,cAAc,KAAK,EAC3B,SAAS,yEACX,CAAC;KAEH,SACE,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,kBAAkB,QAAQ,CAAC;IACvE;IAGA,IAAI,iBAAiB;IACrB,IAAI,QACE;SAAA,MAAM,QAAQ,MAAM,GACtB,iBAAiB;UACZ,IAAI,OAAO,OAAO,OAAO,IAAI,OAAO,OAAO,OAAO,IAAI,IAAI,OAAO,YAEtE,iBAAiB,OAAO,IAAI,IAAI,GAAG;UAC9B,IAAI,OAAO,UAChB,iBAAiB,OAAO;IAAA;IAI5B,OAAO;KACL,SAAS;KACT;KACA,UAAU;KACV,aAAa,EACX,UAAU,eACZ;IACF;GACF,SAAS,OAAY;IAEnB,IAAI,qBAAqB,MAAM,SAAS,WAAW,WAAW,GAC5D,OAAO;KACL,SAAS;KACT;KACA,UAAU;MACR,WAAW;MACX,QAAQ,kBAAkB,MAAM,SAAS,QAAQ,aAAa,EAAE;MAChE,UAAU;KACZ;KACA;KACA,aAAa,EACX,SACF;IACF;IAEF,MAAM;GACR;EACF,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,2BAA2B;EACvD;CACF;AACF,CAAC"}
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../rolldown-runtime-Bd6kNlEP.cjs");
3
3
  let _mastra_core_utils_zod_to_json = require("@mastra/core/utils/zod-to-json");
4
4
  let _mastra_core_tools = require("@mastra/core/tools");
5
- let crypto = require("crypto");
6
5
  //#region src/server/handlers/responses.adapter.ts
7
6
  /**
8
7
  * Flattens Responses API message content into the plain-text shape Mastra agent
@@ -280,7 +279,7 @@ function mapMastraMessagesToResponseOutputItems({ messages, outputMessageId, sta
280
279
  * Creates a stable assistant-message-backed response identifier.
281
280
  */
282
281
  function createMessageId() {
283
- return `msg_${(0, crypto.randomUUID)()}`;
282
+ return `msg_${globalThis.crypto.randomUUID()}`;
284
283
  }
285
284
  /**
286
285
  * Maps Responses API input into the plain execution messages Mastra agents expect.