@mastra/server 1.58.0-alpha.0 → 1.58.0-alpha.3

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 (127) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/dist/_types/@mastra_schema-compat/dist/provider-compats/anthropic.d.ts +1 -1
  3. package/dist/{a2a-CnU9zaGR.js → a2a-8C4O2dVJ.js} +41 -5
  4. package/dist/a2a-8C4O2dVJ.js.map +1 -0
  5. package/dist/{a2a-DKnwIgiw.cjs → a2a-B6YkZ2i9.cjs} +872 -227
  6. package/dist/a2a-B6YkZ2i9.cjs.map +1 -0
  7. package/dist/{a2a-oM7aqLz4.cjs → a2a-MPoM5lzS.cjs} +41 -5
  8. package/dist/a2a-MPoM5lzS.cjs.map +1 -0
  9. package/dist/{a2a-uPi5sPwb.js → a2a-_D2EA4oa.js} +861 -228
  10. package/dist/a2a-_D2EA4oa.js.map +1 -0
  11. package/dist/{agent-builder-BDYN3r89.cjs → agent-builder-DAiJH1u2.cjs} +2 -2
  12. package/dist/{agent-builder-BDYN3r89.cjs.map → agent-builder-DAiJH1u2.cjs.map} +1 -1
  13. package/dist/{agent-builder-Dqy_qumV.js → agent-builder-gGFywDVq.js} +2 -2
  14. package/dist/{agent-builder-Dqy_qumV.js.map → agent-builder-gGFywDVq.js.map} +1 -1
  15. package/dist/{api-schema-manifest-7-NC9Dyc.cjs → api-schema-manifest-B3bC-D98.cjs} +2 -2
  16. package/dist/{api-schema-manifest-7-NC9Dyc.cjs.map → api-schema-manifest-B3bC-D98.cjs.map} +1 -1
  17. package/dist/{api-schema-manifest-C5hpdIE_.js → api-schema-manifest-B4J_QYOr.js} +2 -2
  18. package/dist/{api-schema-manifest-C5hpdIE_.js.map → api-schema-manifest-B4J_QYOr.js.map} +1 -1
  19. package/dist/{datasets-Cvix7Rms.cjs → datasets-BMeFvFwT.cjs} +43 -1
  20. package/dist/datasets-BMeFvFwT.cjs.map +1 -0
  21. package/dist/{datasets-dhXnHLAL.js → datasets-BeBH9Seg.js} +38 -2
  22. package/dist/datasets-BeBH9Seg.js.map +1 -0
  23. package/dist/{dist-DGqlUp0b.js → dist-BKRMiJcn.js} +215 -74
  24. package/dist/dist-BKRMiJcn.js.map +1 -0
  25. package/dist/{dist-COHIL6fR.cjs → dist-C2-SedDQ.cjs} +215 -74
  26. package/dist/dist-C2-SedDQ.cjs.map +1 -0
  27. package/dist/docs/SKILL.md +1 -1
  28. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  29. package/dist/docs/references/docs-agents-a2a.md +75 -2
  30. package/dist/docs/references/reference-server-routes.md +25 -11
  31. package/dist/route-builder-CIk5k35M.js.map +1 -1
  32. package/dist/route-builder-CgLVYL1c.cjs.map +1 -1
  33. package/dist/{routes-hSY4wTeS.cjs → routes-CZwPlO3-.cjs} +3 -2
  34. package/dist/routes-CZwPlO3-.cjs.map +1 -0
  35. package/dist/{routes-CRoTKPvQ.js → routes-HUaCyUb7.js} +4 -3
  36. package/dist/{routes-CRoTKPvQ.js.map → routes-HUaCyUb7.js.map} +1 -1
  37. package/dist/server/a2a/store.cjs +30 -2
  38. package/dist/server/a2a/store.cjs.map +1 -1
  39. package/dist/server/a2a/store.d.ts +21 -2
  40. package/dist/server/a2a/store.d.ts.map +1 -1
  41. package/dist/server/a2a/store.js +30 -3
  42. package/dist/server/a2a/store.js.map +1 -1
  43. package/dist/server/a2a/task-state.d.ts +4 -0
  44. package/dist/server/a2a/task-state.d.ts.map +1 -0
  45. package/dist/server/a2a/tasks.d.ts +1 -1
  46. package/dist/server/a2a/tasks.d.ts.map +1 -1
  47. package/dist/server/handlers/a2a.cjs +3 -1
  48. package/dist/server/handlers/a2a.d.ts +155 -12
  49. package/dist/server/handlers/a2a.d.ts.map +1 -1
  50. package/dist/server/handlers/a2a.js +2 -2
  51. package/dist/server/handlers/agent-builder.cjs +3 -3
  52. package/dist/server/handlers/agent-builder.js +3 -3
  53. package/dist/server/handlers/agent-controller.cjs +25 -6
  54. package/dist/server/handlers/agent-controller.cjs.map +1 -1
  55. package/dist/server/handlers/agent-controller.d.ts +4 -3
  56. package/dist/server/handlers/agent-controller.d.ts.map +1 -1
  57. package/dist/server/handlers/agent-controller.js +25 -6
  58. package/dist/server/handlers/agent-controller.js.map +1 -1
  59. package/dist/server/handlers/agent-versions.cjs +6 -0
  60. package/dist/server/handlers/agent-versions.cjs.map +1 -1
  61. package/dist/server/handlers/agent-versions.d.ts.map +1 -1
  62. package/dist/server/handlers/agent-versions.js +6 -0
  63. package/dist/server/handlers/agent-versions.js.map +1 -1
  64. package/dist/server/handlers/datasets.cjs +26 -11
  65. package/dist/server/handlers/datasets.cjs.map +1 -1
  66. package/dist/server/handlers/datasets.d.ts +136 -0
  67. package/dist/server/handlers/datasets.d.ts.map +1 -1
  68. package/dist/server/handlers/datasets.js +26 -11
  69. package/dist/server/handlers/datasets.js.map +1 -1
  70. package/dist/server/handlers/observability.cjs +20 -9
  71. package/dist/server/handlers/observability.cjs.map +1 -1
  72. package/dist/server/handlers/observability.d.ts.map +1 -1
  73. package/dist/server/handlers/observability.js +20 -9
  74. package/dist/server/handlers/observability.js.map +1 -1
  75. package/dist/server/handlers/stored-agents.cjs +16 -1
  76. package/dist/server/handlers/stored-agents.cjs.map +1 -1
  77. package/dist/server/handlers/stored-agents.d.ts.map +1 -1
  78. package/dist/server/handlers/stored-agents.js +16 -1
  79. package/dist/server/handlers/stored-agents.js.map +1 -1
  80. package/dist/server/handlers/system.cjs +1 -1
  81. package/dist/server/handlers/system.js +1 -1
  82. package/dist/server/handlers/validate-agent-instructions.cjs +52 -0
  83. package/dist/server/handlers/validate-agent-instructions.cjs.map +1 -0
  84. package/dist/server/handlers/validate-agent-instructions.d.ts +13 -0
  85. package/dist/server/handlers/validate-agent-instructions.d.ts.map +1 -0
  86. package/dist/server/handlers/validate-agent-instructions.js +51 -0
  87. package/dist/server/handlers/validate-agent-instructions.js.map +1 -0
  88. package/dist/server/handlers/workflows.cjs +105 -2
  89. package/dist/server/handlers/workflows.cjs.map +1 -1
  90. package/dist/server/handlers/workflows.d.ts +9 -0
  91. package/dist/server/handlers/workflows.d.ts.map +1 -1
  92. package/dist/server/handlers/workflows.js +104 -3
  93. package/dist/server/handlers/workflows.js.map +1 -1
  94. package/dist/server/handlers.cjs +1 -1
  95. package/dist/server/handlers.js +1 -1
  96. package/dist/server/schemas/a2a.d.ts +70 -6
  97. package/dist/server/schemas/a2a.d.ts.map +1 -1
  98. package/dist/server/schemas/datasets.d.ts +53 -0
  99. package/dist/server/schemas/datasets.d.ts.map +1 -1
  100. package/dist/server/schemas/index.cjs +5 -4
  101. package/dist/server/schemas/index.js +5 -5
  102. package/dist/server/schemas/workflows.d.ts +8 -0
  103. package/dist/server/schemas/workflows.d.ts.map +1 -1
  104. package/dist/server/server-adapter/index.cjs +1 -1
  105. package/dist/server/server-adapter/index.js +1 -1
  106. package/dist/server/server-adapter/routes/a2a.d.ts +116 -8
  107. package/dist/server/server-adapter/routes/a2a.d.ts.map +1 -1
  108. package/dist/server/server-adapter/routes/datasets.d.ts +136 -0
  109. package/dist/server/server-adapter/routes/datasets.d.ts.map +1 -1
  110. package/dist/server/server-adapter/routes/workflows.d.ts +7 -1
  111. package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
  112. package/dist/{workflows-DPW6FrY0.js → workflows-CMU5dz_4.js} +7 -2
  113. package/dist/workflows-CMU5dz_4.js.map +1 -0
  114. package/dist/{workflows-XfiENvkF.cjs → workflows-Dzxr6cmf.cjs} +12 -1
  115. package/dist/workflows-Dzxr6cmf.cjs.map +1 -0
  116. package/package.json +8 -8
  117. package/dist/a2a-CnU9zaGR.js.map +0 -1
  118. package/dist/a2a-DKnwIgiw.cjs.map +0 -1
  119. package/dist/a2a-oM7aqLz4.cjs.map +0 -1
  120. package/dist/a2a-uPi5sPwb.js.map +0 -1
  121. package/dist/datasets-Cvix7Rms.cjs.map +0 -1
  122. package/dist/datasets-dhXnHLAL.js.map +0 -1
  123. package/dist/dist-COHIL6fR.cjs.map +0 -1
  124. package/dist/dist-DGqlUp0b.js.map +0 -1
  125. package/dist/routes-hSY4wTeS.cjs.map +0 -1
  126. package/dist/workflows-DPW6FrY0.js.map +0 -1
  127. package/dist/workflows-XfiENvkF.cjs.map +0 -1
