@mastra/ai-sdk 1.3.4-alpha.0 → 1.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.4.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - Added agent versioning support to chat and network route handlers. You can now pass `agentVersion` to `chatRoute()`, `handleChatStream()`, `networkRoute()`, and `handleNetworkStream()` to target a specific agent version by ID or status (draft/published). Route handlers also accept `?versionId=<id>` or `?status=draft|published` query parameters at request time, which take precedence over static configuration. Requires the Editor to be configured. ([#15296](https://github.com/mastra-ai/mastra/pull/15296))
8
+
9
+ ```typescript
10
+ // Static version on route config
11
+ chatRoute({
12
+ path: '/chat',
13
+ agent: 'weatherAgent',
14
+ agentVersion: { status: 'published' },
15
+ });
16
+
17
+ // Programmatic version on handler
18
+ const stream = await handleChatStream({
19
+ mastra,
20
+ agentId: 'weatherAgent',
21
+ agentVersion: { versionId: 'ver_abc123' },
22
+ params,
23
+ });
24
+ ```
25
+
3
26
  ## 1.3.4-alpha.0
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -158,6 +158,33 @@ export async function POST(req: Request) {
158
158
  }
159
159
  ```
160
160
 
161
+ ## Agent versioning
162
+
163
+ All route handlers and standalone stream functions accept an optional `agentVersion` parameter to target a specific agent version. This requires the [Editor](https://mastra.ai/docs/editor/overview) to be configured.
164
+
165
+ Pass a version ID or resolve by status:
166
+
167
+ ```typescript
168
+ chatRoute({
169
+ path: '/chat',
170
+ agent: 'weatherAgent',
171
+ agentVersion: { status: 'published' },
172
+ });
173
+ ```
174
+
175
+ For route handlers (`chatRoute`, `networkRoute`), callers can also override the version at request time with query parameters: `?versionId=<id>` or `?status=draft|published`. Query parameters take precedence over the static `agentVersion` option.
176
+
177
+ The standalone handlers (`handleChatStream`, `handleNetworkStream`) accept `agentVersion` directly:
178
+
179
+ ```typescript
180
+ const stream = await handleChatStream({
181
+ mastra,
182
+ agentId: 'weatherAgent',
183
+ agentVersion: { versionId: 'ver_abc123' },
184
+ params,
185
+ });
186
+ ```
187
+
161
188
  ## Manual transformation
162
189
 
163
190
  If you have a raw Mastra `stream`, you can manually transform it to AI SDK UI message parts:
@@ -10,9 +10,15 @@ export type ChatStreamHandlerParams<UI_MESSAGE extends SupportedUIMessage = Supp
10
10
  /** The trigger for the request - sent by AI SDK's useChat hook */
11
11
  trigger?: 'submit-message' | 'regenerate-message';
12
12
  };
13
+ /**
14
+ * Extracted from the second parameter of `Mastra.getAgentById` so the type
15
+ * stays in sync with core automatically.
16
+ */
17
+ export type AgentVersionOptions = NonNullable<Parameters<Mastra['getAgentById']>[1]>;
13
18
  export type ChatStreamHandlerOptions<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = {
14
19
  mastra: Mastra;
15
20
  agentId: string;
21
+ agentVersion?: AgentVersionOptions;
16
22
  params: ChatStreamHandlerParams<UI_MESSAGE, OUTPUT>;
17
23
  defaultOptions?: AgentExecutionOptions<OUTPUT>;
18
24
  version?: 'v5' | 'v6';
@@ -58,6 +64,7 @@ export declare function handleChatStream<UI_MESSAGE extends V6UIMessage = V6UIMe
58
64
  export type chatRouteOptions<OUTPUT = undefined> = {
59
65
  defaultOptions?: AgentExecutionOptions<OUTPUT>;
60
66
  version?: 'v5' | 'v6';
67
+ agentVersion?: AgentVersionOptions;
61
68
  } & ({
62
69
  path: `${string}:agentId${string}`;
63
70
  agent?: never;
@@ -113,6 +120,6 @@ export type chatRouteOptions<OUTPUT = undefined> = {
113
120
  * - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
114
121
  * - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
115
122
  */
116
- export declare function chatRoute<OUTPUT = undefined>({ path, agent, defaultOptions, version, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
123
+ export declare function chatRoute<OUTPUT = undefined>({ path, agent, defaultOptions, version, agentVersion, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
117
124
  export {};
118
125
  //# sourceMappingURL=chat-route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAK9F,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,qBAAqB,EAA6B,MAAM,oBAAoB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,uBAAuB,CACjC,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAC1D,MAAM,GAAG,SAAS,IAChB,qBAAqB,CAAC,MAAM,CAAC,GAAG;IAClC,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,kEAAkE;IAClE,OAAO,CAAC,EAAE,gBAAgB,GAAG,oBAAoB,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAAC,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAAE,MAAM,GAAG,SAAS,IAAI;IACrH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,uBAAuB,CAAC,UAAU,EAAE,MAAM,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AC1C,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/F,OAAO,EAAE,0BAA0B,CAAC,UAAU,EAAE,MAAM,CAAC,GACtD,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;AAgH1C,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,SAAS,IAAI;IACjD,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC,GAAG,CACA;IACE,IAAI,EAAE,GAAG,MAAM,WAAW,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,GAAG;IACA,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,EAC5C,IAAuB,EACvB,KAAK,EACL,cAAc,EACd,OAAc,EACd,YAAY,EACZ,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAkNhE"}
package/dist/index.cjs CHANGED
@@ -13176,6 +13176,7 @@ function toAISdkStream(stream, options = {
13176
13176
  async function handleChatStream({
13177
13177
  mastra,
13178
13178
  agentId,
13179
+ agentVersion,
13179
13180
  params,
13180
13181
  defaultOptions: defaultOptions3,
13181
13182
  version = "v5",
@@ -13190,7 +13191,7 @@ async function handleChatStream({
13190
13191
  if (resumeData && !runId) {
13191
13192
  throw new Error("runId is required when resumeData is provided");
13192
13193
  }
13193
- const agentObj = mastra.getAgentById(agentId);
13194
+ const agentObj = agentVersion ? await mastra.getAgentById(agentId, agentVersion) : mastra.getAgentById(agentId);
13194
13195
  if (!agentObj) {
13195
13196
  throw new Error(`Agent ${agentId} not found`);
13196
13197
  }
@@ -13266,6 +13267,7 @@ function chatRoute({
13266
13267
  agent,
13267
13268
  defaultOptions: defaultOptions3,
13268
13269
  version = "v5",
13270
+ agentVersion,
13269
13271
  sendStart = true,
13270
13272
  sendFinish = true,
13271
13273
  sendReasoning = false,
@@ -13289,6 +13291,25 @@ function chatRoute({
13289
13291
  schema: {
13290
13292
  type: "string"
13291
13293
  }
13294
+ },
13295
+ {
13296
+ name: "versionId",
13297
+ in: "query",
13298
+ required: false,
13299
+ description: "Specific agent version ID to use. Mutually exclusive with status.",
13300
+ schema: {
13301
+ type: "string"
13302
+ }
13303
+ },
13304
+ {
13305
+ name: "status",
13306
+ in: "query",
13307
+ required: false,
13308
+ description: "Which stored config version to resolve: draft (latest) or published (active version). Mutually exclusive with versionId.",
13309
+ schema: {
13310
+ type: "string",
13311
+ enum: ["draft", "published"]
13312
+ }
13292
13313
  }
13293
13314
  ],
13294
13315
  requestBody: {
@@ -13396,9 +13417,20 @@ function chatRoute({
13396
13417
  if (!agentToUse) {
13397
13418
  throw new Error("Agent ID is required");
13398
13419
  }
13420
+ const queryVersionId = c.req.query("versionId");
13421
+ const rawStatus = c.req.query("status");
13422
+ if (queryVersionId && rawStatus) {
13423
+ throw new Error('Query parameters "versionId" and "status" are mutually exclusive');
13424
+ }
13425
+ if (rawStatus && rawStatus !== "draft" && rawStatus !== "published") {
13426
+ throw new Error('Query parameter "status" must be "draft" or "published"');
13427
+ }
13428
+ const queryStatus = rawStatus;
13429
+ const effectiveAgentVersion = queryVersionId ? { versionId: queryVersionId } : queryStatus ? { status: queryStatus } : agentVersion;
13399
13430
  const handlerOptions = {
13400
13431
  mastra,
13401
13432
  agentId: agentToUse,
13433
+ agentVersion: effectiveAgentVersion,
13402
13434
  params: {
13403
13435
  ...params,
13404
13436
  requestContext: effectiveRequestContext,
@@ -13570,12 +13602,13 @@ function workflowRoute({
13570
13602
  async function handleNetworkStream({
13571
13603
  mastra,
13572
13604
  agentId,
13605
+ agentVersion,
13573
13606
  params,
13574
13607
  defaultOptions: defaultOptions3,
13575
13608
  version = "v5"
13576
13609
  }) {
13577
13610
  const { messages, ...rest } = params;
13578
- const agentObj = mastra.getAgentById(agentId);
13611
+ const agentObj = agentVersion ? await mastra.getAgentById(agentId, agentVersion) : mastra.getAgentById(agentId);
13579
13612
  if (!agentObj) {
13580
13613
  throw new Error(`Agent ${agentId} not found`);
13581
13614
  }
@@ -13612,7 +13645,8 @@ function networkRoute({
13612
13645
  path = "/network/:agentId",
13613
13646
  agent,
13614
13647
  defaultOptions: defaultOptions3,
13615
- version = "v5"
13648
+ version = "v5",
13649
+ agentVersion
13616
13650
  }) {
13617
13651
  if (!agent && !path.includes("/:agentId")) {
13618
13652
  throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
@@ -13630,6 +13664,20 @@ function networkRoute({
13630
13664
  required: true,
13631
13665
  description: "The ID of the routing agent to execute as a network",
13632
13666
  schema: { type: "string" }
13667
+ },
13668
+ {
13669
+ name: "versionId",
13670
+ in: "query",
13671
+ required: false,
13672
+ description: "Specific agent version ID to use. Mutually exclusive with status.",
13673
+ schema: { type: "string" }
13674
+ },
13675
+ {
13676
+ name: "status",
13677
+ in: "query",
13678
+ required: false,
13679
+ description: "Which stored config version to resolve: draft (latest) or published (active version). Mutually exclusive with versionId.",
13680
+ schema: { type: "string", enum: ["draft", "published"] }
13633
13681
  }
13634
13682
  ],
13635
13683
  requestBody: {
@@ -13658,6 +13706,14 @@ function networkRoute({
13658
13706
  description: "Streaming AI SDK UIMessage event stream for the agent network",
13659
13707
  content: { "text/plain": { schema: { type: "string", description: "SSE stream" } } }
13660
13708
  },
13709
+ "400": {
13710
+ description: "Bad request - invalid input",
13711
+ content: {
13712
+ "application/json": {
13713
+ schema: { type: "object", properties: { error: { type: "string" } } }
13714
+ }
13715
+ }
13716
+ },
13661
13717
  "404": {
13662
13718
  description: "Agent not found",
13663
13719
  content: {
@@ -13689,9 +13745,20 @@ function networkRoute({
13689
13745
  if (!agentToUse) {
13690
13746
  throw new Error("Agent ID is required");
13691
13747
  }
13748
+ const queryVersionId = c.req.query("versionId");
13749
+ const rawStatus = c.req.query("status");
13750
+ if (queryVersionId && rawStatus) {
13751
+ throw new Error('Query parameters "versionId" and "status" are mutually exclusive');
13752
+ }
13753
+ if (rawStatus && rawStatus !== "draft" && rawStatus !== "published") {
13754
+ throw new Error('Query parameter "status" must be "draft" or "published"');
13755
+ }
13756
+ const queryStatus = rawStatus;
13757
+ const effectiveAgentVersion = queryVersionId ? { versionId: queryVersionId } : queryStatus ? { status: queryStatus } : agentVersion;
13692
13758
  const handlerOptions = {
13693
13759
  mastra,
13694
13760
  agentId: agentToUse,
13761
+ agentVersion: effectiveAgentVersion,
13695
13762
  params: {
13696
13763
  ...params,
13697
13764
  requestContext: effectiveRequestContext