@mastra/deployer 0.2.5 → 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.
- package/dist/_tsup-dts-rollup.d.cts +10 -0
- package/dist/_tsup-dts-rollup.d.ts +10 -0
- package/dist/server/index.cjs +245 -103
- package/dist/server/index.js +245 -103
- package/dist/templates/instrumentation-template.js +2 -13
- package/package.json +2 -2
package/dist/server/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { logger } from 'hono/logger';
|
|
|
16
16
|
import { HTTPException } from 'hono/http-exception';
|
|
17
17
|
import { z, ZodFirstPartyTypeKind, ZodOptional } from 'zod';
|
|
18
18
|
import { Agent } from '@mastra/core/agent';
|
|
19
|
+
import { TABLE_TRACES } from '@mastra/core/storage';
|
|
19
20
|
import { isVercelTool } from '@mastra/core';
|
|
20
21
|
import { streamText } from 'hono/streaming';
|
|
21
22
|
|
|
@@ -170,11 +171,11 @@ function writeFromReadableStream(stream, writable) {
|
|
|
170
171
|
writable.off("close", cancel);
|
|
171
172
|
writable.off("error", cancel);
|
|
172
173
|
});
|
|
173
|
-
function cancel(
|
|
174
|
-
reader.cancel(
|
|
174
|
+
function cancel(error2) {
|
|
175
|
+
reader.cancel(error2).catch(() => {
|
|
175
176
|
});
|
|
176
|
-
if (
|
|
177
|
-
writable.destroy(
|
|
177
|
+
if (error2) {
|
|
178
|
+
writable.destroy(error2);
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
function onDrain() {
|
|
@@ -2830,9 +2831,9 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
2830
2831
|
|
|
2831
2832
|
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/index.js
|
|
2832
2833
|
var esm_default = zodToJsonSchema;
|
|
2833
|
-
function handleError(
|
|
2834
|
-
console.error(defaultMessage,
|
|
2835
|
-
const apiError =
|
|
2834
|
+
function handleError(error2, defaultMessage) {
|
|
2835
|
+
console.error(defaultMessage, error2);
|
|
2836
|
+
const apiError = error2;
|
|
2836
2837
|
throw new HTTPException(apiError.status || 500, {
|
|
2837
2838
|
message: apiError.message || defaultMessage
|
|
2838
2839
|
});
|
|
@@ -2882,8 +2883,8 @@ async function getAgentsHandler(c2) {
|
|
|
2882
2883
|
return acc;
|
|
2883
2884
|
}, {});
|
|
2884
2885
|
return c2.json(serializedAgents);
|
|
2885
|
-
} catch (
|
|
2886
|
-
return handleError(
|
|
2886
|
+
} catch (error2) {
|
|
2887
|
+
return handleError(error2, "Error getting agents");
|
|
2887
2888
|
}
|
|
2888
2889
|
}
|
|
2889
2890
|
async function getAgentByIdHandler(c2) {
|
|
@@ -2910,8 +2911,8 @@ async function getAgentByIdHandler(c2) {
|
|
|
2910
2911
|
provider: agent.llm?.getProvider(),
|
|
2911
2912
|
modelId: agent.llm?.getModelId()
|
|
2912
2913
|
});
|
|
2913
|
-
} catch (
|
|
2914
|
-
return handleError(
|
|
2914
|
+
} catch (error2) {
|
|
2915
|
+
return handleError(error2, "Error getting agent");
|
|
2915
2916
|
}
|
|
2916
2917
|
}
|
|
2917
2918
|
async function getEvalsByAgentIdHandler(c2) {
|
|
@@ -2926,8 +2927,8 @@ async function getEvalsByAgentIdHandler(c2) {
|
|
|
2926
2927
|
instructions: agent.instructions,
|
|
2927
2928
|
evals
|
|
2928
2929
|
});
|
|
2929
|
-
} catch (
|
|
2930
|
-
return handleError(
|
|
2930
|
+
} catch (error2) {
|
|
2931
|
+
return handleError(error2, "Error getting test evals");
|
|
2931
2932
|
}
|
|
2932
2933
|
}
|
|
2933
2934
|
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
@@ -2942,8 +2943,8 @@ async function getLiveEvalsByAgentIdHandler(c2) {
|
|
|
2942
2943
|
instructions: agent.instructions,
|
|
2943
2944
|
evals
|
|
2944
2945
|
});
|
|
2945
|
-
} catch (
|
|
2946
|
-
return handleError(
|
|
2946
|
+
} catch (error2) {
|
|
2947
|
+
return handleError(error2, "Error getting live evals");
|
|
2947
2948
|
}
|
|
2948
2949
|
}
|
|
2949
2950
|
async function generateHandler(c2) {
|
|
@@ -2959,8 +2960,8 @@ async function generateHandler(c2) {
|
|
|
2959
2960
|
const finalResourceId = resourceId ?? resourceid;
|
|
2960
2961
|
const result = await agent.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
2961
2962
|
return c2.json(result);
|
|
2962
|
-
} catch (
|
|
2963
|
-
return handleError(
|
|
2963
|
+
} catch (error2) {
|
|
2964
|
+
return handleError(error2, "Error generating from agent");
|
|
2964
2965
|
}
|
|
2965
2966
|
}
|
|
2966
2967
|
async function streamGenerateHandler(c2) {
|
|
@@ -2984,13 +2985,13 @@ async function streamGenerateHandler(c2) {
|
|
|
2984
2985
|
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
2985
2986
|
sendUsage: true,
|
|
2986
2987
|
sendReasoning: true,
|
|
2987
|
-
getErrorMessage: (
|
|
2988
|
-
return `An error occurred while processing your request. ${
|
|
2988
|
+
getErrorMessage: (error2) => {
|
|
2989
|
+
return `An error occurred while processing your request. ${error2 instanceof Error ? error2.message : JSON.stringify(error2)}`;
|
|
2989
2990
|
}
|
|
2990
2991
|
});
|
|
2991
2992
|
return streamResponse;
|
|
2992
|
-
} catch (
|
|
2993
|
-
return handleError(
|
|
2993
|
+
} catch (error2) {
|
|
2994
|
+
return handleError(error2, "Error streaming from agent");
|
|
2994
2995
|
}
|
|
2995
2996
|
}
|
|
2996
2997
|
async function setAgentInstructionsHandler(c2) {
|
|
@@ -3016,8 +3017,8 @@ async function setAgentInstructionsHandler(c2) {
|
|
|
3016
3017
|
},
|
|
3017
3018
|
200
|
|
3018
3019
|
);
|
|
3019
|
-
} catch (
|
|
3020
|
-
return handleError(
|
|
3020
|
+
} catch (error2) {
|
|
3021
|
+
return handleError(error2, "Error setting agent instructions");
|
|
3021
3022
|
}
|
|
3022
3023
|
}
|
|
3023
3024
|
|
|
@@ -3061,8 +3062,8 @@ async function getLogsHandler(c2) {
|
|
|
3061
3062
|
}
|
|
3062
3063
|
const logs = await mastra.getLogs(transportId);
|
|
3063
3064
|
return c2.json(logs);
|
|
3064
|
-
} catch (
|
|
3065
|
-
return handleError(
|
|
3065
|
+
} catch (error2) {
|
|
3066
|
+
return handleError(error2, "Error getting logs");
|
|
3066
3067
|
}
|
|
3067
3068
|
}
|
|
3068
3069
|
async function getLogsByRunIdHandler(c2) {
|
|
@@ -3075,8 +3076,8 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
3075
3076
|
}
|
|
3076
3077
|
const logs = await mastra.getLogsByRunId({ runId, transportId });
|
|
3077
3078
|
return c2.json(logs);
|
|
3078
|
-
} catch (
|
|
3079
|
-
return handleError(
|
|
3079
|
+
} catch (error2) {
|
|
3080
|
+
return handleError(error2, "Error getting logs by run ID");
|
|
3080
3081
|
}
|
|
3081
3082
|
}
|
|
3082
3083
|
async function getLogTransports(c2) {
|
|
@@ -3108,8 +3109,8 @@ async function getMemoryStatusHandler(c2) {
|
|
|
3108
3109
|
return c2.json({ result: false });
|
|
3109
3110
|
}
|
|
3110
3111
|
return c2.json({ result: true });
|
|
3111
|
-
} catch (
|
|
3112
|
-
return handleError(
|
|
3112
|
+
} catch (error2) {
|
|
3113
|
+
return handleError(error2, "Error getting memory status");
|
|
3113
3114
|
}
|
|
3114
3115
|
}
|
|
3115
3116
|
async function getThreadsHandler(c2) {
|
|
@@ -3124,8 +3125,8 @@ async function getThreadsHandler(c2) {
|
|
|
3124
3125
|
}
|
|
3125
3126
|
const threads = await memory.getThreadsByResourceId({ resourceId: resourceid });
|
|
3126
3127
|
return c2.json(threads);
|
|
3127
|
-
} catch (
|
|
3128
|
-
return handleError(
|
|
3128
|
+
} catch (error2) {
|
|
3129
|
+
return handleError(error2, "Error getting threads");
|
|
3129
3130
|
}
|
|
3130
3131
|
}
|
|
3131
3132
|
async function getThreadByIdHandler(c2) {
|
|
@@ -3140,8 +3141,8 @@ async function getThreadByIdHandler(c2) {
|
|
|
3140
3141
|
throw new HTTPException(404, { message: "Thread not found" });
|
|
3141
3142
|
}
|
|
3142
3143
|
return c2.json(thread);
|
|
3143
|
-
} catch (
|
|
3144
|
-
return handleError(
|
|
3144
|
+
} catch (error2) {
|
|
3145
|
+
return handleError(error2, "Error getting thread");
|
|
3145
3146
|
}
|
|
3146
3147
|
}
|
|
3147
3148
|
async function saveMessagesHandler(c2) {
|
|
@@ -3162,8 +3163,8 @@ async function saveMessagesHandler(c2) {
|
|
|
3162
3163
|
}));
|
|
3163
3164
|
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
3164
3165
|
return c2.json(result);
|
|
3165
|
-
} catch (
|
|
3166
|
-
return handleError(
|
|
3166
|
+
} catch (error2) {
|
|
3167
|
+
return handleError(error2, "Error saving messages");
|
|
3167
3168
|
}
|
|
3168
3169
|
}
|
|
3169
3170
|
async function createThreadHandler(c2) {
|
|
@@ -3176,8 +3177,8 @@ async function createThreadHandler(c2) {
|
|
|
3176
3177
|
validateBody({ resourceid });
|
|
3177
3178
|
const result = await memory.createThread({ resourceId: resourceid, title, metadata, threadId });
|
|
3178
3179
|
return c2.json(result);
|
|
3179
|
-
} catch (
|
|
3180
|
-
return handleError(
|
|
3180
|
+
} catch (error2) {
|
|
3181
|
+
return handleError(error2, "Error saving thread to memory");
|
|
3181
3182
|
}
|
|
3182
3183
|
}
|
|
3183
3184
|
async function updateThreadHandler(c2) {
|
|
@@ -3203,8 +3204,8 @@ async function updateThreadHandler(c2) {
|
|
|
3203
3204
|
};
|
|
3204
3205
|
const result = await memory.saveThread({ thread: updatedThread });
|
|
3205
3206
|
return c2.json(result);
|
|
3206
|
-
} catch (
|
|
3207
|
-
return handleError(
|
|
3207
|
+
} catch (error2) {
|
|
3208
|
+
return handleError(error2, "Error updating thread");
|
|
3208
3209
|
}
|
|
3209
3210
|
}
|
|
3210
3211
|
async function deleteThreadHandler(c2) {
|
|
@@ -3220,8 +3221,8 @@ async function deleteThreadHandler(c2) {
|
|
|
3220
3221
|
}
|
|
3221
3222
|
await memory.deleteThread(threadId);
|
|
3222
3223
|
return c2.json({ result: "Thread deleted" });
|
|
3223
|
-
} catch (
|
|
3224
|
-
return handleError(
|
|
3224
|
+
} catch (error2) {
|
|
3225
|
+
return handleError(error2, "Error deleting thread");
|
|
3225
3226
|
}
|
|
3226
3227
|
}
|
|
3227
3228
|
async function getMessagesHandler(c2) {
|
|
@@ -3237,8 +3238,8 @@ async function getMessagesHandler(c2) {
|
|
|
3237
3238
|
}
|
|
3238
3239
|
const result = await memory.query({ threadId });
|
|
3239
3240
|
return c2.json(result);
|
|
3240
|
-
} catch (
|
|
3241
|
-
return handleError(
|
|
3241
|
+
} catch (error2) {
|
|
3242
|
+
return handleError(error2, "Error getting messages");
|
|
3242
3243
|
}
|
|
3243
3244
|
}
|
|
3244
3245
|
async function getNetworksHandler(c2) {
|
|
@@ -3264,8 +3265,8 @@ async function getNetworksHandler(c2) {
|
|
|
3264
3265
|
};
|
|
3265
3266
|
});
|
|
3266
3267
|
return c2.json(serializedNetworks);
|
|
3267
|
-
} catch (
|
|
3268
|
-
return handleError(
|
|
3268
|
+
} catch (error2) {
|
|
3269
|
+
return handleError(error2, "Error getting networks");
|
|
3269
3270
|
}
|
|
3270
3271
|
}
|
|
3271
3272
|
async function getNetworkByIdHandler(c2) {
|
|
@@ -3297,8 +3298,8 @@ async function getNetworkByIdHandler(c2) {
|
|
|
3297
3298
|
}
|
|
3298
3299
|
};
|
|
3299
3300
|
return c2.json(serializedNetwork);
|
|
3300
|
-
} catch (
|
|
3301
|
-
return handleError(
|
|
3301
|
+
} catch (error2) {
|
|
3302
|
+
return handleError(error2, "Error getting network by ID");
|
|
3302
3303
|
}
|
|
3303
3304
|
}
|
|
3304
3305
|
async function generateHandler2(c2) {
|
|
@@ -3314,8 +3315,8 @@ async function generateHandler2(c2) {
|
|
|
3314
3315
|
const finalResourceId = resourceId ?? resourceid;
|
|
3315
3316
|
const result = await network.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
3316
3317
|
return c2.json(result);
|
|
3317
|
-
} catch (
|
|
3318
|
-
return handleError(
|
|
3318
|
+
} catch (error2) {
|
|
3319
|
+
return handleError(error2, "Error generating from network");
|
|
3319
3320
|
}
|
|
3320
3321
|
}
|
|
3321
3322
|
async function streamGenerateHandler2(c2) {
|
|
@@ -3339,13 +3340,13 @@ async function streamGenerateHandler2(c2) {
|
|
|
3339
3340
|
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
3340
3341
|
sendUsage: true,
|
|
3341
3342
|
sendReasoning: true,
|
|
3342
|
-
getErrorMessage: (
|
|
3343
|
-
return `An error occurred while processing your request. ${
|
|
3343
|
+
getErrorMessage: (error2) => {
|
|
3344
|
+
return `An error occurred while processing your request. ${error2 instanceof Error ? error2.message : JSON.stringify(error2)}`;
|
|
3344
3345
|
}
|
|
3345
3346
|
});
|
|
3346
3347
|
return streamResponse;
|
|
3347
|
-
} catch (
|
|
3348
|
-
return handleError(
|
|
3348
|
+
} catch (error2) {
|
|
3349
|
+
return handleError(error2, "Error streaming from network");
|
|
3349
3350
|
}
|
|
3350
3351
|
}
|
|
3351
3352
|
async function generateSystemPromptHandler(c2) {
|
|
@@ -3381,8 +3382,8 @@ async function generateSystemPromptHandler(c2) {
|
|
|
3381
3382
|
|
|
3382
3383
|
`
|
|
3383
3384
|
).join("");
|
|
3384
|
-
} catch (
|
|
3385
|
-
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
3385
|
+
} catch (error2) {
|
|
3386
|
+
mastra.getLogger().error(`Error fetching evals`, { error: error2 });
|
|
3386
3387
|
}
|
|
3387
3388
|
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
3388
3389
|
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.
|
|
@@ -3453,8 +3454,8 @@ ${evalSummary}` : ""}
|
|
|
3453
3454
|
}
|
|
3454
3455
|
);
|
|
3455
3456
|
return c2.json(result?.object || {});
|
|
3456
|
-
} catch (
|
|
3457
|
-
return handleError(
|
|
3457
|
+
} catch (error2) {
|
|
3458
|
+
return handleError(error2, "Error generating system prompt");
|
|
3458
3459
|
}
|
|
3459
3460
|
}
|
|
3460
3461
|
|
|
@@ -3489,8 +3490,97 @@ async function getTelemetryHandler(c2) {
|
|
|
3489
3490
|
attributes
|
|
3490
3491
|
});
|
|
3491
3492
|
return c2.json({ traces });
|
|
3492
|
-
} catch (
|
|
3493
|
-
return handleError(
|
|
3493
|
+
} catch (error2) {
|
|
3494
|
+
return handleError(error2, "Error saving messages");
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
async function storeTelemetryHandler(c2) {
|
|
3498
|
+
try {
|
|
3499
|
+
const body = await c2.req.json();
|
|
3500
|
+
const mastra = c2.get("mastra");
|
|
3501
|
+
const storage = mastra.getStorage();
|
|
3502
|
+
const now = /* @__PURE__ */ new Date();
|
|
3503
|
+
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
3504
|
+
const allSpans = items.reduce((acc, scopedSpans) => {
|
|
3505
|
+
const { scope, spans } = scopedSpans;
|
|
3506
|
+
for (const span of spans) {
|
|
3507
|
+
const {
|
|
3508
|
+
spanId,
|
|
3509
|
+
parentSpanId,
|
|
3510
|
+
traceId,
|
|
3511
|
+
name,
|
|
3512
|
+
kind,
|
|
3513
|
+
attributes,
|
|
3514
|
+
status,
|
|
3515
|
+
events,
|
|
3516
|
+
links,
|
|
3517
|
+
startTimeUnixNano,
|
|
3518
|
+
endTimeUnixNano,
|
|
3519
|
+
...rest
|
|
3520
|
+
} = span;
|
|
3521
|
+
const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
|
|
3522
|
+
const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
|
|
3523
|
+
acc.push({
|
|
3524
|
+
id: spanId,
|
|
3525
|
+
parentSpanId,
|
|
3526
|
+
traceId,
|
|
3527
|
+
name,
|
|
3528
|
+
scope: scope.name,
|
|
3529
|
+
kind,
|
|
3530
|
+
status: JSON.stringify(status),
|
|
3531
|
+
events: JSON.stringify(events),
|
|
3532
|
+
links: JSON.stringify(links),
|
|
3533
|
+
attributes: JSON.stringify(
|
|
3534
|
+
attributes.reduce((acc2, attr) => {
|
|
3535
|
+
const valueKey = Object.keys(attr.value)[0];
|
|
3536
|
+
if (valueKey) {
|
|
3537
|
+
acc2[attr.key] = attr.value[valueKey];
|
|
3538
|
+
}
|
|
3539
|
+
return acc2;
|
|
3540
|
+
}, {})
|
|
3541
|
+
),
|
|
3542
|
+
startTime,
|
|
3543
|
+
endTime,
|
|
3544
|
+
other: JSON.stringify(rest),
|
|
3545
|
+
createdAt: now
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
return acc;
|
|
3549
|
+
}, []);
|
|
3550
|
+
return storage.__batchInsert({
|
|
3551
|
+
tableName: TABLE_TRACES,
|
|
3552
|
+
records: allSpans
|
|
3553
|
+
}).then(() => {
|
|
3554
|
+
return c2.json(
|
|
3555
|
+
{
|
|
3556
|
+
status: "success",
|
|
3557
|
+
message: "Traces received and processed successfully",
|
|
3558
|
+
traceCount: body.resourceSpans?.length || 0
|
|
3559
|
+
},
|
|
3560
|
+
200
|
|
3561
|
+
);
|
|
3562
|
+
}).catch((e2) => {
|
|
3563
|
+
return c2.json(
|
|
3564
|
+
{
|
|
3565
|
+
status: "error",
|
|
3566
|
+
message: "Failed to process traces",
|
|
3567
|
+
// @ts-ignore
|
|
3568
|
+
error: error.message
|
|
3569
|
+
},
|
|
3570
|
+
500
|
|
3571
|
+
);
|
|
3572
|
+
});
|
|
3573
|
+
} catch (error2) {
|
|
3574
|
+
console.error("Error processing traces:", error2);
|
|
3575
|
+
return c2.json(
|
|
3576
|
+
{
|
|
3577
|
+
status: "error",
|
|
3578
|
+
message: "Failed to process traces",
|
|
3579
|
+
// @ts-ignore
|
|
3580
|
+
error: error2.message
|
|
3581
|
+
},
|
|
3582
|
+
500
|
|
3583
|
+
);
|
|
3494
3584
|
}
|
|
3495
3585
|
}
|
|
3496
3586
|
async function getToolsHandler(c2) {
|
|
@@ -3512,8 +3602,8 @@ async function getToolsHandler(c2) {
|
|
|
3512
3602
|
{}
|
|
3513
3603
|
);
|
|
3514
3604
|
return c2.json(serializedTools);
|
|
3515
|
-
} catch (
|
|
3516
|
-
return handleError(
|
|
3605
|
+
} catch (error2) {
|
|
3606
|
+
return handleError(error2, "Error getting tools");
|
|
3517
3607
|
}
|
|
3518
3608
|
}
|
|
3519
3609
|
async function getToolByIdHandler(c2) {
|
|
@@ -3530,8 +3620,8 @@ async function getToolByIdHandler(c2) {
|
|
|
3530
3620
|
outputSchema: tool.outputSchema ? stringify(esm_default(tool.outputSchema)) : void 0
|
|
3531
3621
|
};
|
|
3532
3622
|
return c2.json(serializedTool);
|
|
3533
|
-
} catch (
|
|
3534
|
-
return handleError(
|
|
3623
|
+
} catch (error2) {
|
|
3624
|
+
return handleError(error2, "Error getting tool");
|
|
3535
3625
|
}
|
|
3536
3626
|
}
|
|
3537
3627
|
function executeToolHandler(tools) {
|
|
@@ -3557,8 +3647,8 @@ function executeToolHandler(tools) {
|
|
|
3557
3647
|
runId: mastra.runId
|
|
3558
3648
|
});
|
|
3559
3649
|
return c2.json(result);
|
|
3560
|
-
} catch (
|
|
3561
|
-
return handleError(
|
|
3650
|
+
} catch (error2) {
|
|
3651
|
+
return handleError(error2, "Error executing tool");
|
|
3562
3652
|
}
|
|
3563
3653
|
};
|
|
3564
3654
|
}
|
|
@@ -3586,8 +3676,8 @@ async function executeAgentToolHandler(c2) {
|
|
|
3586
3676
|
runId: agentId
|
|
3587
3677
|
});
|
|
3588
3678
|
return c2.json(result);
|
|
3589
|
-
} catch (
|
|
3590
|
-
return handleError(
|
|
3679
|
+
} catch (error2) {
|
|
3680
|
+
return handleError(error2, "Error executing tool");
|
|
3591
3681
|
}
|
|
3592
3682
|
}
|
|
3593
3683
|
var getVector = (c2, vectorName) => {
|
|
@@ -3607,8 +3697,8 @@ async function upsertVectors(c2) {
|
|
|
3607
3697
|
const vector = getVector(c2, vectorName);
|
|
3608
3698
|
const result = await vector.upsert({ indexName, vectors, metadata, ids });
|
|
3609
3699
|
return c2.json({ ids: result });
|
|
3610
|
-
} catch (
|
|
3611
|
-
return handleError(
|
|
3700
|
+
} catch (error2) {
|
|
3701
|
+
return handleError(error2, "Error upserting vectors");
|
|
3612
3702
|
}
|
|
3613
3703
|
}
|
|
3614
3704
|
async function createIndex(c2) {
|
|
@@ -3626,8 +3716,8 @@ async function createIndex(c2) {
|
|
|
3626
3716
|
const vector = getVector(c2, vectorName);
|
|
3627
3717
|
await vector.createIndex({ indexName, dimension, metric });
|
|
3628
3718
|
return c2.json({ success: true });
|
|
3629
|
-
} catch (
|
|
3630
|
-
return handleError(
|
|
3719
|
+
} catch (error2) {
|
|
3720
|
+
return handleError(error2, "Error creating index");
|
|
3631
3721
|
}
|
|
3632
3722
|
}
|
|
3633
3723
|
async function queryVectors(c2) {
|
|
@@ -3640,8 +3730,8 @@ async function queryVectors(c2) {
|
|
|
3640
3730
|
const vector = getVector(c2, vectorName);
|
|
3641
3731
|
const results = await vector.query({ indexName, queryVector, topK, filter, includeVector });
|
|
3642
3732
|
return c2.json({ results });
|
|
3643
|
-
} catch (
|
|
3644
|
-
return handleError(
|
|
3733
|
+
} catch (error2) {
|
|
3734
|
+
return handleError(error2, "Error querying vectors");
|
|
3645
3735
|
}
|
|
3646
3736
|
}
|
|
3647
3737
|
async function listIndexes(c2) {
|
|
@@ -3650,8 +3740,8 @@ async function listIndexes(c2) {
|
|
|
3650
3740
|
const vector = getVector(c2, vectorName);
|
|
3651
3741
|
const indexes = await vector.listIndexes();
|
|
3652
3742
|
return c2.json({ indexes: indexes.filter(Boolean) });
|
|
3653
|
-
} catch (
|
|
3654
|
-
return handleError(
|
|
3743
|
+
} catch (error2) {
|
|
3744
|
+
return handleError(error2, "Error listing indexes");
|
|
3655
3745
|
}
|
|
3656
3746
|
}
|
|
3657
3747
|
async function describeIndex(c2) {
|
|
@@ -3668,8 +3758,8 @@ async function describeIndex(c2) {
|
|
|
3668
3758
|
count: stats.count,
|
|
3669
3759
|
metric: stats.metric?.toLowerCase()
|
|
3670
3760
|
});
|
|
3671
|
-
} catch (
|
|
3672
|
-
return handleError(
|
|
3761
|
+
} catch (error2) {
|
|
3762
|
+
return handleError(error2, "Error describing index");
|
|
3673
3763
|
}
|
|
3674
3764
|
}
|
|
3675
3765
|
async function deleteIndex(c2) {
|
|
@@ -3682,8 +3772,8 @@ async function deleteIndex(c2) {
|
|
|
3682
3772
|
const vector = getVector(c2, vectorName);
|
|
3683
3773
|
await vector.deleteIndex(indexName);
|
|
3684
3774
|
return c2.json({ success: true });
|
|
3685
|
-
} catch (
|
|
3686
|
-
return handleError(
|
|
3775
|
+
} catch (error2) {
|
|
3776
|
+
return handleError(error2, "Error deleting index");
|
|
3687
3777
|
}
|
|
3688
3778
|
}
|
|
3689
3779
|
async function getSpeakersHandler(c2) {
|
|
@@ -3699,8 +3789,8 @@ async function getSpeakersHandler(c2) {
|
|
|
3699
3789
|
}
|
|
3700
3790
|
const speakers = await agent.getSpeakers();
|
|
3701
3791
|
return c2.json(speakers);
|
|
3702
|
-
} catch (
|
|
3703
|
-
return handleError(
|
|
3792
|
+
} catch (error2) {
|
|
3793
|
+
return handleError(error2, "Error getting speakers");
|
|
3704
3794
|
}
|
|
3705
3795
|
}
|
|
3706
3796
|
async function speakHandler(c2) {
|
|
@@ -3720,8 +3810,8 @@ async function speakHandler(c2) {
|
|
|
3720
3810
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3721
3811
|
c2.header("Transfer-Encoding", "chunked");
|
|
3722
3812
|
return c2.body(audioStream);
|
|
3723
|
-
} catch (
|
|
3724
|
-
return handleError(
|
|
3813
|
+
} catch (error2) {
|
|
3814
|
+
return handleError(error2, "Error generating speech");
|
|
3725
3815
|
}
|
|
3726
3816
|
}
|
|
3727
3817
|
async function listenHandler(c2) {
|
|
@@ -3749,16 +3839,16 @@ async function listenHandler(c2) {
|
|
|
3749
3839
|
let parsedOptions;
|
|
3750
3840
|
try {
|
|
3751
3841
|
parsedOptions = options ? JSON.parse(options) : {};
|
|
3752
|
-
} catch (
|
|
3753
|
-
if (
|
|
3754
|
-
logger2.error("Invalid JSON in options:",
|
|
3842
|
+
} catch (error2) {
|
|
3843
|
+
if (error2 instanceof SyntaxError) {
|
|
3844
|
+
logger2.error("Invalid JSON in options:", error2);
|
|
3755
3845
|
}
|
|
3756
3846
|
parsedOptions = {};
|
|
3757
3847
|
}
|
|
3758
3848
|
const transcription = await agent.voice.listen(audioStream, parsedOptions);
|
|
3759
3849
|
return c2.json({ text: transcription });
|
|
3760
|
-
} catch (
|
|
3761
|
-
return handleError(
|
|
3850
|
+
} catch (error2) {
|
|
3851
|
+
return handleError(error2, "Error transcribing speech");
|
|
3762
3852
|
}
|
|
3763
3853
|
}
|
|
3764
3854
|
async function getWorkflowsHandler(c2) {
|
|
@@ -3786,8 +3876,8 @@ async function getWorkflowsHandler(c2) {
|
|
|
3786
3876
|
return acc;
|
|
3787
3877
|
}, {});
|
|
3788
3878
|
return c2.json(_workflows);
|
|
3789
|
-
} catch (
|
|
3790
|
-
return handleError(
|
|
3879
|
+
} catch (error2) {
|
|
3880
|
+
return handleError(error2, "Error getting workflows");
|
|
3791
3881
|
}
|
|
3792
3882
|
}
|
|
3793
3883
|
async function getWorkflowByIdHandler(c2) {
|
|
@@ -3818,8 +3908,8 @@ async function getWorkflowByIdHandler(c2) {
|
|
|
3818
3908
|
serializedStepGraph,
|
|
3819
3909
|
serializedStepSubscriberGraph
|
|
3820
3910
|
});
|
|
3821
|
-
} catch (
|
|
3822
|
-
return handleError(
|
|
3911
|
+
} catch (error2) {
|
|
3912
|
+
return handleError(error2, "Error getting workflow");
|
|
3823
3913
|
}
|
|
3824
3914
|
}
|
|
3825
3915
|
async function startAsyncWorkflowHandler(c2) {
|
|
@@ -3840,8 +3930,8 @@ async function startAsyncWorkflowHandler(c2) {
|
|
|
3840
3930
|
triggerData: body
|
|
3841
3931
|
});
|
|
3842
3932
|
return c2.json(result);
|
|
3843
|
-
} catch (
|
|
3844
|
-
return handleError(
|
|
3933
|
+
} catch (error2) {
|
|
3934
|
+
return handleError(error2, "Error executing workflow");
|
|
3845
3935
|
}
|
|
3846
3936
|
}
|
|
3847
3937
|
async function createRunHandler(c2) {
|
|
@@ -3896,8 +3986,9 @@ async function watchWorkflowHandler(c2) {
|
|
|
3896
3986
|
c2,
|
|
3897
3987
|
async (stream) => {
|
|
3898
3988
|
return new Promise((_resolve, _reject) => {
|
|
3899
|
-
let unwatch = run.watch(({ activePaths,
|
|
3900
|
-
|
|
3989
|
+
let unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
|
|
3990
|
+
const activePathsObj = Object.fromEntries(activePaths);
|
|
3991
|
+
void stream.write(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }) + "");
|
|
3901
3992
|
});
|
|
3902
3993
|
stream.onAbort(() => {
|
|
3903
3994
|
unwatch?.();
|
|
@@ -3910,8 +4001,8 @@ async function watchWorkflowHandler(c2) {
|
|
|
3910
4001
|
await stream.close();
|
|
3911
4002
|
}
|
|
3912
4003
|
);
|
|
3913
|
-
} catch (
|
|
3914
|
-
return handleError(
|
|
4004
|
+
} catch (error2) {
|
|
4005
|
+
return handleError(error2, "Error watching workflow");
|
|
3915
4006
|
}
|
|
3916
4007
|
}
|
|
3917
4008
|
async function resumeAsyncWorkflowHandler(c2) {
|
|
@@ -3933,8 +4024,8 @@ async function resumeAsyncWorkflowHandler(c2) {
|
|
|
3933
4024
|
context
|
|
3934
4025
|
});
|
|
3935
4026
|
return c2.json(result);
|
|
3936
|
-
} catch (
|
|
3937
|
-
return handleError(
|
|
4027
|
+
} catch (error2) {
|
|
4028
|
+
return handleError(error2, "Error resuming workflow step");
|
|
3938
4029
|
}
|
|
3939
4030
|
}
|
|
3940
4031
|
async function resumeWorkflowHandler(c2) {
|
|
@@ -3956,8 +4047,8 @@ async function resumeWorkflowHandler(c2) {
|
|
|
3956
4047
|
context
|
|
3957
4048
|
});
|
|
3958
4049
|
return c2.json({ message: "Workflow run resumed" });
|
|
3959
|
-
} catch (
|
|
3960
|
-
return handleError(
|
|
4050
|
+
} catch (error2) {
|
|
4051
|
+
return handleError(error2, "Error resuming workflow");
|
|
3961
4052
|
}
|
|
3962
4053
|
}
|
|
3963
4054
|
|
|
@@ -4088,7 +4179,7 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4088
4179
|
cors({
|
|
4089
4180
|
origin: "*",
|
|
4090
4181
|
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
4091
|
-
allowHeaders: ["Content-Type", "Authorization"],
|
|
4182
|
+
allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type"],
|
|
4092
4183
|
exposeHeaders: ["Content-Length", "X-Requested-With"],
|
|
4093
4184
|
credentials: false,
|
|
4094
4185
|
maxAge: 3600
|
|
@@ -4115,6 +4206,44 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4115
4206
|
// 4.5 MB,
|
|
4116
4207
|
onError: (c2) => c2.json({ error: "Request body too large" }, 413)
|
|
4117
4208
|
};
|
|
4209
|
+
const server = mastra.getServer();
|
|
4210
|
+
const routes = server?.apiRoutes;
|
|
4211
|
+
if (server?.middleware) {
|
|
4212
|
+
const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
|
|
4213
|
+
const middlewares = normalizedMiddlewares.map((middleware2) => {
|
|
4214
|
+
if (typeof middleware2 === "function") {
|
|
4215
|
+
return {
|
|
4216
|
+
path: "*",
|
|
4217
|
+
handler: middleware2
|
|
4218
|
+
};
|
|
4219
|
+
}
|
|
4220
|
+
return middleware2;
|
|
4221
|
+
});
|
|
4222
|
+
for (const middleware2 of middlewares) {
|
|
4223
|
+
app.use(middleware2.path, middleware2.handler);
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
if (routes) {
|
|
4227
|
+
for (const route of routes) {
|
|
4228
|
+
const middlewares = [];
|
|
4229
|
+
if (route.middleware) {
|
|
4230
|
+
middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
|
|
4231
|
+
}
|
|
4232
|
+
if (route.openapi) {
|
|
4233
|
+
middlewares.push(h(route.openapi));
|
|
4234
|
+
}
|
|
4235
|
+
console.log({ path: route.path, middlewares });
|
|
4236
|
+
if (route.method === "GET") {
|
|
4237
|
+
app.get(route.path, ...middlewares, route.handler);
|
|
4238
|
+
} else if (route.method === "POST") {
|
|
4239
|
+
app.post(route.path, ...middlewares, route.handler);
|
|
4240
|
+
} else if (route.method === "PUT") {
|
|
4241
|
+
app.put(route.path, ...middlewares, route.handler);
|
|
4242
|
+
} else if (route.method === "DELETE") {
|
|
4243
|
+
app.delete(route.path, ...middlewares, route.handler);
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4118
4247
|
app.get(
|
|
4119
4248
|
"/api",
|
|
4120
4249
|
h({
|
|
@@ -5236,6 +5365,19 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5236
5365
|
}),
|
|
5237
5366
|
getTelemetryHandler
|
|
5238
5367
|
);
|
|
5368
|
+
app.post(
|
|
5369
|
+
"/api/telemetry",
|
|
5370
|
+
h({
|
|
5371
|
+
description: "Store telemetry",
|
|
5372
|
+
tags: ["telemetry"],
|
|
5373
|
+
responses: {
|
|
5374
|
+
200: {
|
|
5375
|
+
description: "Traces stored"
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
}),
|
|
5379
|
+
storeTelemetryHandler
|
|
5380
|
+
);
|
|
5239
5381
|
app.get(
|
|
5240
5382
|
"/api/workflows",
|
|
5241
5383
|
h({
|