dsh-session-guard 0.1.2 → 0.1.3

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/lib/client.js CHANGED
@@ -1,271 +1,271 @@
1
- window.__ModuleLoader__.load({
2
- id: "dsh-session-guard",
3
- factory: (require) => {
4
- var module = { exports: {} };
5
- var exports = module.exports;
6
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
- let react = require("react");
8
- let react_jsx_runtime = require("react/jsx-runtime");
9
- //#region src/client/status-badge.tsx
10
- /**
11
- * dsh-session-guard — 状态徽标(纯展示,fail-open)。
12
- *
13
- * 轮询 host 的 /session-guard/status(全局当前阶段),显示 高峰/谷时/周末。
14
- * 仅展示,不做任何队列/会话动作;冻结按钮由 input-traffic 经桥接管(D6/D8)。
15
- */
16
- const LABELS = {
17
- peak: "高峰",
18
- "off-peak": "谷时",
19
- weekend: "周末"
20
- };
21
- const POLL_MS = 15e3;
22
- /** 状态徽标:轮询全局阶段,显示 高峰/谷时/周末(enabled 关闭或请求失败时静默隐藏)。 */
23
- function StatusBadge({ sessionId }) {
24
- const [status, setStatus] = (0, react.useState)(null);
25
- (0, react.useEffect)(() => {
26
- if (!sessionId) return;
27
- let cancelled = false;
28
- const poll = async () => {
29
- try {
30
- const body = await (await fetch("/session-guard/status")).json().catch(() => null);
31
- if (!cancelled && body?.ok && body.status) setStatus(body.status);
32
- } catch {}
33
- };
34
- poll();
35
- const timer = setInterval(poll, POLL_MS);
36
- return () => {
37
- cancelled = true;
38
- clearInterval(timer);
39
- };
40
- }, [sessionId]);
41
- if (!status || !status.enabled) return null;
42
- const cls = status.phase === "peak" ? "sg-peak" : status.phase === "weekend" ? "sg-weekend" : "sg-off";
43
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
44
- className: `sg-status ${cls}`,
45
- title: `${LABELS[status.phase]} · ${status.timezone}${status.weekendMode ? " · 周末模式" : ""}`,
46
- "data-sg-phase": status.phase,
47
- children: LABELS[status.phase]
48
- });
49
- }
50
- //#endregion
51
- //#region src/client/settings-card.tsx
52
- /**
53
- * dsh-session-guard — 插件配置卡片(settings.plugin.item 面)。
54
- *
55
- * 对齐 dsh-thinking-levels / dsh-tidychat 的卡片语法:一个可展开的 `<li>`,
56
- * header 按钮(插件名 + 描述 + chevron)切换字段体;开关为 pill switch
57
- * (track + thumb),不是复选框对勾。
58
- *
59
- * 通过 `settingsScope.bind({ namespace: NS })` 绑定 host 已注册的
60
- * `session-guard` 命名空间;每次变更立即经 scope 提交(无 staged form)。
61
- * 仅依赖 react;CSS 经 `<style data-plugin-css>` 注入一次,控件为原生 HTML,
62
- * 客户端 bundle 无 value-import @deepseek-ai/* 平台包(类型导入被构建擦除)。
63
- */
64
- /** 卡片样式,注入一次(保持 bundle CSS-free)。 */
65
- const CARD_CSS = `
66
- .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}
67
- .sgCard:hover{border-color:var(--dsw-alias-label-dimmed)}
68
- .sgCard-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
69
- .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}
70
- .sgCardHeadtext{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
71
- .sgCardName{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
72
- .sgCardDesc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
73
- .sgCardChevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}
74
- .sgCardChevron-open{transform:rotate(180deg)}
75
- .sgCardBody{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:4px 0 12px}
76
- .sgRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}
77
- .sgRow:last-child{border-bottom:0}
78
- .sgRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}
79
- .sgTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}
80
- .sgDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}
81
- .sgSwitch{position:relative;width:40px;height:22px;flex:none}
82
- .sgSwitch>input{position:absolute;inset:0;width:100%;height:100%;opacity:0;margin:0;cursor:pointer}
83
- .sgSwitch>input:disabled{cursor:not-allowed}
84
- .sgSwitchTrack{position:absolute;inset:0;border-radius:22px;background:var(--dsw-alias-interactive-bg-hover);transition:background .16s}
85
- .sgSwitch>input:checked+.sgSwitchTrack{background:var(--dsw-alias-button-primary-fill)}
86
- .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}
87
- .sgSwitch>input:checked~.sgSwitchThumb{transform:translateX(18px)}
88
- .sgReadonly{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:8px 0 0}
89
- `;
90
- /** 注入一次卡片样式。 */
91
- function injectCss() {
92
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"session-guard-card\"]") === null) {
93
- const tag = document.createElement("style");
94
- tag.dataset.plugin = "dsh-session-guard";
95
- tag.dataset.pluginCss = "session-guard-card";
96
- tag.textContent = CARD_CSS;
97
- document.head.appendChild(tag);
98
- }
99
- }
100
- /** 一行 pill switch(滑块开关,绑定 scope)。 */
101
- function SwitchRow(props) {
102
- const { label, description, checked, disabled, onChange } = props;
103
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
104
- className: "sgRow",
105
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
106
- className: "sgRowText",
107
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
108
- className: "sgTitle",
109
- children: label
110
- }), description !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
111
- className: "sgDesc",
112
- children: description
113
- })]
114
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
115
- className: "sgSwitch",
116
- children: [
117
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
118
- type: "checkbox",
119
- checked,
120
- disabled,
121
- onChange: (e) => onChange(e.currentTarget.checked)
122
- }),
123
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "sgSwitchTrack" }),
124
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "sgSwitchThumb" })
125
- ]
126
- })]
127
- });
128
- }
129
- /** 插件配置卡片主体:可展开的 <li> + header 按钮 + pill switch 字段体。 */
130
- function SessionGuardCard({ scope }) {
131
- const snapshot = (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot());
132
- const unavailable = snapshot.status === "unavailable";
133
- const readonly = unavailable || !snapshot.writable;
134
- const value = snapshot.value ?? {};
135
- const [open, setOpen] = (0, react.useState)(false);
136
- injectCss();
137
- const toggle = (field, next) => {
138
- scope.set(field, next);
139
- };
140
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
141
- className: "sgCard" + (open ? " sgCard-open" : ""),
142
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
143
- type: "button",
144
- className: "sgCardHeader",
145
- "aria-expanded": open,
146
- onClick: () => setOpen(!open),
147
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
148
- className: "sgCardHeadtext",
149
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
150
- className: "sgCardName",
151
- children: "会话守护门禁"
152
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
153
- className: "sgCardDesc",
154
- children: "高峰自动暂停运行会话,周末模式无视峰谷畅快跑"
155
- })]
156
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
157
- className: "sgCardChevron" + (open ? " sgCardChevron-open" : ""),
158
- viewBox: "0 0 14 14",
159
- width: 14,
160
- height: 14,
161
- fill: "none",
162
- "aria-hidden": "true",
163
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
164
- d: "M3.5 5.5L7 9l3.5-3.5",
165
- stroke: "currentColor",
166
- strokeWidth: 1.5,
167
- strokeLinecap: "round",
168
- strokeLinejoin: "round"
169
- })
170
- })]
171
- }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
172
- className: "sgCardBody",
173
- children: unavailable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
174
- style: {
175
- margin: "0",
176
- padding: "12px 0",
177
- fontSize: "13px",
178
- color: "var(--dsw-alias-label-tertiary)"
179
- },
180
- children: "设置命名空间不可用:请确认 dsh-session-guard 已装配进此 profile。"
181
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
182
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
183
- label: "高峰自动暂停冻结会话",
184
- description: "高峰时段自动暂停运行会话",
185
- checked: value.enabled ?? true,
186
- disabled: readonly,
187
- onChange: (next) => toggle("enabled", next)
188
- }),
189
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
190
- label: "低谷自动恢复",
191
- description: "低峰时段自动恢复被暂停的会话",
192
- checked: value.offPeakAutoResume ?? true,
193
- disabled: readonly,
194
- onChange: (next) => toggle("offPeakAutoResume", next)
195
- }),
196
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
197
- label: "周末模式",
198
- description: "识别周末,无视峰谷畅快跑",
199
- checked: value.weekendMode ?? true,
200
- disabled: readonly,
201
- onChange: (next) => toggle("weekendMode", next)
202
- }),
203
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
204
- label: "回退锁队列",
205
- description: "无会话门时锁等待队列",
206
- checked: value.queueFallback ?? true,
207
- disabled: readonly,
208
- onChange: (next) => toggle("queueFallback", next)
209
- }),
210
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
211
- label: "自动重试",
212
- description: "后端重试,默认关(保守)",
213
- checked: value.retryEnabled ?? false,
214
- disabled: readonly,
215
- onChange: (next) => toggle("retryEnabled", next)
216
- }),
217
- !snapshot.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
218
- className: "sgReadonly",
219
- children: "当前只读,无法修改。"
220
- })
221
- ] })
222
- })]
223
- });
224
- }
225
- //#endregion
226
- //#region src/client/index.ts
227
- /**
228
- * dsh-session-guard — 浏览器 half。
229
- *
230
- * 职责(全部 fail-open,D8):
231
- * - 在 composer 输入区右侧注册一个**纯展示**状态徽标(高峰/谷时/周末),轮询
232
- * /session-guard/status;
233
- * - 注册 `settings.plugin.item` 设置卡片,经 `settingsScope.bind({ namespace })`
234
- * 绑定 host 已注册的 `session-guard` 命名空间——这正是“插件配置”面板显示本
235
- * 插件的**必要**机制(对齐 dsh-thinking-levels / dsh-context);
236
- * - **不做**冻结/会话动作——冻结按钮由 input-traffic 接管并经 /session-guard/rpc
237
- * 桥接 host 会话门;本插件客户端不注册任何按钮,避免与 input-traffic 冲突。
238
- *
239
- * 构建:tsdown → lib/client.js(__ModuleLoader__.load 注册,与 input-traffic 同构)。
240
- */
241
- /** 客户端所需服务:slots(状态徽标 + 设置卡片)+ locale + settingsScope(设置卡片绑定)。 */
242
- const inject = [
243
- "slots",
244
- "locale",
245
- "settingsScope"
246
- ];
247
- /** host 侧 src/settings.js 注册的命名空间(保持一致)。 */
248
- const NS = "session-guard";
249
- function apply(ctx) {
250
- ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
251
- name: "conversation.input.right",
252
- id: "session-guard-status",
253
- order: 50,
254
- locale: "session-guard"
255
- }, StatusBadge));
256
- ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
257
- name: "settings.plugin.item",
258
- id: NS,
259
- key: NS,
260
- locale: "session-guard",
261
- inject: () => ({ scope: ctx.settingsScope.bind({ namespace: NS }) })
262
- }, SessionGuardCard));
263
- }
264
- //#endregion
265
- exports.apply = apply;
266
- exports.inject = inject;
267
- return module.exports;
268
- }
269
- });
270
-
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-session-guard",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region src/client/status-badge.tsx
10
+ /**
11
+ * dsh-session-guard — 状态徽标(纯展示,fail-open)。
12
+ *
13
+ * 轮询 host 的 /session-guard/status(全局当前阶段),显示 高峰/谷时/周末。
14
+ * 仅展示,不做任何队列/会话动作;冻结按钮由 input-traffic 经桥接管(D6/D8)。
15
+ */
16
+ const LABELS = {
17
+ peak: "高峰",
18
+ "off-peak": "谷时",
19
+ weekend: "周末"
20
+ };
21
+ const POLL_MS = 15e3;
22
+ /** 状态徽标:轮询全局阶段,显示 高峰/谷时/周末(enabled 关闭或请求失败时静默隐藏)。 */
23
+ function StatusBadge({ sessionId }) {
24
+ const [status, setStatus] = (0, react.useState)(null);
25
+ (0, react.useEffect)(() => {
26
+ if (!sessionId) return;
27
+ let cancelled = false;
28
+ const poll = async () => {
29
+ try {
30
+ const body = await (await fetch("/session-guard/status")).json().catch(() => null);
31
+ if (!cancelled && body?.ok && body.status) setStatus(body.status);
32
+ } catch {}
33
+ };
34
+ poll();
35
+ const timer = setInterval(poll, POLL_MS);
36
+ return () => {
37
+ cancelled = true;
38
+ clearInterval(timer);
39
+ };
40
+ }, [sessionId]);
41
+ if (!status || !status.enabled) return null;
42
+ const cls = status.phase === "peak" ? "sg-peak" : status.phase === "weekend" ? "sg-weekend" : "sg-off";
43
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
44
+ className: `sg-status ${cls}`,
45
+ title: `${LABELS[status.phase]} · ${status.timezone}${status.weekendMode ? " · 周末模式" : ""}`,
46
+ "data-sg-phase": status.phase,
47
+ children: LABELS[status.phase]
48
+ });
49
+ }
50
+ //#endregion
51
+ //#region src/client/settings-card.tsx
52
+ /**
53
+ * dsh-session-guard — 插件配置卡片(settings.plugin.item 面)。
54
+ *
55
+ * 对齐 dsh-thinking-levels / dsh-tidychat 的卡片语法:一个可展开的 `<li>`,
56
+ * header 按钮(插件名 + 描述 + chevron)切换字段体;开关为 pill switch
57
+ * (track + thumb),不是复选框对勾。
58
+ *
59
+ * 通过 `settingsScope.bind({ namespace: NS })` 绑定 host 已注册的
60
+ * `session-guard` 命名空间;每次变更立即经 scope 提交(无 staged form)。
61
+ * 仅依赖 react;CSS 经 `<style data-plugin-css>` 注入一次,控件为原生 HTML,
62
+ * 客户端 bundle 无 value-import @deepseek-ai/* 平台包(类型导入被构建擦除)。
63
+ */
64
+ /** 卡片样式,注入一次(保持 bundle CSS-free)。 */
65
+ const CARD_CSS = `
66
+ .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}
67
+ .sgCard:hover{border-color:var(--dsw-alias-label-dimmed)}
68
+ .sgCard-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
69
+ .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}
70
+ .sgCardHeadtext{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
71
+ .sgCardName{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
72
+ .sgCardDesc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
73
+ .sgCardChevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}
74
+ .sgCardChevron-open{transform:rotate(180deg)}
75
+ .sgCardBody{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:4px 0 12px}
76
+ .sgRow{border-bottom:1px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}
77
+ .sgRow:last-child{border-bottom:0}
78
+ .sgRowText{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}
79
+ .sgTitle{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}
80
+ .sgDesc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}
81
+ .sgSwitch{position:relative;width:40px;height:22px;flex:none}
82
+ .sgSwitch>input{position:absolute;inset:0;width:100%;height:100%;opacity:0;margin:0;cursor:pointer}
83
+ .sgSwitch>input:disabled{cursor:not-allowed}
84
+ .sgSwitchTrack{position:absolute;inset:0;border-radius:22px;background:var(--dsw-alias-interactive-bg-hover);transition:background .16s}
85
+ .sgSwitch>input:checked+.sgSwitchTrack{background:var(--dsw-alias-button-primary-fill)}
86
+ .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}
87
+ .sgSwitch>input:checked~.sgSwitchThumb{transform:translateX(18px)}
88
+ .sgReadonly{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:8px 0 0}
89
+ `;
90
+ /** 注入一次卡片样式。 */
91
+ function injectCss() {
92
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"session-guard-card\"]") === null) {
93
+ const tag = document.createElement("style");
94
+ tag.dataset.plugin = "dsh-session-guard";
95
+ tag.dataset.pluginCss = "session-guard-card";
96
+ tag.textContent = CARD_CSS;
97
+ document.head.appendChild(tag);
98
+ }
99
+ }
100
+ /** 一行 pill switch(滑块开关,绑定 scope)。 */
101
+ function SwitchRow(props) {
102
+ const { label, description, checked, disabled, onChange } = props;
103
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
104
+ className: "sgRow",
105
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
106
+ className: "sgRowText",
107
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
108
+ className: "sgTitle",
109
+ children: label
110
+ }), description !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
111
+ className: "sgDesc",
112
+ children: description
113
+ })]
114
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
115
+ className: "sgSwitch",
116
+ children: [
117
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
118
+ type: "checkbox",
119
+ checked,
120
+ disabled,
121
+ onChange: (e) => onChange(e.currentTarget.checked)
122
+ }),
123
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "sgSwitchTrack" }),
124
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "sgSwitchThumb" })
125
+ ]
126
+ })]
127
+ });
128
+ }
129
+ /** 插件配置卡片主体:可展开的 <li> + header 按钮 + pill switch 字段体。 */
130
+ function SessionGuardCard({ scope }) {
131
+ const snapshot = (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot());
132
+ const unavailable = snapshot.status === "unavailable";
133
+ const readonly = unavailable || !snapshot.writable;
134
+ const value = snapshot.value ?? {};
135
+ const [open, setOpen] = (0, react.useState)(false);
136
+ injectCss();
137
+ const toggle = (field, next) => {
138
+ scope.set(field, next);
139
+ };
140
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
141
+ className: "sgCard" + (open ? " sgCard-open" : ""),
142
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
143
+ type: "button",
144
+ className: "sgCardHeader",
145
+ "aria-expanded": open,
146
+ onClick: () => setOpen(!open),
147
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
148
+ className: "sgCardHeadtext",
149
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
150
+ className: "sgCardName",
151
+ children: "会话守护门禁"
152
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
153
+ className: "sgCardDesc",
154
+ children: "高峰自动暂停运行会话,周末模式无视峰谷畅快跑"
155
+ })]
156
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
157
+ className: "sgCardChevron" + (open ? " sgCardChevron-open" : ""),
158
+ viewBox: "0 0 14 14",
159
+ width: 14,
160
+ height: 14,
161
+ fill: "none",
162
+ "aria-hidden": "true",
163
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
164
+ d: "M3.5 5.5L7 9l3.5-3.5",
165
+ stroke: "currentColor",
166
+ strokeWidth: 1.5,
167
+ strokeLinecap: "round",
168
+ strokeLinejoin: "round"
169
+ })
170
+ })]
171
+ }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
172
+ className: "sgCardBody",
173
+ children: unavailable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
174
+ style: {
175
+ margin: "0",
176
+ padding: "12px 0",
177
+ fontSize: "13px",
178
+ color: "var(--dsw-alias-label-tertiary)"
179
+ },
180
+ children: "设置命名空间不可用:请确认 dsh-session-guard 已装配进此 profile。"
181
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
182
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
183
+ label: "高峰自动暂停冻结会话",
184
+ description: "高峰时段自动暂停运行会话",
185
+ checked: value.enabled ?? true,
186
+ disabled: readonly,
187
+ onChange: (next) => toggle("enabled", next)
188
+ }),
189
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
190
+ label: "低谷自动恢复",
191
+ description: "低峰时段自动恢复被暂停的会话",
192
+ checked: value.offPeakAutoResume ?? true,
193
+ disabled: readonly,
194
+ onChange: (next) => toggle("offPeakAutoResume", next)
195
+ }),
196
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
197
+ label: "周末模式",
198
+ description: "识别周末,无视峰谷畅快跑",
199
+ checked: value.weekendMode ?? true,
200
+ disabled: readonly,
201
+ onChange: (next) => toggle("weekendMode", next)
202
+ }),
203
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
204
+ label: "回退锁队列",
205
+ description: "无会话门时锁等待队列",
206
+ checked: value.queueFallback ?? true,
207
+ disabled: readonly,
208
+ onChange: (next) => toggle("queueFallback", next)
209
+ }),
210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchRow, {
211
+ label: "自动重试",
212
+ description: "后端重试,默认关(保守)",
213
+ checked: value.retryEnabled ?? false,
214
+ disabled: readonly,
215
+ onChange: (next) => toggle("retryEnabled", next)
216
+ }),
217
+ !snapshot.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
218
+ className: "sgReadonly",
219
+ children: "当前只读,无法修改。"
220
+ })
221
+ ] })
222
+ })]
223
+ });
224
+ }
225
+ //#endregion
226
+ //#region src/client/index.ts
227
+ /**
228
+ * dsh-session-guard — 浏览器 half。
229
+ *
230
+ * 职责(全部 fail-open,D8):
231
+ * - 在 composer 输入区右侧注册一个**纯展示**状态徽标(高峰/谷时/周末),轮询
232
+ * /session-guard/status;
233
+ * - 注册 `settings.plugin.item` 设置卡片,经 `settingsScope.bind({ namespace })`
234
+ * 绑定 host 已注册的 `session-guard` 命名空间——这正是“插件配置”面板显示本
235
+ * 插件的**必要**机制(对齐 dsh-thinking-levels / dsh-context);
236
+ * - **不做**冻结/会话动作——冻结按钮由 input-traffic 接管并经 /session-guard/rpc
237
+ * 桥接 host 会话门;本插件客户端不注册任何按钮,避免与 input-traffic 冲突。
238
+ *
239
+ * 构建:tsdown → lib/client.js(__ModuleLoader__.load 注册,与 input-traffic 同构)。
240
+ */
241
+ /** 客户端所需服务:slots(状态徽标 + 设置卡片)+ locale + settingsScope(设置卡片绑定)。 */
242
+ const inject = [
243
+ "slots",
244
+ "locale",
245
+ "settingsScope"
246
+ ];
247
+ /** host 侧 src/settings.js 注册的命名空间(保持一致)。 */
248
+ const NS = "session-guard";
249
+ function apply(ctx) {
250
+ ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
251
+ name: "conversation.input.right",
252
+ id: "session-guard-status",
253
+ order: 50,
254
+ locale: "session-guard"
255
+ }, StatusBadge));
256
+ ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
257
+ name: "settings.plugin.item",
258
+ id: NS,
259
+ key: NS,
260
+ locale: "session-guard",
261
+ inject: () => ({ scope: ctx.settingsScope.bind({ namespace: NS }) })
262
+ }, SessionGuardCard));
263
+ }
264
+ //#endregion
265
+ exports.apply = apply;
266
+ exports.inject = inject;
267
+ return module.exports;
268
+ }
269
+ });
270
+
271
271
  //# sourceMappingURL=client.js.map