@mastra/deployer 0.2.5-alpha.3 → 0.2.6-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.
@@ -18,6 +18,7 @@ var logger = require('hono/logger');
18
18
  var httpException = require('hono/http-exception');
19
19
  var zod = require('zod');
20
20
  var agent = require('@mastra/core/agent');
21
+ var storage = require('@mastra/core/storage');
21
22
  var core = require('@mastra/core');
22
23
  var streaming = require('hono/streaming');
23
24
 
@@ -176,11 +177,11 @@ function writeFromReadableStream(stream, writable) {
176
177
  writable.off("close", cancel);
177
178
  writable.off("error", cancel);
178
179
  });
179
- function cancel(error) {
180
- reader.cancel(error).catch(() => {
180
+ function cancel(error2) {
181
+ reader.cancel(error2).catch(() => {
181
182
  });
182
- if (error) {
183
- writable.destroy(error);
183
+ if (error2) {
184
+ writable.destroy(error2);
184
185
  }
185
186
  }
186
187
  function onDrain() {
@@ -2836,9 +2837,9 @@ var zodToJsonSchema = (schema, options) => {
2836
2837
 
2837
2838
  // ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/index.js
2838
2839
  var esm_default = zodToJsonSchema;
2839
- function handleError(error, defaultMessage) {
2840
- console.error(defaultMessage, error);
2841
- const apiError = error;
2840
+ function handleError(error2, defaultMessage) {
2841
+ console.error(defaultMessage, error2);
2842
+ const apiError = error2;
2842
2843
  throw new httpException.HTTPException(apiError.status || 500, {
2843
2844
  message: apiError.message || defaultMessage
2844
2845
  });
@@ -2888,8 +2889,8 @@ async function getAgentsHandler(c2) {
2888
2889
  return acc;
2889
2890
  }, {});
2890
2891
  return c2.json(serializedAgents);
2891
- } catch (error) {
2892
- return handleError(error, "Error getting agents");
2892
+ } catch (error2) {
2893
+ return handleError(error2, "Error getting agents");
2893
2894
  }
2894
2895
  }
2895
2896
  async function getAgentByIdHandler(c2) {
@@ -2916,8 +2917,8 @@ async function getAgentByIdHandler(c2) {
2916
2917
  provider: agent.llm?.getProvider(),
2917
2918
  modelId: agent.llm?.getModelId()
2918
2919
  });
2919
- } catch (error) {
2920
- return handleError(error, "Error getting agent");
2920
+ } catch (error2) {
2921
+ return handleError(error2, "Error getting agent");
2921
2922
  }
2922
2923
  }
2923
2924
  async function getEvalsByAgentIdHandler(c2) {
@@ -2932,8 +2933,8 @@ async function getEvalsByAgentIdHandler(c2) {
2932
2933
  instructions: agent.instructions,
2933
2934
  evals
2934
2935
  });
2935
- } catch (error) {
2936
- return handleError(error, "Error getting test evals");
2936
+ } catch (error2) {
2937
+ return handleError(error2, "Error getting test evals");
2937
2938
  }
2938
2939
  }
2939
2940
  async function getLiveEvalsByAgentIdHandler(c2) {
@@ -2948,8 +2949,8 @@ async function getLiveEvalsByAgentIdHandler(c2) {
2948
2949
  instructions: agent.instructions,
2949
2950
  evals
2950
2951
  });
2951
- } catch (error) {
2952
- return handleError(error, "Error getting live evals");
2952
+ } catch (error2) {
2953
+ return handleError(error2, "Error getting live evals");
2953
2954
  }
2954
2955
  }
2955
2956
  async function generateHandler(c2) {
@@ -2965,8 +2966,8 @@ async function generateHandler(c2) {
2965
2966
  const finalResourceId = resourceId ?? resourceid;
2966
2967
  const result = await agent.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
2967
2968
  return c2.json(result);
2968
- } catch (error) {
2969
- return handleError(error, "Error generating from agent");
2969
+ } catch (error2) {
2970
+ return handleError(error2, "Error generating from agent");
2970
2971
  }
2971
2972
  }
