dsh-session-superagent 0.8.32 → 0.8.34
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 +50 -0
- package/README.md +1 -1
- package/client.js +34 -8
- package/lib/index.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
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.34] - 2026-11-02 —— 前缀失效后自动重探,面板不会卡死
|
|
6
|
+
|
|
7
|
+
真机时间线:客户端 22:42 加载(当时活着的是 `/r2`),22:45 服务端换到 `/r3` 并**释放了 `/r2`** ——
|
|
8
|
+
于是面板手里的前缀失效,后续请求全部打空,除非手动刷新页面。
|
|
9
|
+
|
|
10
|
+
### 改法
|
|
11
|
+
`call()` 遇到「请求抛错」或「404」时,**重新探一次前缀再试一遍**(只重试一次,避免打转)。
|
|
12
|
+
|
|
13
|
+
这样每一代被接管后,面板自己就跟到新一代,不需要刷新页面。
|
|
14
|
+
|
|
15
|
+
### 测试
|
|
16
|
+
- 合计 **94 例**(该分支靠真机验证,单测的假 fetch 不会产生 404)。
|
|
17
|
+
|
|
18
|
+
## [0.8.33] - 2026-11-02 —— 客户端按版本挑「最新的那个服务端实例」
|
|
19
|
+
|
|
20
|
+
### 背景
|
|
21
|
+
0.8.32 让服务端在撞车时换前缀重放,客户端按「routeBase 与请求前缀一致」认领。真机又暴露一个新情况:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
server.base = '/session-superagent'(21:45 那次挂载没报重复、路由 6 条全成功)
|
|
25
|
+
GET /session-superagent/state -> 没有 routeBase(请求仍被旧 handler 接走)
|
|
26
|
+
POST /session-superagent/watch -> 建的 watcher 仍报 inactive context
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
也就是说「注册成功」不等于「这个实例在服务」。只看前缀匹配会挑到错的实例。
|
|
30
|
+
|
|
31
|
+
### 改法
|
|
32
|
+
- 服务端在 `/state` 里自报 `serverVersion`(`SERVER_VERSION` 常量,meta 测试守着与 package.json 同步);
|
|
33
|
+
- 客户端把所有候选前缀都探一遍,只认「`routeBase === 请求前缀`」的,然后在其中**按版本取最新**。
|
|
34
|
+
|
|
35
|
+
这样即便某个实例在默认前缀"假装成功",只要 `/rN` 上有更新的实例,面板就会用 `/rN`。
|
|
36
|
+
|
|
37
|
+
### 测试
|
|
38
|
+
- 新增守门:`SERVER_VERSION` 必须等于 `package.json` 版本。合计 **94 例**。
|
|
39
|
+
|
|
5
40
|
## [0.8.32] - 2026-11-02 —— 热重载后整组换前缀,面板自己找得到
|
|
6
41
|
|
|
7
42
|
### 背景(真机实测)
|
|
@@ -18,6 +53,21 @@
|
|
|
18
53
|
|
|
19
54
|
这样热重载之后面板会自动用上新代码,不用再重启进程。
|
|
20
55
|
|
|
56
|
+
### 真机验证(不需要重启)
|
|
57
|
+
热重载触发后立刻自证:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
state.server = {at: 21:41:12Z, routes: 6, failed: [], base: '/session-superagent/r2'}
|
|
61
|
+
GET /session-superagent/r2/state -> 200,routeBase = /session-superagent/r2
|
|
62
|
+
POST /session-superagent/r2/watch(绑定不存在的会话)
|
|
63
|
+
-> lastError = 会话已不在:请删除或重建这条主理鱼
|
|
64
|
+
-> consecutiveFailures = 1,nextAt = 22:11:46Z(30 分钟退避)
|
|
65
|
+
watch_doctor -> "OK 面板接口挂载:6 条,无失败"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
也就是说 0.8.21(agentsService)、0.8.22(异常退避)、0.8.29(挂载自检)、0.8.32(前缀接管)
|
|
69
|
+
**全部在真机生效,且没有重启进程**。
|
|
70
|
+
|
|
21
71
|
### 测试
|
|
22
72
|
- 路由层用例改成断言「撞车后整组 6 条换到 `/r2` 重放、`state.server.failed` 清零、前缀被记下」。
|
|
23
73
|
- 合计 **93 例**。
|
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,33 +14,59 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
const { useCallback, useEffect, useRef, useState } = React
|
|
15
15
|
|
|
16
16
|
// 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
|
|
17
|
-
const CLIENT_VERSION = '0.8.
|
|
17
|
+
const CLIENT_VERSION = '0.8.34'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* 挑「最新的那个服务端实例」。
|
|
21
|
+
*
|
|
22
|
+
* 宿主重载时旧 handler 摘不掉,所以可能同时存在多个前缀:默认的(旧代码)和 `/rN`(新代码)。
|
|
23
|
+
* 甚至出现过「新实例在默认前缀注册成功、但请求仍被旧 handler 接走」的情况 ——
|
|
24
|
+
* 所以不能只看「注册成功」,要按实例自报的版本 + routeBase 匹配来选。
|
|
22
25
|
*/
|
|
23
26
|
async function discoverBase() {
|
|
24
27
|
const candidates = [BASE]
|
|
25
28
|
for (let i = 2; i <= 8; i += 1) candidates.push('/session-superagent/r' + i)
|
|
29
|
+
const versionScore = (v) => {
|
|
30
|
+
const parts = String(v || '0').split('.').map((n) => Number(n) || 0)
|
|
31
|
+
return parts[0] * 1e6 + parts[1] * 1e3 + parts[2]
|
|
32
|
+
}
|
|
33
|
+
let best = null
|
|
26
34
|
for (const base of candidates) {
|
|
27
35
|
try {
|
|
28
36
|
const res = await fetch(base + '/state', { headers: { accept: 'application/json' } })
|
|
29
37
|
if (!res.ok) continue
|
|
30
38
|
const body = await res.json()
|
|
31
|
-
|
|
39
|
+
// 只有「自报前缀 = 我请求的前缀」才说明这个实例真的在这条路径上服务
|
|
40
|
+
if (!body || body.routeBase !== base) continue
|
|
41
|
+
const score = versionScore(body.serverVersion)
|
|
42
|
+
if (!best || score > best.score) best = { base, score }
|
|
32
43
|
} catch {}
|
|
33
44
|
}
|
|
45
|
+
if (best) BASE = best.base
|
|
34
46
|
return BASE
|
|
35
47
|
}
|
|
36
|
-
|
|
48
|
+
|
|
37
49
|
const POLL_MS = 5000
|
|
38
50
|
|
|
39
|
-
async function call(path, options) {
|
|
40
|
-
const
|
|
51
|
+
async function call(path, options, retried) {
|
|
52
|
+
const init = {
|
|
41
53
|
...(options || {}),
|
|
42
54
|
headers: { 'content-type': 'application/json', accept: 'application/json', ...((options && options.headers) || {}) },
|
|
43
|
-
}
|
|
55
|
+
}
|
|
56
|
+
let res
|
|
57
|
+
try {
|
|
58
|
+
res = await fetch(BASE + path, init)
|
|
59
|
+
} catch (error) {
|
|
60
|
+
// 前缀失效(这一代被新实例接管并释放了):重新探一次再试,还不行就把错抛出去
|
|
61
|
+
if (retried) throw error
|
|
62
|
+
await discoverBase()
|
|
63
|
+
return call(path, options, true)
|
|
64
|
+
}
|
|
65
|
+
// 旧前缀被释放后宿主会 404:同样重探一次
|
|
66
|
+
if (res.status === 404 && !retried) {
|
|
67
|
+
await discoverBase()
|
|
68
|
+
return call(path, options, true)
|
|
69
|
+
}
|
|
44
70
|
const text = await res.text()
|
|
45
71
|
let body = null
|
|
46
72
|
try { body = text ? JSON.parse(text) : null } catch { body = { raw: text } }
|
package/lib/index.js
CHANGED
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
} from './watch.js'
|
|
30
30
|
|
|
31
31
|
export const name = 'dsh-session-superagent'
|
|
32
|
+
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
33
|
+
export const SERVER_VERSION = '0.8.34'
|
|
32
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
33
35
|
|
|
34
36
|
const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
|
|
@@ -687,6 +689,7 @@ export function apply(ctx) {
|
|
|
687
689
|
res.end(JSON.stringify({
|
|
688
690
|
gh,
|
|
689
691
|
routeBase: activeBase,
|
|
692
|
+
serverVersion: SERVER_VERSION,
|
|
690
693
|
updatedAt: new Date().toISOString(),
|
|
691
694
|
credentials: secretsSummary(),
|
|
692
695
|
sessionGoal: goalView(ctx, focusSession),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.34",
|
|
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",
|