Refactor auto-run flow state preservation

This commit is contained in:
QLHazyCoder
2026-05-18 03:27:30 +08:00
parent e5dc675369
commit feba51da65
21 changed files with 835 additions and 111 deletions
+72 -27
View File
@@ -11,6 +11,7 @@
AUTO_RUN_TIMER_KIND_BETWEEN_ROUNDS,
broadcastAutoRunStatus,
broadcastStopToContentScripts,
buildFreshAutoRunKeepState,
cancelPendingCommands,
clearStopRequest,
createAutoRunSessionId,
@@ -77,6 +78,67 @@
throw new Error('自动运行节点执行器未接入。');
}
function buildFreshStartStateSnapshot(state = {}) {
return {
...(state || {}),
currentNodeId: '',
nodeStatuses: {},
stepStatuses: {},
};
}
function resolveFreshStartNodeId(state = {}) {
const freshState = buildFreshStartStateSnapshot(state);
return String(getFirstUnfinishedWorkflowNode(freshState) || '').trim();
}
function buildFreshAttemptKeepState(state = {}, context = {}) {
if (typeof buildFreshAutoRunKeepState === 'function') {
const helperPatch = buildFreshAutoRunKeepState(state, context);
if (helperPatch && typeof helperPatch === 'object' && !Array.isArray(helperPatch)) {
return {
...helperPatch,
};
}
}
return {
activeFlowId: state.activeFlowId,
flowId: state.flowId || state.activeFlowId,
panelMode: state.panelMode,
kiroSourceId: state.kiroSourceId,
vpsUrl: state.vpsUrl,
vpsPassword: state.vpsPassword,
customPassword: state.customPassword,
plusModeEnabled: state.plusModeEnabled,
plusPaymentMethod: state.plusPaymentMethod,
phoneVerificationEnabled: state.phoneVerificationEnabled,
phoneSignupReloginAfterBindEmailEnabled: state.phoneSignupReloginAfterBindEmailEnabled,
paypalEmail: state.paypalEmail,
paypalPassword: state.paypalPassword,
kiroRsUrl: state.kiroRsUrl,
kiroRsKey: state.kiroRsKey,
autoRunSkipFailures: state.autoRunSkipFailures,
autoRunFallbackThreadIntervalMinutes: state.autoRunFallbackThreadIntervalMinutes,
autoRunDelayEnabled: state.autoRunDelayEnabled,
autoRunDelayMinutes: state.autoRunDelayMinutes,
autoStepDelaySeconds: state.autoStepDelaySeconds,
stepExecutionRangeByFlow: state.stepExecutionRangeByFlow,
signupMethod: state.signupMethod,
mailProvider: state.mailProvider,
emailGenerator: state.emailGenerator,
gmailBaseEmail: state.gmailBaseEmail,
mail2925BaseEmail: state.mail2925BaseEmail,
currentMail2925AccountId: state.currentMail2925AccountId,
emailPrefix: state.emailPrefix,
inbucketHost: state.inbucketHost,
inbucketMailbox: state.inbucketMailbox,
cloudflareDomain: state.cloudflareDomain,
cloudflareDomains: state.cloudflareDomains,
reusablePhoneActivation: state.reusablePhoneActivation,
};
}
function createAutoRunRoundSummary(round) {
return {
round,
@@ -502,12 +564,13 @@
autoRunAttemptRun: attemptRun,
});
roundSummary.attempts = attemptRun;
const defaultStartNodeId = typeof runAutoSequenceFromNode === 'function' ? 'open-chatgpt' : 1;
const attemptState = await getState();
const defaultStartNodeId = resolveFreshStartNodeId(attemptState);
let startNodeId = defaultStartNodeId;
let useExistingProgress = false;
if (reuseExistingProgress) {
let currentState = await getState();
let currentState = attemptState;
if (getRunningWorkflowNodes(currentState).length) {
currentState = await waitForRunningWorkflowNodesToFinish({
currentRun: targetRun,
@@ -525,32 +588,14 @@
}
if (!useExistingProgress) {
const prevState = await getState();
const prevState = attemptState;
const keepSettings = {
vpsUrl: prevState.vpsUrl,
vpsPassword: prevState.vpsPassword,
customPassword: prevState.customPassword,
plusModeEnabled: prevState.plusModeEnabled,
paypalEmail: prevState.paypalEmail,
paypalPassword: prevState.paypalPassword,
autoRunSkipFailures: prevState.autoRunSkipFailures,
autoRunFallbackThreadIntervalMinutes: prevState.autoRunFallbackThreadIntervalMinutes,
autoRunDelayEnabled: prevState.autoRunDelayEnabled,
autoRunDelayMinutes: prevState.autoRunDelayMinutes,
autoStepDelaySeconds: prevState.autoStepDelaySeconds,
stepExecutionRangeByFlow: prevState.stepExecutionRangeByFlow,
signupMethod: prevState.signupMethod,
mailProvider: prevState.mailProvider,
emailGenerator: prevState.emailGenerator,
gmailBaseEmail: prevState.gmailBaseEmail,
mail2925BaseEmail: prevState.mail2925BaseEmail,
currentMail2925AccountId: prevState.currentMail2925AccountId,
emailPrefix: prevState.emailPrefix,
inbucketHost: prevState.inbucketHost,
inbucketMailbox: prevState.inbucketMailbox,
cloudflareDomain: prevState.cloudflareDomain,
cloudflareDomains: prevState.cloudflareDomains,
reusablePhoneActivation: prevState.reusablePhoneActivation,
...buildFreshAttemptKeepState(prevState, {
targetRun,
totalRuns,
attemptRun,
sessionId,
}),
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
autoRunSessionId: sessionId,
tabRegistry: {},