2972
2973
  async function streamGenerateHandler(c2) {
@@ -2990,13 +2991,13 @@ async function streamGenerateHandler(c2) {
2990
2991
  const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
2991
2992
  sendUsage: true,
2992
2993
  sendReasoning: true,
2993
- getErrorMessage: (error) => {
2994
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
2994
+ getErrorMessage: (error2) => {
2995
+ return `An error occurred while processing your request. ${error2 instanceof Error ? error2.message : JSON.stringify(error2)}`;
2995
2996
  }
2996
2997
  });
2997
2998
  return streamResponse;
2998
- } catch (error) {
2999
- return handleError(error, "Error streaming from agent");
2999
+ } catch (error2) {
3000
+ return handleError(error2, "Error streaming from agent");
3000
3001
  }
3001
3002
  }
3002
3003
  async function setAgentInstructionsHandler(c2) {
@@ -3022,8 +3023,8 @@ async function setAgentInstructionsHandler(c2) {
3022
3023
  },
3023
3024
  200
3024
3025
  );
3025
- } catch (error) {
3026
- return handleError(error, "Error setting agent instructions");
3026
+ } catch (error2) {
3027
+ return handleError(error2, "Error setting agent instructions");
3027
3028
  }
3028
3029
  }
3029
3030
 
@@ -3067,8 +3068,8 @@ async function getLogsHandler(c2) {
3067
3068
  }
3068
3069
  const logs = await mastra.getLogs(transportId);
3069
3070
  return c2.json(logs);
3070
- } catch (error) {
3071
- return handleError(error, "Error getting logs");
3071
+ } catch (error2) {
3072
+ return handleError(error2, "Error getting logs");
3072
3073
  }
3073
3074
  }
3074
3075
  async function getLogsByRunIdHandler(c2) {
@@ -3081,8 +3082,8 @@ async function getLogsByRunIdHandler(c2) {
3081
3082
  }
3082
3083
  const logs = await mastra.getLogsByRunId({ runId, transportId });
3083
3084
  return c2.json(logs);
3084
- } catch (error) {
3085
- return handleError(error, "Error getting logs by run ID");
3085
+ } catch (error2) {
3086
+ return handleError(error2, "Error getting logs by run ID");
3086
3087
  }
3087
3088
  }
3088
3089
  async function getLogTransports(c2) {
@@ -3114,8 +3115,8 @@ async function getMemoryStatusHandler(c2) {
3114
3115
  return c2.json({ result: false });
3115
3116
  }
3116
3117
  return c2.json({ result: true });
3117
- } catch (error) {
3118
- return handleError(error, "Error getting memory status");
3118
+ } catch (error2) {
3119
+ return handleError(error2, "Error getting memory status");
3119
3120
  }
3120
3121
  }
3121
3122
  async function getThreadsHandler(c2) {
@@ -3130,8 +3131,8 @@ async function getThreadsHandler(c2) {
3130
3131
  }
3131
3132
  const threads = await memory.getThreadsByResourceId({ resourceId: resourceid });
3132
3133
  return c2.json(threads);
3133
- } catch (error) {
3134
- return handleError(error, "Error getting threads");
3134
+ } catch (error2) {
3135
+ return handleError(error2, "Error getting threads");
3135
3136
  }
3136
3137
  }
3137
3138
  async function getThreadByIdHandler(c2) {
@@ -3146,8 +3147,8 @@ async function getThreadByIdHandler(c2) {
3146
3147
  throw new httpException.HTTPException(404, { message: "Thread not found" });
3147
3148
  }
3148
3149
  return c2.json(thread);
3149
- } catch (error) {
3150
- return handleError(error, "Error getting thread");
3150
+ } catch (error2) {
3151
+ return handleError(error2, "Error getting thread");
3151
3152
  }
3152
3153
  }
3153
3154
  async function saveMessagesHandler(c2) {
@@ -3168,8 +3169,8 @@ async function saveMessagesHandler(c2) {
3168
3169
  }));
3169
3170
  const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
3170
3171
  return c2.json(result);
3171
- } catch (error) {
3172
- return handleError(error, "Error saving messages");
3172
+ } catch (error2) {
3173
+ return handleError(error2, "Error saving messages");
3173
3174
  }
3174
3175
  }
3175
3176
  async function createThreadHandler(c2) {
@@ -3182,8 +3183,8 @@ async function createThreadHandler(c2) {
3182
3183
  validateBody({ resourceid });
3183
3184
  const result = await memory.createThread({ resourceId: resourceid, title, metadata, threadId });
3184
3185
  return c2.json(result);
3185
- } catch (error) {
3186
- return handleError(error, "Error saving thread to memory");
3186
+ } catch (error2) {
3187
+ return handleError(error2, "Error saving thread to memory");
3187
3188
  }
3188
3189
  }
