feat: add flow-aware kiro device auth workflow

This commit is contained in:
QLHazyCoder
2026-05-18 00:34:51 +08:00
parent b3da7c9e7f
commit 0c034c232d
26 changed files with 4085 additions and 383 deletions
+107 -35
View File
@@ -1,11 +1,21 @@
(function attachMultiPageFlowCapabilities(root, factory) {
root.MultiPageFlowCapabilities = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createFlowCapabilitiesModule() {
const DEFAULT_FLOW_ID = 'openai';
const DEFAULT_PANEL_MODE = 'cpa';
const rootScope = typeof self !== 'undefined' ? self : globalThis;
const flowRegistryApi = rootScope.MultiPageFlowRegistry || {};
const settingsSchemaApi = rootScope.MultiPageSettingsSchema || {};
const DEFAULT_FLOW_ID = flowRegistryApi.DEFAULT_FLOW_ID || 'openai';
const DEFAULT_PANEL_MODE = flowRegistryApi.DEFAULT_OPENAI_SOURCE_ID || 'cpa';
const LEGACY_OPENAI_FLOW_ALIAS = String(flowRegistryApi.LEGACY_OPENAI_FLOW_ALIAS || 'codex').trim().toLowerCase();
const SIGNUP_METHOD_EMAIL = 'email';
const SIGNUP_METHOD_PHONE = 'phone';
const VALID_PANEL_MODES = Object.freeze(['cpa', 'sub2api', 'codex2api']);
const VALID_PANEL_MODES = Array.isArray(flowRegistryApi.OPENAI_SOURCE_IDS)
? flowRegistryApi.OPENAI_SOURCE_IDS.slice()
: ['cpa', 'sub2api', 'codex2api'];
const REGISTERED_FLOW_IDS = Array.isArray(flowRegistryApi.getRegisteredFlowIds?.())
? flowRegistryApi.getRegisteredFlowIds().map((flowId) => String(flowId || '').trim().toLowerCase()).filter(Boolean)
: [DEFAULT_FLOW_ID];
const REGISTERED_FLOW_ID_SET = new Set(REGISTERED_FLOW_IDS);
const DEFAULT_FLOW_CAPABILITIES = Object.freeze({
supportsEmailSignup: true,
@@ -16,28 +26,33 @@
supportsPlatformBinding: [],
supportsLuckmail: false,
supportsOauthTimeoutBudget: false,
canSwitchFlow: false,
canSwitchFlow: true,
stepDefinitionMode: 'default',
sourceSelectorLabel: '来源',
});
const FLOW_CAPABILITIES = Object.freeze({
openai: Object.freeze({
...DEFAULT_FLOW_CAPABILITIES,
supportsPhoneSignup: true,
supportsPhoneVerificationSettings: true,
supportsPlusMode: true,
supportsContributionMode: true,
supportsPlatformBinding: ['cpa', 'sub2api', 'codex2api'],
supportsLuckmail: true,
supportsOauthTimeoutBudget: true,
stepDefinitionMode: 'openai-dynamic',
}),
});
const FLOW_CAPABILITIES = Object.freeze(
Object.fromEntries(
(typeof flowRegistryApi.getRegisteredFlowIds === 'function'
? flowRegistryApi.getRegisteredFlowIds()
: [DEFAULT_FLOW_ID]
).map((flowId) => [
flowId,
Object.freeze({
...DEFAULT_FLOW_CAPABILITIES,
...(typeof flowRegistryApi.getFlowCapabilities === 'function'
? flowRegistryApi.getFlowCapabilities(flowId)
: {}),
}),
])
)
);
const DEFAULT_PANEL_CAPABILITIES = Object.freeze({
supportsPhoneSignup: true,
requiresPhoneSignupWarning: false,
});
const MODE_SWITCH_RELEVANT_KEYS = Object.freeze([
'activeFlowId',
'contributionMode',
@@ -45,6 +60,7 @@
'phoneVerificationEnabled',
'plusModeEnabled',
'signupMethod',
'kiroSourceId',
]);
const PANEL_CAPABILITIES = Object.freeze({
@@ -63,12 +79,30 @@
});
function normalizeFlowId(value = '', fallback = DEFAULT_FLOW_ID) {
if (typeof flowRegistryApi.normalizeFlowId === 'function') {
return flowRegistryApi.normalizeFlowId(value, fallback);
}
const normalized = String(value || '').trim().toLowerCase();
return normalized || String(fallback || '').trim().toLowerCase() || DEFAULT_FLOW_ID;
}
function normalizeCapabilityFlowId(value = '', fallback = DEFAULT_FLOW_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (normalized === LEGACY_OPENAI_FLOW_ALIAS) {
return DEFAULT_FLOW_ID;
}
if (normalized) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return fallbackValue || DEFAULT_FLOW_ID;
const normalizedFallback = String(fallback || '').trim().toLowerCase();
if (normalizedFallback === LEGACY_OPENAI_FLOW_ALIAS) {
return DEFAULT_FLOW_ID;
}
return normalizedFallback || DEFAULT_FLOW_ID;
}
function isRegisteredFlowId(flowId = '') {
return REGISTERED_FLOW_ID_SET.has(normalizeCapabilityFlowId(flowId, ''));
}
function normalizePanelMode(value = '', fallback = DEFAULT_PANEL_MODE) {
@@ -122,9 +156,14 @@
flowCapabilities = FLOW_CAPABILITIES,
panelCapabilities = PANEL_CAPABILITIES,
} = deps;
const settingsSchema = settingsSchemaApi.createSettingsSchema
? settingsSchemaApi.createSettingsSchema({
defaultFlowId,
})
: null;
function getFlowCapabilities(flowId) {
const normalizedFlowId = normalizeFlowId(flowId, defaultFlowId);
const normalizedFlowId = normalizeCapabilityFlowId(flowId, defaultFlowId);
const entry = flowCapabilities[normalizedFlowId] || null;
return {
...defaultFlowCapabilities,
@@ -156,9 +195,33 @@
return normalized;
}
function resolveEffectiveSourceId(activeFlowId, state = {}, requestedPanelMode = DEFAULT_PANEL_MODE) {
if (!isRegisteredFlowId(activeFlowId)) {
return normalizePanelMode(state?.panelMode || requestedPanelMode, requestedPanelMode || DEFAULT_PANEL_MODE);
}
if (settingsSchema?.getSelectedSourceId) {
const sourceFromSchema = settingsSchema.getSelectedSourceId({
...state,
activeFlowId,
}, activeFlowId);
if (sourceFromSchema) {
return sourceFromSchema;
}
}
if (typeof flowRegistryApi.normalizeSourceId === 'function') {
if (activeFlowId === 'openai') {
return flowRegistryApi.normalizeSourceId('openai', state?.panelMode || requestedPanelMode, DEFAULT_PANEL_MODE);
}
return flowRegistryApi.normalizeSourceId(activeFlowId, state?.kiroSourceId || '', flowRegistryApi.getDefaultSourceId?.(activeFlowId));
}
return activeFlowId === 'openai'
? normalizePanelMode(state?.panelMode || requestedPanelMode)
: '';
}
function resolveSidepanelCapabilities(options = {}) {
const state = options?.state || {};
const activeFlowId = normalizeFlowId(
const activeFlowId = normalizeCapabilityFlowId(
options?.activeFlowId ?? state?.activeFlowId,
defaultFlowId
);
@@ -173,20 +236,22 @@
: supportedPanelModes.includes(requestedPanelMode);
const effectivePanelMode = panelModeSupported
? requestedPanelMode
: supportedPanelModes[0];
: (supportedPanelModes[0] || requestedPanelMode);
const panelState = getPanelCapabilities(effectivePanelMode);
const effectiveSourceId = resolveEffectiveSourceId(activeFlowId, state, effectivePanelMode);
const runtimeLocks = {
autoRunLocked: Boolean(options?.autoRunLocked ?? state?.autoRunLocked),
contributionMode: flowState.supportsContributionMode && Boolean(state?.contributionMode),
phoneVerificationEnabled: flowState.supportsPhoneVerificationSettings && Boolean(state?.phoneVerificationEnabled),
plusModeEnabled: flowState.supportsPlusMode && Boolean(state?.plusModeEnabled),
contributionMode: activeFlowId === 'openai' && flowState.supportsContributionMode && Boolean(state?.contributionMode),
phoneVerificationEnabled: activeFlowId === 'openai' && flowState.supportsPhoneVerificationSettings && Boolean(state?.phoneVerificationEnabled),
plusModeEnabled: activeFlowId === 'openai' && flowState.supportsPlusMode && Boolean(state?.plusModeEnabled),
settingsMenuLocked: Boolean(options?.settingsMenuLocked ?? state?.settingsMenuLocked),
};
const effectiveSignupMethods = [];
if (flowState.supportsEmailSignup !== false) {
effectiveSignupMethods.push(SIGNUP_METHOD_EMAIL);
}
const canSelectPhoneSignup = Boolean(flowState.supportsPhoneSignup)
const canSelectPhoneSignup = activeFlowId === 'openai'
&& Boolean(flowState.supportsPhoneSignup)
&& Boolean(panelState.supportsPhoneSignup)
&& runtimeLocks.phoneVerificationEnabled
&& !runtimeLocks.plusModeEnabled
@@ -205,19 +270,24 @@
: (effectiveSignupMethods.includes(SIGNUP_METHOD_EMAIL)
? SIGNUP_METHOD_EMAIL
: effectiveSignupMethods[0]);
const visibleGroupIds = typeof flowRegistryApi.getVisibleGroupIds === 'function'
&& isRegisteredFlowId(activeFlowId)
? flowRegistryApi.getVisibleGroupIds(activeFlowId, effectiveSourceId)
: [];
return {
activeFlowId,
canShowContributionMode: Boolean(flowState.supportsContributionMode),
canShowLuckmail: Boolean(flowState.supportsLuckmail),
canShowPhoneSettings: Boolean(flowState.supportsPhoneVerificationSettings),
canShowPlusSettings: Boolean(flowState.supportsPlusMode),
canShowContributionMode: activeFlowId === 'openai' && Boolean(flowState.supportsContributionMode),
canShowLuckmail: activeFlowId === 'openai' && Boolean(flowState.supportsLuckmail),
canShowPhoneSettings: activeFlowId === 'openai' && Boolean(flowState.supportsPhoneVerificationSettings),
canShowPlusSettings: activeFlowId === 'openai' && Boolean(flowState.supportsPlusMode),
canSwitchFlow: Boolean(flowState.canSwitchFlow),
canUsePhoneSignup: canSelectPhoneSignup,
canUseSelectedPanelMode: panelModeSupported,
effectivePanelMode,
effectiveSignupMethod,
effectiveSignupMethods,
effectiveSourceId,
flowCapabilities: flowState,
panelCapabilities: panelState,
panelMode: effectivePanelMode,
@@ -233,6 +303,7 @@
signupMethod: effectiveSignupMethod,
},
supportedPanelModes,
visibleGroupIds,
};
}
@@ -250,13 +321,13 @@
if (!panelState.supportsPhoneSignup) {
return {
code: 'phone_signup_panel_unsupported',
message: `当前面板模式 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 不支持手机号注册。`,
message: `当前来源 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 不支持手机号注册。`,
};
}
if (!runtimeLocks.phoneVerificationEnabled) {
return {
code: 'phone_signup_phone_verification_disabled',
message: '请先开启接码功能后再使用手机号注册。',
message: '请先开启接码设置后再使用手机号注册。',
};
}
if (runtimeLocks.plusModeEnabled) {
@@ -289,7 +360,7 @@
) {
errors.push({
code: 'panel_mode_unsupported',
message: `当前 flow 不支持 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 面板模式`,
message: `当前 flow 不支持 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 来源`,
});
}
@@ -345,7 +416,7 @@
normalizedUpdates.panelMode = capabilityState.effectivePanelMode;
errors.push({
code: 'panel_mode_unsupported',
message: `当前 flow 不支持 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 面板模式`,
message: `当前 flow 不支持 ${getPanelModeLabel(capabilityState.requestedPanelMode)} 来源`,
});
}
@@ -373,7 +444,7 @@
normalizedUpdates.phoneVerificationEnabled = false;
errors.push({
code: 'phone_verification_unsupported',
message: '当前 flow 不支持接码置。',
message: '当前 flow 不支持接码置。',
});
}
@@ -430,6 +501,7 @@
PANEL_CAPABILITIES,
SIGNUP_METHOD_EMAIL,
SIGNUP_METHOD_PHONE,
VALID_PANEL_MODES,
normalizeFlowId,
normalizePanelMode,
normalizeSignupMethod,
+509
View File
@@ -0,0 +1,509 @@
(function attachMultiPageFlowRegistry(root, factory) {
root.MultiPageFlowRegistry = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createFlowRegistryModule() {
const DEFAULT_FLOW_ID = 'openai';
const LEGACY_OPENAI_FLOW_ALIAS = 'codex';
const DEFAULT_OPENAI_SOURCE_ID = 'cpa';
const DEFAULT_KIRO_SOURCE_ID = 'kiro-rs';
const DEFAULT_KIRO_REGION = 'us-east-1';
const DEFAULT_KIRO_RS_URL = 'https://kiro.leftcode.xyz/admin';
const OPENAI_SOURCE_IDS = Object.freeze(['cpa', 'sub2api', 'codex2api']);
const SHARED_SERVICE_IDS = Object.freeze(['email', 'proxy']);
const DEFAULT_FLOW_CAPABILITIES = Object.freeze({
supportsEmailSignup: true,
supportsPhoneSignup: false,
supportsPhoneVerificationSettings: false,
supportsPlusMode: false,
supportsContributionMode: false,
supportsPlatformBinding: [],
supportsLuckmail: false,
supportsOauthTimeoutBudget: false,
canSwitchFlow: true,
stepDefinitionMode: 'default',
sourceSelectorLabel: '来源',
});
function freezeDeep(value) {
if (!value || typeof value !== 'object' || Object.isFrozen(value)) {
return value;
}
Object.getOwnPropertyNames(value).forEach((key) => {
freezeDeep(value[key]);
});
return Object.freeze(value);
}
const FLOW_DEFINITIONS = freezeDeep({
openai: {
id: 'openai',
label: 'Codex / OpenAI',
services: ['email', 'proxy'],
capabilities: {
...DEFAULT_FLOW_CAPABILITIES,
supportsPhoneSignup: true,
supportsPhoneVerificationSettings: true,
supportsPlusMode: true,
supportsContributionMode: true,
supportsPlatformBinding: [...OPENAI_SOURCE_IDS],
supportsLuckmail: true,
supportsOauthTimeoutBudget: true,
stepDefinitionMode: 'openai-dynamic',
},
baseGroups: [
'openai-account',
'openai-plus',
'openai-phone',
'openai-oauth',
],
sources: {
cpa: {
id: 'cpa',
label: 'CPA 面板',
legacyPanelMode: 'cpa',
groups: ['openai-source-cpa'],
},
sub2api: {
id: 'sub2api',
label: 'SUB2API',
legacyPanelMode: 'sub2api',
groups: ['openai-source-sub2api'],
},
codex2api: {
id: 'codex2api',
label: 'Codex2API',
legacyPanelMode: 'codex2api',
groups: ['openai-source-codex2api'],
},
},
runtimeSources: {
'openai-auth': {
flowId: 'openai',
kind: 'flow-page',
label: '认证页',
readyPolicy: 'allow-child-frame',
family: 'openai-auth-family',
driverId: 'content/signup-page',
cleanupScopes: ['oauth-localhost-callback'],
},
chatgpt: {
flowId: 'openai',
kind: 'flow-entry',
label: 'ChatGPT 首页',
readyPolicy: 'allow-child-frame',
family: 'chatgpt-entry-family',
driverId: null,
cleanupScopes: [],
},
'vps-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'CPA 面板',
readyPolicy: 'allow-child-frame',
family: 'vps-panel-family',
driverId: 'content/vps-panel',
cleanupScopes: [],
},
'platform-panel': {
flowId: 'openai',
kind: 'virtual-page',
label: '平台回调面板',
readyPolicy: 'disabled',
family: 'platform-panel-family',
driverId: 'content/platform-panel',
cleanupScopes: [],
},
'sub2api-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'SUB2API 后台',
readyPolicy: 'allow-child-frame',
family: 'sub2api-panel-family',
driverId: 'content/sub2api-panel',
cleanupScopes: [],
},
'codex2api-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'Codex2API 后台',
readyPolicy: 'allow-child-frame',
family: 'codex2api-panel-family',
driverId: 'content/sub2api-panel',
cleanupScopes: [],
},
'plus-checkout': {
flowId: 'openai',
kind: 'flow-page',
label: 'Plus Checkout',
readyPolicy: 'top-frame-only',
family: 'plus-checkout-family',
driverId: 'content/plus-checkout',
cleanupScopes: [],
},
'paypal-flow': {
flowId: 'openai',
kind: 'flow-page',
label: 'PayPal 授权页',
readyPolicy: 'allow-child-frame',
family: 'paypal-flow-family',
driverId: 'content/paypal-flow',
cleanupScopes: [],
},
'gopay-flow': {
flowId: 'openai',
kind: 'flow-page',
label: 'GoPay 授权页',
readyPolicy: 'allow-child-frame',
family: 'gopay-flow-family',
driverId: 'content/gopay-flow',
cleanupScopes: [],
},
},
driverDefinitions: {
'content/signup-page': {
sourceId: 'openai-auth',
commands: [
'submit-signup-email',
'fill-password',
'fill-profile',
'oauth-login',
'submit-verification-code',
'post-login-phone-verification',
'bind-email',
'fetch-bind-email-code',
'confirm-oauth',
'detect-auth-state',
],
},
'content/sub2api-panel': {
sourceId: 'sub2api-panel',
commands: ['open-panel', 'fetch-oauth-url', 'platform-verify'],
},
'content/vps-panel': {
sourceId: 'vps-panel',
commands: ['open-panel', 'fetch-oauth-url', 'platform-verify'],
},
'content/platform-panel': {
sourceId: 'platform-panel',
commands: ['platform-verify', 'fetch-oauth-url'],
},
'content/plus-checkout': {
sourceId: 'plus-checkout',
commands: ['plus-checkout-create', 'plus-checkout-billing', 'plus-checkout-return'],
},
'content/paypal-flow': {
sourceId: 'paypal-flow',
commands: ['paypal-approve'],
},
'content/gopay-flow': {
sourceId: 'gopay-flow',
commands: ['gopay-subscription-confirm'],
},
},
},
kiro: {
id: 'kiro',
label: 'Kiro',
services: ['email', 'proxy'],
capabilities: {
...DEFAULT_FLOW_CAPABILITIES,
stepDefinitionMode: 'kiro-device-auth',
},
baseGroups: [
'kiro-runtime-status',
],
sources: {
'kiro-rs': {
id: 'kiro-rs',
label: 'kiro.rs',
groups: ['kiro-source-kiro-rs'],
},
},
runtimeSources: {
'kiro-device-auth': {
flowId: 'kiro',
kind: 'flow-page',
label: 'Kiro 授权页',
readyPolicy: 'top-frame-only',
family: 'kiro-device-auth-family',
driverId: null,
cleanupScopes: [],
},
'kiro-rs-admin': {
flowId: 'kiro',
kind: 'virtual-page',
label: 'kiro.rs Admin',
readyPolicy: 'disabled',
family: 'kiro-rs-admin-family',
driverId: null,
cleanupScopes: [],
},
},
driverDefinitions: {
'background/kiro-device-auth': {
sourceId: 'kiro-device-auth',
commands: [
'kiro-start-device-login',
'kiro-await-device-login',
'kiro-upload-credential',
],
},
},
},
});
const SETTINGS_GROUP_DEFINITIONS = freezeDeep({
'service-email': {
id: 'service-email',
label: '邮箱服务',
},
'service-proxy': {
id: 'service-proxy',
label: 'IP 代理',
sectionIds: ['ip-proxy-section'],
},
'openai-source-cpa': {
id: 'openai-source-cpa',
label: 'CPA 来源',
rowIds: ['row-vps-url', 'row-vps-password', 'row-local-cpa-step9-mode'],
},
'openai-source-sub2api': {
id: 'openai-source-sub2api',
label: 'SUB2API 来源',
rowIds: [
'row-sub2api-url',
'row-sub2api-email',
'row-sub2api-password',
'row-sub2api-group',
'row-sub2api-account-priority',
'row-sub2api-default-proxy',
],
},
'openai-source-codex2api': {
id: 'openai-source-codex2api',
label: 'Codex2API 来源',
rowIds: ['row-codex2api-url', 'row-codex2api-admin-key'],
},
'openai-account': {
id: 'openai-account',
label: '账户',
rowIds: ['row-custom-password'],
},
'openai-plus': {
id: 'openai-plus',
label: 'Plus',
rowIds: [
'row-plus-mode',
'row-plus-payment-method',
'row-paypal-account',
'row-gpc-helper-api',
'row-gpc-helper-card-key',
'row-gpc-helper-phone-mode',
'row-gpc-helper-country-code',
'row-gpc-helper-phone',
'row-gpc-helper-otp-channel',
'row-gpc-helper-local-sms-enabled',
'row-gpc-helper-local-sms-url',
'row-gpc-helper-pin',
'row-gopay-country-code',
'row-gopay-phone',
'row-gopay-otp',
'row-gopay-pin',
],
},
'openai-phone': {
id: 'openai-phone',
label: '接码设置',
sectionIds: ['phone-verification-section'],
rowIds: ['row-signup-phone'],
},
'openai-oauth': {
id: 'openai-oauth',
label: 'OAuth',
rowIds: ['row-oauth-flow-timeout', 'row-oauth-display'],
},
'kiro-source-kiro-rs': {
id: 'kiro-source-kiro-rs',
label: 'kiro.rs 配置',
rowIds: ['row-kiro-rs-url', 'row-kiro-rs-key', 'row-kiro-region'],
},
'kiro-runtime-status': {
id: 'kiro-runtime-status',
label: 'Kiro 运行态',
rowIds: ['row-kiro-device-code', 'row-kiro-login-url', 'row-kiro-upload-status'],
},
});
function normalizeFlowId(value = '', fallback = DEFAULT_FLOW_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (normalized === LEGACY_OPENAI_FLOW_ALIAS) {
return DEFAULT_FLOW_ID;
}
if (normalized && Object.prototype.hasOwnProperty.call(FLOW_DEFINITIONS, normalized)) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
if (fallbackValue === LEGACY_OPENAI_FLOW_ALIAS) {
return DEFAULT_FLOW_ID;
}
return Object.prototype.hasOwnProperty.call(FLOW_DEFINITIONS, fallbackValue)
? fallbackValue
: DEFAULT_FLOW_ID;
}
function getRegisteredFlowIds() {
return Object.keys(FLOW_DEFINITIONS);
}
function getFlowDefinition(flowId) {
const normalizedFlowId = normalizeFlowId(flowId);
return FLOW_DEFINITIONS[normalizedFlowId] || FLOW_DEFINITIONS[DEFAULT_FLOW_ID];
}
function getFlowLabel(flowId) {
return getFlowDefinition(flowId)?.label || normalizeFlowId(flowId);
}
function getDefaultSourceId(flowId) {
return normalizeFlowId(flowId) === 'kiro'
? DEFAULT_KIRO_SOURCE_ID
: DEFAULT_OPENAI_SOURCE_ID;
}
function normalizeOpenAiSourceId(value = '', fallback = DEFAULT_OPENAI_SOURCE_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (OPENAI_SOURCE_IDS.includes(normalized)) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return OPENAI_SOURCE_IDS.includes(fallbackValue) ? fallbackValue : DEFAULT_OPENAI_SOURCE_ID;
}
function normalizeKiroSourceId(value = '', fallback = DEFAULT_KIRO_SOURCE_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (normalized === DEFAULT_KIRO_SOURCE_ID) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return fallbackValue === DEFAULT_KIRO_SOURCE_ID ? fallbackValue : DEFAULT_KIRO_SOURCE_ID;
}
function normalizeSourceId(flowId, sourceId = '', fallback = undefined) {
const normalizedFlowId = normalizeFlowId(flowId);
if (normalizedFlowId === 'kiro') {
return normalizeKiroSourceId(sourceId, fallback || DEFAULT_KIRO_SOURCE_ID);
}
return normalizeOpenAiSourceId(sourceId, fallback || DEFAULT_OPENAI_SOURCE_ID);
}
function getSourceDefinitions(flowId) {
return getFlowDefinition(flowId)?.sources || {};
}
function getSourceDefinition(flowId, sourceId) {
const normalizedFlowId = normalizeFlowId(flowId);
const normalizedSourceId = normalizeSourceId(normalizedFlowId, sourceId, getDefaultSourceId(normalizedFlowId));
return getSourceDefinitions(normalizedFlowId)[normalizedSourceId] || null;
}
function getSourceOptions(flowId) {
return Object.values(getSourceDefinitions(flowId));
}
function getSourceLabel(flowId, sourceId) {
return getSourceDefinition(flowId, sourceId)?.label || normalizeSourceId(flowId, sourceId);
}
function mapPanelModeToSourceId(panelMode = '', fallback = DEFAULT_OPENAI_SOURCE_ID) {
return normalizeOpenAiSourceId(panelMode, fallback);
}
function mapSourceIdToPanelMode(flowId, sourceId = '', fallback = DEFAULT_OPENAI_SOURCE_ID) {
if (normalizeFlowId(flowId) !== DEFAULT_FLOW_ID) {
return normalizeOpenAiSourceId(fallback, DEFAULT_OPENAI_SOURCE_ID);
}
return normalizeOpenAiSourceId(sourceId, fallback || DEFAULT_OPENAI_SOURCE_ID);
}
function getFlowCapabilities(flowId) {
return {
...DEFAULT_FLOW_CAPABILITIES,
...(getFlowDefinition(flowId)?.capabilities || {}),
};
}
function getVisibleGroupIds(flowId, sourceId, options = {}) {
const normalizedFlowId = normalizeFlowId(flowId);
const flowDefinition = getFlowDefinition(normalizedFlowId);
const normalizedSourceId = normalizeSourceId(normalizedFlowId, sourceId, getDefaultSourceId(normalizedFlowId));
const sourceDefinition = getSourceDefinition(normalizedFlowId, normalizedSourceId);
const includeSharedServices = options?.includeSharedServices !== false;
const serviceGroups = includeSharedServices
? (Array.isArray(flowDefinition?.services) ? flowDefinition.services.map((serviceId) => `service-${serviceId}`) : [])
: [];
return Array.from(new Set([
...(Array.isArray(flowDefinition?.baseGroups) ? flowDefinition.baseGroups : []),
...(Array.isArray(sourceDefinition?.groups) ? sourceDefinition.groups : []),
...serviceGroups,
]));
}
function getSettingsGroupDefinition(groupId) {
const normalizedGroupId = String(groupId || '').trim();
return SETTINGS_GROUP_DEFINITIONS[normalizedGroupId] || null;
}
function getSettingsGroupDefinitions() {
return SETTINGS_GROUP_DEFINITIONS;
}
function getRuntimeSourceDefinitions() {
const next = {};
Object.values(FLOW_DEFINITIONS).forEach((flowDefinition) => {
Object.assign(next, flowDefinition.runtimeSources || {});
});
return next;
}
function getDriverDefinitions() {
const next = {};
Object.values(FLOW_DEFINITIONS).forEach((flowDefinition) => {
Object.assign(next, flowDefinition.driverDefinitions || {});
});
return next;
}
return {
DEFAULT_FLOW_CAPABILITIES,
DEFAULT_FLOW_ID,
DEFAULT_KIRO_REGION,
DEFAULT_KIRO_RS_URL,
DEFAULT_KIRO_SOURCE_ID,
DEFAULT_OPENAI_SOURCE_ID,
FLOW_DEFINITIONS,
LEGACY_OPENAI_FLOW_ALIAS,
OPENAI_SOURCE_IDS,
SETTINGS_GROUP_DEFINITIONS,
SHARED_SERVICE_IDS,
getDefaultSourceId,
getDriverDefinitions,
getFlowCapabilities,
getFlowDefinition,
getFlowLabel,
getRegisteredFlowIds,
getRuntimeSourceDefinitions,
getSettingsGroupDefinition,
getSettingsGroupDefinitions,
getSourceDefinition,
getSourceDefinitions,
getSourceLabel,
getSourceOptions,
getVisibleGroupIds,
mapPanelModeToSourceId,
mapSourceIdToPanelMode,
normalizeFlowId,
normalizeKiroSourceId,
normalizeOpenAiSourceId,
normalizeSourceId,
};
});
+442
View File
@@ -0,0 +1,442 @@
(function attachMultiPageSettingsSchema(root, factory) {
root.MultiPageSettingsSchema = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createSettingsSchemaModule() {
function isPlainObject(value) {
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
}
function cloneValue(value) {
if (Array.isArray(value)) {
return value.map((entry) => cloneValue(entry));
}
if (isPlainObject(value)) {
return Object.fromEntries(
Object.entries(value).map(([key, entryValue]) => [key, cloneValue(entryValue)])
);
}
return value;
}
function normalizeStepExecutionRangeEntry(value = {}, fallback = {}) {
const source = isPlainObject(value) ? value : {};
const fallbackSource = isPlainObject(fallback) ? fallback : {};
const fromStep = Math.max(1, Number(source.fromStep ?? fallbackSource.fromStep ?? 1) || 1);
const toStep = Math.max(fromStep, Number(source.toStep ?? fallbackSource.toStep ?? fromStep) || fromStep);
return {
enabled: Boolean(source.enabled ?? fallbackSource.enabled),
fromStep,
toStep,
};
}
function createSettingsSchema(deps = {}) {
const rootScope = typeof self !== 'undefined' ? self : globalThis;
const flowRegistry = deps.flowRegistry || rootScope.MultiPageFlowRegistry || {};
const defaultFlowId = String(deps.defaultFlowId || flowRegistry.DEFAULT_FLOW_ID || 'openai').trim().toLowerCase() || 'openai';
const defaultOpenAiSourceId = flowRegistry.DEFAULT_OPENAI_SOURCE_ID || 'cpa';
const defaultKiroSourceId = flowRegistry.DEFAULT_KIRO_SOURCE_ID || 'kiro-rs';
const defaultKiroRegion = flowRegistry.DEFAULT_KIRO_REGION || 'us-east-1';
const defaultKiroRsUrl = flowRegistry.DEFAULT_KIRO_RS_URL || 'https://kiro.leftcode.xyz/admin';
const normalizeFlowId = typeof flowRegistry.normalizeFlowId === 'function'
? flowRegistry.normalizeFlowId
: ((value = '', fallback = defaultFlowId) => {
const normalized = String(value || '').trim().toLowerCase();
return normalized || String(fallback || '').trim().toLowerCase() || defaultFlowId;
});
const normalizeSourceId = typeof flowRegistry.normalizeSourceId === 'function'
? flowRegistry.normalizeSourceId
: ((flowId, value = '', fallback = '') => String(value || fallback || '').trim().toLowerCase());
const mapSourceIdToPanelMode = typeof flowRegistry.mapSourceIdToPanelMode === 'function'
? flowRegistry.mapSourceIdToPanelMode
: ((_flowId, sourceId = '', fallback = defaultOpenAiSourceId) => String(sourceId || fallback || defaultOpenAiSourceId).trim().toLowerCase());
const mapPanelModeToSourceId = typeof flowRegistry.mapPanelModeToSourceId === 'function'
? flowRegistry.mapPanelModeToSourceId
: ((panelMode = '', fallback = defaultOpenAiSourceId) => String(panelMode || fallback || defaultOpenAiSourceId).trim().toLowerCase());
function buildDefaultSettingsState() {
return {
schemaVersion: 3,
activeFlowId: defaultFlowId,
services: {
email: {
provider: '163',
},
proxy: {
enabled: false,
provider: '711proxy',
mode: 'account',
},
},
flows: {
openai: {
source: {
selected: defaultOpenAiSourceId,
entries: {
cpa: {
vpsUrl: '',
vpsPassword: '',
localCpaStep9Mode: 'submit',
},
sub2api: {
sub2apiUrl: '',
sub2apiEmail: '',
sub2apiPassword: '',
sub2apiGroupName: 'codex',
sub2apiGroupNames: ['codex', 'openai-plus'],
sub2apiAccountPriority: 1,
sub2apiDefaultProxyName: '',
},
codex2api: {
codex2apiUrl: '',
codex2apiAdminKey: '',
},
},
},
account: {
customPassword: '',
},
signup: {
signupMethod: 'email',
phoneVerificationEnabled: false,
phoneSignupReloginAfterBindEmailEnabled: false,
},
plus: {
plusModeEnabled: false,
plusPaymentMethod: 'paypal',
},
autoRun: {
stepExecutionRange: {
enabled: false,
fromStep: 1,
toStep: 11,
},
},
},
kiro: {
source: {
selected: defaultKiroSourceId,
entries: {
'kiro-rs': {
kiroRsUrl: defaultKiroRsUrl,
kiroRsKey: '',
},
},
},
options: {
kiroRegion: defaultKiroRegion,
kiroRsPriority: 0,
kiroRsEndpoint: '',
kiroRsAuthRegion: '',
kiroRsApiRegion: '',
},
autoRun: {
stepExecutionRange: {
enabled: false,
fromStep: 1,
toStep: 3,
},
},
},
},
};
}
function getSourceValue(settingsState, pathGetter, fallback = {}) {
return cloneValue(pathGetter(isPlainObject(settingsState) ? settingsState : {}) || fallback);
}
function normalizeSettingsState(input = {}, options = {}) {
const defaults = buildDefaultSettingsState();
const nested = isPlainObject(input?.settingsState)
? input.settingsState
: (isPlainObject(input) && isPlainObject(input.flows) && isPlainObject(input.services) ? input : {});
const activeFlowId = normalizeFlowId(
input?.activeFlowId
?? nested?.activeFlowId
?? options?.activeFlowId
?? defaults.activeFlowId,
defaults.activeFlowId
);
const openaiSelectedSource = normalizeSourceId(
'openai',
nested?.flows?.openai?.source?.selected
?? input?.panelMode
?? input?.openaiSourceId
?? defaults.flows.openai.source.selected,
defaults.flows.openai.source.selected
);
const kiroSelectedSource = normalizeSourceId(
'kiro',
nested?.flows?.kiro?.source?.selected
?? input?.kiroSourceId
?? defaults.flows.kiro.source.selected,
defaults.flows.kiro.source.selected
);
const stepExecutionRangeByFlow = isPlainObject(input?.stepExecutionRangeByFlow)
? input.stepExecutionRangeByFlow
: {};
return {
schemaVersion: Number(input?.settingsSchemaVersion || nested?.schemaVersion || defaults.schemaVersion) || defaults.schemaVersion,
activeFlowId,
services: {
email: {
provider: String(
nested?.services?.email?.provider
?? input?.mailProvider
?? defaults.services.email.provider
).trim() || defaults.services.email.provider,
},
proxy: {
enabled: Boolean(
nested?.services?.proxy?.enabled
?? input?.ipProxyEnabled
?? defaults.services.proxy.enabled
),
provider: String(
nested?.services?.proxy?.provider
?? input?.ipProxyService
?? defaults.services.proxy.provider
).trim() || defaults.services.proxy.provider,
mode: String(
nested?.services?.proxy?.mode
?? input?.ipProxyMode
?? defaults.services.proxy.mode
).trim() || defaults.services.proxy.mode,
},
},
flows: {
openai: {
source: {
selected: openaiSelectedSource,
entries: {
cpa: {
...defaults.flows.openai.source.entries.cpa,
...getSourceValue(nested, (state) => state.flows?.openai?.source?.entries?.cpa),
vpsUrl: String(input?.vpsUrl ?? nested?.flows?.openai?.source?.entries?.cpa?.vpsUrl ?? '').trim(),
vpsPassword: String(input?.vpsPassword ?? nested?.flows?.openai?.source?.entries?.cpa?.vpsPassword ?? ''),
localCpaStep9Mode: String(
input?.localCpaStep9Mode
?? nested?.flows?.openai?.source?.entries?.cpa?.localCpaStep9Mode
?? defaults.flows.openai.source.entries.cpa.localCpaStep9Mode
).trim() || defaults.flows.openai.source.entries.cpa.localCpaStep9Mode,
},
sub2api: {
...defaults.flows.openai.source.entries.sub2api,
...getSourceValue(nested, (state) => state.flows?.openai?.source?.entries?.sub2api),
sub2apiUrl: String(input?.sub2apiUrl ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiUrl ?? '').trim(),
sub2apiEmail: String(input?.sub2apiEmail ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiEmail ?? '').trim(),
sub2apiPassword: String(input?.sub2apiPassword ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiPassword ?? ''),
sub2apiGroupName: String(input?.sub2apiGroupName ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiGroupName ?? defaults.flows.openai.source.entries.sub2api.sub2apiGroupName).trim() || defaults.flows.openai.source.entries.sub2api.sub2apiGroupName,
sub2apiGroupNames: Array.isArray(input?.sub2apiGroupNames)
? input.sub2apiGroupNames.map((entry) => String(entry || '').trim()).filter(Boolean)
: (Array.isArray(nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiGroupNames)
? nested.flows.openai.source.entries.sub2api.sub2apiGroupNames.map((entry) => String(entry || '').trim()).filter(Boolean)
: [...defaults.flows.openai.source.entries.sub2api.sub2apiGroupNames]),
sub2apiAccountPriority: Math.max(1, Number(input?.sub2apiAccountPriority ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiAccountPriority ?? defaults.flows.openai.source.entries.sub2api.sub2apiAccountPriority) || defaults.flows.openai.source.entries.sub2api.sub2apiAccountPriority),
sub2apiDefaultProxyName: String(input?.sub2apiDefaultProxyName ?? nested?.flows?.openai?.source?.entries?.sub2api?.sub2apiDefaultProxyName ?? '').trim(),
},
codex2api: {
...defaults.flows.openai.source.entries.codex2api,
...getSourceValue(nested, (state) => state.flows?.openai?.source?.entries?.codex2api),
codex2apiUrl: String(input?.codex2apiUrl ?? nested?.flows?.openai?.source?.entries?.codex2api?.codex2apiUrl ?? '').trim(),
codex2apiAdminKey: String(input?.codex2apiAdminKey ?? nested?.flows?.openai?.source?.entries?.codex2api?.codex2apiAdminKey ?? '').trim(),
},
},
},
account: {
customPassword: String(input?.customPassword ?? nested?.flows?.openai?.account?.customPassword ?? '').trim(),
},
signup: {
signupMethod: String(input?.signupMethod ?? nested?.flows?.openai?.signup?.signupMethod ?? defaults.flows.openai.signup.signupMethod).trim().toLowerCase() === 'phone' ? 'phone' : 'email',
phoneVerificationEnabled: Boolean(input?.phoneVerificationEnabled ?? nested?.flows?.openai?.signup?.phoneVerificationEnabled ?? defaults.flows.openai.signup.phoneVerificationEnabled),
phoneSignupReloginAfterBindEmailEnabled: Boolean(input?.phoneSignupReloginAfterBindEmailEnabled ?? nested?.flows?.openai?.signup?.phoneSignupReloginAfterBindEmailEnabled ?? defaults.flows.openai.signup.phoneSignupReloginAfterBindEmailEnabled),
},
plus: {
plusModeEnabled: Boolean(input?.plusModeEnabled ?? nested?.flows?.openai?.plus?.plusModeEnabled ?? defaults.flows.openai.plus.plusModeEnabled),
plusPaymentMethod: String(input?.plusPaymentMethod ?? nested?.flows?.openai?.plus?.plusPaymentMethod ?? defaults.flows.openai.plus.plusPaymentMethod).trim() || defaults.flows.openai.plus.plusPaymentMethod,
},
autoRun: {
stepExecutionRange: normalizeStepExecutionRangeEntry(
nested?.flows?.openai?.autoRun?.stepExecutionRange
?? stepExecutionRangeByFlow.openai
?? {},
defaults.flows.openai.autoRun.stepExecutionRange
),
},
},
kiro: {
source: {
selected: kiroSelectedSource,
entries: {
'kiro-rs': {
...defaults.flows.kiro.source.entries['kiro-rs'],
...getSourceValue(nested, (state) => state.flows?.kiro?.source?.entries?.['kiro-rs']),
kiroRsUrl: String(
input?.kiroRsUrl
?? nested?.flows?.kiro?.source?.entries?.['kiro-rs']?.kiroRsUrl
?? defaults.flows.kiro.source.entries['kiro-rs'].kiroRsUrl
).trim() || defaults.flows.kiro.source.entries['kiro-rs'].kiroRsUrl,
kiroRsKey: String(
input?.kiroRsKey
?? nested?.flows?.kiro?.source?.entries?.['kiro-rs']?.kiroRsKey
?? defaults.flows.kiro.source.entries['kiro-rs'].kiroRsKey
),
},
},
},
options: {
kiroRegion: String(
input?.kiroRegion
?? nested?.flows?.kiro?.options?.kiroRegion
?? defaults.flows.kiro.options.kiroRegion
).trim() || defaults.flows.kiro.options.kiroRegion,
kiroRsPriority: Number(
input?.kiroRsPriority
?? nested?.flows?.kiro?.options?.kiroRsPriority
?? defaults.flows.kiro.options.kiroRsPriority
) || 0,
kiroRsEndpoint: String(
input?.kiroRsEndpoint
?? nested?.flows?.kiro?.options?.kiroRsEndpoint
?? defaults.flows.kiro.options.kiroRsEndpoint
).trim(),
kiroRsAuthRegion: String(
input?.kiroRsAuthRegion
?? nested?.flows?.kiro?.options?.kiroRsAuthRegion
?? defaults.flows.kiro.options.kiroRsAuthRegion
).trim(),
kiroRsApiRegion: String(
input?.kiroRsApiRegion
?? nested?.flows?.kiro?.options?.kiroRsApiRegion
?? defaults.flows.kiro.options.kiroRsApiRegion
).trim(),
},
autoRun: {
stepExecutionRange: normalizeStepExecutionRangeEntry(
nested?.flows?.kiro?.autoRun?.stepExecutionRange
?? stepExecutionRangeByFlow.kiro
?? {},
defaults.flows.kiro.autoRun.stepExecutionRange
),
},
},
},
};
}
function buildStepExecutionRangeByFlow(settingsState = {}) {
const normalizedState = normalizeSettingsState(settingsState);
return {
openai: normalizeStepExecutionRangeEntry(
normalizedState?.flows?.openai?.autoRun?.stepExecutionRange,
buildDefaultSettingsState().flows.openai.autoRun.stepExecutionRange
),
kiro: normalizeStepExecutionRangeEntry(
normalizedState?.flows?.kiro?.autoRun?.stepExecutionRange,
buildDefaultSettingsState().flows.kiro.autoRun.stepExecutionRange
),
};
}
function getFlowSettings(settingsState = {}, flowId) {
const normalizedState = normalizeSettingsState(settingsState);
const normalizedFlowId = normalizeFlowId(flowId, normalizedState.activeFlowId);
return cloneValue(normalizedState?.flows?.[normalizedFlowId] || {});
}
function getSelectedSourceId(settingsState = {}, flowId) {
const flowSettings = getFlowSettings(settingsState, flowId);
const normalizedFlowId = normalizeFlowId(flowId, normalizeSettingsState(settingsState).activeFlowId);
return normalizeSourceId(
normalizedFlowId,
flowSettings?.source?.selected,
normalizedFlowId === 'kiro' ? defaultKiroSourceId : defaultOpenAiSourceId
);
}
function buildLegacySettingsPayload(settingsState = {}, baseInput = {}) {
const normalizedState = normalizeSettingsState(settingsState);
const next = {
...(isPlainObject(baseInput) ? cloneValue(baseInput) : {}),
};
const openaiState = normalizedState.flows.openai;
const kiroState = normalizedState.flows.kiro;
next.activeFlowId = normalizedState.activeFlowId;
next.panelMode = mapSourceIdToPanelMode('openai', openaiState.source.selected, defaultOpenAiSourceId);
next.kiroSourceId = getSelectedSourceId(normalizedState, 'kiro');
next.vpsUrl = openaiState.source.entries.cpa.vpsUrl;
next.vpsPassword = openaiState.source.entries.cpa.vpsPassword;
next.localCpaStep9Mode = openaiState.source.entries.cpa.localCpaStep9Mode;
next.sub2apiUrl = openaiState.source.entries.sub2api.sub2apiUrl;
next.sub2apiEmail = openaiState.source.entries.sub2api.sub2apiEmail;
next.sub2apiPassword = openaiState.source.entries.sub2api.sub2apiPassword;
next.sub2apiGroupName = openaiState.source.entries.sub2api.sub2apiGroupName;
next.sub2apiGroupNames = cloneValue(openaiState.source.entries.sub2api.sub2apiGroupNames);
next.sub2apiAccountPriority = openaiState.source.entries.sub2api.sub2apiAccountPriority;
next.sub2apiDefaultProxyName = openaiState.source.entries.sub2api.sub2apiDefaultProxyName;
next.codex2apiUrl = openaiState.source.entries.codex2api.codex2apiUrl;
next.codex2apiAdminKey = openaiState.source.entries.codex2api.codex2apiAdminKey;
next.customPassword = openaiState.account.customPassword;
next.signupMethod = openaiState.signup.signupMethod;
next.phoneVerificationEnabled = openaiState.signup.phoneVerificationEnabled;
next.phoneSignupReloginAfterBindEmailEnabled = openaiState.signup.phoneSignupReloginAfterBindEmailEnabled;
next.plusModeEnabled = openaiState.plus.plusModeEnabled;
next.plusPaymentMethod = openaiState.plus.plusPaymentMethod;
next.mailProvider = normalizedState.services.email.provider;
next.ipProxyEnabled = normalizedState.services.proxy.enabled;
next.ipProxyService = normalizedState.services.proxy.provider;
next.ipProxyMode = normalizedState.services.proxy.mode;
next.kiroRsUrl = kiroState.source.entries['kiro-rs'].kiroRsUrl;
next.kiroRsKey = kiroState.source.entries['kiro-rs'].kiroRsKey;
next.kiroRegion = kiroState.options.kiroRegion;
next.kiroRsPriority = kiroState.options.kiroRsPriority;
next.kiroRsEndpoint = kiroState.options.kiroRsEndpoint;
next.kiroRsAuthRegion = kiroState.options.kiroRsAuthRegion;
next.kiroRsApiRegion = kiroState.options.kiroRsApiRegion;
next.stepExecutionRangeByFlow = buildStepExecutionRangeByFlow(normalizedState);
next.settingsSchemaVersion = normalizedState.schemaVersion;
next.settingsState = cloneValue(normalizedState);
return next;
}
function getFlowInputState(settingsState = {}, flowId) {
const normalizedState = normalizeSettingsState(settingsState);
const normalizedFlowId = normalizeFlowId(flowId, normalizedState.activeFlowId);
if (normalizedFlowId === 'kiro') {
return {
activeFlowId: normalizedFlowId,
sourceId: getSelectedSourceId(normalizedState, 'kiro'),
kiroRsUrl: normalizedState.flows.kiro.source.entries['kiro-rs'].kiroRsUrl,
kiroRsKey: normalizedState.flows.kiro.source.entries['kiro-rs'].kiroRsKey,
kiroRegion: normalizedState.flows.kiro.options.kiroRegion,
};
}
return {
activeFlowId: normalizedFlowId,
sourceId: getSelectedSourceId(normalizedState, 'openai'),
panelMode: mapSourceIdToPanelMode('openai', normalizedState.flows.openai.source.selected, defaultOpenAiSourceId),
};
}
function normalizeFlatInput(input = {}) {
const state = normalizeSettingsState(input);
return buildLegacySettingsPayload(state, input);
}
return {
buildDefaultSettingsState,
buildLegacySettingsPayload,
buildStepExecutionRangeByFlow,
getFlowInputState,
getFlowSettings,
getSelectedSourceId,
normalizeFlatInput,
normalizeSettingsState,
};
}
return {
createSettingsSchema,
};
});
+32 -123
View File
@@ -1,29 +1,14 @@
(function attachMultiPageSourceRegistry(root, factory) {
root.MultiPageSourceRegistry = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createSourceRegistryModule() {
const rootScope = typeof self !== 'undefined' ? self : globalThis;
const flowRegistryApi = rootScope.MultiPageFlowRegistry || {};
const SOURCE_ALIASES = Object.freeze({
'signup-page': 'openai-auth',
});
const SOURCE_DEFINITIONS = Object.freeze({
'openai-auth': {
flowId: 'openai',
kind: 'flow-page',
label: '认证页',
readyPolicy: 'allow-child-frame',
family: 'openai-auth-family',
driverId: 'content/signup-page',
cleanupScopes: ['oauth-localhost-callback'],
},
chatgpt: {
flowId: 'openai',
kind: 'flow-entry',
label: 'ChatGPT 首页',
readyPolicy: 'allow-child-frame',
family: 'chatgpt-entry-family',
driverId: null,
cleanupScopes: [],
},
const SHARED_SOURCE_DEFINITIONS = Object.freeze({
'qq-mail': {
flowId: null,
kind: 'mail-provider',
@@ -87,69 +72,6 @@
driverId: 'content/duck-mail',
cleanupScopes: [],
},
'vps-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'CPA 面板',
readyPolicy: 'allow-child-frame',
family: 'vps-panel-family',
driverId: 'content/vps-panel',
cleanupScopes: [],
},
'platform-panel': {
flowId: 'openai',
kind: 'virtual-page',
label: '平台回调面板',
readyPolicy: 'disabled',
family: 'platform-panel-family',
driverId: 'content/platform-panel',
cleanupScopes: [],
},
'sub2api-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'SUB2API 后台',
readyPolicy: 'allow-child-frame',
family: 'sub2api-panel-family',
driverId: 'content/sub2api-panel',
cleanupScopes: [],
},
'codex2api-panel': {
flowId: 'openai',
kind: 'panel-page',
label: 'Codex2API 后台',
readyPolicy: 'allow-child-frame',
family: 'codex2api-panel-family',
driverId: 'content/sub2api-panel',
cleanupScopes: [],
},
'plus-checkout': {
flowId: 'openai',
kind: 'flow-page',
label: 'Plus Checkout',
readyPolicy: 'top-frame-only',
family: 'plus-checkout-family',
driverId: 'content/plus-checkout',
cleanupScopes: [],
},
'paypal-flow': {
flowId: 'openai',
kind: 'flow-page',
label: 'PayPal 授权页',
readyPolicy: 'allow-child-frame',
family: 'paypal-flow-family',
driverId: 'content/paypal-flow',
cleanupScopes: [],
},
'gopay-flow': {
flowId: 'openai',
kind: 'flow-page',
label: 'GoPay 授权页',
readyPolicy: 'allow-child-frame',
family: 'gopay-flow-family',
driverId: 'content/gopay-flow',
cleanupScopes: [],
},
'unknown-source': {
flowId: null,
kind: 'unknown',
@@ -161,22 +83,7 @@
},
});
const DRIVER_DEFINITIONS = Object.freeze({
'content/signup-page': {
sourceId: 'openai-auth',
commands: [
'submit-signup-email',
'fill-password',
'fill-profile',
'oauth-login',
'submit-verification-code',
'post-login-phone-verification',
'bind-email',
'fetch-bind-email-code',
'confirm-oauth',
'detect-auth-state',
],
},
const SHARED_DRIVER_DEFINITIONS = Object.freeze({
'content/qq-mail': {
sourceId: 'qq-mail',
commands: ['POLL_EMAIL'],
@@ -201,30 +108,6 @@
sourceId: 'duck-mail',
commands: ['FETCH_ALIAS_EMAIL'],
},
'content/sub2api-panel': {
sourceId: 'sub2api-panel',
commands: ['open-panel', 'fetch-oauth-url', 'platform-verify'],
},
'content/vps-panel': {
sourceId: 'vps-panel',
commands: ['open-panel', 'fetch-oauth-url', 'platform-verify'],
},
'content/platform-panel': {
sourceId: 'platform-panel',
commands: ['platform-verify', 'fetch-oauth-url'],
},
'content/plus-checkout': {
sourceId: 'plus-checkout',
commands: ['plus-checkout-create', 'plus-checkout-billing', 'plus-checkout-return'],
},
'content/paypal-flow': {
sourceId: 'paypal-flow',
commands: ['paypal-approve'],
},
'content/gopay-flow': {
sourceId: 'gopay-flow',
commands: ['gopay-subscription-confirm'],
},
});
const CLEANUP_SCOPE_OWNERS = Object.freeze({
@@ -240,9 +123,31 @@
'mail-2925',
'inbucket-mail',
'plus-checkout',
'kiro-device-auth',
]);
function getRuntimeSourceDefinitions() {
return {
...(typeof flowRegistryApi.getRuntimeSourceDefinitions === 'function'
? flowRegistryApi.getRuntimeSourceDefinitions()
: {}),
...SHARED_SOURCE_DEFINITIONS,
};
}
function getDriverDefinitions() {
return {
...(typeof flowRegistryApi.getDriverDefinitions === 'function'
? flowRegistryApi.getDriverDefinitions()
: {}),
...SHARED_DRIVER_DEFINITIONS,
};
}
function createSourceRegistry() {
const SOURCE_DEFINITIONS = getRuntimeSourceDefinitions();
const DRIVER_DEFINITIONS = getDriverDefinitions();
function parseUrlSafely(rawUrl) {
if (!rawUrl) return null;
try {
@@ -394,6 +299,9 @@
return candidate.hostname.endsWith('paypal.com');
case 'gopay-flow':
return /gopay|gojek/i.test(candidate.hostname);
case 'kiro-device-auth':
return candidate.hostname === 'view.awsapps.com'
|| candidate.hostname.endsWith('.amazonaws.com');
default:
return false;
}
@@ -416,6 +324,7 @@
if (normalizedHostname === 'www.icloud.com' || normalizedHostname === 'www.icloud.com.cn') return 'icloud-mail';
if (normalizedUrl.includes('duckduckgo.com/email/settings/autofill')) return 'duck-mail';
if (normalizedUrl.includes('2925.com')) return 'mail-2925';
if (normalizedHostname === 'view.awsapps.com' || normalizedHostname.endsWith('.amazonaws.com')) return 'kiro-device-auth';
if (isSignupEntryHost(normalizedHostname)) return 'chatgpt';
return 'unknown-source';
}
@@ -436,10 +345,10 @@
return {
detectSourceFromLocation,
driverAcceptsCommand,
getCleanupOwnerSource,
getDriverIdForSource,
getDriverMeta,
driverAcceptsCommand,
getSourceKeys,
getSourceLabel,
getSourceMeta,