@@ -3,7 +3,7 @@ name: mastra-server
3
3
  description: Documentation for @mastra/server. Use when working with @mastra/server APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/server"
6
- version: "1.58.0-alpha.0"
6
+ version: "1.58.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.58.0-alpha.0",
2
+ "version": "1.58.0-alpha.3",
3
3
  "package": "@mastra/server",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  # A2A (Agent-to-Agent)
4
4
 
5
- Mastra supports the [Agent-to-Agent (A2A) protocol](https://a2a-protocol.org/latest/) for cross-platform multi-agent systems. Use A2A to expose Mastra agents as remote agents, consume remote A2A agents as Mastra subagents, or call A2A endpoints with the JavaScript client SDK.
5
+ Mastra supports version 0.3.0 of the [Agent-to-Agent (A2A) protocol](https://a2a-protocol.org/latest/) for cross-platform multi-agent systems. Use A2A to expose Mastra agents as remote agents, consume remote A2A agents as Mastra subagents, or call A2A endpoints with the JavaScript client SDK.
6
6
 
7
7
  A2A is an open protocol for delegating work to agents across network, framework, vendor, and language boundaries. A remote agent keeps its own tools, prompts, memory, workflows, and infrastructure private while exposing a protocol endpoint that other systems can discover and call.
8
8
 
@@ -57,6 +57,18 @@ A2A represents work as messages and tasks. Messages carry text, file, or structu
57
57
 
58
58
  Tasks are stateful units of work with IDs and lifecycle states. Clients can follow long-running work and send follow-up turns. They can also cancel work or resubscribe after a disconnect.
59
59
 
60
+ ## Protocol versions
61
+
62
+ Mastra supports A2A Protocol v0.3 and v1.0 on the same agent card and execution URLs. The `A2A-Version` request header selects the wire protocol:
63
+
64
+ - Missing, empty, or `0.3`: Uses the existing v0.3 API.
65
+ - `1.0`: Uses the v1.0 API.
66
+ - Any other value: Returns a `VersionNotSupported` protocol error.
67
+
68
+ Existing `A2AAgent` and `MastraClient.getA2A()` integrations continue to use v0.3. Use `MastraClient.getA2AV1()` for v1.0 requests. The v1 client sends `A2A-Version: 1.0` automatically and adds the `tasks/list` operation.
69
+
70
+ Import v1.0 protocol types and codecs from `@mastra/core/a2a/v1`. The existing `@mastra/core/a2a/client` export remains on v0.3.
71
+
60
72
  ## Get started
61
73
 
62
74
  A2A has two common paths in Mastra:
@@ -155,6 +167,33 @@ for await (const event of updates) {
155
167
  }
156
168
  ```
157
169
 
170
+ ### Use the v1.0 client
171
+
172
+ Use `getA2AV1()` to opt into the A2A v1.0 wire protocol. The protocol package provides codecs for creating v1 request values from JSON-shaped input:
173
+
174
+ ```typescript
175
+ import { ListTasksRequest } from '@mastra/core/a2a/v1'
176
+ import { MastraClient } from '@mastra/client-js'
177
+
178
+ const client = new MastraClient({
179
+ baseUrl: 'https://agent.example.com',
180
+ })
181
+
182
+ const a2a = client.getA2AV1('weather-agent')
183
+ const response = await a2a.listTasks(
184
+ ListTasksRequest.fromJSON({
185
+ contextId: 'customer-support',
186
+ pageSize: 20,
187
+ }),
188
+ )
189
+
190
+ for (const task of response.tasks) {
191
+ console.log(task.id, task.status)
192
+ }
193
+ ```
194
+
195
+ The v1.0 client supports `getAgentCard()`, `sendMessage()`, `sendMessageStream()`, `getTask()`, `listTasks()`, `cancelTask()`, and `resubscribeTask()`.
196
+
158
197
  ## Configure subagent calls
159
198
 
160
199
  `A2AAgent` accepts request options for authenticated or constrained environments:
@@ -176,6 +215,38 @@ const remoteWeatherAgent = new A2AAgent({
176
215
 
177
216
  You can also pass `credentials`, `fetch`, and `abortSignal` when the runtime needs custom fetch behavior or request cancellation.
178
217
 
218
+ ## Human-in-the-loop
219
+
220
+ A2A models human-in-the-loop (HITL) work with the `input-required` task state. When a task pauses for input, the client provides the missing input by sending a follow-up message with the same `taskId`, and the server continues the task.
221
+
222
+ Mastra maps its agent suspension model to this state in both directions:
223
+
224
+ - **As a server**: when an exposed agent suspends, the task transitions to `input-required`. This includes suspensions caused by [tool approval](https://mastra.ai/docs/agents/agent-approval) or a tool that calls `suspend()`. The task status message includes a text prompt and a data part with the structured `suspendPayload` and `resumeSchema`. A follow-up `message/send` or `message/stream` request with the same `taskId` resumes the suspended run with the provided input.
225
+ - **As a client**: when a remote task reaches `input-required` or `auth-required`, `A2AAgent` returns a suspended result with `finishReason: 'suspended'` and a `suspendPayload`. Calling `resumeGenerate()` or `resumeStream()` sends the input or credentials back to the remote task with the original `taskId`.
226
+
227
+ ```typescript
228
+ import { A2AAgent } from '@mastra/core/a2a'
229
+
230
+ const agent = new A2AAgent({
231
+ url: 'https://agent.example.com/api/.well-known/booking-agent/agent-card.json',
232
+ })
233
+
234
+ const result = await agent.generate('Book a flight to Paris', { runId: 'run-1' })
235
+
236
+ if (result.finishReason === 'suspended') {
237
+ // Inspect result.suspendPayload, collect input from a human,
238
+ // then resume the remote task.
239
+ const resumed = await agent.resumeGenerate({ approved: true }, { runId: 'run-1' })
240
+ console.log(resumed.text)
241
+ }
242
+ ```
243
+
244
+ Follow-up messages for an `input-required` task can carry the resume data as a structured data part, or as JSON or plain text in a text part.
245
+
246
+ When a resumed run requires additional input, the task returns to `input-required` and the flow repeats. Resuming a suspended run requires storage configured on the Mastra server so the suspended run state can be restored across requests.
247
+
248
+ > **Note:** A2A task records live in an in-memory store, so a paused task can only be resumed by the same server process that suspended it. A server restart or a horizontally scaled deployment without sticky routing loses the task record, and a follow-up message fails with a task-not-found error.
249
+
179
250
  ## Push notifications
180
251
 
181
252
  Mastra supports A2A push notifications for remote agents that advertise `capabilities.pushNotifications`. Use push notifications when a client can't keep a stream open, or when a long-running task should update a callback URL after the original request ends.
@@ -192,7 +263,9 @@ await a2a.setTaskPushNotificationConfig({
192
263
  })
193
264
  ```
194
265
 
195
- Mastra Server sends the current task snapshot to registered callbacks when the task reaches `completed`, `failed`, `canceled`, or `input-required`. Push notification delivery is best-effort. Protect callback URLs, validate notification tokens, and avoid exposing internal network targets as push notification destinations.
266
+ Mastra Server sends the current task snapshot to registered callbacks when the task reaches `completed`, `failed`, `canceled`, `rejected`, `input-required`, or `auth-required`. Push notification delivery is best-effort. Protect callback URLs, validate notification tokens, and avoid exposing internal network targets as push notification destinations.
267
+
268
+ Push notification configurations are stored in memory and must be registered again after a server restart.
196
269
 
197
270
  ## Sign and verify agent cards
198
271
 
@@ -171,17 +171,31 @@ The route returns:
171
171
 
172
172
  ## Workflows
173
173
 
174
- | Method | Path | Description |
175
- | ------ | ----------------------------------------- | ------------------------------- |
176
- | `GET` | `/api/workflows` | List all workflows |
177
- | `GET` | `/api/workflows/:workflowId` | Get workflow by ID |
178
- | `POST` | `/api/workflows/:workflowId/create-run` | Create a new workflow run |
179
- | `POST` | `/api/workflows/:workflowId/start-async` | Start workflow and await result |
180
- | `POST` | `/api/workflows/:workflowId/stream` | Stream workflow execution |
181
- | `POST` | `/api/workflows/:workflowId/resume` | Resume suspended workflow |
182
- | `POST` | `/api/workflows/:workflowId/resume-async` | Resume asynchronously |
183
- | `GET` | `/api/workflows/:workflowId/runs` | List workflow runs |
184
- | `GET` | `/api/workflows/:workflowId/runs/:runId` | Get specific run |
174
+ | Method | Path | Description |
175
+ | ------ | ----------------------------------------- | ----------------------------------------------------- |
176
+ | `GET` | `/api/workflows` | List all workflows |
177
+ | `GET` | `/api/workflows/run-counts` | Get per-workflow counts of running and suspended runs |
178
+ | `GET` | `/api/workflows/:workflowId` | Get workflow by ID |
179
+ | `POST` | `/api/workflows/:workflowId/create-run` | Create a new workflow run |
180
+ | `POST` | `/api/workflows/:workflowId/start-async` | Start workflow and await result |
181
+ | `POST` | `/api/workflows/:workflowId/stream` | Stream workflow execution |
182
+ | `POST` | `/api/workflows/:workflowId/resume` | Resume suspended workflow |
183
+ | `POST` | `/api/workflows/:workflowId/resume-async` | Resume asynchronously |
184
+ | `GET` | `/api/workflows/:workflowId/runs` | List workflow runs |
185
+ | `GET` | `/api/workflows/:workflowId/runs/:runId` | Get specific run |
186
+
187
+ ### Run counts response
188
+
189
+ The `/api/workflows/run-counts` endpoint returns counts of `running` and [`suspended`](https://mastra.ai/docs/workflows/suspend-and-resume) runs for every registered workflow. The record is keyed by the workflow's registry key from the Mastra config, and the server may cache the response for a few seconds:
190
+
191
+ ```typescript
192
+ {
193
+ [workflowRegistryKey: string]: {
194
+ running: number;
195
+ suspended: number;
196
+ };
197
+ }
198
+ ```
185
199
 
186
200
  ### Stored workflows
187
201