3189
3190
  async function updateThreadHandler(c2) {
@@ -3209,8 +3210,8 @@ async function updateThreadHandler(c2) {
3209
3210
  };
3210
3211
  const result = await memory.saveThread({ thread: updatedThread });
3211
3212
  return c2.json(result);
3212
- } catch (error) {
3213
- return handleError(error, "Error updating thread");
3213
+ } catch (error2) {
3214
+ return handleError(error2, "Error updating thread");
3214
3215
  }
3215
3216
  }
3216
3217
  async function deleteThreadHandler(c2) {
@@ -3226,8 +3227,8 @@ async function deleteThreadHandler(c2) {
3226
3227
  }
3227
3228
  await memory.deleteThread(threadId);
3228
3229
  return c2.json({ result: "Thread deleted" });
3229
- } catch (error) {
3230
- return handleError(error, "Error deleting thread");
3230
+ } catch (error2) {
3231
+ return handleError(error2, "Error deleting thread");
3231
3232
  }
3232
3233
  }
3233
3234
  async function getMessagesHandler(c2) {
@@ -3243,8 +3244,8 @@ async function getMessagesHandler(c2) {
3243
3244
  }
3244
3245
  const result = await memory.query({ threadId });
3245
3246
  return c2.json(result);
3246
- } catch (error) {
3247
- return handleError(error, "Error getting messages");
3247
+ } catch (error2) {
3248
+ return handleError(error2, "Error getting messages");
3248
3249
  }
3249
3250
  }
3250
3251
  async function getNetworksHandler(c2) {
@@ -3270,8 +3271,8 @@ async function getNetworksHandler(c2) {
3270
3271
  };
3271
3272
  });
3272
3273
  return c2.json(serializedNetworks);
3273
- } catch (error) {
3274
- return handleError(error, "Error getting networks");
3274
+ } catch (error2) {
3275
+ return handleError(error2, "Error getting networks");
3275
3276
  }
3276
3277
  }
3277
3278
  async function getNetworkByIdHandler(c2) {
@@ -3303,8 +3304,8 @@ async function getNetworkByIdHandler(c2) {
3303
3304
  }
3304
3305
  };
3305
3306
  return c2.json(serializedNetwork);
3306
- } catch (error) {
3307
- return handleError(error, "Error getting network by ID");
3307
+ } catch (error2) {
3308
+ return handleError(error2, "Error getting network by ID");
3308
3309
  }
3309
3310
  }
3310
3311
  async function generateHandler2(c2) {
@@ -3320,8 +3321,8 @@ async function generateHandler2(c2) {
3320
3321
  const finalResourceId = resourceId ?? resourceid;
3321
3322
  const result = await network.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
3322
3323
  return c2.json(result);
3323
- } catch (error) {
3324
- return handleError(error, "Error generating from network");
3324
+ } catch (error2) {
3325
+ return handleError(error2, "Error generating from network");
3325
3326
  }
3326
3327
  }
3327
3328
  async function streamGenerateHandler2(c2) {
@@ -3345,13 +3346,13 @@ async function streamGenerateHandler2(c2) {
3345
3346
  const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
3346
3347
  sendUsage: true,
3347
3348
  sendReasoning: true,
3348
- getErrorMessage: (error) => {
3349
- return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
3349
+ getErrorMessage: (error2) => {
3350
+ return `An error occurred while processing your request. ${error2 instanceof Error ? error2.message : JSON.stringify(error2)}`;
3350
3351
  }
3351
3352
  });
3352
3353
  return streamResponse;
3353
- } catch (error) {
3354
- return handleError(error, "Error streaming from network");
3354
+ } catch (error2) {
3355
+ return handleError(error2, "Error streaming from network");
3355
3356
  }
3356
3357
  }
3357
3358
  async function generateSystemPromptHandler(c2) {
@@ -3387,8 +3388,8 @@ async function generateSystemPromptHandler(c2) {
3387
3388
 
3388
3389
  `
3389
3390
  ).join("");
3390
- } catch (error) {
3391
- mastra.getLogger().error(`Error fetching evals`, { error });
3391
+ } catch (error2) {
3392
+ mastra.getLogger().error(`Error fetching evals`, { error: error2 });
3392
3393
  }
3393
3394
  const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
3394
3395
  You are an expert system prompt engineer, specialized in analyzing and enhancing instructions to create clear, effective, and comprehensive system prompts. Your goal is to help users transform their basic instructions into well-structured system prompts that will guide AI behavior effectively.
@@ -3459,8 +3460,8 @@ ${evalSummary}` : ""}
3459
3460
  }
