@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.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_connect = require("./connect-
|
|
2
|
+
const require_connect = require("./connect-BllPgt3_.cjs");
|
|
3
3
|
let _mastra_core_agent = require("@mastra/core/agent");
|
|
4
4
|
let _mastra_core_error = require("@mastra/core/error");
|
|
5
5
|
let _mastra_core_observability = require("@mastra/core/observability");
|
|
@@ -8,6 +8,7 @@ let _mastra_core_schema = require("@mastra/core/schema");
|
|
|
8
8
|
let _mastra_core_tools = require("@mastra/core/tools");
|
|
9
9
|
let _mastra_core_workflows = require("@mastra/core/workflows");
|
|
10
10
|
let _mastra_core_agent_durable = require("@mastra/core/agent/durable");
|
|
11
|
+
let inngest = require("inngest");
|
|
11
12
|
let _mastra_core_events = require("@mastra/core/events");
|
|
12
13
|
let inngest_hono = require("inngest/hono");
|
|
13
14
|
let _mastra_core_cache = require("@mastra/core/cache");
|
|
@@ -415,15 +416,15 @@ const STREAM_CLEANUP = Symbol("mastra.durable.inngest.streamCleanup");
|
|
|
415
416
|
* ```
|
|
416
417
|
*/
|
|
417
418
|
function createInngestAgent(options) {
|
|
418
|
-
const { agent, inngest, id: idOverride, name: nameOverride, pubsub: customPubsub, cache, mastra: mastraOption } = options;
|
|
419
|
+
const { agent, inngest: inngest$1, id: idOverride, name: nameOverride, pubsub: customPubsub, cache, mastra: mastraOption } = options;
|
|
419
420
|
const agentId = idOverride ?? agent.id;
|
|
420
421
|
const agentName = nameOverride ?? agent.name;
|
|
421
422
|
let mastra = mastraOption;
|
|
422
423
|
const activeStreamUntilIdle = /* @__PURE__ */ new Map();
|
|
423
424
|
let proxyRef;
|
|
424
|
-
const workflow = createInngestDurableAgenticWorkflow({ inngest });
|
|
425
|
+
const workflow = createInngestDurableAgenticWorkflow({ inngest: inngest$1 });
|
|
425
426
|
let _customCache = cache;
|
|
426
|
-
let innerPubsub = customPubsub ?? new require_connect.InngestPubSub(inngest, InngestDurableStepIds.AGENTIC_LOOP);
|
|
427
|
+
let innerPubsub = customPubsub ?? new require_connect.InngestPubSub(inngest$1, InngestDurableStepIds.AGENTIC_LOOP);
|
|
427
428
|
let _cachingPubsub = null;
|
|
428
429
|
function resolveCache() {
|
|
429
430
|
const resolved = _customCache ?? mastra?.serverCache ?? new _mastra_core_cache.InMemoryServerCache();
|
|
@@ -449,17 +450,18 @@ function createInngestAgent(options) {
|
|
|
449
450
|
/**
|
|
450
451
|
* Trigger the workflow via Inngest event
|
|
451
452
|
*/
|
|
452
|
-
async function triggerWorkflow(runId, workflowInput, tracingOptions) {
|
|
453
|
+
async function triggerWorkflow(runId, workflowInput, tracingOptions, actor) {
|
|
453
454
|
const eventName = `workflow.${InngestDurableStepIds.AGENTIC_LOOP}`;
|
|
454
|
-
await inngest.send({
|
|
455
|
+
await inngest$1.send({
|
|
455
456
|
name: eventName,
|
|
456
|
-
data: {
|
|
457
|
+
data: require_connect.buildDurableTriggerEventData({
|
|
457
458
|
inputData: workflowInput,
|
|
458
459
|
runId,
|
|
459
460
|
resourceId: workflowInput.state?.resourceId,
|
|
460
461
|
requestContext: workflowInput.requestContextEntries ?? {},
|
|
461
|
-
tracingOptions
|
|
462
|
-
|
|
462
|
+
tracingOptions,
|
|
463
|
+
actor
|
|
464
|
+
})
|
|
463
465
|
});
|
|
464
466
|
}
|
|
465
467
|
/**
|
|
@@ -503,7 +505,7 @@ function createInngestAgent(options) {
|
|
|
503
505
|
return agent;
|
|
504
506
|
},
|
|
505
507
|
get inngest() {
|
|
506
|
-
return inngest;
|
|
508
|
+
return inngest$1;
|
|
507
509
|
},
|
|
508
510
|
get cache() {
|
|
509
511
|
return getCache();
|
|
@@ -529,7 +531,10 @@ function createInngestAgent(options) {
|
|
|
529
531
|
options: streamOptions,
|
|
530
532
|
runId: streamOptions?.runId,
|
|
531
533
|
requestContext: streamOptions?.requestContext,
|
|
532
|
-
methodType: streamOptions?.__methodType ?? "stream"
|
|
534
|
+
methodType: streamOptions?.__methodType ?? "stream",
|
|
535
|
+
mastra,
|
|
536
|
+
durableAgentId: agentId,
|
|
537
|
+
durableAgentName: agentName
|
|
533
538
|
});
|
|
534
539
|
workflowInput.agentId = agentId;
|
|
535
540
|
workflowInput.agentName = agentName;
|
|
@@ -542,33 +547,6 @@ function createInngestAgent(options) {
|
|
|
542
547
|
registryEntry.abortController = abortController;
|
|
543
548
|
registryEntry.abortSignal = abortController.signal;
|
|
544
549
|
_mastra_core_agent_durable.globalRunRegistry.set(runId, registryEntry);
|
|
545
|
-
const agentSpan = (mastra?.observability?.getSelectedInstance({ requestContext: streamOptions?.requestContext }))?.startSpan({
|
|
546
|
-
type: _mastra_core_observability.SpanType.AGENT_RUN,
|
|
547
|
-
name: `agent run: '${agentId}'`,
|
|
548
|
-
entityType: _mastra_core_observability.EntityType.AGENT,
|
|
549
|
-
entityId: agentId,
|
|
550
|
-
entityName: agentName,
|
|
551
|
-
input: workflowInput.messageListState,
|
|
552
|
-
metadata: {
|
|
553
|
-
runId,
|
|
554
|
-
threadId,
|
|
555
|
-
resourceId
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
const agentSpanData = agentSpan?.exportSpan();
|
|
559
|
-
const modelSpanData = (agentSpan?.createChildSpan({
|
|
560
|
-
type: _mastra_core_observability.SpanType.MODEL_GENERATION,
|
|
561
|
-
name: `llm: '${workflowInput.modelConfig.modelId}'`,
|
|
562
|
-
input: { messages: workflowInput.messageListState },
|
|
563
|
-
attributes: {
|
|
564
|
-
model: workflowInput.modelConfig.modelId,
|
|
565
|
-
provider: workflowInput.modelConfig.provider,
|
|
566
|
-
streaming: true,
|
|
567
|
-
parameters: { temperature: workflowInput.options?.modelSettings?.temperature }
|
|
568
|
-
}
|
|
569
|
-
}))?.exportSpan();
|
|
570
|
-
workflowInput.agentSpanData = agentSpanData;
|
|
571
|
-
workflowInput.modelSpanData = modelSpanData;
|
|
572
550
|
workflowInput.stepIndex = 0;
|
|
573
551
|
let cleanedUp = false;
|
|
574
552
|
const finalizeGlobalRegistry = () => {
|
|
@@ -616,11 +594,12 @@ function createInngestAgent(options) {
|
|
|
616
594
|
} : void 0,
|
|
617
595
|
closeOnSuspend: streamOptions?.[CLOSE_ON_SUSPEND] === true
|
|
618
596
|
});
|
|
619
|
-
const
|
|
597
|
+
const agentSpanData = workflowInput.agentSpanData;
|
|
598
|
+
const tracingOptions = agentSpanData?.traceId && agentSpanData?.id ? {
|
|
620
599
|
traceId: agentSpanData.traceId,
|
|
621
600
|
parentSpanId: agentSpanData.id
|
|
622
601
|
} : void 0;
|
|
623
|
-
const workflowExecution = ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions)).catch((error) => {
|
|
602
|
+
const workflowExecution = ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions, streamOptions?.actor)).catch((error) => {
|
|
624
603
|
emitError(runId, error);
|
|
625
604
|
});
|
|
626
605
|
const trackedEntry = _mastra_core_agent_durable.globalRunRegistry.get(runId);
|
|
@@ -719,40 +698,64 @@ function createInngestAgent(options) {
|
|
|
719
698
|
closeOnSuspend: resumeOptions?.[CLOSE_ON_SUSPEND] === true
|
|
720
699
|
});
|
|
721
700
|
const eventName = `workflow.${InngestDurableStepIds.AGENTIC_LOOP}`;
|
|
722
|
-
const
|
|
701
|
+
const dispatch = ready.then(async () => {
|
|
723
702
|
const snapshot = await (await mastra?.getStorage()?.getStore("workflows"))?.loadWorkflowSnapshot({
|
|
724
703
|
workflowName: InngestDurableStepIds.AGENTIC_LOOP,
|
|
725
704
|
runId
|
|
726
705
|
});
|
|
727
706
|
const suspendedStepIds = snapshot?.suspendedPaths ? Object.keys(snapshot.suspendedPaths) : [];
|
|
728
|
-
const
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
707
|
+
const resumeLabels = snapshot?.resumeLabels ?? {};
|
|
708
|
+
const toolCallId = resumeOptions?.toolCallId;
|
|
709
|
+
const expandToLeafPath = (stepId) => {
|
|
710
|
+
const nestedPath = (snapshot?.context ?? {})[stepId]?.suspendPayload?.__workflow_meta?.path;
|
|
711
|
+
return Array.isArray(nestedPath) ? [stepId, ...nestedPath] : [stepId];
|
|
732
712
|
};
|
|
713
|
+
let steps;
|
|
714
|
+
if (toolCallId) {
|
|
715
|
+
const targetStepId = resumeLabels[toolCallId]?.stepId;
|
|
716
|
+
if (!targetStepId) {
|
|
717
|
+
const available = Object.keys(resumeLabels);
|
|
718
|
+
throw new inngest.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.`));
|
|
719
|
+
}
|
|
720
|
+
steps = expandToLeafPath(targetStepId);
|
|
721
|
+
} else {
|
|
722
|
+
const available = Object.keys(resumeLabels);
|
|
723
|
+
if (suspendedStepIds.length > 1 || available.length > 1) throw new inngest.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(", ")}.` : ""));
|
|
724
|
+
steps = suspendedStepIds[0] ? expandToLeafPath(suspendedStepIds[0]) : [];
|
|
725
|
+
}
|
|
726
|
+
const requestContext = require_connect.mergeResumeRequestContext(snapshot?.requestContext, resumeOptions?.requestContext);
|
|
733
727
|
const tracingOptions = snapshot?.tracingContext ? {
|
|
734
728
|
traceId: snapshot.tracingContext.traceId,
|
|
735
729
|
parentSpanId: snapshot.tracingContext.spanId
|
|
736
730
|
} : void 0;
|
|
737
|
-
await inngest.send({
|
|
731
|
+
await inngest$1.send({
|
|
738
732
|
name: eventName,
|
|
739
|
-
data: {
|
|
733
|
+
data: require_connect.buildDurableResumeEventData({
|
|
740
734
|
inputData: resumeData,
|
|
741
735
|
runId,
|
|
742
736
|
resourceId: resumeOptions?.resourceId,
|
|
743
737
|
requestContext,
|
|
744
738
|
tracingOptions,
|
|
739
|
+
actor: resumeOptions?.actor,
|
|
745
740
|
resume: {
|
|
746
741
|
steps,
|
|
747
742
|
resumePayload: resumeData,
|
|
748
743
|
resumePath: steps[0] ? snapshot?.suspendedPaths?.[steps[0]] : void 0
|
|
749
744
|
}
|
|
750
|
-
}
|
|
745
|
+
})
|
|
751
746
|
});
|
|
752
|
-
})
|
|
747
|
+
});
|
|
748
|
+
const workflowExecution = dispatch.catch((error) => {
|
|
753
749
|
emitError(runId, error);
|
|
754
750
|
});
|
|
755
751
|
existingEntry.workflowExecution = workflowExecution;
|
|
752
|
+
try {
|
|
753
|
+
await dispatch;
|
|
754
|
+
} catch (error) {
|
|
755
|
+
streamCleanup();
|
|
756
|
+
finalizeResumeRegistry();
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
756
759
|
const abort = async (reason) => {
|
|
757
760
|
if (!abortController.signal.aborted) abortController.abort(reason);
|
|
758
761
|
await requestRemoteAbort(runId);
|
|
@@ -779,7 +782,10 @@ function createInngestAgent(options) {
|
|
|
779
782
|
agent,
|
|
780
783
|
messages,
|
|
781
784
|
options: prepareOptions,
|
|
782
|
-
requestContext: prepareOptions?.requestContext
|
|
785
|
+
requestContext: prepareOptions?.requestContext,
|
|
786
|
+
mastra,
|
|
787
|
+
durableAgentId: agentId,
|
|
788
|
+
durableAgentName: agentName
|
|
783
789
|
});
|
|
784
790
|
preparation.workflowInput.agentId = agentId;
|
|
785
791
|
preparation.workflowInput.agentName = agentName;
|