@mastra/server 1.73.0-alpha.0 → 1.73.0
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/{a2a-rSyYjbA3.cjs → a2a-B6oAqhYI.cjs} +2 -2
- package/dist/a2a-B6oAqhYI.cjs.map +1 -0
- package/dist/{a2a-Dyd6lbnr.js → a2a-CfJMDEvo.js} +2 -2
- package/dist/a2a-CfJMDEvo.js.map +1 -0
- package/dist/{api-schema-manifest-azbFW2gh.cjs → api-schema-manifest-Blh5-4VH.cjs} +2 -2
- package/dist/{api-schema-manifest-azbFW2gh.cjs.map → api-schema-manifest-Blh5-4VH.cjs.map} +1 -1
- package/dist/{api-schema-manifest-btfn_x2G.js → api-schema-manifest-BmraF-WX.js} +2 -2
- package/dist/{api-schema-manifest-btfn_x2G.js.map → api-schema-manifest-BmraF-WX.js.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{routes-BqoNkLiT.js → routes-Boe1UThy.js} +2 -2
- package/dist/{routes-BqoNkLiT.js.map → routes-Boe1UThy.js.map} +1 -1
- package/dist/{routes-BaQVELB2.cjs → routes-CcjyQojv.cjs} +2 -2
- package/dist/{routes-BaQVELB2.cjs.map → routes-CcjyQojv.cjs.map} +1 -1
- package/dist/schema-e0VHpMt0-BS9KHnuT.cjs.map +1 -1
- package/dist/schema-e0VHpMt0-CvPvLS06.js.map +1 -1
- package/dist/server/handlers/a2a.cjs +1 -1
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-controller.cjs +66 -23
- package/dist/server/handlers/agent-controller.cjs.map +1 -1
- package/dist/server/handlers/agent-controller.d.ts +14 -0
- package/dist/server/handlers/agent-controller.d.ts.map +1 -1
- package/dist/server/handlers/agent-controller.js +66 -23
- package/dist/server/handlers/agent-controller.js.map +1 -1
- package/dist/server/handlers/agents.cjs +69 -34
- package/dist/server/handlers/agents.cjs.map +1 -1
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +70 -35
- package/dist/server/handlers/agents.js.map +1 -1
- package/dist/server/handlers/system.cjs +1 -1
- package/dist/server/handlers/system.js +1 -1
- package/dist/server/handlers.cjs +1 -1
- package/dist/server/handlers.js +1 -1
- package/dist/server/server-adapter/index.cjs +1 -1
- package/dist/server/server-adapter/index.js +1 -1
- package/package.json +9 -9
- package/dist/a2a-Dyd6lbnr.js.map +0 -1
- package/dist/a2a-rSyYjbA3.cjs.map +0 -1
|
@@ -125,35 +125,48 @@ function hasSuspendedToolCall(snapshot, toolCallId) {
|
|
|
125
125
|
};
|
|
126
126
|
return visit(snapshot.context);
|
|
127
127
|
}
|
|
128
|
+
const DURABLE_SNAPSHOT_WAIT_TIMEOUT_MS = 1e4;
|
|
129
|
+
const DURABLE_SNAPSHOT_WAIT_INTERVAL_MS = 25;
|
|
128
130
|
function getDurableLoopWorkflowName(agent) {
|
|
129
131
|
return agent.durableLoopWorkflowName ?? _mastra_core_agent_durable.DurableStepIds.AGENTIC_LOOP;
|
|
130
132
|
}
|
|
131
|
-
async function validateDurableToolCallAccess({ mastra, agent, runId, toolCallId, requestContext, threadId }) {
|
|
133
|
+
async function validateDurableToolCallAccess({ mastra, agent, runId, toolCallId, requestContext, threadId, abortSignal }) {
|
|
132
134
|
if (!(0, _mastra_core_agent.isDurableAgentLike)(agent)) return;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
if (!workflowRun) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different resource" });
|
|
138
|
-
let snapshot = workflowRun.snapshot;
|
|
139
|
-
if (typeof snapshot === "string") try {
|
|
140
|
-
snapshot = JSON.parse(snapshot);
|
|
141
|
-
} catch {
|
|
142
|
-
snapshot = void 0;
|
|
143
|
-
}
|
|
144
|
-
const input = snapshot?.context?.input;
|
|
145
|
-
const persistedResourceIds = new Set([
|
|
146
|
-
workflowRun.resourceId,
|
|
147
|
-
input?.state?.resourceId,
|
|
148
|
-
input?.messageListState?.memoryInfo?.resourceId,
|
|
149
|
-
input?.requestContextEntries?.[require_constants.MASTRA_RESOURCE_ID_KEY]
|
|
150
|
-
].filter((resourceId) => typeof resourceId === "string" && resourceId.length > 0));
|
|
135
|
+
const workflowsStore = await mastra.getStorage()?.getStore("workflows");
|
|
136
|
+
if (!workflowsStore) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different resource" });
|
|
137
|
+
const workflowName = getDurableLoopWorkflowName(agent);
|
|
151
138
|
const contextResourceId = require_utils$1.getContextResourceId(requestContext);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
139
|
+
const deadline = Date.now() + DURABLE_SNAPSHOT_WAIT_TIMEOUT_MS;
|
|
140
|
+
while (true) {
|
|
141
|
+
const workflowRun = await workflowsStore.getWorkflowRunById({
|
|
142
|
+
workflowName,
|
|
143
|
+
runId
|
|
144
|
+
});
|
|
145
|
+
let snapshot = workflowRun?.snapshot;
|
|
146
|
+
if (typeof snapshot === "string") try {
|
|
147
|
+
snapshot = JSON.parse(snapshot);
|
|
148
|
+
} catch {
|
|
149
|
+
snapshot = void 0;
|
|
150
|
+
}
|
|
151
|
+
const input = snapshot?.context?.input;
|
|
152
|
+
const persistedResourceIds = new Set([
|
|
153
|
+
workflowRun?.resourceId,
|
|
154
|
+
input?.state?.resourceId,
|
|
155
|
+
input?.messageListState?.memoryInfo?.resourceId,
|
|
156
|
+
input?.requestContextEntries?.[require_constants.MASTRA_RESOURCE_ID_KEY]
|
|
157
|
+
].filter((resourceId) => typeof resourceId === "string" && resourceId.length > 0));
|
|
158
|
+
const [persistedResourceId] = persistedResourceIds;
|
|
159
|
+
if (persistedResourceIds.size > 1 || contextResourceId && persistedResourceId && persistedResourceId !== contextResourceId) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different resource" });
|
|
160
|
+
const ready = !!workflowRun && !!snapshot && snapshot.status === "suspended" && (toolCallId === void 0 || hasSuspendedToolCall(snapshot, toolCallId));
|
|
161
|
+
if (ready || Date.now() >= deadline || abortSignal?.aborted) {
|
|
162
|
+
if (!workflowRun) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different resource" });
|
|
163
|
+
const persistedThreadId = input?.state?.threadId ?? input?.messageListState?.memoryInfo?.threadId;
|
|
164
|
+
if (threadId && persistedThreadId !== threadId) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different thread" });
|
|
165
|
+
if (!ready || input?.agentId !== agent.id) throw new require_http_exception.HTTPException(403, { message: "Access denied: tool call is not suspended on this durable run" });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
await new Promise((resolve) => setTimeout(resolve, DURABLE_SNAPSHOT_WAIT_INTERVAL_MS));
|
|
169
|
+
}
|
|
157
170
|
}
|
|
158
171
|
/**
|
|
159
172
|
* Providers whose apiKeyEnvVar entries are aliases for the same credential (any one
|
|
@@ -202,6 +215,24 @@ function schemaToJsonSchema(schema) {
|
|
|
202
215
|
if (!schema) return;
|
|
203
216
|
return require_schema_e0VHpMt0.standardSchemaToJSONSchema(require_schema_e0VHpMt0.toStandardSchema(schema), { target: "draft-2020-12" });
|
|
204
217
|
}
|
|
218
|
+
function getAgentModelRef(agentModel, llm) {
|
|
219
|
+
if (typeof agentModel === "string") {
|
|
220
|
+
const { provider, modelId } = (0, _mastra_core_llm.parseModelString)(agentModel);
|
|
221
|
+
return {
|
|
222
|
+
provider: provider ?? llm?.getProvider(),
|
|
223
|
+
modelId
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const model = llm?.getModel();
|
|
227
|
+
if (model instanceof _mastra_core_llm.ModelRouterLanguageModel && model.gatewayId !== "models.dev" && model.gatewayId !== model.provider) return {
|
|
228
|
+
provider: model.gatewayId,
|
|
229
|
+
modelId: `${model.provider}/${model.modelId}`
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
provider: llm?.getProvider(),
|
|
233
|
+
modelId: llm?.getModelId()
|
|
234
|
+
};
|
|
235
|
+
}
|
|
205
236
|
async function getSerializedAgentTools(tools, partial = false) {
|
|
206
237
|
return Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
207
238
|
const toolId = "id" in tool && typeof tool.id === "string" && tool.id.length > 0 ? tool.id : `tool-${key}`;
|
|
@@ -497,8 +528,7 @@ async function formatAgentList({ id, mastra, agent, requestContext, partial = fa
|
|
|
497
528
|
workspaceId,
|
|
498
529
|
inputProcessors: serializedInputProcessors,
|
|
499
530
|
outputProcessors: serializedOutputProcessors,
|
|
500
|
-
|
|
501
|
-
modelId: typeof agent.model === "string" ? (0, _mastra_core_llm.parseModelString)(agent.model).modelId : llm?.getModelId(),
|
|
531
|
+
...getAgentModelRef(agent.model, llm),
|
|
502
532
|
modelVersion: model?.specificationVersion,
|
|
503
533
|
supportsMemory,
|
|
504
534
|
defaultOptions,
|
|
@@ -727,8 +757,7 @@ async function formatAgent({ mastra, agent, requestContext, isStudio }) {
|
|
|
727
757
|
workspaceId,
|
|
728
758
|
inputProcessors: serializedInputProcessors,
|
|
729
759
|
outputProcessors: serializedOutputProcessors,
|
|
730
|
-
|
|
731
|
-
modelId: typeof agent.model === "string" ? (0, _mastra_core_llm.parseModelString)(agent.model).modelId : llm?.getModelId(),
|
|
760
|
+
...getAgentModelRef(agent.model, llm),
|
|
732
761
|
modelVersion: model?.specificationVersion,
|
|
733
762
|
supportsMemory,
|
|
734
763
|
modelList,
|
|
@@ -1824,7 +1853,8 @@ const APPROVE_TOOL_CALL_ROUTE = require_route_builder.createRoute({
|
|
|
1824
1853
|
agent,
|
|
1825
1854
|
runId: params.runId,
|
|
1826
1855
|
toolCallId: params.toolCallId,
|
|
1827
|
-
requestContext
|
|
1856
|
+
requestContext,
|
|
1857
|
+
abortSignal
|
|
1828
1858
|
});
|
|
1829
1859
|
return (await agent.approveToolCall({
|
|
1830
1860
|
...params,
|
|
@@ -1966,7 +1996,8 @@ const DECLINE_TOOL_CALL_ROUTE = require_route_builder.createRoute({
|
|
|
1966
1996
|
agent,
|
|
1967
1997
|
runId: params.runId,
|
|
1968
1998
|
toolCallId: params.toolCallId,
|
|
1969
|
-
requestContext
|
|
1999
|
+
requestContext,
|
|
2000
|
+
abortSignal
|
|
1970
2001
|
});
|
|
1971
2002
|
return (await agent.declineToolCall({
|
|
1972
2003
|
...params,
|
|
@@ -2035,7 +2066,8 @@ const RESUME_STREAM_ROUTE = require_route_builder.createRoute({
|
|
|
2035
2066
|
runId,
|
|
2036
2067
|
toolCallId,
|
|
2037
2068
|
requestContext: serverRequestContext,
|
|
2038
|
-
threadId: effectiveThreadId
|
|
2069
|
+
threadId: effectiveThreadId,
|
|
2070
|
+
abortSignal
|
|
2039
2071
|
});
|
|
2040
2072
|
await require_utils$1.validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
|
|
2041
2073
|
workflowName: "agentic-loop",
|
|
@@ -2155,7 +2187,8 @@ const RESUME_STREAM_UNTIL_IDLE_ROUTE = require_route_builder.createRoute({
|
|
|
2155
2187
|
runId,
|
|
2156
2188
|
toolCallId,
|
|
2157
2189
|
requestContext: serverRequestContext,
|
|
2158
|
-
threadId: effectiveThreadId
|
|
2190
|
+
threadId: effectiveThreadId,
|
|
2191
|
+
abortSignal
|
|
2159
2192
|
});
|
|
2160
2193
|
await require_utils$1.validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
|
|
2161
2194
|
workflowName: "agentic-loop",
|
|
@@ -2206,7 +2239,8 @@ const APPROVE_TOOL_CALL_GENERATE_ROUTE = require_route_builder.createRoute({
|
|
|
2206
2239
|
agent,
|
|
2207
2240
|
runId: params.runId,
|
|
2208
2241
|
toolCallId: params.toolCallId,
|
|
2209
|
-
requestContext
|
|
2242
|
+
requestContext,
|
|
2243
|
+
abortSignal
|
|
2210
2244
|
});
|
|
2211
2245
|
return await agent.approveToolCallGenerate({
|
|
2212
2246
|
...params,
|
|
@@ -2244,7 +2278,8 @@ const DECLINE_TOOL_CALL_GENERATE_ROUTE = require_route_builder.createRoute({
|
|
|
2244
2278
|
agent,
|
|
2245
2279
|
runId: params.runId,
|
|
2246
2280
|
toolCallId: params.toolCallId,
|
|
2247
|
-
requestContext
|
|
2281
|
+
requestContext,
|
|
2282
|
+
abortSignal
|
|
2248
2283
|
});
|
|
2249
2284
|
return await agent.declineToolCallGenerate({
|
|
2250
2285
|
...params,
|