Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4619,9 +4619,13 @@ async function setEmailState(email, options = {}) {
await setEmailStateSilently(email, options);
if (email) {
const latestState = await getState();
const recordStatus = shouldMarkAccountRunRecordRunning(latestState) ? 'running' : 'node:submit-signup-email:stopped';
const recordReason = recordStatus === 'running' ? '正在运行' : '节点 submit-signup-email 已使用邮箱,流程尚未完成。';
await appendManualAccountRunRecordIfNeeded(recordStatus, latestState, recordReason);
if (!shouldMarkAccountRunRecordRunning(latestState)) {
await appendManualAccountRunRecordIfNeeded(
'node:submit-signup-email:stopped',
latestState,
'节点 submit-signup-email 已使用邮箱,流程尚未完成。'
);
}
await resumeAutoRunIfWaitingForEmail();
}
}
Expand Down Expand Up @@ -4700,9 +4704,13 @@ async function setSignupPhoneState(phoneNumber) {
await setSignupPhoneStateSilently(phoneNumber);
if (String(phoneNumber || '').trim()) {
const latestState = await getState();
const recordStatus = shouldMarkAccountRunRecordRunning(latestState) ? 'running' : 'node:submit-signup-email:stopped';
const recordReason = recordStatus === 'running' ? '正在运行' : '节点 submit-signup-email 已使用手机号,流程尚未完成。';
await appendManualAccountRunRecordIfNeeded(recordStatus, latestState, recordReason);
if (!shouldMarkAccountRunRecordRunning(latestState)) {
await appendManualAccountRunRecordIfNeeded(
'node:submit-signup-email:stopped',
latestState,
'节点 submit-signup-email 已使用手机号,流程尚未完成。'
);
}
}
}

Expand Down Expand Up @@ -10985,6 +10993,27 @@ async function handleStepData(step, payload) {
}),
signupVerificationRequestedAt: null,
});
if (payload.skipProfileStep) {
const latestState = await getState();
const step5NodeId = getNodeIdByStepForState(5, latestState);
const step5Status = step5NodeId ? latestState.nodeStatuses?.[step5NodeId] : '';
if (step5NodeId && step5Status !== 'running' && step5Status !== 'completed' && step5Status !== 'manual_completed') {
await setNodeStatus(step5NodeId, 'skipped');
if (payload.skipProfileStepReason === 'combined_verification_profile') {
await addLog('步骤 4:当前验证码页已内嵌完成注册资料提交,已自动跳过步骤 5。', 'warn');
} else {
await addLog('步骤 4:检测到账号已直接进入已登录态,已自动跳过步骤 5。', 'warn');
}
}
if (payload.skipRegistrationWaitStep) {
const step6NodeId = getNodeIdByStepForState(6, latestState);
const step6Status = step6NodeId ? latestState.nodeStatuses?.[step6NodeId] : '';
if (step6NodeId && step6Status !== 'running' && step6Status !== 'completed' && step6Status !== 'manual_completed') {
await setNodeStatus(step6NodeId, 'skipped');
await addLog('步骤 4:账号已进入 ChatGPT 已登录态,已自动跳过步骤 6,流程将直接进入步骤 7。', 'warn');
}
}
}
break;
case 8:
await setState({
Expand Down Expand Up @@ -11308,9 +11337,8 @@ async function completeNodeFromBackground(nodeId, payload = {}) {
nodeId: normalizedNodeId,
});
}
await runCompletedNodeSideEffects(normalizedNodeId, payload, completionState, lastNodeId);
notifyNodeComplete(normalizedNodeId, payload);
void runCompletedNodeSideEffects(normalizedNodeId, payload, completionState, lastNodeId)
.catch((error) => reportCompletedNodeSideEffectError(normalizedNodeId, error));
return;
}

