aram-mayhem-dsh 0.3.1 → 0.3.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/INSTALL.zh-CN.txt +3 -2
- package/README.md +12 -10
- package/client.js +157 -13
- package/cordis.patch.yml +0 -1
- package/index.js +132 -27
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
- package/scripts/dsh_service.py +1 -1
package/INSTALL.zh-CN.txt
CHANGED
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
|
|
31
31
|
三、使用
|
|
32
32
|
--------
|
|
33
|
-
-
|
|
34
|
-
|
|
33
|
+
- 服务不会自动启动。打开「海斗助手」页面,先点右上角 **「服务 开」**;
|
|
34
|
+
不用时点 **「服务 关」**,Python 进程会立即停止。
|
|
35
|
+
- 需要桌面图标时,再点 **「桌面图标 开」**;服务关闭时图标会一并停止。
|
|
35
36
|
- 点击图标展开:英雄 / 推荐海克斯 / 出装;点「收起」、按 Esc 或点击游戏
|
|
36
37
|
会自动缩回右侧小图标。
|
|
37
38
|
- 游戏内必须使用「无边框」或「窗口化」。独占全屏会遮挡图标和 OCR。
|
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
把《英雄联盟》**海克斯大乱斗**(ARAM: Mayhem)的选人、推荐海克斯和出装数据搬进 DeepSeek Harness。
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
- **DSH
|
|
12
|
-
-
|
|
13
|
-
- **本地 Python 服务**:复用统计、LCU、OCR 模块,不依赖 Qt 的页面通过 DSH Host 的 `/aram-api`
|
|
10
|
+
- **屏幕置顶小图标**:默认不启动。先在页面点击 **「服务 开」**,再点 **「桌面图标 开」**;点击图标展开英雄、推荐海克斯和出装。窗口置顶、可拖动、记住位置。
|
|
11
|
+
- **DSH 侧边栏页面**:完整的「海斗助手」页面(选人 / 推荐海克斯 / 出装),右上角有 **「服务 开/关」** 和 **「桌面图标 开/关」** 两个独立开关。
|
|
12
|
+
- **九个 `aram_*` 工具**:让模型查询英雄胜率、海克斯推荐分、出装、当前 LCU 状态,并启动/停止服务、打开/关闭桌面图标。
|
|
13
|
+
- **本地 Python 服务**:复用统计、LCU、OCR 模块,不依赖 Qt 的页面通过 DSH Host 的 `/aram-api` 同源代理访问;桌面图标直接访问本地服务。**服务不会自动启动**,关闭后释放 Python 进程。
|
|
14
14
|
- **只读**:不读取游戏内存、不自动选人/点海克斯、不修改客户端。
|
|
15
15
|
|
|
16
16
|