3460
3461
  );
3461
3462
  return c2.json(result?.object || {});
3462
- } catch (error) {
3463
- return handleError(error, "Error generating system prompt");
3463
+ } catch (error2) {
3464
+ return handleError(error2, "Error generating system prompt");
3464
3465
  }
3465
3466
  }
3466
3467
 
@@ -3495,8 +3496,97 @@ async function getTelemetryHandler(c2) {
3495
3496
  attributes
3496
3497
  });
3497
3498
  return c2.json({ traces });
3498
- } catch (error) {
3499
- return handleError(error, "Error saving messages");
3499
+ } catch (error2) {
3500
+ return handleError(error2, "Error saving messages");
3501
+ }
3502
+ }
3503
+ async function storeTelemetryHandler(c2) {
3504
+ try {
3505
+ const body = await c2.req.json();
3506
+ const mastra = c2.get("mastra");
3507
+ const storage$1 = mastra.getStorage();
3508
+ const now = /* @__PURE__ */ new Date();
3509
+ const items = body?.resourceSpans?.[0]?.scopeSpans;
3510
+ const allSpans = items.reduce((acc, scopedSpans) => {
3511
+ const { scope, spans } = scopedSpans;
3512
+ for (const span of spans) {
3513
+ const {
3514
+ spanId,
3515
+ parentSpanId,
3516
+ traceId,
3517
+ name,
3518
+ kind,
3519
+ attributes,
3520
+ status,
3521
+ events,
3522
+ links,
3523
+ startTimeUnixNano,
3524
+ endTimeUnixNano,
3525
+ ...rest
3526
+ } = span;
3527
+ const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
3528
+ const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
3529
+ acc.push({
3530
+ id: spanId,
3531
+ parentSpanId,
3532
+ traceId,
3533
+ name,
3534
+ scope: scope.name,
3535
+ kind,
3536
+ status: JSON.stringify(status),
3537
+ events: JSON.stringify(events),
3538
+ links: JSON.stringify(links),
3539
+ attributes: JSON.stringify(
3540
+ attributes.reduce((acc2, attr) => {
3541
+ const valueKey = Object.keys(attr.value)[0];
3542
+ if (valueKey) {
3543
+ acc2[attr.key] = attr.value[valueKey];
3544
+ }
3545
+ return acc2;
3546
+ }, {})
3547
+ ),
3548
+ startTime,
3549
+ endTime,
3550
+ other: JSON.stringify(rest),
3551
+ createdAt: now
3552
+ });
3553
+ }
3554
+ return acc;
3555
+ }, []);
3556
+ return storage$1.__batchInsert({
3557
+ tableName: storage.TABLE_TRACES,
3558
+ records: allSpans
3559
+ }).then(() => {
3560
+ return c2.json(
3561
+ {
3562
+ status: "success",
3563
+ message: "Traces received and processed successfully",
3564
+ traceCount: body.resourceSpans?.length || 0
3565
+ },
3566
+ 200
3567
+ );
3568
+ }).catch((e2) => {
3569
+ return c2.json(
3570
+ {
3571
+ status: "error",
3572
+ message: "Failed to process traces",
3573
+ // @ts-ignore
3574
+ error: error.message
3575
+ },
3576
+ 500
3577
+ );
3578
+ });
3579
+ } catch (error2) {
3580
+ console.error("Error processing traces:", error2);
3581
+ return c2.json(
3582
+ {
3583
+ status: "error",
3584
+ message: "Failed to process traces",
3585
+ // @ts-ignore
3586
+ error: error2.message
3587
+ },
3588
+ 500
3589
+ );
3500
3590
  }
3501
3591
  }
3502
3592
  async function getToolsHandler(c2) {
@@ -3518,8 +3608,8 @@ async function getToolsHandler(c2) {
3518
3608
  {}
3519
3609
  );
3520
3610
  return c2.json(serializedTools);
3521
- } catch (error) {
3522
- return handleError(error, "Error getting tools");
3611
+ } catch (error2) {
3612
+ return handleError(error2, "Error getting tools");
3523
3613
  }
