dsh-session-superagent 0.8.30 → 0.8.32
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 +40 -0
- package/README.md +1 -1
- package/client.js +24 -2
- package/lib/index.js +31 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## [0.8.32] - 2026-11-02 —— 热重载后整组换前缀,面板自己找得到
|
|
6
|
+
|
|
7
|
+
### 背景(真机实测)
|
|
8
|
+
宿主重载后,旧实例注册的 handler **摘不掉**(`webServer.register` 没有可靠的注销,属于宿主路由表行为)。
|
|
9
|
+
结果:新实例注册 6 条全部撞车(`duplicate exact route`),HTTP 面永远是旧代码,
|
|
10
|
+
从面板加的 watcher 一跑就报 `cannot get required service "agents" in inactive context`。
|
|
11
|
+
唯一的解法以前是**整进程重启**。
|
|
12
|
+
|
|
13
|
+
### 改法
|
|
14
|
+
1. **服务端**:注册时如果出现重复,就换一个带序号的前缀(`/session-superagent/r2`、`/r3`…)
|
|
15
|
+
把 6 条**整组重放**,并在 `state.server.base` 与 `GET /state` 的 `routeBase` 里公布当前前缀。
|
|
16
|
+
2. **客户端**:面板首次加载时依次探 `/session-superagent`、`/r2`…`/r8`,
|
|
17
|
+
认「`routeBase` 与请求前缀一致」的那个并切换 —— 老版本没有这个字段,行为不变。
|
|
18
|
+
|
|
19
|
+
这样热重载之后面板会自动用上新代码,不用再重启进程。
|
|
20
|
+
|
|
21
|
+
### 测试
|
|
22
|
+
- 路由层用例改成断言「撞车后整组 6 条换到 `/r2` 重放、`state.server.failed` 清零、前缀被记下」。
|
|
23
|
+
- 合计 **93 例**。
|
|
24
|
+
|
|
25
|
+
## [0.8.31] - 2026-11-02 —— 上下文已释放时,别再默默造一条死守
|
|
26
|
+
|
|
27
|
+
0.8.30 之后真机仍在报 `inactive context`(`server.at` 已经更新到 20:08,说明新实例挂上了),
|
|
28
|
+
结论是:**宿主重载后旧实例的 handler 仍然在吃 HTTP 请求**,而那条路径跑在已 dispose 的 ctx 里。
|
|
29
|
+
插件侧摘不掉它(这正是宿主的路由表行为,不是我们能改的)。
|
|
30
|
+
|
|
31
|
+
那就换一个策略:**别再装作成功**。
|
|
32
|
+
|
|
33
|
+
### 新增
|
|
34
|
+
`POST /watch` 在创建前先检查这个实例还能不能摸到 `agents` 服务;摸不到就返回
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
503 {"ok":false,"error":"插件实例已失效(当前 handler 跑在已释放的上下文里):请重载 DSH 后再添加"}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
用户会立刻看到"要重载",而不是加了一条守、第二天发现它从没跑过。
|
|
41
|
+
|
|
42
|
+
### 测试
|
|
43
|
+
- 新增用例:ctx 读 `agents` 就抛且 `get('agents')` 也取不到时,`POST /watch` 必须返回 503 且提示重载。合计 **93 例**。
|
|
44
|
+
|
|
5
45
|
## [0.8.30] - 2026-11-02 —— 0.8.28 没修好:宿主重载是「重新 import 一份模块」
|
|
6
46
|
|
|
7
47
|
### 真机判定实验(20:00 重载后,routes 6 / failed [])
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<img src="assets/icon-180.png" width="88" height="88" alt="">
|
|
4
4
|
|
|
5
5
|
[](LICENSE)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](https://github.com/topics/dsh-plugin)
|
|
9
9
|
|
package/client.js
CHANGED
|
@@ -14,8 +14,25 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const { useCallback, useEffect, useRef, useState } = React
|
|
15
15
|
|
|
16
16
|
// 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
|
|
17
|
-
const CLIENT_VERSION = '0.8.
|
|
18
|
-
|
|
17
|
+
const CLIENT_VERSION = '0.8.32'
|
|
18
|
+
let BASE = '/session-superagent'
|
|
19
|
+
/**
|
|
20
|
+
* 服务端热重载后旧 handler 摘不掉,会整组换到 `/session-superagent/rN` 重放。
|
|
21
|
+
* 这里逐个探一遍,认「routeBase 与请求前缀一致」的那个;老版本没有这个字段,就留在默认前缀。
|
|
22
|
+
*/
|
|
23
|
+
async function discoverBase() {
|
|
24
|
+
const candidates = [BASE]
|
|
25
|
+
for (let i = 2; i <= 8; i += 1) candidates.push('/session-superagent/r' + i)
|
|
26
|
+
for (const base of candidates) {
|
|
27
|
+
try {
|
|
28
|
+
const res = await fetch(base + '/state', { headers: { accept: 'application/json' } })
|
|
29
|
+
if (!res.ok) continue
|
|
30
|
+
const body = await res.json()
|
|
31
|
+
if (body && body.routeBase === base) { BASE = base; return base }
|
|
32
|
+
} catch {}
|
|
33
|
+
}
|
|
34
|
+
return BASE
|
|
35
|
+
}
|
|
19
36
|
const ENDPOINT = BASE + '/state'
|
|
20
37
|
const POLL_MS = 5000
|
|
21
38
|
|
|
@@ -582,8 +599,13 @@ window.__ModuleLoader__.load({
|
|
|
582
599
|
useEffect(() => {
|
|
583
600
|
let alive = true
|
|
584
601
|
let timer = null
|
|
602
|
+
let discovered = false
|
|
585
603
|
const step = async () => {
|
|
586
604
|
if (!alive) return
|
|
605
|
+
if (!discovered) {
|
|
606
|
+
discovered = true
|
|
607
|
+
try { await discoverBase() } catch {}
|
|
608
|
+
}
|
|
587
609
|
const hidden = typeof document !== 'undefined' && document.hidden === true
|
|
588
610
|
const delay = hidden ? intervalMs * 6 : intervalMs
|
|
589
611
|
if (!busy.current) {
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,10 @@ const INFLIGHT_KEY = Symbol.for('dsh-session-superagent.inFlight')
|
|
|
59
59
|
const sharedTimers = (globalThis[TIMERS_KEY] ||= new Map())
|
|
60
60
|
const sharedInFlight = (globalThis[INFLIGHT_KEY] ||= new Set())
|
|
61
61
|
|
|
62
|
+
const DEFAULT_ROUTE_BASE = '/session-superagent'
|
|
63
|
+
const ROUTE_GEN_KEY = Symbol.for('dsh-session-superagent.routeGeneration')
|
|
64
|
+
/** 本实例实际使用的路由前缀(正常情况下等于默认前缀)。 */
|
|
65
|
+
let activeBase = DEFAULT_ROUTE_BASE
|
|
62
66
|
const ROUTES_KEY = Symbol.for('dsh-session-superagent.activeRoutes')
|
|
63
67
|
const activeRoutes = (globalThis[ROUTES_KEY] ||= [])
|
|
64
68
|
|
|
@@ -620,7 +624,9 @@ export function apply(ctx) {
|
|
|
620
624
|
// 面板和所有接口一起 404(2026-11-02 真机踩到 webserver: duplicate exact route)。
|
|
621
625
|
// 改成每条路由单独容错:重复的那条记下来,其余照常注册。
|
|
622
626
|
const failedRoutes = []
|
|
627
|
+
const attempted = []
|
|
623
628
|
const addRoute = (options) => {
|
|
629
|
+
attempted.push(options)
|
|
624
630
|
try {
|
|
625
631
|
const dispose = httpServer['register'](options)
|
|
626
632
|
routes.push(dispose)
|
|
@@ -680,6 +686,7 @@ export function apply(ctx) {
|
|
|
680
686
|
res.setHeader('cache-control', 'no-store')
|
|
681
687
|
res.end(JSON.stringify({
|
|
682
688
|
gh,
|
|
689
|
+
routeBase: activeBase,
|
|
683
690
|
updatedAt: new Date().toISOString(),
|
|
684
691
|
credentials: secretsSummary(),
|
|
685
692
|
sessionGoal: goalView(ctx, focusSession),
|
|
@@ -763,6 +770,15 @@ export function apply(ctx) {
|
|
|
763
770
|
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo)) return json(res, 400, { error: 'repo must be owner/name' })
|
|
764
771
|
const sessionId = String(body.sessionId || '').trim()
|
|
765
772
|
if (!sessionId) return json(res, 400, { error: 'sessionId is required (open the panel in the session that should be woken)' })
|
|
773
|
+
// 若这个实例的 ctx 已经 dispose(宿主重载后旧 handler 仍在服务请求),
|
|
774
|
+
// 建出来的 watcher 一定跑不起来(定时器一 tick 就 inactive context)。
|
|
775
|
+
// 与其静默造一条死守,不如直接拒绝并让用户重载宿主。
|
|
776
|
+
const agentsHere = agentsService(ctx)
|
|
777
|
+
const canReachSessions = agentsHere && typeof agentsHere.get === 'function'
|
|
778
|
+
if (!canReachSessions) {
|
|
779
|
+
json(res, 503, { ok: false, error: '插件实例已失效(当前 handler 跑在已释放的上下文里):请重载 DSH 后再添加' })
|
|
780
|
+
return
|
|
781
|
+
}
|
|
766
782
|
const intervalSec = Math.max(30, Math.min(3600, Number(body.intervalSec) || 60))
|
|
767
783
|
const state = readState()
|
|
768
784
|
state.watchers = state.watchers || {}
|
|
@@ -874,8 +890,22 @@ export function apply(ctx) {
|
|
|
874
890
|
},
|
|
875
891
|
})
|
|
876
892
|
|
|
893
|
+
// 热重载时旧实例的 handler 摘不掉(宿主路由表行为):默认前缀会全部撞车。
|
|
894
|
+
// 那就换一个带序号的前缀整组重放 —— 面板会自己发现新前缀(客户端 discoverBase)。
|
|
895
|
+
if (failedRoutes.length > 0) {
|
|
896
|
+
const generation = (Number(globalThis[ROUTE_GEN_KEY]) || 1) + 1
|
|
897
|
+
globalThis[ROUTE_GEN_KEY] = generation
|
|
898
|
+
const altBase = DEFAULT_ROUTE_BASE + '/r' + generation
|
|
899
|
+
const replay = attempted.map((options) => ({ ...options, path: String(options.path).replace(DEFAULT_ROUTE_BASE, altBase) }))
|
|
900
|
+
failedRoutes.length = 0
|
|
901
|
+
for (const options of replay) addRoute(options)
|
|
902
|
+
if (failedRoutes.length === 0) {
|
|
903
|
+
activeBase = altBase
|
|
904
|
+
record('route-base', altBase)
|
|
905
|
+
}
|
|
906
|
+
}
|
|
877
907
|
const state = readState()
|
|
878
|
-
state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes }
|
|
908
|
+
state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes, base: activeBase }
|
|
879
909
|
writeState(state)
|
|
880
910
|
} catch (error) {
|
|
881
911
|
const state = readState()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.32",
|
|
4
4
|
"description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|