dsh-session-superagent 0.8.31 → 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 +20 -0
- package/README.md +1 -1
- package/client.js +24 -2
- package/lib/index.js +22 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
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
|
+
|
|
5
25
|
## [0.8.31] - 2026-11-02 —— 上下文已释放时,别再默默造一条死守
|
|
6
26
|
|
|
7
27
|
0.8.30 之后真机仍在报 `inactive context`(`server.at` 已经更新到 20:08,说明新实例挂上了),
|
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),
|
|
@@ -883,8 +890,22 @@ export function apply(ctx) {
|
|
|
883
890
|
},
|
|
884
891
|
})
|
|
885
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
|
+
}
|
|
886
907
|
const state = readState()
|
|
887
|
-
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 }
|
|
888
909
|
writeState(state)
|
|
889
910
|
} catch (error) {
|
|
890
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",
|