@mastra/inngest 1.0.0-beta.11 → 1.0.0-beta.13

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/index.js CHANGED
@@ -1,4 +1,7 @@
1
- import { Agent } from '@mastra/core/agent';
1
+ import { MessageList, Agent, TripWire } from '@mastra/core/agent';
2
+ import { getErrorFromUnknown, MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';
3
+ import { EntityType, SpanType } from '@mastra/core/observability';
4
+ import { ProcessorStepOutputSchema, ProcessorStepSchema, ProcessorRunner } from '@mastra/core/processors';
2
5
  import { Tool } from '@mastra/core/tools';
3
6
  import { DefaultExecutionEngine, createTimeTravelExecutionParams, Run, hydrateSerializedStepErrors, Workflow } from '@mastra/core/workflows';
4
7
  import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
@@ -6,7 +9,6 @@ import { z } from 'zod';
6
9
  import { randomUUID } from 'crypto';
7
10
  import { RequestContext } from '@mastra/core/di';
8
11
  import { NonRetriableError } from 'inngest';
9
- import { getErrorFromUnknown } from '@mastra/core/error';
10
12
  import { subscribe } from '@inngest/realtime';
11
13
  import { PubSub } from '@mastra/core/events';
12
14
  import { ReadableStream } from 'stream/web';
@@ -114,15 +116,32 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
114
116
  }
115
117
  /**
116
118
  * Wrap durable operations in Inngest step.run() for durability.
117
- * If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
118
- * Inngest's step-level retry mechanism (not function-level retry).
119
+ *
120
+ * IMPORTANT: Errors are wrapped with a cause structure before throwing.
121
+ * This is necessary because Inngest's error serialization (serialize-error-cjs)
122
+ * only captures standard Error properties (message, name, stack, code, cause).
123
+ * Custom properties like statusCode, responseHeaders from AI SDK errors would
124
+ * be lost. By putting our serialized error (via getErrorFromUnknown with toJSON())
125
+ * in the cause property, we ensure custom properties survive serialization.
126
+ * The cause property is in serialize-error-cjs's allowlist, and when the cause
127
+ * object is finally JSON.stringify'd, our error's toJSON() is called.
119
128
  */
120
129
  async wrapDurableOperation(operationId, operationFn) {
121
130
  return this.inngestStep.run(operationId, async () => {
122
131
  try {
123
132
  return await operationFn();
124
133
  } catch (e) {
125
- throw e;
134
+ const errorInstance = getErrorFromUnknown(e, {
135
+ serializeStack: false,
136
+ fallbackMessage: "Unknown step execution error"
137
+ });
138
+ throw new Error(errorInstance.message, {
139
+ cause: {
140
+ status: "failed",
141
+ error: errorInstance,
142
+ endedAt: Date.now()
143
+ }
144
+ });
126
145
  }
127
146
  });
128
147
  }
@@ -144,6 +163,96 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
144
163
  async invokeLifecycleCallbacksInternal(result) {
145
164
  return super.invokeLifecycleCallbacks(result);
146
165
  }
166
+ // =============================================================================
167
+ // Durable Span Lifecycle Hooks
168
+ // =============================================================================
169
+ /**
170
+ * Create a step span durably - on first execution, creates and exports span.
171
+ * On replay, returns cached span data without re-creating.
172
+ */
173
+ async createStepSpan(params) {
174
+ const { executionContext, operationId, options, parentSpan } = params;
175
+ const parentSpanId = parentSpan?.id ?? executionContext.tracingIds?.workflowSpanId;
176
+ const exportedSpan = await this.wrapDurableOperation(operationId, async () => {
177
+ const observability = this.mastra?.observability?.getSelectedInstance({});
178
+ if (!observability) return void 0;
179
+ const span = observability.startSpan({
180
+ ...options,
181
+ entityType: options.entityType,
182
+ traceId: executionContext.tracingIds?.traceId,
183
+ parentSpanId
184
+ });
185
+ return span?.exportSpan();
186
+ });
187
+ if (exportedSpan) {
188
+ const observability = this.mastra?.observability?.getSelectedInstance({});
189
+ return observability?.rebuildSpan(exportedSpan);
190
+ }
191
+ return void 0;
192
+ }
193
+ /**
194
+ * End a step span durably.
195
+ */
196
+ async endStepSpan(params) {
197
+ const { span, operationId, endOptions } = params;
198
+ if (!span) return;
199
+ await this.wrapDurableOperation(operationId, async () => {
200
+ span.end(endOptions);
201
+ });
202
+ }
203
+ /**
204
+ * Record error on step span durably.
205
+ */
206
+ async errorStepSpan(params) {
207
+ const { span, operationId, errorOptions } = params;
208
+ if (!span) return;
209
+ await this.wrapDurableOperation(operationId, async () => {
210
+ span.error(errorOptions);
211
+ });
212
+ }
213
+ /**
214
+ * Create a generic child span durably (for control-flow operations).
215
+ * On first execution, creates and exports span. On replay, returns cached span data.
216
+ */
217
+ async createChildSpan(params) {
218
+ const { executionContext, operationId, options, parentSpan } = params;
219
+ const parentSpanId = parentSpan?.id ?? executionContext.tracingIds?.workflowSpanId;
220
+ const exportedSpan = await this.wrapDurableOperation(operationId, async () => {
221
+ const observability = this.mastra?.observability?.getSelectedInstance({});
222
+ if (!observability) return void 0;
223
+ const span = observability.startSpan({
224
+ ...options,
225
+ traceId: executionContext.tracingIds?.traceId,
226
+ parentSpanId
227
+ });
228
+ return span?.exportSpan();
229
+ });
230
+ if (exportedSpan) {
231
+ const observability = this.mastra?.observability?.getSelectedInstance({});
232
+ return observability?.rebuildSpan(exportedSpan);
233
+ }
234
+ return void 0;
235
+ }
236
+ /**
237
+ * End a generic child span durably (for control-flow operations).
238
+ */
239
+ async endChildSpan(params) {
240
+ const { span, operationId, endOptions } = params;
241
+ if (!span) return;
242
+ await this.wrapDurableOperation(operationId, async () => {
243
+ span.end(endOptions);
244
+ });
245
+ }
246
+ /**
247
+ * Record error on a generic child span durably (for control-flow operations).
248
+ */
249
+ async errorChildSpan(params) {
250
+ const { span, operationId, errorOptions } = params;
251
+ if (!span) return;
252
+ await this.wrapDurableOperation(operationId, async () => {
253
+ span.error(errorOptions);
254
+ });
255
+ }
147
256
  /**
148
257
  * Execute nested InngestWorkflow using inngestStep.invoke() for durability.
149
258
  * This MUST be called directly (not inside step.run()) due to Inngest constraints.
@@ -162,8 +271,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
162
271
  inputData,
163
272
  pubsub,
164
273
  startedAt,
165
- perStep
274
+ perStep,
275
+ stepSpan
166
276
  } = params;
277
+ const nestedTracingContext = executionContext.tracingIds?.traceId ? {
278
+ traceId: executionContext.tracingIds.traceId,
279
+ parentSpanId: stepSpan?.id
280
+ } : void 0;
167
281
  const isResume = !!resume?.steps?.length;
168
282
  let result;
169
283
  let runId;
@@ -190,7 +304,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
190
304
  resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
191
305
  },
192
306
  outputOptions: { includeState: true },
193
- perStep
307
+ perStep,
308
+ tracingOptions: nestedTracingContext
194
309
  }
195
310
  });
196
311
  result = invokeResp.result;
@@ -218,7 +333,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
218
333
  initialState: executionContext.state ?? {},
219
334
  runId: executionContext.runId,
220
335
  outputOptions: { includeState: true },
221
- perStep
336
+ perStep,
337
+ tracingOptions: nestedTracingContext
222
338
  }
223
339
  });
224
340
  result = invokeResp.result;
@@ -231,7 +347,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
231
347
  inputData,
232
348
  initialState: executionContext.state ?? {},
233
349
  outputOptions: { includeState: true },
234
- perStep
350
+ perStep,
351
+ tracingOptions: nestedTracingContext
235
352
  }
236
353
  });
237
354
  result = invokeResp.result;
@@ -628,8 +745,8 @@ var InngestRun = class extends Run {
628
745
  });
629
746
  }
630
747
  }
631
- async start(params) {
632
- return this._start(params);
748
+ async start(args) {
749
+ return this._start(args);
633
750
  }
634
751
  /**
635
752
  * Starts the workflow execution without waiting for completion (fire-and-forget).
@@ -637,7 +754,7 @@ var InngestRun = class extends Run {
637
754
  * The workflow executes independently in Inngest.
638
755
  * Use this when you don't need to wait for the result or want to avoid polling failures.
639
756
  */
