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

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.
@@ -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,CAAC,CAAC;IACpD,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,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;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,iBAE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,wDAE3D"}
package/dist/index.cjs CHANGED
@@ -12298,6 +12298,14 @@ function createAgentStreamToAISDKTransformer(convertMastraChunkToAISDK, {
12298
12298
  if (chunk.type === "finish") {
12299
12299
  finishEventSent = true;
12300
12300
  }
12301
+ if (chunk.type === "object-result") {
12302
+ controller.enqueue({
12303
+ type: "data-structured-output",
12304
+ data: {
12305
+ object: chunk.object
12306
+ }
12307
+ });
12308
+ }
12301
12309
  const part = convertMastraChunkToAISDK({ chunk, mode: "stream" });
12302
12310
  const transformedChunk = convertFullStreamChunkToUIMessageStream({
12303
12311
  part,
@@ -13176,6 +13184,7 @@ function toAISdkStream(stream, options = {
13176
13184
  async function handleChatStream({
13177
13185
  mastra,
13178
13186
  agentId,
13187
+ agentVersion,
13179
13188
  params,
13180
13189
  defaultOptions: defaultOptions3,
13181
13190
  version = "v5",
@@ -13190,7 +13199,7 @@ async function handleChatStream({
13190
13199
  if (resumeData && !runId) {
13191
13200
  throw new Error("runId is required when resumeData is provided");
13192
13201
  }
13193
- const agentObj = mastra.getAgentById(agentId);
13202
+ const agentObj = agentVersion ? await mastra.getAgentById(agentId, agentVersion) : mastra.getAgentById(agentId);
13194
13203
  if (!agentObj) {
13195
13204
  throw new Error(`Agent ${agentId} not found`);
13196
13205
  }
@@ -13266,6 +13275,7 @@ function chatRoute({
13266
13275
  agent,
13267
13276
  defaultOptions: defaultOptions3,
13268
13277
  version = "v5",
13278
+ agentVersion,
13269
13279
  sendStart = true,
13270
13280
  sendFinish = true,
13271
13281
  sendReasoning = false,
@@ -13289,6 +13299,25 @@ function chatRoute({
13289
13299
  schema: {
13290
13300
  type: "string"
13291
13301
  }
13302
+ },
13303
+ {
13304
+ name: "versionId",
13305
+ in: "query",
13306
+ required: false,
13307
+ description: "Specific agent version ID to use. Mutually exclusive with status.",
13308
+ schema: {
13309
+ type: "string"
13310
+ }
13311
+ },
13312
+ {
13313
+ name: "status",
13314
+ in: "query",
13315
+ required: false,
13316
+ description: "Which stored config version to resolve: draft (latest) or published (active version). Mutually exclusive with versionId.",
13317
+ schema: {
13318
+ type: "string",
13319
+ enum: ["draft", "published"]
13320
+ }
13292
13321
  }
13293
13322
  ],
13294
13323
  requestBody: {
@@ -13396,9 +13425,20 @@ function chatRoute({
13396
13425
  if (!agentToUse) {
13397
13426
  throw new Error("Agent ID is required");
13398
13427
  }
13428
+ const queryVersionId = c.req.query("versionId");
13429
+ const rawStatus = c.req.query("status");
13430
+ if (queryVersionId && rawStatus) {
13431
+ throw new Error('Query parameters "versionId" and "status" are mutually exclusive');
13432
+ }
13433
+ if (rawStatus && rawStatus !== "draft" && rawStatus !== "published") {
13434
+ throw new Error('Query parameter "status" must be "draft" or "published"');
13435
+ }
13436
+ const queryStatus = rawStatus;
13437
+ const effectiveAgentVersion = queryVersionId ? { versionId: queryVersionId } : queryStatus ? { status: queryStatus } : agentVersion;
13399
13438
  const handlerOptions = {
13400
13439
  mastra,
13401
13440
  agentId: agentToUse,
13441
+ agentVersion: effectiveAgentVersion,
13402
13442
  params: {
13403
13443
  ...params,
13404
13444
  requestContext: effectiveRequestContext,
@@ -13570,12 +13610,13 @@ function workflowRoute({
13570
13610
  async function handleNetworkStream({
13571
13611
  mastra,
13572
13612
  agentId,
13613
+ agentVersion,
13573
13614
  params,
13574
13615
  defaultOptions: defaultOptions3,
13575
13616
  version = "v5"
13576
13617
  }) {
13577
13618
  const { messages, ...rest } = params;
13578
- const agentObj = mastra.getAgentById(agentId);
13619
+ const agentObj = agentVersion ? await mastra.getAgentById(agentId, agentVersion) : mastra.getAgentById(agentId);
13579
13620
  if (!agentObj) {
13580
13621
  throw new Error(`Agent ${agentId} not found`);
13581
13622
  }
@@ -13612,7 +13653,8 @@ function networkRoute({
13612
13653
  path = "/network/:agentId",
13613
13654
  agent,
13614
13655
  defaultOptions: defaultOptions3,
13615
- version = "v5"
13656
+ version = "v5",
13657
+ agentVersion
13616
13658
  }) {
13617
13659
  if (!agent && !path.includes("/:agentId")) {
13618
13660
  throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
@@ -13630,6 +13672,20 @@ function networkRoute({
13630
13672
  required: true,
13631
13673
  description: "The ID of the routing agent to execute as a network",
13632
13674
  schema: { type: "string" }
13675
+ },
13676
+ {
13677
+ name: "versionId",
13678
+ in: "query",
13679
+ required: false,
13680
+ description: "Specific agent version ID to use. Mutually exclusive with status.",
13681
+ schema: { type: "string" }
13682
+ },
13683
+ {
13684
+ name: "status",
13685
+ in: "query",
13686
+ required: false,
13687
+ description: "Which stored config version to resolve: draft (latest) or published (active version). Mutually exclusive with versionId.",
13688
+ schema: { type: "string", enum: ["draft", "published"] }
13633
13689
  }
13634
13690
  ],
13635
13691
  requestBody: {
@@ -13658,6 +13714,14 @@ function networkRoute({
13658
13714
  description: "Streaming AI SDK UIMessage event stream for the agent network",
13659
13715
  content: { "text/plain": { schema: { type: "string", description: "SSE stream" } } }
13660
13716
  },
13717
+ "400": {
13718
+ description: "Bad request - invalid input",
13719
+ content: {
13720
+ "application/json": {
13721
+ schema: { type: "object", properties: { error: { type: "string" } } }
13722
+ }
13723
+ }
13724
+ },
13661
13725
  "404": {
13662
13726
  description: "Agent not found",
13663
13727
  content: {
@@ -13689,9 +13753,20 @@ function networkRoute({
13689
13753
  if (!agentToUse) {
13690
13754
  throw new Error("Agent ID is required");
13691
13755
  }
13756
+ const queryVersionId = c.req.query("versionId");
13757
+ const rawStatus = c.req.query("status");
13758
+ if (queryVersionId && rawStatus) {
13759
+ throw new Error('Query parameters "versionId" and "status" are mutually exclusive');
13760
+ }
13761
+ if (rawStatus && rawStatus !== "draft" && rawStatus !== "published") {
13762
+ throw new Error('Query parameter "status" must be "draft" or "published"');
13763
+ }
13764
+ const queryStatus = rawStatus;
13765
+ const effectiveAgentVersion = queryVersionId ? { versionId: queryVersionId } : queryStatus ? { status: queryStatus } : agentVersion;
13692
13766
  const handlerOptions = {
13693
13767
  mastra,
13694
13768
  agentId: agentToUse,
13769
+ agentVersion: effectiveAgentVersion,
13695
13770
  params: {
13696
13771
  ...params,
13697
13772
  requestContext: effectiveRequestContext