@mastra/inngest 1.10.5 → 1.10.6

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.
@@ -2561,6 +2561,40 @@ function createInngestDurableAgenticWorkflow(options) {
2561
2561
  }, { id: "execute-scorers" }).commit();
2562
2562
  }
2563
2563
  //#endregion
2564
+ //#region src/durable-agent/resume-scopes.ts
2565
+ const SCOPES_KEY = "mastra__scopes";
2566
+ /**
2567
+ * A resumed run keeps the scopes it started with. Scopes re-supplied on resume (request
2568
+ * context or `scopes` option) may only repeat scopes the suspended run held, or name its own
2569
+ * resource and thread; anything else throws. The resumed run then acts with the saved set.
2570
+ * Post-upgrade runs persist their set unconditionally ([] included), so an ABSENT saved set
2571
+ * marks a pre-upgrade snapshot: the resume adopts the supplied scopes instead of rejecting
2572
+ * them, matching core's resume semantics.
2573
+ */
2574
+ function keepSuspendedRunScopes(snapshot, requestContext, resumeOptions) {
2575
+ const saved = snapshot?.requestContext?.[SCOPES_KEY];
2576
+ const fromContext = resumeOptions?.requestContext?.get(SCOPES_KEY);
2577
+ const supplied = [...Array.isArray(fromContext) ? fromContext : [], ...Array.isArray(resumeOptions?.scopes) ? resumeOptions.scopes : []];
2578
+ if (!Array.isArray(saved)) return;
2579
+ const held = new Set(Array.isArray(saved) ? saved : []);
2580
+ const memoryInfo = snapshot?.context?.input?.messageListState?.memoryInfo;
2581
+ for (const scope of supplied) {
2582
+ if (held.has(scope)) continue;
2583
+ const separator = typeof scope === "string" ? scope.indexOf(":") : -1;
2584
+ const type = separator > 0 ? scope.slice(0, separator) : void 0;
2585
+ const value = separator > 0 ? scope.slice(separator + 1) : void 0;
2586
+ if (type === "resource" && value === memoryInfo?.resourceId || type === "thread" && value === memoryInfo?.threadId) continue;
2587
+ throw new _mastra_core_error.MastraError({
2588
+ id: "AGENT_SCOPES_CONFLICT",
2589
+ domain: _mastra_core_error.ErrorDomain.AGENT,
2590
+ category: _mastra_core_error.ErrorCategory.USER,
2591
+ text: `Agent scope "${String(scope)}" was not part of the suspended run's scopes. A resumed run keeps the scopes it started with.`,
2592
+ details: { status: 400 }
2593
+ });
2594
+ }
2595
+ requestContext[SCOPES_KEY] = saved;
2596
+ }
2597
+ //#endregion
2564
2598
  //#region src/durable-agent/create-inngest-agent.ts
2565
2599
  var InngestAgentPubSubRouter = class extends _mastra_core_events.PubSub {
2566
2600
  defaultPubsub;
@@ -2815,6 +2849,7 @@ function createInngestAgent(options) {
2815
2849
  messages,
2816
2850
  options: callbackOptions,
2817
2851
  optionsAreResolved: true,
2852
+ callScopes: streamOptions?.scopes,
2818
2853
  runId: streamOptions?.runId,
2819
2854
  requestContext: streamOptions?.requestContext,
2820
2855
  methodType: streamOptions?.__methodType ?? "stream",
@@ -3039,6 +3074,12 @@ function createInngestAgent(options) {
3039
3074
  steps = suspendedStepIds[0] ? expandToLeafPath(suspendedStepIds[0]) : [];
3040
3075
  }
3041
3076
  const requestContext = mergeResumeRequestContext(snapshot?.requestContext, resumeOptions?.requestContext);
3077
+ try {
3078
+ keepSuspendedRunScopes(snapshot, requestContext, resumeOptions);
3079
+ } catch (error) {
3080
+ notResumable = true;
3081
+ throw error;
3082
+ }
3042
3083
  const tracingOptions = snapshot?.tracingContext ? {
3043
3084
  traceId: snapshot.tracingContext.traceId,
3044
3085
  parentSpanId: snapshot.tracingContext.spanId
@@ -4179,4 +4220,4 @@ Object.defineProperty(exports, "serve", {
4179
4220
  }
4180
4221
  });
4181
4222
 
4182
- //# sourceMappingURL=src-DotczbYI.cjs.map
4223
+ //# sourceMappingURL=src-DUdnLJZo.cjs.map