@mastra/core
Version:
75 lines (74 loc) • 6.76 kB
JavaScript
import { $l as getStepIds, Al as DefaultExecutionEngine, Bl as RESUME_SNAPSHOT_WAIT_STATUSES, Gl as createDeprecationProxy, Hl as applyStateDelta, Jl as defineLazyWriter, Kl as createRestartExecutionParams, Ml as createStepFromAgent, Nl as createStepFromClassifier, Pl as createStepFromTool, Ql as getSingleStepEntryId, Ul as assertTimeTravelGraphMatchesSnapshot, Vl as abortableSleep, Wl as cleanStepResult, Xl as getRestartStartIndex, Yl as defineStateAccessors, Zl as getResumeLabelsByStepId, _l as isProcessor, _u as getEntryWorkflow, au as resolveForeachConcurrency, bl as evaluatePredicate, bt as computeScheduleDefinitionHash, bu as ExecutionEngine, cu as validateStepInput, dt as createWorkflow, du as validateStepStateData, eu as hydrateSerializedStepErrors, fu as validateStepSuspendData, gl as createStep, gu as getEntryId, hl as cloneStep, iu as omitPriorSuspensionFields, jl as createMappingStep, lt as cloneWorkflow, lu as validateStepRequestContext, ml as Workflow, nu as isSingleStepEntry, ou as runCountDeprecationMessage, pl as Run, pu as waitForSuspendedSnapshot, ql as createTimeTravelExecutionParams, ru as omitPriorCompletionFields, su as setLongTimeout, tu as isEntryFinished, ut as createEventedWorkflow, uu as validateStepResumeData, vl as mapVariable, yl as predicateToCondition, yu as workflowTermination, zl as RESUME_SNAPSHOT_POLL_INTERVAL_MS } from "../run-registry-Ca8idv6o.js";
import { St as getStepResultAsync, xt as getStepResult } from "../stream-sJ8FGaH9.js";
import { derivePredicateLabel, predicateSchema } from "../predicate/index.js";
import { d as computeNextFireAt, p as validateCron } from "../schedules-CGkeqNro.js";
import { n as WorkflowScheduler, t as Scheduler } from "../scheduler-DOueSa7x.js";
import { a as jsonSchemaToZod, c as analyzeMapConfig, d as toJsonSchemaOrUndefined, f as validateWorkflowRefs, h as forEachSingleStepEntryWithPath, i as validateWorkflowSchemas, l as parseMapConfig, m as forEachSingleStepEntry, n as validateDynamicWorkflow, o as validateStorableJsonSchema, p as collectNestedWorkflowIds, r as validateWorkflowStructure, s as inferGraphSchemas, t as assertValidDynamicWorkflow, u as schemaCompatibility } from "../validate-CfgsbSxQ.js";
import { n as entryOptionFields, r as toStorableGraph, t as rehydrateWorkflow } from "../rehydrate-DzumSyB6.js";
// src/workflows/state-reader.ts
const getStep = (state, stepId) => state.steps?.[stepId];
const getFirstStepResult = (step) => {
return Array.isArray(step) ? step.find((result) => result?.status === "suspended") ?? step[0] : step;
};
const getNestedSuspendPath = (step) => {
const path = getFirstStepResult(step)?.suspendPayload?.__workflow_meta?.path;
return Array.isArray(path) ? path.filter((part) => typeof part === "string") : [];
};
function getWorkflowStepOutput(state, stepId) {
const step = getStep(state, stepId);
return Array.isArray(step) ? step.map((result) => result?.output) : step?.output;
}
function getWorkflowStepPayload(state, stepId) {
const step = getStep(state, stepId);
return Array.isArray(step) ? step.map((result) => result?.payload) : step?.payload;
}
function getWorkflowResumeLabel(state, label) {
const resumeLabel = state.resumeLabels?.[label];
return resumeLabel ? { ...resumeLabel } : void 0;
}
function getWorkflowResumeLabels(state) {
return Object.entries(state.resumeLabels ?? {}).reduce((labels, [label, value]) => {
labels[label] = { ...value };
return labels;
}, {});
}
function getWorkflowSuspendedSteps(state) {
return Object.entries(state.suspendedPaths ?? {}).map(([stepId, executionPath]) => {
const step = getStep(state, stepId);
const firstStepResult = getFirstStepResult(step);
const nestedPath = getNestedSuspendPath(step);
const path = nestedPath.length > 0 ? nestedPath[0] === stepId ? nestedPath : [stepId, ...nestedPath] : [stepId];
const resumeLabels = Object.entries(state.resumeLabels ?? {}).reduce((labels, [label, value]) => {
if (value.stepId === stepId) labels[label] = { ...value };
return labels;
}, {});
return {
stepId,
path,
executionPath,
step,
payload: Array.isArray(step) ? step.map((result) => result?.payload) : step?.payload,
suspendPayload: firstStepResult?.suspendPayload,
suspendOutput: firstStepResult?.suspendOutput,
resumeLabels
};
});
}
function getWorkflowSuspendedStep(state) {
return getWorkflowSuspendedSteps(state)[0];
}
function createWorkflowStateReader(state) {
return {
getStatus: () => state.status,
getResult: () => state.result,
getError: () => state.error,
getStepOutput: (stepId) => getWorkflowStepOutput(state, stepId),
getStepPayload: (stepId) => getWorkflowStepPayload(state, stepId),
getSuspendedStep: () => getWorkflowSuspendedStep(state),
getSuspendedSteps: () => getWorkflowSuspendedSteps(state),
getResumeLabel: (label) => getWorkflowResumeLabel(state, label),
getResumeLabels: () => getWorkflowResumeLabels(state)
};
}
export { DefaultExecutionEngine, ExecutionEngine, RESUME_SNAPSHOT_POLL_INTERVAL_MS, RESUME_SNAPSHOT_WAIT_STATUSES, Run, Scheduler, Workflow, WorkflowScheduler, abortableSleep, analyzeMapConfig, applyStateDelta, assertTimeTravelGraphMatchesSnapshot, assertValidDynamicWorkflow, cleanStepResult, cloneStep, cloneWorkflow, collectNestedWorkflowIds, computeNextFireAt, computeScheduleDefinitionHash, createDeprecationProxy, createEventedWorkflow, createMappingStep, createRestartExecutionParams, createStep, createStepFromAgent, createStepFromClassifier, createStepFromTool, createTimeTravelExecutionParams, createWorkflow, createWorkflowStateReader, defineLazyWriter, defineStateAccessors, derivePredicateLabel, entryOptionFields, evaluatePredicate, forEachSingleStepEntry, forEachSingleStepEntryWithPath, getEntryId, getEntryWorkflow, getRestartStartIndex, getResumeLabelsByStepId, getSingleStepEntryId, getStepIds, getStepResult, getStepResultAsync, getWorkflowResumeLabel, getWorkflowResumeLabels, getWorkflowStepOutput, getWorkflowStepPayload, getWorkflowSuspendedStep, getWorkflowSuspendedSteps, hydrateSerializedStepErrors, inferGraphSchemas, isEntryFinished, isProcessor, isSingleStepEntry, jsonSchemaToZod, mapVariable, omitPriorCompletionFields, omitPriorSuspensionFields, parseMapConfig, predicateSchema, predicateToCondition, rehydrateWorkflow, resolveForeachConcurrency, runCountDeprecationMessage, schemaCompatibility, setLongTimeout, toJsonSchemaOrUndefined, toStorableGraph, validateCron, validateDynamicWorkflow, validateStepInput, validateStepRequestContext, validateStepResumeData, validateStepStateData, validateStepSuspendData, validateStorableJsonSchema, validateWorkflowRefs, validateWorkflowSchemas, validateWorkflowStructure, waitForSuspendedSnapshot, workflowTermination };
//# sourceMappingURL=index.js.map