@mastra/inngest 1.10.3 → 1.10.4-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-C_m1Tz7d.cjs");
2
+ const require_src = require("./src-CGrVAs0_.cjs");
3
3
  exports.connect = require_src.connect;
package/dist/connect.js CHANGED
@@ -1,2 +1,2 @@
1
- import { i as connect } from "./src-B3okURIT.js";
1
+ import { i as connect } from "./src-CoboLrh1.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":"AA2BA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAwCzD;;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;AAuCD,oCAAoC;AACpC,eAAO,MAAM,qBAAqB;aAChC,iBAAiB;aACjB,YAAY;CACJ,CAAC;AAEX,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA8UhG"}
1
+ {"version":3,"file":"create-inngest-agentic-workflow.d.ts","sourceRoot":"","sources":["../../src/durable-agent/create-inngest-agentic-workflow.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAe,OAAO,EAAE,MAAM,SAAS,CAAC;AAIpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAwCzD;;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;AAuCD,oCAAoC;AACpC,eAAO,MAAM,qBAAqB;aAChC,iBAAiB;aACjB,YAAY;CACJ,CAAC;AAEX,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAkXhG"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-C_m1Tz7d.cjs");
2
+ const require_src = require("./src-CGrVAs0_.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, n as init, o as serve, p as InngestExecutionEngine, r as _compatibilityCheck, s as createInngestAgent, t as createStep, u as InngestWorkflow } from "./src-B3okURIT.js";
1
+ import { a as createServe, c as isInngestAgent, d as InngestRun, f as InngestPubSub, i as connect, l as createInngestDurableAgenticWorkflow, n as init, o as serve, p as InngestExecutionEngine, r as _compatibilityCheck, s as createInngestAgent, t as createStep, u as InngestWorkflow } from "./src-CoboLrh1.js";
2
2
  export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, _compatibilityCheck, connect, createInngestAgent, createInngestDurableAgenticWorkflow, createServe, createStep, init, isInngestAgent, serve };
@@ -1949,30 +1949,34 @@ var InngestWorkflow = class extends _mastra_core_workflows.Workflow {
1949
1949
  workflowName: this.id,
1950
1950
  runId
1951
1951
  }) ?? void 0;
1952
+ const finalSnapshot = {
1953
+ runId,
1954
+ status: result.status,
1955
+ value: result.state ?? initialState ?? {},
1956
+ context: toSnapshotContext(result.steps),
1957
+ activePaths: [],
1958
+ activeStepsPath: {},
1959
+ serializedStepGraph: this.serializedStepGraph,
1960
+ suspendedPaths: existingSnapshot?.suspendedPaths ?? {},
1961
+ waitingPaths: {},
1962
+ resumeLabels: existingSnapshot?.resumeLabels ?? result.resumeLabels ?? {},
1963
+ result: result.status === "success" ? toSnapshotResult(result.result) : void 0,
1964
+ error: result.status === "failed" ? result.error : void 0,
1965
+ requestContext: requestContext.toJSON(),
1966
+ tracingContext: workflowSpanData ? {
1967
+ traceId: workflowSpanData.traceId,
1968
+ spanId: workflowSpanData.id
1969
+ } : void 0,
1970
+ timestamp: Date.now()
1971
+ };
1952
1972
  await workflowsStore.persistWorkflowSnapshot({
1953
1973
  workflowName: this.id,
1954
1974
  runId,
1955
1975
  resourceId,
1956
- snapshot: {
1957
- runId,
1958
- status: result.status,
1959
- value: result.state ?? initialState ?? {},
1960
- context: toSnapshotContext(result.steps),
1961
- activePaths: [],
1962
- activeStepsPath: {},
1963
- serializedStepGraph: this.serializedStepGraph,
1964
- suspendedPaths: existingSnapshot?.suspendedPaths ?? {},
1965
- waitingPaths: {},
1966
- resumeLabels: existingSnapshot?.resumeLabels ?? result.resumeLabels ?? {},
1967
- result: result.status === "success" ? toSnapshotResult(result.result) : void 0,
1968
- error: result.status === "failed" ? result.error : void 0,
1969
- requestContext: requestContext.toJSON(),
1970
- tracingContext: workflowSpanData ? {
1971
- traceId: workflowSpanData.traceId,
1972
- spanId: workflowSpanData.id
1973
- } : void 0,
1974
- timestamp: Date.now()
1975
- }
1976
+ snapshot: this.options.pruneSnapshot ? this.options.pruneSnapshot({
1977
+ snapshot: finalSnapshot,
1978
+ workflowStatus: result.status
1979
+ }) : finalSnapshot
1976
1980
  });
1977
1981
  }