3524
3614
  }
3525
3615
  async function getToolByIdHandler(c2) {
@@ -3536,8 +3626,8 @@ async function getToolByIdHandler(c2) {
3536
3626
  outputSchema: tool.outputSchema ? stringify(esm_default(tool.outputSchema)) : void 0
3537
3627
  };
3538
3628
  return c2.json(serializedTool);
3539
- } catch (error) {
3540
- return handleError(error, "Error getting tool");
3629
+ } catch (error2) {
3630
+ return handleError(error2, "Error getting tool");
3541
3631
  }
3542
3632
  }
3543
3633
  function executeToolHandler(tools) {
@@ -3563,8 +3653,8 @@ function executeToolHandler(tools) {
3563
3653
  runId: mastra.runId
3564
3654
  });
3565
3655
  return c2.json(result);
3566
- } catch (error) {
3567
- return handleError(error, "Error executing tool");
3656
+ } catch (error2) {
3657
+ return handleError(error2, "Error executing tool");
3568
3658
  }
3569
3659
  };
3570
3660
  }
@@ -3592,8 +3682,8 @@ async function executeAgentToolHandler(c2) {
3592
3682
  runId: agentId
3593
3683
  });
3594
3684
  return c2.json(result);
3595
- } catch (error) {
3596
- return handleError(error, "Error executing tool");
3685
+ } catch (error2) {
3686
+ return handleError(error2, "Error executing tool");
3597
3687
  }
3598
3688
  }
3599
3689
  var getVector = (c2, vectorName) => {
@@ -3613,8 +3703,8 @@ async function upsertVectors(c2) {
3613
3703
  const vector = getVector(c2, vectorName);
3614
3704
  const result = await vector.upsert({ indexName, vectors, metadata, ids });
3615
3705
  return c2.json({ ids: result });
3616
- } catch (error) {
3617
- return handleError(error, "Error upserting vectors");
3706
+ } catch (error2) {
3707
+ return handleError(error2, "Error upserting vectors");
3618
3708
  }
3619
3709
  }
3620
3710
  async function createIndex(c2) {
@@ -3632,8 +3722,8 @@ async function createIndex(c2) {
3632
3722
  const vector = getVector(c2, vectorName);
3633
3723
  await vector.createIndex({ indexName, dimension, metric });
3634
3724
  return c2.json({ success: true });
3635
- } catch (error) {
3636
- return handleError(error, "Error creating index");
3725
+ } catch (error2) {
3726
+ return handleError(error2, "Error creating index");
3637
3727
  }
3638
3728
  }
3639
3729
  async function queryVectors(c2) {
@@ -3646,8 +3736,8 @@ async function queryVectors(c2) {
3646
3736
  const vector = getVector(c2, vectorName);
3647
3737
  const results = await vector.query({ indexName, queryVector, topK, filter, includeVector });
3648
3738
  return c2.json({ results });
3649
- } catch (error) {
3650
- return handleError(error, "Error querying vectors");
3739
+ } catch (error2) {
3740
+ return handleError(error2, "Error querying vectors");
3651
3741
  }
3652
3742
  }
3653
3743
  async function listIndexes(c2) {
@@ -3656,8 +3746,8 @@ async function listIndexes(c2) {
3656
3746
  const vector = getVector(c2, vectorName);
3657
3747
  const indexes = await vector.listIndexes();
3658
3748
  return c2.json({ indexes: indexes.filter(Boolean) });
3659
- } catch (error) {
3660
- return handleError(error, "Error listing indexes");
3749
+ } catch (error2) {
3750
+ return handleError(error2, "Error listing indexes");
3661
3751
  }
3662
3752
  }
3663
3753
  async function describeIndex(c2) {
@@ -3674,8 +3764,8 @@ async function describeIndex(c2) {
3674
3764
  count: stats.count,
3675
3765
  metric: stats.metric?.toLowerCase()
3676
3766
  });
3677
- } catch (error) {
3678
- return handleError(error, "Error describing index");
3767
+ } catch (error2) {
3768
+ return handleError(error2, "Error describing index");
3679
3769
  }
3680
3770
  }
3681
3771
  async function deleteIndex(c2) {
@@ -3688,8 +3778,8 @@ async function deleteIndex(c2) {
3688
3778
  const vector = getVector(c2, vectorName);
3689
3779
  await vector.deleteIndex(indexName);
3690
3780
  return c2.json({ success: true });
3691
- } catch (error) {
3692
- return handleError(error, "Error deleting index");
3781
+ } catch (error2) {
3782
+ return handleError(error2, "Error deleting index");
3693
3783
  }
3694
3784
  }
