dsh-session-guard 0.1.2 → 0.1.5-beta.1

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.
@@ -1,191 +1,370 @@
1
- /**
2
- * dsh-session-guard — 插件配置卡片(settings.plugin.item 面)。
3
- *
4
- * 对齐 dsh-thinking-levels / dsh-tidychat 的卡片语法:一个可展开的 `<li>`,
5
- * header 按钮(插件名 + 描述 + chevron)切换字段体;开关为 pill switch
6
- * (track + thumb),不是复选框对勾。
7
- *
8
- * 通过 `settingsScope.bind({ namespace: NS })` 绑定 host 已注册的
9
- * `session-guard` 命名空间;每次变更立即经 scope 提交(无 staged form)。
10
- * 仅依赖 react;CSS 经 `<style data-plugin-css>` 注入一次,控件为原生 HTML,
11
- * 客户端 bundle 无 value-import @deepseek-ai/* 平台包(类型导入被构建擦除)。
12
- */
13
- import { useState, useSyncExternalStore } from 'react'
14
- import type { JSX } from 'react'
15
- import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
16
-
17
- /** 命名空间值形状(与 host 的 DEFAULT_SETTINGS 对应)。 */
18
- export interface SessionGuardConfig {
19
- enabled: boolean
20
- offPeakAutoResume: boolean
21
- weekendMode: boolean
22
- queueFallback: boolean
23
- retryEnabled: boolean
24
- timezone: string
25
- pauseMode: 'safe' | 'force'
26
- pauseReason: 'wait' | 'stop'
27
- }
28
-
29
- /** 注入给卡片的面:绑定到 session-guard 命名空间的 settings scope。 */
30
- export interface SettingsCardInjected {
31
- scope: SettingsScope<SessionGuardConfig>
32
- }
33
-
34
- export type SettingsCardProps = SettingsCardInjected
35
-
36
- /** 卡片样式,注入一次(保持 bundle CSS-free)。 */
37
- const CARD_CSS = `
38
- .sgCard{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
39
- .sgCard:hover{border-color:var(--dsw-alias-label-dimmed)}
40
- .sgCard-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
41
- .sgCardHeader{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
42
- .sgCardHeadtext{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
43
- .sgCardName{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
44
- .sgCardDesc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
45
- .sgCardChevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}
46
- .sgCardChevron-open{transform:rotate(180deg)}
47
- .sgCardBody{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:4px 0 12px}
48
- .sgRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}
49
- .sgRow:last-child{border-bottom:0}
50
- .sgRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}
51
- .sgTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}
52
- .sgDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}
53
- .sgSwitch{position:relative;width:40px;height:22px;flex:none}
54
- .sgSwitch>input{position:absolute;inset:0;width:100%;height:100%;opacity:0;margin:0;cursor:pointer}
55
- .sgSwitch>input:disabled{cursor:not-allowed}
56
- .sgSwitchTrack{position:absolute;inset:0;border-radius:22px;background:var(--dsw-alias-interactive-bg-hover);transition:background .16s}
57
- .sgSwitch>input:checked+.sgSwitchTrack{background:var(--dsw-alias-button-primary-fill)}
58
- .sgSwitchThumb{position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:transform .16s}
59
- .sgSwitch>input:checked~.sgSwitchThumb{transform:translateX(18px)}
60
- .sgReadonly{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:8px 0 0}
61
- `
62
-
63
- /** 注入一次卡片样式。 */
64
- function injectCss(): void {
65
- if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css="session-guard-card"]') === null) {
66
- const tag = document.createElement('style')
67
- tag.dataset.plugin = 'dsh-session-guard'
68
- tag.dataset.pluginCss = 'session-guard-card'
69
- tag.textContent = CARD_CSS
70
- document.head.appendChild(tag)
71
- }
72
- }
73
-
74
- /** 一行 pill switch(滑块开关,绑定 scope)。 */
75
- function SwitchRow(props: {
76
- label: string
77
- description?: string
78
- checked: boolean
79
- disabled: boolean
80
- onChange: (_next: boolean) => void
81
- }): JSX.Element {
82
- const { label, description, checked, disabled, onChange } = props
83
- return (
84
- <div className="sgRow">
85
- <div className="sgRowText">
86
- <div className="sgTitle">{label}</div>
87
- {description !== undefined && <div className="sgDesc">{description}</div>}
88
- </div>
89
- <label className="sgSwitch">
90
- <input
91
- type="checkbox"
92
- checked={checked}
93
- disabled={disabled}
94
- onChange={(e) => onChange(e.currentTarget.checked)}
95
- />
96
- <span className="sgSwitchTrack" />
97
- <span className="sgSwitchThumb" />
98
- </label>
99
- </div>
100
- )
101
- }
102
-
103
- /** 插件配置卡片主体:可展开的 <li> + header 按钮 + pill switch 字段体。 */
104
- export function SessionGuardCard({ scope }: SettingsCardProps): JSX.Element {
105
- const snapshot = useSyncExternalStore(
106
- (listener) => scope.subscribe(listener),
107
- () => scope.getSnapshot(),
108
- )
109
- const unavailable = snapshot.status === 'unavailable'
110
- const readonly = unavailable || !snapshot.writable
111
- const value = (snapshot.value ?? {}) as Partial<SessionGuardConfig>
112
- const [open, setOpen] = useState(false)
113
-
114
- injectCss()
115
-
116
- const toggle = (field: keyof SessionGuardConfig, next: boolean) => { void scope.set(field, next) }
117
-
118
- return (
119
- <li className={'sgCard' + (open ? ' sgCard-open' : '')}>
120
- <button
121
- type="button"
122
- className="sgCardHeader"
123
- aria-expanded={open}
124
- onClick={() => setOpen(!open)}
125
- >
126
- <span className="sgCardHeadtext">
127
- <span className="sgCardName">会话守护门禁</span>
128
- <span className="sgCardDesc">高峰自动暂停运行会话,周末模式无视峰谷畅快跑</span>
129
- </span>
130
- <svg
131
- className={'sgCardChevron' + (open ? ' sgCardChevron-open' : '')}
132
- viewBox="0 0 14 14"
133
- width={14}
134
- height={14}
135
- fill="none"
136
- aria-hidden="true"
137
- >
138
- <path d="M3.5 5.5L7 9l3.5-3.5" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" />
139
- </svg>
140
- </button>
141
- {open && (
142
- <div className="sgCardBody">
143
- {unavailable ? (
144
- <p style={{ margin: '0', padding: '12px 0', fontSize: '13px', color: 'var(--dsw-alias-label-tertiary)' }}>
145
- 设置命名空间不可用:请确认 dsh-session-guard 已装配进此 profile。
146
- </p>
147
- ) : (
148
- <>
149
- <SwitchRow
150
- label="高峰自动暂停冻结会话"
151
- description="高峰时段自动暂停运行会话"
152
- checked={value.enabled ?? true}
153
- disabled={readonly}
154
- onChange={(next) => toggle('enabled', next)}
155
- />
156
- <SwitchRow
157
- label="低谷自动恢复"
158
- description="低峰时段自动恢复被暂停的会话"
159
- checked={value.offPeakAutoResume ?? true}
160
- disabled={readonly}
161
- onChange={(next) => toggle('offPeakAutoResume', next)}
162
- />
163
- <SwitchRow
164
- label="周末模式"
165
- description="识别周末,无视峰谷畅快跑"
166
- checked={value.weekendMode ?? true}
167
- disabled={readonly}
168
- onChange={(next) => toggle('weekendMode', next)}
169
- />
170
- <SwitchRow
171
- label="回退锁队列"
172
- description="无会话门时锁等待队列"
173
- checked={value.queueFallback ?? true}
174
- disabled={readonly}
175
- onChange={(next) => toggle('queueFallback', next)}
176
- />
177
- <SwitchRow
178
- label="自动重试"
179
- description="后端重试,默认关(保守)"
180
- checked={value.retryEnabled ?? false}
181
- disabled={readonly}
182
- onChange={(next) => toggle('retryEnabled', next)}
183
- />
184
- {!snapshot.writable && <p className="sgReadonly">当前只读,无法修改。</p>}
185
- </>
186
- )}
187
- </div>
188
- )}
189
- </li>
190
- )
191
- }
1
+ /**
2
+ * dsh-session-guard — 插件配置卡片(settings.plugin.item 面)。
3
+ *
4
+ * 对齐 dsh-thinking-levels / dsh-tidychat 的卡片语法:一个可展开的 `<li>`,
5
+ * header 按钮(插件名 + 描述 + chevron)切换字段体;开关为 pill switch
6
+ * (track + thumb),不是复选框对勾。
7
+ *
8
+ * 通过 `settingsScope.bind({ namespace: NS })` 绑定 host 已注册的
9
+ * `session-guard` 命名空间;每次变更立即经 scope 提交(无 staged form)。
10
+ * 仅依赖 react;CSS 经 `<style data-plugin-css>` 注入一次,控件为原生 HTML,
11
+ * 客户端 bundle 无 value-import @deepseek-ai/* 平台包(类型导入被构建擦除)。
12
+ */
13
+ import { useEffect, useState, useSyncExternalStore } from 'react'
14
+ import type { JSX } from 'react'
15
+ import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
16
+
17
+ /** 命名空间值形状(与 host 的 DEFAULT_SETTINGS 对应)。 */
18
+ export interface SessionGuardConfig {
19
+ enabled: boolean
20
+ offPeakAutoResume: boolean
21
+ weekendMode: boolean
22
+ queueFallback: boolean
23
+ retryEnabled: boolean
24
+ timezone: string
25
+ pauseMode: 'safe' | 'force'
26
+ pauseReason: 'wait' | 'stop'
27
+ // ── 官方 provider 二维判定(高峰 × 目标源)──
28
+ providerGuard: boolean
29
+ officialProviders: string[]
30
+ officialBaseURLs: string[]
31
+ deferredResume: boolean
32
+ deferredResumeText: string
33
+ deferredMode: 'hold' | 'error'
34
+ deferredMaxHoldMs: number
35
+ guardSubagents: boolean
36
+ }
37
+
38
+ /** 注入给卡片的面:绑定到 session-guard 命名空间的 settings scope。 */
39
+ export interface SettingsCardInjected {
40
+ scope: SettingsScope<SessionGuardConfig>
41
+ }
42
+
43
+ export type SettingsCardProps = SettingsCardInjected
44
+
45
+ /** 卡片样式,注入一次(保持 bundle CSS-free)。 */
46
+ const CARD_CSS = `
47
+ .sgCard{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
48
+ .sgCard:hover{border-color:var(--dsw-alias-label-dimmed)}
49
+ .sgCard-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
50
+ .sgCardHeader{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
51
+ .sgCardHeadtext{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
52
+ .sgCardName{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
53
+ .sgCardDesc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
54
+ .sgCardChevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}
55
+ .sgCardChevron-open{transform:rotate(180deg)}
56
+ .sgCardBody{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:4px 0 12px}
57
+ .sgRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}
58
+ .sgRow:last-child{border-bottom:0}
59
+ .sgRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}
60
+ .sgRowText-wide{padding-right:0}
61
+ .sgTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}
62
+ .sgDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}
63
+ .sgSwitch{position:relative;width:40px;height:22px;flex:none}
64
+ .sgSwitch>input{position:absolute;inset:0;width:100%;height:100%;opacity:0;margin:0;cursor:pointer}
65
+ .sgSwitch>input:disabled{cursor:not-allowed}
66
+ .sgSwitchTrack{position:absolute;inset:0;border-radius:22px;background:var(--dsw-alias-interactive-bg-hover);transition:background .16s}
67
+ .sgSwitch>input:checked+.sgSwitchTrack{background:var(--dsw-alias-button-primary-fill)}
68
+ .sgSwitchThumb{position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:transform .16s}
69
+ .sgSwitch>input:checked~.sgSwitchThumb{transform:translateX(18px)}
70
+ .sgInput{appearance:none;min-width:0;width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:7px 10px;margin-top:8px}
71
+ .sgInput:disabled{opacity:.6;cursor:not-allowed}
72
+ .sgSelect{appearance:none;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:7px 10px;min-width:160px;flex:none}
73
+ .sgSelect:disabled{opacity:.6;cursor:not-allowed}
74
+ .sgHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:6px 0 0}
75
+ .sgReadonly{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:8px 0 0}
76
+ `
77
+
78
+ /** 注入一次卡片样式。 */
79
+ function injectCss(): void {
80
+ if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css="session-guard-card"]') === null) {
81
+ const tag = document.createElement('style')
82
+ tag.dataset.plugin = 'dsh-session-guard'
83
+ tag.dataset.pluginCss = 'session-guard-card'
84
+ tag.textContent = CARD_CSS
85
+ document.head.appendChild(tag)
86
+ }
87
+ }
88
+
89
+ /** 一行 pill switch(滑块开关,绑定 scope)。 */
90
+ function SwitchRow(props: {
91
+ label: string
92
+ description?: string
93
+ checked: boolean
94
+ disabled: boolean
95
+ onChange: (_next: boolean) => void
96
+ }): JSX.Element {
97
+ const { label, description, checked, disabled, onChange } = props
98
+ return (
99
+ <div className="sgRow">
100
+ <div className="sgRowText">
101
+ <div className="sgTitle">{label}</div>
102
+ {description !== undefined && <div className="sgDesc">{description}</div>}
103
+ </div>
104
+ <label className="sgSwitch">
105
+ <input
106
+ type="checkbox"
107
+ checked={checked}
108
+ disabled={disabled}
109
+ onChange={(e) => onChange(e.currentTarget.checked)}
110
+ />
111
+ <span className="sgSwitchTrack" />
112
+ <span className="sgSwitchThumb" />
113
+ </label>
114
+ </div>
115
+ )
116
+ }
117
+
118
+ /** 一行文本输入(失焦提交;外部值变化时同步草稿)。 */
119
+ function TextRow(props: {
120
+ label: string
121
+ description?: string
122
+ value: string
123
+ placeholder?: string
124
+ disabled: boolean
125
+ onCommit: (_next: string) => void
126
+ }): JSX.Element {
127
+ const { label, description, value, placeholder, disabled, onCommit } = props
128
+ const [draft, setDraft] = useState(value)
129
+ useEffect(() => {
130
+ setDraft(value)
131
+ }, [value])
132
+ return (
133
+ <div className="sgRow">
134
+ <div className="sgRowText sgRowText-wide">
135
+ <div className="sgTitle">{label}</div>
136
+ {description !== undefined && <div className="sgDesc">{description}</div>}
137
+ <input
138
+ className="sgInput"
139
+ type="text"
140
+ value={draft}
141
+ placeholder={placeholder}
142
+ disabled={disabled}
143
+ onChange={(e) => setDraft(e.currentTarget.value)}
144
+ onBlur={() => onCommit(draft)}
145
+ />
146
+ </div>
147
+ </div>
148
+ )
149
+ }
150
+
151
+ /** 一行「逗号/换行分隔」的字符串列表(失焦提交为数组)。 */
152
+ function ListRow(props: {
153
+ label: string
154
+ description?: string
155
+ values: string[]
156
+ placeholder?: string
157
+ disabled: boolean
158
+ onCommit: (_next: string[]) => void
159
+ }): JSX.Element {
160
+ const { label, description, values, placeholder, disabled, onCommit } = props
161
+ const joined = values.join(', ')
162
+ const [draft, setDraft] = useState(joined)
163
+ useEffect(() => {
164
+ setDraft(joined)
165
+ }, [joined])
166
+ return (
167
+ <div className="sgRow">
168
+ <div className="sgRowText sgRowText-wide">
169
+ <div className="sgTitle">{label}</div>
170
+ {description !== undefined && <div className="sgDesc">{description}</div>}
171
+ <input
172
+ className="sgInput"
173
+ type="text"
174
+ value={draft}
175
+ placeholder={placeholder}
176
+ disabled={disabled}
177
+ onChange={(e) => setDraft(e.currentTarget.value)}
178
+ onBlur={() => {
179
+ const next = draft
180
+ .split(/[,\n]/)
181
+ .map((s) => s.trim())
182
+ .filter((s) => s !== '')
183
+ onCommit(next)
184
+ }}
185
+ />
186
+ </div>
187
+ </div>
188
+ )
189
+ }
190
+
191
+ /** 一行下拉选择。 */
192
+ function SelectRow<T extends string>(props: {
193
+ label: string
194
+ description?: string
195
+ value: T
196
+ options: readonly { value: T; label: string }[]
197
+ disabled: boolean
198
+ onChange: (_next: T) => void
199
+ }): JSX.Element {
200
+ const { label, description, value, options, disabled, onChange } = props
201
+ return (
202
+ <div className="sgRow">
203
+ <div className="sgRowText">
204
+ <div className="sgTitle">{label}</div>
205
+ {description !== undefined && <div className="sgDesc">{description}</div>}
206
+ </div>
207
+ <select
208
+ className="sgSelect"
209
+ value={value}
210
+ disabled={disabled}
211
+ onChange={(e) => onChange(e.currentTarget.value as T)}
212
+ >
213
+ {options.map((o) => (
214
+ <option key={o.value} value={o.value}>
215
+ {o.label}
216
+ </option>
217
+ ))}
218
+ </select>
219
+ </div>
220
+ )
221
+ }
222
+
223
+ /** 插件配置卡片主体:可展开的 <li> + header 按钮 + pill switch 字段体。 */
224
+ export function SessionGuardCard({ scope }: SettingsCardProps): JSX.Element {
225
+ const snapshot = useSyncExternalStore(
226
+ (listener) => scope.subscribe(listener),
227
+ () => scope.getSnapshot(),
228
+ )
229
+ const unavailable = snapshot.status === 'unavailable'
230
+ const readonly = unavailable || !snapshot.writable
231
+ const value = (snapshot.value ?? {}) as Partial<SessionGuardConfig>
232
+ const [open, setOpen] = useState(false)
233
+
234
+ injectCss()
235
+
236
+ const toggle = (field: keyof SessionGuardConfig, next: boolean) => { void scope.set(field, next) }
237
+ return (
238
+ <li className={'sgCard' + (open ? ' sgCard-open' : '')}>
239
+ <button
240
+ type="button"
241
+ className="sgCardHeader"
242
+ aria-expanded={open}
243
+ onClick={() => setOpen(!open)}
244
+ >
245
+ <span className="sgCardHeadtext">
246
+ <span className="sgCardName">会话守护门禁</span>
247
+ <span className="sgCardDesc">高峰自动暂停运行会话,周末模式无视峰谷畅快跑</span>
248
+ </span>
249
+ <svg
250
+ className={'sgCardChevron' + (open ? ' sgCardChevron-open' : '')}
251
+ viewBox="0 0 14 14"
252
+ width={14}
253
+ height={14}
254
+ fill="none"
255
+ aria-hidden="true"
256
+ >
257
+ <path d="M3.5 5.5L7 9l3.5-3.5" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" />
258
+ </svg>
259
+ </button>
260
+ {open && (
261
+ <div className="sgCardBody">
262
+ {unavailable ? (
263
+ <p style={{ margin: '0', padding: '12px 0', fontSize: '13px', color: 'var(--dsw-alias-label-tertiary)' }}>
264
+ 设置命名空间不可用:请确认 dsh-session-guard 已装配进此 profile。
265
+ </p>
266
+ ) : (
267
+ <>
268
+ <SwitchRow
269
+ label="高峰自动暂停冻结会话"
270
+ description="高峰时段自动暂停运行会话"
271
+ checked={value.enabled ?? true}
272
+ disabled={readonly}
273
+ onChange={(next) => toggle('enabled', next)}
274
+ />
275
+ <SwitchRow
276
+ label="官方源二维判定"
277
+ description="高峰期只拦 DeepSeek 官方源;本地/第三方 provider 照常跑"
278
+ checked={value.providerGuard ?? true}
279
+ disabled={readonly}
280
+ onChange={(next) => toggle('providerGuard', next)}
281
+ />
282
+ <ListRow
283
+ label="追加官方 provider id"
284
+ description="精确匹配,优先级最高(逗号分隔)"
285
+ values={value.officialProviders ?? []}
286
+ placeholder="deepseek-official"
287
+ disabled={readonly}
288
+ onCommit={(next) => { void scope.set('officialProviders', next) }}
289
+ />
290
+ <ListRow
291
+ label="官方端点名单"
292
+ description="baseURL 归一化后的 host(逗号分隔)"
293
+ values={value.officialBaseURLs ?? []}
294
+ placeholder="api.deepseek.com"
295
+ disabled={readonly}
296
+ onCommit={(next) => { void scope.set('officialBaseURLs', next) }}
297
+ />
298
+ <SelectRow<'hold' | 'error'>
299
+ label="拦截方式"
300
+ description="挂起等待不报错;或报错并记入延后队列"
301
+ value={value.deferredMode ?? 'hold'}
302
+ options={[
303
+ { value: 'hold', label: '挂起等待(退峰自动放行)' },
304
+ { value: 'error', label: '报错并延后(退峰续跑)' },
305
+ ]}
306
+ disabled={readonly}
307
+ onChange={(next) => { void scope.set('deferredMode', next) }}
308
+ />
309
+ <SwitchRow
310
+ label="退峰自动继续"
311
+ description="关闭后延后的请求/会话不自动续跑,需手动 /resume"
312
+ checked={value.deferredResume ?? true}
313
+ disabled={readonly}
314
+ onChange={(next) => toggle('deferredResume', next)}
315
+ />
316
+ <TextRow
317
+ label="退峰续跑文案"
318
+ description="error 模式退峰时发送的消息内容"
319
+ value={value.deferredResumeText ?? ''}
320
+ placeholder="继续(高峰已过,自动继续)"
321
+ disabled={readonly}
322
+ onCommit={(next) => { void scope.set('deferredResumeText', next) }}
323
+ />
324
+ <SwitchRow
325
+ label="纳入子代理请求"
326
+ description="子代理请求同样计费,默认一并拦截"
327
+ checked={value.guardSubagents ?? true}
328
+ disabled={readonly}
329
+ onChange={(next) => toggle('guardSubagents', next)}
330
+ />
331
+ <SwitchRow
332
+ label="低谷自动恢复"
333
+ description="低峰时段自动恢复被暂停的会话"
334
+ checked={value.offPeakAutoResume ?? true}
335
+ disabled={readonly}
336
+ onChange={(next) => toggle('offPeakAutoResume', next)}
337
+ />
338
+ <SwitchRow
339
+ label="周末模式"
340
+ description="识别周末,无视峰谷畅快跑"
341
+ checked={value.weekendMode ?? true}
342
+ disabled={readonly}
343
+ onChange={(next) => toggle('weekendMode', next)}
344
+ />
345
+ <SwitchRow
346
+ label="回退锁队列"
347
+ description="无会话门时锁等待队列"
348
+ checked={value.queueFallback ?? true}
349
+ disabled={readonly}
350
+ onChange={(next) => toggle('queueFallback', next)}
351
+ />
352
+ <SwitchRow
353
+ label="自动重试"
354
+ description="后端重试,默认关(保守)"
355
+ checked={value.retryEnabled ?? false}
356
+ disabled={readonly}
357
+ onChange={(next) => toggle('retryEnabled', next)}
358
+ />
359
+ <p className="sgHint">
360
+ 判定口径:显式 id 名单 → baseURL 端点 → catalog 默认端点 → 内置 id。
361
+ 排查误判访问 /session-guard/provider?provider=&lt;id&gt; 看 matchedBy。
362
+ </p>
363
+ {!snapshot.writable && <p className="sgReadonly">当前只读,无法修改。</p>}
364
+ </>
365
+ )}
366
+ </div>
367
+ )}
368
+ </li>
369
+ )
370
+ }