@mastra/inngest 1.7.1-alpha.0 → 1.8.0-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/CHANGELOG.md +34 -0
- package/dist/durable-agent/create-inngest-agent.d.ts +126 -17
- package/dist/durable-agent/create-inngest-agent.d.ts.map +1 -1
- package/dist/index.cjs +223 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +224 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 1.8.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Bring `InngestAgent` (Inngest-backed durable agent) to parity with `DurableAgent` for per-call execution options, abort handling, idle-aware resume, and `generate()`. ([#18615](https://github.com/mastra-ai/mastra/pull/18615))
|
|
8
|
+
|
|
9
|
+
`InngestAgent.stream()` and `resume()` now accept the same execution-option surface as `DurableAgent`, including `stopWhen`, `activeTools`, `structuredOutput`, `versions`, `system`, `disableBackgroundTasks`, `tracingOptions`, `actor`, `transform`, `prepareStep`, `isTaskComplete`, `delegation`, function-form `requireToolApproval`, and the lifecycle callbacks `onAbort` / `onIterationComplete`. Closure-shaped options (`prepareStep`, `transform`, function-form `isTaskComplete` / `requireToolApproval`, `stopWhen` callbacks) continue to work in-process; they degrade after a worker hop the same way they do for in-memory `DurableAgent`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const result = await inngestAgent.stream(messages, {
|
|
13
|
+
runId: 'run-1',
|
|
14
|
+
abortSignal: controller.signal,
|
|
15
|
+
stopWhen: stepCountIs(5),
|
|
16
|
+
onIterationComplete: ({ iteration }) => console.log('done', iteration),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Cancel a live run from the caller
|
|
20
|
+
result.abort();
|
|
21
|
+
|
|
22
|
+
// Resume and drive the run to completion in a single call
|
|
23
|
+
await inngestAgent.resume({ runId: 'run-1', resumeData, untilIdle: true });
|
|
24
|
+
|
|
25
|
+
// Durable equivalents of Agent.generate / resumeGenerate
|
|
26
|
+
const out = await inngestAgent.generate(messages, { runId: 'run-2' });
|
|
27
|
+
const resumed = await inngestAgent.resumeGenerate({ runId: 'run-2', resumeData });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`@mastra/core` re-exports `globalRunRegistry` and `runResumeDurableStreamUntilIdle` from `@mastra/core/agent/durable` so durable-agent integrations can share the same registry and idle-wrapper plumbing.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [[`705ba98`](https://github.com/mastra-ai/mastra/commit/705ba98726d388a596e896225f237907ca6807a9), [`e62c108`](https://github.com/mastra-ai/mastra/commit/e62c108409dfd6a6cac0a48ec39c5cc81d24fd52), [`bfbbb01`](https://github.com/mastra-ai/mastra/commit/bfbbb01bd845ba54cdc0c678c277d08a7cb847e4)]:
|
|
35
|
+
- @mastra/core@1.48.0-alpha.4
|
|
36
|
+
|
|
3
37
|
## 1.7.1-alpha.0
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
|
@@ -41,7 +41,7 @@ import type { MessageListInput } from '@mastra/core/agent/message-list';
|
|
|
41
41
|
import type { MastraServerCache } from '@mastra/core/cache';
|
|
42
42
|
import type { PubSub } from '@mastra/core/events';
|
|
43
43
|
import type { Mastra } from '@mastra/core/mastra';
|
|
44
|
-
import type { MastraModelOutput, ChunkType } from '@mastra/core/stream';
|
|
44
|
+
import type { MastraModelOutput, ChunkType, FullOutput } from '@mastra/core/stream';
|
|
45
45
|
import type { Workflow } from '@mastra/core/workflows';
|
|
46
46
|
import type { Inngest } from 'inngest';
|
|
47
47
|
/**
|
|
@@ -70,7 +70,13 @@ export interface CreateInngestAgentOptions {
|
|
|
70
70
|
mastra?: Mastra;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* Options for InngestAgent.stream()
|
|
73
|
+
* Options for InngestAgent.stream().
|
|
74
|
+
*
|
|
75
|
+
* Mirrors `DurableAgentStreamOptions` from `@mastra/core/agent/durable` so that
|
|
76
|
+
* Inngest-backed durable agents accept the same execution surface as the
|
|
77
|
+
* in-memory `DurableAgent`. Most options flow straight through
|
|
78
|
+
* `prepareForDurableExecution` and onto the shared workflow steps; see
|
|
79
|
+
* `.context/durable-agent-parity.md` for the per-option durability matrix.
|
|
74
80
|
*/
|
|
75
81
|
export interface InngestAgentStreamOptions<OUTPUT = undefined> {
|
|
76
82
|
/** Custom instructions that override the agent's default instructions */
|
|
@@ -85,16 +91,25 @@ export interface InngestAgentStreamOptions<OUTPUT = undefined> {
|
|
|
85
91
|
requestContext?: AgentExecutionOptions<OUTPUT>['requestContext'];
|
|
86
92
|
/** Maximum number of steps */
|
|
87
93
|
maxSteps?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Stop condition(s) for the agentic loop. Data-shaped conditions are
|
|
96
|
+
* serialized into the workflow snapshot; function-form conditions are stored
|
|
97
|
+
* on the in-process run registry and degrade to "no extra stop" on a
|
|
98
|
+
* cross-worker resume (same as core DurableAgent).
|
|
99
|
+
*/
|
|
100
|
+
stopWhen?: AgentExecutionOptions<OUTPUT>['stopWhen'];
|
|
88
101
|
/** Additional tool sets */
|
|
89
102
|
toolsets?: AgentExecutionOptions<OUTPUT>['toolsets'];
|
|
90
103
|
/** Client-side tools */
|
|
91
104
|
clientTools?: AgentExecutionOptions<OUTPUT>['clientTools'];
|
|
92
105
|
/** Tool selection strategy */
|
|
93
106
|
toolChoice?: AgentExecutionOptions<OUTPUT>['toolChoice'];
|
|
107
|
+
/** Tool names enabled for this execution */
|
|
108
|
+
activeTools?: AgentExecutionOptions<OUTPUT>['activeTools'];
|
|
94
109
|
/** Model settings */
|
|
95
110
|
modelSettings?: AgentExecutionOptions<OUTPUT>['modelSettings'];
|
|
96
|
-
/** Require approval for
|
|
97
|
-
requireToolApproval?:
|
|
111
|
+
/** Require approval for tool calls. Boolean (gate all / none) or a per-call function policy. */
|
|
112
|
+
requireToolApproval?: AgentExecutionOptions<OUTPUT>['requireToolApproval'];
|
|
98
113
|
/** Automatically resume suspended tools */
|
|
99
114
|
autoResumeSuspendedTools?: boolean;
|
|
100
115
|
/** Maximum concurrent tool calls */
|
|
@@ -103,6 +118,43 @@ export interface InngestAgentStreamOptions<OUTPUT = undefined> {
|
|
|
103
118
|
includeRawChunks?: boolean;
|
|
104
119
|
/** Maximum processor retries */
|
|
105
120
|
maxProcessorRetries?: number;
|
|
121
|
+
/** Structured output configuration */
|
|
122
|
+
structuredOutput?: AgentExecutionOptions<OUTPUT>['structuredOutput'];
|
|
123
|
+
/** Version overrides for sub-agent delegation */
|
|
124
|
+
versions?: AgentExecutionOptions<OUTPUT>['versions'];
|
|
125
|
+
/** Additional system message appended after context but before user messages. */
|
|
126
|
+
system?: AgentExecutionOptions<OUTPUT>['system'];
|
|
127
|
+
/** When true, background tasks are disabled for this run. */
|
|
128
|
+
disableBackgroundTasks?: AgentExecutionOptions<OUTPUT>['disableBackgroundTasks'];
|
|
129
|
+
/** Tracing options forwarded to the agent/model spans. */
|
|
130
|
+
tracingOptions?: AgentExecutionOptions<OUTPUT>['tracingOptions'];
|
|
131
|
+
/** Per-call actor signal forwarded to FGA checks and tool execution. */
|
|
132
|
+
actor?: AgentExecutionOptions<OUTPUT>['actor'];
|
|
133
|
+
/**
|
|
134
|
+
* Tool payload transform policy. `targets` is JSON-safe and persisted in the
|
|
135
|
+
* workflow snapshot; `transformToolPayload` is a closure on the run registry
|
|
136
|
+
* and degrades on cross-worker resume.
|
|
137
|
+
*/
|
|
138
|
+
transform?: AgentExecutionOptions<OUTPUT>['transform'];
|
|
139
|
+
/**
|
|
140
|
+
* Per-step preparation hook. Stored on the run registry and applied via a
|
|
141
|
+
* processor in the durable LLM step. Closure — degrades on cross-worker
|
|
142
|
+
* resume.
|
|
143
|
+
*/
|
|
144
|
+
prepareStep?: AgentExecutionOptions<OUTPUT>['prepareStep'];
|
|
145
|
+
/**
|
|
146
|
+
* Optional completion config (scorers + onComplete + suppressFeedback).
|
|
147
|
+
* JSON-safe parts are serialized; the `onComplete` callback lives on the run
|
|
148
|
+
* registry and degrades on cross-worker resume.
|
|
149
|
+
*/
|
|
150
|
+
isTaskComplete?: AgentExecutionOptions<OUTPUT>['isTaskComplete'];
|
|
151
|
+
/**
|
|
152
|
+
* Sub-agent delegation hooks. Forwarded into `convertTools` at prepare time
|
|
153
|
+
* and baked into the sub-agent tool wrappers stored on the run registry.
|
|
154
|
+
* Cross-worker resume on a fresh worker loses the callbacks and degrades to
|
|
155
|
+
* the agent's default delegation.
|
|
156
|
+
*/
|
|
157
|
+
delegation?: AgentExecutionOptions<OUTPUT>['delegation'];
|
|
106
158
|
/** Callback when chunk is received */
|
|
107
159
|
onChunk?: (chunk: ChunkType<OUTPUT>) => void | Promise<void>;
|
|
108
160
|
/** Callback when step finishes */
|
|
@@ -113,6 +165,17 @@ export interface InngestAgentStreamOptions<OUTPUT = undefined> {
|
|
|
113
165
|
onError?: (error: Error) => void | Promise<void>;
|
|
114
166
|
/** Callback when workflow suspends */
|
|
115
167
|
onSuspended?: (data: AgentSuspendedEventData) => void | Promise<void>;
|
|
168
|
+
/** Callback when execution is aborted via abortSignal or `result.abort()` */
|
|
169
|
+
onAbort?: AgentExecutionOptions<OUTPUT>['onAbort'];
|
|
170
|
+
/** Callback fired after each agentic-loop iteration (observation only) */
|
|
171
|
+
onIterationComplete?: AgentExecutionOptions<OUTPUT>['onIterationComplete'];
|
|
172
|
+
/**
|
|
173
|
+
* Optional external abort signal. Forwarded onto an internal AbortController
|
|
174
|
+
* stored on the run registry. Either the external signal or
|
|
175
|
+
* `result.abort()` will cancel the stream and emit an ABORT event over
|
|
176
|
+
* pubsub.
|
|
177
|
+
*/
|
|
178
|
+
abortSignal?: AbortSignal;
|
|
116
179
|
/**
|
|
117
180
|
* When set, `stream()` delegates to the idle-loop wrapper that keeps the
|
|
118
181
|
* outer stream open across background-task continuations.
|
|
@@ -142,6 +205,44 @@ export interface InngestAgentStreamResult<OUTPUT = undefined> {
|
|
|
142
205
|
resourceId?: string;
|
|
143
206
|
/** Cleanup function */
|
|
144
207
|
cleanup: () => void;
|
|
208
|
+
/**
|
|
209
|
+
* Abort this run. Flips the internal AbortController for this stream so the
|
|
210
|
+
* durable LLM step short-circuits (when the step worker shares the same
|
|
211
|
+
* process) and emits an ABORT event over pubsub so the consumer stream
|
|
212
|
+
* closes. Safe to call after the run has already finished.
|
|
213
|
+
*/
|
|
214
|
+
abort: (reason?: unknown) => void;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Options for InngestAgent.resume(). Mirrors core DurableAgent.resume().
|
|
218
|
+
*/
|
|
219
|
+
export interface InngestAgentResumeOptions<OUTPUT = undefined> {
|
|
220
|
+
threadId?: string;
|
|
221
|
+
resourceId?: string;
|
|
222
|
+
onChunk?: (chunk: ChunkType<OUTPUT>) => void | Promise<void>;
|
|
223
|
+
onStepFinish?: (result: AgentStepFinishEventData) => void | Promise<void>;
|
|
224
|
+
onFinish?: (result: AgentFinishEventData) => void | Promise<void>;
|
|
225
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
226
|
+
onSuspended?: (data: AgentSuspendedEventData) => void | Promise<void>;
|
|
227
|
+
/** Callback when execution is aborted via abortSignal or `result.abort()` */
|
|
228
|
+
onAbort?: AgentExecutionOptions<OUTPUT>['onAbort'];
|
|
229
|
+
/**
|
|
230
|
+
* Optional abort signal scoped to the resumed segment. Forwarded onto a
|
|
231
|
+
* fresh internal controller installed on the run's registry entry, so
|
|
232
|
+
* `result.abort()` and the external signal can both cancel the resumed
|
|
233
|
+
* iterations.
|
|
234
|
+
*/
|
|
235
|
+
abortSignal?: AbortSignal;
|
|
236
|
+
/**
|
|
237
|
+
* When set, keep the resumed segment open after the workflow's initial
|
|
238
|
+
* resume turn finishes and continue streaming follow-up turns until the
|
|
239
|
+
* agent goes idle (no in-flight background tasks for the same memory
|
|
240
|
+
* scope). Same semantics as `stream({ untilIdle })`. Pass an object to
|
|
241
|
+
* tune `maxIdleMs`.
|
|
242
|
+
*/
|
|
243
|
+
untilIdle?: boolean | {
|
|
244
|
+
maxIdleMs?: number;
|
|
245
|
+
};
|
|
145
246
|
}
|
|
146
247
|
/**
|
|
147
248
|
* An Inngest-powered durable agent.
|
|
@@ -178,15 +279,7 @@ export interface InngestAgent<TOutput = undefined> {
|
|
|
178
279
|
/**
|
|
179
280
|
* Resume a suspended workflow execution.
|
|
180
281
|
*/
|
|
181
|
-
resume(runId: string, resumeData: unknown, options?:
|
|
182
|
-
threadId?: string;
|
|
183
|
-
resourceId?: string;
|
|
184
|
-
onChunk?: (chunk: ChunkType<TOutput>) => void | Promise<void>;
|
|
185
|
-
onStepFinish?: (result: AgentStepFinishEventData) => void | Promise<void>;
|
|
186
|
-
onFinish?: (result: AgentFinishEventData) => void | Promise<void>;
|
|
187
|
-
onError?: (error: Error) => void | Promise<void>;
|
|
188
|
-
onSuspended?: (data: AgentSuspendedEventData) => void | Promise<void>;
|
|
189
|
-
}): Promise<InngestAgentStreamResult<TOutput>>;
|
|
282
|
+
resume(runId: string, resumeData: unknown, options?: InngestAgentResumeOptions<TOutput>): Promise<InngestAgentStreamResult<TOutput>>;
|
|
190
283
|
/**
|
|
191
284
|
* Prepare for durable execution without starting it.
|
|
192
285
|
*/
|
|
@@ -226,8 +319,26 @@ export interface InngestAgent<TOutput = undefined> {
|
|
|
226
319
|
* @internal
|
|
227
320
|
*/
|
|
228
321
|
__setMastra(mastra: Mastra): void;
|
|
229
|
-
/**
|
|
230
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Drain a durable run to a single {@link FullOutput}. Mirrors
|
|
324
|
+
* {@link DurableAgent.generate}: kicks off the same Inngest durable
|
|
325
|
+
* workflow as {@link InngestAgent.stream}, but threads
|
|
326
|
+
* `methodType: 'generate'` into preparation (so tool/preparation paths
|
|
327
|
+
* that branch on method behave consistently with non-durable
|
|
328
|
+
* `Agent.generate`) and awaits `output.getFullOutput()`.
|
|
329
|
+
*
|
|
330
|
+
* If the run suspends (e.g. tool approval), the returned output's
|
|
331
|
+
* `finishReason` is `'suspended'` — use {@link InngestAgent.resumeGenerate}
|
|
332
|
+
* to continue. The run registry entry is intentionally not cleaned up on
|
|
333
|
+
* suspend so resume can pick it up.
|
|
334
|
+
*/
|
|
335
|
+
generate(messages: MessageListInput, options?: InngestAgentStreamOptions<TOutput>): Promise<FullOutput<TOutput>>;
|
|
336
|
+
/**
|
|
337
|
+
* Resume a suspended durable run and drain it to a single
|
|
338
|
+
* {@link FullOutput}. Mirrors {@link DurableAgent.resumeGenerate} on top
|
|
339
|
+
* of {@link InngestAgent.resume}.
|
|
340
|
+
*/
|
|
341
|
+
resumeGenerate(runId: string, resumeData: unknown, options?: InngestAgentResumeOptions<TOutput>): Promise<FullOutput<TOutput>>;
|
|
231
342
|
/** Get the agent's description. Forwarded to the underlying Agent. */
|
|
232
343
|
getDescription(): string;
|
|
233
344
|
/** Get the agent's instructions. Forwarded to the underlying Agent. */
|
|
@@ -262,8 +373,6 @@ export interface InngestAgent<TOutput = undefined> {
|
|
|
262
373
|
toRawConfig(...args: any[]): any;
|
|
263
374
|
/** Resume a streaming execution. Forwarded to the underlying Agent. */
|
|
264
375
|
resumeStream(...args: any[]): any;
|
|
265
|
-
/** Resume a generate execution. Forwarded to the underlying Agent. */
|
|
266
|
-
resumeGenerate(...args: any[]): any;
|
|
267
376
|
/** Approve a pending tool call. Forwarded to the underlying Agent. */
|
|
268
377
|
approveToolCall(...args: any[]): any;
|
|
269
378
|
/** @internal Update the agent's model. Forwarded to the underlying Agent. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-inngest-agent.d.ts","sourceRoot":"","sources":["../../src/durable-agent/create-inngest-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAA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5E,sBAAsB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAC5C,+DAA+D;IAC/D,WAAW,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IACjC,wEAAwE;IACxE,oBAAoB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAC1C,6EAA6E;IAC7E,gBAAgB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;CACvC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,yBAAyB,GAAG,YAAY,CAAC,OAAO,CAAC,CAutBjH;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAU5D"}
|
package/dist/index.cjs
CHANGED
|
@@ -298,6 +298,8 @@ function createInngestDurableAgenticWorkflow(options) {
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
// src/durable-agent/create-inngest-agent.ts
|
|
301
|
+
var CLOSE_ON_SUSPEND = /* @__PURE__ */ Symbol("mastra.durable.inngest.closeOnSuspend");
|
|
302
|
+
var STREAM_CLEANUP = /* @__PURE__ */ Symbol("mastra.durable.inngest.streamCleanup");
|
|
301
303
|
function createInngestAgent(options) {
|
|
302
304
|
const {
|
|
303
305
|
agent,
|
|
@@ -391,11 +393,28 @@ function createInngestAgent(options) {
|
|
|
391
393
|
messages,
|
|
392
394
|
options: streamOptions,
|
|
393
395
|
runId: streamOptions?.runId,
|
|
394
|
-
requestContext: streamOptions?.requestContext
|
|
396
|
+
requestContext: streamOptions?.requestContext,
|
|
397
|
+
methodType: streamOptions?.__methodType ?? "stream"
|
|
395
398
|
});
|
|
396
|
-
const { runId, messageId, workflowInput, threadId, resourceId } = preparation;
|
|
399
|
+
const { runId, messageId, workflowInput, registryEntry, threadId, resourceId } = preparation;
|
|
397
400
|
workflowInput.agentId = agentId;
|
|
398
401
|
workflowInput.agentName = agentName;
|
|
402
|
+
const abortController = new AbortController();
|
|
403
|
+
if (streamOptions?.abortSignal) {
|
|
404
|
+
const external = streamOptions.abortSignal;
|
|
405
|
+
if (external.aborted) {
|
|
406
|
+
abortController.abort(external.reason);
|
|
407
|
+
} else {
|
|
408
|
+
external.addEventListener(
|
|
409
|
+
"abort",
|
|
410
|
+
() => abortController.abort(external.reason),
|
|
411
|
+
{ once: true }
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
registryEntry.abortController = abortController;
|
|
416
|
+
registryEntry.abortSignal = abortController.signal;
|
|
417
|
+
durable.globalRunRegistry.set(runId, registryEntry);
|
|
399
418
|
const observability$1 = mastra?.observability?.getSelectedInstance({
|
|
400
419
|
requestContext: streamOptions?.requestContext
|
|
401
420
|
});
|
|
@@ -430,6 +449,12 @@ function createInngestAgent(options) {
|
|
|
430
449
|
workflowInput.agentSpanData = agentSpanData;
|
|
431
450
|
workflowInput.modelSpanData = modelSpanData;
|
|
432
451
|
workflowInput.stepIndex = 0;
|
|
452
|
+
let cleanedUp = false;
|
|
453
|
+
const finalizeGlobalRegistry = () => {
|
|
454
|
+
if (cleanedUp) return;
|
|
455
|
+
cleanedUp = true;
|
|
456
|
+
durable.globalRunRegistry.delete(runId);
|
|
457
|
+
};
|
|
433
458
|
const {
|
|
434
459
|
output,
|
|
435
460
|
cleanup: streamCleanup,
|
|
@@ -447,28 +472,114 @@ function createInngestAgent(options) {
|
|
|
447
472
|
resourceId,
|
|
448
473
|
onChunk: streamOptions?.onChunk,
|
|
449
474
|
onStepFinish: streamOptions?.onStepFinish,
|
|
450
|
-
onFinish:
|
|
451
|
-
|
|
452
|
-
|
|
475
|
+
onFinish: async (result3) => {
|
|
476
|
+
try {
|
|
477
|
+
await streamOptions?.onFinish?.(result3);
|
|
478
|
+
} finally {
|
|
479
|
+
finalizeGlobalRegistry();
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
onError: async (error) => {
|
|
483
|
+
try {
|
|
484
|
+
await streamOptions?.onError?.(error);
|
|
485
|
+
} finally {
|
|
486
|
+
finalizeGlobalRegistry();
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
onSuspended: streamOptions?.onSuspended,
|
|
490
|
+
onAbort: async (data) => {
|
|
491
|
+
try {
|
|
492
|
+
await streamOptions?.onAbort?.(data);
|
|
493
|
+
} finally {
|
|
494
|
+
finalizeGlobalRegistry();
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
onIterationComplete: streamOptions?.onIterationComplete ? async (data) => {
|
|
498
|
+
await streamOptions.onIterationComplete?.(data);
|
|
499
|
+
} : void 0,
|
|
500
|
+
closeOnSuspend: streamOptions?.[CLOSE_ON_SUSPEND] === true
|
|
453
501
|
});
|
|
454
502
|
const tracingOptions = agentSpanData ? { traceId: agentSpanData.traceId, parentSpanId: agentSpanData.id } : void 0;
|
|
455
|
-
ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions)).catch((error) => {
|
|
503
|
+
const workflowExecution = ready.then(() => triggerWorkflow(runId, workflowInput, tracingOptions)).catch((error) => {
|
|
456
504
|
void emitError(runId, error);
|
|
457
505
|
});
|
|
506
|
+
const trackedEntry = durable.globalRunRegistry.get(runId);
|
|
507
|
+
if (trackedEntry) {
|
|
508
|
+
trackedEntry.workflowExecution = workflowExecution;
|
|
509
|
+
}
|
|
510
|
+
const cleanup = () => {
|
|
511
|
+
streamCleanup();
|
|
512
|
+
finalizeGlobalRegistry();
|
|
513
|
+
};
|
|
514
|
+
const abort = (reason) => {
|
|
515
|
+
if (!abortController.signal.aborted) {
|
|
516
|
+
abortController.abort(reason);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
458
519
|
const result2 = {
|
|
459
520
|
output,
|
|
460
521
|
runId,
|
|
461
522
|
threadId,
|
|
462
523
|
resourceId,
|
|
463
|
-
cleanup
|
|
524
|
+
cleanup,
|
|
525
|
+
abort,
|
|
464
526
|
// Also expose fullStream directly for server compatibility
|
|
465
527
|
get fullStream() {
|
|
466
528
|
return output.fullStream;
|
|
467
|
-
}
|
|
529
|
+
},
|
|
530
|
+
// Internal: stream-only cleanup for generate()/resumeGenerate() to
|
|
531
|
+
// release the subscription on suspend without dropping the registry.
|
|
532
|
+
[STREAM_CLEANUP]: streamCleanup
|
|
468
533
|
};
|
|
469
534
|
return result2;
|
|
470
535
|
},
|
|
471
536
|
async resume(runId, resumeData, resumeOptions) {
|
|
537
|
+
if (resumeOptions?.untilIdle) {
|
|
538
|
+
const { untilIdle, ...rest } = resumeOptions;
|
|
539
|
+
const maxIdleMs = typeof untilIdle === "object" ? untilIdle.maxIdleMs : void 0;
|
|
540
|
+
return durable.runResumeDurableStreamUntilIdle(
|
|
541
|
+
proxyRef,
|
|
542
|
+
runId,
|
|
543
|
+
resumeData,
|
|
544
|
+
{ ...rest, maxIdleMs },
|
|
545
|
+
{
|
|
546
|
+
activeStreams: activeStreamUntilIdle,
|
|
547
|
+
bgManager: mastra?.backgroundTaskManager
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
const abortController = new AbortController();
|
|
552
|
+
if (resumeOptions?.abortSignal) {
|
|
553
|
+
const external = resumeOptions.abortSignal;
|
|
554
|
+
if (external.aborted) {
|
|
555
|
+
abortController.abort(external.reason);
|
|
556
|
+
} else {
|
|
557
|
+
external.addEventListener(
|
|
558
|
+
"abort",
|
|
559
|
+
() => abortController.abort(external.reason),
|
|
560
|
+
{ once: true }
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
let existingEntry = durable.globalRunRegistry.get(runId);
|
|
565
|
+
if (!existingEntry) {
|
|
566
|
+
existingEntry = {
|
|
567
|
+
// Minimal placeholder fields. The durable LLM step recreates tools
|
|
568
|
+
// and model from the workflow input; this slot exists primarily to
|
|
569
|
+
// carry the abort controller across the resumed segment.
|
|
570
|
+
tools: {},
|
|
571
|
+
model: void 0
|
|
572
|
+
};
|
|
573
|
+
durable.globalRunRegistry.set(runId, existingEntry);
|
|
574
|
+
}
|
|
575
|
+
existingEntry.abortController = abortController;
|
|
576
|
+
existingEntry.abortSignal = abortController.signal;
|
|
577
|
+
let resumeCleanedUp = false;
|
|
578
|
+
const finalizeResumeRegistry = () => {
|
|
579
|
+
if (resumeCleanedUp) return;
|
|
580
|
+
resumeCleanedUp = true;
|
|
581
|
+
durable.globalRunRegistry.delete(runId);
|
|
582
|
+
};
|
|
472
583
|
const {
|
|
473
584
|
output,
|
|
474
585
|
cleanup: streamCleanup,
|
|
@@ -486,12 +597,32 @@ function createInngestAgent(options) {
|
|
|
486
597
|
resourceId: resumeOptions?.resourceId,
|
|
487
598
|
onChunk: resumeOptions?.onChunk,
|
|
488
599
|
onStepFinish: resumeOptions?.onStepFinish,
|
|
489
|
-
onFinish:
|
|
490
|
-
|
|
491
|
-
|
|
600
|
+
onFinish: async (result2) => {
|
|
601
|
+
try {
|
|
602
|
+
await resumeOptions?.onFinish?.(result2);
|
|
603
|
+
} finally {
|
|
604
|
+
finalizeResumeRegistry();
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
onError: async (error) => {
|
|
608
|
+
try {
|
|
609
|
+
await resumeOptions?.onError?.(error);
|
|
610
|
+
} finally {
|
|
611
|
+
finalizeResumeRegistry();
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
onSuspended: resumeOptions?.onSuspended,
|
|
615
|
+
onAbort: async (data) => {
|
|
616
|
+
try {
|
|
617
|
+
await resumeOptions?.onAbort?.(data);
|
|
618
|
+
} finally {
|
|
619
|
+
finalizeResumeRegistry();
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
closeOnSuspend: resumeOptions?.[CLOSE_ON_SUSPEND] === true
|
|
492
623
|
});
|
|
493
624
|
const eventName = `workflow.${InngestDurableStepIds.AGENTIC_LOOP}`;
|
|
494
|
-
ready.then(async () => {
|
|
625
|
+
const workflowExecution = ready.then(async () => {
|
|
495
626
|
const workflowsStore = await mastra?.getStorage()?.getStore("workflows");
|
|
496
627
|
const snapshot = await workflowsStore?.loadWorkflowSnapshot({
|
|
497
628
|
workflowName: InngestDurableStepIds.AGENTIC_LOOP,
|
|
@@ -519,6 +650,16 @@ function createInngestAgent(options) {
|
|
|
519
650
|
}).catch((error) => {
|
|
520
651
|
void emitError(runId, error);
|
|
521
652
|
});
|
|
653
|
+
existingEntry.workflowExecution = workflowExecution;
|
|
654
|
+
const abort = (reason) => {
|
|
655
|
+
if (!abortController.signal.aborted) {
|
|
656
|
+
abortController.abort(reason);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const cleanup = () => {
|
|
660
|
+
streamCleanup();
|
|
661
|
+
finalizeResumeRegistry();
|
|
662
|
+
};
|
|
522
663
|
return {
|
|
523
664
|
output,
|
|
524
665
|
get fullStream() {
|
|
@@ -527,7 +668,11 @@ function createInngestAgent(options) {
|
|
|
527
668
|
runId,
|
|
528
669
|
threadId: resumeOptions?.threadId,
|
|
529
670
|
resourceId: resumeOptions?.resourceId,
|
|
530
|
-
cleanup
|
|
671
|
+
cleanup,
|
|
672
|
+
abort,
|
|
673
|
+
// Internal: stream-only cleanup for resumeGenerate() to release the
|
|
674
|
+
// subscription on suspend without dropping the resumed registry entry.
|
|
675
|
+
[STREAM_CLEANUP]: streamCleanup
|
|
531
676
|
};
|
|
532
677
|
},
|
|
533
678
|
async prepare(messages, prepareOptions) {
|
|
@@ -569,14 +714,78 @@ function createInngestAgent(options) {
|
|
|
569
714
|
onSuspended: observeOptions?.onSuspended
|
|
570
715
|
});
|
|
571
716
|
await ready;
|
|
717
|
+
const abort = (_reason) => {
|
|
718
|
+
streamCleanup();
|
|
719
|
+
};
|
|
572
720
|
return {
|
|
573
721
|
output,
|
|
574
722
|
get fullStream() {
|
|
575
723
|
return output.fullStream;
|
|
576
724
|
},
|
|
577
725
|
runId,
|
|
578
|
-
cleanup: streamCleanup
|
|
726
|
+
cleanup: streamCleanup,
|
|
727
|
+
abort
|
|
728
|
+
};
|
|
729
|
+
},
|
|
730
|
+
async generate(messages, generateOptions) {
|
|
731
|
+
const { untilIdle, ...rest } = generateOptions ?? {};
|
|
732
|
+
const streamOpts = {
|
|
733
|
+
...rest,
|
|
734
|
+
[CLOSE_ON_SUSPEND]: true,
|
|
735
|
+
__methodType: "generate"
|
|
579
736
|
};
|
|
737
|
+
const result2 = await proxyRef.stream(messages, streamOpts);
|
|
738
|
+
let suspended = false;
|
|
739
|
+
try {
|
|
740
|
+
const fullOutput = await result2.output.getFullOutput();
|
|
741
|
+
if (fullOutput.error) {
|
|
742
|
+
throw fullOutput.error;
|
|
743
|
+
}
|
|
744
|
+
suspended = fullOutput.finishReason === "suspended";
|
|
745
|
+
if (suspended) {
|
|
746
|
+
await durable.globalRunRegistry.get(result2.runId)?.workflowExecution;
|
|
747
|
+
}
|
|
748
|
+
if (!fullOutput.runId) {
|
|
749
|
+
fullOutput.runId = result2.runId;
|
|
750
|
+
}
|
|
751
|
+
return fullOutput;
|
|
752
|
+
} finally {
|
|
753
|
+
if (suspended) {
|
|
754
|
+
const streamOnlyCleanup = result2[STREAM_CLEANUP];
|
|
755
|
+
streamOnlyCleanup?.();
|
|
756
|
+
} else {
|
|
757
|
+
result2.cleanup();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
async resumeGenerate(runId, resumeData, resumeOptions) {
|
|
762
|
+
const { untilIdle, ...rest } = resumeOptions ?? {};
|
|
763
|
+
const result2 = await proxyRef.resume(runId, resumeData, {
|
|
764
|
+
...rest,
|
|
765
|
+
[CLOSE_ON_SUSPEND]: true
|
|
766
|
+
});
|
|
767
|
+
let suspended = false;
|
|
768
|
+
try {
|
|
769
|
+
const fullOutput = await result2.output.getFullOutput();
|
|
770
|
+
if (fullOutput.error) {
|
|
771
|
+
throw fullOutput.error;
|
|
772
|
+
}
|
|
773
|
+
suspended = fullOutput.finishReason === "suspended";
|
|
774
|
+
if (suspended) {
|
|
775
|
+
await durable.globalRunRegistry.get(result2.runId)?.workflowExecution;
|
|
776
|
+
}
|
|
777
|
+
if (!fullOutput.runId) {
|
|
778
|
+
fullOutput.runId = result2.runId;
|
|
779
|
+
}
|
|
780
|
+
return fullOutput;
|
|
781
|
+
} finally {
|
|
782
|
+
if (suspended) {
|
|
783
|
+
const streamOnlyCleanup = result2[STREAM_CLEANUP];
|
|
784
|
+
streamOnlyCleanup?.();
|
|
785
|
+
} else {
|
|
786
|
+
result2.cleanup();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
580
789
|
},
|
|
581
790
|
getDurableWorkflows() {
|
|
582
791
|
return [workflow];
|