640
- async startAsync(params) {
757
+ async startAsync(args) {
641
758
  const workflowsStore = await this.#mastra.getStorage()?.getStore("workflows");
642
759
  await workflowsStore?.persistWorkflowSnapshot({
643
760
  workflowName: this.workflowId,
@@ -657,8 +774,8 @@ var InngestRun = class extends Run {
657
774
  timestamp: Date.now()
658
775
  }
659
776
  });
660
- const inputDataToUse = await this._validateInput(params.inputData);
661
- const initialStateToUse = await this._validateInitialState(params.initialState ?? {});
777
+ const inputDataToUse = await this._validateInput(args.inputData);
778
+ const initialStateToUse = await this._validateInitialState(args.initialState ?? {});
662
779
  const eventOutput = await this.inngest.send({
663
780
  name: `workflow.${this.workflowId}`,
664
781
  data: {
@@ -666,10 +783,10 @@ var InngestRun = class extends Run {
666
783
  initialState: initialStateToUse,
667
784
  runId: this.runId,
668
785
  resourceId: this.resourceId,
669
- outputOptions: params.outputOptions,
670
- tracingOptions: params.tracingOptions,
671
- requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {},
672
- perStep: params.perStep
786
+ outputOptions: args.outputOptions,
787
+ tracingOptions: args.tracingOptions,
788
+ requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},
789
+ perStep: args.perStep
673
790
  }
674
791
  });
675
792
  const eventId = eventOutput.ids[0];
@@ -1041,6 +1158,7 @@ var InngestRun = class extends Run {
1041
1158
  context,
1042
1159
  nestedStepsContext,
1043
1160
  requestContext,
1161
+ // tracingContext,
1044
1162
  tracingOptions,
1045
1163
  outputOptions,
1046
1164
  perStep
@@ -1173,7 +1291,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1173
1291
  }
1174
1292
  async createRun(options) {
1175
1293
  const runIdToUse = options?.runId || randomUUID();
1176
- const run = this.runs.get(runIdToUse) ?? new InngestRun(
1294
+ const existingInMemoryRun = this.runs.get(runIdToUse);
1295
+ const newRun = new InngestRun(
1177
1296
  {
1178
1297
  workflowId: this.id,
1179
1298
  runId: runIdToUse,
@@ -1190,15 +1309,16 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1190
1309
  },
1191
1310
  this.inngest
1192
1311
  );
1312
+ const run = existingInMemoryRun ?? newRun;
1193
1313
  this.runs.set(runIdToUse, run);
1194
1314
  const shouldPersistSnapshot = this.options.shouldPersistSnapshot({
1195
1315
  workflowStatus: run.workflowRunStatus,
1196
1316
  stepResults: {}
1197
1317
  });
1198
- const existingRun = await this.getWorkflowRunById(runIdToUse, {
1318
+ const existingStoredRun = await this.getWorkflowRunById(runIdToUse, {
1199
1319
  withNestedWorkflows: false
1200
1320
  });
1201
- const existsInStorage = existingRun && !existingRun.isFromInMemory;
1321
+ const existsInStorage = existingStoredRun && !existingStoredRun.isFromInMemory;
1202
1322
  if (!existsInStorage && shouldPersistSnapshot) {
1203
1323
  const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
1204
1324
  await workflowsStore?.persistWorkflowSnapshot({
@@ -1262,47 +1382,120 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1262
1382
  },
1263
1383
  { event: `workflow.${this.id}` },
1264
1384
  async ({ event, step, attempt, publish }) => {
1265
- let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel, perStep } = event.data;
1385
+ let {
1386
+ inputData,
1387
+ initialState,
1388
+ runId,
1389
+ resourceId,
1390
+ resume,
1391
+ outputOptions,
1392
+ format,
1393
+ timeTravel,
1394
+ perStep,
1395
+ tracingOptions
1396
+ } = event.data;
1266
1397
  if (!runId) {
1267
1398
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
1268
1399
  return randomUUID();
1269
1400
  });
1270
1401
  }
1271
1402
  const pubsub = new InngestPubSub(this.inngest, this.id, publish);
1403
+ const requestContext = new RequestContext(Object.entries(event.data.requestContext ?? {}));
1404
+ const mastra = this.#mastra;
1405
+ const tracingPolicy = this.options.tracingPolicy;
1406
+ const workflowSpanData = await step.run(`workflow.${this.id}.span.start`, async () => {
1407
+ const observability = mastra?.observability?.getSelectedInstance({ requestContext });
1408
+ if (!observability) return void 0;
1409
+ const span = observability.startSpan({
1410
+ type: SpanType.WORKFLOW_RUN,
1411
+ name: `workflow run: '${this.id}'`,
1412
+ entityType: EntityType.WORKFLOW_RUN,
1413
+ entityId: this.id,
1414
+ input: inputData,
1415
+ metadata: {
1416
+ resourceId,
1417
+ runId
1418
+ },
1419
+ tracingPolicy,
1420
+ tracingOptions,
1421
+ requestContext
1422
+ });
1423
+ return span?.exportSpan();
1424
+ });
1272
1425
  const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
1273
- const result = await engine.execute({
1274
- workflowId: this.id,
1275
- runId,
1276
- resourceId,
1277
- graph: this.executionGraph,
1278
- serializedStepGraph: this.serializedStepGraph,
1279
- input: inputData,
1280
- initialState,
1281
- pubsub,
1282
- retryConfig: this.retryConfig,
1283
- requestContext: new RequestContext(Object.entries(event.data.requestContext ?? {})),
1284
- resume,
1285
- timeTravel,
1286
- perStep,
1287
- format,
1288
- abortController: new AbortController(),
1289
- // currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
1290
- outputOptions,
1291
- outputWriter: async (chunk) => {
1292
- try {
1293
- await pubsub.publish(`workflow.events.v2.${runId}`, {
1294
- type: "watch",
1295
- runId,
1296
- data: chunk
1297
- });
1298
- } catch (err) {
1299
- this.logger.debug?.("Failed to publish watch event:", err);
1426
+ let result;
1427
+ try {
1428
+ result = await engine.execute({
1429
+ workflowId: this.id,
1430
+ runId,
1431
+ resourceId,
1432
+ graph: this.executionGraph,
1433
+ serializedStepGraph: this.serializedStepGraph,
1434
+ input: inputData,
1435
+ initialState,
1436
+ pubsub,
1437
+ retryConfig: this.retryConfig,
1438
+ requestContext,
1439
+ resume,
1440
+ timeTravel,
1441
+ perStep,
1442
+ format,
1443
+ abortController: new AbortController(),
1444
+ // For Inngest, we don't pass workflowSpan - step spans use tracingIds instead
1445
+ workflowSpan: void 0,
1446
+ // Pass tracing IDs for durable span operations
1447
+ tracingIds: workflowSpanData ? {
1448
+ traceId: workflowSpanData.traceId,
1449
+ workflowSpanId: workflowSpanData.id
1450
+ } : void 0,
1451
+ outputOptions,
1452
+ outputWriter: async (chunk) => {
1453
+ try {
1454
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
1455
+ type: "watch",
1456
+ runId,
1457
+ data: chunk
1458
+ });
1459
+ } catch (err) {
1460
+ this.logger.debug?.("Failed to publish watch event:", err);
1461
+ }
1300
1462
  }
1301
- }
1302
- });
1463
+ });
1464
+ } catch (error) {
1465
+ throw error;
1466
+ }
1303
1467
  await step.run(`workflow.${this.id}.finalize`, async () => {
1304
1468
  if (result.status !== "paused") {
1305
- await engine.invokeLifecycleCallbacksInternal(result);
1469
+ await engine.invokeLifecycleCallbacksInternal({
1470
+ status: result.status,
1471
+ result: "result" in result ? result.result : void 0,
1472
+ error: "error" in result ? result.error : void 0,
1473
+ steps: result.steps,
1474
+ tripwire: "tripwire" in result ? result.tripwire : void 0,
1475
+ runId,
1476
+ workflowId: this.id,
1477
+ resourceId,
1478
+ input: inputData,
1479
+ requestContext,
1480
+ state: result.state ?? initialState ?? {}
1481
+ });
1482
+ }
1483
+ if (workflowSpanData) {
1484
+ const observability = mastra?.observability?.getSelectedInstance({ requestContext });
1485
+ if (observability) {
1486
+ const workflowSpan = observability.rebuildSpan(workflowSpanData);
1487
+ if (result.status === "failed") {
1488
+ workflowSpan.error({
1489
+ error: result.error instanceof Error ? result.error : new Error(String(result.error)),
1490
+ attributes: { status: "failed" }
1491
+ });
1492
+ } else {
1493
+ workflowSpan.end({
1494
+ output: result.status === "success" ? result.result : void 0,
1495
+ attributes: { status: result.status }
1496
+ });
1497
+ }
1498
+ }
1306
1499
  }
1307
1500
  if (result.status === "failed") {
1308
1501
  throw new NonRetriableError(`Workflow failed`, {
@@ -1337,12 +1530,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1337
1530
  ];
1338
1531
  }
1339
1532
  };
1340
- function serve({
1341
- mastra,
1342
- inngest,
1343
- functions: userFunctions = [],
1344
- registerOptions
1345
- }) {
1533
+ function prepareServeOptions({ mastra, inngest, functions: userFunctions = [], registerOptions }) {
1346
1534
  const wfs = mastra.listWorkflows();
1347
1535
  const workflowFunctions = Array.from(
1348
1536
  new Set(
@@ -1355,175 +1543,181 @@ function serve({
1355
1543
  })
1356
1544
  )
1357
1545
  );
1358
- return serve$1({
1546
+ return {
1359
1547
  ...registerOptions,
1360
1548
  client: inngest,
1361
1549
  functions: [...workflowFunctions, ...userFunctions]
1362
- });
1550
+ };
1551
+ }
1552
+ function createServe(adapter) {
1553
+ return (options) => {
1554
+ const serveOptions = prepareServeOptions(options);
1555
+ return adapter(serveOptions);
1556
+ };
1363
1557
  }
1558
+ var serve = createServe(serve$1);
1364
1559
 
1365
1560
  // src/types.ts
1366
1561
  var _compatibilityCheck = true;
1367
1562
 
1368
1563
  // src/index.ts
1564
+ function isInngestWorkflow(input) {
1565
+ return input instanceof InngestWorkflow;
1566
+ }
1567
+ function isAgent(input) {
1568
+ return input instanceof Agent;
1569
+ }
1570
+ function isToolStep(input) {
1571
+ return input instanceof Tool;
1572
+ }
1573
+ function isStepParams(input) {
1574
+ return input !== null && typeof input === "object" && "id" in input && "execute" in input && !(input instanceof Agent) && !(input instanceof Tool) && !(input instanceof InngestWorkflow);
1575
+ }
1576
+ function isProcessor(obj) {
1577
+ return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && !(obj instanceof Agent) && !(obj instanceof Tool) && !(obj instanceof InngestWorkflow) && (typeof obj.processInput === "function" || typeof obj.processInputStep === "function" || typeof obj.processOutputStream === "function" || typeof obj.processOutputResult === "function" || typeof obj.processOutputStep === "function");
1578
+ }
1369
1579
  function createStep(params, agentOrToolOptions) {
1370
- if (params instanceof InngestWorkflow) {
1580
+ if (isInngestWorkflow(params)) {
1371
1581
  return params;
1372
1582
  }
1373
- if (params instanceof Agent) {
1374
- const options = agentOrToolOptions;
1375
- const outputSchema = options?.structuredOutput?.schema ?? z.object({ text: z.string() });
1376
- const { retries, scorers, ...agentOptions } = options ?? {};
1377
- return {
1378
- id: params.name,
1379
- description: params.getDescription(),
1380
- inputSchema: z.object({
1381
- prompt: z.string()
1382
- // resourceId: z.string().optional(),
1383
- // threadId: z.string().optional(),
1384
- }),
1385
- outputSchema,
1386
- retries,
1387
- scorers,
1388
- execute: async ({
1389
- inputData,
1390
- runId,
1391
- [PUBSUB_SYMBOL]: pubsub,
1392
- [STREAM_FORMAT_SYMBOL]: streamFormat,
1393
- requestContext,
1394
- tracingContext,
1395
- abortSignal,
1396
- abort,
1397
- writer
1398
- }) => {
1399
- let streamPromise = {};
1400
- streamPromise.promise = new Promise((resolve, reject) => {
1401
- streamPromise.resolve = resolve;
1402
- streamPromise.reject = reject;
1583
+ if (isAgent(params)) {
1584
+ return createStepFromAgent(params, agentOrToolOptions);
1585
+ }
1586
+ if (isToolStep(params)) {
1587
+ return createStepFromTool(params, agentOrToolOptions);
1588
+ }
1589
+ if (isStepParams(params)) {
1590
+ return createStepFromParams(params);
1591
+ }
1592
+ if (isProcessor(params)) {
1593
+ return createStepFromProcessor(params);
1594
+ }
1595
+ throw new Error("Invalid input: expected StepParams, Agent, ToolStep, Processor, or InngestWorkflow");
1596
+ }
1597
+ function createStepFromParams(params) {
1598
+ return {
1599
+ id: params.id,
1600
+ description: params.description,
1601
+ inputSchema: params.inputSchema,
1602
+ stateSchema: params.stateSchema,
1603
+ outputSchema: params.outputSchema,
1604
+ resumeSchema: params.resumeSchema,
1605
+ suspendSchema: params.suspendSchema,
1606
+ scorers: params.scorers,
1607
+ retries: params.retries,
1608
+ execute: params.execute.bind(params)
1609
+ };
1610
+ }
1611
+ function createStepFromAgent(params, agentOrToolOptions) {
1612
+ const options = agentOrToolOptions ?? {};
1613
+ const outputSchema = options?.structuredOutput?.schema ?? z.object({ text: z.string() });
1614
+ const { retries, scorers, ...agentOptions } = options ?? {};
1615
+ return {
1616
+ id: params.name,
1617
+ description: params.getDescription(),
1618
+ inputSchema: z.object({
1619
+ prompt: z.string()
1620
+ }),
1621
+ outputSchema,
1622
+ retries,
1623
+ scorers,
1624
+ execute: async ({
1625
+ inputData,
1626
+ runId,
1627
+ [PUBSUB_SYMBOL]: pubsub,
1628
+ [STREAM_FORMAT_SYMBOL]: streamFormat,
1629
+ requestContext,
1630
+ tracingContext,
1631
+ abortSignal,
1632
+ abort,
1633
+ writer
1634
+ }) => {
1635
+ let streamPromise = {};
1636
+ streamPromise.promise = new Promise((resolve, reject) => {
1637
+ streamPromise.resolve = resolve;
1638
+ streamPromise.reject = reject;
1639
+ });
1640
+ let structuredResult = null;
1641
+ const toolData = {
1642
+ name: params.name,
1643
+ args: inputData
1644
+ };
1645
+ let stream;
1646
+ if ((await params.getModel()).specificationVersion === "v1") {
1647
+ const { fullStream } = await params.streamLegacy(inputData.prompt, {
1648
+ ...agentOptions ?? {},
1649
+ requestContext,
1650
+ tracingContext,
1651
+ onFinish: (result) => {
1652
+ const resultWithObject = result;
1653
+ if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
1654
+ structuredResult = resultWithObject.object;
1655
+ }
1656
+ streamPromise.resolve(result.text);
1657
+ void agentOptions?.onFinish?.(result);
1658
+ },
1659
+ abortSignal
1403
1660
  });
1404
- let structuredResult = null;
1405
- const toolData = {
1406
- name: params.name,
1407
- args: inputData
1408
- };
1409
- let stream;
1410
- if ((await params.getModel()).specificationVersion === "v1") {
1411
- const { fullStream } = await params.streamLegacy(inputData.prompt, {
1412
- ...agentOptions ?? {},
1413
- // resourceId: inputData.resourceId,
1414
- // threadId: inputData.threadId,
1415
- requestContext,
1416
- tracingContext,
1417
- onFinish: (result) => {
1418
- const resultWithObject = result;
1419
- if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
1420
- structuredResult = resultWithObject.object;
1421
- }
1422
- streamPromise.resolve(result.text);
1423
- void agentOptions?.onFinish?.(result);
1424
- },
1425
- abortSignal
1426
- });
1427
- stream = fullStream;
1428
- } else {
1429
- const modelOutput = await params.stream(inputData.prompt, {
1430
- ...agentOptions ?? {},
1431
- requestContext,
1432
- tracingContext,
1433
- onFinish: (result) => {
1434
- const resultWithObject = result;
1435
- if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
1436
- structuredResult = resultWithObject.object;
1437
- }
1438
- streamPromise.resolve(result.text);
1439
- void agentOptions?.onFinish?.(result);
1440
- },
1441
- abortSignal
1442
- });
1443
- stream = modelOutput.fullStream;
1444
- }
1445
- if (streamFormat === "legacy") {
1446
- await pubsub.publish(`workflow.events.v2.${runId}`, {
1447
- type: "watch",
1448
- runId,
1449
- data: { type: "tool-call-streaming-start", ...toolData ?? {} }
1450
- });
1451
- for await (const chunk of stream) {
1452
- if (chunk.type === "text-delta") {
1453
- await pubsub.publish(`workflow.events.v2.${runId}`, {
1454
- type: "watch",
1455
- runId,
1456
- data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
1457
- });
1661
+ stream = fullStream;
1662
+ } else {
1663
+ const modelOutput = await params.stream(inputData.prompt, {
1664
+ ...agentOptions ?? {},
1665
+ requestContext,
1666
+ tracingContext,
1667
+ onFinish: (result) => {
1668
+ const resultWithObject = result;
1669
+ if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
1670
+ structuredResult = resultWithObject.object;
1458
1671
  }
1459
- }
1460
- await pubsub.publish(`workflow.events.v2.${runId}`, {
1461
- type: "watch",
1462
- runId,
1463
- data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
1464
- });
1465
- } else {
1466
- for await (const chunk of stream) {
1467
- await writer.write(chunk);
1672
+ streamPromise.resolve(result.text);
1673
+ void agentOptions?.onFinish?.(result);
1674
+ },
1675
+ abortSignal
1676
+ });
1677
+ stream = modelOutput.fullStream;
1678
+ }
1679
+ if (streamFormat === "legacy") {
1680
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
1681
+ type: "watch",
1682
+ runId,
1683
+ data: { type: "tool-call-streaming-start", ...toolData ?? {} }
1684
+ });
1685
+ for await (const chunk of stream) {
1686
+ if (chunk.type === "text-delta") {
1687
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
1688
+ type: "watch",
1689
+ runId,
1690
+ data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
1691
+ });
1468
1692
  }
1469
1693
  }
1470
- if (abortSignal.aborted) {
1471
- return abort();
1472
- }
1473
- if (structuredResult !== null) {
1474
- return structuredResult;
1694
+ await pubsub.publish(`workflow.events.v2.${runId}`, {
1695
+ type: "watch",
1696
+ runId,
1697
+ data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
1698
+ });
1699
+ } else {
1700
+ for await (const chunk of stream) {
1701
+ await writer.write(chunk);
1475
1702
  }
1476
- return {
1477
- text: await streamPromise.promise
1478
- };
1479
- },
1480
- component: params.component
1481
- };
1482
- }
1483
- if (params instanceof Tool) {
1484
- const toolOpts = agentOrToolOptions;
1485
- if (!params.inputSchema || !params.outputSchema) {
1486
- throw new Error("Tool must have input and output schemas defined");
1487
- }
1488
- return {
1489
- // TODO: tool probably should have strong id type
1490
- id: params.id,
1491
- description: params.description,
1492
- inputSchema: params.inputSchema,
1493
- outputSchema: params.outputSchema,
1494
- suspendSchema: params.suspendSchema,
1495
- resumeSchema: params.resumeSchema,
1496
- retries: toolOpts?.retries,
1497
- scorers: toolOpts?.scorers,
1498
- execute: async ({
1499
- inputData,
1500
- mastra,
1501
- requestContext,
1502
- tracingContext,
1503
- suspend,
1504
- resumeData,
1505
- runId,
1506
- workflowId,
1507
- state,
1508
- setState
1509
- }) => {
1510
- const toolContext = {
1511
- mastra,
1512
- requestContext,
1513
- tracingContext,
1514
- workflow: {
1515
- runId,
1516
- resumeData,
1517
- suspend,
1518
- workflowId,
1519
- state,
1520
- setState
1521
- }
1522
- };
1523
- return params.execute(inputData, toolContext);
1524
- },
1525
- component: "TOOL"
1526
- };
1703
+ }
1704
+ if (abortSignal.aborted) {
1705
+ return abort();
1706
+ }
1707
+ if (structuredResult !== null) {
1708
+ return structuredResult;
1709
+ }
1710
+ return {
1711
+ text: await streamPromise.promise
1712
+ };
1713
+ },
1714
+ component: params.component
1715
+ };
1716
+ }
1717
+ function createStepFromTool(params, agentOrToolOptions) {
1718
+ const toolOpts = agentOrToolOptions;
1719
+ if (!params.inputSchema || !params.outputSchema) {
1720
+ throw new Error("Tool must have input and output schemas defined");
1527
1721
  }
1528
1722
  return {
1529
1723
  id: params.id,
@@ -1532,9 +1726,480 @@ function createStep(params, agentOrToolOptions) {
1532
1726
  outputSchema: params.outputSchema,
1533
1727
  resumeSchema: params.resumeSchema,
1534
1728
  suspendSchema: params.suspendSchema,
1535
- retries: params.retries,
1536
- scorers: params.scorers,
1537
- execute: params.execute
1729
+ retries: toolOpts?.retries,
1730
+ scorers: toolOpts?.scorers,
1731
+ execute: async ({
1732
+ inputData,
1733
+ mastra,
1734
+ requestContext,
1735
+ tracingContext,
1736
+ suspend,
1737
+ resumeData,
1738
+ runId,
1739
+ workflowId,
1740
+ state,
1741
+ setState
1742
+ }) => {
1743
+ const toolContext = {
1744
+ mastra,
1745
+ requestContext,
1746
+ tracingContext,
1747
+ workflow: {
1748
+ runId,
1749
+ resumeData,
1750
+ suspend,
1751
+ workflowId,
1752
+ state,
1753
+ setState
1754
+ }
1755
+ };
1756
+ return params.execute(inputData, toolContext);
1757
+ },
1758
+ component: "TOOL"
1759
+ };
1760
+ }
1761
+ function createStepFromProcessor(processor) {
1762
+ const getProcessorEntityType = (phase) => {
1763
+ switch (phase) {
1764
+ case "input":
1765
+ return EntityType.INPUT_PROCESSOR;
1766
+ case "inputStep":
1767
+ return EntityType.INPUT_STEP_PROCESSOR;
1768
+ case "outputStream":
1769
+ case "outputResult":
1770
+ return EntityType.OUTPUT_PROCESSOR;
1771
+ case "outputStep":
1772
+ return EntityType.OUTPUT_STEP_PROCESSOR;
1773
+ default:
1774
+ return EntityType.OUTPUT_PROCESSOR;
1775
+ }
1776
+ };
1777
+ const getSpanNamePrefix = (phase) => {
1778
+ switch (phase) {
1779
+ case "input":
1780
+ return "input processor";
1781
+ case "inputStep":
1782
+ return "input step processor";
1783
+ case "outputStream":
1784
+ return "output stream processor";
1785
+ case "outputResult":
1786
+ return "output processor";
1787
+ case "outputStep":
1788
+ return "output step processor";
1789
+ default:
1790
+ return "processor";
1791
+ }
1792
+ };
1793
+ const hasPhaseMethod = (phase) => {
1794
+ switch (phase) {
1795
+ case "input":
1796
+ return !!processor.processInput;
1797
+ case "inputStep":
1798
+ return !!processor.processInputStep;
1799
+ case "outputStream":
1800
+ return !!processor.processOutputStream;
1801
+ case "outputResult":
1802
+ return !!processor.processOutputResult;
1803
+ case "outputStep":
1804
+ return !!processor.processOutputStep;
1805
+ default:
1806
+ return false;
1807
+ }
1808
+ };
1809
+ return {
1810
+ id: `processor:${processor.id}`,
1811
+ description: processor.name ?? `Processor ${processor.id}`,
1812
+ inputSchema: ProcessorStepSchema,
1813
+ outputSchema: ProcessorStepOutputSchema,
1814
+ execute: async ({ inputData, requestContext, tracingContext }) => {
1815
+ const input = inputData;
1816
+ const {
1817
+ phase,
1818
+ messages,
1819
+ messageList,
1820
+ stepNumber,
1821
+ systemMessages,
1822
+ part,
1823
+ streamParts,
1824
+ state,
1825
+ finishReason,
1826
+ toolCalls,
1827
+ text,
1828
+ retryCount,
1829
+ // inputStep phase fields for model/tools configuration
1830
+ model,
1831
+ tools,
1832
+ toolChoice,
1833
+ activeTools,
1834
+ providerOptions,
1835
+ modelSettings,
1836
+ structuredOutput,
1837
+ steps
1838
+ } = input;
1839
+ const abort = (reason, options) => {
1840
+ throw new TripWire(reason || `Tripwire triggered by ${processor.id}`, options, processor.id);
1841
+ };
1842
+ if (!hasPhaseMethod(phase)) {
1843
+ return input;
1844
+ }
1845
+ const currentSpan = tracingContext?.currentSpan;
1846
+ const parentSpan = phase === "inputStep" || phase === "outputStep" ? currentSpan?.findParent(SpanType.MODEL_STEP) || currentSpan : currentSpan?.findParent(SpanType.AGENT_RUN) || currentSpan;
1847
+ const processorSpan = phase !== "outputStream" ? parentSpan?.createChildSpan({
1848
+ type: SpanType.PROCESSOR_RUN,
1849
+ name: `${getSpanNamePrefix(phase)}: ${processor.id}`,
1850
+ entityType: getProcessorEntityType(phase),
1851
+ entityId: processor.id,
1852
+ entityName: processor.name ?? processor.id,
1853
+ input: { phase, messageCount: messages?.length },
1854
+ attributes: {
1855
+ processorExecutor: "workflow",
1856
+ // Read processorIndex from processor (set in combineProcessorsIntoWorkflow)
1857
+ processorIndex: processor.processorIndex
1858
+ }
1859
+ }) : void 0;
1860
+ const processorTracingContext = processorSpan ? { currentSpan: processorSpan } : tracingContext;
1861
+ const baseContext = {
1862
+ abort,
1863
+ retryCount: retryCount ?? 0,
1864
+ requestContext,
1865
+ tracingContext: processorTracingContext
1866
+ };
1867
+ const passThrough = {
1868
+ phase,
1869
+ // Auto-create MessageList from messages if not provided
1870
+ // This enables running processor workflows from the UI where messageList can't be serialized
1871
+ messageList: messageList ?? (Array.isArray(messages) ? new MessageList().add(messages, "input").addSystem(systemMessages ?? []) : void 0),
1872
+ stepNumber,
1873
+ systemMessages,
1874
+ streamParts,
1875
+ state,
1876
+ finishReason,
1877
+ toolCalls,
1878
+ text,
1879
+ retryCount,
1880
+ // inputStep phase fields for model/tools configuration
1881
+ model,
1882
+ tools,
1883
+ toolChoice,
1884
+ activeTools,
1885
+ providerOptions,
1886
+ modelSettings,
1887
+ structuredOutput,
1888
+ steps
1889
+ };
1890
+ const executePhaseWithSpan = async (fn) => {
1891
+ try {
1892
+ const result = await fn();
1893
+ processorSpan?.end({ output: result });
1894
+ return result;
1895
+ } catch (error) {
1896
+ if (error instanceof TripWire) {
1897
+ processorSpan?.end({ output: { tripwire: error.message } });
1898
+ } else {
1899
+ processorSpan?.error({ error, endSpan: true });
1900
+ }
1901
+ throw error;
1902
+ }
1903
+ };
1904
+ return executePhaseWithSpan(async () => {
1905
+ switch (phase) {
1906
+ case "input": {
1907
+ if (processor.processInput) {
1908
+ if (!passThrough.messageList) {
1909
+ throw new MastraError({
1910
+ category: ErrorCategory.USER,
1911
+ domain: ErrorDomain.MASTRA_WORKFLOW,
1912
+ id: "PROCESSOR_MISSING_MESSAGE_LIST",
1913
+ text: `Processor ${processor.id} requires messageList or messages for processInput phase`
1914
+ });
1915
+ }
1916
+ const idsBeforeProcessing = messages.map((m) => m.id);
1917
+ const check = passThrough.messageList.makeMessageSourceChecker();
1918
+ const result = await processor.processInput({
1919
+ ...baseContext,
1920
+ messages,
1921
+ messageList: passThrough.messageList,
1922
+ systemMessages: systemMessages ?? []
1923
+ });
1924
+ if (result instanceof MessageList) {
1925
+ if (result !== passThrough.messageList) {
1926
+ throw new MastraError({
1927
+ category: ErrorCategory.USER,
1928
+ domain: ErrorDomain.MASTRA_WORKFLOW,
1929
+ id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
1930
+ text: `Processor ${processor.id} returned a MessageList instance other than the one passed in. Use the messageList argument instead.`
1931
+ });
1932
+ }
1933
+ return {
1934
+ ...passThrough,
1935
+ messages: result.get.all.db(),
1936
+ systemMessages: result.getAllSystemMessages()
1937
+ };
1938
+ } else if (Array.isArray(result)) {
1939
+ ProcessorRunner.applyMessagesToMessageList(
1940
+ result,
1941
+ passThrough.messageList,
1942
+ idsBeforeProcessing,
1943
+ check,
1944
+ "input"
1945
+ );
1946
+ return { ...passThrough, messages: result };
1947
+ } else if (result && "messages" in result && "systemMessages" in result) {
1948
+ const typedResult = result;
1949
+ ProcessorRunner.applyMessagesToMessageList(
1950
+ typedResult.messages,
1951
+ passThrough.messageList,
1952
+ idsBeforeProcessing,
1953
+ check,
1954
+ "input"
1955
+ );
1956
+ passThrough.messageList.replaceAllSystemMessages(typedResult.systemMessages);
1957
+ return {
1958
+ ...passThrough,
1959
+ messages: typedResult.messages,
1960
+ systemMessages: typedResult.systemMessages
1961
+ };
1962
+ }
1963
+ return { ...passThrough, messages };
1964
+ }
1965
+ return { ...passThrough, messages };
1966
+ }
1967
+ case "inputStep": {
1968
+ if (processor.processInputStep) {
1969
+ if (!passThrough.messageList) {
1970
+ throw new MastraError({
1971
+ category: ErrorCategory.USER,
1972
+ domain: ErrorDomain.MASTRA_WORKFLOW,
1973
+ id: "PROCESSOR_MISSING_MESSAGE_LIST",
1974
+ text: `Processor ${processor.id} requires messageList or messages for processInputStep phase`
1975
+ });
1976
+ }
1977
+ const idsBeforeProcessing = messages.map((m) => m.id);
1978
+ const check = passThrough.messageList.makeMessageSourceChecker();
1979
+ const result = await processor.processInputStep({
1980
+ ...baseContext,
1981
+ messages,
1982
+ messageList: passThrough.messageList,
1983
+ stepNumber: stepNumber ?? 0,
1984
+ systemMessages: systemMessages ?? [],
1985
+ // Pass model/tools configuration fields - types match ProcessInputStepArgs
1986
+ model,
1987
+ tools,
1988
+ toolChoice,
1989
+ activeTools,
1990
+ providerOptions,
1991
+ modelSettings,
1992
+ structuredOutput,
1993
+ steps: steps ?? []
1994
+ });
1995
+ const validatedResult = await ProcessorRunner.validateAndFormatProcessInputStepResult(result, {
1996
+ messageList: passThrough.messageList,
1997
+ processor,
1998
+ stepNumber: stepNumber ?? 0
1999
+ });
2000
+ if (validatedResult.messages) {
2001
+ ProcessorRunner.applyMessagesToMessageList(
2002
+ validatedResult.messages,
2003
+ passThrough.messageList,
2004
+ idsBeforeProcessing,
2005
+ check
2006
+ );
2007
+ }
2008
+ if (validatedResult.systemMessages) {
2009
+ passThrough.messageList.replaceAllSystemMessages(validatedResult.systemMessages);
2010
+ }
2011
+ return { ...passThrough, messages, ...validatedResult };
2012
+ }
2013
+ return { ...passThrough, messages };
2014
+ }
2015
+ case "outputStream": {
2016
+ if (processor.processOutputStream) {
2017
+ const spanKey = `__outputStreamSpan_${processor.id}`;
2018
+ const mutableState = state ?? {};
2019
+ let processorSpan2 = mutableState[spanKey];
2020
+ if (!processorSpan2 && parentSpan) {
2021
+ processorSpan2 = parentSpan.createChildSpan({
2022
+ type: SpanType.PROCESSOR_RUN,
2023
+ name: `output stream processor: ${processor.id}`,
2024
+ entityType: EntityType.OUTPUT_PROCESSOR,
2025
+ entityId: processor.id,
2026
+ entityName: processor.name ?? processor.id,
2027
+ input: { phase, streamParts: [] },
2028
+ attributes: {
2029
+ processorExecutor: "workflow",
2030
+ processorIndex: processor.processorIndex
2031
+ }
2032
+ });
2033
+ mutableState[spanKey] = processorSpan2;
2034
+ }
2035
+ if (processorSpan2) {
2036
+ processorSpan2.input = {
2037
+ phase,
2038
+ streamParts: streamParts ?? [],
2039
+ totalChunks: (streamParts ?? []).length
2040
+ };
2041
+ }
2042
+ const processorTracingContext2 = processorSpan2 ? { currentSpan: processorSpan2 } : baseContext.tracingContext;
2043
+ let result;
2044
+ try {
2045
+ result = await processor.processOutputStream({
2046
+ ...baseContext,
2047
+ tracingContext: processorTracingContext2,
2048
+ part,
2049
+ streamParts: streamParts ?? [],
2050
+ state: mutableState,
2051
+ messageList: passThrough.messageList
2052
+ // Optional for stream processing
2053
+ });
2054
+ if (part && part.type === "finish") {
2055
+ processorSpan2?.end({ output: result });
2056
+ delete mutableState[spanKey];
2057
+ }
2058
+ } catch (error) {
2059
+ if (error instanceof TripWire) {
2060
+ processorSpan2?.end({ output: { tripwire: error.message } });
2061
+ } else {
2062
+ processorSpan2?.error({ error, endSpan: true });
2063
+ }
2064
+ delete mutableState[spanKey];
2065
+ throw error;
2066
+ }
2067
+ return { ...passThrough, state: mutableState, part: result };
2068
+ }
2069
+ return { ...passThrough, part };
2070
+ }
2071
+ case "outputResult": {
2072
+ if (processor.processOutputResult) {
2073
+ if (!passThrough.messageList) {
2074
+ throw new MastraError({
2075
+ category: ErrorCategory.USER,
2076
+ domain: ErrorDomain.MASTRA_WORKFLOW,
2077
+ id: "PROCESSOR_MISSING_MESSAGE_LIST",
2078
+ text: `Processor ${processor.id} requires messageList or messages for processOutputResult phase`
2079
+ });
2080
+ }
2081
+ const idsBeforeProcessing = messages.map((m) => m.id);
2082
+ const check = passThrough.messageList.makeMessageSourceChecker();
2083
+ const result = await processor.processOutputResult({
2084
+ ...baseContext,
2085
+ messages,
2086
+ messageList: passThrough.messageList
2087
+ });
2088
+ if (result instanceof MessageList) {
2089
+ if (result !== passThrough.messageList) {
2090
+ throw new MastraError({
2091
+ category: ErrorCategory.USER,
2092
+ domain: ErrorDomain.MASTRA_WORKFLOW,
2093
+ id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
2094
+ text: `Processor ${processor.id} returned a MessageList instance other than the one passed in. Use the messageList argument instead.`
2095
+ });
2096
+ }
2097
+ return {
2098
+ ...passThrough,
2099
+ messages: result.get.all.db(),
2100
+ systemMessages: result.getAllSystemMessages()
2101
+ };
2102
+ } else if (Array.isArray(result)) {
2103
+ ProcessorRunner.applyMessagesToMessageList(
2104
+ result,
2105
+ passThrough.messageList,
2106
+ idsBeforeProcessing,
2107
+ check,
2108
+ "response"
2109
+ );
2110
+ return { ...passThrough, messages: result };
2111
+ } else if (result && "messages" in result && "systemMessages" in result) {
2112
+ const typedResult = result;
2113
+ ProcessorRunner.applyMessagesToMessageList(
2114
+ typedResult.messages,
2115
+ passThrough.messageList,
2116
+ idsBeforeProcessing,
2117
+ check,
2118
+ "response"
2119
+ );
2120
+ passThrough.messageList.replaceAllSystemMessages(typedResult.systemMessages);
2121
+ return {
2122
+ ...passThrough,
2123
+ messages: typedResult.messages,
2124
+ systemMessages: typedResult.systemMessages
2125
+ };
2126
+ }
2127
+ return { ...passThrough, messages };
2128
+ }
2129
+ return { ...passThrough, messages };
2130
+ }
2131
+ case "outputStep": {
2132
+ if (processor.processOutputStep) {
2133
+ if (!passThrough.messageList) {
2134
+ throw new MastraError({
2135
+ category: ErrorCategory.USER,
2136
+ domain: ErrorDomain.MASTRA_WORKFLOW,
2137
+ id: "PROCESSOR_MISSING_MESSAGE_LIST",
2138
+ text: `Processor ${processor.id} requires messageList or messages for processOutputStep phase`
2139
+ });
2140
+ }
2141
+ const idsBeforeProcessing = messages.map((m) => m.id);
2142
+ const check = passThrough.messageList.makeMessageSourceChecker();
2143
+ const result = await processor.processOutputStep({
2144
+ ...baseContext,
2145
+ messages,
2146
+ messageList: passThrough.messageList,
2147
+ stepNumber: stepNumber ?? 0,
2148
+ finishReason,
2149
+ toolCalls,
2150
+ text,
2151
+ systemMessages: systemMessages ?? [],
2152
+ steps: steps ?? []
2153
+ });
2154
+ if (result instanceof MessageList) {
2155
+ if (result !== passThrough.messageList) {
2156
+ throw new MastraError({
2157
+ category: ErrorCategory.USER,
2158
+ domain: ErrorDomain.MASTRA_WORKFLOW,
2159
+ id: "PROCESSOR_RETURNED_EXTERNAL_MESSAGE_LIST",
2160
+ text: `Processor ${processor.id} returned a MessageList instance other than the one passed in. Use the messageList argument instead.`
2161
+ });
2162
+ }
2163
+ return {
2164
+ ...passThrough,
2165
+ messages: result.get.all.db(),
2166
+ systemMessages: result.getAllSystemMessages()
2167
+ };
2168
+ } else if (Array.isArray(result)) {
2169
+ ProcessorRunner.applyMessagesToMessageList(
2170
+ result,
2171
+ passThrough.messageList,
2172
+ idsBeforeProcessing,
2173
+ check,
2174
+ "response"
2175
+ );
2176
+ return { ...passThrough, messages: result };
2177
+ } else if (result && "messages" in result && "systemMessages" in result) {
2178
+ const typedResult = result;
2179
+ ProcessorRunner.applyMessagesToMessageList(
2180
+ typedResult.messages,
2181
+ passThrough.messageList,
2182
+ idsBeforeProcessing,
2183
+ check,
2184
+ "response"
2185
+ );
2186
+ passThrough.messageList.replaceAllSystemMessages(typedResult.systemMessages);
2187
+ return {
2188
+ ...passThrough,
2189
+ messages: typedResult.messages,
2190
+ systemMessages: typedResult.systemMessages
2191
+ };
2192
+ }
2193
+ return { ...passThrough, messages };
2194
+ }
2195
+ return { ...passThrough, messages };
2196
+ }
2197
+ default:
2198
+ return { ...passThrough, messages };
2199
+ }
2200
+ });
2201
+ },
2202
+ component: "PROCESSOR"
1538
2203
  };
1539
2204
  }
1540
2205
  function init(inngest) {
@@ -1577,6 +2242,6 @@ function init(inngest) {
1577
2242
  };
1578
2243
  }
1579
2244
 
1580
- export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, _compatibilityCheck, createStep, init, serve };
2245
+ export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, _compatibilityCheck, createServe, createStep, init, serve };
1581
2246
  //# sourceMappingURL=index.js.map
1582
2247
  //# sourceMappingURL=index.js.map