@mastra/server 0.14.0-alpha.2 → 0.14.0-alpha.4

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.
@@ -113,6 +113,7 @@ var require_secure_json_parse = __commonJS({
113
113
  var agents_exports = {};
114
114
  __export(agents_exports, {
115
115
  generateHandler: () => generateHandler,
116
+ generateVNextHandler: () => generateVNextHandler,
116
117
  getAgentByIdHandler: () => getAgentByIdHandler,
117
118
  getAgentsHandler: () => getAgentsHandler,
118
119
  getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
@@ -120,6 +121,7 @@ __export(agents_exports, {
120
121
  getSerializedAgentTools: () => getSerializedAgentTools,
121
122
  streamGenerateHandler: () => streamGenerateHandler,
122
123
  streamVNextGenerateHandler: () => streamVNextGenerateHandler,
124
+ streamVNextUIMessageHandler: () => streamVNextUIMessageHandler,
123
125
  updateAgentModelHandler: () => updateAgentModelHandler
124
126
  });
125
127
 
@@ -7549,6 +7551,7 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
7549
7551
  logger.error("Error getting workflows for agent", { agentName: agent.name, error });
7550
7552
  }
7551
7553
  }
7554
+ const model = llm?.getModel();
7552
7555
  return {
7553
7556
  id,
7554
7557
  name: agent.name,
@@ -7557,6 +7560,7 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
7557
7560
  workflows: serializedAgentWorkflows,
7558
7561
  provider: llm?.getProvider(),
7559
7562
  modelId: llm?.getModelId(),
7563
+ modelVersion: model?.specificationVersion,
7560
7564
  defaultGenerateOptions,
7561
7565
  defaultStreamOptions
7562
7566
  };
@@ -7628,6 +7632,7 @@ async function getAgentByIdHandler({
7628
7632
  const llm = await agent.getLLM({ runtimeContext });
7629
7633
  const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
7630
7634
  const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
7635
+ const model = llm?.getModel();
7631
7636
  return {
7632
7637
  name: agent.name,
7633
7638
  instructions,
@@ -7635,6 +7640,7 @@ async function getAgentByIdHandler({
7635
7640
  workflows: serializedAgentWorkflows,
7636
7641
  provider: llm?.getProvider(),
7637
7642
  modelId: llm?.getModelId(),
7643
+ modelVersion: model?.specificationVersion,
7638
7644
  defaultGenerateOptions,
7639
7645
  defaultStreamOptions
7640
7646
  };
@@ -7711,6 +7717,38 @@ async function generateHandler({
7711
7717
  return handleError(error, "Error generating from agent");
7712
7718
  }
7713
7719
  }
7720
+ async function generateVNextHandler({
7721
+ mastra,
7722
+ runtimeContext,
7723
+ agentId,
7724
+ body,
7725
+ abortSignal
7726
+ }) {
7727
+ try {
7728
+ const agent = mastra.getAgent(agentId);
7729
+ if (!agent) {
7730
+ throw new HTTPException(404, { message: "Agent not found" });
7731
+ }
7732
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
7733
+ const finalRuntimeContext = new RuntimeContext([
7734
+ ...Array.from(runtimeContext.entries()),
7735
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
7736
+ ]);
7737
+ validateBody({ messages });
7738
+ const result = await agent.generateVNext(messages, {
7739
+ ...rest,
7740
+ runtimeContext: finalRuntimeContext,
7741
+ format: rest.format || "mastra",
7742
+ options: {
7743
+ ...rest?.options ?? {},
7744
+ abortSignal
7745
+ }
7746
+ });
7747
+ return result;
7748
+ } catch (error) {
7749
+ return handleError(error, "Error generating from agent");
7750
+ }
7751
+ }
7714
7752
  async function streamGenerateHandler({
7715
7753
  mastra,
7716
7754
  runtimeContext,
@@ -7777,13 +7815,49 @@ function streamVNextGenerateHandler({
7777
7815
  const streamResult = agent.streamVNext(messages, {
7778
7816
  ...rest,
7779
7817
  runtimeContext: finalRuntimeContext,
7780
- abortSignal
7818
+ options: {
7819
+ ...rest?.options ?? {},
7820
+ abortSignal
7821
+ },
7822
+ format: body.format ?? "mastra"
7781
7823
  });
7782
7824
  return streamResult;
7783
7825
  } catch (error) {
7784
7826
  return handleError(error, "error streaming agent response");
7785
7827
  }
7786
7828
  }
7829
+ async function streamVNextUIMessageHandler({
7830
+ mastra,
7831
+ runtimeContext,
7832
+ agentId,
7833
+ body,
7834
+ abortSignal
7835
+ }) {
7836
+ try {
7837
+ const agent = mastra.getAgent(agentId);
7838
+ if (!agent) {
7839
+ throw new HTTPException(404, { message: "Agent not found" });
7840
+ }
7841
+ const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
7842
+ const finalRuntimeContext = new RuntimeContext([
7843
+ ...Array.from(runtimeContext.entries()),
7844
+ ...Array.from(Object.entries(agentRuntimeContext ?? {}))
7845
+ ]);
7846
+ validateBody({ messages });
7847
+ const streamResult = await agent.streamVNext(messages, {
7848
+ ...rest,
7849
+ runtimeContext: finalRuntimeContext,
7850
+ options: {
7851
+ ...rest?.options ?? {},
7852
+ abortSignal
7853
+ },
7854
+ format: "aisdk"
7855
+ });
7856
+ return streamResult.toUIMessageStreamResponse();
7857
+ } catch (error) {
7858
+ return handleError(error, "error streaming agent response");
7859
+ }
7860
+ }
7787
7861
  function updateAgentModelHandler({
7788
7862
  mastra,
7789
7863
  agentId,
@@ -7810,6 +7884,6 @@ function updateAgentModelHandler({
7810
7884
  }
7811
7885
  }
7812
7886
 
7813
- export { agents_exports, generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getSerializedAgentTools, streamGenerateHandler, streamVNextGenerateHandler, updateAgentModelHandler };
7814
- //# sourceMappingURL=chunk-MG5HDGGH.js.map
7815
- //# sourceMappingURL=chunk-MG5HDGGH.js.map
7887
+ export { agents_exports, generateHandler, generateVNextHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getSerializedAgentTools, streamGenerateHandler, streamVNextGenerateHandler, streamVNextUIMessageHandler, updateAgentModelHandler };
7888
+ //# sourceMappingURL=chunk-6LHEW5YZ.js.map
7889
+ //# sourceMappingURL=chunk-6LHEW5YZ.js.map