|
|
@@ -36,12 +36,12 @@ python -m pip install -r requirements-dsh.txt
|
|
|
36
36
|
|
|
37
37
|
也可以直接运行 `.\install.ps1`(完整依赖),或 `.\install.ps1 -Minimal`(只装图标/页面/LCU,不装 OCR);不熟悉 PowerShell 的话双击 `install.bat` 即可。桌面图标需要 **PySide6**(已包含在依赖中)。然后在 DSH 的 **Plugins** 里用 **Add plugin** 安装本目录(或由 Agent 用 `plugin_manager install_bundle` 安装)。安装后:
|
|
38
38
|
|
|
39
|
-
1.
|
|
40
|
-
2.
|
|
41
|
-
3.
|
|
42
|
-
4. 新开会话后,模型即可使用 `aram_*`
|
|
39
|
+
1. 打开侧边栏「海斗助手」页面,点击右上角 **「服务 开」**;服务不会随插件自动启动;
|
|
40
|
+
2. 需要桌面图标时再点 **「桌面图标 开」**;点图标展开,点「收起」或按 `Esc` 缩回;
|
|
41
|
+
3. 不用时点 **「服务 关」**,Python 服务会立即停止;桌面图标也会一并关闭;
|
|
42
|
+
4. 新开会话后,模型即可使用 `aram_*` 工具;工具需要服务处于开启状态,也可以让 Agent 调用 `aram_service start`。
|
|
43
43
|
|
|
44
|
-
> 修改 `pythonPath` 可编辑 `cordis.patch.yml` 的配置。页面与服务固定使用 `127.0.0.1:8123
|
|
44
|
+
> 修改 `pythonPath` 可编辑 `cordis.patch.yml` 的配置。页面与服务固定使用 `127.0.0.1:8123`。服务未启动时工具会明确报错,不会静默拉起服务。
|
|
45
45
|
|
|
46
46
|
### 手动启动服务/图标(排查用)
|
|
47
47
|
|
|
@@ -86,6 +86,7 @@ powershell -ExecutionPolicy Bypass -File .\scripts\package_share.ps1
|
|
|
86
86
|
- 海克斯品质使用官方配色:**棱彩**为青→紫→金的虹彩渐变,**黄金**为金色,**白银**为银灰;页面和桌面图标保持一致。
|
|
87
87
|
- 游戏中如果服务是在选人结束后才启动,会通过 **Live Client Data API** 读取当前英雄,不要求重新进选人。
|
|
88
88
|
- 关闭图标或页面开关会退出进程并记住「关闭」,下次插件加载不会再自动弹出;点页面开关或调用 `aram_overlay open` 可重新打开。
|
|
89
|
+
- 关闭 **「服务」** 会终止 Python 进程,并同时关闭桌面图标;下次使用时需重新点「服务 开」。
|
|
89
90
|
- 页面右上角的 **「桌面图标 开/关」** 开关会立即启动/关闭图标,并把偏好保存到 `config/overlay_pref.json`;关闭后即使重载插件也不会自动弹出。
|
|
90
91
|
|
|
91
92
|
## 页面
|
|
@@ -119,6 +120,7 @@ powershell -ExecutionPolicy Bypass -File .\scripts\package_share.ps1
|
|
|
119
120
|
| `aram_lcu` | 当前客户端阶段、队列、我的英雄和备战席 |
|
|
120
121
|
| `aram_scan` | 对局中截图 OCR 当前海克斯卡片并评分 |
|
|
121
122
|
| `aram_refresh` | 从授权数据 URL 下载并原子替换本地缓存 |
|
|
123
|
+
| `aram_service` | 启动 / 停止 / 查询本地 Python 服务(不会自动启动) |
|
|
122
124
|
| `aram_overlay` | 打开 / 关闭 / 查询桌面置顶图标 |
|
|
123
125
|
|
|
124
126
|
工具与页面复用同一个服务方法;工具不会越过用户执行游戏操作。
|
|
@@ -145,7 +147,7 @@ python scripts/sync_data.py --accept-license
|
|
|
145
147
|
aram-mayhem-assistant/
|
|
146
148
|
├── package.json # DSH bundle manifest
|
|
147
149
|
├── cordis.patch.yml # Host 行、pythonPath、overlay
|
|
148
|
-
├── index.js # Host
|
|
150
|
+
├── index.js # Host 插件:按需启停服务、注册 aram_* 工具
|
|
149
151
|
├── client.js # DSH Web 页面 + 侧边栏入口
|
|
150
152
|
├── scripts/desktop_overlay.py # 屏幕置顶小图标 / 展开悬浮窗
|
|
151
153
|
├── scripts/dsh_service.py # 本地 HTTP 服务
|
package/client.js
CHANGED
|
@@ -8,6 +8,7 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
// Web and Electron (app://app) use the DSH same-origin relay; a plain
|
|
9
9
|
// file:// page falls back to the loopback service, which allows null origin.
|
|
10
10
|
const API = location.protocol === 'file:' ? 'http://127.0.0.1:8123' : '/aram-api'
|
|
11
|
+
const CONTROL = '/aram-control'
|
|
11
12
|
const AUTO_KEY = 'dsh.aram-mayhem.auto-scan.v1'
|
|
12
13
|
const TABS = [
|
|
13
14
|
{ id: 'champ', label: '选人' },
|
|
@@ -145,6 +146,25 @@ window.__ModuleLoader__.load({
|
|
|
145
146
|
return data
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
async function controlGet(path = '/status', timeout = 5000) {
|
|
150
|
+
const response = await fetch(`${CONTROL}${path}`, { signal: AbortSignal.timeout(timeout) })
|
|
151
|
+
const data = await response.json().catch(() => ({}))
|
|
152
|
+
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`)
|
|
153
|
+
return data
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function controlPost(path, timeout = 75000) {
|
|
157
|
+
const response = await fetch(`${CONTROL}${path}`, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
160
|
+
body: '{}',
|
|
161
|
+
signal: AbortSignal.timeout(timeout),
|
|
162
|
+
})
|
|
163
|
+
const data = await response.json().catch(() => ({}))
|
|
164
|
+
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`)
|
|
165
|
+
return data
|
|
166
|
+
}
|
|
167
|
+
|
|
148
168
|
function Chip({ children, tone = 'normal', title }) {
|
|
149
169
|
const color = tone === 'gold' ? '#B8862F' : tone === 'green' ? '#2F9E62'
|
|
150
170
|
: tone === 'red' ? '#C05050' : undefined
|
|
@@ -400,6 +420,9 @@ window.__ModuleLoader__.load({
|
|
|
400
420
|
})
|
|
401
421
|
const [scanAt, setScanAt] = useState(0)
|
|
402
422
|
const [serviceWait, setServiceWait] = useState(false)
|
|
423
|
+
const [serviceOn, setServiceOn] = useState(null)
|
|
424
|
+
const [serviceBusy, setServiceBusy] = useState(false)
|
|
425
|
+
const [serviceError, setServiceError] = useState('')
|
|
403
426
|
const [overlayOn, setOverlayOn] = useState(null)
|
|
404
427
|
const [overlayBusy, setOverlayBusy] = useState(false)
|
|
405
428
|
const [overlayError, setOverlayError] = useState('')
|
|
@@ -414,6 +437,27 @@ window.__ModuleLoader__.load({
|
|
|
414
437
|
}, [])
|
|
415
438
|
|
|
416
439
|
useEffect(() => {
|
|
440
|
+
let alive = true
|
|
441
|
+
const pull = async () => {
|
|
442
|
+
try {
|
|
443
|
+
const data = await controlGet('/status', 4000)
|
|
444
|
+
if (!alive) return
|
|
445
|
+
setServiceOn(!!data.running)
|
|
446
|
+
setServiceError(data.error || '')
|
|
447
|
+
} catch {
|
|
448
|
+
if (alive) setServiceOn(false)
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
pull()
|
|
452
|
+
const timer = setInterval(pull, 3000)
|
|
453
|
+
return () => { alive = false; clearInterval(timer) }
|
|
454
|
+
}, [])
|
|
455
|
+
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
if (!serviceOn) {
|
|
458
|
+
setOverlayOn(false)
|
|
459
|
+
return
|
|
460
|
+
}
|
|
417
461
|
let alive = true
|
|
418
462
|
const pull = async () => {
|
|
419
463
|
try {
|
|
@@ -428,9 +472,14 @@ window.__ModuleLoader__.load({
|
|
|
428
472
|
pull()
|
|
429
473
|
const timer = setInterval(pull, 8000)
|
|
430
474
|
return () => { alive = false; clearInterval(timer) }
|
|
431
|
-
}, [])
|
|
475
|
+
}, [serviceOn])
|
|
432
476
|
|
|
433
477
|
useEffect(() => {
|
|
478
|
+
if (!serviceOn) {
|
|
479
|
+
setSnap(null)
|
|
480
|
+
setLoadError('')
|
|
481
|
+
return
|
|
482
|
+
}
|
|
434
483
|
let alive = true
|
|
435
484
|
const pull = async () => {
|
|
436
485
|
try {
|
|
@@ -445,13 +494,13 @@ window.__ModuleLoader__.load({
|
|
|
445
494
|
setScanAt(data.last_scan.at)
|
|
446
495
|
}
|
|
447
496
|
} catch (error) {
|
|
448
|
-
if (alive) setLoadError(`${error?.message || error}
|
|
497
|
+
if (alive) setLoadError(`${error?.message || error}(服务已启动,但请求失败)`)
|
|
449
498
|
}
|
|
450
499
|
}
|
|
451
500
|
pull()
|
|
452
501
|
const timer = setInterval(pull, 2000)
|
|
453
502
|
return () => { alive = false; clearInterval(timer) }
|
|
454
|
-
}, [])
|
|
503
|
+
}, [serviceOn])
|
|
455
504
|
|
|
456
505
|
const myId = snap?.champ_select?.my_champion_id || 0
|
|
457
506
|
useEffect(() => {
|
|
@@ -559,8 +608,45 @@ window.__ModuleLoader__.load({
|
|
|
559
608
|
}
|
|
560
609
|
}
|
|
561
610
|
|
|
611
|
+
const toggleService = async () => {
|
|
612
|
+
if (serviceBusy || serviceOn === null) return
|
|
613
|
+
const turningOff = !!serviceOn
|
|
614
|
+
setServiceBusy(true)
|
|
615
|
+
setServiceError('')
|
|
616
|
+
try {
|
|
617
|
+
const data = turningOff
|
|
618
|
+
? await controlPost('/stop', 15000)
|
|
619
|
+
: await controlPost('/start', 75000)
|
|
620
|
+
if (turningOff) {
|
|
621
|
+
setServiceOn(false)
|
|
622
|
+
setSnap(null)
|
|
623
|
+
setOverlayOn(false)
|
|
624
|
+
setDetected([])
|
|
625
|
+
setEvals([])
|
|
626
|
+
setScanError('')
|
|
627
|
+
if (data.running) throw new Error(data.error || '服务关闭失败')
|
|
628
|
+
} else if (data.running || data.starting) {
|
|
629
|
+
setServiceOn(true)
|
|
630
|
+
} else {
|
|
631
|
+
throw new Error(data.error || '服务启动失败')
|
|
632
|
+
}
|
|
633
|
+
} catch (error) {
|
|
634
|
+
setServiceError(String(error?.message || error))
|
|
635
|
+
try {
|
|
636
|
+
const status = await controlGet('/status', 4000)
|
|
637
|
+
setServiceOn(!!status.running)
|
|
638
|
+
} catch { /* keep previous state */ }
|
|
639
|
+
} finally {
|
|
640
|
+
setServiceBusy(false)
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
562
644
|
const toggleOverlay = async () => {
|
|
563
|
-
if (overlayBusy
|
|
645
|
+
if (overlayBusy) return
|
|
646
|
+
if (!serviceOn) {
|
|
647
|
+
setOverlayError('请先启动本地服务,再打开桌面图标')
|
|
648
|
+
return
|
|
649
|
+
}
|
|
564
650
|
const turningOff = !!overlayOn
|
|
565
651
|
setOverlayBusy(true)
|
|
566
652
|
setOverlayError('')
|
|
@@ -598,18 +684,74 @@ window.__ModuleLoader__.load({
|
|
|
598
684
|
Lobby: '大厅', None: '空闲', Disconnected: '未连接', EndOfGame: '对局结束',
|
|
599
685
|
}[phase] || phase
|
|
600
686
|
|
|
687
|
+
const serviceSwitch = h('button', {
|
|
688
|
+
type: 'button',
|
|
689
|
+
role: 'switch',
|
|
690
|
+
'aria-checked': !!serviceOn,
|
|
691
|
+
'aria-label': '启动或关闭本地服务',
|
|
692
|
+
title: '启动/关闭本地 Python 服务(不会自动启动)',
|
|
693
|
+
disabled: serviceBusy || serviceOn === null,
|
|
694
|
+
onClick: toggleService,
|
|
695
|
+
style: {
|
|
696
|
+
...S.chip,
|
|
697
|
+
fontFamily: 'inherit', fontSize: 11.5,
|
|
698
|
+
cursor: serviceBusy || serviceOn === null ? 'wait' : 'pointer',
|
|
699
|
+
background: serviceOn ? 'rgba(47,158,98,.12)' : 'transparent',
|
|
700
|
+
borderColor: serviceOn ? '#2F9E62' : 'var(--dsw-alias-border-l2, rgba(128,128,128,.3))',
|
|
701
|
+
opacity: serviceOn === null ? .6 : 1,
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
h('span', {
|
|
705
|
+
style: {
|
|
706
|
+
width: 7, height: 7, borderRadius: '50%',
|
|
707
|
+
background: serviceOn ? '#2F9E62' : '#8A8A8A',
|
|
708
|
+
},
|
|
709
|
+
}),
|
|
710
|
+
`服务 ${serviceBusy ? '…' : serviceOn === null ? '…' : serviceOn ? '开' : '关'}`)
|
|
711
|
+
|
|
712
|
+
if (serviceOn === false) {
|
|
713
|
+
return h('div', { style: S.page },
|
|
714
|
+
h('div', { style: S.header },
|
|
715
|
+
h('div', null,
|
|
716
|
+
h('h1', { style: S.title }, '海斗助手'),
|
|
717
|
+
h('div', { style: S.sub }, 'ARAM: Mayhem · 按需启动')),
|
|
718
|
+
serviceSwitch),
|
|
719
|
+
h('div', { style: S.card, padding: 18 },
|
|
720
|
+
h('div', { style: { fontWeight: 650, fontSize: 16, marginBottom: 6 } }, '本地服务未启动'),
|
|
721
|
+
h('div', { style: S.muted }, '服务不会随插件自动启动,也不会一直占用后台。点击「启动服务」后才加载英雄、海克斯、出装和 LCU 数据;不用时请关闭服务。'),
|
|
722
|
+
h('div', { style: { ...S.row, gap: 8, marginTop: 12, flexWrap: 'wrap' } },
|
|
723
|
+
h('button', {
|
|
724
|
+
type: 'button',
|
|
725
|
+
style: { ...S.primary, opacity: serviceBusy ? .55 : 1 },
|
|
726
|
+
disabled: serviceBusy,
|
|
727
|
+
onClick: toggleService,
|
|
728
|
+
}, serviceBusy ? '启动中…' : '启动服务')),
|
|
729
|
+
serviceError ? h('div', { style: { ...S.error, marginTop: 10 } }, serviceError) : null,
|
|
730
|
+
h('div', { style: { ...S.muted, marginTop: 10 } },
|
|
731
|
+
'启动后仍可在右上角关闭;桌面图标需要单独打开,服务关闭时会一并停止。')),
|
|
732
|
+
h('div', { style: S.muted },
|
|
733
|
+
'数据依赖本地 Python 服务(127.0.0.1:8123)。'))
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (!snap && serviceOn === null) {
|
|
737
|
+
return h('div', { style: { ...S.page, justifyContent: 'center', alignItems: 'center', opacity: .75 }, role: 'status' },
|
|
738
|
+
'正在检测本地服务…')
|
|
739
|
+
}
|
|
740
|
+
|
|
601
741
|
if (!snap && loadError) {
|
|
602
742
|
if (!serviceWait) {
|
|
603
743
|
return h('div', { style: { ...S.page, justifyContent: 'center', alignItems: 'center', opacity: .7 }, role: 'status' },
|
|
604
|
-
'
|
|
744
|
+
'服务已启动,正在连接数据…')
|
|
605
745
|
}
|
|
606
746
|
return h('div', { style: S.page },
|
|
607
|
-
h('div', { style: S.header },
|
|
747
|
+
h('div', { style: S.header },
|
|
748
|
+
h('div', null, h('h1', { style: S.title }, '海斗助手'), h('div', { style: S.sub }, 'ARAM: Mayhem · 服务已启动但数据不可用')),
|
|
749
|
+
serviceSwitch),
|
|
608
750
|
h('div', { style: S.error, role: 'alert' },
|
|
609
|
-
h('div', { style: { fontWeight: 650, marginBottom: 4 } }, '
|
|
751
|
+
h('div', { style: { fontWeight: 650, marginBottom: 4 } }, '本地服务已启动,但数据请求失败'),
|
|
610
752
|
h('div', null, loadError),
|
|
611
|
-
h('div', { style: { ...S.muted, marginTop: 6 } }, '
|
|
612
|
-
h('button', { style: { ...S.btn, marginTop: 8 }, onClick:
|
|
753
|
+
h('div', { style: { ...S.muted, marginTop: 6 } }, '可以先关闭服务,再重新启动;也可以检查 Python 日志 logs\\dsh-service.log。'),
|
|
754
|
+
h('button', { style: { ...S.btn, marginTop: 8 }, onClick: toggleService }, '关闭服务')),
|
|
613
755
|
h('div', { style: { ...S.card, padding: 16, marginTop: 8 } },
|
|
614
756
|
h('div', { style: { fontWeight: 650, marginBottom: 6 } }, '仍无法启动时'),
|
|
615
757
|
h('div', { style: S.muted }, '在插件目录运行:python scripts/dsh_service.py --port 8123 --root .'),
|
|
@@ -629,21 +771,22 @@ window.__ModuleLoader__.load({
|
|
|
629
771
|
h(Chip, { tone: lcu.connected ? 'green' : 'normal', title: lcu.error || undefined },
|
|
630
772
|
`LCU ${lcu.connected ? '已连接' : '未连接'}`),
|
|
631
773
|
h(Chip, null, phaseLabel),
|
|
774
|
+
serviceSwitch,
|
|
632
775
|
h('button', {
|
|
633
776
|
type: 'button',
|
|
634
777
|
role: 'switch',
|
|
635
778
|
'aria-checked': !!overlayOn,
|
|
636
779
|
'aria-label': '显示屏幕置顶桌面图标',
|
|
637
|
-
title: '显示或隐藏屏幕置顶的海斗助手图标',
|
|
638
|
-
disabled: overlayBusy || overlayOn === null,
|
|
780
|
+
title: serviceOn ? '显示或隐藏屏幕置顶的海斗助手图标' : '请先启动本地服务',
|
|
781
|
+
disabled: overlayBusy || overlayOn === null || !serviceOn,
|
|
639
782
|
onClick: toggleOverlay,
|
|
640
783
|
style: {
|
|
641
784
|
...S.chip,
|
|
642
785
|
fontFamily: 'inherit', fontSize: 11.5,
|
|
643
|
-
cursor: overlayBusy || overlayOn === null ? '
|
|
786
|
+
cursor: overlayBusy || overlayOn === null || !serviceOn ? 'not-allowed' : 'pointer',
|
|
644
787
|
background: overlayOn ? 'rgba(47,158,98,.12)' : 'transparent',
|
|
645
788
|
borderColor: overlayOn ? '#2F9E62' : 'var(--dsw-alias-border-l2, rgba(128,128,128,.3))',
|
|
646
|
-
opacity: overlayOn === null ? .6 : 1,
|
|
789
|
+
opacity: overlayOn === null || !serviceOn ? .6 : 1,
|
|
647
790
|
},
|
|
648
791
|
},
|
|
649
792
|
h('span', {
|
|
@@ -666,6 +809,7 @@ window.__ModuleLoader__.load({
|
|
|
666
809
|
h('button', { style: S.btn, onClick: doSearch, disabled: searchBusy }, searchBusy ? '…' : '查询'))),
|
|
667
810
|
|
|
668
811
|
loadError ? h('div', { style: S.error, role: 'alert', 'aria-live': 'polite' }, `服务暂时不可用:${loadError}`) : null,
|
|
812
|
+
serviceError ? h('div', { style: S.error, role: 'alert', 'aria-live': 'polite' }, `本地服务:${serviceError}`) : null,
|
|
669
813
|
overlayError ? h('div', { style: S.error, role: 'alert', 'aria-live': 'polite' }, `桌面图标:${overlayError}`) : null,
|
|
670
814
|
!lcu.connected && lcu.error
|
|
671
815
|
? h('div', { style: { ...S.muted, flexShrink: 0 } }, `LCU:${lcu.error}。仍可搜索英雄;进入对局后可手动扫描。`)
|
package/cordis.patch.yml
CHANGED
package/index.js
CHANGED
|
@@ -16,7 +16,6 @@ const DEFAULTS = {
|
|
|
16
16
|
pythonPath: 'python',
|
|
17
17
|
host: '127.0.0.1',
|
|
18
18
|
port: 8123,
|
|
19
|
-
overlay: true,
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
@@ -106,9 +105,25 @@ export function apply(ctx, config = {}) {
|
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
async function
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
async function serviceInfo() {
|
|
109
|
+
try {
|
|
110
|
+
const response = await fetch(`${base}/health`, { signal: AbortSignal.timeout(1200) })
|
|
111
|
+
if (!response.ok) return { ok: true, running: false, starting: !!starting }
|
|
112
|
+
const data = await response.json().catch(() => null)
|
|
113
|
+
if (data?.service !== 'aram-mayhem-dsh') return { ok: true, running: false, starting: !!starting }
|
|
114
|
+
return { ok: true, running: true, pid: data.pid, version: data.version, starting: false }
|
|
115
|
+
} catch {
|
|
116
|
+
return { ok: true, running: false, starting: !!starting }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function startService() {
|
|
121
|
+
const current = await serviceInfo()
|
|
122
|
+
if (current.running) return current
|
|
123
|
+
if (starting) {
|
|
124
|
+
try { await starting } catch { /* propagate below via status */ }
|
|
125
|
+
return serviceInfo()
|
|
126
|
+
}
|
|
112
127
|
starting = (async () => {
|
|
113
128
|
if (!existsSync(serviceScript)) throw new Error(`本地服务脚本不存在:${serviceScript}`)
|
|
114
129
|
if (!child) {
|
|
@@ -133,14 +148,48 @@ export function apply(ctx, config = {}) {
|
|
|
133
148
|
)
|
|
134
149
|
})()
|
|
135
150
|
try {
|
|
136
|
-
|
|
151
|
+
await starting
|
|
137
152
|
} finally {
|
|
138
153
|
starting = null
|
|
139
154
|
}
|
|
155
|
+
return serviceInfo()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function stopService() {
|
|
159
|
+
if (starting) {
|
|
160
|
+
try { await starting } catch { /* start failed */ }
|
|
161
|
+
}
|
|
162
|
+
// The icon is a separate process; close it before stopping its API.
|
|
163
|
+
try {
|
|
164
|
+
await fetch(`${base}/overlay/stop`, {
|
|
165
|
+
method: 'POST',
|
|
166
|
+
headers: { 'Content-Type': 'application/json' },
|
|
167
|
+
body: '{}',
|
|
168
|
+
signal: AbortSignal.timeout(1500),
|
|
169
|
+
})
|
|
170
|
+
} catch { /* service or icon not running */ }
|
|
171
|
+
const current = await serviceInfo()
|
|
172
|
+
if (!current.running) {
|
|
173
|
+
child = null
|
|
174
|
+
return current
|
|
175
|
+
}
|
|
176
|
+
const pid = child?.pid || current.pid
|
|
177
|
+
if (pid) {
|
|
178
|
+
try { process.kill(pid) } catch { /* already gone */ }
|
|
179
|
+
}
|
|
180
|
+
const deadline = Date.now() + 5000
|
|
181
|
+
while (Date.now() < deadline) {
|
|
182
|
+
await new Promise(resolve => setTimeout(resolve, 250))
|
|
183
|
+
if (!(await alive())) break
|
|
184
|
+
}
|
|
185
|
+
child = null
|
|
186
|
+
return serviceInfo()
|
|
140
187
|
}
|
|
141
188
|
|
|
142
189
|
async function request(path, options = {}) {
|
|
143
|
-
await
|
|
190
|
+
if (!(await alive())) {
|
|
191
|
+
throw new Error('海斗助手服务未启动。请打开「海斗助手」页面,点击「服务 开」启动,或调用 aram_service start。')
|
|
192
|
+
}
|
|
144
193
|
const response = await fetch(`${base}${path}`, {
|
|
145
194
|
...options,
|
|
146
195
|
signal: options.signal || AbortSignal.timeout(180_000),
|
|
@@ -158,7 +207,16 @@ export function apply(ctx, config = {}) {
|
|
|
158
207
|
*/
|
|
159
208
|
async function proxy(req, res) {
|
|
160
209
|
try {
|
|
161
|
-
await
|
|
210
|
+
if (!(await alive())) {
|
|
211
|
+
res.statusCode = 503
|
|
212
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
213
|
+
res.setHeader('Cache-Control', 'no-store')
|
|
214
|
+
res.end(JSON.stringify({
|
|
215
|
+
ok: false,
|
|
216
|
+
error: '海斗助手服务未启动。请打开插件页面,点击「服务 开」。',
|
|
217
|
+
}))
|
|
218
|
+
return
|
|
219
|
+
}
|
|
162
220
|
const chunks = []
|
|
163
221
|
for await (const chunk of req) chunks.push(chunk)
|
|
164
222
|
const body = chunks.length ? Buffer.concat(chunks) : undefined
|
|
@@ -186,6 +244,33 @@ export function apply(ctx, config = {}) {
|
|
|
186
244
|
}
|
|
187
245
|
}
|
|
188
246
|
|
|
247
|
+
/** Start/stop/status control plane for the Python service (no auto-start). */
|
|
248
|
+
async function control(req, res) {
|
|
249
|
+
const path = (req.url || '/').replace(/^\/aram-control/, '') || '/status'
|
|
250
|
+
const send = (status, payload) => {
|
|
251
|
+
res.statusCode = status
|
|
252
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
253
|
+
res.setHeader('Cache-Control', 'no-store')
|
|
254
|
+
res.end(JSON.stringify(payload))
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
if (req.method === 'GET' && path === '/status') {
|
|
258
|
+
return send(200, await serviceInfo())
|
|
259
|
+
}
|
|
260
|
+
if (req.method === 'POST' && path === '/start') {
|
|
261
|
+
await startService()
|
|
262
|
+
return send(200, await serviceInfo())
|
|
263
|
+
}
|
|
264
|
+
if (req.method === 'POST' && path === '/stop') {
|
|
265
|
+
await stopService()
|
|
266
|
+
return send(200, await serviceInfo())
|
|
267
|
+
}
|
|
268
|
+
return send(404, { ok: false, error: 'not found' })
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return send(500, { ok: false, running: false, error: String(error?.message || error) })
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
189
274
|
const get = path => request(path)
|
|
190
275
|
const post = (path, body) => request(path, {
|
|
191
276
|
method: 'POST',
|
|
@@ -362,6 +447,30 @@ export function apply(ctx, config = {}) {
|
|
|
362
447
|
},
|
|
363
448
|
}
|
|
364
449
|
|
|
450
|
+
definitions.aram_service = {
|
|
451
|
+
name: 'aram_service',
|
|
452
|
+
description: 'Start, stop or inspect the local ARAM: Mayhem Python service. The service does not auto-start; '
|
|
453
|
+
+ 'all data tools require it to be running.',
|
|
454
|
+
parameters: objectSchema({
|
|
455
|
+
action: {
|
|
456
|
+
type: 'string',
|
|
457
|
+
enum: ['start', 'stop', 'status'],
|
|
458
|
+
description: 'start launches the local service; stop terminates it; status only reports whether it is running.',
|
|
459
|
+
},
|
|
460
|
+
}, []),
|
|
461
|
+
output: { schema: { type: 'string' }, render: (_args, value) => asText(value) },
|
|
462
|
+
execute: async args => {
|
|
463
|
+
const action = String(args?.action || 'status')
|
|
464
|
+
if (action === 'start') await startService()
|
|
465
|
+
if (action === 'stop') await stopService()
|
|
466
|
+
const info = await serviceInfo()
|
|
467
|
+
if (info.running) {
|
|
468
|
+
return `海斗助手服务正在运行(PID ${info.pid}${info.version ? `,v${info.version}` : ''})。`
|
|
469
|
+
}
|
|
470
|
+
return info.starting ? '海斗助手服务正在启动…' : '海斗助手服务未运行。'
|
|
471
|
+
},
|
|
472
|
+
}
|
|
473
|
+
|
|
365
474
|
definitions.aram_overlay = {
|
|
366
475
|
name: 'aram_overlay',
|
|
367
476
|
description: 'Open, close or inspect the always-on-top desktop icon for the ARAM: Mayhem assistant. '
|
|
@@ -376,6 +485,7 @@ export function apply(ctx, config = {}) {
|
|
|
376
485
|
output: { schema: { type: 'string' }, render: (_args, value) => asText(value) },
|
|
377
486
|
execute: async args => {
|
|
378
487
|
const action = String(args?.action || 'open')
|
|
488
|
+
if (!(await alive())) return '海斗助手服务未启动;请让用户先在页面点击「服务 开」,或调用 aram_service start。'
|
|
379
489
|
if (action === 'status') {
|
|
380
490
|
const data = await get('/overlay/status')
|
|
381
491
|
return data.running
|
|
@@ -404,36 +514,31 @@ export function apply(ctx, config = {}) {
|
|
|
404
514
|
'aram-mayhem: local service proxy',
|
|
405
515
|
)
|
|
406
516
|
|
|
517
|
+
ctx.effect(
|
|
518
|
+
() => ctx.webServer.register({
|
|
519
|
+
kind: 'prefix',
|
|
520
|
+
path: '/aram-control',
|
|
521
|
+
handler: control,
|
|
522
|
+
}),
|
|
523
|
+
'aram-mayhem: service control',
|
|
524
|
+
)
|
|
525
|
+
|
|
407
526
|
ctx.systemPrompt.section({
|
|
408
527
|
name: 'aram-mayhem',
|
|
409
528
|
order: 210,
|
|
410
529
|
text: 'When the user asks about League of Legends ARAM: Mayhem (海克斯大乱斗) champions, augment choices, '
|
|
411
530
|
+ 'win rates, builds or the current client state, use the aram_status / aram_champion / aram_augment_rank / '
|
|
412
|
-
+ 'aram_build / aram_lcu tools instead of guessing.
|
|
531
|
+
+ 'aram_build / aram_lcu tools instead of guessing. The local service does not auto-start; use aram_service '
|
|
532
|
+
+ 'to start/stop it when needed. '
|
|
533
|
+
+ 'Use aram_scan only when a game is running and the user '
|
|
413
534
|
+ 'asks about the cards currently on screen. State the patch and that the data is a partial sample; '
|
|
414
535
|
+ 'when giving statistics, mention the source and its CC BY-NC 4.0 non-commercial license. '
|
|
415
536
|
+ 'Never present correlation as causation. The plugin is read-only and must not automate picks or gameplay.',
|
|
416
537
|
})
|
|
417
538
|
|
|
418
|
-
//
|
|
419
|
-
|
|
420
|
-
.then(() => {
|
|
421
|
-
if (cfg.overlay !== false) return post('/overlay/start', {})
|
|
422
|
-
return null
|
|
423
|
-
})
|
|
424
|
-
.catch(error => {
|
|
425
|
-
console.warn('[aram-mayhem] local service or overlay start failed:', error?.message || error)
|
|
426
|
-
})
|
|
427
|
-
|
|
539
|
+
// Intentionally no auto-start: the service and icon are started from the
|
|
540
|
+
// page switches, the aram_service tool, or aram_overlay open.
|
|
428
541
|
ctx.effect(() => () => {
|
|
429
|
-
|
|
430
|
-
// plugin is disabled/unloaded, then release the managed service child.
|
|
431
|
-
try {
|
|
432
|
-
void fetch(`${base}/overlay/stop`, { method: 'POST', signal: AbortSignal.timeout(1500) }).catch(() => {})
|
|
433
|
-
} catch { /* ignore */ }
|
|
434
|
-
if (child) {
|
|
435
|
-
try { child.kill() } catch { /* already gone */ }
|
|
436
|
-
child = null
|
|
437
|
-
}
|
|
542
|
+
void stopService().catch(() => {})
|
|
438
543
|
})
|
|
439
544
|
}
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "ARAM: Mayhem assistant",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "On-demand ARAM: Mayhem companion for DSH. Start the local service from the page, then open the screen-top icon for champions, recommended augments and builds; includes nine aram_* tools. Install the Python dependencies in requirements-dsh.txt first.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "海斗助手",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "按需启动的《英雄联盟》海克斯大乱斗 DSH 助手:页面开关启动/停止本地服务,再打开屏幕置顶图标查看英雄、推荐海克斯和出装;同时提供九个 aram_* 工具。首次使用需安装 requirements-dsh.txt 中的 Python 依赖。",
|
|
5
5
|
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aram-mayhem-dsh",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ARAM: Mayhem companion for DSH: a screen-top desktop icon plus a sidebar page with local LCU state, champion/augment statistics, builds and screen OCR, with eight agent tools.",
|
|
6
6
|
"license": "MIT",
|
package/scripts/dsh_service.py
CHANGED
|
@@ -65,7 +65,7 @@ from src.lcu.listener import parse_champ_select, parse_queue_info
|
|
|
65
65
|
log = logging.getLogger("aram-dsh-service")
|
|
66
66
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
67
67
|
|
|
68
|
-
VERSION = "0.3.
|
|
68
|
+
VERSION = "0.3.2"
|
|
69
69
|
IN_GAME_PHASES = {"InProgress", "Reconnect"}
|
|
70
70
|
|
|
71
71
|
|