3695
3785
  async function getSpeakersHandler(c2) {
@@ -3705,8 +3795,8 @@ async function getSpeakersHandler(c2) {
3705
3795
  }
3706
3796
  const speakers = await agent.getSpeakers();
3707
3797
  return c2.json(speakers);
3708
- } catch (error) {
3709
- return handleError(error, "Error getting speakers");
3798
+ } catch (error2) {
3799
+ return handleError(error2, "Error getting speakers");
3710
3800
  }
3711
3801
  }
3712
3802
  async function speakHandler(c2) {
@@ -3726,8 +3816,8 @@ async function speakHandler(c2) {
3726
3816
  c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
3727
3817
  c2.header("Transfer-Encoding", "chunked");
3728
3818
  return c2.body(audioStream);
3729
- } catch (error) {
3730
- return handleError(error, "Error generating speech");
3819
+ } catch (error2) {
3820
+ return handleError(error2, "Error generating speech");
3731
3821
  }
3732
3822
  }
3733
3823
  async function listenHandler(c2) {
@@ -3755,16 +3845,16 @@ async function listenHandler(c2) {
3755
3845
  let parsedOptions;
3756
3846
  try {
3757
3847
  parsedOptions = options ? JSON.parse(options) : {};
3758
- } catch (error) {
3759
- if (error instanceof SyntaxError) {
3760
- logger2.error("Invalid JSON in options:", error);
3848
+ } catch (error2) {
3849
+ if (error2 instanceof SyntaxError) {
3850
+ logger2.error("Invalid JSON in options:", error2);
3761
3851
  }
3762
3852
  parsedOptions = {};
3763
3853
  }
3764
3854
  const transcription = await agent.voice.listen(audioStream, parsedOptions);
3765
3855
  return c2.json({ text: transcription });
3766
- } catch (error) {
3767
- return handleError(error, "Error transcribing speech");
3856
+ } catch (error2) {
3857
+ return handleError(error2, "Error transcribing speech");
3768
3858
  }
3769
3859
  }
3770
3860
  async function getWorkflowsHandler(c2) {
@@ -3792,8 +3882,8 @@ async function getWorkflowsHandler(c2) {
3792
3882
  return acc;
3793
3883
  }, {});
3794
3884
  return c2.json(_workflows);
3795
- } catch (error) {
3796
- return handleError(error, "Error getting workflows");
3885
+ } catch (error2) {
3886
+ return handleError(error2, "Error getting workflows");
3797
3887
  }
3798
3888
  }
3799
3889
  async function getWorkflowByIdHandler(c2) {
@@ -3824,8 +3914,8 @@ async function getWorkflowByIdHandler(c2) {
3824
3914
  serializedStepGraph,
3825
3915
  serializedStepSubscriberGraph
3826
3916
  });
3827
- } catch (error) {
3828
- return handleError(error, "Error getting workflow");
3917
+ } catch (error2) {
3918
+ return handleError(error2, "Error getting workflow");
3829
3919
  }
3830
3920
  }
3831
3921
  async function startAsyncWorkflowHandler(c2) {
@@ -3846,8 +3936,8 @@ async function startAsyncWorkflowHandler(c2) {
3846
3936
  triggerData: body
3847
3937
  });
3848
3938
  return c2.json(result);
3849
- } catch (error) {
3850
- return handleError(error, "Error executing workflow");
3939
+ } catch (error2) {
3940
+ return handleError(error2, "Error executing workflow");
3851
3941
  }
3852
3942
  }
