@mastra/core 1.87.0-alpha.14 → 1.87.0-alpha.15
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/agent/durable/index.cjs +1 -1
- package/dist/agent/durable/index.js +1 -1
- package/dist/agent/index.cjs +2 -2
- package/dist/agent/index.js +2 -2
- package/dist/agent-builder/ee/index.cjs +1 -1
- package/dist/agent-builder/ee/index.js +1 -1
- package/dist/agent-controller/index.cjs +1 -1
- package/dist/agent-controller/index.js +1 -1
- package/dist/{agent-controller-k4B293tu.cjs → agent-controller-DhDQXNoI.cjs} +5 -5
- package/dist/{agent-controller-FSjSZ_iD.js → agent-controller-DihwxeVJ.js} +5 -5
- package/dist/background-tasks/index.cjs +1 -1
- package/dist/background-tasks/index.js +1 -1
- package/dist/{background-tasks-ClI6oF60.js → background-tasks-BoUX5G90.js} +1 -1
- package/dist/{background-tasks-D40Y_iLc.cjs → background-tasks-udYDvnlw.cjs} +1 -1
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/{builder-C_I6l0US.cjs → builder-B2n-bUbl.cjs} +2 -2
- package/dist/{builder-D00XMm41.js → builder-Cn1lOWio.js} +2 -2
- package/dist/channels/index.cjs +2 -2
- package/dist/channels/index.js +2 -2
- package/dist/{channels-DMSae7xD.js → channels-DA3oMfhF.js} +1 -1
- package/dist/{channels-BU5_kAUO.cjs → channels-HRrlHnwF.cjs} +1 -1
- package/dist/coding-agent/index.cjs +2 -2
- package/dist/coding-agent/index.js +2 -2
- package/dist/datasets/index.cjs +2 -2
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +530 -530
- package/dist/docs/references/docs-signals-sending-signals.md +13 -0
- package/dist/docs/references/docs-signals-state-signals.md +1 -1
- package/dist/docs/references/reference-signals-time-signal-provider.md +35 -0
- package/dist/evals/index.cjs +1 -1
- package/dist/evals/index.js +1 -1
- package/dist/evals/scoreTraces/index.cjs +1 -1
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/harness/index.cjs +1 -1
- package/dist/harness/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/knowledge/index.cjs +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/llm/index.cjs +3 -3
- package/dist/llm/index.js +3 -3
- package/dist/{llm-C1aiWB6O.cjs → llm-Bljw7LII.cjs} +2 -2
- package/dist/{llm-D5rGQSnS.js → llm-CxHzqEEI.js} +2 -2
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +2 -2
- package/dist/{manager-DxwPLhYJ.js → manager-BimN8ZdV.js} +2 -2
- package/dist/{manager-B2z5f39G.cjs → manager-DVYVB-3O.cjs} +2 -2
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-CHd7UnbI.js → mastra-BpMvri3z.js} +17 -16
- package/dist/{mastra-WMuI7TZD.cjs → mastra-k8L1lFip.cjs} +17 -16
- package/dist/memory/index.cjs +2 -2
- package/dist/memory/index.js +2 -2
- package/dist/{model-C2CTzjMk.cjs → model-CrDuEDRq.cjs} +1 -1
- package/dist/{model-B8DlLHex.js → model-sUJDcX2v.js} +1 -1
- package/dist/{netlify-xQFmVbr4.js → netlify-BEJ96z-w.js} +1 -1
- package/dist/{netlify-Dhs0UJul.cjs → netlify-Td-JUUkt.cjs} +1 -1
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/processor-provider/index.cjs +1 -1
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/{provider-registry-CSQPAFzz.cjs → provider-registry-CCYXykIZ.cjs} +4 -4
- package/dist/{provider-registry-FxVHWmht.js → provider-registry-DBG4hlGl.js} +4 -4
- package/dist/{registry-generator-Dsh7xcz9.cjs → registry-generator-BxiC9XcX.cjs} +1 -1
- package/dist/{registry-generator-BzsrHxrr.js → registry-generator-D2lO3JJJ.js} +1 -1
- package/dist/{rehydrate-8q7KX4rD.cjs → rehydrate-BD0zOfc8.cjs} +2 -2
- package/dist/{rehydrate-DV1iO9eZ.js → rehydrate-PRFAu8yl.js} +2 -2
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +2 -2
- package/dist/{run-registry-DOlZccsr.cjs → run-registry-BvMXuIb_.cjs} +451 -345
- package/dist/{run-registry-sTm40Ecv.js → run-registry-Cqp-VFdv.js} +451 -345
- package/dist/signals/index.cjs +1 -1
- package/dist/signals/index.js +1 -1
- package/dist/signals/time-signal-provider.d.ts +8 -0
- package/dist/{signals-CIwzgkvN.cjs → signals-CbmgVwL-.cjs} +74 -7
- package/dist/{signals-BTfT-6DE.js → signals-Clupx3jz.js} +74 -7
- package/dist/storage/domains/knowledge/base.d.ts +33 -1
- package/dist/storage/domains/knowledge/inmemory.d.ts +2 -0
- package/dist/storage/domains/knowledge/pages-inmemory.d.ts +20 -12
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.js +2 -2
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/{stream-aGuW9AL8.cjs → stream-BIbVD8V8.cjs} +1 -1
- package/dist/{stream-k-Q1NLUs.js → stream-D607FmAx.js} +1 -1
- package/dist/test-utils/llm-mock.cjs +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/{tool-loop-agent-WcRtGJHn.cjs → tool-loop-agent-Cnf7vONA.cjs} +3 -3
- package/dist/{tool-loop-agent-CJrysPOR.js → tool-loop-agent-eyoY_TEX.js} +3 -3
- package/dist/{utils-DamF4CfD.js → utils-CQkzZUcK.js} +1 -1
- package/dist/{utils-DEzQLxWP.cjs → utils-O1TXaFUl.cjs} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{validate-CDlONK0o.cjs → validate-CEgWy7P0.cjs} +1 -1
- package/dist/{validate-rum3NMFA.js → validate-CTWjOlWp.js} +1 -1
- package/dist/vector/index.cjs +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/worker/index.cjs +1 -1
- package/dist/worker/index.js +1 -1
- package/dist/{worker-rwal1zI8.cjs → worker-CCDvbK3P.cjs} +2 -2
- package/dist/{worker-st16x0my.js → worker-CCNb2aJe.js} +2 -2
- package/dist/{worker-6MiKMAqB.cjs → worker-CI1joT3R.cjs} +2 -2
- package/dist/{worker-BnXipQth.js → worker-D52cos24.js} +2 -2
- package/dist/{workflow-D2-gn0U0.cjs → workflow-BJL0qlPN.cjs} +3 -3
- package/dist/{workflow-BzhYKgc_.js → workflow-DsmyWwxG.js} +3 -3
- package/dist/workflows/builder/index.cjs +1 -1
- package/dist/workflows/builder/index.js +1 -1
- package/dist/workflows/evented/index.cjs +1 -1
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +4 -4
- package/dist/workflows/index.js +4 -4
- package/package.json +6 -6
|
@@ -4,14 +4,14 @@ import { t as MastraBase } from "./base-CKLWBhDo.js";
|
|
|
4
4
|
import { A as compactStopReasonContext, D as agentLoopTermination, O as executionFailureTermination, S as resolveObservabilityContext, b as wrapMastra, i as subtractReportedUsage, k as tripwireTermination, n as extractUsageMetrics, r as isUsageIncomplete, t as calculateObservedUsage, x as createObservabilityContext, y as unwrapMastraTracingProxy } from "./observability-D7RNOAPx.js";
|
|
5
5
|
import { a as MastraNonRetryableError, i as MastraError, n as ErrorDomain, o as getErrorFromUnknown, t as ErrorCategory } from "./error-oh2DLsP2.js";
|
|
6
6
|
import { a as classifyProviderError, l as describeProviderError, t as recordTerminalErrorMessage, u as readProviderErrorDetails } from "./error-BC9Au-22.js";
|
|
7
|
-
import { $ as summarizeToolChoiceForSpan, $t as commitToolResult, A as isSignalChunkExcluded, An as raceAgainstAbort, At as getSnapshotMemoryInfo, B as removeTrailingAssistantGuardContinuations, Bt as stateColumnsWrite, C as stampChunkProducedAt, Cn as DEADLINE_SAVE_WAIT_MS, D as isStructuredOutputError, Dn as guardStreamUntilMatch, Dt as validateTemplate, E as escapeUnescapedControlCharsInJsonStrings, En as getAbortReason, Et as traverseMappingPath, F as endOutputStreamSpanOutsideStep, Fn as safeEnqueue, Ft as latestStepResults, G as FLUSH_HELD_PARTS_KEY, Gt as diffStateAsJson, Ht as unusedStateEntries, I as findOwnModelStepSpan, In as safeError, It as materializeState, J as withoutHeldContent, K as REPROCESS_PART_KEY, Kt as patchState, Ln as createRunScope, Lt as materializeWorkflowRun, M as ProcessorRunner, N as ProcessorState, Nn as MastraModelInput, Nt as applyStateColumnsWrite, O as asJsonSchema, On as guardStreamWithAbort, Ot as getStepResult, P as endOutputStreamSpanAtStepEnd, Pn as safeClose, Pt as isStateCheckpointDue, Q as summarizeProcessorToolsForSpan, R as isTrailingAssistantGuardContinuation, Rn as createRunScopeKey, Rt as pickStateKeys, S as getChunkProducedAt, Sn as DEADLINE_SAVE_CLAIM_HOLD_MS, St as stepRefId, T as createOutputHandler, Tn as createTimeoutAbortSignal, Tt as templateReadsState, Ut as applyStatePatch, V as ProviderHistoryCompat, Vt as summarizeStepResult, X as summarizeProcessorModelForSpan, Y as summarizeActiveToolsForSpan, Yt as isObservationalMemoryEnabled$1, Z as summarizeProcessorResultForSpan, Zt as parseMemoryRequestContext, _ as persistProcessorDataChunk, _t as stubStepResult, a as convertFullStreamChunkToMastra, an as snapshotToolResult, at as PROCESSOR_ABORT_SIGNAL, b as resolveOutputMessageSkippingCompletionChecks, bn as pendingQueueThreadId, bt as predicateReadsState, c as WorkflowRunOutput, cn as validationErrorModelOutput, ct as getHydratedStepResult, d as MastraModelOutput, dn as resolveSuspendedToolRunId, dt as lazyStepResults, en as computeModelOutputProviderMetadata, et as resolveProcessorSpanAttributes, f as clearStepPartIndexes, fn as resolveThreadIdFromArgs, ft as loadStepResults, g as isFeedbackContinuation, gn as applyStateSignal, gt as storageV2StepResultAccessors, h as findStepPartBoundaries, hn as tryStreamWithJsonFallback, ht as residentStepResultsLoader, in as resolveModelOutputAfterToolResultProcessors, it as createProcessorSendSignal, j as OUTPUT_STREAM_HOOK_DURATION_KEY_PREFIX, jn as settledOrElapsed, k as getResponseFormat, kn as isMastraTimeoutError, kt as getStepResultAsync, l as TripWire, ln as isProcessorWorkflow, lt as hydrateStepResults, m as findIterationOffsetInParts, mn as tryGenerateWithJsonFallback, mt as residentStepResults, nn as latestProcessedModelOutput, nt as toProcessorSpanPhase, on as withAgentWorkflowToolMarker, ot as RunJournal, p as createDestructurableOutput, pn as supportedLanguageModelSpecifications, pt as loadedStepResults, q as takeHeldParts, rn as readModelOutput, rt as PROCESSOR_LATE_SIGNAL_SINK, s as MastraAgentNetworkStream, sn as normalizeModelOutput, st as buildStepResultAccessors, tn as hasToolResultProcessor, tt as resolveProcessorSpanName, u as getModelOutputForTripwire, un as isSupportedLanguageModel, ut as isStepResultStub, v as reconcileBufferedStepTexts, vn as assertNotQueueThreadId, vt as collectMappingStepRefs, w as markChunkOutputProcessed, wn as MastraTimeoutError, wt as resolveTemplate, x as resolveProcessorWriterMessageId, xn as takenQueueThreadId, xt as resolveStepOutputs, y as resolveMessageText, yn as isQueueThreadId, yt as collectPredicateStepRefs, z as needsTrailingAssistantGuard, zt as stateBaseOf } from "./stream-
|
|
7
|
+
import { $ as summarizeToolChoiceForSpan, $t as commitToolResult, A as isSignalChunkExcluded, An as raceAgainstAbort, At as getSnapshotMemoryInfo, B as removeTrailingAssistantGuardContinuations, Bt as stateColumnsWrite, C as stampChunkProducedAt, Cn as DEADLINE_SAVE_WAIT_MS, D as isStructuredOutputError, Dn as guardStreamUntilMatch, Dt as validateTemplate, E as escapeUnescapedControlCharsInJsonStrings, En as getAbortReason, Et as traverseMappingPath, F as endOutputStreamSpanOutsideStep, Fn as safeEnqueue, Ft as latestStepResults, G as FLUSH_HELD_PARTS_KEY, Gt as diffStateAsJson, Ht as unusedStateEntries, I as findOwnModelStepSpan, In as safeError, It as materializeState, J as withoutHeldContent, K as REPROCESS_PART_KEY, Kt as patchState, Ln as createRunScope, Lt as materializeWorkflowRun, M as ProcessorRunner, N as ProcessorState, Nn as MastraModelInput, Nt as applyStateColumnsWrite, O as asJsonSchema, On as guardStreamWithAbort, Ot as getStepResult, P as endOutputStreamSpanAtStepEnd, Pn as safeClose, Pt as isStateCheckpointDue, Q as summarizeProcessorToolsForSpan, R as isTrailingAssistantGuardContinuation, Rn as createRunScopeKey, Rt as pickStateKeys, S as getChunkProducedAt, Sn as DEADLINE_SAVE_CLAIM_HOLD_MS, St as stepRefId, T as createOutputHandler, Tn as createTimeoutAbortSignal, Tt as templateReadsState, Ut as applyStatePatch, V as ProviderHistoryCompat, Vt as summarizeStepResult, X as summarizeProcessorModelForSpan, Y as summarizeActiveToolsForSpan, Yt as isObservationalMemoryEnabled$1, Z as summarizeProcessorResultForSpan, Zt as parseMemoryRequestContext, _ as persistProcessorDataChunk, _t as stubStepResult, a as convertFullStreamChunkToMastra, an as snapshotToolResult, at as PROCESSOR_ABORT_SIGNAL, b as resolveOutputMessageSkippingCompletionChecks, bn as pendingQueueThreadId, bt as predicateReadsState, c as WorkflowRunOutput, cn as validationErrorModelOutput, ct as getHydratedStepResult, d as MastraModelOutput, dn as resolveSuspendedToolRunId, dt as lazyStepResults, en as computeModelOutputProviderMetadata, et as resolveProcessorSpanAttributes, f as clearStepPartIndexes, fn as resolveThreadIdFromArgs, ft as loadStepResults, g as isFeedbackContinuation, gn as applyStateSignal, gt as storageV2StepResultAccessors, h as findStepPartBoundaries, hn as tryStreamWithJsonFallback, ht as residentStepResultsLoader, in as resolveModelOutputAfterToolResultProcessors, it as createProcessorSendSignal, j as OUTPUT_STREAM_HOOK_DURATION_KEY_PREFIX, jn as settledOrElapsed, k as getResponseFormat, kn as isMastraTimeoutError, kt as getStepResultAsync, l as TripWire, ln as isProcessorWorkflow, lt as hydrateStepResults, m as findIterationOffsetInParts, mn as tryGenerateWithJsonFallback, mt as residentStepResults, nn as latestProcessedModelOutput, nt as toProcessorSpanPhase, on as withAgentWorkflowToolMarker, ot as RunJournal, p as createDestructurableOutput, pn as supportedLanguageModelSpecifications, pt as loadedStepResults, q as takeHeldParts, rn as readModelOutput, rt as PROCESSOR_LATE_SIGNAL_SINK, s as MastraAgentNetworkStream, sn as normalizeModelOutput, st as buildStepResultAccessors, tn as hasToolResultProcessor, tt as resolveProcessorSpanName, u as getModelOutputForTripwire, un as isSupportedLanguageModel, ut as isStepResultStub, v as reconcileBufferedStepTexts, vn as assertNotQueueThreadId, vt as collectMappingStepRefs, w as markChunkOutputProcessed, wn as MastraTimeoutError, wt as resolveTemplate, x as resolveProcessorWriterMessageId, xn as takenQueueThreadId, xt as resolveStepOutputs, y as resolveMessageText, yn as isQueueThreadId, yt as collectPredicateStepRefs, z as needsTrailingAssistantGuard, zt as stateBaseOf } from "./stream-D607FmAx.js";
|
|
8
8
|
import { c as MASTRA_THREAD_ID_KEY, d as isReservedRequestContextKey, f as mergeVersionOverrides$1, l as MASTRA_VERSIONS_KEY, n as MASTRA_AUTH_TOKEN_KEY, o as MASTRA_RESOURCE_ID_KEY, p as withoutLiveRequestKeys, r as MASTRA_INHERITED_MEMORY_KEY, s as MASTRA_SCOPES_KEY, t as MASTRA_CONTINUATION_TOOL_CALL_IDS_KEY, u as RequestContext } from "./request-context-COnZHt2-.js";
|
|
9
9
|
import { S as withAck, _ as serializeError$1, h as stripModelSnapshots, n as PublisherQueueLimitError, p as slimNestedAgentChunks, r as CachingPubSub, t as DefaultStepResult, u as isRunLocalTopic, v as EventEmitterPubSub, x as isLeaseProvider, y as NoopLeaseProvider } from "./output-helpers-CVzhy1Y0.js";
|
|
10
10
|
import { A as stableStringify$1, E as removeWorkingMemoryTags, P as embed$3, Z as preserveResponseItemIdsOnMerge, a as isTerminalToolInvocationState, c as withUnavailableAttachmentUrls, d as aiV5UIMessagesToAIV5ModelMessages, f as coreContentToString, i as isClientToolInvocationUpdate, l as isDownloadAssetsError, m as filterMessagesForPersistence, n as MessageList, ot as normalizeToolOutput, p as messagesAreEqual, r as advancesToolInvocationState, s as unavailableAttachmentPlaceholder, t as convertMessages, u as MessageMerger } from "./message-list-RgFlLrxG.js";
|
|
11
11
|
import { Bt as listScoresArgsSchema, Ft as listLogsArgsSchema, Lt as listMetricsArgsSchema, Nt as listFeedbackArgsSchema, t as EntityType } from "./storage-Cc50aQAp.js";
|
|
12
12
|
import { a as getOrCreateSpan, f as resolveCurrentSpan, l as getTimeToFirstChunkMs, n as executeWithContextSync, o as getResumeTracingContext, p as resolveExportedSpanId, s as getRootExportSpan, t as executeWithContext, u as getWorkflowResumeTracingContext } from "./utils-DU_pU5SK.js";
|
|
13
13
|
import { i as setSpanErrorOrigin, n as getSpanErrorOrigin } from "./error-count-BH-rJW7q.js";
|
|
14
|
-
import { a as ModelRouterLanguageModel, d as attachModelStreamTransport, f as isDataChunk, i as resolveModelConfig, n as ModelRouterEmbeddingModel, o as resolveApiProviderId, p as readModelStreamTransport } from "./llm-
|
|
14
|
+
import { a as ModelRouterLanguageModel, d as attachModelStreamTransport, f as isDataChunk, i as resolveModelConfig, n as ModelRouterEmbeddingModel, o as resolveApiProviderId, p as readModelStreamTransport } from "./llm-CxHzqEEI.js";
|
|
15
15
|
import { a as withToolPayloadTransformMetadata, i as transformToolPayloadForTargets, n as hasTransformedToolPayload, o as withToolPayloadTransformProviderMetadata, r as normalizeToolPayloadTransformPolicy, t as getTransformedToolPayload } from "./payload-transform-Dj3HUeD4.js";
|
|
16
16
|
import { boundedStringify, ensureSerializable, safeStringify } from "./utils/safe-stringify.js";
|
|
17
17
|
import { d as signalSpanAttributes, h as signalToXmlMarkup, l as mastraDBMessageToSignal, n as createSignal, o as isMastraSignalMessage, s as isTransientSignalMessage, u as resolveDeliveryAttributes } from "./signals-CqR_iWkg.js";
|
|
@@ -24,13 +24,13 @@ import { _ as getRequestContextInputValues, a as getModelFacingValidationError,
|
|
|
24
24
|
import { a as isApprovalExempt, c as isProviderDefinedTool, d as markAgentWorkflowTool, f as markApprovalExempt, l as isProviderTool, n as getNeedsApprovalFn, o as isBuiltBeforeApproval, r as getProviderToolName, s as isMastraTool, t as getBeforeApprovalFn } from "./toolchecks-DrsZdc3S.js";
|
|
25
25
|
import { a as waitDelay, i as getRetryAfterMs, n as DEFAULT_MAX_RETRY_AFTER_MS, r as clampDelayMs } from "./fetchWithRetry-DFSvpYDT.js";
|
|
26
26
|
import { i as hasFreeFormObject } from "./model-DS-b2R-R.js";
|
|
27
|
-
import { c as modelSupportsStructuredOutput, l as modelSupportsTemperature } from "./provider-registry-
|
|
27
|
+
import { c as modelSupportsStructuredOutput, l as modelSupportsTemperature } from "./provider-registry-DBG4hlGl.js";
|
|
28
28
|
import { t as InMemoryServerCache } from "./inmemory-BK3zLwvM.js";
|
|
29
29
|
import { n as resolveDynamicArgument, t as getRequestUser } from "./dynamic-argument-BzPK3qPN.js";
|
|
30
|
-
import { t as MastraLLMV1 } from "./model-
|
|
31
|
-
import { A as eagerToolCallDidNotExecute, D as EagerToolExecutionCoordinator, E as EAGER_TOOL_EXECUTION_MARKER, F as hasRunningRunStep, I as isRunStepActive, L as setRunLeaseFence, M as isEagerlyExecutableToolCall, N as TOOL_ABORT_NOTICE, O as EagerToolExecutionNotRun, P as clearRunLeaseFence, R as startRunStep, S as selectFields, T as EAGER_TOOL_BAILOUT, a as ensureToolProperties, b as removeUndefinedValues, d as makeCoreTool, i as delay$1, j as eagerToolCallSuspensionIntent, k as eagerToolCallAlreadyAnnouncedInput, n as createMastraProxy, o as generateEmptyFromSchema, p as makeProcessorCoreTool, r as deepMerge$1, v as readPositiveIntEnv, w as EAGER_TOOL_ABORT_SIGNAL, y as rebindProcessorTools, z as whenRunStepsSettle } from "./utils-
|
|
30
|
+
import { t as MastraLLMV1 } from "./model-sUJDcX2v.js";
|
|
31
|
+
import { A as eagerToolCallDidNotExecute, D as EagerToolExecutionCoordinator, E as EAGER_TOOL_EXECUTION_MARKER, F as hasRunningRunStep, I as isRunStepActive, L as setRunLeaseFence, M as isEagerlyExecutableToolCall, N as TOOL_ABORT_NOTICE, O as EagerToolExecutionNotRun, P as clearRunLeaseFence, R as startRunStep, S as selectFields, T as EAGER_TOOL_BAILOUT, a as ensureToolProperties, b as removeUndefinedValues, d as makeCoreTool, i as delay$1, j as eagerToolCallSuspensionIntent, k as eagerToolCallAlreadyAnnouncedInput, n as createMastraProxy, o as generateEmptyFromSchema, p as makeProcessorCoreTool, r as deepMerge$1, v as readPositiveIntEnv, w as EAGER_TOOL_ABORT_SIGNAL, y as rebindProcessorTools, z as whenRunStepsSettle } from "./utils-CQkzZUcK.js";
|
|
32
32
|
import { h as getWorkflowFGAResourceId, i as MastraFGAPermissions, y as requireFGA } from "./ee-iTj2bRDt-By_B9ngH.js";
|
|
33
|
-
import { c as createBackgroundTask, o as resolveBackgroundConfig, s as sanitizeToolArguments, t as generateBackgroundTaskSystemPrompt } from "./background-tasks-
|
|
33
|
+
import { c as createBackgroundTask, o as resolveBackgroundConfig, s as sanitizeToolArguments, t as generateBackgroundTaskSystemPrompt } from "./background-tasks-BoUX5G90.js";
|
|
34
34
|
import { t as ToolStream } from "./stream-D9JOykz7.js";
|
|
35
35
|
import { MISSING, collectInvalidPredicatePaths, createPredicateEvaluator, derivePredicateLabel, normalizePredicatePath, walk } from "./predicate/index.js";
|
|
36
36
|
import { Classifier } from "./classifier/index.js";
|
|
@@ -40932,6 +40932,12 @@ var InMemoryKnowledgePageStore = class {
|
|
|
40932
40932
|
read: input.read
|
|
40933
40933
|
})));
|
|
40934
40934
|
}
|
|
40935
|
+
async getPagesAtPaths(input) {
|
|
40936
|
+
return Promise.all(input.lookups.map((lookup) => this.getPageByPath({
|
|
40937
|
+
...lookup,
|
|
40938
|
+
read: input.read
|
|
40939
|
+
})));
|
|
40940
|
+
}
|
|
40935
40941
|
async getLastChildPositions(input) {
|
|
40936
40942
|
return Object.fromEntries([...new Set(input.parentIds)].map((id) => [id, this.#children(id).sort(byPosition).at(-1)?.position ?? null]));
|
|
40937
40943
|
}
|
|
@@ -41473,9 +41479,37 @@ var InMemoryKnowledgePageStore = class {
|
|
|
41473
41479
|
this.#pins.set(key, pin);
|
|
41474
41480
|
return clone$1(pin);
|
|
41475
41481
|
}
|
|
41482
|
+
async listPinsByTier(input) {
|
|
41483
|
+
const { tiers, count, limit, ...filters } = input;
|
|
41484
|
+
const rank = (pin) => tiers.findIndex((tier) => pin.audience.some((entry) => tier.includes(entry)));
|
|
41485
|
+
const pins = this.#matchingPins({
|
|
41486
|
+
...filters,
|
|
41487
|
+
audience: tiers.flat()
|
|
41488
|
+
}).sort((a, b) => rank(a) - rank(b));
|
|
41489
|
+
return {
|
|
41490
|
+
pins: pins.slice(0, pageSize(limit)).map((pin) => this.#listed(pin)),
|
|
41491
|
+
...count ? { total: pins.length } : {}
|
|
41492
|
+
};
|
|
41493
|
+
}
|
|
41476
41494
|
async listPins(input) {
|
|
41495
|
+
const pins = this.#matchingPins(input);
|
|
41496
|
+
const { items, nextCursor } = paginate(pins, input.cursor, input.limit);
|
|
41497
|
+
return {
|
|
41498
|
+
pins: items.map((pin) => this.#listed(pin)),
|
|
41499
|
+
...nextCursor ? { nextCursor } : {},
|
|
41500
|
+
...input.count ? { total: pins.length } : {}
|
|
41501
|
+
};
|
|
41502
|
+
}
|
|
41503
|
+
#listed(pin) {
|
|
41504
|
+
return {
|
|
41505
|
+
...clone$1(pin),
|
|
41506
|
+
pageName: this.#pages.get(pin.pageId).name
|
|
41507
|
+
};
|
|
41508
|
+
}
|
|
41509
|
+
/** The pins {@link listPins} lists, newest first, before paging. */
|
|
41510
|
+
#matchingPins(input) {
|
|
41477
41511
|
const audience = input.audience === "all" ? null : new Set(input.audience);
|
|
41478
|
-
|
|
41512
|
+
return [...this.#pins.values()].filter((pin) => {
|
|
41479
41513
|
const page = this.#pages.get(pin.pageId);
|
|
41480
41514
|
if (!page || page.deletedAt || !this.#pageReadable(page, input.read)) return false;
|
|
41481
41515
|
if (input.kind && pin.kind !== input.kind) return false;
|
|
@@ -41484,15 +41518,6 @@ var InMemoryKnowledgePageStore = class {
|
|
|
41484
41518
|
if (pin.kind === "page" && input.withBody && !/\S/.test(page.body ?? "")) return false;
|
|
41485
41519
|
return !audience || pin.audience.some((entry) => audience.has(entry));
|
|
41486
41520
|
}).sort(newestFirst);
|
|
41487
|
-
const { items, nextCursor } = paginate(pins, input.cursor, input.limit);
|
|
41488
|
-
return {
|
|
41489
|
-
pins: items.map((pin) => ({
|
|
41490
|
-
...clone$1(pin),
|
|
41491
|
-
pageName: this.#pages.get(pin.pageId).name
|
|
41492
|
-
})),
|
|
41493
|
-
...nextCursor ? { nextCursor } : {},
|
|
41494
|
-
...input.count ? { total: pins.length } : {}
|
|
41495
|
-
};
|
|
41496
41521
|
}
|
|
41497
41522
|
};
|
|
41498
41523
|
// src/storage/domains/knowledge/inmemory.ts
|
|
@@ -41526,6 +41551,12 @@ var InMemoryKnowledgeStorage = class extends KnowledgeStorage {
|
|
|
41526
41551
|
getPagesByPaths(input) {
|
|
41527
41552
|
return this.#pageStore.getPagesByPaths(input);
|
|
41528
41553
|
}
|
|
41554
|
+
getPagesAtPaths(input) {
|
|
41555
|
+
return this.#pageStore.getPagesAtPaths(input);
|
|
41556
|
+
}
|
|
41557
|
+
listPinsByTier(input) {
|
|
41558
|
+
return this.#pageStore.listPinsByTier(input);
|
|
41559
|
+
}
|
|
41529
41560
|
getLastChildPositions(input) {
|
|
41530
41561
|
return this.#pageStore.getLastChildPositions(input);
|
|
41531
41562
|
}
|
|
@@ -66534,16 +66565,28 @@ async function configPins(run, maxTokens) {
|
|
|
66534
66565
|
listings: []
|
|
66535
66566
|
};
|
|
66536
66567
|
const scopes = await run.storage.getScopesByAddress([...new Set(bound.map((pin) => pin.address))]);
|
|
66568
|
+
const scopeOf = new Map(scopes.map((scope) => [scope.address, scope]));
|
|
66569
|
+
const lookups = bound.flatMap((pin) => {
|
|
66570
|
+
const scope = scopeOf.get(pin.address);
|
|
66571
|
+
return scope && pin.path.length > 0 ? [{
|
|
66572
|
+
scopeId: scope.id,
|
|
66573
|
+
path: pin.path
|
|
66574
|
+
}] : [];
|
|
66575
|
+
});
|
|
66576
|
+
const found = lookups.length === 0 ? [] : run.storage.getPagesAtPaths ? await run.storage.getPagesAtPaths({
|
|
66577
|
+
lookups,
|
|
66578
|
+
read: run.read
|
|
66579
|
+
}) : await Promise.all(lookups.map((lookup) => run.storage.getPageByPath({
|
|
66580
|
+
...lookup,
|
|
66581
|
+
read: run.read
|
|
66582
|
+
})));
|
|
66583
|
+
let next = 0;
|
|
66537
66584
|
const pages = /* @__PURE__ */ new Map();
|
|
66538
66585
|
const listings = /* @__PURE__ */ new Map();
|
|
66539
66586
|
for (const pin of bound) {
|
|
66540
|
-
const scope =
|
|
66587
|
+
const scope = scopeOf.get(pin.address);
|
|
66541
66588
|
if (!scope) continue;
|
|
66542
|
-
const page = pin.path.length === 0 ? knowledgeScopeReadable(scope, run.read) ? scope : null :
|
|
66543
|
-
scopeId: scope.id,
|
|
66544
|
-
path: pin.path,
|
|
66545
|
-
read: run.read
|
|
66546
|
-
});
|
|
66589
|
+
const page = pin.path.length === 0 ? knowledgeScopeReadable(scope, run.read) ? scope : null : found[next++];
|
|
66547
66590
|
if (!page || page.deletedAt) continue;
|
|
66548
66591
|
if (pin.depth === void 0) pages.set(page.id, page);
|
|
66549
66592
|
else if ((listings.get(page.id)?.depth ?? 0) < pin.depth) listings.set(page.id, await resolveListing(run, page, pin.depth, maxTokens));
|
|
@@ -66565,6 +66608,28 @@ async function rankedStoredPins(run, excludePageIds, want) {
|
|
|
66565
66608
|
withBody: true,
|
|
66566
66609
|
excludePageIds
|
|
66567
66610
|
};
|
|
66611
|
+
if (tiers.length === 0) return {
|
|
66612
|
+
pins: [],
|
|
66613
|
+
total: 0
|
|
66614
|
+
};
|
|
66615
|
+
if (run.storage.listPinsByTier && want <= 100) {
|
|
66616
|
+
const ranked = await run.storage.listPinsByTier({
|
|
66617
|
+
...base,
|
|
66618
|
+
tiers,
|
|
66619
|
+
limit: want,
|
|
66620
|
+
count: true
|
|
66621
|
+
});
|
|
66622
|
+
const total = ranked.total ?? (await run.storage.listPins({
|
|
66623
|
+
...base,
|
|
66624
|
+
audience: run.principals,
|
|
66625
|
+
limit: 1,
|
|
66626
|
+
count: true
|
|
66627
|
+
})).total ?? 0;
|
|
66628
|
+
return {
|
|
66629
|
+
pins: ranked.pins,
|
|
66630
|
+
total
|
|
66631
|
+
};
|
|
66632
|
+
}
|
|
66568
66633
|
const pins = [];
|
|
66569
66634
|
const seen = /* @__PURE__ */ new Set();
|
|
66570
66635
|
let total;
|
|
@@ -66588,7 +66653,7 @@ async function rankedStoredPins(run, excludePageIds, want) {
|
|
|
66588
66653
|
} while (cursor && pins.length < want);
|
|
66589
66654
|
if (pins.length >= want) break;
|
|
66590
66655
|
}
|
|
66591
|
-
if (total === void 0) total =
|
|
66656
|
+
if (total === void 0) total = (await run.storage.listPins({
|
|
66592
66657
|
...base,
|
|
66593
66658
|
audience: run.principals,
|
|
66594
66659
|
limit: 1,
|
|
@@ -80200,22 +80265,29 @@ function createDurableLLMExecutionStep(_options) {
|
|
|
80200
80265
|
}
|
|
80201
80266
|
throwIfInterrupted();
|
|
80202
80267
|
cleanupToolObservabilitySpans(true);
|
|
80203
|
-
logger?.error?.("Error processing LLM stream", {
|
|
80204
|
-
error,
|
|
80205
|
-
runId
|
|
80206
|
-
});
|
|
80207
80268
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
80208
|
-
if (modelSpanTracker) modelSpanTracker.reportGenerationError({
|
|
80209
|
-
error: errorObj,
|
|
80210
|
-
endSpan: false
|
|
80211
|
-
});
|
|
80212
|
-
else if (modelSpan) modelSpan.error({
|
|
80213
|
-
error: errorObj,
|
|
80214
|
-
endSpan: false
|
|
80215
|
-
});
|
|
80216
80269
|
const innerTimeout = resolveTotalTimeoutAbort(executionAbortSignal, errorObj);
|
|
80270
|
+
const isAbort = !innerTimeout && (executionAbortSignal?.aborted === true || errorObj.name === "AbortError");
|
|
80271
|
+
if (!isAbort) {
|
|
80272
|
+
logger?.error?.("Error processing LLM stream", {
|
|
80273
|
+
error,
|
|
80274
|
+
runId
|
|
80275
|
+
});
|
|
80276
|
+
if (modelSpanTracker) modelSpanTracker.reportGenerationError({
|
|
80277
|
+
error: errorObj,
|
|
80278
|
+
endSpan: false
|
|
80279
|
+
});
|
|
80280
|
+
else if (modelSpan) modelSpan.error({
|
|
80281
|
+
error: errorObj,
|
|
80282
|
+
endSpan: false
|
|
80283
|
+
});
|
|
80284
|
+
}
|
|
80217
80285
|
if (innerTimeout) throw innerTimeout;
|
|
80218
|
-
if (
|
|
80286
|
+
if (isAbort) {
|
|
80287
|
+
logger?.debug?.("LLM stream aborted", {
|
|
80288
|
+
error: errorObj,
|
|
80289
|
+
runId
|
|
80290
|
+
});
|
|
80219
80291
|
materializeStreamedMessages();
|
|
80220
80292
|
return {
|
|
80221
80293
|
...await storeStepTranscript(),
|
|
@@ -80280,21 +80352,28 @@ function createDurableLLMExecutionStep(_options) {
|
|
|
80280
80352
|
const streamError = outputStream.error;
|
|
80281
80353
|
if (streamError) {
|
|
80282
80354
|
const streamErrorObj = streamError instanceof Error ? streamError : new Error(String(streamError));
|
|
80283
|
-
logger?.error?.("Stream captured error", {
|
|
80284
|
-
error: streamErrorObj,
|
|
80285
|
-
runId
|
|
80286
|
-
});
|
|
80287
|
-
if (modelSpanTracker) modelSpanTracker.reportGenerationError({
|
|
80288
|
-
error: streamErrorObj,
|
|
80289
|
-
endSpan: false
|
|
80290
|
-
});
|
|
80291
|
-
else if (modelSpan) modelSpan.error({
|
|
80292
|
-
error: streamErrorObj,
|
|
80293
|
-
endSpan: false
|
|
80294
|
-
});
|
|
80295
80355
|
const streamErrorTimeout = resolveTotalTimeoutAbort(executionAbortSignal, streamErrorObj);
|
|
80356
|
+
const isStreamErrorAbort = !streamErrorTimeout && (executionAbortSignal?.aborted === true || streamErrorObj.name === "AbortError");
|
|
80357
|
+
if (!isStreamErrorAbort) {
|
|
80358
|
+
logger?.error?.("Stream captured error", {
|
|
80359
|
+
error: streamErrorObj,
|
|
80360
|
+
runId
|
|
80361
|
+
});
|
|
80362
|
+
if (modelSpanTracker) modelSpanTracker.reportGenerationError({
|
|
80363
|
+
error: streamErrorObj,
|
|
80364
|
+
endSpan: false
|
|
80365
|
+
});
|
|
80366
|
+
else if (modelSpan) modelSpan.error({
|
|
80367
|
+
error: streamErrorObj,
|
|
80368
|
+
endSpan: false
|
|
80369
|
+
});
|
|
80370
|
+
}
|
|
80296
80371
|
if (streamErrorTimeout) throw streamErrorTimeout;
|
|
80297
|
-
if (
|
|
80372
|
+
if (isStreamErrorAbort) {
|
|
80373
|
+
logger?.debug?.("Captured LLM stream aborted", {
|
|
80374
|
+
error: streamErrorObj,
|
|
80375
|
+
runId
|
|
80376
|
+
});
|
|
80298
80377
|
materializeStreamedMessages();
|
|
80299
80378
|
return {
|
|
80300
80379
|
...await storeStepTranscript(),
|
|
@@ -86268,7 +86347,7 @@ async function prepareForDurableExecution(options) {
|
|
|
86268
86347
|
});
|
|
86269
86348
|
let tripwireData;
|
|
86270
86349
|
if (inputProcessors.length > 0) try {
|
|
86271
|
-
const { ProcessorRunner } = await import("./stream-
|
|
86350
|
+
const { ProcessorRunner } = await import("./stream-D607FmAx.js").then((n) => n.L);
|
|
86272
86351
|
await new ProcessorRunner({
|
|
86273
86352
|
inputProcessors,
|
|
86274
86353
|
outputProcessors,
|
|
@@ -96142,7 +96221,7 @@ var Agent = class Agent extends MastraBase {
|
|
|
96142
96221
|
}
|
|
96143
96222
|
}
|
|
96144
96223
|
/** Rebuilds process-local recovery state from the persisted durable workflow input. */
|
|
96145
|
-
async #rehydrateRecoveryState({ runId, workflowInput, abortController, executionFence, originalSpansEnded, openStepsOf, latestMessageListState }) {
|
|
96224
|
+
async #rehydrateRecoveryState({ runId, workflowInput, abortController, onTerminalDeadline, executionFence, originalSpansEnded, openStepsOf, latestMessageListState }) {
|
|
96146
96225
|
const requestContext = workflowInput.requestContextEntries ? new RequestContext(Object.entries(workflowInput.requestContextEntries)) : new RequestContext();
|
|
96147
96226
|
restoreRunAgentScopes(requestContext);
|
|
96148
96227
|
const messageListMemoryInfo = workflowInput.messageListState?.memoryInfo;
|
|
@@ -96358,7 +96437,7 @@ var Agent = class Agent extends MastraBase {
|
|
|
96358
96437
|
subscribePendingSignals: (listener) => wrapped.__getSubscribePendingSignals()(runId, listener),
|
|
96359
96438
|
cleanup: () => {}
|
|
96360
96439
|
};
|
|
96361
|
-
this.installAbortWithTotalTimeout(registryEntry, abortController, executionFence);
|
|
96440
|
+
this.installAbortWithTotalTimeout(registryEntry, abortController, executionFence, onTerminalDeadline);
|
|
96362
96441
|
this.#runInputs.set(executionFence, {
|
|
96363
96442
|
...workflowInput,
|
|
96364
96443
|
messageListState: latestMessageListState ?? workflowInput.messageListState
|
|
@@ -96557,7 +96636,7 @@ var Agent = class Agent extends MastraBase {
|
|
|
96557
96636
|
* each session gets a fresh timer. The timer is torn down via the entry's
|
|
96558
96637
|
* `cleanup` slot, which every settle path invokes through the run registry.
|
|
96559
96638
|
*/
|
|
96560
|
-
installAbortWithTotalTimeout(entry, abortController, executionFence) {
|
|
96639
|
+
installAbortWithTotalTimeout(entry, abortController, executionFence, onTerminalDeadline) {
|
|
96561
96640
|
entry.abortController = abortController;
|
|
96562
96641
|
entry.deadlineErrorRedelivered = false;
|
|
96563
96642
|
const totalTimeout = createTimeoutAbortSignal({
|
|
@@ -96569,10 +96648,14 @@ var Agent = class Agent extends MastraBase {
|
|
|
96569
96648
|
entry.abortSignal = totalTimeout.signal;
|
|
96570
96649
|
if (totalTimeout.timeoutPromise) totalTimeout.timeoutPromise.catch(async (error) => {
|
|
96571
96650
|
if (!isMastraTimeoutError(error) || error.timeoutType !== "total" || totalTimeout.signal?.reason !== error) return;
|
|
96572
|
-
|
|
96573
|
-
|
|
96574
|
-
|
|
96575
|
-
|
|
96651
|
+
try {
|
|
96652
|
+
await this.settleExecution(executionFence.runId, executionFence, {
|
|
96653
|
+
status: "failed",
|
|
96654
|
+
error
|
|
96655
|
+
});
|
|
96656
|
+
} finally {
|
|
96657
|
+
onTerminalDeadline?.();
|
|
96658
|
+
}
|
|
96576
96659
|
}).catch((error) => {
|
|
96577
96660
|
this.logger.warn("Failed to settle durable agent at its total deadline", { error });
|
|
96578
96661
|
});
|
|
@@ -96671,11 +96754,19 @@ var Agent = class Agent extends MastraBase {
|
|
|
96671
96754
|
}
|
|
96672
96755
|
this.executionEngine.assertRecoveryActive();
|
|
96673
96756
|
const releaseLocalRecovery = this.executionEngine.claimLocalRecovery(this.id, this.name, runId);
|
|
96674
|
-
const { controller: abortController } = createRunAbortController(options?.abortSignal);
|
|
96757
|
+
const { controller: abortController, detach: detachExternalAbort } = createRunAbortController(options?.abortSignal);
|
|
96758
|
+
let recoveryReleased = false;
|
|
96759
|
+
const releaseRecovery = () => {
|
|
96760
|
+
if (recoveryReleased) return;
|
|
96761
|
+
recoveryReleased = true;
|
|
96762
|
+
detachExternalAbort();
|
|
96763
|
+
releaseLocalRecovery();
|
|
96764
|
+
};
|
|
96675
96765
|
let executionFence;
|
|
96676
96766
|
let recoveryState;
|
|
96677
96767
|
let finishPublishedBeforeCrash;
|
|
96678
96768
|
let claimedSnapshot;
|
|
96769
|
+
let recoveryHandedOff = false;
|
|
96679
96770
|
try {
|
|
96680
96771
|
executionFence = await this.executionEngine.claimExecution(runId, options?.force ? "takeover" : "recover", this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, this.logger, this.#untrackedRunLiveness(runId, workflowInput));
|
|
96681
96772
|
this.executionEngine.assertRecoveryActive();
|
|
@@ -96689,6 +96780,7 @@ var Agent = class Agent extends MastraBase {
|
|
|
96689
96780
|
runId,
|
|
96690
96781
|
workflowInput,
|
|
96691
96782
|
abortController,
|
|
96783
|
+
onTerminalDeadline: detachExternalAbort,
|
|
96692
96784
|
executionFence,
|
|
96693
96785
|
originalSpansEnded: loaded.originalSpansEnded,
|
|
96694
96786
|
openStepsOf: loaded.openStepsOf,
|
|
@@ -96698,146 +96790,154 @@ var Agent = class Agent extends MastraBase {
|
|
|
96698
96790
|
this.#recoveredEntries.set(executionFence, recoveryState.registryEntry);
|
|
96699
96791
|
this.executionEngine.assertRecoveryActive();
|
|
96700
96792
|
} catch (error) {
|
|
96701
|
-
|
|
96702
|
-
|
|
96703
|
-
|
|
96704
|
-
|
|
96705
|
-
|
|
96706
|
-
const { requestContext, threadId, resourceId, messageList, recoverAgentSpan, recoverModelSpan, registryEntry } = recoveryState;
|
|
96707
|
-
if (executionFence.generation !== void 0) {
|
|
96708
|
-
const supersededFrom = await this.executionEngine.recoverySupersededFrom(workflowsStore, runId, claimedSnapshot, () => this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, () => this.logger);
|
|
96709
|
-
await emitOwnershipClaimedEvent(this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, runId, executionFence.generation, supersededFrom).catch((error) => {
|
|
96710
|
-
this.logger.warn(`[DurableAgent] recover(${runId}) failed to announce its claim on the run stream`, {
|
|
96711
|
-
runId,
|
|
96712
|
-
error
|
|
96713
|
-
});
|
|
96714
|
-
});
|
|
96715
|
-
}
|
|
96716
|
-
setExecutionClaim(requestContext, runId, executionFence.claim);
|
|
96717
|
-
registryEntry.executionFence = executionFence;
|
|
96718
|
-
let streamCleanup;
|
|
96719
|
-
const cleanupOwnedRegistryState = () => {
|
|
96720
|
-
if (registryEntry.executionFence !== executionFence) return;
|
|
96721
|
-
if (this.executionRunRegistry.get(runId) === registryEntry) this.executionRunRegistry.cleanup(runId);
|
|
96722
|
-
if (getRunRegistryEntry(runId, this.#mastra) === registryEntry) {
|
|
96723
|
-
globalRunRegistry.delete(runId);
|
|
96724
|
-
if (!this.#unverifiedReaderFences.has(executionFence) && (registryEntry.executionFence?.ownsRunTopics() ?? true)) this.clearPubsubTopic(runId, registryEntry);
|
|
96725
|
-
}
|
|
96726
|
-
};
|
|
96727
|
-
const runCleanup = createRunCleanup({
|
|
96728
|
-
scheduleTimer: (cleanup) => this.scheduleReaderCleanup(executionFence, cleanup),
|
|
96729
|
-
release: () => {
|
|
96730
|
-
agentThreadStreamRuntime.closeRunContinuation(output, this.getPubSub());
|
|
96731
|
-
streamCleanup?.();
|
|
96732
|
-
cleanupOwnedRegistryState();
|
|
96793
|
+
try {
|
|
96794
|
+
const settlement = await executionFence?.settle(async () => {});
|
|
96795
|
+
if (executionFence && settlement !== "superseded" && this.executionEngine.shouldReportRecoveryFailure(error)) await this.#reportRecoveryFailure(runId, error, executionFence.generation);
|
|
96796
|
+
} finally {
|
|
96797
|
+
releaseRecovery();
|
|
96733
96798
|
}
|
|
96734
|
-
});
|
|
96735
|
-
const performCleanup = runCleanup.run;
|
|
96736
|
-
const scheduleAutoCleanup = runCleanup.schedule;
|
|
96737
|
-
let workflow;
|
|
96738
|
-
try {
|
|
96739
|
-
this.executionEngine.assertRecoveryActive();
|
|
96740
|
-
workflow = this.getWorkflow();
|
|
96741
|
-
} catch (error) {
|
|
96742
|
-
if (await executionFence.settle(async () => {}) !== "superseded" && this.executionEngine.shouldReportRecoveryFailure(error)) await this.#reportRecoveryFailure(runId, error, executionFence.generation);
|
|
96743
|
-
releaseLocalRecovery();
|
|
96744
96799
|
throw error;
|
|
96745
96800
|
}
|
|
96746
|
-
|
|
96747
|
-
|
|
96748
|
-
|
|
96749
|
-
|
|
96750
|
-
|
|
96751
|
-
|
|
96752
|
-
|
|
96753
|
-
|
|
96754
|
-
|
|
96755
|
-
scheduleAutoCleanup,
|
|
96756
|
-
executionFence
|
|
96757
|
-
}).catch((error) => {
|
|
96758
|
-
releaseLocalRecovery();
|
|
96759
|
-
throw error;
|
|
96760
|
-
});
|
|
96761
|
-
const { output, cleanup: createdStreamCleanup, ready } = stream;
|
|
96762
|
-
streamCleanup = createdStreamCleanup;
|
|
96763
|
-
const recoveryPubsub = this.fenceRunPubSub(executionFence, abortController);
|
|
96764
|
-
const workflowExecution = executionFence.run(() => this.executionEngine.raceFenceLoss(ready, executionFence).then(async () => {
|
|
96765
|
-
const result = await this.executionEngine.restartRun(workflow, executionFence, recoveryPubsub, this.workflowEngine, this.logger, resourceId, requestContext, createObservabilityContext({ currentSpan: recoverAgentSpan }));
|
|
96766
|
-
if (finishPublishedBeforeCrash && result?.status === "success") {
|
|
96767
|
-
const { output: finalOutput, stepResult, tracingTermination, stopCause } = result.result;
|
|
96768
|
-
recoverModelSpan?.end({ ...tracingTermination });
|
|
96769
|
-
recoverAgentSpan?.end({
|
|
96770
|
-
...tracingTermination,
|
|
96771
|
-
output: { text: finalOutput?.text }
|
|
96772
|
-
});
|
|
96773
|
-
await emitFinishEvent(recoveryPubsub, runId, {
|
|
96774
|
-
output: finalOutput,
|
|
96775
|
-
stepResult,
|
|
96776
|
-
...stopCause && { stopCause }
|
|
96801
|
+
try {
|
|
96802
|
+
const { requestContext, threadId, resourceId, messageList, recoverAgentSpan, recoverModelSpan, registryEntry } = recoveryState;
|
|
96803
|
+
if (executionFence.generation !== void 0) {
|
|
96804
|
+
const supersededFrom = await this.executionEngine.recoverySupersededFrom(workflowsStore, runId, claimedSnapshot, () => this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, () => this.logger);
|
|
96805
|
+
await emitOwnershipClaimedEvent(this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, runId, executionFence.generation, supersededFrom).catch((error) => {
|
|
96806
|
+
this.logger.warn(`[DurableAgent] recover(${runId}) failed to announce its claim on the run stream`, {
|
|
96807
|
+
runId,
|
|
96808
|
+
error
|
|
96809
|
+
});
|
|
96777
96810
|
});
|
|
96778
96811
|
}
|
|
96779
|
-
|
|
96780
|
-
|
|
96781
|
-
|
|
96782
|
-
|
|
96783
|
-
|
|
96812
|
+
setExecutionClaim(requestContext, runId, executionFence.claim);
|
|
96813
|
+
registryEntry.executionFence = executionFence;
|
|
96814
|
+
let streamCleanup;
|
|
96815
|
+
const cleanupOwnedRegistryState = () => {
|
|
96816
|
+
if (registryEntry.executionFence !== executionFence) return;
|
|
96817
|
+
if (this.executionRunRegistry.get(runId) === registryEntry) this.executionRunRegistry.cleanup(runId);
|
|
96818
|
+
if (getRunRegistryEntry(runId, this.#mastra) === registryEntry) {
|
|
96819
|
+
globalRunRegistry.delete(runId);
|
|
96820
|
+
if (!this.#unverifiedReaderFences.has(executionFence) && (registryEntry.executionFence?.ownsRunTopics() ?? true)) this.clearPubsubTopic(runId, registryEntry);
|
|
96821
|
+
}
|
|
96822
|
+
};
|
|
96823
|
+
const runCleanup = createRunCleanup({
|
|
96824
|
+
scheduleTimer: (cleanup) => this.scheduleReaderCleanup(executionFence, cleanup),
|
|
96825
|
+
release: () => {
|
|
96826
|
+
agentThreadStreamRuntime.closeRunContinuation(output, this.getPubSub());
|
|
96827
|
+
streamCleanup?.();
|
|
96828
|
+
cleanupOwnedRegistryState();
|
|
96829
|
+
}
|
|
96830
|
+
});
|
|
96831
|
+
const performCleanup = runCleanup.run;
|
|
96832
|
+
const scheduleAutoCleanup = runCleanup.schedule;
|
|
96833
|
+
let workflow;
|
|
96834
|
+
try {
|
|
96835
|
+
this.executionEngine.assertRecoveryActive();
|
|
96836
|
+
workflow = this.getWorkflow();
|
|
96837
|
+
} catch (error) {
|
|
96838
|
+
if (await executionFence.settle(async () => {}) !== "superseded" && this.executionEngine.shouldReportRecoveryFailure(error)) await this.#reportRecoveryFailure(runId, error, executionFence.generation);
|
|
96839
|
+
releaseRecovery();
|
|
96840
|
+
throw error;
|
|
96784
96841
|
}
|
|
96785
|
-
const
|
|
96786
|
-
|
|
96787
|
-
|
|
96788
|
-
|
|
96842
|
+
const { stream, threadRegistration } = await this.#setupRecoveredStream({
|
|
96843
|
+
runId,
|
|
96844
|
+
workflowInput,
|
|
96845
|
+
requestContext,
|
|
96846
|
+
threadId,
|
|
96847
|
+
resourceId,
|
|
96848
|
+
messageList,
|
|
96849
|
+
registryEntry,
|
|
96850
|
+
options,
|
|
96851
|
+
scheduleAutoCleanup,
|
|
96852
|
+
executionFence
|
|
96853
|
+
}).catch((error) => {
|
|
96854
|
+
releaseRecovery();
|
|
96855
|
+
throw error;
|
|
96789
96856
|
});
|
|
96790
|
-
|
|
96791
|
-
|
|
96792
|
-
|
|
96793
|
-
const
|
|
96794
|
-
|
|
96795
|
-
|
|
96796
|
-
|
|
96797
|
-
|
|
96798
|
-
|
|
96799
|
-
|
|
96800
|
-
|
|
96801
|
-
|
|
96802
|
-
|
|
96803
|
-
|
|
96804
|
-
|
|
96805
|
-
|
|
96806
|
-
|
|
96807
|
-
|
|
96808
|
-
|
|
96809
|
-
|
|
96857
|
+
const { output, cleanup: createdStreamCleanup, ready } = stream;
|
|
96858
|
+
streamCleanup = createdStreamCleanup;
|
|
96859
|
+
const recoveryPubsub = this.fenceRunPubSub(executionFence, abortController);
|
|
96860
|
+
const workflowExecution = executionFence.run(() => this.executionEngine.raceFenceLoss(ready, executionFence).then(async () => {
|
|
96861
|
+
const result = await this.executionEngine.restartRun(workflow, executionFence, recoveryPubsub, this.workflowEngine, this.logger, resourceId, requestContext, createObservabilityContext({ currentSpan: recoverAgentSpan }));
|
|
96862
|
+
if (finishPublishedBeforeCrash && result?.status === "success") {
|
|
96863
|
+
const { output: finalOutput, stepResult, tracingTermination, stopCause } = result.result;
|
|
96864
|
+
recoverModelSpan?.end({ ...tracingTermination });
|
|
96865
|
+
recoverAgentSpan?.end({
|
|
96866
|
+
...tracingTermination,
|
|
96867
|
+
output: { text: finalOutput?.text }
|
|
96868
|
+
});
|
|
96869
|
+
await emitFinishEvent(recoveryPubsub, runId, {
|
|
96870
|
+
output: finalOutput,
|
|
96871
|
+
stepResult,
|
|
96872
|
+
...stopCause && { stopCause }
|
|
96873
|
+
});
|
|
96874
|
+
}
|
|
96875
|
+
if (result?.status === "suspended" && options?.closeOnSuspend) {
|
|
96876
|
+
await this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub.flush();
|
|
96877
|
+
await stream.waitForEventDelivery();
|
|
96878
|
+
executionFence.throwIfLost();
|
|
96879
|
+
stream.detach();
|
|
96880
|
+
}
|
|
96881
|
+
const finished = !!result?.status && result.status !== "suspended";
|
|
96882
|
+
await executionFence.settle(async () => {
|
|
96883
|
+
if (finished) await this.deleteRunSnapshots(runId);
|
|
96884
|
+
if (finished) await releaseRemoteAbortListener(runId, this.#mastra);
|
|
96810
96885
|
});
|
|
96811
|
-
|
|
96812
|
-
|
|
96813
|
-
|
|
96814
|
-
|
|
96815
|
-
|
|
96816
|
-
|
|
96817
|
-
|
|
96818
|
-
|
|
96819
|
-
|
|
96820
|
-
|
|
96821
|
-
|
|
96822
|
-
|
|
96823
|
-
|
|
96824
|
-
|
|
96825
|
-
|
|
96826
|
-
|
|
96827
|
-
|
|
96828
|
-
|
|
96829
|
-
|
|
96830
|
-
|
|
96831
|
-
|
|
96832
|
-
|
|
96833
|
-
|
|
96834
|
-
|
|
96835
|
-
|
|
96836
|
-
|
|
96837
|
-
|
|
96838
|
-
|
|
96839
|
-
|
|
96840
|
-
|
|
96886
|
+
if (result?.status === "failed") throw this.executionEngine.workflowFailureError(result.error, "Workflow recover failed");
|
|
96887
|
+
}).catch(async (error) => {
|
|
96888
|
+
if (error?.id === "DURABLE_AGENT_RECOVER_SHUTDOWN") await executionFence.abandon();
|
|
96889
|
+
const executionError = this.executionEngine.workflowExecutionError(error, "Workflow recover failed");
|
|
96890
|
+
if (await executionFence.settle(async () => {}) === "superseded") {
|
|
96891
|
+
const output = {
|
|
96892
|
+
status: "interrupted",
|
|
96893
|
+
reason: "recovery superseded"
|
|
96894
|
+
};
|
|
96895
|
+
recoverModelSpan?.end({
|
|
96896
|
+
output,
|
|
96897
|
+
outcome: "interrupted",
|
|
96898
|
+
stopReason: null,
|
|
96899
|
+
stopReasonContext: null
|
|
96900
|
+
});
|
|
96901
|
+
recoverAgentSpan?.end({
|
|
96902
|
+
output,
|
|
96903
|
+
outcome: "interrupted",
|
|
96904
|
+
stopReason: null,
|
|
96905
|
+
stopReasonContext: null
|
|
96906
|
+
});
|
|
96907
|
+
await threadRegistration?.rollback({ releaseLease: false });
|
|
96908
|
+
performCleanup();
|
|
96909
|
+
} else if (!this.#timedOutExecutions.has(executionFence) && !await this.#reportRecoveryFailure(runId, executionError, executionFence.generation)) {
|
|
96910
|
+
await threadRegistration?.rollback();
|
|
96911
|
+
performCleanup();
|
|
96912
|
+
}
|
|
96913
|
+
throw executionError;
|
|
96914
|
+
}).finally(releaseRecovery));
|
|
96915
|
+
recoveryHandedOff = true;
|
|
96916
|
+
const trackedRecoverEntry = getRunRegistryEntry(runId, this.#mastra);
|
|
96917
|
+
if (trackedRecoverEntry) trackedRecoverEntry.workflowExecution = workflowExecution;
|
|
96918
|
+
workflowExecution.catch(() => {});
|
|
96919
|
+
const cleanup = performCleanup;
|
|
96920
|
+
const abort = async (reason) => {
|
|
96921
|
+
if (!abortController.signal.aborted) abortController.abort(reason);
|
|
96922
|
+
await this.requestRemoteAbort(runId);
|
|
96923
|
+
if (agentThreadStreamRuntime.isRunParked(runId, this.getPubSub())) this.abortRunStream(runId);
|
|
96924
|
+
};
|
|
96925
|
+
return {
|
|
96926
|
+
output,
|
|
96927
|
+
get fullStream() {
|
|
96928
|
+
return output.fullStream;
|
|
96929
|
+
},
|
|
96930
|
+
runId,
|
|
96931
|
+
threadId,
|
|
96932
|
+
resourceId,
|
|
96933
|
+
traceId: output.traceId,
|
|
96934
|
+
spanId: output.spanId,
|
|
96935
|
+
cleanup,
|
|
96936
|
+
abort
|
|
96937
|
+
};
|
|
96938
|
+
} finally {
|
|
96939
|
+
if (!recoveryHandedOff) releaseRecovery();
|
|
96940
|
+
}
|
|
96841
96941
|
}
|
|
96842
96942
|
/**
|
|
96843
96943
|
* Clear retained pubsub state for a run's topics (cached history and, for
|
|
@@ -97241,166 +97341,172 @@ var Agent = class Agent extends MastraBase {
|
|
|
97241
97341
|
setExecutionClaim(requestContext, runId, executionFence.claim);
|
|
97242
97342
|
registryEntry.executionFence = executionFence;
|
|
97243
97343
|
this.#runInputs.set(executionFence, workflowInput);
|
|
97244
|
-
const { controller: abortController } = createRunAbortController(options?.abortSignal);
|
|
97245
|
-
|
|
97246
|
-
|
|
97247
|
-
|
|
97248
|
-
|
|
97249
|
-
|
|
97250
|
-
|
|
97251
|
-
|
|
97252
|
-
|
|
97253
|
-
|
|
97254
|
-
...registryEntry,
|
|
97255
|
-
messageList
|
|
97256
|
-
};
|
|
97257
|
-
globalRunRegistry.set(runId, globalRegistryEntry);
|
|
97258
|
-
await this.attachStreamPublisher(runId, {
|
|
97259
|
-
threadId,
|
|
97260
|
-
resourceId
|
|
97261
|
-
});
|
|
97262
|
-
const segment = methodType === "stream" ? this.#beginSegment(runId) : void 0;
|
|
97263
|
-
let streamCleanup;
|
|
97264
|
-
const releaseRunState = () => {
|
|
97265
|
-
if (segment !== void 0) {
|
|
97266
|
-
if (!this.#releaseSegment(runId, segment, registryEntry)) return;
|
|
97267
|
-
} else if (this.executionRunRegistry.get(runId) === registryEntry) this.executionRunRegistry.cleanup(runId);
|
|
97268
|
-
if (getRunRegistryEntry(runId, this.#mastra) === globalRegistryEntry) {
|
|
97269
|
-
globalRunRegistry.delete(runId);
|
|
97270
|
-
if (!this.#unverifiedReaderFences.has(executionFence) && (globalRegistryEntry.executionFence?.ownsRunTopics() ?? true)) this.clearPubsubTopic(runId, globalRegistryEntry);
|
|
97271
|
-
}
|
|
97272
|
-
};
|
|
97273
|
-
const runCleanup = createRunCleanup({
|
|
97274
|
-
scheduleTimer: (cleanup) => this.scheduleReaderCleanup(executionFence, cleanup),
|
|
97275
|
-
release: () => {
|
|
97276
|
-
agentThreadStreamRuntime.closeRunContinuation(output, this.getPubSub());
|
|
97277
|
-
streamCleanup?.();
|
|
97278
|
-
releaseRunState();
|
|
97279
|
-
},
|
|
97280
|
-
...methodType === "generate" ? { releaseOnTimer: releaseRunState } : {}
|
|
97281
|
-
});
|
|
97282
|
-
const performCleanup = runCleanup.run;
|
|
97283
|
-
const scheduleAutoCleanup = runCleanup.schedule;
|
|
97284
|
-
const closeOnSuspend = methodType === "generate" || (options?.closeOnSuspend ?? false);
|
|
97285
|
-
const closeOnPersistedSuspend = methodType === "stream" && closeOnSuspend && this.executionEngine.suspendPersistedOnReturn;
|
|
97286
|
-
const { output, cleanup: createdStreamCleanup, detach: detachStream, waitForEventDelivery, ready } = createDurableAgentStream({
|
|
97287
|
-
pubsub: this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub,
|
|
97288
|
-
runId,
|
|
97289
|
-
minGeneration: executionFence.generation,
|
|
97290
|
-
onTerminalEvent: this.owningReaderTerminal(runId, executionFence),
|
|
97291
|
-
readLocalRequest,
|
|
97292
|
-
messageId,
|
|
97293
|
-
model: {
|
|
97294
|
-
modelId: workflowInput.modelConfig.modelId,
|
|
97295
|
-
provider: workflowInput.modelConfig.provider,
|
|
97296
|
-
version: "v3"
|
|
97297
|
-
},
|
|
97298
|
-
threadId,
|
|
97299
|
-
resourceId,
|
|
97300
|
-
onChunk: options?.onChunk,
|
|
97301
|
-
experimentalTransform: options?.experimentalTransform,
|
|
97302
|
-
onStepFinish: options?.onStepFinish,
|
|
97303
|
-
onFinish: options?.onFinish,
|
|
97304
|
-
onStreamFinished: scheduleAutoCleanup,
|
|
97305
|
-
onError: async (error) => {
|
|
97306
|
-
await options?.onError?.(error);
|
|
97307
|
-
scheduleAutoCleanup();
|
|
97308
|
-
},
|
|
97309
|
-
onSuspended: options?.onSuspended,
|
|
97310
|
-
onAbort: async (data) => {
|
|
97311
|
-
try {
|
|
97312
|
-
await (options?.onAbort)?.(data);
|
|
97313
|
-
} finally {
|
|
97314
|
-
scheduleAutoCleanup();
|
|
97315
|
-
}
|
|
97316
|
-
},
|
|
97317
|
-
closeOnSuspend: closeOnSuspend && !closeOnPersistedSuspend,
|
|
97318
|
-
...methodType === "stream" ? { hideSignals: options?.hideSignals } : {},
|
|
97319
|
-
structuredOutput: registryEntry.structuredOutput,
|
|
97320
|
-
outputProcessors: registryEntry.outputProcessors,
|
|
97321
|
-
processorStates: registryEntry.processorStates,
|
|
97322
|
-
agent: registryEntry.agent,
|
|
97323
|
-
requestContext: registryEntry.requestContext,
|
|
97324
|
-
returnScorerData: workflowInput.options.returnScorerData,
|
|
97325
|
-
tracingContext: registryEntry.agentSpan ? { currentSpan: registryEntry.agentSpan } : void 0,
|
|
97326
|
-
messageList,
|
|
97327
|
-
messageListFollowsStream: () => !this.executionEngine.executesStepsLocally
|
|
97328
|
-
});
|
|
97329
|
-
streamCleanup = createdStreamCleanup;
|
|
97330
|
-
const threadRegistration = agentThreadStreamRuntime.registerRun(this, output, options, this.getPubSub(), {
|
|
97331
|
-
continuation: methodType === "stream" && !closeOnSuspend ? "across-suspension" : void 0,
|
|
97332
|
-
generation: executionFence.generation,
|
|
97333
|
-
ownershipLost: () => executionFence.isLost(),
|
|
97334
|
-
stepOwner: () => getRunRegistryEntry(runId, this.#mastra),
|
|
97335
|
-
signalsStore: registryEntry.pendingSignalsStore
|
|
97336
|
-
});
|
|
97337
|
-
const workflowExecution = executionFence.run(() => Promise.all([ready, threadRegistration]).then(async () => {
|
|
97338
|
-
if (await this.redeliverDeadlineError(registryEntry, executionFence)) return;
|
|
97339
|
-
await emitChunkEvent(fencePubSub(this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, executionFence), runId, {
|
|
97340
|
-
type: "start",
|
|
97341
|
-
runId,
|
|
97342
|
-
from: "AGENT",
|
|
97343
|
-
payload: {
|
|
97344
|
-
id: workflowInput.agentId,
|
|
97345
|
-
messageId
|
|
97346
|
-
}
|
|
97344
|
+
const { controller: abortController, detach: detachExternalAbort } = createRunAbortController(options?.abortSignal);
|
|
97345
|
+
let workflowExecutionOwnsDetach = false;
|
|
97346
|
+
try {
|
|
97347
|
+
if (agentThreadStreamRuntime.isRunAborted(runId, this.getPubSub())) abortController.abort();
|
|
97348
|
+
this.installAbortWithTotalTimeout(registryEntry, abortController, executionFence, detachExternalAbort);
|
|
97349
|
+
const readLocalRequest = createLocalRequestReader(runId, registryEntry, this.#mastra);
|
|
97350
|
+
registryEntry.agentId = this.id;
|
|
97351
|
+
this.executionRunRegistry.registerWithMessageList(runId, registryEntry, messageList, {
|
|
97352
|
+
threadId,
|
|
97353
|
+
resourceId
|
|
97347
97354
|
});
|
|
97348
|
-
|
|
97349
|
-
|
|
97350
|
-
|
|
97355
|
+
const globalRegistryEntry = {
|
|
97356
|
+
...registryEntry,
|
|
97357
|
+
messageList
|
|
97358
|
+
};
|
|
97359
|
+
globalRunRegistry.set(runId, globalRegistryEntry);
|
|
97360
|
+
await this.attachStreamPublisher(runId, {
|
|
97351
97361
|
threadId,
|
|
97362
|
+
resourceId
|
|
97363
|
+
});
|
|
97364
|
+
const segment = methodType === "stream" ? this.#beginSegment(runId) : void 0;
|
|
97365
|
+
let streamCleanup;
|
|
97366
|
+
const releaseRunState = () => {
|
|
97367
|
+
if (segment !== void 0) {
|
|
97368
|
+
if (!this.#releaseSegment(runId, segment, registryEntry)) return;
|
|
97369
|
+
} else if (this.executionRunRegistry.get(runId) === registryEntry) this.executionRunRegistry.cleanup(runId);
|
|
97370
|
+
if (getRunRegistryEntry(runId, this.#mastra) === globalRegistryEntry) {
|
|
97371
|
+
globalRunRegistry.delete(runId);
|
|
97372
|
+
if (!this.#unverifiedReaderFences.has(executionFence) && (globalRegistryEntry.executionFence?.ownsRunTopics() ?? true)) this.clearPubsubTopic(runId, globalRegistryEntry);
|
|
97373
|
+
}
|
|
97374
|
+
};
|
|
97375
|
+
const runCleanup = createRunCleanup({
|
|
97376
|
+
scheduleTimer: (cleanup) => this.scheduleReaderCleanup(executionFence, cleanup),
|
|
97377
|
+
release: () => {
|
|
97378
|
+
agentThreadStreamRuntime.closeRunContinuation(output, this.getPubSub());
|
|
97379
|
+
streamCleanup?.();
|
|
97380
|
+
releaseRunState();
|
|
97381
|
+
},
|
|
97382
|
+
...methodType === "generate" ? { releaseOnTimer: releaseRunState } : {}
|
|
97383
|
+
});
|
|
97384
|
+
const performCleanup = runCleanup.run;
|
|
97385
|
+
const scheduleAutoCleanup = runCleanup.schedule;
|
|
97386
|
+
const closeOnSuspend = methodType === "generate" || (options?.closeOnSuspend ?? false);
|
|
97387
|
+
const closeOnPersistedSuspend = methodType === "stream" && closeOnSuspend && this.executionEngine.suspendPersistedOnReturn;
|
|
97388
|
+
const { output, cleanup: createdStreamCleanup, detach: detachStream, waitForEventDelivery, ready } = createDurableAgentStream({
|
|
97389
|
+
pubsub: this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub,
|
|
97352
97390
|
runId,
|
|
97353
|
-
|
|
97391
|
+
minGeneration: executionFence.generation,
|
|
97392
|
+
onTerminalEvent: this.owningReaderTerminal(runId, executionFence),
|
|
97393
|
+
readLocalRequest,
|
|
97394
|
+
messageId,
|
|
97395
|
+
model: {
|
|
97396
|
+
modelId: workflowInput.modelConfig.modelId,
|
|
97397
|
+
provider: workflowInput.modelConfig.provider,
|
|
97398
|
+
version: "v3"
|
|
97399
|
+
},
|
|
97400
|
+
threadId,
|
|
97401
|
+
resourceId,
|
|
97402
|
+
onChunk: options?.onChunk,
|
|
97403
|
+
experimentalTransform: options?.experimentalTransform,
|
|
97404
|
+
onStepFinish: options?.onStepFinish,
|
|
97405
|
+
onFinish: options?.onFinish,
|
|
97406
|
+
onStreamFinished: scheduleAutoCleanup,
|
|
97407
|
+
onError: async (error) => {
|
|
97408
|
+
await options?.onError?.(error);
|
|
97409
|
+
scheduleAutoCleanup();
|
|
97410
|
+
},
|
|
97411
|
+
onSuspended: options?.onSuspended,
|
|
97412
|
+
onAbort: async (data) => {
|
|
97413
|
+
try {
|
|
97414
|
+
await (options?.onAbort)?.(data);
|
|
97415
|
+
} finally {
|
|
97416
|
+
scheduleAutoCleanup();
|
|
97417
|
+
}
|
|
97418
|
+
},
|
|
97419
|
+
closeOnSuspend: closeOnSuspend && !closeOnPersistedSuspend,
|
|
97420
|
+
...methodType === "stream" ? { hideSignals: options?.hideSignals } : {},
|
|
97421
|
+
structuredOutput: registryEntry.structuredOutput,
|
|
97422
|
+
outputProcessors: registryEntry.outputProcessors,
|
|
97423
|
+
processorStates: registryEntry.processorStates,
|
|
97424
|
+
agent: registryEntry.agent,
|
|
97425
|
+
requestContext: registryEntry.requestContext,
|
|
97426
|
+
returnScorerData: workflowInput.options.returnScorerData,
|
|
97427
|
+
tracingContext: registryEntry.agentSpan ? { currentSpan: registryEntry.agentSpan } : void 0,
|
|
97428
|
+
messageList,
|
|
97429
|
+
messageListFollowsStream: () => !this.executionEngine.executesStepsLocally
|
|
97354
97430
|
});
|
|
97355
|
-
|
|
97356
|
-
|
|
97357
|
-
|
|
97358
|
-
|
|
97359
|
-
|
|
97360
|
-
|
|
97361
|
-
|
|
97362
|
-
}
|
|
97363
|
-
|
|
97364
|
-
|
|
97365
|
-
|
|
97366
|
-
|
|
97367
|
-
|
|
97431
|
+
streamCleanup = createdStreamCleanup;
|
|
97432
|
+
const threadRegistration = agentThreadStreamRuntime.registerRun(this, output, options, this.getPubSub(), {
|
|
97433
|
+
continuation: methodType === "stream" && !closeOnSuspend ? "across-suspension" : void 0,
|
|
97434
|
+
generation: executionFence.generation,
|
|
97435
|
+
ownershipLost: () => executionFence.isLost(),
|
|
97436
|
+
stepOwner: () => getRunRegistryEntry(runId, this.#mastra),
|
|
97437
|
+
signalsStore: registryEntry.pendingSignalsStore
|
|
97438
|
+
});
|
|
97439
|
+
const workflowExecution = executionFence.run(() => Promise.all([ready, threadRegistration]).then(async () => {
|
|
97440
|
+
if (await this.redeliverDeadlineError(registryEntry, executionFence)) return;
|
|
97441
|
+
await emitChunkEvent(fencePubSub(this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub, executionFence), runId, {
|
|
97442
|
+
type: "start",
|
|
97443
|
+
runId,
|
|
97444
|
+
from: "AGENT",
|
|
97445
|
+
payload: {
|
|
97446
|
+
id: workflowInput.agentId,
|
|
97447
|
+
messageId
|
|
97448
|
+
}
|
|
97449
|
+
});
|
|
97450
|
+
if (this.__getGoalConfig()) await beginGoalActivity({
|
|
97451
|
+
mastra: this.#mastra,
|
|
97368
97452
|
agentId: workflowInput.agentId,
|
|
97369
|
-
|
|
97453
|
+
threadId,
|
|
97454
|
+
runId,
|
|
97455
|
+
requestContext: getRunRegistryEntry(runId, this.#mastra)?.requestContext
|
|
97370
97456
|
});
|
|
97371
|
-
|
|
97372
|
-
|
|
97373
|
-
|
|
97374
|
-
|
|
97375
|
-
|
|
97376
|
-
|
|
97377
|
-
|
|
97378
|
-
|
|
97379
|
-
|
|
97380
|
-
|
|
97381
|
-
|
|
97382
|
-
|
|
97383
|
-
|
|
97384
|
-
|
|
97385
|
-
|
|
97386
|
-
|
|
97387
|
-
|
|
97388
|
-
|
|
97389
|
-
|
|
97390
|
-
|
|
97391
|
-
|
|
97392
|
-
|
|
97393
|
-
|
|
97394
|
-
|
|
97395
|
-
|
|
97396
|
-
runId,
|
|
97397
|
-
|
|
97398
|
-
|
|
97399
|
-
|
|
97400
|
-
|
|
97401
|
-
|
|
97402
|
-
|
|
97403
|
-
|
|
97457
|
+
let result;
|
|
97458
|
+
try {
|
|
97459
|
+
const signalsStore = registryEntry.pendingSignalsStore;
|
|
97460
|
+
const moved = signalsStore ? agentThreadStreamRuntime.storedSignalWritesSettled(signalsStore, this.getPubSub()) : void 0;
|
|
97461
|
+
if (moved) await moved;
|
|
97462
|
+
await this.#persistInitialInput(runId, workflowInput);
|
|
97463
|
+
result = await this.executeWorkflow(runId, workflowInput);
|
|
97464
|
+
} catch (error) {
|
|
97465
|
+
await this.#discardRestartableStart(runId, workflowInput.agentId);
|
|
97466
|
+
throw error;
|
|
97467
|
+
} finally {
|
|
97468
|
+
this.#restartableStarts.delete(runId);
|
|
97469
|
+
await stopGoalActivity({
|
|
97470
|
+
agentId: workflowInput.agentId,
|
|
97471
|
+
runId
|
|
97472
|
+
});
|
|
97473
|
+
}
|
|
97474
|
+
if (closeOnPersistedSuspend && result?.status === "suspended") {
|
|
97475
|
+
await this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub.flush();
|
|
97476
|
+
await waitForEventDelivery();
|
|
97477
|
+
detachStream();
|
|
97478
|
+
}
|
|
97479
|
+
if (methodType === "generate") return result;
|
|
97480
|
+
}).catch((error) => this.settleExecution(runId, executionFence, { error: this.executionEngine.workflowExecutionError(error, "Workflow execution failed") })).finally(detachExternalAbort));
|
|
97481
|
+
workflowExecutionOwnsDetach = true;
|
|
97482
|
+
const trackedEntry = getRunRegistryEntry(runId, this.#mastra);
|
|
97483
|
+
if (trackedEntry) trackedEntry.workflowExecution = workflowExecution;
|
|
97484
|
+
await threadRegistration;
|
|
97485
|
+
const cleanup = () => {
|
|
97486
|
+
if (methodType === "generate" || runCleanup.done || output.status !== "running") return performCleanup();
|
|
97487
|
+
Promise.race([workflowExecution, executionFence.whenSettled]).then(() => this.#executionStreamBus.forRun(this.__usesSharedRunLog()).pubsub.flush()).then(() => waitForEventDelivery()).catch(() => {}).finally(performCleanup);
|
|
97488
|
+
};
|
|
97489
|
+
const abort = async (reason) => {
|
|
97490
|
+
if (!abortController.signal.aborted) abortController.abort(reason);
|
|
97491
|
+
await this.requestRemoteAbort(runId);
|
|
97492
|
+
if (agentThreadStreamRuntime.isRunParked(runId, this.getPubSub())) this.abortRunStream(runId);
|
|
97493
|
+
};
|
|
97494
|
+
return {
|
|
97495
|
+
output,
|
|
97496
|
+
get fullStream() {
|
|
97497
|
+
return output.fullStream;
|
|
97498
|
+
},
|
|
97499
|
+
runId,
|
|
97500
|
+
threadId,
|
|
97501
|
+
resourceId,
|
|
97502
|
+
traceId: output.traceId,
|
|
97503
|
+
spanId: output.spanId,
|
|
97504
|
+
cleanup,
|
|
97505
|
+
abort
|
|
97506
|
+
};
|
|
97507
|
+
} finally {
|
|
97508
|
+
if (!workflowExecutionOwnsDetach) detachExternalAbort();
|
|
97509
|
+
}
|
|
97404
97510
|
}
|
|
97405
97511
|
async #generateDurable(messages, options) {
|
|
97406
97512
|
options = await this.#resolveDurableRunOptions(applyReservedMemoryContextKeys(options));
|
|
@@ -97805,7 +97911,7 @@ var Agent = class Agent extends MastraBase {
|
|
|
97805
97911
|
const resumeTotalMs = resolvedOptions.modelSettings?.timeout?.totalMs;
|
|
97806
97912
|
if (resumeTotalMs !== void 0) entry.timeoutTotalMs = resumeTotalMs;
|
|
97807
97913
|
if (persistedInput) this.#runInputs.set(executionFence, persistedInput);
|
|
97808
|
-
this.installAbortWithTotalTimeout(entry, abortController, executionFence);
|
|
97914
|
+
this.installAbortWithTotalTimeout(entry, abortController, executionFence, detachExternalAbort);
|
|
97809
97915
|
const globalEntryForAbort = getRunRegistryEntry(runId, this.#mastra);
|
|
97810
97916
|
if (globalEntryForAbort) {
|
|
97811
97917
|
globalEntryForAbort.abortController = abortController;
|