lantern-harness 0.1.44 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +224 -0
- package/README.md +25 -8
- package/builtin/session/lh-fs.mjs +93 -4
- package/builtin/session/lh-nav-groups.mjs +3 -0
- package/builtin/session/mcp-client.mjs +7 -3
- package/builtin/session/session-runs.mjs +5 -1
- package/builtin/session/skill-validation.mjs +72 -0
- package/builtin/session/space-skills.mjs +751 -0
- package/cli/data-root.mjs +21 -4
- package/cli/lantern.mjs +26 -1
- package/cli/mcp-server.mjs +2779 -0
- package/cli/server.mjs +8 -2
- package/config/app.defaults.json +4 -2
- package/dist/500.html +9 -6
- package/dist/_astro/Base.Du_-4L-4.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js +2 -0
- package/dist/_astro/BusinessMapBoard.mRxl2G3D.js +5 -0
- package/dist/_astro/CaseExecBoard.Cqkxuf5c.js +1 -0
- package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +5 -0
- package/dist/_astro/CaseGenerateApp.acgnxl79.js +10 -0
- package/dist/_astro/CasesLibrary.zmzOQwdn.js +21 -0
- package/dist/_astro/ChatApp.Ben9LFra.js +1 -0
- package/dist/_astro/ChatApp.DBi6q7Qv.js +262 -0
- package/dist/_astro/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
- package/dist/_astro/DashboardBoard.CAJVE2G4.js +5 -0
- package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
- package/dist/_astro/DefectSubmitEntry.BzKXJ-zq.js +2 -0
- package/dist/_astro/DocsFileBrowser.apKMbGVf.js +1 -0
- package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.DMN9-Tjg.js} +1 -1
- package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
- package/dist/_astro/KnowledgeLibrary.BcoMQeUd.js +1 -0
- package/dist/_astro/LifeKrTasksBoard.DJU0-QI-.js +1 -0
- package/dist/_astro/LifeKrTodosBoard.GK7KRAO3.js +1 -0
- package/dist/_astro/LifeObjectivesBoard.DuKa6Q3k.js +1 -0
- package/dist/_astro/LifePlanTypeSelect.Cm2lUmnH.js +1 -0
- package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.BWOOVMtz.js} +3 -3
- package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.bY2l01Ha.js} +2 -2
- package/dist/_astro/LifeStagesBoard.CIzxPOJB.js +1 -0
- package/dist/_astro/LifeYearCycleSelect.BlsyPmmI.js +1 -0
- package/dist/_astro/LifeYearPlansBoard.DaA9O08j.js +1 -0
- package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
- package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
- package/dist/_astro/NavLibraries.DVR5Ua-S.js +1 -0
- package/dist/_astro/PluginsPage.B063QIlQ.js +18 -0
- package/dist/_astro/PmBugsBoard.Cu-v0Gfd.js +1 -0
- package/dist/_astro/PmIterationsBoard.CgRzkP-j.js +1 -0
- package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.DVCEh0Lm.js} +1 -1
- package/dist/_astro/PmProjectsBoard.z-bQa98r.js +1 -0
- package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +1 -0
- package/dist/_astro/PmRequirementsBoard.CyfBI0u_.js +1 -0
- package/dist/_astro/PmShared.BQVzwsiz.js +1 -0
- package/dist/_astro/ReportsPage.najSzJeT.js +1 -0
- package/dist/_astro/ReqAnalysisBoard.BQb8dHFD.js +39 -0
- package/dist/_astro/RequirementBreakdownLibrary.Cn6OV6xt.js +2 -0
- package/dist/_astro/RequirementsLibrary.CqKNFVsP.js +1 -0
- package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
- package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
- package/dist/_astro/SettingsDialog.db3BpFw0.js +1 -0
- package/dist/_astro/SlideOverDrawer.BMg2tce6.js +1 -0
- package/dist/_astro/SpaceSwitcher.DSUVAPOi.js +7 -0
- package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.72AL-8p-.js} +1 -1
- package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
- package/dist/_astro/TasksBoard.CCDhCSR7.js +1 -0
- package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +1 -0
- package/dist/_astro/TestReportsLibrary.fWiEyCRx.js +1 -0
- package/dist/_astro/TestStatsBoard.BSUBsWSu.js +1 -0
- package/dist/_astro/Toast.BydY-X7T.js +1 -0
- package/dist/_astro/TodosBoard.By5YdlUe.js +1 -0
- package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +3 -0
- package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +10 -0
- package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +12 -0
- package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +3 -0
- package/dist/_astro/app-config.Dvfzl5_N.js +1 -0
- package/dist/_astro/app-version.CNpnKIb9.js +1 -0
- package/dist/_astro/{bash-tools.D9HCzC_7.js → bash-tools.CS2w8LOb.js} +1 -1
- package/dist/_astro/business-map.BiJ85oxm.js +1 -0
- package/dist/_astro/business-map.DKwdW1VL.css +1 -0
- package/dist/_astro/case-gen-run.Cvvdv_kv.js +26 -0
- package/dist/_astro/case-prompt.CZ3vWUju.js +2 -0
- package/dist/_astro/{case-review.TdDs1WFM.js → case-review.DFWZkoR9.js} +1 -1
- package/dist/_astro/{case-template.Cd2xNbgy.js → case-template.Clb7HrDB.js} +1 -1
- package/dist/_astro/defect-submit.Dc49lFjm.css +1 -0
- package/dist/_astro/defect-workbench.CjTb4FDv.js +6 -0
- package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
- package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
- package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.O4CIma9y.js} +1 -1
- package/dist/_astro/i18n.Cp4so7KR.js +7 -0
- package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
- package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
- package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BpcAcBSI.js} +1 -1
- package/dist/_astro/plugins.Db9xoFZb.js +1 -0
- package/dist/_astro/project-docs.bB9lQ1Ki.js +1 -0
- package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
- package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
- package/dist/_astro/req-analysis.C_gARMrB.js +31 -0
- package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
- package/dist/_astro/{settings.38J2uD5M.js → settings.D02wZj3w.js} +2 -2
- package/dist/_astro/space-skills.CPucW8zt.js +1 -0
- package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.BAtG6PkW.js} +1 -1
- package/dist/_astro/story-review.DTN91Vl9.js +7 -0
- package/dist/_astro/test-points.C7ZgggQT.js +8 -0
- package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
- package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
- package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.COAKEQtZ.js} +1 -1
- package/dist/business-map/index.html +983 -0
- package/dist/case-exec/index.html +10 -7
- package/dist/{prompts → case-execution}/index.html +12 -9
- package/dist/cases/generate/index.html +9 -6
- package/dist/cases/library/index.html +10 -7
- package/dist/dashboard/index.html +10 -7
- package/dist/defect-rules/index.html +690 -0
- package/dist/defect-submit/index.html +690 -0
- package/dist/defect-submit/templates/index.html +690 -0
- package/dist/docs/changelog/index.html +265 -51
- package/dist/docs/install/index.html +44 -12
- package/dist/docs/manual/index.html +213 -75
- package/dist/knowledge/index.html +10 -7
- package/dist/life/kr-tasks/index.html +10 -7
- package/dist/life/kr-todos/index.html +10 -7
- package/dist/life/objectives/index.html +10 -7
- package/dist/life/reviews/index.html +10 -7
- package/dist/life/stages/index.html +10 -7
- package/dist/life/year-plans/index.html +10 -7
- package/dist/plugins/index.html +10 -7
- package/dist/pm/bugs/index.html +10 -7
- package/dist/pm/iterations/index.html +10 -7
- package/dist/pm/projects/detail/index.html +10 -7
- package/dist/pm/projects/index.html +10 -7
- package/dist/pm/requirements/index.html +10 -7
- package/dist/reports/index.html +10 -7
- package/dist/requirement-analysis/index.html +10 -7
- package/dist/requirement-breakdowns/index.html +983 -0
- package/dist/requirements/index.html +10 -7
- package/dist/tasks/index.html +10 -7
- package/dist/templates/index.html +10 -7
- package/dist/test-automation/index.html +10 -7
- package/dist/test-automation/projects/index.html +10 -7
- package/dist/test-reports/index.html +10 -7
- package/dist/test-stats/index.html +10 -7
- package/dist/todos/index.html +10 -7
- package/dist/workbench/index.html +9 -6
- package/docs/Codex-MCP/351/233/206/346/210/220.md +296 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/206/345/210/253/351/207/215/346/236/204/346/226/271/346/241/210.md +88 -0
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +22 -3
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +63 -17
- package/docs//346/217/222/344/273/266/344/273/223/345/272/223/344/270/216/346/212/200/350/203/275/346/225/264/345/220/210/346/226/271/346/241/210.md +187 -0
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +208 -69
- package/lh-plugins/business-map/assistant.mjs +958 -0
- package/lh-plugins/business-map/auth-paths.mjs +61 -0
- package/lh-plugins/business-map/jobs.mjs +749 -0
- package/lh-plugins/business-map/login.mjs +295 -0
- package/lh-plugins/business-map/sources.mjs +1014 -0
- package/lh-plugins/case-execution/files.mjs +777 -0
- package/lh-plugins/case-execution/service.mjs +959 -0
- package/lh-plugins/case-execution-prompt.mjs +33 -0
- package/lh-plugins/lh-business-map.mjs +2431 -0
- package/lh-plugins/lh-case-execution.mjs +304 -0
- package/lh-plugins/lh-config.mjs +13 -0
- package/lh-plugins/lh-defect-submit.mjs +989 -0
- package/lh-plugins/lh-project-docs.mjs +31 -140
- package/lh-plugins/lh-reports.mjs +29 -57
- package/lh-plugins/lh-req-analysis.mjs +32 -3
- package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
- package/lh-plugins/lh-uiauto.mjs +514 -22
- package/lh-plugins/plugin-prompts.mjs +19 -15
- package/lh-plugins/req-analysis-revision.mjs +24 -0
- package/lh-plugins/test-points-prompt.mjs +2 -3
- package/lh-plugins/uiauto-auth-setup.mjs +218 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
- package/lh-plugins/uiauto-explorer/runner.mjs +15 -2
- package/lh-plugins/uiauto-explorer/sessions.mjs +305 -17
- package/lh-plugins/uiauto-node.mjs +102 -11
- package/lh-plugins/uiauto-prompt.mjs +20 -15
- package/lh-plugins/uiauto-sso.mjs +407 -0
- package/package.json +5 -2
- package/skills/case-execution/SKILL.md +30 -0
- package/skills/lantern-defect-submit/SKILL.md +15 -0
- package/skills/lantern-workflow/SKILL.md +57 -0
- package/skills/office/SKILL.md +26 -0
- package/dist/_astro/Base.DIbzr8uT.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.CPR_CfsE.js +0 -2
- package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
- package/dist/_astro/CaseGenerateApp.CcAtVSQJ.js +0 -10
- package/dist/_astro/CasesLibrary.Ci_0hYqL.js +0 -21
- package/dist/_astro/ChatApp.DFKZOkZy.js +0 -227
- package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
- package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
- package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
- package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
- package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
- package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
- package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
- package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
- package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
- package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
- package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
- package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
- package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
- package/dist/_astro/PluginsPage.BVrMtkLi.js +0 -17
- package/dist/_astro/PluginsPage.xdbDGigE.js +0 -1
- package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
- package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
- package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
- package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
- package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
- package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
- package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
- package/dist/_astro/PromptsLibrary.B2LMGsrj.js +0 -1
- package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
- package/dist/_astro/ReqAnalysisBoard.D-KmRwQM.js +0 -39
- package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
- package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
- package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
- package/dist/_astro/SettingsDialog.C62iJkMt.js +0 -1
- package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
- package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
- package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
- package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
- package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
- package/dist/_astro/Toast.BO2NFckG.js +0 -1
- package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
- package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
- package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
- package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
- package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
- package/dist/_astro/app-config.DkyjuL-S.js +0 -1
- package/dist/_astro/app-version.3eY3FSw1.js +0 -1
- package/dist/_astro/case-gen-run.BQeK-XUw.js +0 -22
- package/dist/_astro/case-types.DlFkbZJN.js +0 -1
- package/dist/_astro/dialog.DZHZCe_T.js +0 -1
- package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
- package/dist/_astro/i18n.D_aOCHSN.js +0 -7
- package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
- package/dist/_astro/plugins.BRvXWHLe.js +0 -1
- package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
- package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
- package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
- package/dist/_astro/req-analysis.FrD6BfwK.js +0 -31
- package/dist/_astro/story-review.R8iWiFzl.js +0 -14
- package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
- package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
- package/dist/_astro/ui-auto.DMv940x4.js +0 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { loadBrowserRuntime } from './sources.mjs';
|
|
6
|
+
import {
|
|
7
|
+
businessLoginDir,
|
|
8
|
+
businessLoginStatePath,
|
|
9
|
+
hasLoginChallenge,
|
|
10
|
+
resolveBusinessLoginState,
|
|
11
|
+
} from './auth-paths.mjs';
|
|
12
|
+
import { runSsoLoginAndSave } from '../uiauto-sso.mjs';
|
|
13
|
+
|
|
14
|
+
const MODES = ['none', 'password', 'sso', 'manual'];
|
|
15
|
+
/** @type {(message: string, statusCode?: number) => never} */
|
|
16
|
+
const fail = (message, statusCode = 400) => {
|
|
17
|
+
throw Object.assign(new Error(message), { statusCode });
|
|
18
|
+
};
|
|
19
|
+
const str = (value, max = 2000) => (typeof value === 'string' ? value.trim().slice(0, max) : '');
|
|
20
|
+
function httpUrl(value, base) {
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(value, base);
|
|
23
|
+
if (['http:', 'https:'].includes(url.protocol) && !url.username && !url.password)
|
|
24
|
+
return url.href;
|
|
25
|
+
} catch {
|
|
26
|
+
/* invalid */
|
|
27
|
+
}
|
|
28
|
+
fail('请填写有效的 HTTP / HTTPS 登录地址');
|
|
29
|
+
}
|
|
30
|
+
function read(root, id) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(
|
|
33
|
+
fs.readFileSync(path.join(businessLoginDir(root, id), 'config.json'), 'utf8'),
|
|
34
|
+
);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code === 'ENOENT') return { mode: 'none', revision: '' };
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function writePrivate(file, value) {
|
|
41
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
42
|
+
const tmp = file + '.' + crypto.randomUUID() + '.tmp';
|
|
43
|
+
fs.writeFileSync(tmp, JSON.stringify(value, null, 2), { mode: 0o600 });
|
|
44
|
+
fs.renameSync(tmp, file);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createBusinessLoginService({
|
|
48
|
+
browserRuntime = loadBrowserRuntime,
|
|
49
|
+
ssoLogin = runSsoLoginAndSave,
|
|
50
|
+
} = {}) {
|
|
51
|
+
const sessions = new Map();
|
|
52
|
+
const key = (root, id) => path.resolve(businessLoginDir(root, id));
|
|
53
|
+
function status(root, system) {
|
|
54
|
+
const config = read(root, system.id);
|
|
55
|
+
const session = sessions.get(key(root, system.id));
|
|
56
|
+
const { password, ...publicConfig } = config;
|
|
57
|
+
// 公共响应只提供密码是否已配置,不回显密码或浏览器中的 token / Cookie。
|
|
58
|
+
const statePath = resolveBusinessLoginState(root, system);
|
|
59
|
+
return {
|
|
60
|
+
config: publicConfig,
|
|
61
|
+
hasPassword: Boolean(password),
|
|
62
|
+
stateReady: Boolean(statePath && fs.existsSync(statePath)),
|
|
63
|
+
status: session?.status || 'idle',
|
|
64
|
+
message: session?.message || '',
|
|
65
|
+
savedAt: config.savedAt || '',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function save(root, system, input) {
|
|
69
|
+
const previous = read(root, system.id);
|
|
70
|
+
if (input.revision !== previous.revision) fail('登录配置已变更,请重新打开后修改', 409);
|
|
71
|
+
if (sessions.has(key(root, system.id))) fail('请先完成或取消正在进行的登录', 409);
|
|
72
|
+
if (!MODES.includes(input.mode)) fail('登录方式无效');
|
|
73
|
+
const mode = input.mode;
|
|
74
|
+
const next = {
|
|
75
|
+
mode,
|
|
76
|
+
username: str(input.username, 500),
|
|
77
|
+
password:
|
|
78
|
+
input.clearPassword === true
|
|
79
|
+
? ''
|
|
80
|
+
: typeof input.password === 'string' && input.password
|
|
81
|
+
? input.password.slice(0, 8000)
|
|
82
|
+
: previous.password || '',
|
|
83
|
+
loginUrl: input.loginUrl ? httpUrl(input.loginUrl) : '',
|
|
84
|
+
endpoint: str(input.endpoint),
|
|
85
|
+
bodyTemplate:
|
|
86
|
+
str(input.bodyTemplate, 8000) || '{"username":"{{username}}","password":"{{password}}"}',
|
|
87
|
+
tokenPath: str(input.tokenPath, 300),
|
|
88
|
+
tokenStorageKey: str(input.tokenStorageKey, 300) || 'token',
|
|
89
|
+
usernameSelector: str(input.usernameSelector, 1000),
|
|
90
|
+
passwordSelector: str(input.passwordSelector, 1000),
|
|
91
|
+
submitSelector: str(input.submitSelector, 1000),
|
|
92
|
+
};
|
|
93
|
+
if (mode === 'sso' && next.endpoint) httpUrl(next.endpoint, system.entryUrl);
|
|
94
|
+
const oldComparable = Object.fromEntries(
|
|
95
|
+
Object.keys(next).map((name) => [name, previous[name]]),
|
|
96
|
+
);
|
|
97
|
+
const changed = JSON.stringify(oldComparable) !== JSON.stringify(next);
|
|
98
|
+
writePrivate(path.join(businessLoginDir(root, system.id), 'config.json'), {
|
|
99
|
+
...next,
|
|
100
|
+
revision: crypto.randomUUID(),
|
|
101
|
+
savedAt: changed ? '' : previous.savedAt || '',
|
|
102
|
+
});
|
|
103
|
+
if (changed) fs.rmSync(businessLoginStatePath(root, system.id), { force: true });
|
|
104
|
+
return status(root, system);
|
|
105
|
+
}
|
|
106
|
+
function copyConfig(root, source, target, { copyCredentials = true } = {}) {
|
|
107
|
+
const config = read(root, source.id);
|
|
108
|
+
if (!config.revision) return status(root, target);
|
|
109
|
+
const { savedAt: _savedAt, ...settings } = copyCredentials
|
|
110
|
+
? config
|
|
111
|
+
: { ...config, password: '' };
|
|
112
|
+
writePrivate(path.join(businessLoginDir(root, target.id), 'config.json'), {
|
|
113
|
+
...settings,
|
|
114
|
+
revision: crypto.randomUUID(),
|
|
115
|
+
savedAt: '',
|
|
116
|
+
});
|
|
117
|
+
return status(root, target);
|
|
118
|
+
}
|
|
119
|
+
async function closeSession(session) {
|
|
120
|
+
if (!session) return;
|
|
121
|
+
clearTimeout(session.timer);
|
|
122
|
+
session.abort?.abort();
|
|
123
|
+
if (sessions.get(session.key) === session) sessions.delete(session.key);
|
|
124
|
+
await session.browser?.close().catch(() => {});
|
|
125
|
+
}
|
|
126
|
+
async function complete(root, system) {
|
|
127
|
+
const session = sessions.get(key(root, system.id));
|
|
128
|
+
if (!session?.context || session.status !== 'awaiting_login') fail('没有等待完成的登录窗口');
|
|
129
|
+
const pages = session.context.pages();
|
|
130
|
+
const page = pages.at(-1);
|
|
131
|
+
if (
|
|
132
|
+
!page ||
|
|
133
|
+
new URL(page.url()).origin !== new URL(system.entryUrl).origin ||
|
|
134
|
+
(await hasLoginChallenge(page))
|
|
135
|
+
)
|
|
136
|
+
fail('请先在登录窗口完成验证码或 SSO,并进入业务系统后再保存');
|
|
137
|
+
const state = await session.context.storageState();
|
|
138
|
+
if (sessions.get(session.key) !== session) fail('登录已取消,请重新打开登录窗口');
|
|
139
|
+
writePrivate(businessLoginStatePath(root, system.id), state);
|
|
140
|
+
const config = read(root, system.id);
|
|
141
|
+
writePrivate(path.join(businessLoginDir(root, system.id), 'config.json'), {
|
|
142
|
+
...config,
|
|
143
|
+
savedAt: new Date().toISOString(),
|
|
144
|
+
});
|
|
145
|
+
await closeSession(session);
|
|
146
|
+
return { ...status(root, system), status: 'ready', message: '登录态已保存,可继续自动识别' };
|
|
147
|
+
}
|
|
148
|
+
async function start(root, system, { manual = false } = {}) {
|
|
149
|
+
if (sessions.has(key(root, system.id))) fail('已有登录操作,请先完成或取消', 409);
|
|
150
|
+
const config = read(root, system.id);
|
|
151
|
+
httpUrl(system.entryUrl);
|
|
152
|
+
if (config.mode === 'none') fail('请先选择登录方式并保存配置');
|
|
153
|
+
if (config.mode === 'sso' && !manual && !config.endpoint) fail('请先配置登录接口地址');
|
|
154
|
+
if (
|
|
155
|
+
!manual &&
|
|
156
|
+
['password', 'sso'].includes(config.mode) &&
|
|
157
|
+
(!config.username || !config.password)
|
|
158
|
+
)
|
|
159
|
+
fail('请先配置登录账号和密码');
|
|
160
|
+
const session = {
|
|
161
|
+
key: key(root, system.id),
|
|
162
|
+
status: 'opening',
|
|
163
|
+
message: '正在打开登录',
|
|
164
|
+
abort: new AbortController(),
|
|
165
|
+
};
|
|
166
|
+
sessions.set(session.key, session);
|
|
167
|
+
try {
|
|
168
|
+
if (config.mode === 'sso' && !manual) {
|
|
169
|
+
const dir = businessLoginDir(root, system.id);
|
|
170
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
171
|
+
const result = await ssoLogin({
|
|
172
|
+
dir,
|
|
173
|
+
baseURL: system.entryUrl,
|
|
174
|
+
signal: session.abort.signal,
|
|
175
|
+
envMap: {
|
|
176
|
+
ADMIN_USERNAME: config.username,
|
|
177
|
+
ADMIN_PASSWORD: config.password,
|
|
178
|
+
LOGIN_API_URL: httpUrl(config.endpoint, system.entryUrl),
|
|
179
|
+
LOGIN_API_BODY: config.bodyTemplate,
|
|
180
|
+
LOGIN_API_TOKEN_PATH: config.tokenPath,
|
|
181
|
+
LOGIN_TOKEN_STORAGE_KEY: config.tokenStorageKey,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
session.abort.signal.throwIfAborted();
|
|
185
|
+
if (!result.ok)
|
|
186
|
+
fail(
|
|
187
|
+
'接口登录失败,请检查接口地址、账号密码和 Token 提取配置;需要验证码时可改用手动登录',
|
|
188
|
+
);
|
|
189
|
+
const statePath = businessLoginStatePath(root, system.id);
|
|
190
|
+
fs.chmodSync(statePath, 0o600);
|
|
191
|
+
const latest = read(root, system.id);
|
|
192
|
+
writePrivate(path.join(dir, 'config.json'), {
|
|
193
|
+
...latest,
|
|
194
|
+
savedAt: new Date().toISOString(),
|
|
195
|
+
});
|
|
196
|
+
await closeSession(session);
|
|
197
|
+
return {
|
|
198
|
+
...status(root, system),
|
|
199
|
+
status: 'ready',
|
|
200
|
+
message: '接口登录态已保存,可继续自动识别',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const runtime = browserRuntime([
|
|
204
|
+
system.sourceDir,
|
|
205
|
+
fileURLToPath(new URL('../..', import.meta.url)),
|
|
206
|
+
process.cwd(),
|
|
207
|
+
]);
|
|
208
|
+
session.browser = await runtime.chromium.launch({ headless: false });
|
|
209
|
+
session.abort.signal.throwIfAborted();
|
|
210
|
+
session.context = await session.browser.newContext();
|
|
211
|
+
session.browser.on('disconnected', () => {
|
|
212
|
+
if (sessions.get(session.key) === session) {
|
|
213
|
+
clearTimeout(session.timer);
|
|
214
|
+
sessions.delete(session.key);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
session.timer = setTimeout(() => void closeSession(session), 15 * 60_000);
|
|
218
|
+
session.timer.unref?.();
|
|
219
|
+
const page = await session.context.newPage();
|
|
220
|
+
await page.goto(config.loginUrl || system.entryUrl, {
|
|
221
|
+
waitUntil: 'domcontentloaded',
|
|
222
|
+
timeout: 30_000,
|
|
223
|
+
});
|
|
224
|
+
session.status = 'awaiting_login';
|
|
225
|
+
session.message = '请在登录窗口完成登录或验证码,进入业务页面后点击「保存登录态」';
|
|
226
|
+
if (config.mode === 'password' && !manual) {
|
|
227
|
+
const username = page
|
|
228
|
+
.locator(
|
|
229
|
+
config.usernameSelector ||
|
|
230
|
+
'input[autocomplete="username"],input[name="username"],input[type="email"],input[type="text"]',
|
|
231
|
+
)
|
|
232
|
+
.filter({ visible: true })
|
|
233
|
+
.first();
|
|
234
|
+
const password = page
|
|
235
|
+
.locator(config.passwordSelector || 'input[type="password"]')
|
|
236
|
+
.filter({ visible: true })
|
|
237
|
+
.first();
|
|
238
|
+
await username.fill(config.username, { timeout: 5000 });
|
|
239
|
+
await password.fill(config.password, { timeout: 5000 });
|
|
240
|
+
const captcha = page.locator(
|
|
241
|
+
'input[autocomplete="one-time-code"]:visible,input[name*="captcha" i]:visible,input[placeholder*="验证码"]:visible',
|
|
242
|
+
);
|
|
243
|
+
if (!(await captcha.count())) {
|
|
244
|
+
await page
|
|
245
|
+
.locator(config.submitSelector || 'button[type="submit"],input[type="submit"]')
|
|
246
|
+
.filter({ visible: true })
|
|
247
|
+
.first()
|
|
248
|
+
.click({ timeout: 5000 });
|
|
249
|
+
await page.waitForTimeout(500);
|
|
250
|
+
if (
|
|
251
|
+
new URL(page.url()).origin === new URL(system.entryUrl).origin &&
|
|
252
|
+
!(await hasLoginChallenge(page))
|
|
253
|
+
)
|
|
254
|
+
return await complete(root, system);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return status(root, system);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
// 页面选择器失败时仍保留窗口,用户可继续手动登录;不回显可能包含凭据的异常。
|
|
260
|
+
if (!session.abort.signal.aborted && session.context && session.status === 'awaiting_login')
|
|
261
|
+
return status(root, system);
|
|
262
|
+
await closeSession(session);
|
|
263
|
+
if (error.statusCode) throw error;
|
|
264
|
+
fail('登录未完成,请检查系统入口或浏览器运行环境后重试');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
status,
|
|
269
|
+
save,
|
|
270
|
+
copyConfig,
|
|
271
|
+
start,
|
|
272
|
+
complete,
|
|
273
|
+
invalidate: async (root, system) => {
|
|
274
|
+
await closeSession(sessions.get(key(root, system.id)));
|
|
275
|
+
fs.rmSync(businessLoginStatePath(root, system.id), { force: true });
|
|
276
|
+
const config = read(root, system.id);
|
|
277
|
+
if (config.revision)
|
|
278
|
+
writePrivate(path.join(businessLoginDir(root, system.id), 'config.json'), {
|
|
279
|
+
...config,
|
|
280
|
+
savedAt: '',
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
cancel: async (root, system) => {
|
|
284
|
+
await closeSession(sessions.get(key(root, system.id)));
|
|
285
|
+
return status(root, system);
|
|
286
|
+
},
|
|
287
|
+
remove: async (root, system) => {
|
|
288
|
+
await closeSession(sessions.get(key(root, system.id)));
|
|
289
|
+
fs.rmSync(businessLoginDir(root, system.id), { recursive: true, force: true });
|
|
290
|
+
},
|
|
291
|
+
close: async () => {
|
|
292
|
+
await Promise.all([...sessions.values()].map(closeSession));
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|