3853
3943
  async function createRunHandler(c2) {
@@ -3902,8 +3992,9 @@ async function watchWorkflowHandler(c2) {
3902
3992
  c2,
3903
3993
  async (stream) => {
3904
3994
  return new Promise((_resolve, _reject) => {
3905
- let unwatch = run.watch(({ activePaths, context, runId: runId2, timestamp, suspendedSteps }) => {
3906
- void stream.write(JSON.stringify({ activePaths, context, runId: runId2, timestamp, suspendedSteps }) + "");
3995
+ let unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
3996
+ const activePathsObj = Object.fromEntries(activePaths);
3997
+ void stream.write(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }) + "");
3907
3998
  });
3908
3999
  stream.onAbort(() => {
3909
4000
  unwatch?.();
@@ -3916,8 +4007,8 @@ async function watchWorkflowHandler(c2) {
3916
4007
  await stream.close();
3917
4008
  }
3918
4009
  );
3919
- } catch (error) {
3920
- return handleError(error, "Error watching workflow");
4010
+ } catch (error2) {
4011
+ return handleError(error2, "Error watching workflow");
3921
4012
  }
3922
4013
  }
3923
4014
  async function resumeAsyncWorkflowHandler(c2) {
@@ -3939,8 +4030,8 @@ async function resumeAsyncWorkflowHandler(c2) {
3939
4030
  context
3940
4031
  });
3941
4032
  return c2.json(result);
3942
- } catch (error) {
3943
- return handleError(error, "Error resuming workflow step");
4033
+ } catch (error2) {
4034
+ return handleError(error2, "Error resuming workflow step");
3944
4035
  }
3945
4036
  }
3946
4037
  async function resumeWorkflowHandler(c2) {
@@ -3962,8 +4053,8 @@ async function resumeWorkflowHandler(c2) {
3962
4053
  context
3963
4054
  });
3964
4055
  return c2.json({ message: "Workflow run resumed" });
3965
- } catch (error) {
3966
- return handleError(error, "Error resuming workflow");
4056
+ } catch (error2) {
4057
+ return handleError(error2, "Error resuming workflow");
3967
4058
  }
3968
4059
  }
3969
4060
 
@@ -4094,7 +4185,7 @@ async function createHonoServer(mastra, options = {}) {
4094
4185
  cors.cors({
4095
4186
  origin: "*",
4096
4187
  allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
4097
- allowHeaders: ["Content-Type", "Authorization"],
4188
+ allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type"],
4098
4189
  exposeHeaders: ["Content-Length", "X-Requested-With"],
4099
4190
  credentials: false,
4100
4191
  maxAge: 3600
@@ -4121,6 +4212,44 @@ async function createHonoServer(mastra, options = {}) {
4121
4212
  // 4.5 MB,
4122
4213
  onError: (c2) => c2.json({ error: "Request body too large" }, 413)
4123
4214
  };
4215
+ const server = mastra.getServer();
4216
+ const routes = server?.apiRoutes;
4217
+ if (server?.middleware) {
4218
+ const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
4219
+ const middlewares = normalizedMiddlewares.map((middleware2) => {
4220
+ if (typeof middleware2 === "function") {
4221
+ return {
4222
+ path: "*",
4223
+ handler: middleware2
4224
+ };
4225
+ }
4226
+ return middleware2;
4227
+ });
4228
+ for (const middleware2 of middlewares) {
4229
+ app.use(middleware2.path, middleware2.handler);
4230
+ }
4231
+ }
4232
+ if (routes) {
4233
+ for (const route of routes) {
4234
+ const middlewares = [];
4235
+ if (route.middleware) {
4236
+ middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
4237
+ }
4238
+ if (route.openapi) {
4239
+ middlewares.push(h(route.openapi));
4240
+ }
4241
+ console.log({ path: route.path, middlewares });
4242
+ if (route.method === "GET") {
4243
+ app.get(route.path, ...middlewares, route.handler);
4244
+ } else if (route.method === "POST") {
4245
+ app.post(route.path, ...middlewares, route.handler);
4246
+ } else if (route.method === "PUT") {
4247
+ app.put(route.path, ...middlewares, route.handler);
4248
+ } else if (route.method === "DELETE") {
4249
+ app.delete(route.path, ...middlewares, route.handler);
4250
+ }
4251
+ }
4252
+ }
4124
4253
  app.get(
4125
4254
  "/api",
4126
4255
  h({
@@ -5242,6 +5371,19 @@ async function createHonoServer(mastra, options = {}) {
5242
5371
  }),
5243
5372
  getTelemetryHandler
5244
5373
  );
5374
+ app.post(
5375
+ "/api/telemetry",
5376
+ h({
5377
+ description: "Store telemetry",
5378
+ tags: ["telemetry"],
5379
+ responses: {
5380
+ 200: {
5381
+ description: "Traces stored"
5382
+ }
5383
+ }
5384
+ }),
5385
+ storeTelemetryHandler
5386
+ );
5245
5387
  app.get(
5246
5388
  "/api/workflows",
5247
5389
  h({