@mastra/deployer 0.16.2 → 0.16.3-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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAuB5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,KAAK,QAAQ,GAAG,EAAE,CAAC;AAEnB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,GAAG,CAAC;QAAE,UAAU,EAAE,+BAA+B,CAAA;KAAE,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAGgC,QAAQ;eAAa,SAAS;2CAydhE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAkClG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAuB5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,KAAK,QAAQ,GAAG,EAAE,CAAC;AAEnB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,GAAG,CAAC;QAAE,UAAU,EAAE,+BAA+B,CAAA;KAAE,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAGgC,QAAQ;eAAa,SAAS;2CAwfhE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAkClG"}
@@ -21,7 +21,7 @@ import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecution
21
21
  import { stream } from 'hono/streaming';
22
22
  import { bodyLimit } from 'hono/body-limit';
23
23
  import { getAgentBuilderActionsHandler as getAgentBuilderActionsHandler$1, getAgentBuilderActionByIdHandler as getAgentBuilderActionByIdHandler$1, getAgentBuilderActionRunsHandler as getAgentBuilderActionRunsHandler$1, getAgentBuilderActionRunExecutionResultHandler as getAgentBuilderActionRunExecutionResultHandler$1, getAgentBuilderActionRunByIdHandler as getAgentBuilderActionRunByIdHandler$1, resumeAgentBuilderActionHandler as resumeAgentBuilderActionHandler$1, resumeAsyncAgentBuilderActionHandler as resumeAsyncAgentBuilderActionHandler$1, streamAgentBuilderActionHandler as streamAgentBuilderActionHandler$1, streamVNextAgentBuilderActionHandler as streamVNextAgentBuilderActionHandler$1, createAgentBuilderActionRunHandler as createAgentBuilderActionRunHandler$1, startAsyncAgentBuilderActionHandler as startAsyncAgentBuilderActionHandler$1, startAgentBuilderActionRunHandler as startAgentBuilderActionRunHandler$1, watchAgentBuilderActionHandler as watchAgentBuilderActionHandler$1, cancelAgentBuilderActionRunHandler as cancelAgentBuilderActionRunHandler$1, sendAgentBuilderActionRunEventHandler as sendAgentBuilderActionRunEventHandler$1 } from '@mastra/server/handlers/agent-builder';
24
- import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, generateVNextHandler as generateVNextHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextUIMessageHandler as streamVNextUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1 } from '@mastra/server/handlers/agents';
24
+ import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, streamNetworkHandler as streamNetworkHandler$1, generateVNextHandler as generateVNextHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextUIMessageHandler as streamVNextUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1 } from '@mastra/server/handlers/agents';
25
25
  import { Agent } from '@mastra/core/agent';
26
26
  import { z } from 'zod';
