dsh-session-guard 4.0.2 → 4.1.5
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/LICENSE +21 -21
- package/README.de.md +375 -375
- package/README.es.md +374 -374
- package/README.fr.md +373 -373
- package/README.it.md +374 -374
- package/README.ru.md +374 -374
- package/cordis.patch.yml +10 -10
- package/dsh.plugin.json +16 -16
- package/lib/client.js +179 -37
- package/lib/client.js.map +1 -1
- package/package.json +9 -11
- package/src/bridge.js +136 -136
- package/src/client/index.ts +125 -47
- package/src/client/pause-button-text.ts +60 -60
- package/src/client/pause-button.tsx +129 -129
- package/src/client/scope-face.ts +20 -20
- package/src/client/settings-card.tsx +391 -391
- package/src/client/shell-overlay.tsx +69 -0
- package/src/client/status-badge.tsx +17 -0
- package/src/client/styles.ts +30 -30
- package/src/detect.js +27 -27
- package/src/gate.js +93 -93
- package/src/index.js +36 -1
- package/src/pause-gate.js +544 -544
- package/src/pause-store.js +101 -101
- package/src/retry.js +227 -227
- package/src/scheduler.js +42 -42
- package/src/step-gate.js +399 -399
- package/src/store.js +77 -77
- package/src/wiring.js +305 -305
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-guard",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.5",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"tag": "
|
|
5
|
+
"tag": "latest"
|
|
6
6
|
},
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "高峰自动会话门:周末模式 + 高峰自动暂停 + 官方源二维判定 + 会话级冻结 + 后端自动重试。",
|
|
@@ -51,9 +51,7 @@
|
|
|
51
51
|
"dsh": {
|
|
52
52
|
"client": {
|
|
53
53
|
"inject": [
|
|
54
|
-
"@deepseek-ai/dsh-client-locale"
|
|
55
|
-
"@deepseek-ai/dsh-client-ui-settings",
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-renderer"
|
|
54
|
+
"@deepseek-ai/dsh-client-locale"
|
|
57
55
|
],
|
|
58
56
|
"platform": "web"
|
|
59
57
|
},
|
|
@@ -68,17 +66,17 @@
|
|
|
68
66
|
},
|
|
69
67
|
"engines": {
|
|
70
68
|
"node": ">=20",
|
|
71
|
-
"dsh": "
|
|
69
|
+
"dsh": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2"
|
|
72
70
|
},
|
|
73
71
|
"dependencies": {
|
|
74
72
|
"@deepseek-ai/schemastery": "^3.18.4"
|
|
75
73
|
},
|
|
76
74
|
"peerDependencies": {
|
|
77
75
|
"@deepseek-ai/cordis": "^4.0.4",
|
|
78
|
-
"@deepseek-ai/dsh-client-locale": "
|
|
79
|
-
"@deepseek-ai/dsh-client-ui-renderer": "
|
|
80
|
-
"@deepseek-ai/dsh-client-ui-settings": "
|
|
81
|
-
"@deepseek-ai/dsh-client-ui-slots": "
|
|
76
|
+
"@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2"
|
|
82
80
|
},
|
|
83
81
|
"peerDependenciesMeta": {
|
|
84
82
|
"@deepseek-ai/cordis": {
|
|
@@ -106,4 +104,4 @@
|
|
|
106
104
|
"typescript": "^5.6.0",
|
|
107
105
|
"typescript-eslint": "^8.67.0"
|
|
108
106
|
}
|
|
109
|
-
}
|
|
107
|
+
}
|
package/src/bridge.js
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-session-guard — sessionGuard 冗余端口(D5/D6/D8)。
|
|
3
|
-
*
|
|
4
|
-
* `ctx.provide('sessionGuard', service)`:
|
|
5
|
-
* - stopNextTurn / resume:会话门(透传 taskControl,或回退锁队列)。
|
|
6
|
-
* - lockQueue / unlockQueue:显式队列锁(供 input-traffic 冻结按钮桥接,
|
|
7
|
-
* 或未来手动触发)。
|
|
8
|
-
* - state(sessionId):{ queueLocked, lockReason, taskControlAvailable, taskControl }。
|
|
9
|
-
*
|
|
10
|
-
* input-traffic(方案 A,基于 feat/absorb-auto-continue 分支改造)在冻结按钮
|
|
11
|
-
* 触发时调用 stopNextTurn;本服务不存在时 input-traffic 静默跳过(fail-open,D8)。
|
|
12
|
-
*/
|
|
13
|
-
import { idleState } from './store.js'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {object} ctx host context
|
|
17
|
-
* @param {ReturnType<import('./gate.js').createGate>} gate
|
|
18
|
-
* @param {ReturnType<import('./store.js').createStore>} store
|
|
19
|
-
* @param {ReturnType<import('./pause-gate.js').createPauseGate>} [pauseGate]
|
|
20
|
-
* @param {ReturnType<import('./step-gate.js').createStepGate>} [stepGate] step 级门控(v0.2.0)
|
|
21
|
-
*/
|
|
22
|
-
export function createBridge(ctx, gate, store, pauseGate, stepGate) {
|
|
23
|
-
function taskControlState(sessionId) {
|
|
24
|
-
let tcState = null
|
|
25
|
-
try {
|
|
26
|
-
const tc = ctx && typeof ctx.get === 'function' ? ctx.get('taskControl') : undefined
|
|
27
|
-
if (tc && typeof tc.state === 'function') {
|
|
28
|
-
const s = tc.state(sessionId)
|
|
29
|
-
tcState = {
|
|
30
|
-
status: s && s.status,
|
|
31
|
-
paused: !!(s && s.paused),
|
|
32
|
-
forced: !!(s && s.forced),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
/* 状态读取失败 → 保持 null,fail-open */
|
|
37
|
-
}
|
|
38
|
-
return tcState
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
/** 停掉 session 下一回合(会话门 / 回退锁队列)。 */
|
|
43
|
-
stopNextTurn(sessionId, opts) {
|
|
44
|
-
return gate.stopNextTurn(sessionId, opts)
|
|
45
|
-
},
|
|
46
|
-
/** 恢复。 */
|
|
47
|
-
resume(sessionId, opts) {
|
|
48
|
-
return gate.resume(sessionId, opts)
|
|
49
|
-
},
|
|
50
|
-
/** 显式锁队列(手动触发)。 */
|
|
51
|
-
lockQueue(sessionId, reason = 'manual') {
|
|
52
|
-
const next = gate.lockQueue(sessionId, reason)
|
|
53
|
-
return { ok: true, state: next }
|
|
54
|
-
},
|
|
55
|
-
/** 显式解锁队列。 */
|
|
56
|
-
unlockQueue(sessionId) {
|
|
57
|
-
const next = gate.unlockQueue(sessionId)
|
|
58
|
-
return { ok: true, state: next }
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* 手动请求 step 级暂停(「暂停会话」按钮)。
|
|
62
|
-
* 不打断当前 step:在下一次 `agent/pre-step` 边界拉门(step 1 也拦,且不受峰谷/provider 限制)。
|
|
63
|
-
* @param {string} sessionId
|
|
64
|
-
*/
|
|
65
|
-
stepPause(sessionId) {
|
|
66
|
-
if (!stepGate || typeof stepGate.requestPause !== 'function') {
|
|
67
|
-
return { requested: false, held: false, reason: 'no-step-gate' }
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
return stepGate.requestPause(sessionId)
|
|
71
|
-
} catch {
|
|
72
|
-
return { requested: false, held: false, reason: 'error' }
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* 解开 step 门(v0.2.0):放行被挂起的 step。
|
|
77
|
-
* 默认 `bypass=true`(用户手动「继续」)——本高峰窗口内不再拦该会话;
|
|
78
|
-
* 退峰/非官方切换等自动释放请用 `{ bypass: false }`。
|
|
79
|
-
* @param {string} sessionId
|
|
80
|
-
* @param {{bypass?:boolean, reason?:string}} [opts]
|
|
81
|
-
*/
|
|
82
|
-
stepResume(sessionId, opts = {}) {
|
|
83
|
-
if (!stepGate || typeof stepGate.release !== 'function') {
|
|
84
|
-
return { released: false, bypass: false, reason: 'no-step-gate' }
|
|
85
|
-
}
|
|
86
|
-
const reason = opts.reason ?? 'manual'
|
|
87
|
-
let r
|
|
88
|
-
try {
|
|
89
|
-
r = stepGate.release(sessionId, reason)
|
|
90
|
-
} catch {
|
|
91
|
-
return { released: false, bypass: false, reason }
|
|
92
|
-
}
|
|
93
|
-
const released = !!(r && r.released === true)
|
|
94
|
-
let bypassed = false
|
|
95
|
-
if (released && opts.bypass !== false && typeof stepGate.markBypass === 'function') {
|
|
96
|
-
try {
|
|
97
|
-
stepGate.markBypass(sessionId)
|
|
98
|
-
bypassed = true
|
|
99
|
-
} catch {
|
|
100
|
-
/* ignore */
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { released, bypass: bypassed, reason }
|
|
104
|
-
},
|
|
105
|
-
/** 读一会话状态。 */
|
|
106
|
-
state(sessionId) {
|
|
107
|
-
const cur = store.get(sessionId)
|
|
108
|
-
const base = cur || idleState(sessionId)
|
|
109
|
-
const pausedState = pauseGate ? (pauseGate.state(sessionId) || {}) : {}
|
|
110
|
-
let stepState = {}
|
|
111
|
-
if (stepGate && typeof stepGate.state === 'function') {
|
|
112
|
-
try {
|
|
113
|
-
stepState = stepGate.state(sessionId) || {}
|
|
114
|
-
} catch {
|
|
115
|
-
stepState = {}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
sessionId: String(sessionId),
|
|
120
|
-
queueLocked: base.queueLocked === true,
|
|
121
|
-
lockReason: base.lockReason ?? null,
|
|
122
|
-
// 自研会话门真暂停状态(脱离 task-control)。
|
|
123
|
-
paused: pausedState.paused === true,
|
|
124
|
-
pausedForced: pausedState.forced === true,
|
|
125
|
-
// step 级门控(v0.2.0):paused 保持布尔以兼容既有消费者,step 态用独立字段。
|
|
126
|
-
pausedStep: stepState.held === true,
|
|
127
|
-
stepHeldSince: stepState.since ?? null,
|
|
128
|
-
stepBypass: stepState.bypass === true,
|
|
129
|
-
stepManual: stepState.manual === true,
|
|
130
|
-
taskControlAvailable: gate.taskControlAvailable(),
|
|
131
|
-
taskControl: taskControlState(sessionId),
|
|
132
|
-
updatedAt: base.updatedAt ?? null,
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
}
|
|
136
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* dsh-session-guard — sessionGuard 冗余端口(D5/D6/D8)。
|
|
3
|
+
*
|
|
4
|
+
* `ctx.provide('sessionGuard', service)`:
|
|
5
|
+
* - stopNextTurn / resume:会话门(透传 taskControl,或回退锁队列)。
|
|
6
|
+
* - lockQueue / unlockQueue:显式队列锁(供 input-traffic 冻结按钮桥接,
|
|
7
|
+
* 或未来手动触发)。
|
|
8
|
+
* - state(sessionId):{ queueLocked, lockReason, taskControlAvailable, taskControl }。
|
|
9
|
+
*
|
|
10
|
+
* input-traffic(方案 A,基于 feat/absorb-auto-continue 分支改造)在冻结按钮
|
|
11
|
+
* 触发时调用 stopNextTurn;本服务不存在时 input-traffic 静默跳过(fail-open,D8)。
|
|
12
|
+
*/
|
|
13
|
+
import { idleState } from './store.js'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {object} ctx host context
|
|
17
|
+
* @param {ReturnType<import('./gate.js').createGate>} gate
|
|
18
|
+
* @param {ReturnType<import('./store.js').createStore>} store
|
|
19
|
+
* @param {ReturnType<import('./pause-gate.js').createPauseGate>} [pauseGate]
|
|
20
|
+
* @param {ReturnType<import('./step-gate.js').createStepGate>} [stepGate] step 级门控(v0.2.0)
|
|
21
|
+
*/
|
|
22
|
+
export function createBridge(ctx, gate, store, pauseGate, stepGate) {
|
|
23
|
+
function taskControlState(sessionId) {
|
|
24
|
+
let tcState = null
|
|
25
|
+
try {
|
|
26
|
+
const tc = ctx && typeof ctx.get === 'function' ? ctx.get('taskControl') : undefined
|
|
27
|
+
if (tc && typeof tc.state === 'function') {
|
|
28
|
+
const s = tc.state(sessionId)
|
|
29
|
+
tcState = {
|
|
30
|
+
status: s && s.status,
|
|
31
|
+
paused: !!(s && s.paused),
|
|
32
|
+
forced: !!(s && s.forced),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
/* 状态读取失败 → 保持 null,fail-open */
|
|
37
|
+
}
|
|
38
|
+
return tcState
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
/** 停掉 session 下一回合(会话门 / 回退锁队列)。 */
|
|
43
|
+
stopNextTurn(sessionId, opts) {
|
|
44
|
+
return gate.stopNextTurn(sessionId, opts)
|
|
45
|
+
},
|
|
46
|
+
/** 恢复。 */
|
|
47
|
+
resume(sessionId, opts) {
|
|
48
|
+
return gate.resume(sessionId, opts)
|
|
49
|
+
},
|
|
50
|
+
/** 显式锁队列(手动触发)。 */
|
|
51
|
+
lockQueue(sessionId, reason = 'manual') {
|
|
52
|
+
const next = gate.lockQueue(sessionId, reason)
|
|
53
|
+
return { ok: true, state: next }
|
|
54
|
+
},
|
|
55
|
+
/** 显式解锁队列。 */
|
|
56
|
+
unlockQueue(sessionId) {
|
|
57
|
+
const next = gate.unlockQueue(sessionId)
|
|
58
|
+
return { ok: true, state: next }
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* 手动请求 step 级暂停(「暂停会话」按钮)。
|
|
62
|
+
* 不打断当前 step:在下一次 `agent/pre-step` 边界拉门(step 1 也拦,且不受峰谷/provider 限制)。
|
|
63
|
+
* @param {string} sessionId
|
|
64
|
+
*/
|
|
65
|
+
stepPause(sessionId) {
|
|
66
|
+
if (!stepGate || typeof stepGate.requestPause !== 'function') {
|
|
67
|
+
return { requested: false, held: false, reason: 'no-step-gate' }
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return stepGate.requestPause(sessionId)
|
|
71
|
+
} catch {
|
|
72
|
+
return { requested: false, held: false, reason: 'error' }
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* 解开 step 门(v0.2.0):放行被挂起的 step。
|
|
77
|
+
* 默认 `bypass=true`(用户手动「继续」)——本高峰窗口内不再拦该会话;
|
|
78
|
+
* 退峰/非官方切换等自动释放请用 `{ bypass: false }`。
|
|
79
|
+
* @param {string} sessionId
|
|
80
|
+
* @param {{bypass?:boolean, reason?:string}} [opts]
|
|
81
|
+
*/
|
|
82
|
+
stepResume(sessionId, opts = {}) {
|
|
83
|
+
if (!stepGate || typeof stepGate.release !== 'function') {
|
|
84
|
+
return { released: false, bypass: false, reason: 'no-step-gate' }
|
|
85
|
+
}
|
|
86
|
+
const reason = opts.reason ?? 'manual'
|
|
87
|
+
let r
|
|
88
|
+
try {
|
|
89
|
+
r = stepGate.release(sessionId, reason)
|
|
90
|
+
} catch {
|
|
91
|
+
return { released: false, bypass: false, reason }
|
|
92
|
+
}
|
|
93
|
+
const released = !!(r && r.released === true)
|
|
94
|
+
let bypassed = false
|
|
95
|
+
if (released && opts.bypass !== false && typeof stepGate.markBypass === 'function') {
|
|
96
|
+
try {
|
|
97
|
+
stepGate.markBypass(sessionId)
|
|
98
|
+
bypassed = true
|
|
99
|
+
} catch {
|
|
100
|
+
/* ignore */
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { released, bypass: bypassed, reason }
|
|
104
|
+
},
|
|
105
|
+
/** 读一会话状态。 */
|
|
106
|
+
state(sessionId) {
|
|
107
|
+
const cur = store.get(sessionId)
|
|
108
|
+
const base = cur || idleState(sessionId)
|
|
109
|
+
const pausedState = pauseGate ? (pauseGate.state(sessionId) || {}) : {}
|
|
110
|
+
let stepState = {}
|
|
111
|
+
if (stepGate && typeof stepGate.state === 'function') {
|
|
112
|
+
try {
|
|
113
|
+
stepState = stepGate.state(sessionId) || {}
|
|
114
|
+
} catch {
|
|
115
|
+
stepState = {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
sessionId: String(sessionId),
|
|
120
|
+
queueLocked: base.queueLocked === true,
|
|
121
|
+
lockReason: base.lockReason ?? null,
|
|
122
|
+
// 自研会话门真暂停状态(脱离 task-control)。
|
|
123
|
+
paused: pausedState.paused === true,
|
|
124
|
+
pausedForced: pausedState.forced === true,
|
|
125
|
+
// step 级门控(v0.2.0):paused 保持布尔以兼容既有消费者,step 态用独立字段。
|
|
126
|
+
pausedStep: stepState.held === true,
|
|
127
|
+
stepHeldSince: stepState.since ?? null,
|
|
128
|
+
stepBypass: stepState.bypass === true,
|
|
129
|
+
stepManual: stepState.manual === true,
|
|
130
|
+
taskControlAvailable: gate.taskControlAvailable(),
|
|
131
|
+
taskControl: taskControlState(sessionId),
|
|
132
|
+
updatedAt: base.updatedAt ?? null,
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -8,13 +8,19 @@
|
|
|
8
8
|
* 桥接 host 会话门;本插件客户端不注册任何按钮,避免与 input-traffic 冲突。
|
|
9
9
|
* - 0.1.7:旧的插件设置卡已随席位删除 —— 设置表单由 host
|
|
10
10
|
* 侧 Config 的 `.volatile()` 字段自动生成。
|
|
11
|
+
* - 跨版本(universal-rc):持久设置经 configForms(0.1.7+)/settingsScope(≤0.1.5)
|
|
12
|
+
* 双代腰产出同形 scope;无设置页宿主(0.1.0/0.1.1)经 shell.overlay 浮窗
|
|
13
|
+
* 齿轮提供配置入口(配置存储全在 host 侧,浮层与宿主设置页解耦)。
|
|
11
14
|
*
|
|
12
15
|
* 构建:tsdown → lib/client.js(__ModuleLoader__.load 注册,与 input-traffic 同构)。
|
|
13
16
|
*/
|
|
14
17
|
import { StatusBadge } from './status-badge'
|
|
15
18
|
import { PauseButton } from './pause-button'
|
|
16
19
|
import { SessionGuardCard } from './settings-card'
|
|
20
|
+
import { ShellSettingsEntry } from './shell-overlay'
|
|
17
21
|
import { GuardFamilySection, type FamilyTabEntry } from './family-section'
|
|
22
|
+
import type { SessionGuardConfig } from './settings-card'
|
|
23
|
+
import type { SettingsScope } from './scope-face'
|
|
18
24
|
|
|
19
25
|
// 起子插件族共用设置节:宿主 dsh-thinking-levels 注册顶级 `settings.section`
|
|
20
26
|
// (id `dsh-family`)并声明 `dsh-family.tab` 子席位,本插件贡献卡片。宿主缺席
|
|
@@ -33,6 +39,8 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
|
33
39
|
* 本卡片改经 inject 工厂拿自己的 scope(与 dsh-family.tab 注册同源)。
|
|
34
40
|
*/
|
|
35
41
|
'plugins.bundle.config': { kind: 'keyed'; scope: 'root'; owner: Record<string, unknown> }
|
|
42
|
+
/** 无设置页宿主(0.1.0/0.1.1)的兜底配置入口(壳级 overlay)。 */
|
|
43
|
+
'shell.overlay': { kind: 'list'; scope: 'root' }
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
|
|
@@ -47,8 +55,12 @@ const FAMILY_CHILD_KEY = 'dsh-family.tab'
|
|
|
47
55
|
*/
|
|
48
56
|
const FAMILY_HOST_GRACE_MS = 2000
|
|
49
57
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
58
|
+
/**
|
|
59
|
+
* 客户端所需服务:slots(状态徽标)+ locale。持久设置走双代腰
|
|
60
|
+
* (registerSettingsFaces):configForms 为 0.1.7+ 独有,顶层注入会在
|
|
61
|
+
* 0.1.0/0.1.1(无此服务)上让整段 apply 静默死。
|
|
62
|
+
*/
|
|
63
|
+
export const inject = ['slots', 'locale']
|
|
52
64
|
|
|
53
65
|
/** 轻量 ctx 类型(仅本客户端用到的方法;构建时类型被剥离)。 */
|
|
54
66
|
interface SlotsFace {
|
|
@@ -58,73 +70,139 @@ interface SlotsFace {
|
|
|
58
70
|
getVersion: (_name: string) => number
|
|
59
71
|
subscribe: (_name: string, _listener: () => void) => () => void
|
|
60
72
|
}
|
|
61
|
-
interface
|
|
62
|
-
get: <T>(_entryId: string) =>
|
|
73
|
+
interface ConfigFormsFactoryFace {
|
|
74
|
+
get: <T>(_entryId: string) => SettingsScope<T>
|
|
75
|
+
}
|
|
76
|
+
interface SettingsScopeFactoryFace {
|
|
77
|
+
bind: <T>(_opts: { namespace: string }) => SettingsScope<T>
|
|
63
78
|
}
|
|
64
79
|
interface ClientCtx {
|
|
65
80
|
slots: SlotsFace
|
|
66
|
-
|
|
81
|
+
inject: (
|
|
82
|
+
_names: string[],
|
|
83
|
+
_fn: (sctx: { configForms?: ConfigFormsFactoryFace; settingsScope?: SettingsScopeFactoryFace }) => void,
|
|
84
|
+
) => void
|
|
67
85
|
}
|
|
68
86
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, PauseButton))
|
|
87
|
+
/** 单面注册护栏:某条宿主线上未知槽名/缺服务的同步异常不得带走其它面。 */
|
|
88
|
+
function safe(tag: string, fn: () => void): void {
|
|
89
|
+
try {
|
|
90
|
+
fn()
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.warn(`dsh-session-guard: client surface '${tag}' failed:`, error)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
78
95
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
96
|
+
/**
|
|
97
|
+
* 双代持久设置腰(移植 input-traffic registerSettingsFaces):两个 scoped
|
|
98
|
+
* 子注入各自产出同形 scope 后回调;0.2.0 两代并存时以 configForms 先到为准
|
|
99
|
+
* (mounted 位防双挂载,ui-slots 同 id 仲裁兜底)。
|
|
100
|
+
*/
|
|
101
|
+
function registerSettingsFaces(
|
|
102
|
+
ctx: ClientCtx,
|
|
103
|
+
onScope: (scope: SettingsScope<SessionGuardConfig>, generation: 'configForms' | 'settingsScope') => void,
|
|
104
|
+
): void {
|
|
105
|
+
let mounted = false
|
|
106
|
+
ctx.inject(['configForms'], (sctx) => {
|
|
107
|
+
if (mounted) return
|
|
108
|
+
mounted = true
|
|
109
|
+
onScope(sctx.configForms!.get<SessionGuardConfig>('session-guard'), 'configForms')
|
|
110
|
+
})
|
|
111
|
+
ctx.inject(['settingsScope'], (sctx) => {
|
|
112
|
+
if (mounted) return
|
|
113
|
+
mounted = true
|
|
114
|
+
onScope(sctx.settingsScope!.bind<SessionGuardConfig>({ namespace: 'session-guard' }), 'settingsScope')
|
|
115
|
+
})
|
|
116
|
+
}
|
|
86
117
|
|
|
87
|
-
|
|
118
|
+
/** 两张配置卡(family tab + bundle 详情页)挂载;scope 由双代腰产出。 */
|
|
119
|
+
function mountConfigCards(ctx: ClientCtx, scope: SettingsScope<SessionGuardConfig>): void {
|
|
120
|
+
// 插件族共用 tab 贡献卡:读写本插件 entry(`session-guard`)的持久配置。
|
|
88
121
|
ctx.slots.inject('dsh-family.tab', () => ctx.slots.register({
|
|
89
122
|
name: 'dsh-family.tab',
|
|
90
123
|
id: 'session-guard',
|
|
91
124
|
order: 20,
|
|
92
125
|
label: '会话守护门禁',
|
|
93
126
|
locale: 'session-guard',
|
|
94
|
-
inject: () => ({ scope
|
|
127
|
+
inject: () => ({ scope }),
|
|
95
128
|
}, SessionGuardCard))
|
|
96
129
|
|
|
97
130
|
// 插件页配置卡(DSH 0.2.0):Plugins 页不自动渲染 volatile 配置表单,须注册
|
|
98
131
|
// `plugins.bundle.config` 席位(key = 包名),配置卡才渲染在 bundle 详情页。
|
|
99
|
-
// 卡片组件与 props(scope)与上方 dsh-family.tab
|
|
100
|
-
// SessionGuardCard、同一 inject 工厂,配置仍写入 entry `session-guard` 的
|
|
101
|
-
// volatile config;页面注入的 owner props(form 等)本卡不消费。
|
|
132
|
+
// 卡片组件与 props(scope)与上方 dsh-family.tab 注册完全同源。
|
|
102
133
|
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
103
134
|
name: 'plugins.bundle.config',
|
|
104
135
|
key: 'dsh-session-guard',
|
|
105
|
-
inject: () => ({ scope
|
|
136
|
+
inject: () => ({ scope }),
|
|
106
137
|
}, SessionGuardCard))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function apply(ctx: ClientCtx) {
|
|
141
|
+
// 暂停会话按钮(v0.2.0):step 级门控的状态显示 + 手动解除。
|
|
142
|
+
// order 20 < input-traffic 冻结按钮的 30 → 排在左侧,两者并列互不取代(ADR-001/002)。
|
|
143
|
+
safe('conversation.input.right/pause', () => ctx.slots.inject('conversation.input.right', () => ctx.slots.register({
|
|
144
|
+
name: 'conversation.input.right',
|
|
145
|
+
id: 'session-guard-pause',
|
|
146
|
+
order: 20,
|
|
147
|
+
locale: 'session-guard',
|
|
148
|
+
}, PauseButton)))
|
|
149
|
+
|
|
150
|
+
// 状态徽标:输入区右侧,纯展示。
|
|
151
|
+
safe('conversation.input.right/status', () => ctx.slots.inject('conversation.input.right', () => ctx.slots.register({
|
|
152
|
+
name: 'conversation.input.right',
|
|
153
|
+
id: 'session-guard-status',
|
|
154
|
+
order: 40,
|
|
155
|
+
locale: 'session-guard',
|
|
156
|
+
}, StatusBadge)))
|
|
157
|
+
|
|
158
|
+
// 双代腰:scope 就绪后按代挂载(每条宿主线恰好一代服务)。
|
|
159
|
+
registerSettingsFaces(ctx, (scope, generation) => {
|
|
160
|
+
safe(`config-cards/${generation}`, () => {
|
|
161
|
+
// 两代共有:family tab(0.1.7+ 由 thinking-levels 容器渲染)与
|
|
162
|
+
// bundle 详情页平铺卡(0.1.7+ 的 plugin-manager 槽)。
|
|
163
|
+
mountConfigCards(ctx, scope)
|
|
164
|
+
// 老设置页(≤0.1.5)插件列表配置卡;0.1.7+ 无此槽,注册静默闲置。
|
|
165
|
+
ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
|
|
166
|
+
name: 'settings.plugin.item',
|
|
167
|
+
id: 'session-guard',
|
|
168
|
+
key: 'session-guard',
|
|
169
|
+
order: 60,
|
|
170
|
+
locale: 'session-guard',
|
|
171
|
+
inject: () => ({ scope }),
|
|
172
|
+
}, SessionGuardCard))
|
|
173
|
+
})
|
|
174
|
+
// 无设置页宿主(0.1.0/0.1.1)的兜底配置入口:壳级 overlay 浮窗齿轮。
|
|
175
|
+
safe('shell.overlay', () => ctx.slots.inject('shell.overlay', () => ctx.slots.register(
|
|
176
|
+
{ name: 'shell.overlay', id: 'session-guard-settings' },
|
|
177
|
+
() => ShellSettingsEntry({ scope }),
|
|
178
|
+
)))
|
|
179
|
+
})
|
|
107
180
|
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ctx.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
181
|
+
// 家族节宿主选举:仅 configForms 代(0.1.7+;族面容器 thinking-levels 也只在
|
|
182
|
+
// 该代)。≤0.1.5 的设置壳不渲染 children 子槽,自起只会得到空节(实测),
|
|
183
|
+
// 故经 configForms 服务探测把选举门在该代之外。宽限期后若 settings.section
|
|
184
|
+
// 里没有 id `dsh-family` 的条目,则按同一 id 接管;与 session-steward 的
|
|
185
|
+
// 并发竞争由 ui-slots 同 id 重复注册抛错仲裁,先到者胜。
|
|
186
|
+
safe('family-section-election', () => {
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
if (ctx.slots.entries('settings.section').some(e => e.options.id === FAMILY_SECTION_ID)) return
|
|
189
|
+
ctx.inject(['configForms'], () => {
|
|
190
|
+
if (ctx.slots.entries('settings.section').some(e => e.options.id === FAMILY_SECTION_ID)) return
|
|
191
|
+
try {
|
|
192
|
+
ctx.slots.register({
|
|
193
|
+
name: 'settings.section',
|
|
194
|
+
id: FAMILY_SECTION_ID,
|
|
195
|
+
order: 40,
|
|
196
|
+
label: () => '起子插件设置',
|
|
197
|
+
inject: () => makeGuardFamilyTabsHooks(ctx.slots),
|
|
198
|
+
children: { [FAMILY_CHILD_KEY]: { kind: 'list', scope: 'root' } },
|
|
199
|
+
}, GuardFamilySection)
|
|
200
|
+
} catch {
|
|
201
|
+
// 并发接管竞争落败(或设置壳未声明席位):胜出方的节服务整个家族。
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
}, FAMILY_HOST_GRACE_MS)
|
|
205
|
+
})
|
|
128
206
|
}
|
|
129
207
|
|
|
130
208
|
/** 接管节的账本投影 hooks(与 thinking-levels 的 FamilySectionInjected 同形)。 */
|