feat: rebuild kiro flow as independent desktop auth pipeline

This commit is contained in:
QLHazyCoder
2026-05-18 22:50:43 +08:00
parent 4aa459e599
commit 995982d7be
42 changed files with 5029 additions and 2293 deletions
+117 -120
View File
@@ -5,11 +5,11 @@
const flowRegistryApi = rootScope.MultiPageFlowRegistry || {};
const settingsSchemaApi = rootScope.MultiPageSettingsSchema || {};
const DEFAULT_FLOW_ID = flowRegistryApi.DEFAULT_FLOW_ID || 'openai';
const DEFAULT_OPENAI_INTEGRATION_TARGET_ID = flowRegistryApi.DEFAULT_OPENAI_INTEGRATION_TARGET_ID || 'cpa';
const DEFAULT_OPENAI_TARGET_ID = flowRegistryApi.DEFAULT_OPENAI_TARGET_ID || 'cpa';
const SIGNUP_METHOD_EMAIL = 'email';
const SIGNUP_METHOD_PHONE = 'phone';
const VALID_OPENAI_INTEGRATION_TARGET_IDS = Array.isArray(flowRegistryApi.OPENAI_INTEGRATION_TARGET_IDS)
? flowRegistryApi.OPENAI_INTEGRATION_TARGET_IDS.slice()
const VALID_OPENAI_TARGET_IDS = Array.isArray(flowRegistryApi.OPENAI_TARGET_IDS)
? flowRegistryApi.OPENAI_TARGET_IDS.slice()
: ['cpa', 'sub2api', 'codex2api'];
const REGISTERED_FLOW_IDS = Array.isArray(flowRegistryApi.getRegisteredFlowIds?.())
? flowRegistryApi.getRegisteredFlowIds().map((flowId) => String(flowId || '').trim().toLowerCase()).filter(Boolean)
@@ -22,12 +22,12 @@
supportsPhoneVerificationSettings: false,
supportsPlusMode: false,
supportsContributionMode: false,
supportedIntegrationTargets: [],
supportedTargetIds: [],
supportsLuckmail: false,
supportsOauthTimeoutBudget: false,
canSwitchFlow: true,
stepDefinitionMode: 'default',
sourceSelectorLabel: '来源',
targetSelectorLabel: '来源',
});
const FLOW_CAPABILITIES = Object.freeze(
@@ -47,7 +47,7 @@
)
);
const DEFAULT_INTEGRATION_TARGET_CAPABILITIES = Object.freeze({
const DEFAULT_TARGET_CAPABILITIES = Object.freeze({
supportsPhoneSignup: true,
requiresPhoneSignupWarning: false,
});
@@ -59,12 +59,11 @@
'phoneVerificationEnabled',
'plusModeEnabled',
'signupMethod',
'kiroSourceId',
'openaiIntegrationTargetId',
'kiroIntegrationTargetId',
'kiroTargetId',
]);
const OPENAI_INTEGRATION_TARGET_CAPABILITIES = Object.freeze({
const OPENAI_TARGET_CAPABILITIES = Object.freeze({
cpa: Object.freeze({
supportsPhoneSignup: true,
requiresPhoneSignupWarning: true,
@@ -100,15 +99,15 @@
return Boolean(normalized) && REGISTERED_FLOW_ID_SET.has(normalized);
}
function normalizeOpenAiIntegrationTargetId(value = '', fallback = DEFAULT_OPENAI_INTEGRATION_TARGET_ID) {
function normalizeOpenAiTargetId(value = '', fallback = DEFAULT_OPENAI_TARGET_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (VALID_OPENAI_INTEGRATION_TARGET_IDS.includes(normalized)) {
if (VALID_OPENAI_TARGET_IDS.includes(normalized)) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return VALID_OPENAI_INTEGRATION_TARGET_IDS.includes(fallbackValue)
return VALID_OPENAI_TARGET_IDS.includes(fallbackValue)
? fallbackValue
: DEFAULT_OPENAI_INTEGRATION_TARGET_ID;
: DEFAULT_OPENAI_TARGET_ID;
}
function normalizeSignupMethod(value = '') {
@@ -117,31 +116,31 @@
: SIGNUP_METHOD_EMAIL;
}
function normalizeOpenAiIntegrationTargetList(values = []) {
function normalizeOpenAiTargetList(values = []) {
if (!Array.isArray(values)) {
return [];
}
const seen = new Set();
const normalized = [];
values.forEach((value) => {
const integrationTargetId = normalizeOpenAiIntegrationTargetId(value, '');
if (!integrationTargetId || seen.has(integrationTargetId)) {
const targetId = normalizeOpenAiTargetId(value, '');
if (!targetId || seen.has(targetId)) {
return;
}
seen.add(integrationTargetId);
normalized.push(integrationTargetId);
seen.add(targetId);
normalized.push(targetId);
});
return normalized;
}
function getIntegrationTargetLabel(flowId = DEFAULT_FLOW_ID, integrationTargetId = '') {
function getTargetLabel(flowId = DEFAULT_FLOW_ID, targetId = '') {
if (
isRegisteredFlowId(flowId)
&& typeof flowRegistryApi.getIntegrationTargetLabel === 'function'
&& typeof flowRegistryApi.getTargetLabel === 'function'
) {
return flowRegistryApi.getIntegrationTargetLabel(flowId, integrationTargetId);
return flowRegistryApi.getTargetLabel(flowId, targetId);
}
const normalized = String(integrationTargetId || '').trim().toLowerCase();
const normalized = String(targetId || '').trim().toLowerCase();
if (normalized === 'sub2api') {
return 'SUB2API';
}
@@ -151,16 +150,16 @@
if (normalized === 'cpa') {
return 'CPA';
}
return normalized || String(integrationTargetId || '').trim();
return normalized || String(targetId || '').trim();
}
function createFlowCapabilityRegistry(deps = {}) {
const {
defaultFlowCapabilities = DEFAULT_FLOW_CAPABILITIES,
defaultFlowId = DEFAULT_FLOW_ID,
defaultIntegrationTargetCapabilities = DEFAULT_INTEGRATION_TARGET_CAPABILITIES,
defaultTargetCapabilities = DEFAULT_TARGET_CAPABILITIES,
flowCapabilities = FLOW_CAPABILITIES,
integrationTargetCapabilities = OPENAI_INTEGRATION_TARGET_CAPABILITIES,
targetCapabilities = OPENAI_TARGET_CAPABILITIES,
} = deps;
const settingsSchema = settingsSchemaApi.createSettingsSchema
? settingsSchemaApi.createSettingsSchema({
@@ -171,70 +170,69 @@
function getFlowCapabilities(flowId) {
const normalizedFlowId = normalizeCapabilityFlowId(flowId, defaultFlowId);
const entry = flowCapabilities[normalizedFlowId] || null;
const supportedIntegrationTargets = normalizedFlowId === 'openai'
? normalizeOpenAiIntegrationTargetList(
entry?.supportedIntegrationTargets || defaultFlowCapabilities.supportedIntegrationTargets
const supportedTargetIds = normalizedFlowId === 'openai'
? normalizeOpenAiTargetList(
entry?.supportedTargetIds || defaultFlowCapabilities.supportedTargetIds
)
: (Array.isArray(entry?.supportedIntegrationTargets)
? entry.supportedIntegrationTargets.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean)
: (Array.isArray(entry?.supportedTargetIds)
? entry.supportedTargetIds.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean)
: []);
return {
...defaultFlowCapabilities,
...(entry || {}),
supportedIntegrationTargets,
supportedTargetIds,
};
}
function getOpenAiIntegrationTargetCapabilities(integrationTargetId) {
const normalizedIntegrationTargetId = normalizeOpenAiIntegrationTargetId(integrationTargetId);
function getOpenAiTargetCapabilities(targetId) {
const normalizedTargetId = normalizeOpenAiTargetId(targetId);
return {
...defaultIntegrationTargetCapabilities,
...(integrationTargetCapabilities[normalizedIntegrationTargetId] || {}),
...defaultTargetCapabilities,
...(targetCapabilities[normalizedTargetId] || {}),
};
}
function normalizeRequestedIntegrationTargetId(activeFlowId, state = {}, options = {}) {
function normalizeRequestedTargetId(activeFlowId, state = {}, options = {}) {
if (activeFlowId === 'openai') {
return normalizeOpenAiIntegrationTargetId(
options?.integrationTargetId
return normalizeOpenAiTargetId(
options?.targetId
?? options?.integrationTargetId
?? options?.panelMode
?? state?.openaiIntegrationTargetId
?? state?.panelMode,
DEFAULT_OPENAI_INTEGRATION_TARGET_ID
DEFAULT_OPENAI_TARGET_ID
);
}
const rawIntegrationTargetId = activeFlowId === 'kiro'
const rawTargetId = activeFlowId === 'kiro'
? (
options?.integrationTargetId
?? state?.kiroIntegrationTargetId
?? state?.kiroSourceId
?? flowRegistryApi.getDefaultIntegrationTargetId?.(activeFlowId)
options?.targetId
?? state?.kiroTargetId
?? flowRegistryApi.getDefaultTargetId?.(activeFlowId)
?? ''
)
: (
options?.integrationTargetId
?? state?.integrationTargetId
options?.targetId
?? state?.targetId
?? state?.openaiIntegrationTargetId
?? state?.panelMode
?? state?.kiroIntegrationTargetId
?? state?.kiroSourceId
?? flowRegistryApi.getDefaultIntegrationTargetId?.(activeFlowId)
?? state?.kiroTargetId
?? flowRegistryApi.getDefaultTargetId?.(activeFlowId)
?? ''
);
if (
isRegisteredFlowId(activeFlowId)
&& typeof flowRegistryApi.normalizeIntegrationTargetId === 'function'
&& typeof flowRegistryApi.normalizeTargetId === 'function'
) {
return flowRegistryApi.normalizeIntegrationTargetId(
return flowRegistryApi.normalizeTargetId(
activeFlowId,
rawIntegrationTargetId,
flowRegistryApi.getDefaultIntegrationTargetId?.(activeFlowId)
rawTargetId,
flowRegistryApi.getDefaultTargetId?.(activeFlowId)
);
}
return String(rawIntegrationTargetId || '').trim().toLowerCase();
return String(rawTargetId || '').trim().toLowerCase();
}
function normalizeChangedKeys(values = []) {
@@ -252,33 +250,33 @@
return normalized;
}
function resolveEffectiveIntegrationTargetId(activeFlowId, state = {}, requestedIntegrationTargetId = DEFAULT_OPENAI_INTEGRATION_TARGET_ID) {
function resolveEffectiveTargetId(activeFlowId, state = {}, requestedTargetId = DEFAULT_OPENAI_TARGET_ID) {
if (!isRegisteredFlowId(activeFlowId)) {
return normalizeRequestedIntegrationTargetId(activeFlowId, state, {
integrationTargetId: requestedIntegrationTargetId,
return normalizeRequestedTargetId(activeFlowId, state, {
targetId: requestedTargetId,
});
}
if (settingsSchema?.getSelectedIntegrationTargetId) {
const integrationTargetId = settingsSchema.getSelectedIntegrationTargetId({
if (settingsSchema?.getSelectedTargetId) {
const targetId = settingsSchema.getSelectedTargetId({
...state,
activeFlowId,
}, activeFlowId);
if (integrationTargetId) {
return integrationTargetId;
if (targetId) {
return targetId;
}
}
if (typeof flowRegistryApi.normalizeIntegrationTargetId === 'function') {
return flowRegistryApi.normalizeIntegrationTargetId(
if (typeof flowRegistryApi.normalizeTargetId === 'function') {
return flowRegistryApi.normalizeTargetId(
activeFlowId,
activeFlowId === 'openai'
? (state?.openaiIntegrationTargetId || state?.panelMode || requestedIntegrationTargetId)
: (state?.kiroIntegrationTargetId || state?.kiroSourceId || requestedIntegrationTargetId),
flowRegistryApi.getDefaultIntegrationTargetId?.(activeFlowId)
? (state?.openaiIntegrationTargetId || state?.panelMode || requestedTargetId)
: (state?.kiroTargetId || requestedTargetId),
flowRegistryApi.getDefaultTargetId?.(activeFlowId)
);
}
return activeFlowId === 'openai'
? normalizeOpenAiIntegrationTargetId(requestedIntegrationTargetId)
: String(requestedIntegrationTargetId || '').trim().toLowerCase();
? normalizeOpenAiTargetId(requestedTargetId)
: String(requestedTargetId || '').trim().toLowerCase();
}
function resolveSidepanelCapabilities(options = {}) {
@@ -288,25 +286,25 @@
defaultFlowId
);
const flowState = getFlowCapabilities(activeFlowId);
const requestedIntegrationTargetId = normalizeRequestedIntegrationTargetId(
const requestedTargetId = normalizeRequestedTargetId(
activeFlowId,
state,
options
);
const supportedIntegrationTargets = activeFlowId === 'openai'
? normalizeOpenAiIntegrationTargetList(flowState.supportedIntegrationTargets)
: (Array.isArray(flowState.supportedIntegrationTargets)
? flowState.supportedIntegrationTargets.slice()
const supportedTargetIds = activeFlowId === 'openai'
? normalizeOpenAiTargetList(flowState.supportedTargetIds)
: (Array.isArray(flowState.supportedTargetIds)
? flowState.supportedTargetIds.slice()
: []);
const integrationTargetSupported = supportedIntegrationTargets.length === 0
const targetSupported = supportedTargetIds.length === 0
? true
: supportedIntegrationTargets.includes(requestedIntegrationTargetId);
const effectiveIntegrationTargetId = integrationTargetSupported
? requestedIntegrationTargetId
: (supportedIntegrationTargets[0] || requestedIntegrationTargetId);
const integrationTargetState = activeFlowId === 'openai'
? getOpenAiIntegrationTargetCapabilities(effectiveIntegrationTargetId)
: defaultIntegrationTargetCapabilities;
: supportedTargetIds.includes(requestedTargetId);
const effectiveTargetId = targetSupported
? requestedTargetId
: (supportedTargetIds[0] || requestedTargetId);
const targetState = activeFlowId === 'openai'
? getOpenAiTargetCapabilities(effectiveTargetId)
: defaultTargetCapabilities;
const runtimeLocks = {
autoRunLocked: Boolean(options?.autoRunLocked ?? state?.autoRunLocked),
contributionMode: activeFlowId === 'openai' && flowState.supportsContributionMode && Boolean(state?.contributionMode),
@@ -320,7 +318,7 @@
}
const canSelectPhoneSignup = activeFlowId === 'openai'
&& Boolean(flowState.supportsPhoneSignup)
&& Boolean(integrationTargetState.supportsPhoneSignup)
&& Boolean(targetState.supportsPhoneSignup)
&& runtimeLocks.phoneVerificationEnabled
&& !runtimeLocks.plusModeEnabled
&& !runtimeLocks.contributionMode;
@@ -340,7 +338,7 @@
: effectiveSignupMethods[0]);
const visibleGroupIds = typeof flowRegistryApi.getVisibleGroupIds === 'function'
&& isRegisteredFlowId(activeFlowId)
? flowRegistryApi.getVisibleGroupIds(activeFlowId, effectiveIntegrationTargetId)
? flowRegistryApi.getVisibleGroupIds(activeFlowId, effectiveTargetId)
: [];
return {
@@ -351,38 +349,38 @@
canShowPlusSettings: activeFlowId === 'openai' && Boolean(flowState.supportsPlusMode),
canSwitchFlow: Boolean(flowState.canSwitchFlow),
canUsePhoneSignup: canSelectPhoneSignup,
canUseSelectedPanelMode: integrationTargetSupported,
effectiveIntegrationTargetId,
effectivePanelMode: effectiveIntegrationTargetId,
canUseSelectedTarget: targetSupported,
effectivePanelMode: effectiveTargetId,
effectiveSignupMethod,
effectiveSignupMethods,
effectiveSourceId: effectiveIntegrationTargetId,
effectiveTargetId,
flowCapabilities: flowState,
integrationTargetCapabilities: integrationTargetState,
panelCapabilities: integrationTargetState,
panelMode: effectiveIntegrationTargetId,
requestedIntegrationTargetId,
requestedPanelMode: requestedIntegrationTargetId,
panelCapabilities: targetState,
panelMode: effectiveTargetId,
requestedSignupMethod,
requestedTargetId,
runtimeLocks,
shouldWarnCpaPhoneSignup: effectiveSignupMethod === SIGNUP_METHOD_PHONE
&& Boolean(integrationTargetState.requiresPhoneSignupWarning),
&& Boolean(targetState.requiresPhoneSignupWarning),
stepDefinitionOptions: {
activeFlowId,
integrationTargetId: effectiveIntegrationTargetId,
panelMode: effectiveIntegrationTargetId,
integrationTargetId: effectiveTargetId,
panelMode: effectiveTargetId,
targetId: effectiveTargetId,
plusModeEnabled: runtimeLocks.plusModeEnabled,
signupMethod: effectiveSignupMethod,
},
supportedIntegrationTargets,
supportedPanelModes: supportedIntegrationTargets,
supportedPanelModes: supportedTargetIds,
supportedTargetIds,
targetCapabilities: targetState,
targetId: effectiveTargetId,
visibleGroupIds,
};
}
function buildPhoneSignupValidationError(capabilityState = {}) {
const flowState = capabilityState.flowCapabilities || {};
const integrationTargetState = capabilityState.integrationTargetCapabilities || {};
const targetState = capabilityState.targetCapabilities || {};
const runtimeLocks = capabilityState.runtimeLocks || {};
if (!flowState.supportsPhoneSignup) {
@@ -391,10 +389,10 @@
message: '当前 flow 不支持手机号注册。',
};
}
if (!integrationTargetState.supportsPhoneSignup) {
if (!targetState.supportsPhoneSignup) {
return {
code: 'phone_signup_panel_unsupported',
message: `当前来源 ${getIntegrationTargetLabel(capabilityState.activeFlowId, capabilityState.requestedIntegrationTargetId)} 不支持手机号注册。`,
message: `当前来源 ${getTargetLabel(capabilityState.activeFlowId, capabilityState.requestedTargetId)} 不支持手机号注册。`,
};
}
if (!runtimeLocks.phoneVerificationEnabled) {
@@ -427,13 +425,13 @@
const errors = [];
if (
Array.isArray(capabilityState.supportedIntegrationTargets)
&& capabilityState.supportedIntegrationTargets.length > 0
&& capabilityState.canUseSelectedPanelMode === false
Array.isArray(capabilityState.supportedTargetIds)
&& capabilityState.supportedTargetIds.length > 0
&& capabilityState.canUseSelectedTarget === false
) {
errors.push({
code: 'panel_mode_unsupported',
message: `当前 flow 不支持 ${getIntegrationTargetLabel(capabilityState.activeFlowId, capabilityState.requestedIntegrationTargetId)} 来源。`,
message: `当前 flow 不支持 ${getTargetLabel(capabilityState.activeFlowId, capabilityState.requestedTargetId)} 来源。`,
});
}
@@ -481,18 +479,17 @@
const shouldReconcileSignupMethod = MODE_SWITCH_RELEVANT_KEYS.some((key) => changedKeySet.has(key));
if (
(changedKeySet.has('panelMode') || changedKeySet.has('openaiIntegrationTargetId') || changedKeySet.has('kiroIntegrationTargetId'))
&& Array.isArray(capabilityState.supportedIntegrationTargets)
&& capabilityState.supportedIntegrationTargets.length > 0
&& capabilityState.canUseSelectedPanelMode === false
(changedKeySet.has('panelMode') || changedKeySet.has('openaiIntegrationTargetId') || changedKeySet.has('kiroTargetId'))
&& Array.isArray(capabilityState.supportedTargetIds)
&& capabilityState.supportedTargetIds.length > 0
&& capabilityState.canUseSelectedTarget === false
) {
normalizedUpdates.panelMode = capabilityState.effectiveIntegrationTargetId;
normalizedUpdates.openaiIntegrationTargetId = capabilityState.effectiveIntegrationTargetId;
normalizedUpdates.kiroIntegrationTargetId = capabilityState.effectiveIntegrationTargetId;
normalizedUpdates.kiroSourceId = capabilityState.effectiveIntegrationTargetId;
normalizedUpdates.panelMode = capabilityState.effectiveTargetId;
normalizedUpdates.openaiIntegrationTargetId = capabilityState.effectiveTargetId;
normalizedUpdates.kiroTargetId = capabilityState.effectiveTargetId;
errors.push({
code: 'panel_mode_unsupported',
message: `当前 flow 不支持 ${getIntegrationTargetLabel(capabilityState.activeFlowId, capabilityState.requestedIntegrationTargetId)} 来源。`,
message: `当前 flow 不支持 ${getTargetLabel(capabilityState.activeFlowId, capabilityState.requestedTargetId)} 来源。`,
});
}
@@ -556,9 +553,9 @@
return {
canUsePhoneSignup,
getFlowCapabilities,
getOpenAiIntegrationTargetCapabilities,
getOpenAiTargetCapabilities,
normalizeFlowId,
normalizeOpenAiIntegrationTargetId,
normalizeOpenAiTargetId,
normalizeSignupMethod,
resolveSidepanelCapabilities,
resolveSignupMethod,
@@ -571,15 +568,15 @@
createFlowCapabilityRegistry,
DEFAULT_FLOW_CAPABILITIES,
DEFAULT_FLOW_ID,
DEFAULT_INTEGRATION_TARGET_CAPABILITIES,
DEFAULT_OPENAI_INTEGRATION_TARGET_ID,
DEFAULT_TARGET_CAPABILITIES,
DEFAULT_OPENAI_TARGET_ID,
FLOW_CAPABILITIES,
OPENAI_INTEGRATION_TARGET_CAPABILITIES,
OPENAI_TARGET_CAPABILITIES,
SIGNUP_METHOD_EMAIL,
SIGNUP_METHOD_PHONE,
VALID_OPENAI_INTEGRATION_TARGET_IDS,
VALID_OPENAI_TARGET_IDS,
normalizeFlowId,
normalizeOpenAiIntegrationTargetId,
normalizeOpenAiTargetId,
normalizeSignupMethod,
};
});
+98 -71
View File
@@ -2,11 +2,11 @@
root.MultiPageFlowRegistry = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createFlowRegistryModule() {
const DEFAULT_FLOW_ID = 'openai';
const DEFAULT_OPENAI_INTEGRATION_TARGET_ID = 'cpa';
const DEFAULT_KIRO_INTEGRATION_TARGET_ID = 'kiro-rs';
const DEFAULT_OPENAI_TARGET_ID = 'cpa';
const DEFAULT_KIRO_TARGET_ID = 'kiro-rs';
const DEFAULT_KIRO_PUBLICATION_TARGET_ID = 'kiro-rs';
const DEFAULT_KIRO_RS_URL = 'https://kiro.leftcode.xyz/admin';
const OPENAI_INTEGRATION_TARGET_IDS = Object.freeze(['cpa', 'sub2api', 'codex2api']);
const OPENAI_TARGET_IDS = Object.freeze(['cpa', 'sub2api', 'codex2api']);
const SHARED_SERVICE_IDS = Object.freeze(['account', 'email', 'proxy']);
const DEFAULT_FLOW_CAPABILITIES = Object.freeze({
@@ -15,12 +15,12 @@
supportsPhoneVerificationSettings: false,
supportsPlusMode: false,
supportsContributionMode: false,
supportedIntegrationTargets: [],
supportedTargetIds: [],
supportsLuckmail: false,
supportsOauthTimeoutBudget: false,
canSwitchFlow: true,
stepDefinitionMode: 'default',
sourceSelectorLabel: '来源',
targetSelectorLabel: '来源',
});
function freezeDeep(value) {
@@ -44,7 +44,7 @@
supportsPhoneVerificationSettings: true,
supportsPlusMode: true,
supportsContributionMode: true,
supportedIntegrationTargets: [...OPENAI_INTEGRATION_TARGET_IDS],
supportedTargetIds: [...OPENAI_TARGET_IDS],
supportsLuckmail: true,
supportsOauthTimeoutBudget: true,
stepDefinitionMode: 'openai-dynamic',
@@ -55,7 +55,7 @@
'openai-oauth',
'openai-step6',
],
integrationTargets: {
targets: {
cpa: {
id: 'cpa',
label: 'CPA 面板',
@@ -203,13 +203,13 @@
services: ['account', 'email', 'proxy'],
capabilities: {
...DEFAULT_FLOW_CAPABILITIES,
supportedIntegrationTargets: [DEFAULT_KIRO_INTEGRATION_TARGET_ID],
stepDefinitionMode: 'kiro-device-auth',
supportedTargetIds: [DEFAULT_KIRO_TARGET_ID],
stepDefinitionMode: 'kiro',
},
baseGroups: [
'kiro-runtime-status',
],
integrationTargets: {
targets: {
'kiro-rs': {
id: 'kiro-rs',
label: 'kiro.rs',
@@ -223,13 +223,22 @@
},
},
runtimeSources: {
'kiro-device-auth': {
'kiro-register-page': {
flowId: 'kiro',
kind: 'flow-page',
label: 'Kiro 授权页',
label: 'Kiro 注册页',
readyPolicy: 'top-frame-only',
family: 'kiro-device-auth-family',
driverId: 'content/kiro-device-auth-page',
family: 'kiro-register-page-family',
driverId: 'content/kiro/register-page',
cleanupScopes: [],
},
'kiro-desktop-authorize': {
flowId: 'kiro',
kind: 'flow-page',
label: 'Kiro 桌面授权页',
readyPolicy: 'top-frame-only',
family: 'kiro-desktop-authorize-family',
driverId: 'content/kiro/desktop-authorize-page',
cleanupScopes: [],
},
'kiro-rs-admin': {
@@ -243,25 +252,43 @@
},
},
driverDefinitions: {
'content/kiro-device-auth-page': {
sourceId: 'kiro-device-auth',
'content/kiro/register-page': {
sourceId: 'kiro-register-page',
commands: [
'kiro-submit-email',
'kiro-submit-name',
'kiro-submit-verification-code',
'kiro-fill-password',
'kiro-confirm-access',
'kiro-submit-password',
'kiro-complete-register-consent',
],
},
'background/kiro-device-auth': {
sourceId: 'kiro-device-auth',
'content/kiro/desktop-authorize-page': {
sourceId: 'kiro-desktop-authorize',
commands: [
'kiro-start-device-login',
'kiro-complete-desktop-authorize',
],
},
'background/kiro-register': {
sourceId: 'kiro-register-page',
commands: [
'kiro-open-register-page',
'kiro-submit-email',
'kiro-submit-name',
'kiro-submit-verification-code',
'kiro-fill-password',
'kiro-confirm-access',
'kiro-submit-password',
'kiro-complete-register-consent',
],
},
'background/kiro-desktop-authorize': {
sourceId: 'kiro-desktop-authorize',
commands: [
'kiro-start-desktop-authorize',
'kiro-complete-desktop-authorize',
],
},
'background/kiro-publisher-kiro-rs': {
sourceId: 'kiro-rs-admin',
commands: [
'kiro-upload-credential',
],
},
@@ -362,69 +389,69 @@
return getFlowDefinition(flowId)?.label || normalizeFlowId(flowId);
}
function getDefaultIntegrationTargetId(flowId) {
function getDefaultTargetId(flowId) {
return normalizeFlowId(flowId) === 'kiro'
? DEFAULT_KIRO_INTEGRATION_TARGET_ID
: DEFAULT_OPENAI_INTEGRATION_TARGET_ID;
? DEFAULT_KIRO_TARGET_ID
: DEFAULT_OPENAI_TARGET_ID;
}
function normalizeOpenAiIntegrationTargetId(value = '', fallback = DEFAULT_OPENAI_INTEGRATION_TARGET_ID) {
function normalizeOpenAiTargetId(value = '', fallback = DEFAULT_OPENAI_TARGET_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (OPENAI_INTEGRATION_TARGET_IDS.includes(normalized)) {
if (OPENAI_TARGET_IDS.includes(normalized)) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return OPENAI_INTEGRATION_TARGET_IDS.includes(fallbackValue)
return OPENAI_TARGET_IDS.includes(fallbackValue)
? fallbackValue
: DEFAULT_OPENAI_INTEGRATION_TARGET_ID;
: DEFAULT_OPENAI_TARGET_ID;
}
function normalizeKiroIntegrationTargetId(value = '', fallback = DEFAULT_KIRO_INTEGRATION_TARGET_ID) {
function normalizeKiroTargetId(value = '', fallback = DEFAULT_KIRO_TARGET_ID) {
const normalized = String(value || '').trim().toLowerCase();
if (normalized === DEFAULT_KIRO_INTEGRATION_TARGET_ID) {
if (normalized === DEFAULT_KIRO_TARGET_ID) {
return normalized;
}
const fallbackValue = String(fallback || '').trim().toLowerCase();
return fallbackValue === DEFAULT_KIRO_INTEGRATION_TARGET_ID
return fallbackValue === DEFAULT_KIRO_TARGET_ID
? fallbackValue
: DEFAULT_KIRO_INTEGRATION_TARGET_ID;
: DEFAULT_KIRO_TARGET_ID;
}
function normalizeIntegrationTargetId(flowId, integrationTargetId = '', fallback = undefined) {
function normalizeTargetId(flowId, targetId = '', fallback = undefined) {
const normalizedFlowId = normalizeFlowId(flowId);
if (normalizedFlowId === 'kiro') {
return normalizeKiroIntegrationTargetId(
integrationTargetId,
fallback || DEFAULT_KIRO_INTEGRATION_TARGET_ID
return normalizeKiroTargetId(
targetId,
fallback || DEFAULT_KIRO_TARGET_ID
);
}
return normalizeOpenAiIntegrationTargetId(
integrationTargetId,
fallback || DEFAULT_OPENAI_INTEGRATION_TARGET_ID
return normalizeOpenAiTargetId(
targetId,
fallback || DEFAULT_OPENAI_TARGET_ID
);
}
function getIntegrationTargetDefinitions(flowId) {
return getFlowDefinition(flowId)?.integrationTargets || {};
function getTargetDefinitions(flowId) {
return getFlowDefinition(flowId)?.targets || {};
}
function getIntegrationTargetDefinition(flowId, integrationTargetId) {
function getTargetDefinition(flowId, targetId) {
const normalizedFlowId = normalizeFlowId(flowId);
const normalizedIntegrationTargetId = normalizeIntegrationTargetId(
const normalizedTargetId = normalizeTargetId(
normalizedFlowId,
integrationTargetId,
getDefaultIntegrationTargetId(normalizedFlowId)
targetId,
getDefaultTargetId(normalizedFlowId)
);
return getIntegrationTargetDefinitions(normalizedFlowId)[normalizedIntegrationTargetId] || null;
return getTargetDefinitions(normalizedFlowId)[normalizedTargetId] || null;
}
function getIntegrationTargetOptions(flowId) {
return Object.values(getIntegrationTargetDefinitions(flowId));
function getTargetOptions(flowId) {
return Object.values(getTargetDefinitions(flowId));
}
function getIntegrationTargetLabel(flowId, integrationTargetId) {
return getIntegrationTargetDefinition(flowId, integrationTargetId)?.label
|| normalizeIntegrationTargetId(flowId, integrationTargetId);
function getTargetLabel(flowId, targetId) {
return getTargetDefinition(flowId, targetId)?.label
|| normalizeTargetId(flowId, targetId);
}
function getPublicationTargetDefinitions(flowId) {
@@ -450,17 +477,17 @@
};
}
function getVisibleGroupIds(flowId, integrationTargetId, options = {}) {
function getVisibleGroupIds(flowId, targetId, options = {}) {
const normalizedFlowId = normalizeFlowId(flowId);
const flowDefinition = getFlowDefinition(normalizedFlowId);
const normalizedIntegrationTargetId = normalizeIntegrationTargetId(
const normalizedTargetId = normalizeTargetId(
normalizedFlowId,
integrationTargetId,
getDefaultIntegrationTargetId(normalizedFlowId)
targetId,
getDefaultTargetId(normalizedFlowId)
);
const integrationTargetDefinition = getIntegrationTargetDefinition(
const targetDefinition = getTargetDefinition(
normalizedFlowId,
normalizedIntegrationTargetId
normalizedTargetId
);
const includeSharedServices = options?.includeSharedServices !== false;
const serviceGroups = includeSharedServices
@@ -470,7 +497,7 @@
: [];
return Array.from(new Set([
...(Array.isArray(flowDefinition?.baseGroups) ? flowDefinition.baseGroups : []),
...(Array.isArray(integrationTargetDefinition?.groups) ? integrationTargetDefinition.groups : []),
...(Array.isArray(targetDefinition?.groups) ? targetDefinition.groups : []),
...serviceGroups,
]));
}
@@ -503,33 +530,33 @@
return {
DEFAULT_FLOW_CAPABILITIES,
DEFAULT_FLOW_ID,
DEFAULT_KIRO_INTEGRATION_TARGET_ID,
DEFAULT_KIRO_TARGET_ID,
DEFAULT_KIRO_PUBLICATION_TARGET_ID,
DEFAULT_KIRO_RS_URL,
DEFAULT_OPENAI_INTEGRATION_TARGET_ID,
DEFAULT_OPENAI_TARGET_ID,
FLOW_DEFINITIONS,
OPENAI_INTEGRATION_TARGET_IDS,
OPENAI_TARGET_IDS,
SETTINGS_GROUP_DEFINITIONS,
SHARED_SERVICE_IDS,
getDefaultIntegrationTargetId,
getDriverDefinitions,
getDefaultTargetId,
getFlowCapabilities,
getFlowDefinition,
getFlowLabel,
getIntegrationTargetDefinition,
getIntegrationTargetDefinitions,
getIntegrationTargetLabel,
getIntegrationTargetOptions,
getPublicationTargetDefinition,
getPublicationTargetDefinitions,
getRegisteredFlowIds,
getRuntimeSourceDefinitions,
getSettingsGroupDefinition,
getSettingsGroupDefinitions,
getTargetDefinition,
getTargetDefinitions,
getTargetLabel,
getTargetOptions,
getVisibleGroupIds,
normalizeFlowId,
normalizeIntegrationTargetId,
normalizeKiroIntegrationTargetId,
normalizeOpenAiIntegrationTargetId,
normalizeKiroTargetId,
normalizeOpenAiTargetId,
normalizeTargetId,
};
});
+43 -40
View File
@@ -35,8 +35,8 @@
const defaultFlowId = String(
deps.defaultFlowId || flowRegistry.DEFAULT_FLOW_ID || 'openai'
).trim().toLowerCase() || 'openai';
const defaultOpenAiIntegrationTargetId = flowRegistry.DEFAULT_OPENAI_INTEGRATION_TARGET_ID || 'cpa';
const defaultKiroIntegrationTargetId = flowRegistry.DEFAULT_KIRO_INTEGRATION_TARGET_ID || 'kiro-rs';
const defaultOpenAiTargetId = flowRegistry.DEFAULT_OPENAI_TARGET_ID || 'cpa';
const defaultKiroTargetId = flowRegistry.DEFAULT_KIRO_TARGET_ID || 'kiro-rs';
const defaultKiroRsUrl = flowRegistry.DEFAULT_KIRO_RS_URL || 'https://kiro.leftcode.xyz/admin';
const normalizeFlowId = typeof flowRegistry.normalizeFlowId === 'function'
? flowRegistry.normalizeFlowId
@@ -44,8 +44,8 @@
const normalized = String(value || '').trim().toLowerCase();
return normalized || String(fallback || '').trim().toLowerCase() || defaultFlowId;
});
const normalizeIntegrationTargetId = typeof flowRegistry.normalizeIntegrationTargetId === 'function'
? flowRegistry.normalizeIntegrationTargetId
const normalizeTargetId = typeof flowRegistry.normalizeTargetId === 'function'
? flowRegistry.normalizeTargetId
: ((_flowId, value = '', fallback = '') => String(value || fallback || '').trim().toLowerCase());
function buildDefaultSettingsState() {
@@ -67,7 +67,7 @@
},
flows: {
openai: {
integrationTargetId: defaultOpenAiIntegrationTargetId,
integrationTargetId: defaultOpenAiTargetId,
integrationTargets: {
cpa: {
vpsUrl: '',
@@ -106,8 +106,8 @@
},
},
kiro: {
integrationTargetId: defaultKiroIntegrationTargetId,
integrationTargets: {
targetId: defaultKiroTargetId,
targets: {
'kiro-rs': {
baseUrl: defaultKiroRsUrl,
apiKey: '',
@@ -117,7 +117,7 @@
stepExecutionRange: {
enabled: false,
fromStep: 1,
toStep: 7,
toStep: 9,
},
},
},
@@ -141,7 +141,7 @@
?? defaults.activeFlowId,
defaults.activeFlowId
);
const openaiIntegrationTargetId = normalizeIntegrationTargetId(
const openaiIntegrationTargetId = normalizeTargetId(
'openai',
nested?.flows?.openai?.integrationTargetId
?? input?.openaiIntegrationTargetId
@@ -149,13 +149,12 @@
?? defaults.flows.openai.integrationTargetId,
defaults.flows.openai.integrationTargetId
);
const kiroIntegrationTargetId = normalizeIntegrationTargetId(
const kiroTargetId = normalizeTargetId(
'kiro',
nested?.flows?.kiro?.integrationTargetId
?? input?.kiroIntegrationTargetId
?? input?.kiroSourceId
?? defaults.flows.kiro.integrationTargetId,
defaults.flows.kiro.integrationTargetId
nested?.flows?.kiro?.targetId
?? input?.kiroTargetId
?? defaults.flows.kiro.targetId,
defaults.flows.kiro.targetId
);
const stepExecutionRangeByFlow = isPlainObject(input?.stepExecutionRangeByFlow)
? input.stepExecutionRangeByFlow
@@ -313,22 +312,22 @@
},
},
kiro: {
integrationTargetId: kiroIntegrationTargetId,
integrationTargets: {
targetId: kiroTargetId,
targets: {
'kiro-rs': {
...defaults.flows.kiro.integrationTargets['kiro-rs'],
...getIntegrationTargetValue(nested, (state) => state.flows?.kiro?.integrationTargets?.['kiro-rs']),
...defaults.flows.kiro.targets['kiro-rs'],
...getIntegrationTargetValue(nested, (state) => state.flows?.kiro?.targets?.['kiro-rs']),
baseUrl: String(
input?.kiroRsUrl
?? input?.kiroRsBaseUrl
?? nested?.flows?.kiro?.integrationTargets?.['kiro-rs']?.baseUrl
?? defaults.flows.kiro.integrationTargets['kiro-rs'].baseUrl
).trim() || defaults.flows.kiro.integrationTargets['kiro-rs'].baseUrl,
?? nested?.flows?.kiro?.targets?.['kiro-rs']?.baseUrl
?? defaults.flows.kiro.targets['kiro-rs'].baseUrl
).trim() || defaults.flows.kiro.targets['kiro-rs'].baseUrl,
apiKey: String(
input?.kiroRsKey
?? input?.kiroRsApiKey
?? nested?.flows?.kiro?.integrationTargets?.['kiro-rs']?.apiKey
?? defaults.flows.kiro.integrationTargets['kiro-rs'].apiKey
?? nested?.flows?.kiro?.targets?.['kiro-rs']?.apiKey
?? defaults.flows.kiro.targets['kiro-rs'].apiKey
),
},
},
@@ -379,16 +378,21 @@
return cloneValue(normalizedState?.flows?.[normalizedFlowId] || {});
}
function getSelectedIntegrationTargetId(settingsState = {}, flowId) {
function getSelectedTargetId(settingsState = {}, flowId) {
const normalizedState = normalizeSettingsState(settingsState);
const normalizedFlowId = normalizeFlowId(flowId, normalizedState.activeFlowId);
const flowSettings = normalizedState?.flows?.[normalizedFlowId] || {};
return normalizeIntegrationTargetId(
if (normalizedFlowId === 'kiro') {
return normalizeTargetId(
normalizedFlowId,
flowSettings?.targetId,
defaultKiroTargetId
);
}
return normalizeTargetId(
normalizedFlowId,
flowSettings?.integrationTargetId,
normalizedFlowId === 'kiro'
? defaultKiroIntegrationTargetId
: defaultOpenAiIntegrationTargetId
defaultOpenAiTargetId
);
}
@@ -414,10 +418,9 @@
const openaiState = normalizedState.flows.openai;
const kiroState = normalizedState.flows.kiro;
next.activeFlowId = normalizedState.activeFlowId;
next.openaiIntegrationTargetId = getSelectedIntegrationTargetId(normalizedState, 'openai');
next.kiroIntegrationTargetId = getSelectedIntegrationTargetId(normalizedState, 'kiro');
next.openaiIntegrationTargetId = getSelectedTargetId(normalizedState, 'openai');
next.kiroTargetId = getSelectedTargetId(normalizedState, 'kiro');
next.panelMode = next.openaiIntegrationTargetId;
next.kiroSourceId = next.kiroIntegrationTargetId;
next.vpsUrl = openaiState.integrationTargets.cpa.vpsUrl;
next.vpsPassword = openaiState.integrationTargets.cpa.vpsPassword;
next.localCpaStep9Mode = openaiState.integrationTargets.cpa.localCpaStep9Mode;
@@ -440,8 +443,8 @@
next.ipProxyEnabled = normalizedState.services.proxy.enabled;
next.ipProxyService = normalizedState.services.proxy.provider;
next.ipProxyMode = normalizedState.services.proxy.mode;
next.kiroRsUrl = kiroState.integrationTargets['kiro-rs'].baseUrl;
next.kiroRsKey = kiroState.integrationTargets['kiro-rs'].apiKey;
next.kiroRsUrl = kiroState.targets['kiro-rs'].baseUrl;
next.kiroRsKey = kiroState.targets['kiro-rs'].apiKey;
next.stepExecutionRangeByFlow = buildStepExecutionRangeByFlow(normalizedState);
next.settingsSchemaVersion = normalizedState.schemaVersion;
next.settingsState = cloneValue(normalizedState);
@@ -451,18 +454,18 @@
function getFlowInputState(settingsState = {}, flowId) {
const normalizedState = normalizeSettingsState(settingsState);
const normalizedFlowId = normalizeFlowId(flowId, normalizedState.activeFlowId);
const integrationTargetId = getSelectedIntegrationTargetId(normalizedState, normalizedFlowId);
const targetId = getSelectedTargetId(normalizedState, normalizedFlowId);
if (normalizedFlowId === 'kiro') {
return {
activeFlowId: normalizedFlowId,
integrationTargetId,
kiroRsUrl: normalizedState.flows.kiro.integrationTargets['kiro-rs'].baseUrl,
kiroRsKey: normalizedState.flows.kiro.integrationTargets['kiro-rs'].apiKey,
targetId,
kiroRsUrl: normalizedState.flows.kiro.targets['kiro-rs'].baseUrl,
kiroRsKey: normalizedState.flows.kiro.targets['kiro-rs'].apiKey,
};
}
return {
activeFlowId: normalizedFlowId,
integrationTargetId,
targetId,
};
}
@@ -472,7 +475,7 @@
buildStepExecutionRangeByFlow,
getFlowInputState,
getFlowSettings,
getSelectedIntegrationTargetId,
getSelectedTargetId,
mergeSettingsState,
normalizeSettingsState,
};
+5 -3
View File
@@ -123,7 +123,8 @@
'mail-2925',
'inbucket-mail',
'plus-checkout',
'kiro-device-auth',
'kiro-register-page',
'kiro-desktop-authorize',
]);
function normalizeHostname(hostname = '') {
@@ -325,7 +326,8 @@
return candidate.hostname.endsWith('paypal.com');
case 'gopay-flow':
return /gopay|gojek/i.test(candidate.hostname);
case 'kiro-device-auth':
case 'kiro-register-page':
case 'kiro-desktop-authorize':
return isKiroAuthHost(candidate.hostname);
default:
return false;
@@ -349,7 +351,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 (isKiroAuthHost(normalizedHostname)) return 'kiro-device-auth';
if (isKiroAuthHost(normalizedHostname)) return 'kiro-register-page';
if (isSignupEntryHost(normalizedHostname)) return 'chatgpt';
return 'unknown-source';
}