@mastra/inngest 1.11.4 → 1.11.5-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/dist/connect.cjs +1 -1
- package/dist/connect.js +1 -1
- package/dist/durable-agent/create-inngest-agent.d.ts +4 -0
- package/dist/durable-agent/create-inngest-agent.d.ts.map +1 -1
- package/dist/durable-agent/create-inngest-agentic-workflow.d.ts +2 -0
- package/dist/durable-agent/create-inngest-agentic-workflow.d.ts.map +1 -1
- package/dist/execution-engine.d.ts +11 -2
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/observability-compat.d.ts +18 -0
- package/dist/observability-compat.d.ts.map +1 -1
- package/dist/{src-BrTLEx4Z.cjs → src-BrPOwm__.cjs} +187 -20
- package/dist/src-BrPOwm__.cjs.map +1 -0
- package/dist/{src-hK_U-MJ5.js → src-CAadC9Do.js} +188 -21
- package/dist/src-CAadC9Do.js.map +1 -0
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/src-BrTLEx4Z.cjs.map +0 -1
- package/dist/src-hK_U-MJ5.js.map +0 -1
|
@@ -176,6 +176,31 @@ function generationUsage(usage, steps) {
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
|
+
* Whether the durable steps of this core end the span pair a resume carries on the request context.
|
|
180
|
+
* Without it a resume opens no pair, since no worker would end it.
|
|
181
|
+
*/
|
|
182
|
+
function carriesSegmentSpans() {
|
|
183
|
+
return _mastra_core_features.coreFeatures.has("durable-segment-spans");
|
|
184
|
+
}
|
|
185
|
+
/** Record the pair a resume opened, or `null` for none, for the workers' steps; a no-op on older cores. */
|
|
186
|
+
function carrySegmentSpans(...args) {
|
|
187
|
+
if (carriesSegmentSpans()) _mastra_core_agent_durable.carrySegmentSpans?.(...args);
|
|
188
|
+
}
|
|
189
|
+
/** The pair the current execution reports under; an older core reports under the run's first pair. */
|
|
190
|
+
function segmentSpanData(...args) {
|
|
191
|
+
if (carriesSegmentSpans()) return _mastra_core_agent_durable.segmentSpanData?.(...args) ?? {};
|
|
192
|
+
const [, , state] = args;
|
|
193
|
+
return {
|
|
194
|
+
agentSpanData: state.agentSpanData,
|
|
195
|
+
modelSpanData: state.modelSpanData
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** The live span behind `data` held by this process; an older core ends the first live span it holds. */
|
|
199
|
+
function liveSegmentSpan(data, ...candidates) {
|
|
200
|
+
if (carriesSegmentSpans()) return _mastra_core_agent_durable.liveSegmentSpan?.(data, ...candidates);
|
|
201
|
+
return candidates.find((span) => span !== void 0);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
179
204
|
* The context a suspending workflow run saves for its resume. A core without the helper saves the
|
|
180
205
|
* lineage alone, and its resume samples again.
|
|
181
206
|
*/
|
|
@@ -208,15 +233,17 @@ const BUILTIN_ERROR_TYPES = [
|
|
|
208
233
|
var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecutionEngine {
|
|
209
234
|
parentStream;
|
|
210
235
|
inngestRunId;
|
|
236
|
+
workflowSpan;
|
|
211
237
|
inngestStep;
|
|
212
238
|
inngestAttempts;
|
|
213
|
-
constructor(mastra, inngestStep, inngestAttempts = 0, options, parentStream, inngestRunId) {
|
|
239
|
+
constructor(mastra, inngestStep, inngestAttempts = 0, options, parentStream, inngestRunId, workflowSpan) {
|
|
214
240
|
super({
|
|
215
241
|
mastra,
|
|
216
242
|
options
|
|
217
243
|
});
|
|
218
244
|
this.parentStream = parentStream;
|
|
219
245
|
this.inngestRunId = inngestRunId;
|
|
246
|
+
this.workflowSpan = workflowSpan;
|
|
220
247
|
this.inngestStep = inngestStep;
|
|
221
248
|
this.inngestAttempts = inngestAttempts;
|
|
222
249
|
}
|
|
@@ -421,6 +448,13 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
421
448
|
return super.invokeLifecycleCallbacks(result);
|
|
422
449
|
}
|
|
423
450
|
/**
|
|
451
|
+
* The trace's hidden input/output and request context keys. A live parent hands them down;
|
|
452
|
+
* spans here start from ids, so they take them from the nearest parent.
|
|
453
|
+
*/
|
|
454
|
+
inheritedTraceState(parentSpan) {
|
|
455
|
+
return (parentSpan ?? this.workflowSpan)?.traceState;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
424
458
|
* Create a step span durably - on first execution, creates and exports span.
|
|
425
459
|
* On replay, returns cached span data without re-creating.
|
|
426
460
|
*/
|
|
@@ -435,7 +469,9 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
435
469
|
...options,
|
|
436
470
|
entityType: options.entityType,
|
|
437
471
|
traceId: parentSpan?.traceId ?? executionContext.tracingIds?.traceId,
|
|
438
|
-
parentSpanId
|
|
472
|
+
parentSpanId,
|
|
473
|
+
samplingDecision: executionContext.tracingIds?.sampled,
|
|
474
|
+
traceState: this.inheritedTraceState(parentSpan)
|
|
439
475
|
});
|
|
440
476
|
return span?.snapshot?.() ?? span?.exportSpan();
|
|
441
477
|
});
|
|
@@ -478,6 +514,8 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
478
514
|
...options,
|
|
479
515
|
traceId: parentSpan?.traceId ?? executionContext.tracingIds?.traceId,
|
|
480
516
|
parentSpanId,
|
|
517
|
+
samplingDecision: executionContext.tracingIds?.sampled,
|
|
518
|
+
traceState: this.inheritedTraceState(parentSpan),
|
|
481
519
|
tracingPolicy: this.options?.tracingPolicy
|
|
482
520
|
});
|
|
483
521
|
return span?.snapshot?.() ?? span?.exportSpan();
|
|
@@ -517,9 +555,13 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
517
555
|
if (!(params.step instanceof InngestWorkflow)) return null;
|
|
518
556
|
const { step, stepResults, executionContext, resume, timeTravel, prevOutput, inputData, pubsub, startedAt, perStep, stepSpan, actor, requestContext: parentRequestContext } = params;
|
|
519
557
|
const forwardedRequestContext = parentRequestContext ? this.serializeRequestContext(parentRequestContext) : inputData?.requestContextEntries ?? {};
|
|
558
|
+
const { hideInput, hideOutput, requestContextKeys } = this.inheritedTraceState(stepSpan) ?? {};
|
|
520
559
|
const nestedTracingContext = executionContext.tracingIds?.traceId ? {
|
|
521
560
|
traceId: executionContext.tracingIds.traceId,
|
|
522
|
-
parentSpanId: stepSpan?.id
|
|
561
|
+
parentSpanId: stepSpan?.id,
|
|
562
|
+
hideInput,
|
|
563
|
+
hideOutput,
|
|
564
|
+
requestContextKeys
|
|
523
565
|
} : void 0;
|
|
524
566
|
const parentStream = this.parentStream ?? {
|
|
525
567
|
workflowId: executionContext.workflowId,
|
|
@@ -571,6 +613,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
571
613
|
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
572
614
|
perStep,
|
|
573
615
|
tracingOptions: nestedTracingContext,
|
|
616
|
+
parentSampled: executionContext.tracingIds?.sampled,
|
|
574
617
|
actor
|
|
575
618
|
}
|
|
576
619
|
});
|
|
@@ -606,6 +649,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
606
649
|
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
607
650
|
perStep,
|
|
608
651
|
tracingOptions: nestedTracingContext,
|
|
652
|
+
parentSampled: executionContext.tracingIds?.sampled,
|
|
609
653
|
actor
|
|
610
654
|
}
|
|
611
655
|
});
|
|
@@ -629,6 +673,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
629
673
|
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
630
674
|
perStep,
|
|
631
675
|
tracingOptions: nestedTracingContext,
|
|
676
|
+
parentSampled: executionContext.tracingIds?.sampled,
|
|
632
677
|
actor
|
|
633
678
|
}
|
|
634
679
|
});
|
|
@@ -2156,7 +2201,7 @@ var InngestWorkflow = class extends _mastra_core_workflows.Workflow {
|
|
|
2156
2201
|
* @returns The workflow result and run identifier returned to Inngest.
|
|
2157
2202
|
*/
|
|
2158
2203
|
async ({ event, step, attempt, runId: inngestRunId }) => {
|
|
2159
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel, perStep, tracingOptions, actor, parentStream, nestedWorkflowOutputMode: requestedNestedWorkflowOutputMode } = event.data;
|
|
2204
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel, perStep, tracingOptions, parentSampled, actor, parentStream, nestedWorkflowOutputMode: requestedNestedWorkflowOutputMode } = event.data;
|
|
2160
2205
|
const shouldCompactNestedWorkflowOutput = resolveNestedWorkflowOutputMode(requestedNestedWorkflowOutputMode) === NESTED_WORKFLOW_OUTPUT_MODE.COMPACT;
|
|
2161
2206
|
if (!runId) {
|
|
2162
2207
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
@@ -2218,11 +2263,12 @@ var InngestWorkflow = class extends _mastra_core_workflows.Workflow {
|
|
|
2218
2263
|
tracingOptions,
|
|
2219
2264
|
requestContext,
|
|
2220
2265
|
resumeFrom: suspendedTracingContext,
|
|
2266
|
+
samplingDecision: parentSampled,
|
|
2221
2267
|
mastra
|
|
2222
2268
|
});
|
|
2223
2269
|
return span?.snapshot?.() ?? span?.exportSpan();
|
|
2224
2270
|
});
|
|
2225
|
-
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options, parentStream, inngestRunId);
|
|
2271
|
+
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options, parentStream, inngestRunId, workflowSpanData);
|
|
2226
2272
|
let result;
|
|
2227
2273
|
try {
|
|
2228
2274
|
result = await engine.execute({
|
|
@@ -2245,7 +2291,8 @@ var InngestWorkflow = class extends _mastra_core_workflows.Workflow {
|
|
|
2245
2291
|
workflowSpan: void 0,
|
|
2246
2292
|
tracingIds: workflowSpanData ? {
|
|
2247
2293
|
traceId: workflowSpanData.traceId,
|
|
2248
|
-
workflowSpanId: workflowSpanData.id
|
|
2294
|
+
workflowSpanId: workflowSpanData.id,
|
|
2295
|
+
sampled: workflowResumeTracingContext(workflowSpanData)?.sampled
|
|
2249
2296
|
} : void 0,
|
|
2250
2297
|
outputOptions,
|
|
2251
2298
|
outputWriter: async (chunk) => {
|
|
@@ -2629,6 +2676,14 @@ const setLoopStatus = (store, runId, status, expectedStatus) => store.updateWork
|
|
|
2629
2676
|
}
|
|
2630
2677
|
});
|
|
2631
2678
|
/**
|
|
2679
|
+
* The agent span this execution reports under: live in this process, else rebuilt. A loop step's own
|
|
2680
|
+
* span is internal with no live parent, so spans and scores made in the step take this one instead.
|
|
2681
|
+
*/
|
|
2682
|
+
function segmentAgentSpan(requestContext, state, registry, mastra) {
|
|
2683
|
+
const { agentSpanData } = segmentSpanData(requestContext, state.runId, state, registry);
|
|
2684
|
+
return liveSegmentSpan(agentSpanData, registry?.resumeAgentSpan, registry?.agentSpan) ?? (agentSpanData ? mastra?.observability?.getSelectedInstance({ requestContext })?.rebuildSpan(agentSpanData) : void 0);
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2632
2687
|
* Ends a resumed segment Inngest failed or cancelled, which never reaches the finalize step that
|
|
2633
2688
|
* would: marks the run failed or canceled, ends its stream and releases its claim. The run is not
|
|
2634
2689
|
* parked again, since a nested segment Inngest did not cancel can still be running its tools.
|
|
@@ -2885,6 +2940,7 @@ function createAgenticLoopWorkflow(options) {
|
|
|
2885
2940
|
const state = inputData;
|
|
2886
2941
|
const tracingRegistry = (0, _mastra_core_agent_durable.getRunRegistryEntry)(state.runId, mastra);
|
|
2887
2942
|
const initData = params.getInitData();
|
|
2943
|
+
const agentSpan = segmentAgentSpan(requestContext, state, tracingRegistry, mastra);
|
|
2888
2944
|
const pubsub = params[_mastra_core_workflows__constants.PUBSUB_SYMBOL];
|
|
2889
2945
|
const resolveDeadlineError = () => {
|
|
2890
2946
|
const abortReason = tracingRegistry?.abortSignal?.aborted ? tracingRegistry.abortSignal.reason : void 0;
|
|
@@ -2903,7 +2959,7 @@ function createAgenticLoopWorkflow(options) {
|
|
|
2903
2959
|
messageListState: state.messageListState,
|
|
2904
2960
|
mastra,
|
|
2905
2961
|
requestContext,
|
|
2906
|
-
tracingContext,
|
|
2962
|
+
tracingContext: agentSpan ? { currentSpan: agentSpan } : tracingContext,
|
|
2907
2963
|
logger: mastra?.getLogger?.(),
|
|
2908
2964
|
messageId: state.messageId,
|
|
2909
2965
|
outputResult: {
|
|
@@ -2969,11 +3025,13 @@ function createAgenticLoopWorkflow(options) {
|
|
|
2969
3025
|
},
|
|
2970
3026
|
state: state.state
|
|
2971
3027
|
};
|
|
2972
|
-
const observability = mastra?.observability?.getSelectedInstance({});
|
|
3028
|
+
const observability = mastra?.observability?.getSelectedInstance({ requestContext });
|
|
2973
3029
|
const registry = (0, _mastra_core_agent_durable.getRunRegistryEntry)(state.runId, mastra);
|
|
2974
3030
|
const deadlineTermination = deadlineError && !tripwire ? executionFailureTermination(deadlineError) : void 0;
|
|
2975
|
-
const
|
|
2976
|
-
const
|
|
3031
|
+
const { agentSpanData, modelSpanData, carried } = segmentSpanData(requestContext, state.runId, state, registry);
|
|
3032
|
+
const firstPairClocks = carried ? void 0 : state;
|
|
3033
|
+
const completionClock = registry?.resumeModelSpan ? registry.resumeCompletionStartTime : firstPairClocks?.completionStartTime;
|
|
3034
|
+
const timeToFirstTokenMs = registry?.resumeModelSpan ? registry.resumeTimeToFirstTokenMs : firstPairClocks?.timeToFirstTokenMs;
|
|
2977
3035
|
const clocks = {
|
|
2978
3036
|
...completionClock ? { completionStartTime: new Date(completionClock) } : {},
|
|
2979
3037
|
...timeToFirstTokenMs !== void 0 ? { timeToFirstTokenMs } : {}
|
|
@@ -2989,8 +3047,8 @@ function createAgenticLoopWorkflow(options) {
|
|
|
2989
3047
|
tripwire: tripwire ?? state.lastStepResult?.tripwire,
|
|
2990
3048
|
maxSteps: state.options?.maxSteps ?? maxSteps
|
|
2991
3049
|
});
|
|
2992
|
-
if (
|
|
2993
|
-
const modelSpan = registry?.resumeModelSpan
|
|
3050
|
+
if (modelSpanData) {
|
|
3051
|
+
const modelSpan = liveSegmentSpan(modelSpanData, registry?.resumeModelSpan, registry?.modelSpan) ?? observability?.rebuildSpan(modelSpanData);
|
|
2994
3052
|
const toolCalls = state.accumulatedSteps.flatMap((step) => (step.toolCalls ?? []).map((tc) => ({
|
|
2995
3053
|
toolCallId: tc.toolCallId,
|
|
2996
3054
|
toolName: tc.toolName,
|
|
@@ -3013,7 +3071,7 @@ function createAgenticLoopWorkflow(options) {
|
|
|
3013
3071
|
usage
|
|
3014
3072
|
});
|
|
3015
3073
|
}
|
|
3016
|
-
if (
|
|
3074
|
+
if (agentSpanData) (liveSegmentSpan(agentSpanData, registry?.resumeAgentSpan, registry?.agentSpan) ?? observability?.rebuildSpan(agentSpanData))?.end({
|
|
3017
3075
|
...termination,
|
|
3018
3076
|
output: { text: finalText },
|
|
3019
3077
|
...Object.keys(clocks).length ? { attributes: clocks } : {}
|
|
@@ -3028,9 +3086,7 @@ function createAgenticLoopWorkflow(options) {
|
|
|
3028
3086
|
}, { id: "map-final-output" }).map(async (params) => {
|
|
3029
3087
|
const { inputData, getInitData, mastra, requestContext, tracingContext } = params;
|
|
3030
3088
|
const initData = getInitData();
|
|
3031
|
-
const
|
|
3032
|
-
const agentSpanData = registry?.resumeAgentSpanData ?? initData.agentSpanData;
|
|
3033
|
-
const agentSpan = registry?.resumeAgentSpan ?? registry?.agentSpan ?? (agentSpanData ? mastra?.observability?.getSelectedInstance({})?.rebuildSpan(agentSpanData) : void 0);
|
|
3089
|
+
const agentSpan = segmentAgentSpan(requestContext, initData, (0, _mastra_core_agent_durable.getRunRegistryEntry)(initData.runId, mastra), mastra);
|
|
3034
3090
|
(0, _mastra_core_agent_durable.executeDurableAgentScorers)({
|
|
3035
3091
|
initData,
|
|
3036
3092
|
finalOutput: inputData,
|
|
@@ -3278,6 +3334,22 @@ function createInngestAgent(options) {
|
|
|
3278
3334
|
}
|
|
3279
3335
|
}
|
|
3280
3336
|
/**
|
|
3337
|
+
* The agent run span saved with a run that has no live span in this process (another process
|
|
3338
|
+
* started it, or it already finished here), so an observer still names the run's trace.
|
|
3339
|
+
* `undefined` when the run is untraced or its snapshot is gone. Never throws.
|
|
3340
|
+
*/
|
|
3341
|
+
async function loadRunAgentSpan(runId) {
|
|
3342
|
+
try {
|
|
3343
|
+
const agentSpanData = ((await (await mastra?.getStorage()?.getStore("workflows"))?.loadWorkflowSnapshot({
|
|
3344
|
+
runId,
|
|
3345
|
+
workflowName: InngestDurableStepIds.AGENTIC_LOOP
|
|
3346
|
+
}))?.context?.input)?.agentSpanData;
|
|
3347
|
+
return agentSpanData ? mastra?.observability?.getSelectedInstance({})?.rebuildSpan(agentSpanData) : void 0;
|
|
3348
|
+
} catch {
|
|
3349
|
+
return;
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3281
3353
|
* A run parked on a suspension has no prepared run in this process, so a
|
|
3282
3354
|
* fenced resume is the first point where it is known it can never continue.
|
|
3283
3355
|
* Delete its still-suspended snapshot rows and publish the abort terminal so
|
|
@@ -3358,6 +3430,73 @@ function createInngestAgent(options) {
|
|
|
3358
3430
|
};
|
|
3359
3431
|
}
|
|
3360
3432
|
/**
|
|
3433
|
+
* The AGENT_RUN + MODEL_GENERATION pair a resumed execution reports under, nested under the run's
|
|
3434
|
+
* first pair in its trace, with its wire form for the workers' steps. `null` when the run is
|
|
3435
|
+
* untraced, span creation fails, or this core's steps would not end a carried pair. Never throws.
|
|
3436
|
+
*/
|
|
3437
|
+
function openResumeSegment(runId, snapshot, requestContext) {
|
|
3438
|
+
const input = snapshot?.context?.input;
|
|
3439
|
+
const previous = input?.agentSpanData;
|
|
3440
|
+
if (!previous || !mastra?.observability || !carriesSegmentSpans()) return null;
|
|
3441
|
+
const { instructions: _instructions, ...attributes } = previous.attributes ?? {};
|
|
3442
|
+
const { threadId, resourceId } = previous.metadata ?? {};
|
|
3443
|
+
try {
|
|
3444
|
+
const resumeFrom = (0, _mastra_core_observability.getResumeTracingContext)(previous);
|
|
3445
|
+
const resolvedVersionId = agent.toRawConfig?.()?.resolvedVersionId;
|
|
3446
|
+
const agentSpan = (0, _mastra_core_observability.getOrCreateSpan)({
|
|
3447
|
+
type: _mastra_core_observability.SpanType.AGENT_RUN,
|
|
3448
|
+
outcome: null,
|
|
3449
|
+
name: `agent run: '${agent.id}' (resumed)`,
|
|
3450
|
+
entityType: _mastra_core_observability.EntityType.AGENT,
|
|
3451
|
+
entityId: agent.id,
|
|
3452
|
+
entityName: agent.name,
|
|
3453
|
+
attributes,
|
|
3454
|
+
metadata: {
|
|
3455
|
+
runId,
|
|
3456
|
+
resourceId,
|
|
3457
|
+
threadId,
|
|
3458
|
+
resumed: true,
|
|
3459
|
+
...resumeFrom ? { resumedFromSpanId: previous.id } : {},
|
|
3460
|
+
...typeof resolvedVersionId === "string" ? { entityVersionId: resolvedVersionId } : {}
|
|
3461
|
+
},
|
|
3462
|
+
resumeFrom,
|
|
3463
|
+
tracingPolicy: agent.getTracingPolicy?.(),
|
|
3464
|
+
tracingOptions: {
|
|
3465
|
+
traceId: previous.traceId,
|
|
3466
|
+
...previous.traceState
|
|
3467
|
+
},
|
|
3468
|
+
traceState: previous.traceState,
|
|
3469
|
+
samplingDecision: !!resumeFrom,
|
|
3470
|
+
requestContext,
|
|
3471
|
+
mastra
|
|
3472
|
+
});
|
|
3473
|
+
if (!agentSpan) return null;
|
|
3474
|
+
const modelSpan = agentSpan.createChildSpan({
|
|
3475
|
+
type: _mastra_core_observability.SpanType.MODEL_GENERATION,
|
|
3476
|
+
outcome: null,
|
|
3477
|
+
name: input.modelSpanData?.name ?? "llm: ''",
|
|
3478
|
+
attributes: input.modelSpanData?.attributes ?? {},
|
|
3479
|
+
metadata: {
|
|
3480
|
+
runId,
|
|
3481
|
+
resumed: true
|
|
3482
|
+
},
|
|
3483
|
+
requestContext
|
|
3484
|
+
});
|
|
3485
|
+
return {
|
|
3486
|
+
agentSpan,
|
|
3487
|
+
modelSpan,
|
|
3488
|
+
carried: {
|
|
3489
|
+
agentSpanData: agentSpan.snapshot?.() ?? agentSpan.exportSpan(),
|
|
3490
|
+
modelSpanData: modelSpan?.snapshot?.() ?? modelSpan?.exportSpan(),
|
|
3491
|
+
stepParentId: (0, _mastra_core_observability.resolveExportedSpanId)(modelSpan ?? agentSpan)
|
|
3492
|
+
}
|
|
3493
|
+
};
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
mastra?.getLogger?.()?.warn?.(`[InngestAgent] resume(${runId}) failed to open its spans: ${error}`);
|
|
3496
|
+
return null;
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
/**
|
|
3361
3500
|
* The request context a segment's event carries: the caller's, plus this segment's absolute
|
|
3362
3501
|
* deadline (or none), so a worker that subscribes after the deadline's abort request went out
|
|
3363
3502
|
* still stops at it.
|
|
@@ -3407,13 +3546,15 @@ function createInngestAgent(options) {
|
|
|
3407
3546
|
})) return false;
|
|
3408
3547
|
const threadId = workflowInput.state?.threadId;
|
|
3409
3548
|
const resourceId = workflowInput.state?.resourceId;
|
|
3549
|
+
const { input: _input, attributes: _attributes, ...agentSpanData } = workflowInput.agentSpanData ?? {};
|
|
3410
3550
|
const context = {};
|
|
3411
3551
|
context.input = {
|
|
3412
3552
|
agentId: workflowInput.agentId,
|
|
3413
3553
|
state: {
|
|
3414
3554
|
threadId,
|
|
3415
3555
|
resourceId
|
|
3416
|
-
}
|
|
3556
|
+
},
|
|
3557
|
+
...workflowInput.agentSpanData ? { agentSpanData } : {}
|
|
3417
3558
|
};
|
|
3418
3559
|
await workflowsStore.persistWorkflowSnapshot({
|
|
3419
3560
|
workflowName,
|
|
@@ -3722,6 +3863,7 @@ function createInngestAgent(options) {
|
|
|
3722
3863
|
outputProcessors: registryEntry.outputProcessors,
|
|
3723
3864
|
processorStates: registryEntry.processorStates,
|
|
3724
3865
|
requestContext: registryEntry.requestContext,
|
|
3866
|
+
tracingContext: registryEntry.agentSpan ? { currentSpan: registryEntry.agentSpan } : void 0,
|
|
3725
3867
|
onChunk: (chunk) => {
|
|
3726
3868
|
if (chunk.type === "tool-call-approval" || chunk.type === "tool-call-suspended") stopForwardingAbort?.();
|
|
3727
3869
|
return callbackOptions.onChunk?.(chunk);
|
|
@@ -3810,6 +3952,8 @@ function createInngestAgent(options) {
|
|
|
3810
3952
|
runId,
|
|
3811
3953
|
threadId,
|
|
3812
3954
|
resourceId,
|
|
3955
|
+
traceId: output.traceId,
|
|
3956
|
+
spanId: output.spanId,
|
|
3813
3957
|
cleanup,
|
|
3814
3958
|
abort,
|
|
3815
3959
|
get fullStream() {
|
|
@@ -3953,6 +4097,11 @@ function createInngestAgent(options) {
|
|
|
3953
4097
|
}
|
|
3954
4098
|
existingEntry.abortController = abortController;
|
|
3955
4099
|
existingEntry.requestContext = callbackOptions.requestContext;
|
|
4100
|
+
const resumeSegment = openResumeSegment(runId, suspendedSnapshot, callbackOptions.requestContext);
|
|
4101
|
+
existingEntry.resumeAgentSpan = resumeSegment?.agentSpan;
|
|
4102
|
+
existingEntry.resumeModelSpan = resumeSegment?.modelSpan;
|
|
4103
|
+
existingEntry.resumeCompletionStartTime = void 0;
|
|
4104
|
+
existingEntry.resumeTimeToFirstTokenMs = void 0;
|
|
3956
4105
|
const { clear: clearTotalTimeout, deadline: segmentDeadline } = armTotalTimeout(existingEntry, abortController, runId, callbackOptions.modelSettings?.timeout?.totalMs ?? existingRegistryEntry?.timeoutTotalMs ?? (await resumableSnapshot.catch(() => void 0))?.snapshot?.context?.input?.options?.modelSettings?.timeout?.totalMs);
|
|
3957
4106
|
if (existingRegistryEntry && !existingRegistryEntry.isPlaceholder && (resumeOptions?.requestContext || resumeOptions?.hooks)) try {
|
|
3958
4107
|
const snapshotMemoryInfo = (await resumableSnapshot.catch(() => void 0))?.snapshot?.context?.input?.messageListState?.memoryInfo;
|
|
@@ -4000,6 +4149,7 @@ function createInngestAgent(options) {
|
|
|
4000
4149
|
(0, _mastra_core_agent_durable.deleteRunRegistryEntry)(runId, mastra);
|
|
4001
4150
|
};
|
|
4002
4151
|
let resumedChunkSeen = false;
|
|
4152
|
+
const resumeSegmentSpan = existingEntry.resumeAgentSpan ?? existingEntry.agentSpan;
|
|
4003
4153
|
const { output, cleanup: streamCleanup, detach: detachStream, ready } = (0, _mastra_core_agent_durable.createDurableAgentStream)({
|
|
4004
4154
|
pubsub: getPubsub(),
|
|
4005
4155
|
runId,
|
|
@@ -4020,6 +4170,7 @@ function createInngestAgent(options) {
|
|
|
4020
4170
|
outputProcessors: existingEntry.outputProcessors,
|
|
4021
4171
|
processorStates: existingEntry.processorStates,
|
|
4022
4172
|
requestContext: callbackOptions.requestContext,
|
|
4173
|
+
tracingContext: resumeSegmentSpan ? { currentSpan: resumeSegmentSpan } : void 0,
|
|
4023
4174
|
onChunk: (chunk) => {
|
|
4024
4175
|
resumedChunkSeen = true;
|
|
4025
4176
|
if (chunk.type === "tool-call-approval" || chunk.type === "tool-call-suspended") {
|
|
@@ -4075,6 +4226,7 @@ function createInngestAgent(options) {
|
|
|
4075
4226
|
notResumable = true;
|
|
4076
4227
|
throw error;
|
|
4077
4228
|
}
|
|
4229
|
+
carrySegmentSpans(requestContext, runId, resumeSegment?.carried ?? null);
|
|
4078
4230
|
const tracingOptions = snapshot?.tracingContext ? {
|
|
4079
4231
|
traceId: snapshot.tracingContext.traceId,
|
|
4080
4232
|
parentSpanId: snapshot.tracingContext.spanId
|
|
@@ -4109,7 +4261,15 @@ function createInngestAgent(options) {
|
|
|
4109
4261
|
} catch (error) {
|
|
4110
4262
|
streamCleanup();
|
|
4111
4263
|
finalizeResumeRegistry();
|
|
4112
|
-
if (!sendStarted)
|
|
4264
|
+
if (!sendStarted) {
|
|
4265
|
+
const failure = (0, _mastra_core_error.getErrorFromUnknown)(error);
|
|
4266
|
+
for (const span of [resumeSegment?.modelSpan, resumeSegment?.agentSpan]) span?.error({
|
|
4267
|
+
error: failure,
|
|
4268
|
+
...executionFailureTermination(failure),
|
|
4269
|
+
endSpan: true
|
|
4270
|
+
});
|
|
4271
|
+
await claim.release().catch((releaseError) => mastra?.getLogger?.()?.warn?.(`[InngestAgent] resume(${runId}) failed to release its claim`, releaseError));
|
|
4272
|
+
}
|
|
4113
4273
|
throw error;
|
|
4114
4274
|
}
|
|
4115
4275
|
const resumeMemory = resumeOptions?.memory;
|
|
@@ -4142,6 +4302,8 @@ function createInngestAgent(options) {
|
|
|
4142
4302
|
runId,
|
|
4143
4303
|
threadId: resumeOptions?.threadId,
|
|
4144
4304
|
resourceId: resumeOptions?.resourceId,
|
|
4305
|
+
traceId: output.traceId,
|
|
4306
|
+
spanId: output.spanId,
|
|
4145
4307
|
cleanup,
|
|
4146
4308
|
abort,
|
|
4147
4309
|
[STREAM_CLEANUP]: streamCleanup
|
|
@@ -4181,6 +4343,8 @@ function createInngestAgent(options) {
|
|
|
4181
4343
|
};
|
|
4182
4344
|
},
|
|
4183
4345
|
async observe(runId, observeOptions) {
|
|
4346
|
+
const observedEntry = (0, _mastra_core_agent_durable.getRunRegistryEntry)(runId, mastra);
|
|
4347
|
+
const observedAgentSpan = observedEntry?.resumeAgentSpan ?? observedEntry?.agentSpan ?? await loadRunAgentSpan(runId);
|
|
4184
4348
|
const stream = (0, _mastra_core_agent_durable.createDurableAgentStream)({
|
|
4185
4349
|
pubsub: getPubsub(),
|
|
4186
4350
|
runId,
|
|
@@ -4194,7 +4358,8 @@ function createInngestAgent(options) {
|
|
|
4194
4358
|
replayResponseMessagesBeforeOffset: true,
|
|
4195
4359
|
idleTimeoutMs: observeOptions?.idleTimeoutMs,
|
|
4196
4360
|
isAlive: observeOptions?.isAlive,
|
|
4197
|
-
structuredOutput:
|
|
4361
|
+
structuredOutput: observedEntry?.structuredOutput,
|
|
4362
|
+
tracingContext: observedAgentSpan ? { currentSpan: observedAgentSpan } : void 0,
|
|
4198
4363
|
onChunk: observeOptions?.onChunk,
|
|
4199
4364
|
onStepFinish: observeOptions?.onStepFinish,
|
|
4200
4365
|
onFinish: observeOptions?.onFinish,
|
|
@@ -4247,6 +4412,8 @@ function createInngestAgent(options) {
|
|
|
4247
4412
|
return output.fullStream;
|
|
4248
4413
|
},
|
|
4249
4414
|
runId,
|
|
4415
|
+
traceId: output.traceId,
|
|
4416
|
+
spanId: output.spanId,
|
|
4250
4417
|
cleanup: streamCleanup,
|
|
4251
4418
|
detach,
|
|
4252
4419
|
abort
|
|
@@ -5304,4 +5471,4 @@ Object.defineProperty(exports, "serve", {
|
|
|
5304
5471
|
}
|
|
5305
5472
|
});
|
|
5306
5473
|
|
|
5307
|
-
//# sourceMappingURL=src-
|
|
5474
|
+
//# sourceMappingURL=src-BrPOwm__.cjs.map
|