@mastra/inngest 1.6.0 → 1.7.0

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
@@ -10,7 +10,7 @@ import { Workflow } from '@mastra/core/workflows';
10
10
  import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
11
11
  import { z } from 'zod';
12
12
  import { serve as serve$1 } from 'inngest/hono';
13
- import { modelConfigSchema, baseIterationStateSchema, createDurableLLMExecutionStep, createDurableToolCallStep, createDurableLLMMappingStep, createDurableBackgroundTaskCheckStep, DurableStepIds, createBaseIterationStateUpdate, durableAgenticOutputSchema, emitFinishEvent, createDurableAgentStream, prepareForDurableExecution, emitErrorEvent, DurableAgentDefaults } from '@mastra/core/agent/durable';
13
+ import { modelConfigSchema, baseIterationStateSchema, createDurableLLMExecutionStep, createDurableToolCallStep, createDurableLLMMappingStep, createDurableBackgroundTaskCheckStep, DurableStepIds, createBaseIterationStateUpdate, durableAgenticOutputSchema, emitFinishEvent, createDurableAgentStream, prepareForDurableExecution, runDurableStreamUntilIdle, emitErrorEvent, DurableAgentDefaults } from '@mastra/core/agent/durable';
14
14
  import { CachingPubSub } from '@mastra/core/events';
15
15
 
16
16
  function prepareServeOptions({ mastra, inngest, functions: userFunctions = [], registerOptions }) {
@@ -309,6 +309,8 @@ function createInngestAgent(options) {
309
309
  const agentId = idOverride ?? agent.id;
310
310
  const agentName = nameOverride ?? agent.name;
311
311
  let mastra = mastraOption;
312
+ const activeStreamUntilIdle = /* @__PURE__ */ new Map();
313
+ let proxyRef;
312
314
  const workflow = createInngestDurableAgenticWorkflow({ inngest });
313
315
  let _customCache = cache;
314
316
  let innerPubsub = customPubsub ?? new InngestPubSub(inngest, InngestDurableStepIds.AGENTIC_LOOP);
@@ -365,6 +367,14 @@ function createInngestAgent(options) {
365
367
  return getPubsub();
366
368
  },
367
369
  async stream(messages, streamOptions) {
370
+ if (streamOptions?.untilIdle) {
371
+ const { untilIdle, ...rest } = streamOptions;
372
+ const maxIdleMs = typeof untilIdle === "object" ? untilIdle.maxIdleMs : void 0;
373
+ return runDurableStreamUntilIdle(proxyRef, messages, { ...rest, maxIdleMs }, {
374
+ activeStreams: activeStreamUntilIdle,
375
+ bgManager: mastra?.backgroundTaskManager
376
+ });
377
+ }
368
378
  const preparation = await prepareForDurableExecution({
369
379
  agent,
370
380
  messages,
@@ -434,7 +444,7 @@ function createInngestAgent(options) {
434
444
  ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions)).catch((error) => {
435
445
  void emitError(runId, error);
436
446
  });
437
- const result = {
447
+ const result2 = {
438
448
  output,
439
449
  runId,
440
450
  threadId,
@@ -445,7 +455,7 @@ function createInngestAgent(options) {
445
455
  return output.fullStream;
446
456
  }
447
457
  };
448
- return result;
458
+ return result2;
449
459
  },
450
460
  async resume(runId, resumeData, resumeOptions) {
451
461
  const {
@@ -564,7 +574,7 @@ function createInngestAgent(options) {
564
574
  mastra = mastraInstance;
565
575
  }
566
576
  };
567
- return new Proxy(inngestAgent, {
577
+ const result = new Proxy(inngestAgent, {
568
578
  get(target, prop, receiver) {
569
579
  if (prop in target) {
570
580
  return Reflect.get(target, prop, receiver);
@@ -579,6 +589,8 @@ function createInngestAgent(options) {
579
589
  return prop in target || prop in agent;
580
590
  }
581
591
  });
592
+ proxyRef = result;
593
+ return result;
582
594
  }
583
595
  function isInngestAgent(obj) {
584
596
  if (!obj) return false;