@mastra/inngest 1.10.2-alpha.0 → 1.10.2

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.
@@ -16,6 +16,7 @@ import { ChunkFrom, WorkflowRunOutput } from "@mastra/core/stream";
16
16
  import { MASTRA_AUTH_TOKEN_KEY } from "@mastra/core/request-context";
17
17
  import { serve } from "inngest/hono";
18
18
  import { InMemoryServerCache } from "@mastra/core/cache";
19
+ import { deepMerge } from "@mastra/core/utils";
19
20
  import { PUBSUB_SYMBOL } from "@mastra/core/workflows/_constants";
20
21
  import { z } from "zod";
21
22
  //#region src/nested-workflow-output.ts
@@ -488,7 +489,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
488
489
  runId = globalThis.crypto.randomUUID();
489
490
  result = {
490
491
  status: "failed",
491
- error: e instanceof Error ? e : new Error(String(e))
492
+ error: getErrorFromUnknown(e, {
493
+ serializeStack: true,
494
+ fallbackMessage: "Nested workflow failed"
495
+ })
492
496
  };
493
497
  }
494
498
  }
@@ -1284,8 +1288,7 @@ var InngestRun = class extends Run {
1284
1288
  snapshotForRollback = pendingSnapshot;
1285
1289
  }
1286
1290
  if (snapshot?.status === "running") throw new Error("This workflow run is still running, cannot time travel");
1287
- let inputDataToUse = params.inputData;
1288
- if (inputDataToUse && steps.length === 1) inputDataToUse = await this._validateTimetravelInputData(params.inputData, this.workflowSteps[steps[0]]);
1291
+ const inputDataToUse = await this._resolveTimetravelInputData(params.inputData, steps);
1289
1292
  const timeTravelData = createTimeTravelExecutionParams({
1290
1293
  steps,
1291
1294
  inputData: inputDataToUse,
@@ -2934,6 +2937,82 @@ function createInngestAgent(options) {
2934
2937
  ...reason !== void 0 ? { reason } : {}
2935
2938
  }, resumeOptions);
2936
2939
  },
2940
+ async sendToolApproval(options) {
2941
+ const { threadId, resourceId, approved, resumeData: customResumeData, declineContext, messages, streamOptions, ...executionOptions } = options;
2942
+ if (messages && approved) {
2943
+ const continuation = agentThreadStreamRuntime.continueWithMessages(proxyRef, messages, {
2944
+ resourceId,
2945
+ threadId,
2946
+ runId: executionOptions.runId,
2947
+ streamOptions: deepMerge(streamOptions ?? {}, executionOptions)
2948
+ }, agent.getPubSub());
2949
+ return {
2950
+ accepted: continuation.accepted,
2951
+ runId: continuation.runId,
2952
+ toolCallId: options.toolCallId
2953
+ };
2954
+ }
2955
+ let runId = executionOptions.runId ?? agent.getActiveThreadRunId({
2956
+ threadId,
2957
+ resourceId
2958
+ });
2959
+ if (!runId) {
2960
+ let runs = [];
2961
+ try {
2962
+ ({runs} = await agent.listSuspendedRuns({
2963
+ threadId,
2964
+ resourceId
2965
+ }));
2966
+ } catch (error) {
2967
+ if (!(error instanceof MastraError) || error.id !== "AGENT_LIST_SUSPENDED_RUNS_NO_STORAGE") throw error;
2968
+ }
2969
+ const matchingRuns = options.toolCallId ? runs.filter((run) => run.toolCalls.some((toolCall) => toolCall.toolCallId === options.toolCallId)) : runs;
2970
+ if (matchingRuns.length > 1) throw new MastraError({
2971
+ id: "AGENT_SEND_TOOL_APPROVAL_AMBIGUOUS_SUSPENDED_RUNS",
2972
+ domain: ErrorDomain.AGENT,
2973
+ category: ErrorCategory.USER,
2974
+ text: `Agent "${agent.name}" sendToolApproval() found ${matchingRuns.length} suspended runs for thread "${threadId}". Pass a toolCallId to disambiguate, or resume a specific run with approveToolCall()/declineToolCall() and an explicit runId.`,
2975
+ details: {
2976
+ threadId,
2977
+ resourceId,
2978
+ agentName: agent.name,
2979
+ runIds: matchingRuns.map((run) => run.runId).join(", ")
2980
+ }
2981
+ });
2982
+ runId = matchingRuns[0]?.runId;
2983
+ }
2984
+ if (!runId) throw new MastraError({
2985
+ id: "AGENT_SEND_TOOL_APPROVAL_NO_ACTIVE_THREAD_RUN",
2986
+ domain: ErrorDomain.AGENT,
2987
+ category: ErrorCategory.USER,
2988
+ text: `Agent "${agent.name}" sendToolApproval() could not find an active or suspended run for thread "${threadId}". The run may have already completed or been resumed.`,
2989
+ details: {
2990
+ threadId,
2991
+ resourceId,
2992
+ agentName: agent.name
2993
+ }
2994
+ });
2995
+ const resumeData = customResumeData !== void 0 ? customResumeData : approved ? { approved } : {
2996
+ approved,
2997
+ ...declineContext ?? {}
2998
+ };
2999
+ const resumeOptions = deepMerge(streamOptions ?? {}, executionOptions);
3000
+ await proxyRef.resumeStream(resumeData, {
3001
+ ...resumeOptions,
3002
+ runId,
3003
+ ...options.toolCallId ? { toolCallId: options.toolCallId } : {},
3004
+ memory: {
3005
+ ...resumeOptions.memory ?? {},
3006
+ thread: resumeOptions.memory?.thread ?? threadId,
3007
+ resource: resumeOptions.memory?.resource ?? resourceId
3008
+ }
3009
+ });
3010
+ return {
3011
+ accepted: true,
3012
+ runId,
3013
+ toolCallId: options.toolCallId
3014
+ };
3015
+ },
2937
3016
  async approveToolCallGenerate(options) {
2938
3017
  const { runId, ...resumeOptions } = options;
2939
3018
  if (!runId) throw new Error("approveToolCallGenerate() on InngestAgent requires a runId.");
@@ -3640,4 +3719,4 @@ function init(inngest) {
3640
3719
  //#endregion
3641
3720
  export { createServe as a, isInngestAgent as c, InngestRun as d, InngestPubSub as f, connect as i, createInngestDurableAgenticWorkflow as l, init as n, serve$1 as o, InngestExecutionEngine as p, _compatibilityCheck as r, createInngestAgent as s, createStep as t, InngestWorkflow as u };
3642
3721
 
3643
- //# sourceMappingURL=src-Cc6OY9_U.js.map
3722
+ //# sourceMappingURL=src-D3sbOdZM.js.map