Expand Down
6 changes: 0 additions & 6 deletions background/account-run-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
if (normalized === 'success') {
return 'success';
}
if (normalized === 'running' || /_running$/.test(normalized) || /^node:[^:]+:running$/.test(normalized)) {
return 'running';
}
if (normalized === 'failed' || /_failed$/.test(normalized) || /^node:[^:]+:failed$/.test(normalized)) {
return 'failed';
}
Expand Down Expand Up @@ -210,9 +207,6 @@
if (finalStatus === 'success') {
return '流程完成';
}
if (finalStatus === 'running') {
return '正在运行';
}
if (finalStatus === 'stopped') {
if (failedNodeId) {
return `节点 ${getNodeDisplayName(failedNodeId, state)} 停止`;
Expand Down
36 changes: 14 additions & 22 deletions background/auto-run-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@

for (let targetRun = resumeCurrentRun; targetRun <= totalRuns; targetRun += 1) {
const roundSummary = roundSummaries[targetRun - 1];
let roundRecordAppended = false;
const resumingCurrentRound = continueCurrentOnFirstAttempt && targetRun === resumeCurrentRun;
let attemptRun = resumingCurrentRound ? resumeAttemptRun : 1;
let reuseExistingProgress = resumingCurrentRound;
Expand Down Expand Up @@ -756,21 +755,14 @@
forceFreshTabsNextRun = false;
}

const appendRoundRecordIfNeeded = async (status, reason = '', errorLike = null) => {
if (roundRecordAppended) {
return;
}

const appendRoundRecord = async (status, reason = '', errorLike = null, stateOverride = null) => {
if (typeof appendAccountRunRecord !== 'function') {
return;
}

const recordState = await getState();
const recordState = stateOverride || await getState();
const recordStatus = resolveAutoRunAccountRecordStatus(status, recordState, errorLike);
const record = await appendAccountRunRecord(recordStatus, recordState, reason);
if (record) {
roundRecordAppended = true;
}
return appendAccountRunRecord(recordStatus, recordState, reason);
};

try {
Expand Down Expand Up @@ -810,7 +802,7 @@
} catch (err) {
if (isStopError(err)) {
stoppedEarly = true;
await appendRoundRecordIfNeeded('stopped', getErrorMessage(err), err);
await appendRoundRecord('stopped', getErrorMessage(err), err);
await addLog(`第 ${targetRun}/${totalRuns} 轮已被用户停止`, 'warn');
await broadcastAutoRunStatus('stopped', {
currentRun: targetRun,
Expand Down Expand Up @@ -871,7 +863,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因认证流程进入 add-phone 已终止。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -906,7 +898,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因接码号池暂无可用号码已终止。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -941,7 +933,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因 Plus 免费试用资格不可用已终止。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -976,7 +968,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因 GPC 页面流程已结束。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -1011,7 +1003,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因 user_already_exists 已终止。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -1046,7 +1038,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮因步骤 4 连续 405 错误已终止。');
await broadcastStopToContentScripts();
if (!autoRunSkipFailures) {
Expand Down Expand Up @@ -1081,7 +1073,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
cancelPendingCommands('当前轮检测到 Kiro 代理异常页,已停止自动运行,等待用户切换代理。');
await broadcastStopToContentScripts();
await addLog(`第 ${targetRun}/${totalRuns} 轮检测到 Kiro 代理异常页:${reason}`, 'error');
Expand Down Expand Up @@ -1123,7 +1115,7 @@
} catch (sleepError) {
if (isStopError(sleepError)) {
stoppedEarly = true;
await appendRoundRecordIfNeeded('stopped', getErrorMessage(sleepError), sleepError);
await appendRoundRecord('stopped', getErrorMessage(sleepError), sleepError);
await addLog(`第 ${targetRun}/${totalRuns} 轮已被用户停止`, 'warn');
await broadcastAutoRunStatus('stopped', {
currentRun: targetRun,
Expand All @@ -1147,7 +1139,7 @@
} catch (sleepError) {
if (isStopError(sleepError)) {
stoppedEarly = true;
await appendRoundRecordIfNeeded('stopped', getErrorMessage(sleepError), sleepError);
await appendRoundRecord('stopped', getErrorMessage(sleepError), sleepError);
await addLog(`第 ${targetRun}/${totalRuns} 轮已被用户停止`, 'warn');
await broadcastAutoRunStatus('stopped', {
currentRun: targetRun,
Expand All @@ -1169,7 +1161,7 @@
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
await appendRoundRecordIfNeeded('failed', reason, err);
await appendRoundRecord('failed', reason, err);
if (!autoRunSkipFailures) {
cancelPendingCommands('当前轮执行失败。');
await broadcastStopToContentScripts();
Expand Down
9 changes: 8 additions & 1 deletion background/message-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,13 @@
await addLog('步骤 4:检测到账号已直接进入已登录态,已自动跳过步骤 5。', 'warn');
}
}
if (payload.skipRegistrationWaitStep) {
const step6Status = getNodeStatusByStep(6, latestState);
if (step6Status !== 'running' && step6Status !== 'completed' && step6Status !== 'manual_completed') {
await setNodeStatusByStep(6, 'skipped', latestState);
await addLog('步骤 4:账号已进入 ChatGPT 已登录态,已自动跳过步骤 6,流程将直接进入步骤 7。', 'warn');
}
}
}
break;
case 7:
Expand Down Expand Up @@ -1141,10 +1148,10 @@
stepKey: nodeId,
});
}
await handleStepData(resolvedStep, completionPayload);
if (isFinalNode && typeof appendAccountRunRecord === 'function') {
await appendAccountRunRecord('success', completionState);
}
await handleStepData(resolvedStep, completionPayload);
notifyNodeComplete(nodeId, completionPayload);
return { ok: true };
}
Expand Down
11 changes: 10 additions & 1 deletion background/verification-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@
: '';
}

const isRetryableVerificationTransportError = typeof deps.isRetryableContentScriptTransportError === 'function'
const baseRetryableVerificationTransportError = typeof deps.isRetryableContentScriptTransportError === 'function'
? deps.isRetryableContentScriptTransportError
: ((error) => /back\/forward cache|message channel is closed|Receiving end does not exist|port closed before a response was received|A listener indicated an asynchronous response|内容脚本\s+\d+(?:\.\d+)?\s*秒内未响应|did not respond in \d+s/i.test(
String(typeof error === 'string' ? error : error?.message || '')
));

function isRetryableVerificationTransportError(error) {
const message = String(typeof error === 'string' ? error : error?.message || '');
return Boolean(baseRetryableVerificationTransportError(error))
|| /页面刚完成跳转或刷新,内容脚本还没有重新接回/i.test(message);
}

function getVerificationCodeStateKey(step) {
return step === 4 ? 'lastSignupCode' : 'lastLoginCode';
}
Expand Down Expand Up @@ -199,6 +205,7 @@
success: true,
reason: 'chatgpt_home',
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: currentUrl,
};
}
Expand Down Expand Up @@ -1176,6 +1183,7 @@
assumed: true,
transportRecovered: true,
skipProfileStep: Boolean(fallback.skipProfileStep),
skipRegistrationWaitStep: Boolean(fallback.skipRegistrationWaitStep),
url: fallback.url,
};
}
Expand Down Expand Up @@ -1439,6 +1447,7 @@
code: result.code,
phoneVerificationRequired: Boolean(submitResult.addPhonePage),
...(step === 4 && submitResult?.skipProfileStep ? { skipProfileStep: true } : {}),
...(step === 4 && submitResult?.skipRegistrationWaitStep ? { skipRegistrationWaitStep: true } : {}),
...(step === 4 && submitResult?.skipProfileStepReason
? { skipProfileStepReason: submitResult.skipProfileStepReason }
: {}),
Expand Down
11 changes: 10 additions & 1 deletion flows/openai/content/openai-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ function inspectSignupEntryState() {
return {
state: 'logged_in_home',
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: postVerificationState.url || location.href,
};
}
Expand Down Expand Up @@ -2707,6 +2708,7 @@ async function step3_fillEmailPassword(payload) {
skippedPasswordPage: true,
deferredSubmit: false,
...(snapshot.skipProfileStep ? { skipProfileStep: true } : {}),
...(snapshot.skipRegistrationWaitStep ? { skipRegistrationWaitStep: true } : {}),
};
log('步骤 3:当前页面已进入验证码或后续阶段,密码页按已跳过处理。', 'warn');
reportComplete(3, completionPayload);
Expand Down Expand Up @@ -3065,6 +3067,7 @@ function getStep4PostVerificationState(options = {}) {
return {
state: 'logged_in_home',
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: location.href,
};
}
Expand Down Expand Up @@ -5040,6 +5043,7 @@ function inspectSignupVerificationState() {
return {
state: 'logged_in_home',
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: postVerificationState.url || location.href,
};
}
Expand Down Expand Up @@ -5200,11 +5204,12 @@ async function prepareSignupVerificationFlow(payload = {}, timeout = 30000) {
}

if (snapshot.state === 'logged_in_home') {
log(`${prepareLogLabel}:页面已直接进入 ChatGPT 已登录态,本步骤按已完成处理,并将跳过步骤 5。`, 'ok');
log(`${prepareLogLabel}:页面已直接进入 ChatGPT 已登录态,本步骤按已完成处理,并将跳过步骤 5/6。`, 'ok');
return {
ready: true,
alreadyVerified: true,
skipProfileStep: true,
skipRegistrationWaitStep: true,
retried: recoveryRound,
prepareSource,
};
Expand All @@ -5219,6 +5224,7 @@ async function prepareSignupVerificationFlow(payload = {}, timeout = 30000) {
skipLoginVerificationStep: true,
directOAuthConsentPage: true,
skipProfileStep: true,
skipRegistrationWaitStep: true,
retried: recoveryRound,
prepareSource,
};
Expand Down Expand Up @@ -5341,6 +5347,7 @@ async function waitForVerificationSubmitOutcome(step, timeout, options = {}) {
return {
success: true,
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: postVerificationState.url || location.href,
};
}
Expand Down Expand Up @@ -5384,6 +5391,7 @@ async function waitForVerificationSubmitOutcome(step, timeout, options = {}) {
return {
success: true,
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: postVerificationState.url || location.href,
};
}
Expand Down Expand Up @@ -5521,6 +5529,7 @@ async function fillVerificationCode(step, payload) {
assumed: true,
alreadyAdvanced: true,
skipProfileStep: true,
skipRegistrationWaitStep: true,
url: postVerificationState.url || location.href,
};
}
Expand Down
Loading