@mastra/server 1.72.0-alpha.5 → 1.72.0-alpha.7

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.
@@ -128,7 +128,7 @@ function hasSuspendedToolCall(snapshot, toolCallId) {
128
128
  function getDurableLoopWorkflowName(agent) {
129
129
  return agent.durableLoopWorkflowName ?? _mastra_core_agent_durable.DurableStepIds.AGENTIC_LOOP;
130
130
  }
131
- async function validateDurableToolCallAccess({ mastra, agent, runId, toolCallId, requestContext }) {
131
+ async function validateDurableToolCallAccess({ mastra, agent, runId, toolCallId, requestContext, threadId }) {
132
132
  if (!(0, _mastra_core_agent.isDurableAgentLike)(agent)) return;
133
133
  const workflowRun = await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
134
134
  workflowName: getDurableLoopWorkflowName(agent),
@@ -151,7 +151,9 @@ async function validateDurableToolCallAccess({ mastra, agent, runId, toolCallId,
151
151
  const effectiveResourceId = require_utils$1.getEffectiveResourceId(requestContext, void 0);
152
152
  const [persistedResourceId] = persistedResourceIds;
153
153
  if (persistedResourceIds.size > 1 || persistedResourceId && persistedResourceId !== effectiveResourceId) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different resource" });
154
- if (!snapshot || snapshot.status !== "suspended" || input?.agentId !== agent.id || !hasSuspendedToolCall(snapshot, toolCallId)) throw new require_http_exception.HTTPException(403, { message: "Access denied: tool call is not suspended on this durable run" });
154
+ const persistedThreadId = input?.state?.threadId ?? input?.messageListState?.memoryInfo?.threadId;
155
+ if (threadId && persistedThreadId !== threadId) throw new require_http_exception.HTTPException(403, { message: "Access denied: durable run belongs to a different thread" });
156
+ if (!snapshot || snapshot.status !== "suspended" || input?.agentId !== agent.id || toolCallId !== void 0 && !hasSuspendedToolCall(snapshot, toolCallId)) throw new require_http_exception.HTTPException(403, { message: "Access denied: tool call is not suspended on this durable run" });
155
157
  }
156
158
  /**
157
159
  * Providers whose apiKeyEnvVar entries are aliases for the same credential (any one
@@ -1098,35 +1100,43 @@ async function buildProvidersList(mastra) {
1098
1100
  const blockExternalProviders = process.env.AUTO_BLOCK_EXTERNAL_PROVIDERS === "true" || process.env.AUTO_BLOCK_EXTERNAL_PROVIDERS === "1";
1099
1101
  const defaultGatewayIds = new Set(_mastra_core_llm.defaultGateways.map((gateway) => gateway.id));
1100
1102
  if (!blockExternalProviders) for (const [id, provider] of Object.entries(_mastra_core_llm.PROVIDER_REGISTRY)) allProviders[id] = provider;
1101
- if (mastra) {
1102
- const allGateways = mastra.listGateways();
1103
- if (allGateways) for (const gateway of Object.values(allGateways)) {
1104
- if (gateway.id === "models.dev") continue;
1105
- if (blockExternalProviders && defaultGatewayIds.has(gateway.id)) continue;
1106
- try {
1107
- const gatewayProviders = await gateway.fetchProviders();
1108
- for (const [providerId, config] of Object.entries(gatewayProviders)) {
1109
- const prefixedId = providerId === gateway.id ? gateway.id : `${gateway.id}/${providerId}`;
1110
- if (!(prefixedId in allProviders)) allProviders[prefixedId] = config;
1111
- }
1112
- } catch (error) {
1113
- console.warn(`Failed to fetch providers from gateway "${gateway.id}":`, error);
1103
+ const gateways = mastra ? Object.values(mastra.listGateways() ?? {}) : [];
1104
+ for (const gateway of gateways) {
1105
+ if (gateway.id === "models.dev") continue;
1106
+ if (blockExternalProviders && defaultGatewayIds.has(gateway.id)) continue;
1107
+ try {
1108
+ const gatewayProviders = await gateway.fetchProviders();
1109
+ for (const [providerId, config] of Object.entries(gatewayProviders)) {
1110
+ const prefixedId = providerId === gateway.id ? gateway.id : `${gateway.id}/${providerId}`;
1111
+ if (!(prefixedId in allProviders)) allProviders[prefixedId] = config;
1114
1112
  }
1113
+ } catch (error) {
1114
+ console.warn(`Failed to fetch providers from gateway "${gateway.id}":`, error);
1115
1115
  }
1116
1116
  }
1117
1117
  return Object.entries(allProviders).map(([id, provider]) => {
1118
1118
  return {
1119
1119
  id,
1120
1120
  name: provider.name,
1121
- label: provider.label || provider.name,
1122
- description: provider.description || "",
1121
+ label: readStringField(provider, "label") || provider.name,
1122
+ description: readStringField(provider, "description") || "",
1123
1123
  envVar: provider.apiKeyEnvVar,
1124
- connected: isProviderConnected(id, allProviders),
1124
+ connected: isProviderConnected(id, allProviders) || isClaimedByGateway(id, provider.models, gateways),
1125
1125
  docUrl: provider.docUrl,
1126
1126
  models: [...provider.models]
1127
1127
  };
1128
1128
  });
1129
1129
  }
1130
+ function isClaimedByGateway(providerId, models, gateways) {
1131
+ const [firstModel] = models;
1132
+ if (!firstModel) return false;
1133
+ const routerId = `${providerId}/${firstModel}`;
1134
+ return gateways.some((gateway) => gateway.shouldEnable?.() !== false && gateway.handlesModel?.(routerId) === true);
1135
+ }
1136
+ function readStringField(source, field) {
1137
+ const value = source[field];
1138
+ return typeof value === "string" ? value : void 0;
1139
+ }
1130
1140
  const GET_PROVIDERS_ROUTE = require_route_builder.createRoute({
1131
1141
  method: "GET",
1132
1142
  path: "/agents/providers",
@@ -2019,6 +2029,14 @@ const RESUME_STREAM_ROUTE = require_route_builder.createRoute({
2019
2029
  ...effectiveResourceId ? { resource: effectiveResourceId } : {},
2020
2030
  ...effectiveThreadId ? { thread: effectiveThreadId } : {}
2021
2031
  };
2032
+ await validateDurableToolCallAccess({
2033
+ mastra,
2034
+ agent,
2035
+ runId,
2036
+ toolCallId,
2037
+ requestContext: serverRequestContext,
2038
+ threadId: effectiveThreadId
2039
+ });
2022
2040
  await require_utils$1.validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
2023
2041
  workflowName: "agentic-loop",
2024
2042
  runId
@@ -2131,6 +2149,14 @@ const RESUME_STREAM_UNTIL_IDLE_ROUTE = require_route_builder.createRoute({
2131
2149
  ...effectiveResourceId ? { resource: effectiveResourceId } : {},
2132
2150
  ...effectiveThreadId ? { thread: effectiveThreadId } : {}
2133
2151
  };
2152
+ await validateDurableToolCallAccess({
2153
+ mastra,
2154
+ agent,
2155
+ runId,
2156
+ toolCallId,
2157
+ requestContext: serverRequestContext,
2158
+ threadId: effectiveThreadId
2159
+ });
2134
2160
  await require_utils$1.validateRunOwnership(await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
2135
2161
  workflowName: "agentic-loop",
2136
2162
  runId