@mastra/inngest 1.10.6 → 1.10.7-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/connect.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-DUdnLJZo.cjs");
2
+ const require_src = require("./src-DHttGs_P.cjs");
3
3
  exports.connect = require_src.connect;
package/dist/connect.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as connect } from "./src-BUC2y-4a.js";
1
+ import { i as connect } from "./src-BprrWHph.js";
2
2
  export { connect };
@@ -1 +1 @@
1
- {"version":3,"file":"create-inngest-agentic-workflow.d.ts","sourceRoot":"","sources":["../../src/durable-agent/create-inngest-agentic-workflow.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAe,OAAO,EAAE,MAAM,SAAS,CAAC;AAIpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AA0CzD;;GAEG;AACH,MAAM,WAAW,oCAAoC;IACnD,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kGAAkG;IAClG,OAAO,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;CAC/C;AAyCD,oCAAoC;AACpC,eAAO,MAAM,qBAAqB;aAChC,iBAAiB;aACjB,YAAY;CACJ,CAAC;AAEX,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAsZhG"}
1
+ {"version":3,"file":"create-inngest-agentic-workflow.d.ts","sourceRoot":"","sources":["../../src/durable-agent/create-inngest-agentic-workflow.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAe,OAAO,EAAE,MAAM,SAAS,CAAC;AAIpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AA0CzD;;GAEG;AACH,MAAM,WAAW,oCAAoC;IACnD,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kGAAkG;IAClG,OAAO,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;CAC/C;AAyCD,oCAAoC;AACpC,eAAO,MAAM,qBAAqB;aAChC,iBAAiB;aACjB,YAAY;CACJ,CAAC;AAEX,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+ahG"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-DUdnLJZo.cjs");
2
+ const require_src = require("./src-DHttGs_P.cjs");
3
3
  exports.InngestExecutionEngine = require_src.InngestExecutionEngine;
4
4
  exports.InngestPubSub = require_src.InngestPubSub;
5
5
  exports.InngestRun = require_src.InngestRun;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as createServe, c as isInngestAgent, d as InngestRun, f as InngestPubSub, i as connect, l as createInngestDurableAgenticWorkflow, m as InngestExecutionEngine, n as init, o as serve, p as OVERSIZED_EVENT_CHUNK_TYPE, r as _compatibilityCheck, s as createInngestAgent, t as createStep, u as InngestWorkflow } from "./src-BUC2y-4a.js";
1
+ import { a as createServe, c as isInngestAgent, d as InngestRun, f as InngestPubSub, i as connect, l as createInngestDurableAgenticWorkflow, m as InngestExecutionEngine, n as init, o as serve, p as OVERSIZED_EVENT_CHUNK_TYPE, r as _compatibilityCheck, s as createInngestAgent, t as createStep, u as InngestWorkflow } from "./src-BprrWHph.js";
2
2
  export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, OVERSIZED_EVENT_CHUNK_TYPE, _compatibilityCheck, connect, createInngestAgent, createInngestDurableAgenticWorkflow, createServe, createStep, init, isInngestAgent, serve };
@@ -5,7 +5,7 @@ import { ProcessorRunner, ProcessorState, ProcessorStepOutputSchema, ProcessorSt
5
5
  import { toStandardSchema } from "@mastra/core/schema";
6
6
  import { Tool, createTool } from "@mastra/core/tools";
7
7
  import { DefaultExecutionEngine, Run, Workflow, createStepFromAgent, createStepFromTool, createTimeTravelExecutionParams, getEntryWorkflow, hydrateSerializedStepErrors, isSingleStepEntry } from "@mastra/core/workflows";
8
- import { AGENT_STREAM_TOPIC, DurableAgentDefaults, DurableStepIds, agentThreadStreamRuntime, baseIterationStateSchema, createBaseIterationStateUpdate, createDurableAgentStream, createDurableBackgroundTaskCheckStep, createDurableLLMExecutionStep, createDurableLLMMappingStep, createDurableToolCallStep, deleteRunRegistryEntry, durableAgenticOutputSchema, emitChunkEvent, emitErrorEvent, emitFinishEvent, executeDurableAgentScorers, getRunRegistryEntry, globalRunRegistry, loadRunStoredMessages, modelConfigSchema, modelListEntrySchema, prepareForDurableExecution, pruneAgentLoopSnapshot, publishAbortRequest, resolveDurableToolCallConcurrency, runDurableFinishSideEffects, runDurableStreamUntilIdle, runResumeDurableStreamUntilIdle } from "@mastra/core/agent/durable";
8
+ import { AGENT_STREAM_TOPIC, DURABLE_STOP_WHEN_ERROR_ID, DurableAgentDefaults, DurableStepIds, agentThreadStreamRuntime, baseIterationStateSchema, createBaseIterationStateUpdate, createDurableAgentStream, createDurableBackgroundTaskCheckStep, createDurableLLMExecutionStep, createDurableLLMMappingStep, createDurableToolCallStep, deleteRunRegistryEntry, durableAgenticOutputSchema, emitChunkEvent, emitErrorEvent, emitFinishEvent, executeDurableAgentScorers, getRunRegistryEntry, globalRunRegistry, loadRunStoredMessages, modelConfigSchema, modelListEntrySchema, prepareForDurableExecution, pruneAgentLoopSnapshot, publishAbortRequest, resolveDurableToolCallConcurrency, runDurableFinishSideEffects, runDurableStreamUntilIdle, runResumeDurableStreamUntilIdle } from "@mastra/core/agent/durable";
9
9
  import { RequestContext } from "@mastra/core/di";
10
10
  import { CachingPubSub, PubSub } from "@mastra/core/events";
11
11
  import { NonRetriableError } from "inngest";
@@ -1696,6 +1696,20 @@ var InngestRun = class extends Run {
1696
1696
  };
1697
1697
  //#endregion
1698
1698
  //#region src/workflow.ts
1699
+ function durableAgentWorkflowError(error) {
1700
+ const serialized = error;
1701
+ const isMarkedStopWhenError = serialized?.code === DURABLE_STOP_WHEN_ERROR_ID || serialized?.id === DURABLE_STOP_WHEN_ERROR_ID;
1702
+ const isStopWhenStepError = typeof serialized?.stepId === "string" && serialized.stepId.startsWith("stop-when-");
1703
+ if (isMarkedStopWhenError || isStopWhenStepError) {
1704
+ const normalized = new Error(typeof serialized.details?.message === "string" ? serialized.details.message : typeof serialized.cause?.message === "string" ? serialized.cause.message : typeof serialized.message === "string" ? serialized.message : "Workflow execution failed");
1705
+ normalized.name = typeof serialized.details?.name === "string" ? serialized.details.name : typeof serialized.cause?.name === "string" ? serialized.cause.name : typeof serialized.name === "string" ? serialized.name : "Error";
1706
+ return {
1707
+ error: normalized,
1708
+ delivery: "reject"
1709
+ };
1710
+ }
1711
+ return { error: getErrorFromUnknown(error, { fallbackMessage: "Workflow execution failed" }) };
1712
+ }
1699
1713
  /**
1700
1714
  * Resolves the nested `InngestWorkflow` wrapped by a graph entry, if any.
1701
1715
  * Handles both plain single-step entries and `loop` / `foreach` entries whose
@@ -2057,9 +2071,9 @@ var InngestWorkflow = class extends Workflow {
2057
2071
  */
2058
2072
  const finalizeWorkflow = async () => {
2059
2073
  if (result.status === "failed" && inputData?.__workflowKind === "durable-agent" && inputData?.runId) {
2060
- const error = getErrorFromUnknown(result.error, { fallbackMessage: "Workflow execution failed" });
2074
+ const { error, delivery } = durableAgentWorkflowError(result.error);
2061
2075
  try {
2062
- await emitErrorEvent(pubsub, inputData.runId, error);
2076
+ await emitErrorEvent(pubsub, inputData.runId, error, void 0, delivery);
2063
2077
  } catch (e) {
2064
2078
  this.logger.debug?.("Failed to emit error event:", e);
2065
2079
  }
@@ -2354,6 +2368,7 @@ function createInngestDurableAgenticWorkflow(options) {
2354
2368
  requestContextEntries: state.requestContextEntries,
2355
2369
  agentSpanData: state.agentSpanData,
2356
2370
  modelSpanData: state.modelSpanData,
2371
+ completionStartTime: state.completionStartTime,
2357
2372
  stepIndex: state.stepIndex,
2358
2373
  accumulatedSteps: state.accumulatedSteps
2359
2374
  };
@@ -2361,7 +2376,8 @@ function createInngestDurableAgenticWorkflow(options) {
2361
2376
  const llmOutput = inputData;
2362
2377
  return (llmOutput.toolCalls ?? []).map((toolCall) => ({
2363
2378
  ...toolCall,
2364
- stepSpanData: llmOutput.stepSpanData
2379
+ stepSpanData: llmOutput.stepSpanData,
2380
+ completionStartTime: llmOutput.completionStartTime
2365
2381
  }));
2366
2382
  }, { id: "extract-tool-calls" }).foreach(toolCallStep, { concurrency: ({ inputData, getInitData }) => {
2367
2383
  const state = getInitData();
@@ -2454,18 +2470,28 @@ function createInngestDurableAgenticWorkflow(options) {
2454
2470
  await emitStepFinish(false);
2455
2471
  return false;
2456
2472
  }
2457
- let stopped;
2458
- try {
2459
- stopped = await step.run(`stop-when-${state.runId}-${state.iterationCount}`, async () => {
2460
- const stopWhen = getRunRegistryEntry(state.runId, mastra)?.stopWhen;
2461
- if (!stopWhen || state.accumulatedSteps.length === 0) return false;
2462
- const steps = state.accumulatedSteps;
2463
- return (await Promise.all((Array.isArray(stopWhen) ? stopWhen : [stopWhen]).map((condition) => condition({ steps })))).some(Boolean);
2464
- });
2465
- } catch (error) {
2466
- await emitStepFinish(shouldContinue);
2467
- throw error;
2468
- }
2473
+ const stopped = await step.run(`stop-when-${state.runId}-${state.iterationCount}`, async () => {
2474
+ const stopWhen = getRunRegistryEntry(state.runId, mastra)?.stopWhen;
2475
+ if (!stopWhen || state.accumulatedSteps.length === 0) return false;
2476
+ const steps = state.accumulatedSteps;
2477
+ return (await Promise.all((Array.isArray(stopWhen) ? stopWhen : [stopWhen]).map(async (condition) => {
2478
+ try {
2479
+ return await condition({ steps });
2480
+ } catch (error) {
2481
+ const originalError = getErrorFromUnknown(error);
2482
+ throw new MastraError({
2483
+ id: DURABLE_STOP_WHEN_ERROR_ID,
2484
+ domain: ErrorDomain.AGENT,
2485
+ category: ErrorCategory.USER,
2486
+ text: originalError.message,
2487
+ details: {
2488
+ name: originalError.name,
2489
+ message: originalError.message
2490
+ }
2491
+ }, originalError);
2492
+ }
2493
+ }))).some(Boolean);
2494
+ });
2469
2495
  await emitStepFinish(!stopped);
2470
2496
  return !stopped;
2471
2497
  }).map(async (params) => {
@@ -2525,6 +2551,7 @@ function createInngestDurableAgenticWorkflow(options) {
2525
2551
  state: state.state
2526
2552
  };
2527
2553
  const observability = mastra?.observability?.getSelectedInstance({});
2554
+ const completionStartTime = state.completionStartTime ? new Date(state.completionStartTime) : void 0;
2528
2555
  if (state.modelSpanData) {
2529
2556
  const modelSpan = observability?.rebuildSpan(state.modelSpanData);
2530
2557
  const toolCalls = state.accumulatedSteps.flatMap((step) => (step.toolCalls ?? []).map((tc) => ({
@@ -2537,11 +2564,17 @@ function createInngestDurableAgenticWorkflow(options) {
2537
2564
  text: finalText,
2538
2565
  ...toolCalls.length ? { toolCalls } : {}
2539
2566
  },
2540
- attributes: { finishReason: state.lastStepResult?.reason || "stop" },
2567
+ attributes: {
2568
+ finishReason: state.lastStepResult?.reason || "stop",
2569
+ ...completionStartTime ? { completionStartTime } : {}
2570
+ },
2541
2571
  usage: state.accumulatedUsage
2542
2572
  });
2543
2573
  }
2544
- if (state.agentSpanData) (observability?.rebuildSpan(state.agentSpanData))?.end({ output: { text: finalText } });
2574
+ if (state.agentSpanData) (observability?.rebuildSpan(state.agentSpanData))?.end({
2575
+ output: { text: finalText },
2576
+ ...completionStartTime ? { attributes: { completionStartTime } } : {}
2577
+ });
2545
2578
  if (pubsub) await emitFinishEvent(pubsub, state.runId, {
2546
2579
  output: finalOutput.output,
2547
2580
  stepResult: finalOutput.stepResult
@@ -4137,4 +4170,4 @@ function init(inngest) {
4137
4170
  //#endregion
4138
4171
  export { createServe as a, isInngestAgent as c, InngestRun as d, InngestPubSub as f, connect as i, createInngestDurableAgenticWorkflow as l, InngestExecutionEngine as m, init as n, serve$1 as o, OVERSIZED_EVENT_CHUNK_TYPE as p, _compatibilityCheck as r, createInngestAgent as s, createStep as t, InngestWorkflow as u };
4139
4172
 
4140
- //# sourceMappingURL=src-BUC2y-4a.js.map
4173
+ //# sourceMappingURL=src-BprrWHph.js.map