1978
1982
  }
@@ -2126,6 +2130,7 @@ function createInngestDurableAgenticWorkflow(options) {
2126
2130
  options: {
2127
2131
  tracingPolicy: { internal: _mastra_core_observability.InternalSpans.WORKFLOW },
2128
2132
  shouldPersistSnapshot: ({ workflowStatus }) => PERSISTED_SNAPSHOT_STATUSES.has(workflowStatus),
2133
+ pruneSnapshot: _mastra_core_agent_durable.pruneAgentLoopSnapshot,
2129
2134
  evaluatePersistencePredicateBeforeDurableOperation: true,
2130
2135
  validateInputs: false,
2131
2136
  emitStepEvents: false
@@ -2195,6 +2200,7 @@ function createInngestDurableAgenticWorkflow(options) {
2195
2200
  options: {
2196
2201
  tracingPolicy: { internal: _mastra_core_observability.InternalSpans.WORKFLOW },
2197
2202
  shouldPersistSnapshot: ({ workflowStatus }) => PERSISTED_SNAPSHOT_STATUSES.has(workflowStatus),
2203
+ pruneSnapshot: _mastra_core_agent_durable.pruneAgentLoopSnapshot,
2198
2204
  evaluatePersistencePredicateBeforeDurableOperation: true,
2199
2205
  validateInputs: false,
2200
2206
  emitStepEvents: false
@@ -2218,13 +2224,20 @@ function createInngestDurableAgenticWorkflow(options) {
2218
2224
  modelSpanData,
2219
2225
  stepIndex: input.stepIndex ?? 0
2220
2226
  };
2221
- }, { id: "init-iteration-state" }).dowhile(singleIterationWorkflow, async ({ inputData }) => {
2227
+ }, { id: "init-iteration-state" }).dowhile(singleIterationWorkflow, async ({ inputData, engine }) => {
2222
2228
  const state = inputData;
2223
2229
  if (state.delegationBailed) return false;
2224
2230
  const shouldContinue = state.lastStepResult?.isContinued === true;
2225
2231
  const effectiveMaxSteps = state.options?.maxSteps ?? maxSteps;
2226
2232
  const underMaxSteps = state.iterationCount < effectiveMaxSteps;
2227
- return shouldContinue && underMaxSteps;
2233
+ if (!shouldContinue || !underMaxSteps) return false;
2234
+ const { step } = engine;
2235
+ return !await step.run(`stop-when-${state.runId}-${state.iterationCount}`, async () => {
2236
+ const stopWhen = _mastra_core_agent_durable.globalRunRegistry.get(state.runId)?.stopWhen;
2237
+ if (!stopWhen || state.accumulatedSteps.length === 0) return false;
2238
+ const steps = state.accumulatedSteps;
2239
+ return (await Promise.all((Array.isArray(stopWhen) ? stopWhen : [stopWhen]).map((condition) => condition({ steps })))).some(Boolean);
2240
+ });
2228
2241
  }).map(async (params) => {
2229
2242
  const { inputData, mastra, requestContext, tracingContext } = params;
2230
2243
  const state = inputData;
@@ -2251,10 +2264,21 @@ function createInngestDurableAgenticWorkflow(options) {
2251
2264
  lastStep.text = finishResult.outputText;
2252
2265
  finalText = finishResult.outputText;
2253
2266
  }
2267
+ const tripwire = finishResult.tripwire;
2268
+ if (tripwire && pubsub) await (0, _mastra_core_agent_durable.emitChunkEvent)(pubsub, state.runId, {
2269
+ type: "tripwire",
2270
+ runId: state.runId,
2271
+ from: _mastra_core_stream.ChunkFrom.AGENT,
2272
+ payload: tripwire
2273
+ });
2254
2274
  const finalOutput = {
2255
2275
  messageListState: finishResult.messageListState,
2256
2276
  messageId: state.messageId,
2257
- stepResult: state.lastStepResult || {
2277
+ stepResult: tripwire ? {
2278
+ ...state.lastStepResult ?? { warnings: [] },
2279
+ reason: "tripwire",
2280
+ isContinued: false
2281
+ } : state.lastStepResult || {
2258
2282
  reason: "stop",
2259
2283
  warnings: [],
2260
2284
  isContinued: false
@@ -3887,4 +3911,4 @@ Object.defineProperty(exports, "serve", {
3887
3911
  }
3888
3912
  });
3889
3913
 
3890
- //# sourceMappingURL=src-C_m1Tz7d.cjs.map
3914
+ //# sourceMappingURL=src-CGrVAs0_.cjs.map