27
27
  import { getAgentToolHandler as getAgentToolHandler$1, executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
@@ -2125,39 +2125,21 @@ var AllowedProviderKeys = {
2125
2125
  };
2126
2126
 
2127
2127
  // src/server/handlers/routes/agents/handlers.ts
2128
- var vNextBodyOptions = {
2128
+ var sharedBodyOptions = {
2129
2129
  messages: {
2130
2130
  type: "array",
2131
2131
  items: { type: "object" }
2132
2132
  },
2133
- threadId: { type: "string" },
2134
- resourceId: { type: "string", description: "The resource ID for the conversation" },
2135
2133
  runId: { type: "string" },
2136
- output: { type: "object" },
2137
- instructions: { type: "string", description: "Optional instructions to override the agent's default instructions" },
2138
- context: {
2139
- type: "array",
2140
- items: { type: "object" },
2141
- description: "Additional context messages to include"
2142
- },
2143
2134
  memory: {
2144
2135
  type: "object",
2145
2136
  properties: {
2146
- threadId: { type: "string" },
2147
- resourceId: { type: "string", description: "The resource ID for the conversation" },
2137
+ thread: { type: "string" },
2138
+ resource: { type: "string", description: "The resource ID for the conversation" },
2148
2139
  options: { type: "object", description: "Memory configuration options" }
2149
2140
  },
2150
2141
  description: "Memory options for the conversation"
2151
2142
  },
2152
- savePerStep: { type: "boolean", description: "Whether to save messages incrementally on step finish" },
2153
- format: { type: "string", enum: ["mastra", "aisdk"], description: "Response format" },
2154
- toolChoice: {
2155
- oneOf: [
2156
- { type: "string", enum: ["auto", "none", "required"] },
2157
- { type: "object", properties: { type: { type: "string" }, toolName: { type: "string" } } }
2158
- ],
2159
- description: "Controls how tools are selected during generation"
2160
- },
2161
2143
  modelSettings: {
2162
2144
  type: "object",
2163
2145
  properties: {
@@ -2175,6 +2157,27 @@ var vNextBodyOptions = {
2175
2157
  description: "Model settings for generation"
2176
2158
  }
2177
2159
  };
2160
+ var vNextBodyOptions = {
2161
+ threadId: { type: "string" },
2162
+ resourceId: { type: "string", description: "The resource ID for the conversation" },
2163
+ output: { type: "object" },
2164
+ instructions: { type: "string", description: "Optional instructions to override the agent's default instructions" },
2165
+ context: {
2166
+ type: "array",
2167
+ items: { type: "object" },
2168
+ description: "Additional context messages to include"
2169
+ },
2170
+ savePerStep: { type: "boolean", description: "Whether to save messages incrementally on step finish" },
2171
+ toolChoice: {
2172
+ oneOf: [
2173
+ { type: "string", enum: ["auto", "none", "required"] },
2174
+ { type: "object", properties: { type: { type: "string" }, toolName: { type: "string" } } }
2175
+ ],
2176
+ description: "Controls how tools are selected during generation"
2177
+ },
2178
+ format: { type: "string", enum: ["mastra", "aisdk"], description: "Response format" },
2179
+ ...sharedBodyOptions
2180
+ };
2178
2181
  async function getAgentsHandler(c2) {
2179
2182
  const serializedAgents = await getAgentsHandler$1({
2180
2183
  mastra: c2.get("mastra"),
@@ -2350,6 +2353,49 @@ async function streamVNextGenerateHandler(c2) {
2350
2353
  return handleError(error, "Error streaming from agent");
2351
2354
  }
2352
2355
  }
2356
+ async function streamNetworkHandler(c2) {
2357
+ try {
2358
+ const mastra = c2.get("mastra");
2359
+ const agentId = c2.req.param("agentId");
2360
+ const runtimeContext = c2.get("runtimeContext");
2361
+ const body = await c2.req.json();
2362
+ const logger2 = mastra.getLogger();
2363
+ c2.header("Transfer-Encoding", "chunked");
2364
+ return stream(
2365
+ c2,
2366
+ async (stream7) => {
2367
+ try {
2368
+ const streamResponse = await streamNetworkHandler$1({
2369
+ mastra,
2370
+ agentId,
2371
+ runtimeContext,
2372
+ body
2373
+ // abortSignal: c.req.raw.signal,
2374
+ });
2375
+ const reader = streamResponse.getReader();
2376
+ stream7.onAbort(() => {
2377
+ void reader.cancel("request aborted");
2378
+ });
2379
+ let chunkResult;
2380
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
2381
+ await stream7.write(`data: ${JSON.stringify(chunkResult.value)}
2382
+
2383
+ `);
2384
+ }
2385
+ await stream7.write("data: [DONE]\n\n");
2386
+ } catch (err) {
2387
+ logger2.error("Error in streamNetwork generate: " + (err?.message ?? "Unknown error"));
2388
+ }
2389
+ await stream7.close();
2390
+ },
2391
+ async (err) => {
2392
+ logger2.error("Error in watch stream: " + err?.message);
2393
+ }
2394
+ );
2395
+ } catch (error) {
2396
+ return handleError(error, "Error streaming from agent in network mode");
2397
+ }
2398
+ }
2353
2399
  async function streamVNextUIMessageHandler(c2) {
2354
2400
  try {
2355
2401
  const mastra = c2.get("mastra");
@@ -2628,9 +2674,11 @@ async function getSpeakersHandler(c2) {
2628
2674
  try {
2629
2675
  const mastra = c2.get("mastra");
2630
2676
  const agentId = c2.req.param("agentId");
2677
+ const runtimeContext = c2.get("runtimeContext");
2631
2678
  const speakers = await getSpeakersHandler$1({
2632
2679
  mastra,
2633
- agentId
2680
+ agentId,
2681
+ runtimeContext
2634
2682
  });
2635
2683
  return c2.json(speakers);
2636
2684
  } catch (error) {
@@ -2641,10 +2689,12 @@ async function speakHandler(c2) {
2641
2689
  try {
2642
2690
  const mastra = c2.get("mastra");
2643
2691
  const agentId = c2.req.param("agentId");
2692
+ const runtimeContext = c2.get("runtimeContext");
2644
2693
  const { input, options } = await c2.req.json();
2645
2694
  const audioStream = await generateSpeechHandler({
2646
2695
  mastra,
2647
2696
  agentId,
2697
+ runtimeContext,
2648
2698
  body: { text: input, speakerId: options?.speakerId }
2649
2699
  });
2650
2700
  c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
@@ -2658,9 +2708,11 @@ async function getListenerHandler(c2) {
2658
2708
  try {
2659
2709
  const mastra = c2.get("mastra");
2660
2710
  const agentId = c2.req.param("agentId");
2711
+ const runtimeContext = c2.get("runtimeContext");
2661
2712
  const listeners = await getListenerHandler$1({
2662
2713
  mastra,
2663
- agentId
2714
+ agentId,
2715
+ runtimeContext
2664
2716
  });
2665
2717
  return c2.json(listeners);
2666
2718
  } catch (error) {
@@ -2671,6 +2723,7 @@ async function listenHandler(c2) {
2671
2723
  try {
2672
2724
  const mastra = c2.get("mastra");
2673
2725
  const agentId = c2.req.param("agentId");
2726
+ const runtimeContext = c2.get("runtimeContext");
2674
2727
  const formData = await c2.req.formData();
2675
2728
  const audioFile = formData.get("audio");
2676
2729
  const options = formData.get("options");
@@ -2686,6 +2739,7 @@ async function listenHandler(c2) {
2686
2739
  const transcription = await transcribeSpeechHandler({
2687
2740
  mastra,
2688
2741
  agentId,
2742
+ runtimeContext,
2689
2743
  body: {
2690
2744
  audioData: Buffer.from(audioData),
2691
2745
  options: parsedOptions
@@ -2881,6 +2935,35 @@ function agentsRouter(bodyLimitOptions) {
2881
2935
  }),
2882
2936
  generateHandler
2883
2937
  );
2938
+ router.post(
2939
+ "/:agentId/network",
2940
+ bodyLimit(bodyLimitOptions),
2941
+ w({
2942
+ description: "Execute an agent as a Network",
2943
+ tags: ["agents"],
2944
+ parameters: [
2945
+ {
2946
+ name: "agentId",
2947
+ in: "path",
2948
+ required: true,
2949
+ schema: { type: "string" }
2950
+ }
2951
+ ],
2952
+ requestBody: {
2953
+ required: true,
2954
+ content: {
2955
+ "application/json": {
2956
+ schema: {
2957
+ type: "object",
2958
+ properties: sharedBodyOptions,
2959
+ required: ["messages"]
2960
+ }
2961
+ }
2962
+ }
2963
+ }
2964
+ }),
2965
+ streamNetworkHandler
2966
+ );
2884
2967
  router.post(
2885
2968
  "/:agentId/generate/vnext",
2886
2969
  bodyLimit(bodyLimitOptions),
@@ -10923,6 +11006,27 @@ async function createHonoServer(mastra, options = {
10923
11006
  }
10924
11007
  }
10925
11008
  }
11009
+ if (c2.req.method === "GET") {
11010
+ try {
11011
+ const encodedRuntimeContext = c2.req.query("runtimeContext");
11012
+ if (encodedRuntimeContext) {
11013
+ let parsedRuntimeContext;
11014
+ try {
11015
+ parsedRuntimeContext = JSON.parse(encodedRuntimeContext);
11016
+ } catch {
11017
+ try {
11018
+ const json = Buffer.from(encodedRuntimeContext, "base64").toString("utf-8");
11019
+ parsedRuntimeContext = JSON.parse(json);
11020
+ } catch {
11021
+ }
11022
+ }
11023
+ if (parsedRuntimeContext && typeof parsedRuntimeContext === "object") {
11024
+ runtimeContext = new RuntimeContext([...runtimeContext.entries(), ...Object.entries(parsedRuntimeContext)]);
11025
+ }
11026
+ }
11027
+ } catch {
11028
+ }
11029
+ }
10926
11030
  c2.set("runtimeContext", runtimeContext);
10927
11031
  c2.set("mastra", mastra);
10928
11032
  c2.set("tools", options.tools);