@mastra/inngest 1.8.7 → 1.8.8
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/CHANGELOG.md +46 -0
- package/dist/{connect-BC21XS-T.cjs → connect-BllPgt3_.cjs} +104 -22
- package/dist/connect-BllPgt3_.cjs.map +1 -0
- package/dist/{connect-D7Dro-2T.js → connect-Dsxakf92.js} +87 -23
- package/dist/connect-Dsxakf92.js.map +1 -0
- package/dist/connect.cjs +1 -1
- package/dist/connect.js +1 -1
- package/dist/durable-agent/create-inngest-agent.d.ts +13 -0
- package/dist/durable-agent/create-inngest-agent.d.ts.map +1 -1
- package/dist/durable-event-payload.d.ts +88 -0
- package/dist/durable-event-payload.d.ts.map +1 -0
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +56 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -44
- package/dist/index.js.map +1 -1
- package/dist/nested-workflow-output.d.ts +1 -1
- package/dist/nested-workflow-output.d.ts.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/connect-BC21XS-T.cjs.map +0 -1
- package/dist/connect-D7Dro-2T.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as InngestPubSub, i as InngestRun, n as collectInngestFunctions, o as
|
|
1
|
+
import { a as buildDurableResumeEventData, c as InngestPubSub, i as InngestRun, l as InngestExecutionEngine, n as collectInngestFunctions, o as buildDurableTriggerEventData, r as InngestWorkflow, s as mergeResumeRequestContext, t as connect } from "./connect-Dsxakf92.js";
|
|
2
2
|
import { Agent, MessageList, TripWire } from "@mastra/core/agent";
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
4
4
|
import { EntityType, InternalSpans, SpanType } from "@mastra/core/observability";
|
|
@@ -7,6 +7,7 @@ import { toStandardSchema } from "@mastra/core/schema";
|
|
|
7
7
|
import { Tool, createTool } from "@mastra/core/tools";
|
|
8
8
|
import { Workflow, createStepFromAgent, createStepFromTool } from "@mastra/core/workflows";
|
|
9
9
|
import { DurableAgentDefaults, DurableStepIds, baseIterationStateSchema, createBaseIterationStateUpdate, createDurableAgentStream, createDurableBackgroundTaskCheckStep, createDurableLLMExecutionStep, createDurableLLMMappingStep, createDurableToolCallStep, durableAgenticOutputSchema, emitErrorEvent, emitFinishEvent, executeDurableAgentScorers, globalRunRegistry, modelConfigSchema, prepareForDurableExecution, publishAbortRequest, resolveDurableToolCallConcurrency, runDurableFinishSideEffects, runDurableStreamUntilIdle, runResumeDurableStreamUntilIdle } from "@mastra/core/agent/durable";
|
|
10
|
+
import { NonRetriableError } from "inngest";
|
|
10
11
|
import { CachingPubSub } from "@mastra/core/events";
|
|
11
12
|
import { serve as serve$1 } from "inngest/hono";
|
|
12
13
|
import { InMemoryServerCache } from "@mastra/core/cache";
|
|
@@ -448,17 +449,18 @@ function createInngestAgent(options) {
|
|
|
448
449
|
/**
|
|
449
450
|
* Trigger the workflow via Inngest event
|
|
450
451
|
*/
|
|
451
|
-
async function triggerWorkflow(runId, workflowInput, tracingOptions) {
|
|
452
|
+
async function triggerWorkflow(runId, workflowInput, tracingOptions, actor) {
|
|
452
453
|
const eventName = `workflow.${InngestDurableStepIds.AGENTIC_LOOP}`;
|
|
453
454
|
await inngest.send({
|
|
454
455
|
name: eventName,
|
|
455
|
-
data: {
|
|
456
|
+
data: buildDurableTriggerEventData({
|
|
456
457
|
inputData: workflowInput,
|
|
457
458
|
runId,
|
|
458
459
|
resourceId: workflowInput.state?.resourceId,
|
|
459
460
|
requestContext: workflowInput.requestContextEntries ?? {},
|
|
460
|
-
tracingOptions
|
|
461
|
-
|
|
461
|
+
tracingOptions,
|
|
462
|
+
actor
|
|
463
|
+
})
|
|
462
464
|
});
|
|
463
465
|
}
|
|
464
466
|
/**
|
|
@@ -528,7 +530,10 @@ function createInngestAgent(options) {
|
|
|
528
530
|
options: streamOptions,
|
|
529
531
|
runId: streamOptions?.runId,
|
|
530
532
|
requestContext: streamOptions?.requestContext,
|
|
531
|
-
methodType: streamOptions?.__methodType ?? "stream"
|
|
533
|
+
methodType: streamOptions?.__methodType ?? "stream",
|
|
534
|
+
mastra,
|
|
535
|
+
durableAgentId: agentId,
|
|
536
|
+
durableAgentName: agentName
|
|
532
537
|
});
|
|
533
538
|
workflowInput.agentId = agentId;
|
|
534
539
|
workflowInput.agentName = agentName;
|
|
@@ -541,33 +546,6 @@ function createInngestAgent(options) {
|
|
|
541
546
|
registryEntry.abortController = abortController;
|
|
542
547
|
registryEntry.abortSignal = abortController.signal;
|
|
543
548
|
globalRunRegistry.set(runId, registryEntry);
|
|
544
|
-
const agentSpan = (mastra?.observability?.getSelectedInstance({ requestContext: streamOptions?.requestContext }))?.startSpan({
|
|
545
|
-
type: SpanType.AGENT_RUN,
|
|
546
|
-
name: `agent run: '${agentId}'`,
|
|
547
|
-
entityType: EntityType.AGENT,
|
|
548
|
-
entityId: agentId,
|
|
549
|
-
entityName: agentName,
|
|
550
|
-
input: workflowInput.messageListState,
|
|
551
|
-
metadata: {
|
|
552
|
-
runId,
|
|
553
|
-
threadId,
|
|
554
|
-
resourceId
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
const agentSpanData = agentSpan?.exportSpan();
|
|
558
|
-
const modelSpanData = (agentSpan?.createChildSpan({
|
|
559
|
-
type: SpanType.MODEL_GENERATION,
|
|
560
|
-
name: `llm: '${workflowInput.modelConfig.modelId}'`,
|
|
561
|
-
input: { messages: workflowInput.messageListState },
|
|
562
|
-
attributes: {
|
|
563
|
-
model: workflowInput.modelConfig.modelId,
|
|
564
|
-
provider: workflowInput.modelConfig.provider,
|
|
565
|
-
streaming: true,
|
|
566
|
-
parameters: { temperature: workflowInput.options?.modelSettings?.temperature }
|
|
567
|
-
}
|
|
568
|
-
}))?.exportSpan();
|
|
569
|
-
workflowInput.agentSpanData = agentSpanData;
|
|
570
|
-
workflowInput.modelSpanData = modelSpanData;
|
|
571
549
|
workflowInput.stepIndex = 0;
|
|
572
550
|
let cleanedUp = false;
|
|
573
551
|
const finalizeGlobalRegistry = () => {
|
|
@@ -615,11 +593,12 @@ function createInngestAgent(options) {
|
|
|
615
593
|
} : void 0,
|
|
616
594
|
closeOnSuspend: streamOptions?.[CLOSE_ON_SUSPEND] === true
|
|
617
595
|
});
|
|
618
|
-
const
|
|
596
|
+
const agentSpanData = workflowInput.agentSpanData;
|
|
597
|
+
const tracingOptions = agentSpanData?.traceId && agentSpanData?.id ? {
|
|
619
598
|
traceId: agentSpanData.traceId,
|
|
620
599
|
parentSpanId: agentSpanData.id
|
|
621
600
|
} : void 0;
|
|
622
|
-
const workflowExecution = ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions)).catch((error) => {
|
|
601
|
+
const workflowExecution = ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions, streamOptions?.actor)).catch((error) => {
|
|
623
602
|
emitError(runId, error);
|
|
624
603
|
});
|
|
625
604
|
const trackedEntry = globalRunRegistry.get(runId);
|
|
@@ -718,40 +697,64 @@ function createInngestAgent(options) {
|
|
|
718
697
|
closeOnSuspend: resumeOptions?.[CLOSE_ON_SUSPEND] === true
|
|
719
698
|
});
|
|
720
699
|
const eventName = `workflow.${InngestDurableStepIds.AGENTIC_LOOP}`;
|
|
721
|
-
const
|
|
700
|
+
const dispatch = ready.then(async () => {
|
|
722
701
|
const snapshot = await (await mastra?.getStorage()?.getStore("workflows"))?.loadWorkflowSnapshot({
|
|
723
702
|
workflowName: InngestDurableStepIds.AGENTIC_LOOP,
|
|
724
703
|
runId
|
|
725
704
|
});
|
|
726
705
|
const suspendedStepIds = snapshot?.suspendedPaths ? Object.keys(snapshot.suspendedPaths) : [];
|
|
727
|
-
const
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
706
|
+
const resumeLabels = snapshot?.resumeLabels ?? {};
|
|
707
|
+
const toolCallId = resumeOptions?.toolCallId;
|
|
708
|
+
const expandToLeafPath = (stepId) => {
|
|
709
|
+
const nestedPath = (snapshot?.context ?? {})[stepId]?.suspendPayload?.__workflow_meta?.path;
|
|
710
|
+
return Array.isArray(nestedPath) ? [stepId, ...nestedPath] : [stepId];
|
|
731
711
|
};
|
|
712
|
+
let steps;
|
|
713
|
+
if (toolCallId) {
|
|
714
|
+
const targetStepId = resumeLabels[toolCallId]?.stepId;
|
|
715
|
+
if (!targetStepId) {
|
|
716
|
+
const available = Object.keys(resumeLabels);
|
|
717
|
+
throw new NonRetriableError(`Cannot resume run ${runId}: no suspended tool call with id "${toolCallId}". ` + (available.length > 0 ? `Suspended tool call ids: ${available.join(", ")}.` : `No tool calls are currently suspended.`));
|
|
718
|
+
}
|
|
719
|
+
steps = expandToLeafPath(targetStepId);
|
|
720
|
+
} else {
|
|
721
|
+
const available = Object.keys(resumeLabels);
|
|
722
|
+
if (suspendedStepIds.length > 1 || available.length > 1) throw new NonRetriableError(`Cannot resume run ${runId}: more than one suspension is parked. Pass "toolCallId" to choose which suspended tool call to resume.` + (available.length > 0 ? ` Suspended tool call ids: ${available.join(", ")}.` : ""));
|
|
723
|
+
steps = suspendedStepIds[0] ? expandToLeafPath(suspendedStepIds[0]) : [];
|
|
724
|
+
}
|
|
725
|
+
const requestContext = mergeResumeRequestContext(snapshot?.requestContext, resumeOptions?.requestContext);
|
|
732
726
|
const tracingOptions = snapshot?.tracingContext ? {
|
|
733
727
|
traceId: snapshot.tracingContext.traceId,
|
|
734
728
|
parentSpanId: snapshot.tracingContext.spanId
|
|
735
729
|
} : void 0;
|
|
736
730
|
await inngest.send({
|
|
737
731
|
name: eventName,
|
|
738
|
-
data: {
|
|
732
|
+
data: buildDurableResumeEventData({
|
|
739
733
|
inputData: resumeData,
|
|
740
734
|
runId,
|
|
741
735
|
resourceId: resumeOptions?.resourceId,
|
|
742
736
|
requestContext,
|
|
743
737
|
tracingOptions,
|
|
738
|
+
actor: resumeOptions?.actor,
|
|
744
739
|
resume: {
|
|
745
740
|
steps,
|
|
746
741
|
resumePayload: resumeData,
|
|
747
742
|
resumePath: steps[0] ? snapshot?.suspendedPaths?.[steps[0]] : void 0
|
|
748
743
|
}
|
|
749
|
-
}
|
|
744
|
+
})
|
|
750
745
|
});
|
|
751
|
-
})
|
|
746
|
+
});
|
|
747
|
+
const workflowExecution = dispatch.catch((error) => {
|
|
752
748
|
emitError(runId, error);
|
|
753
749
|
});
|
|
754
750
|
existingEntry.workflowExecution = workflowExecution;
|
|
751
|
+
try {
|
|
752
|
+
await dispatch;
|
|
753
|
+
} catch (error) {
|
|
754
|
+
streamCleanup();
|
|
755
|
+
finalizeResumeRegistry();
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
755
758
|
const abort = async (reason) => {
|
|
756
759
|
if (!abortController.signal.aborted) abortController.abort(reason);
|
|
757
760
|
await requestRemoteAbort(runId);
|
|
@@ -778,7 +781,10 @@ function createInngestAgent(options) {
|
|
|
778
781
|
agent,
|
|
779
782
|
messages,
|
|
780
783
|
options: prepareOptions,
|
|
781
|
-
requestContext: prepareOptions?.requestContext
|
|
784
|
+
requestContext: prepareOptions?.requestContext,
|
|
785
|
+
mastra,
|
|
786
|
+
durableAgentId: agentId,
|
|
787
|
+
durableAgentName: agentName
|
|
782
788
|
});
|
|
783
789
|
preparation.workflowInput.agentId = agentId;
|
|
784
790
|
preparation.workflowInput.agentName = agentName;
|