@linxin666/dsh-liangshen 0.3.23 → 0.4.0
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/README.i18n.yaml +2 -2
- package/README.md +55 -41
- package/README.zh.md +54 -40
- package/cordis.patch.yml +3 -2
- package/icon.svg +3 -0
- package/lib/client.js +1380 -29
- package/lib/client.js.map +1 -1
- package/lib/index.js +616 -367
- package/lib/types/announce.test.d.ts +10 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +78 -0
- package/lib/types/client/PluginSettingsCard.d.ts +137 -0
- package/lib/types/client/index.d.ts +57 -4
- package/lib/types/client/lever-controller.d.ts +16 -2
- package/lib/types/client/locales.d.ts +40 -1
- package/lib/types/client/main-session.d.ts +32 -0
- package/lib/types/client/plugin-card-seat.d.ts +103 -0
- package/lib/types/client/settings-form.d.ts +197 -0
- package/lib/types/composition.d.ts +116 -0
- package/lib/types/composition.test.d.ts +7 -0
- package/lib/types/core/lever.d.ts +6 -3
- package/lib/types/index.d.ts +160 -33
- package/lib/types/index.test.d.ts +5 -0
- package/package.json +27 -18
- package/presets/liangshen/NOTICE +4 -4
- package/presets/liangshen/agent.cordis.yml +168 -123
- package/presets/liangshen/fact-ledger.mjs +141 -0
- package/presets/liangshen/guard.mjs +426 -0
- package/presets/liangshen/minimal-prompt.mjs +73 -38
- package/presets/liangshen/paging.mjs +232 -0
- package/presets/liangshen/tool-activate.mjs +176 -0
- package/presets/liangshen/tool-catalog.mjs +615 -219
- package/presets/liangshen/working-context.mjs +222 -0
- package/src/announce.test.ts +248 -55
- package/src/client/LiangShenLever.module.css +2 -0
- package/src/client/LiangShenLever.tsx +41 -10
- package/src/client/LiangShenSettingsCard.tsx +233 -0
- package/src/client/PluginSettingsCard.tsx +555 -0
- package/src/client/index.ts +102 -5
- package/src/client/lever-controller.ts +76 -9
- package/src/client/locales.ts +79 -1
- package/src/client/main-session.ts +43 -0
- package/src/client/plugin-card-seat.ts +192 -0
- package/src/client/settings-card.module.css +418 -0
- package/src/client/settings-form.ts +442 -0
- package/src/composition.test.ts +294 -0
- package/src/composition.ts +554 -0
- package/src/core/lever.ts +7 -4
- package/src/index.test.ts +68 -1
- package/src/index.ts +293 -101
- package/tools/benchmark-live-run.mjs +193 -63
- package/lib/types/schema.d.ts +0 -18
- package/lib/types/schema.test.d.ts +0 -1
- package/lib/types/sync.d.ts +0 -47
- package/lib/types/sync.test.d.ts +0 -1
- package/presets/liangshen/custom-bash.mjs +0 -213
- package/src/schema.test.ts +0 -64
- package/src/schema.ts +0 -110
- package/src/sync.test.ts +0 -224
- package/src/sync.ts +0 -222
package/lib/client.js
CHANGED
|
@@ -7,13 +7,13 @@ window.__ModuleLoader__.load({
|
|
|
7
7
|
let react = require("react");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
9
|
//#region \0dsh-css:packages/dsh-liangshen/src/client/LiangShenLever.module.css.mjs
|
|
10
|
-
const css = ".hYkIZq_lever{align-items:center;font-size:12px;line-height:1;display:inline-flex;position:relative}.hYkIZq_control{color:var(--dsw-alias-label-secondary,inherit);font:inherit;cursor:pointer;touch-action:none;background:0 0;border:none;border-radius:999px;align-items:center;gap:6px;margin:0;padding:2px 8px 2px 4px;transition:background-color .16s,color .16s;display:inline-flex}.hYkIZq_control:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,#0000000f)}.hYkIZq_control:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:2px}.hYkIZq_control:disabled{cursor:default;opacity:.55}.hYkIZq_track{background:linear-gradient(#2b2f36,#14161a);border-radius:8px;justify-content:center;align-items:flex-end;width:24px;height:28px;display:inline-flex;position:relative;overflow:hidden;box-shadow:inset 0 0 0 1px #ffffff24,inset 0 6px 10px #0000008c}.hYkIZq_track:after{content:\"\";background:#ffffff38;border-radius:2px;height:3px;position:absolute;bottom:2px;left:3px;right:3px}.hYkIZq_arm{transform-origin:50% 24px;width:16px;height:26px;margin-left:-8px;transition:transform .34s cubic-bezier(.2,1.7,.32,1);position:absolute;bottom:2px;left:50%;transform:rotate(-24deg)}.hYkIZq_lever[data-state=on] .hYkIZq_arm{transform:rotate(24deg)}.hYkIZq_rod{fill:#c9ced6;transition:fill .2s}.hYkIZq_knob{fill:#e04a33;stroke:#00000059;stroke-width:.6px;transition:fill .2s}.hYkIZq_lever[data-state=on] .hYkIZq_rod{fill:#ffd76a}.hYkIZq_lever[data-state=on] .hYkIZq_knob{fill:#f7c637}.hYkIZq_lever[data-state=on] .hYkIZq_track{box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l3,#0000001f), 0 0 10px #f7c6378c}.hYkIZq_lever[data-busy=true] .hYkIZq_arm{animation:.42s ease-in-out infinite hYkIZq_lever-jitter}.hYkIZq_readout{white-space:nowrap;letter-spacing:.02em;min-width:4.4em}.hYkIZq_lever[data-state=on] .hYkIZq_readout{color:var(--dsw-alias-label-primary,inherit);font-weight:600}.hYkIZq_error{background:var(--dsw-alias-bg-layer-3,#0000000f);max-width:22ch;color:var(--dsw-alias-state-error-primary,#c0392b);text-overflow:ellipsis;white-space:nowrap;border-radius:6px;margin-left:4px;padding:2px 6px;overflow:hidden}.hYkIZq_burst{z-index:60;pointer-events:none;place-items:center;display:grid;position:fixed;inset:0;overflow:hidden}.hYkIZq_flash{background:radial-gradient(circle at 50% 62%,#fff6c8eb,#ffd04a73 38%,#ffa00000 72%);animation:.72s ease-out both hYkIZq_burst-flash;position:absolute;inset:0}.hYkIZq_ring{border:6px solid #ffd65ad9;border-radius:50%;width:220px;height:220px;animation:1.1s cubic-bezier(.16,.9,.3,1) both hYkIZq_burst-ring;position:absolute}.hYkIZq_ring:nth-of-type(2){animation-delay:.12s}.hYkIZq_ring:nth-of-type(3){animation-delay:.24s}.hYkIZq_banner{color:#ffe9a8;text-align:center;background:linear-gradient(160deg,#181004f0,#402604eb);border-radius:22px;flex-direction:column;align-items:center;gap:6px;padding:22px 40px;animation:.6s cubic-bezier(.16,1.5,.3,1) both hYkIZq_banner-slam,.5s ease-in-out .6s 2 hYkIZq_banner-shake;display:flex;position:relative;box-shadow:0 0 0 2px #ffd65abf,0 24px 70px #00000073}.hYkIZq_bannerName{letter-spacing:.16em;background:linear-gradient(#fff6d0,#ffc93c 55%,#b8730a);color:#0000;text-shadow:0 0 24px #ffc93ca6;-webkit-background-clip:text;background-clip:text;font-size:44px;font-weight:800}.hYkIZq_line{letter-spacing:.08em;font-size:15px}.hYkIZq_code{font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);letter-spacing:.06em;opacity:.82;font-size:11px;animation:.5s steps(2,end) 6 hYkIZq_code-blink}.hYkIZq_sparks{place-items:center;display:grid;position:absolute;inset:0}.hYkIZq_spark{transform-origin:50%;background:linear-gradient(#ffeca0f2,#ffaa1400);border-radius:3px;grid-area:1/1;width:3px;height:30px;animation:.95s ease-out both hYkIZq_spark-fly}@keyframes hYkIZq_lever-jitter{0%,to{transform:rotate(-22deg)}50%{transform:rotate(-8deg)}}@keyframes hYkIZq_burst-flash{0%{opacity:0;transform:scale(.6)}18%{opacity:1}to{opacity:0;transform:scale(1.5)}}@keyframes hYkIZq_burst-ring{0%{opacity:.9;transform:scale(.2)}to{opacity:0;transform:scale(3.4)}}@keyframes hYkIZq_banner-slam{0%{opacity:0;transform:scale(3.6)rotate(-9deg)}55%{opacity:1;transform:scale(.94)rotate(1.5deg)}75%{transform:scale(1.06)rotate(-1deg)}to{opacity:1;transform:scale(1)rotate(0)}}@keyframes hYkIZq_banner-shake{0%,to{transform:translate(0)}25%{transform:translate(-9px)rotate(-.6deg)}75%{transform:translate(9px)rotate(.6deg)}}@keyframes hYkIZq_spark-fly{0%{opacity:0;transform:translateY(-40px)scaleY(.3)}18%{opacity:1}to{opacity:0;transform:translateY(-300px)scaleY(1.15)}}@keyframes hYkIZq_code-blink{0%,to{opacity:.35}50%{opacity:1}}@media (prefers-reduced-motion:reduce){.hYkIZq_arm,.hYkIZq_control,.hYkIZq_rod,.hYkIZq_knob{transition:none}.hYkIZq_lever[data-busy=true] .hYkIZq_arm,.hYkIZq_flash,.hYkIZq_ring,.hYkIZq_banner,.hYkIZq_code,.hYkIZq_spark{animation:none}.hYkIZq_burst{animation:.3s ease-out both hYkIZq_burst-flash}.hYkIZq_spark{display:none}}";
|
|
11
|
-
const tagId = "@linxin666/dsh-liangshen/packages/dsh-liangshen/src/client/LiangShenLever.module.css";
|
|
12
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
10
|
+
const css$1 = ".hYkIZq_lever{align-items:center;font-size:12px;line-height:1;display:inline-flex;position:relative}.hYkIZq_control{color:var(--dsw-alias-label-secondary,inherit);font:inherit;cursor:pointer;touch-action:none;-webkit-user-select:none;user-select:none;background:0 0;border:none;border-radius:999px;align-items:center;gap:6px;margin:0;padding:2px 8px 2px 4px;transition:background-color .16s,color .16s;display:inline-flex}.hYkIZq_control:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,#0000000f)}.hYkIZq_control:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:2px}.hYkIZq_control:disabled{cursor:default;opacity:.55}.hYkIZq_track{background:linear-gradient(#2b2f36,#14161a);border-radius:8px;justify-content:center;align-items:flex-end;width:24px;height:28px;display:inline-flex;position:relative;overflow:hidden;box-shadow:inset 0 0 0 1px #ffffff24,inset 0 6px 10px #0000008c}.hYkIZq_track:after{content:\"\";background:#ffffff38;border-radius:2px;height:3px;position:absolute;bottom:2px;left:3px;right:3px}.hYkIZq_arm{transform-origin:50% 24px;width:16px;height:26px;margin-left:-8px;transition:transform .34s cubic-bezier(.2,1.7,.32,1);position:absolute;bottom:2px;left:50%;transform:rotate(-24deg)}.hYkIZq_lever[data-state=on] .hYkIZq_arm{transform:rotate(24deg)}.hYkIZq_rod{fill:#c9ced6;transition:fill .2s}.hYkIZq_knob{fill:#e04a33;stroke:#00000059;stroke-width:.6px;transition:fill .2s}.hYkIZq_lever[data-state=on] .hYkIZq_rod{fill:#ffd76a}.hYkIZq_lever[data-state=on] .hYkIZq_knob{fill:#f7c637}.hYkIZq_lever[data-state=on] .hYkIZq_track{box-shadow:inset 0 0 0 1px var(--dsw-alias-border-l3,#0000001f), 0 0 10px #f7c6378c}.hYkIZq_lever[data-busy=true] .hYkIZq_arm{animation:.42s ease-in-out infinite hYkIZq_lever-jitter}.hYkIZq_readout{white-space:nowrap;letter-spacing:.02em;min-width:4.4em}.hYkIZq_lever[data-state=on] .hYkIZq_readout{color:var(--dsw-alias-label-primary,inherit);font-weight:600}.hYkIZq_error{background:var(--dsw-alias-bg-layer-3,#0000000f);max-width:22ch;color:var(--dsw-alias-state-error-primary,#c0392b);text-overflow:ellipsis;white-space:nowrap;border-radius:6px;margin-left:4px;padding:2px 6px;overflow:hidden}.hYkIZq_burst{z-index:60;pointer-events:none;place-items:center;display:grid;position:fixed;inset:0;overflow:hidden}.hYkIZq_flash{background:radial-gradient(circle at 50% 62%,#fff6c8eb,#ffd04a73 38%,#ffa00000 72%);animation:.72s ease-out both hYkIZq_burst-flash;position:absolute;inset:0}.hYkIZq_ring{border:6px solid #ffd65ad9;border-radius:50%;width:220px;height:220px;animation:1.1s cubic-bezier(.16,.9,.3,1) both hYkIZq_burst-ring;position:absolute}.hYkIZq_ring:nth-of-type(2){animation-delay:.12s}.hYkIZq_ring:nth-of-type(3){animation-delay:.24s}.hYkIZq_banner{color:#ffe9a8;text-align:center;background:linear-gradient(160deg,#181004f0,#402604eb);border-radius:22px;flex-direction:column;align-items:center;gap:6px;padding:22px 40px;animation:.6s cubic-bezier(.16,1.5,.3,1) both hYkIZq_banner-slam,.5s ease-in-out .6s 2 hYkIZq_banner-shake;display:flex;position:relative;box-shadow:0 0 0 2px #ffd65abf,0 24px 70px #00000073}.hYkIZq_bannerName{letter-spacing:.16em;background:linear-gradient(#fff6d0,#ffc93c 55%,#b8730a);color:#0000;text-shadow:0 0 24px #ffc93ca6;-webkit-background-clip:text;background-clip:text;font-size:44px;font-weight:800}.hYkIZq_line{letter-spacing:.08em;font-size:15px}.hYkIZq_code{font-family:var(--dsw-font-mono,ui-monospace, SFMono-Regular, Menlo, monospace);letter-spacing:.06em;opacity:.82;font-size:11px;animation:.5s steps(2,end) 6 hYkIZq_code-blink}.hYkIZq_sparks{place-items:center;display:grid;position:absolute;inset:0}.hYkIZq_spark{transform-origin:50%;background:linear-gradient(#ffeca0f2,#ffaa1400);border-radius:3px;grid-area:1/1;width:3px;height:30px;animation:.95s ease-out both hYkIZq_spark-fly}@keyframes hYkIZq_lever-jitter{0%,to{transform:rotate(-22deg)}50%{transform:rotate(-8deg)}}@keyframes hYkIZq_burst-flash{0%{opacity:0;transform:scale(.6)}18%{opacity:1}to{opacity:0;transform:scale(1.5)}}@keyframes hYkIZq_burst-ring{0%{opacity:.9;transform:scale(.2)}to{opacity:0;transform:scale(3.4)}}@keyframes hYkIZq_banner-slam{0%{opacity:0;transform:scale(3.6)rotate(-9deg)}55%{opacity:1;transform:scale(.94)rotate(1.5deg)}75%{transform:scale(1.06)rotate(-1deg)}to{opacity:1;transform:scale(1)rotate(0)}}@keyframes hYkIZq_banner-shake{0%,to{transform:translate(0)}25%{transform:translate(-9px)rotate(-.6deg)}75%{transform:translate(9px)rotate(.6deg)}}@keyframes hYkIZq_spark-fly{0%{opacity:0;transform:translateY(-40px)scaleY(.3)}18%{opacity:1}to{opacity:0;transform:translateY(-300px)scaleY(1.15)}}@keyframes hYkIZq_code-blink{0%,to{opacity:.35}50%{opacity:1}}@media (prefers-reduced-motion:reduce){.hYkIZq_arm,.hYkIZq_control,.hYkIZq_rod,.hYkIZq_knob{transition:none}.hYkIZq_lever[data-busy=true] .hYkIZq_arm,.hYkIZq_flash,.hYkIZq_ring,.hYkIZq_banner,.hYkIZq_code,.hYkIZq_spark{animation:none}.hYkIZq_burst{animation:.3s ease-out both hYkIZq_burst-flash}.hYkIZq_spark{display:none}}";
|
|
11
|
+
const tagId$1 = "@linxin666/dsh-liangshen/packages/dsh-liangshen/src/client/LiangShenLever.module.css";
|
|
12
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
|
|
13
13
|
const tag = document.createElement("style");
|
|
14
14
|
tag.dataset.plugin = "@linxin666/dsh-liangshen";
|
|
15
|
-
tag.dataset.pluginCss = tagId;
|
|
16
|
-
tag.textContent = css;
|
|
15
|
+
tag.dataset.pluginCss = tagId$1;
|
|
16
|
+
tag.textContent = css$1;
|
|
17
17
|
document.head.appendChild(tag);
|
|
18
18
|
}
|
|
19
19
|
var LiangShenLever_module_css_default = {
|
|
@@ -66,6 +66,14 @@ window.__ModuleLoader__.load({
|
|
|
66
66
|
const MORSE = "-.. . . .--. ... . . -.- / .... .- .-. -. . ... ...";
|
|
67
67
|
/** One spark per spoke of the burst. */
|
|
68
68
|
const SPARKS = Array.from({ length: 14 }, (_, index) => index);
|
|
69
|
+
/** Sync the hero preset chip above the composer so both controls always agree. */
|
|
70
|
+
function syncHeroChip(label) {
|
|
71
|
+
try {
|
|
72
|
+
if (typeof document === "undefined") return;
|
|
73
|
+
const chip = document.querySelector("button[aria-haspopup=\"menu\"] span[class*=\"seatLabel\"]") ?? Array.from(document.querySelectorAll("button[aria-haspopup=\"menu\"] span")).find((s) => s.className.includes("seatLabel"));
|
|
74
|
+
if (chip && chip.textContent !== label) chip.textContent = label;
|
|
75
|
+
} catch {}
|
|
76
|
+
}
|
|
69
77
|
/** Slot entry for `conversation.input.right` (left of the model selector). */
|
|
70
78
|
function LiangShenLever(face) {
|
|
71
79
|
const { state, restoreLabel, busy, error, burst } = (0, react.useSyncExternalStore)(face.store.subscribe, face.store.getSnapshot);
|
|
@@ -88,7 +96,17 @@ window.__ModuleLoader__.load({
|
|
|
88
96
|
clearTimeout(timer);
|
|
89
97
|
};
|
|
90
98
|
}, [burstKey]);
|
|
91
|
-
|
|
99
|
+
const prevState = (0, react.useRef)(state);
|
|
100
|
+
(0, react.useEffect)(() => {
|
|
101
|
+
if (state === "on") syncHeroChip(face.t("lever.name"));
|
|
102
|
+
else if (prevState.current === "on" && state === "off" && restoreLabel !== "") syncHeroChip(restoreLabel);
|
|
103
|
+
prevState.current = state;
|
|
104
|
+
}, [
|
|
105
|
+
state,
|
|
106
|
+
restoreLabel,
|
|
107
|
+
face
|
|
108
|
+
]);
|
|
109
|
+
if (state === "locked" || state === "missing" || state === "on" && restoreLabel === "") return null;
|
|
92
110
|
const toggle = () => {
|
|
93
111
|
if (!actionable) return;
|
|
94
112
|
if (on) face.push();
|
|
@@ -97,21 +115,23 @@ window.__ModuleLoader__.load({
|
|
|
97
115
|
const onPointerDown = (event) => {
|
|
98
116
|
if (!actionable) return;
|
|
99
117
|
drag.current = {
|
|
118
|
+
x: event.clientX,
|
|
100
119
|
y: event.clientY,
|
|
101
120
|
fired: false
|
|
102
121
|
};
|
|
103
|
-
|
|
122
|
+
try {
|
|
123
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
124
|
+
} catch {}
|
|
104
125
|
};
|
|
105
126
|
const onPointerMove = (event) => {
|
|
106
127
|
const pending = drag.current;
|
|
107
128
|
if (pending === void 0 || pending.fired) return;
|
|
108
|
-
const
|
|
109
|
-
|
|
129
|
+
const travelY = event.clientY - pending.y;
|
|
130
|
+
const travelX = event.clientX - pending.x;
|
|
131
|
+
if (Math.hypot(travelX, travelY) >= DRAG_THRESHOLD_PX) {
|
|
110
132
|
pending.fired = true;
|
|
111
|
-
face.
|
|
112
|
-
|
|
113
|
-
pending.fired = true;
|
|
114
|
-
face.push();
|
|
133
|
+
if (on) face.push();
|
|
134
|
+
else face.pull();
|
|
115
135
|
}
|
|
116
136
|
};
|
|
117
137
|
const onPointerUp = () => {
|
|
@@ -236,6 +256,21 @@ window.__ModuleLoader__.load({
|
|
|
236
256
|
});
|
|
237
257
|
}
|
|
238
258
|
//#endregion
|
|
259
|
+
//#region src/client/main-session.ts
|
|
260
|
+
/**
|
|
261
|
+
* Resolve the Session the main view currently shows.
|
|
262
|
+
*
|
|
263
|
+
* Reads the catalog's rows rather than a per-id retain-info source: ownership
|
|
264
|
+
* counts ride the list snapshot, so this neither allocates observers nor opens
|
|
265
|
+
* history, and a subscription to the list still fires when the selection moves.
|
|
266
|
+
* @param byId - the session catalog's rows (`SessionListState.byId`), when available.
|
|
267
|
+
* @returns the main-view session id, or undefined when the main view shows none.
|
|
268
|
+
*/
|
|
269
|
+
function mainViewSessionId(byId) {
|
|
270
|
+
if (byId === void 0 || byId === null) return void 0;
|
|
271
|
+
for (const row of Object.values(byId)) if (row !== void 0 && (row.retainedBy?.mainView ?? 0) > 0) return row.id;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
239
274
|
//#region \0dsh-store-engine
|
|
240
275
|
const platform = ["@deepseek-ai/dsh-client", "-store"].join("");
|
|
241
276
|
const legacy = ["@deepseek-ai/dsh-client-runtime", "/client"].join("");
|
|
@@ -274,20 +309,36 @@ window.__ModuleLoader__.load({
|
|
|
274
309
|
}
|
|
275
310
|
/**
|
|
276
311
|
* The preset a push-up restores: the preset the user was on before pulling the
|
|
277
|
-
* lever, else the deployment default
|
|
278
|
-
* LiangShen preset
|
|
279
|
-
* no
|
|
312
|
+
* lever, else the deployment default, else the first usable roster row that is
|
|
313
|
+
* not the LiangShen preset. A candidate is skipped when it is the LiangShen
|
|
314
|
+
* preset itself (restoring it would be a no-op) or when the roster no longer
|
|
315
|
+
* supplies it. That last resort is what keeps the push direction alive when the
|
|
316
|
+
* deployment default IS LiangShen mode: `fallback` is skipped then, and after a
|
|
317
|
+
* reload `previous` is gone, so without it the gesture would have no target.
|
|
280
318
|
*/
|
|
281
319
|
function restoreTarget(facts) {
|
|
282
320
|
for (const candidate of [facts.previous, facts.fallback]) {
|
|
283
321
|
if (candidate === void 0 || candidate === "liangshen") continue;
|
|
284
322
|
if (facts.available.includes(candidate)) return candidate;
|
|
285
323
|
}
|
|
324
|
+
return facts.available.find((candidate) => candidate !== LIANGSHEN_PRESET_ID);
|
|
286
325
|
}
|
|
287
326
|
/** Whether the lever can act at all in its current state. */
|
|
288
327
|
function isActionable(state) {
|
|
289
328
|
return state === "on" || state === "off";
|
|
290
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Settings entry ids whose writes can move the roster this lever reads: the
|
|
332
|
+
* agent-preset registry's own entry (its default and selection policy) and this
|
|
333
|
+
* plugin's row under either install shape — the aggregate's generated row id
|
|
334
|
+
* and the standalone row id — because disabling the plugin unregisters the
|
|
335
|
+
* preset it declares.
|
|
336
|
+
*/
|
|
337
|
+
const ROSTER_SETTINGS_ENTRY_IDS = [
|
|
338
|
+
"agent-preset-registry",
|
|
339
|
+
"web-ui-liangshen",
|
|
340
|
+
"liangshen"
|
|
341
|
+
];
|
|
291
342
|
/** Read the preset a session summary reports, when it reports one. */
|
|
292
343
|
function presetOf(session) {
|
|
293
344
|
const value = session?.projectionValues?.["agentPreset"];
|
|
@@ -337,7 +388,7 @@ window.__ModuleLoader__.load({
|
|
|
337
388
|
}));
|
|
338
389
|
const remote = readService(() => this.ctx.remote);
|
|
339
390
|
if (typeof remote?.$on === "function") this.disposers.push(remote.$on("settings/document-updated", (ns) => {
|
|
340
|
-
if (ns
|
|
391
|
+
if (ROSTER_SETTINGS_ENTRY_IDS.includes(ns)) this.load();
|
|
341
392
|
}));
|
|
342
393
|
this.refresh();
|
|
343
394
|
if (this.remote !== void 0) this.load();
|
|
@@ -439,7 +490,10 @@ window.__ModuleLoader__.load({
|
|
|
439
490
|
this.refresh();
|
|
440
491
|
return;
|
|
441
492
|
}
|
|
442
|
-
|
|
493
|
+
if (direction === "down") {
|
|
494
|
+
const prev = facts.agentPreset ?? this.detectPreset();
|
|
495
|
+
if (prev !== void 0 && prev !== "liangshen") this.rememberPrevious(prev);
|
|
496
|
+
}
|
|
443
497
|
const next = this.store.getSnapshot();
|
|
444
498
|
this.store.set({
|
|
445
499
|
...next,
|
|
@@ -449,26 +503,56 @@ window.__ModuleLoader__.load({
|
|
|
449
503
|
});
|
|
450
504
|
this.refresh();
|
|
451
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Try to detect the active preset from the DOM hero chip or storage
|
|
508
|
+
* when session.projectionValues.agentPreset is absent.
|
|
509
|
+
*/
|
|
510
|
+
detectPreset() {
|
|
511
|
+
try {
|
|
512
|
+
if (typeof document !== "undefined") {
|
|
513
|
+
const text = (document.querySelector("button[aria-haspopup=\"menu\"] span[class*=\"seatLabel\"]") ?? Array.from(document.querySelectorAll("button[aria-haspopup=\"menu\"] span")).find((s) => s.className.includes("seatLabel")))?.textContent?.trim();
|
|
514
|
+
if (text) {
|
|
515
|
+
const matched = this.rows.find((row) => (row.name === text || row.id === text) && row.id !== "liangshen");
|
|
516
|
+
if (matched) return matched.id;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
} catch {}
|
|
520
|
+
try {
|
|
521
|
+
if (typeof sessionStorage !== "undefined") {
|
|
522
|
+
const stored = sessionStorage.getItem("dsh-liangshen:previous-preset");
|
|
523
|
+
if (stored && stored !== "liangshen" && this.rows.some((r) => r.id === stored)) return stored;
|
|
524
|
+
}
|
|
525
|
+
} catch {}
|
|
526
|
+
}
|
|
527
|
+
rememberPrevious(presetId) {
|
|
528
|
+
if (presetId === void 0 || presetId === "liangshen") return;
|
|
529
|
+
this.previous = presetId;
|
|
530
|
+
try {
|
|
531
|
+
if (typeof sessionStorage !== "undefined") sessionStorage.setItem("dsh-liangshen:previous-preset", presetId);
|
|
532
|
+
} catch {}
|
|
533
|
+
}
|
|
452
534
|
/** The facts one decision reads, from the live session and the roster. */
|
|
453
535
|
facts() {
|
|
454
536
|
const summary = this.currentSession();
|
|
455
537
|
const available = this.rows.filter((row) => row.broken === void 0).map((row) => row.id);
|
|
456
538
|
const fallback = this.rows.find((row) => row.isDefault)?.id;
|
|
539
|
+
const currentPreset = presetOf(summary);
|
|
540
|
+
if (currentPreset !== void 0 && currentPreset !== "liangshen") this.rememberPrevious(currentPreset);
|
|
541
|
+
const previous = this.previous ?? this.detectPreset();
|
|
457
542
|
return {
|
|
458
543
|
blank: summary?.blank === true,
|
|
459
|
-
agentPreset:
|
|
544
|
+
agentPreset: currentPreset,
|
|
460
545
|
available,
|
|
461
546
|
fallback,
|
|
462
|
-
previous
|
|
547
|
+
previous
|
|
463
548
|
};
|
|
464
549
|
}
|
|
465
550
|
currentSessionId() {
|
|
466
|
-
|
|
467
|
-
return current === void 0 ? void 0 : String(current);
|
|
551
|
+
return mainViewSessionId(this.sessions?.list.getSnapshot().byId);
|
|
468
552
|
}
|
|
469
553
|
currentSession() {
|
|
470
554
|
const state = this.sessions?.list.getSnapshot();
|
|
471
|
-
const current = state?.
|
|
555
|
+
const current = mainViewSessionId(state?.byId);
|
|
472
556
|
if (state === void 0 || current === void 0) return void 0;
|
|
473
557
|
return state.byId[current];
|
|
474
558
|
}
|
|
@@ -528,6 +612,1029 @@ window.__ModuleLoader__.load({
|
|
|
528
612
|
return error instanceof Error ? error.message : String(error);
|
|
529
613
|
}
|
|
530
614
|
//#endregion
|
|
615
|
+
//#region \0dsh-css:packages/dsh-liangshen/src/client/settings-card.module.css.mjs
|
|
616
|
+
const css = "._9t79wq_card{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}._9t79wq_card:hover{border-color:var(--dsw-alias-label-dimmed)}._9t79wq_cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}._9t79wq_header{appearance:none;box-sizing:border-box;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}._9t79wq_header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}._9t79wq_headerStatic{box-sizing:border-box;border-radius:12px;align-items:center;gap:12px;width:100%;padding:14px 16px;display:flex}._9t79wq_headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}._9t79wq_name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}._9t79wq_description{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:1.5}._9t79wq_pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._9t79wq_chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}._9t79wq_chevronOpen{transform:rotate(180deg)}._9t79wq_body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}._9t79wq_readOnly{color:var(--dsw-alias-label-secondary);margin:12px 0 0;font-size:12px;line-height:1.5}._9t79wq_notExposed{color:var(--dsw-alias-state-warn-primary);margin:12px 0 0;font-size:12px;line-height:1.5}._9t79wq_footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex}._9t79wq_failed{min-width:0;color:var(--dsw-alias-state-error-primary,#b42318);text-overflow:ellipsis;white-space:nowrap;flex:1;margin:0;font-size:12px;line-height:1.5;overflow:hidden}._9t79wq_discard,._9t79wq_save{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}._9t79wq_discard{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}._9t79wq_discard:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}._9t79wq_save{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}._9t79wq_discard:disabled,._9t79wq_save:disabled{opacity:.4;cursor:default}._9t79wq_discard:focus-visible,._9t79wq_save:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}._9t79wq_field{flex-direction:column;gap:6px;padding:12px 0;display:flex}._9t79wq_field+._9t79wq_field{border-top:1px solid var(--dsw-alias-border-l2)}._9t79wq_head{align-items:center;gap:8px;display:flex}._9t79wq_label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}._9t79wq_badges{align-items:center;gap:8px;display:inline-flex}._9t79wq_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}._9t79wq_reset{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;padding:0;font-size:12px;line-height:1.5}._9t79wq_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}._9t79wq_reset:disabled{cursor:default}._9t79wq_reset:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px;outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}._9t79wq_input,._9t79wq_select{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}._9t79wq_input:focus-visible,._9t79wq_select:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}._9t79wq_input:disabled,._9t79wq_select:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}._9t79wq_inputInvalid{border:1px solid var(--dsw-alias-state-error-primary,#b42318);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}._9t79wq_inputInvalid:focus-visible{outline:2px solid var(--dsw-alias-state-error-primary,#b42318);outline-offset:1px;border-color:var(--dsw-alias-state-error-primary,#b42318)}._9t79wq_selectWrap{position:relative}._9t79wq_selectButton{appearance:none;text-align:left;cursor:pointer;justify-content:space-between;align-items:center;gap:8px;width:100%;display:flex}._9t79wq_selectLabel{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}._9t79wq_selectChevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}._9t79wq_selectChevronOpen{transform:rotate(180deg)}._9t79wq_selectPopup{z-index:40;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);max-height:240px;box-shadow:0 8px 24px var(--dsw-alias-bg-mask-2);opacity:0;border-radius:8px;flex-direction:column;padding:4px;transition:opacity .1s,transform .1s;display:flex;position:absolute;top:calc(100% + 4px);left:0;right:0;overflow-y:auto;transform:translateY(-4px)}._9t79wq_selectPopupOpen{opacity:1;transform:none}._9t79wq_selectPopupClose{opacity:0;pointer-events:none;transform:translateY(-4px)}._9t79wq_selectOption{color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;border-radius:6px;flex-shrink:0;padding:6px 10px;font-size:13px;line-height:1.5;overflow:hidden}._9t79wq_selectOption:hover,._9t79wq_selectOptionActive{background:var(--dsw-alias-interactive-bg-hover)}._9t79wq_selectOptionSelected{color:var(--dsw-alias-brand-primary);background:color-mix(in srgb, var(--dsw-alias-brand-primary-new-colorprimary-new-color) 10%, transparent);font-weight:500}._9t79wq_invalid{color:var(--dsw-alias-state-error-primary,#b42318);margin:0;font-size:12px;line-height:1.5}._9t79wq_hint{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px;line-height:1.5}@media (prefers-reduced-motion:reduce){._9t79wq_card,._9t79wq_header,._9t79wq_chevron,._9t79wq_chevronOpen,._9t79wq_discard,._9t79wq_save,._9t79wq_selectChevron,._9t79wq_selectChevronOpen,._9t79wq_selectPopup{transition:none}}";
|
|
617
|
+
const tagId = "@linxin666/dsh-liangshen/packages/dsh-liangshen/src/client/settings-card.module.css";
|
|
618
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
619
|
+
const tag = document.createElement("style");
|
|
620
|
+
tag.dataset.plugin = "@linxin666/dsh-liangshen";
|
|
621
|
+
tag.dataset.pluginCss = tagId;
|
|
622
|
+
tag.textContent = css;
|
|
623
|
+
document.head.appendChild(tag);
|
|
624
|
+
}
|
|
625
|
+
var settings_card_module_css_default = {
|
|
626
|
+
"badge": "_9t79wq_badge",
|
|
627
|
+
"badges": "_9t79wq_badges",
|
|
628
|
+
"body": "_9t79wq_body",
|
|
629
|
+
"card": "_9t79wq_card",
|
|
630
|
+
"cardOpen": "_9t79wq_cardOpen",
|
|
631
|
+
"chevron": "_9t79wq_chevron",
|
|
632
|
+
"chevronOpen": "_9t79wq_chevronOpen",
|
|
633
|
+
"description": "_9t79wq_description",
|
|
634
|
+
"discard": "_9t79wq_discard",
|
|
635
|
+
"failed": "_9t79wq_failed",
|
|
636
|
+
"field": "_9t79wq_field",
|
|
637
|
+
"footer": "_9t79wq_footer",
|
|
638
|
+
"head": "_9t79wq_head",
|
|
639
|
+
"headText": "_9t79wq_headText",
|
|
640
|
+
"header": "_9t79wq_header",
|
|
641
|
+
"headerStatic": "_9t79wq_headerStatic",
|
|
642
|
+
"hint": "_9t79wq_hint",
|
|
643
|
+
"input": "_9t79wq_input",
|
|
644
|
+
"inputInvalid": "_9t79wq_inputInvalid",
|
|
645
|
+
"invalid": "_9t79wq_invalid",
|
|
646
|
+
"label": "_9t79wq_label",
|
|
647
|
+
"name": "_9t79wq_name",
|
|
648
|
+
"notExposed": "_9t79wq_notExposed",
|
|
649
|
+
"pending": "_9t79wq_pending",
|
|
650
|
+
"readOnly": "_9t79wq_readOnly",
|
|
651
|
+
"reset": "_9t79wq_reset",
|
|
652
|
+
"save": "_9t79wq_save",
|
|
653
|
+
"select": "_9t79wq_select",
|
|
654
|
+
"selectButton": "_9t79wq_selectButton",
|
|
655
|
+
"selectChevron": "_9t79wq_selectChevron",
|
|
656
|
+
"selectChevronOpen": "_9t79wq_selectChevronOpen",
|
|
657
|
+
"selectLabel": "_9t79wq_selectLabel",
|
|
658
|
+
"selectOption": "_9t79wq_selectOption",
|
|
659
|
+
"selectOptionActive": "_9t79wq_selectOptionActive",
|
|
660
|
+
"selectOptionSelected": "_9t79wq_selectOptionSelected",
|
|
661
|
+
"selectPopup": "_9t79wq_selectPopup",
|
|
662
|
+
"selectPopupClose": "_9t79wq_selectPopupClose",
|
|
663
|
+
"selectPopupOpen": "_9t79wq_selectPopupOpen",
|
|
664
|
+
"selectWrap": "_9t79wq_selectWrap"
|
|
665
|
+
};
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region src/client/PluginSettingsCard.tsx
|
|
668
|
+
/**
|
|
669
|
+
* Family-shared chrome for plugin settings cards: a disclosure header naming
|
|
670
|
+
* the plugin and what its settings govern, the controls inside, and the save
|
|
671
|
+
* that writes them. Renders nothing while the namespace is unavailable — a
|
|
672
|
+
* deployment that does not compose the owning plugin should show no trace of
|
|
673
|
+
* it. Inlined into each consumer's client bundle; mirrors the official
|
|
674
|
+
* ui-plugin-config PluginCard in a self-contained slice.
|
|
675
|
+
*/
|
|
676
|
+
/**
|
|
677
|
+
* Render one plugin settings card.
|
|
678
|
+
* @param props - the plugin's copy keys, its form state, and its controls.
|
|
679
|
+
* @returns the card, or nothing while the namespace is still loading.
|
|
680
|
+
*/
|
|
681
|
+
function PluginSettingsCard(props) {
|
|
682
|
+
const [open, setOpen] = (0, react.useState)(props.defaultOpen ?? true);
|
|
683
|
+
const { state, alwaysOpen } = props;
|
|
684
|
+
if (!state.available) return null;
|
|
685
|
+
const title = props.t(props.titleKey);
|
|
686
|
+
const description = props.t(props.descriptionKey);
|
|
687
|
+
const blocked = !state.dirty || state.invalid || state.saving;
|
|
688
|
+
const expanded = alwaysOpen === true || open;
|
|
689
|
+
const cardClass = expanded ? `${settings_card_module_css_default.cardOpen} ${settings_card_module_css_default.card}` : settings_card_module_css_default.card;
|
|
690
|
+
const header = alwaysOpen === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
691
|
+
className: settings_card_module_css_default.headerStatic,
|
|
692
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
693
|
+
className: settings_card_module_css_default.headText,
|
|
694
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
695
|
+
className: settings_card_module_css_default.name,
|
|
696
|
+
title,
|
|
697
|
+
children: title
|
|
698
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
699
|
+
className: settings_card_module_css_default.description,
|
|
700
|
+
title: description,
|
|
701
|
+
children: props.descriptionNode ?? description
|
|
702
|
+
})]
|
|
703
|
+
}), state.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
704
|
+
className: settings_card_module_css_default.pending,
|
|
705
|
+
title: props.t("settings.unsaved"),
|
|
706
|
+
children: props.t("settings.unsaved")
|
|
707
|
+
}) : null]
|
|
708
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
709
|
+
type: "button",
|
|
710
|
+
className: settings_card_module_css_default.header,
|
|
711
|
+
"aria-expanded": open,
|
|
712
|
+
"aria-label": `${props.t(open ? "settings.collapse" : "settings.expand")}: ${title}`,
|
|
713
|
+
onClick: () => {
|
|
714
|
+
setOpen(!open);
|
|
715
|
+
},
|
|
716
|
+
children: [
|
|
717
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
718
|
+
className: settings_card_module_css_default.headText,
|
|
719
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
720
|
+
className: settings_card_module_css_default.name,
|
|
721
|
+
title,
|
|
722
|
+
children: title
|
|
723
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
724
|
+
className: settings_card_module_css_default.description,
|
|
725
|
+
title: description,
|
|
726
|
+
children: props.descriptionNode ?? description
|
|
727
|
+
})]
|
|
728
|
+
}),
|
|
729
|
+
state.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
730
|
+
className: settings_card_module_css_default.pending,
|
|
731
|
+
title: props.t("settings.unsaved"),
|
|
732
|
+
children: props.t("settings.unsaved")
|
|
733
|
+
}) : null,
|
|
734
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
735
|
+
width: "14",
|
|
736
|
+
height: "14",
|
|
737
|
+
viewBox: "0 0 14 14",
|
|
738
|
+
fill: "none",
|
|
739
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
740
|
+
className: open ? `${settings_card_module_css_default.chevron} ${settings_card_module_css_default.chevronOpen}` : settings_card_module_css_default.chevron,
|
|
741
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
742
|
+
d: "M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z",
|
|
743
|
+
fill: "currentColor"
|
|
744
|
+
})
|
|
745
|
+
})
|
|
746
|
+
]
|
|
747
|
+
});
|
|
748
|
+
if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
|
|
749
|
+
const showNotice = props.hideNotExposedNotice !== true;
|
|
750
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
751
|
+
className: cardClass,
|
|
752
|
+
children: [header, expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
753
|
+
className: settings_card_module_css_default.body,
|
|
754
|
+
children: showNotice ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
755
|
+
className: settings_card_module_css_default.notExposed,
|
|
756
|
+
role: "status",
|
|
757
|
+
children: props.t("settings.notExposed")
|
|
758
|
+
}) : null
|
|
759
|
+
}) : null]
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
763
|
+
className: cardClass,
|
|
764
|
+
children: [header, expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
765
|
+
className: settings_card_module_css_default.body,
|
|
766
|
+
children: [
|
|
767
|
+
!state.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
768
|
+
className: settings_card_module_css_default.readOnly,
|
|
769
|
+
role: "status",
|
|
770
|
+
children: props.t("settings.readOnly")
|
|
771
|
+
}) : null,
|
|
772
|
+
props.children,
|
|
773
|
+
props.hideFooter === true ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
774
|
+
className: settings_card_module_css_default.footer,
|
|
775
|
+
children: [
|
|
776
|
+
state.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
777
|
+
className: settings_card_module_css_default.failed,
|
|
778
|
+
role: "status",
|
|
779
|
+
children: [props.t("settings.saveFailed"), state.failedReason ? " - " + state.failedReason : ""]
|
|
780
|
+
}) : null,
|
|
781
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
782
|
+
type: "button",
|
|
783
|
+
className: settings_card_module_css_default.discard,
|
|
784
|
+
disabled: !state.dirty || state.saving,
|
|
785
|
+
onClick: props.onDiscard,
|
|
786
|
+
children: props.t("settings.discard")
|
|
787
|
+
}),
|
|
788
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
789
|
+
type: "button",
|
|
790
|
+
className: settings_card_module_css_default.save,
|
|
791
|
+
disabled: blocked,
|
|
792
|
+
onClick: props.onSave,
|
|
793
|
+
children: props.t(!state.saving ? "settings.save" : "settings.saving")
|
|
794
|
+
})
|
|
795
|
+
]
|
|
796
|
+
})
|
|
797
|
+
]
|
|
798
|
+
}) : null]
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
/** A staged value field. `numeric` only hints the keypad: which drafts a field accepts is decided by its spec. */
|
|
802
|
+
function ValueField(props) {
|
|
803
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
804
|
+
className: settings_card_module_css_default.field,
|
|
805
|
+
children: [
|
|
806
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
807
|
+
className: settings_card_module_css_default.head,
|
|
808
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
809
|
+
className: settings_card_module_css_default.label,
|
|
810
|
+
htmlFor: props.id,
|
|
811
|
+
children: props.label
|
|
812
|
+
}), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
813
|
+
className: settings_card_module_css_default.badges,
|
|
814
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
815
|
+
className: settings_card_module_css_default.badge,
|
|
816
|
+
children: props.overriddenLabel
|
|
817
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
818
|
+
type: "button",
|
|
819
|
+
className: settings_card_module_css_default.reset,
|
|
820
|
+
disabled: props.disabled,
|
|
821
|
+
onClick: props.onReset,
|
|
822
|
+
children: props.resetLabel
|
|
823
|
+
})]
|
|
824
|
+
}) : null]
|
|
825
|
+
}),
|
|
826
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
827
|
+
id: props.id,
|
|
828
|
+
className: props.invalid ? settings_card_module_css_default.inputInvalid : settings_card_module_css_default.input,
|
|
829
|
+
type: "text",
|
|
830
|
+
...props.numeric === true ? { inputMode: "numeric" } : {},
|
|
831
|
+
...props.invalid ? { "aria-invalid": true } : {},
|
|
832
|
+
value: props.text,
|
|
833
|
+
placeholder: props.placeholder ?? "",
|
|
834
|
+
disabled: props.disabled,
|
|
835
|
+
onChange: (event) => {
|
|
836
|
+
props.onEdit(event.target.value);
|
|
837
|
+
}
|
|
838
|
+
}),
|
|
839
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
840
|
+
className: props.invalid ? settings_card_module_css_default.invalid : settings_card_module_css_default.hint,
|
|
841
|
+
children: props.invalid ? props.invalidLabel : props.hint
|
|
842
|
+
})
|
|
843
|
+
]
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
const NON_SKIN_BODY_MARKERS = /* @__PURE__ */ new Set(["dshSkinCenter", "dshSidebarCollapsed"]);
|
|
847
|
+
function isSkinActive() {
|
|
848
|
+
return Object.keys(document.body.dataset).some((key) => key.startsWith("dsh") && !NON_SKIN_BODY_MARKERS.has(key));
|
|
849
|
+
}
|
|
850
|
+
const SELECT_CLOSE_MS = 100;
|
|
851
|
+
/**
|
|
852
|
+
* The shared dual-mode select control. While an appearance skin is active it
|
|
853
|
+
* renders the legacy native `<select>` untouched, so element-level skin
|
|
854
|
+
* selectors keep working; under the default appearance it renders a
|
|
855
|
+
* self-drawn `role="listbox"` popup whose open/close is transition-animated.
|
|
856
|
+
* Staged cards reach it through BooleanField/ChoiceField; immediate-apply
|
|
857
|
+
* editors (the side-card prefs) bind it directly through onEdit.
|
|
858
|
+
* 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
|
|
859
|
+
*/
|
|
860
|
+
function SelectField(props) {
|
|
861
|
+
const { id, options, value } = props;
|
|
862
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
863
|
+
const [closing, setClosing] = (0, react.useState)(false);
|
|
864
|
+
const [phase, setPhase] = (0, react.useState)("initial");
|
|
865
|
+
const [activeIndex, setActiveIndex] = (0, react.useState)(0);
|
|
866
|
+
const closeTimer = (0, react.useRef)(void 0);
|
|
867
|
+
const wrapRef = (0, react.useRef)(null);
|
|
868
|
+
const popupRef = (0, react.useRef)(null);
|
|
869
|
+
const currentIndex = () => {
|
|
870
|
+
const index = options.findIndex((option) => option.value === value);
|
|
871
|
+
return index >= 0 ? index : 0;
|
|
872
|
+
};
|
|
873
|
+
const close = (0, react.useCallback)(() => {
|
|
874
|
+
if (closeTimer.current !== void 0) clearTimeout(closeTimer.current);
|
|
875
|
+
setClosing(true);
|
|
876
|
+
closeTimer.current = setTimeout(() => {
|
|
877
|
+
setClosing(false);
|
|
878
|
+
setOpen(false);
|
|
879
|
+
}, SELECT_CLOSE_MS);
|
|
880
|
+
}, []);
|
|
881
|
+
const openPopup = () => {
|
|
882
|
+
if (closeTimer.current !== void 0) clearTimeout(closeTimer.current);
|
|
883
|
+
setActiveIndex(currentIndex());
|
|
884
|
+
setPhase("initial");
|
|
885
|
+
setClosing(false);
|
|
886
|
+
setOpen(true);
|
|
887
|
+
};
|
|
888
|
+
const commit = (index) => {
|
|
889
|
+
const option = options[index];
|
|
890
|
+
if (option) props.onEdit(option.value);
|
|
891
|
+
close();
|
|
892
|
+
};
|
|
893
|
+
const onTriggerClick = () => {
|
|
894
|
+
if (props.disabled) return;
|
|
895
|
+
if (open && !closing) close();
|
|
896
|
+
else openPopup();
|
|
897
|
+
};
|
|
898
|
+
const onKeyDown = (event) => {
|
|
899
|
+
if (props.disabled) return;
|
|
900
|
+
const count = options.length;
|
|
901
|
+
switch (event.key) {
|
|
902
|
+
case "ArrowDown":
|
|
903
|
+
case "ArrowUp":
|
|
904
|
+
case "Enter":
|
|
905
|
+
case " ":
|
|
906
|
+
event.preventDefault();
|
|
907
|
+
if (!open) openPopup();
|
|
908
|
+
else if (!closing) if (event.key === "ArrowDown") setActiveIndex((index) => (index + 1) % count);
|
|
909
|
+
else if (event.key === "ArrowUp") setActiveIndex((index) => (index - 1 + count) % count);
|
|
910
|
+
else commit(activeIndex);
|
|
911
|
+
break;
|
|
912
|
+
case "Escape":
|
|
913
|
+
if (open) {
|
|
914
|
+
event.preventDefault();
|
|
915
|
+
event.stopPropagation();
|
|
916
|
+
close();
|
|
917
|
+
}
|
|
918
|
+
break;
|
|
919
|
+
case "Tab":
|
|
920
|
+
if (open) close();
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
(0, react.useEffect)(() => () => {
|
|
925
|
+
if (closeTimer.current !== void 0) clearTimeout(closeTimer.current);
|
|
926
|
+
}, []);
|
|
927
|
+
(0, react.useLayoutEffect)(() => {
|
|
928
|
+
if (open && !closing && phase === "initial") {
|
|
929
|
+
popupRef.current?.offsetHeight;
|
|
930
|
+
setPhase("open");
|
|
931
|
+
}
|
|
932
|
+
}, [
|
|
933
|
+
open,
|
|
934
|
+
closing,
|
|
935
|
+
phase
|
|
936
|
+
]);
|
|
937
|
+
(0, react.useEffect)(() => {
|
|
938
|
+
if (!open) return;
|
|
939
|
+
const onPointerDown = (event) => {
|
|
940
|
+
const target = event.target;
|
|
941
|
+
if (target instanceof Node && !wrapRef.current?.contains(target)) close();
|
|
942
|
+
};
|
|
943
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
944
|
+
return () => document.removeEventListener("pointerdown", onPointerDown);
|
|
945
|
+
}, [open, close]);
|
|
946
|
+
(0, react.useEffect)(() => {
|
|
947
|
+
if (props.disabled && open) close();
|
|
948
|
+
}, [
|
|
949
|
+
props.disabled,
|
|
950
|
+
open,
|
|
951
|
+
close
|
|
952
|
+
]);
|
|
953
|
+
if (isSkinActive()) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
954
|
+
id,
|
|
955
|
+
className: settings_card_module_css_default.select,
|
|
956
|
+
value,
|
|
957
|
+
disabled: props.disabled,
|
|
958
|
+
onChange: (event) => {
|
|
959
|
+
props.onEdit(event.target.value);
|
|
960
|
+
},
|
|
961
|
+
children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
962
|
+
value: option.value,
|
|
963
|
+
children: option.label
|
|
964
|
+
}, option.value))
|
|
965
|
+
});
|
|
966
|
+
const label = options.find((option) => option.value === value)?.label ?? "";
|
|
967
|
+
const popupClass = closing ? `${settings_card_module_css_default.selectPopup} ${settings_card_module_css_default.selectPopupClose}` : phase === "open" ? `${settings_card_module_css_default.selectPopup} ${settings_card_module_css_default.selectPopupOpen}` : settings_card_module_css_default.selectPopup;
|
|
968
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
969
|
+
className: settings_card_module_css_default.selectWrap,
|
|
970
|
+
ref: wrapRef,
|
|
971
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
972
|
+
type: "button",
|
|
973
|
+
id,
|
|
974
|
+
className: `${settings_card_module_css_default.select} ${settings_card_module_css_default.selectButton}`,
|
|
975
|
+
disabled: props.disabled,
|
|
976
|
+
"aria-haspopup": "listbox",
|
|
977
|
+
"aria-expanded": open,
|
|
978
|
+
"aria-activedescendant": open ? `${id}-o${activeIndex}` : void 0,
|
|
979
|
+
"aria-invalid": props.invalid || void 0,
|
|
980
|
+
onClick: onTriggerClick,
|
|
981
|
+
onKeyDown,
|
|
982
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
983
|
+
className: settings_card_module_css_default.selectLabel,
|
|
984
|
+
children: label
|
|
985
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
986
|
+
width: "14",
|
|
987
|
+
height: "14",
|
|
988
|
+
viewBox: "0 0 14 14",
|
|
989
|
+
fill: "none",
|
|
990
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
991
|
+
className: open ? `${settings_card_module_css_default.selectChevron} ${settings_card_module_css_default.selectChevronOpen}` : settings_card_module_css_default.selectChevron,
|
|
992
|
+
"aria-hidden": "true",
|
|
993
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
994
|
+
d: "M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z",
|
|
995
|
+
fill: "currentColor"
|
|
996
|
+
})
|
|
997
|
+
})]
|
|
998
|
+
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
999
|
+
className: popupClass,
|
|
1000
|
+
role: "listbox",
|
|
1001
|
+
ref: popupRef,
|
|
1002
|
+
children: options.map((option, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1003
|
+
id: `${id}-o${index}`,
|
|
1004
|
+
role: "option",
|
|
1005
|
+
"aria-selected": option.value === value,
|
|
1006
|
+
className: `${settings_card_module_css_default.selectOption}${option.value === value ? ` ${settings_card_module_css_default.selectOptionSelected}` : ""}${index === activeIndex && !closing ? ` ${settings_card_module_css_default.selectOptionActive}` : ""}`,
|
|
1007
|
+
onClick: () => {
|
|
1008
|
+
commit(index);
|
|
1009
|
+
},
|
|
1010
|
+
children: option.label
|
|
1011
|
+
}, option.value))
|
|
1012
|
+
}) : null]
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
/** A staged boolean field: 继承 / 开 / 关. */
|
|
1016
|
+
function BooleanField(props) {
|
|
1017
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1018
|
+
className: settings_card_module_css_default.field,
|
|
1019
|
+
children: [
|
|
1020
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1021
|
+
className: settings_card_module_css_default.head,
|
|
1022
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
1023
|
+
className: settings_card_module_css_default.label,
|
|
1024
|
+
htmlFor: props.id,
|
|
1025
|
+
children: props.label
|
|
1026
|
+
}), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1027
|
+
className: settings_card_module_css_default.badges,
|
|
1028
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1029
|
+
className: settings_card_module_css_default.badge,
|
|
1030
|
+
children: props.overriddenLabel
|
|
1031
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1032
|
+
type: "button",
|
|
1033
|
+
className: settings_card_module_css_default.reset,
|
|
1034
|
+
disabled: props.disabled,
|
|
1035
|
+
onClick: props.onReset,
|
|
1036
|
+
children: props.resetLabel
|
|
1037
|
+
})]
|
|
1038
|
+
}) : null]
|
|
1039
|
+
}),
|
|
1040
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, {
|
|
1041
|
+
id: props.id,
|
|
1042
|
+
options: [
|
|
1043
|
+
{
|
|
1044
|
+
value: "",
|
|
1045
|
+
label: props.inheritLabel
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
value: "true",
|
|
1049
|
+
label: props.onLabel
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
value: "false",
|
|
1053
|
+
label: props.offLabel
|
|
1054
|
+
}
|
|
1055
|
+
],
|
|
1056
|
+
value: props.text,
|
|
1057
|
+
disabled: props.disabled,
|
|
1058
|
+
invalid: props.invalid,
|
|
1059
|
+
onEdit: props.onEdit
|
|
1060
|
+
}),
|
|
1061
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1062
|
+
className: settings_card_module_css_default.hint,
|
|
1063
|
+
children: props.hint
|
|
1064
|
+
})
|
|
1065
|
+
]
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
/** A staged enumerated field rendered as a select. */
|
|
1069
|
+
function ChoiceField(props) {
|
|
1070
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1071
|
+
className: settings_card_module_css_default.field,
|
|
1072
|
+
children: [
|
|
1073
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1074
|
+
className: settings_card_module_css_default.head,
|
|
1075
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
1076
|
+
className: settings_card_module_css_default.label,
|
|
1077
|
+
htmlFor: props.id,
|
|
1078
|
+
children: props.label
|
|
1079
|
+
}), props.overridden ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1080
|
+
className: settings_card_module_css_default.badges,
|
|
1081
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1082
|
+
className: settings_card_module_css_default.badge,
|
|
1083
|
+
children: props.overriddenLabel
|
|
1084
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1085
|
+
type: "button",
|
|
1086
|
+
className: settings_card_module_css_default.reset,
|
|
1087
|
+
disabled: props.disabled,
|
|
1088
|
+
onClick: props.onReset,
|
|
1089
|
+
children: props.resetLabel
|
|
1090
|
+
})]
|
|
1091
|
+
}) : null]
|
|
1092
|
+
}),
|
|
1093
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, {
|
|
1094
|
+
id: props.id,
|
|
1095
|
+
options: [{
|
|
1096
|
+
value: "",
|
|
1097
|
+
label: props.inheritLabel
|
|
1098
|
+
}, ...props.choices],
|
|
1099
|
+
value: props.text,
|
|
1100
|
+
disabled: props.disabled,
|
|
1101
|
+
invalid: props.invalid,
|
|
1102
|
+
onEdit: props.onEdit
|
|
1103
|
+
}),
|
|
1104
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1105
|
+
className: props.invalid ? settings_card_module_css_default.invalid : settings_card_module_css_default.hint,
|
|
1106
|
+
children: props.invalid ? props.invalidLabel : props.hint
|
|
1107
|
+
})
|
|
1108
|
+
]
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/client/settings-form.ts
|
|
1113
|
+
/** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints blocks the save. */
|
|
1114
|
+
function numberField(field, constraints = {}) {
|
|
1115
|
+
const { integer = false, min } = constraints;
|
|
1116
|
+
return {
|
|
1117
|
+
field,
|
|
1118
|
+
format: (value) => typeof value === "number" ? String(value) : "",
|
|
1119
|
+
parse: (text) => {
|
|
1120
|
+
const trimmed = text.trim();
|
|
1121
|
+
if (trimmed === "") return { kind: "clear" };
|
|
1122
|
+
const parsed = Number(trimmed);
|
|
1123
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
1124
|
+
if (integer && !Number.isInteger(parsed)) return void 0;
|
|
1125
|
+
if (min !== void 0 && parsed < min) return void 0;
|
|
1126
|
+
return {
|
|
1127
|
+
kind: "set",
|
|
1128
|
+
value: parsed
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
/** A boolean field, edited through true/false draft text. */
|
|
1134
|
+
function booleanField(field) {
|
|
1135
|
+
return {
|
|
1136
|
+
field,
|
|
1137
|
+
format: (value) => typeof value === "boolean" ? String(value) : "",
|
|
1138
|
+
parse: (text) => {
|
|
1139
|
+
const trimmed = text.trim();
|
|
1140
|
+
if (trimmed === "") return { kind: "clear" };
|
|
1141
|
+
if (trimmed === "true") return {
|
|
1142
|
+
kind: "set",
|
|
1143
|
+
value: true
|
|
1144
|
+
};
|
|
1145
|
+
if (trimmed === "false") return {
|
|
1146
|
+
kind: "set",
|
|
1147
|
+
value: false
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
/** An enumerated string field; only the listed choices are accepted. An empty draft clears the field. */
|
|
1153
|
+
function choiceField(field, choices) {
|
|
1154
|
+
return {
|
|
1155
|
+
field,
|
|
1156
|
+
format: (value) => typeof value === "string" && choices.includes(value) ? value : "",
|
|
1157
|
+
parse: (text) => {
|
|
1158
|
+
if (text === "") return { kind: "clear" };
|
|
1159
|
+
return choices.includes(text) ? {
|
|
1160
|
+
kind: "set",
|
|
1161
|
+
value: text
|
|
1162
|
+
} : void 0;
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Stages one card's edits over one settings namespace and writes them on save.
|
|
1168
|
+
*
|
|
1169
|
+
* The Host is the only authority on whether a value was accepted — its
|
|
1170
|
+
* validators own the constraints no schema can express — so the outcome is
|
|
1171
|
+
* read back from the section rather than predicted here. A save that did not
|
|
1172
|
+
* land keeps its drafts, so the user can correct them instead of retyping.
|
|
1173
|
+
*/
|
|
1174
|
+
var CardForm = class {
|
|
1175
|
+
scope;
|
|
1176
|
+
specs;
|
|
1177
|
+
staged = /* @__PURE__ */ new Map();
|
|
1178
|
+
listeners = /* @__PURE__ */ new Set();
|
|
1179
|
+
/** The form subscription installed in the constructor; released by dispose(). */
|
|
1180
|
+
disposeForm;
|
|
1181
|
+
disposed = false;
|
|
1182
|
+
saving = false;
|
|
1183
|
+
failed = false;
|
|
1184
|
+
failedReason;
|
|
1185
|
+
/** @param scope - the bound configuration form for this card's namespace. */
|
|
1186
|
+
constructor(scope, specs) {
|
|
1187
|
+
this.scope = scope;
|
|
1188
|
+
this.specs = new Map(specs.map((spec) => [spec.field, spec]));
|
|
1189
|
+
this.disposeForm = scope.subscribe(() => {
|
|
1190
|
+
this.publish();
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Release the form subscription and every bound store listener. The card
|
|
1195
|
+
* must call this on teardown; later calls are no-ops.
|
|
1196
|
+
*/
|
|
1197
|
+
dispose() {
|
|
1198
|
+
if (this.disposed) return;
|
|
1199
|
+
this.disposed = true;
|
|
1200
|
+
this.disposeForm();
|
|
1201
|
+
this.listeners.clear();
|
|
1202
|
+
}
|
|
1203
|
+
/** Publish a projection of this form, rebuilt whenever the form or a draft changes. */
|
|
1204
|
+
bind(project) {
|
|
1205
|
+
const store = createSnapshotStore(project());
|
|
1206
|
+
this.listeners.add(() => {
|
|
1207
|
+
store.set(project());
|
|
1208
|
+
});
|
|
1209
|
+
return store;
|
|
1210
|
+
}
|
|
1211
|
+
/** Read the card-level state: what the Host serves, and what a save would do. */
|
|
1212
|
+
shell() {
|
|
1213
|
+
const snapshot = this.scope.getSnapshot();
|
|
1214
|
+
const plan = this.plan();
|
|
1215
|
+
return {
|
|
1216
|
+
available: snapshot.status !== "loading",
|
|
1217
|
+
exposed: snapshot.status === "ready",
|
|
1218
|
+
writable: snapshot.writable,
|
|
1219
|
+
dirty: plan.length > 0,
|
|
1220
|
+
invalid: plan.some((item) => item.judge === void 0),
|
|
1221
|
+
saving: this.saving,
|
|
1222
|
+
failed: this.failed,
|
|
1223
|
+
...this.failedReason === void 0 ? {} : { failedReason: this.failedReason }
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
/** Read one field's state from the effective section and its staged draft. */
|
|
1227
|
+
field(field) {
|
|
1228
|
+
const spec = this.specOf(field);
|
|
1229
|
+
const staged = this.staged.get(field);
|
|
1230
|
+
if (staged === void 0) return {
|
|
1231
|
+
text: spec.format(this.sectionValue(field)),
|
|
1232
|
+
overridden: this.stored(field),
|
|
1233
|
+
invalid: false
|
|
1234
|
+
};
|
|
1235
|
+
const write = staged.clear ? { kind: "clear" } : spec.parse(staged.text);
|
|
1236
|
+
return {
|
|
1237
|
+
text: staged.text,
|
|
1238
|
+
overridden: write?.kind === "set",
|
|
1239
|
+
invalid: write === void 0
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
/** The actions the card's slot registration injects. */
|
|
1243
|
+
actions() {
|
|
1244
|
+
return {
|
|
1245
|
+
edit: (field, text) => {
|
|
1246
|
+
this.stage(field, {
|
|
1247
|
+
text,
|
|
1248
|
+
clear: false
|
|
1249
|
+
});
|
|
1250
|
+
},
|
|
1251
|
+
resetField: (field) => {
|
|
1252
|
+
this.stage(field, {
|
|
1253
|
+
text: this.specOf(field).format(this.baseValue(field)),
|
|
1254
|
+
clear: true
|
|
1255
|
+
});
|
|
1256
|
+
},
|
|
1257
|
+
save: () => {
|
|
1258
|
+
this.save();
|
|
1259
|
+
},
|
|
1260
|
+
discard: () => {
|
|
1261
|
+
if (this.staged.size === 0 && !this.failed) return;
|
|
1262
|
+
this.staged.clear();
|
|
1263
|
+
this.failed = false;
|
|
1264
|
+
this.failedReason = void 0;
|
|
1265
|
+
this.publish();
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Write every staged edit in one atomic form mutation, then re-seed from
|
|
1271
|
+
* what the Host accepted.
|
|
1272
|
+
*
|
|
1273
|
+
* The whole batch rides one mutate, so cross-field validate hooks
|
|
1274
|
+
* (baseURL+model) judge it as a unit: the Host either applies every write
|
|
1275
|
+
* or refuses the batch. The form contract answers a refusal or a skipped
|
|
1276
|
+
* write with `false` (it recovers with a fresh Host view instead of
|
|
1277
|
+
* throwing), so the outcome is judged twice: the answer itself, and then the
|
|
1278
|
+
* settled snapshot read back one planned write at a time. One missed write
|
|
1279
|
+
* fails the whole save. A transport that rejects instead (the dsh-web bridge
|
|
1280
|
+
* controller on a dead connection) reports through the same failure path
|
|
1281
|
+
* with its rejection message. A save that did not land keeps its drafts, so
|
|
1282
|
+
* the user can correct them instead of retyping.
|
|
1283
|
+
* @returns settlement after the mutation and the read-back.
|
|
1284
|
+
*/
|
|
1285
|
+
async save() {
|
|
1286
|
+
const plan = this.plan();
|
|
1287
|
+
const valid = plan.filter((item) => item.judge !== void 0);
|
|
1288
|
+
if (plan.length === 0 || this.saving || valid.length !== plan.length) return;
|
|
1289
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (const item of plan) pending.set(item.field, this.staged.get(item.field));
|
|
1291
|
+
this.saving = true;
|
|
1292
|
+
this.failed = false;
|
|
1293
|
+
this.failedReason = void 0;
|
|
1294
|
+
this.publish();
|
|
1295
|
+
const ops = valid.map((item) => item.op.op === "set" ? {
|
|
1296
|
+
op: "set",
|
|
1297
|
+
path: [item.field],
|
|
1298
|
+
value: item.op.value
|
|
1299
|
+
} : {
|
|
1300
|
+
op: "unset",
|
|
1301
|
+
path: [item.field]
|
|
1302
|
+
});
|
|
1303
|
+
let failedReason;
|
|
1304
|
+
let accepted = false;
|
|
1305
|
+
try {
|
|
1306
|
+
accepted = await this.scope.mutate(ops);
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
failedReason = error instanceof Error ? error.message : String(error);
|
|
1309
|
+
}
|
|
1310
|
+
const landed = accepted && failedReason === void 0 && valid.every((item) => item.judge());
|
|
1311
|
+
for (const [field, before] of pending) if (landed && this.staged.get(field) === before) this.staged.delete(field);
|
|
1312
|
+
this.saving = false;
|
|
1313
|
+
this.failed = !landed;
|
|
1314
|
+
this.failedReason = failedReason;
|
|
1315
|
+
this.publish();
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Every staged edit a save would write. An entry whose draft is not a value
|
|
1319
|
+
* its field accepts carries no write: the form is still dirty, and the save
|
|
1320
|
+
* refuses rather than dropping the edit. A staged edit that matches the
|
|
1321
|
+
* effective section is not a write at all.
|
|
1322
|
+
* @returns the planned writes, in the order the fields were staged.
|
|
1323
|
+
*/
|
|
1324
|
+
plan() {
|
|
1325
|
+
const plan = [];
|
|
1326
|
+
for (const [field, staged] of this.staged) {
|
|
1327
|
+
const spec = this.specOf(field);
|
|
1328
|
+
if (staged.clear) {
|
|
1329
|
+
if (this.stored(field)) plan.push({
|
|
1330
|
+
field,
|
|
1331
|
+
op: {
|
|
1332
|
+
field,
|
|
1333
|
+
op: "unset"
|
|
1334
|
+
},
|
|
1335
|
+
judge: () => this.landedUnset(field)
|
|
1336
|
+
});
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
if (staged.text === spec.format(this.sectionValue(field))) continue;
|
|
1340
|
+
const write = spec.parse(staged.text);
|
|
1341
|
+
if (write === void 0) plan.push({
|
|
1342
|
+
field,
|
|
1343
|
+
op: {
|
|
1344
|
+
field,
|
|
1345
|
+
op: "unset"
|
|
1346
|
+
},
|
|
1347
|
+
judge: void 0
|
|
1348
|
+
});
|
|
1349
|
+
else if (write.kind === "clear") plan.push({
|
|
1350
|
+
field,
|
|
1351
|
+
op: {
|
|
1352
|
+
field,
|
|
1353
|
+
op: "unset"
|
|
1354
|
+
},
|
|
1355
|
+
judge: () => this.landedUnset(field)
|
|
1356
|
+
});
|
|
1357
|
+
else plan.push({
|
|
1358
|
+
field,
|
|
1359
|
+
op: {
|
|
1360
|
+
field,
|
|
1361
|
+
op: "set",
|
|
1362
|
+
value: write.value
|
|
1363
|
+
},
|
|
1364
|
+
judge: () => this.landedSet(field, write.value)
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
return plan;
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Read-back judgment for a planned set: the user layer must hold the
|
|
1371
|
+
* intended value once the mutation has settled.
|
|
1372
|
+
*/
|
|
1373
|
+
landedSet(field, value) {
|
|
1374
|
+
if (this.specOf(field).secret) return true;
|
|
1375
|
+
return this.userLayer()?.[field] === value;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Read-back judgment for a planned unset: the field must be gone from the
|
|
1379
|
+
* user layer once the mutation has settled.
|
|
1380
|
+
*/
|
|
1381
|
+
landedUnset(field) {
|
|
1382
|
+
return !this.stored(field);
|
|
1383
|
+
}
|
|
1384
|
+
stage(field, edit) {
|
|
1385
|
+
this.staged.set(field, edit);
|
|
1386
|
+
this.failed = false;
|
|
1387
|
+
this.failedReason = void 0;
|
|
1388
|
+
this.publish();
|
|
1389
|
+
}
|
|
1390
|
+
specOf(field) {
|
|
1391
|
+
const spec = this.specs.get(field);
|
|
1392
|
+
if (spec === void 0) throw new Error(`settings card has no field ${field}`);
|
|
1393
|
+
return spec;
|
|
1394
|
+
}
|
|
1395
|
+
snapshotOf() {
|
|
1396
|
+
return this.scope.getSnapshot();
|
|
1397
|
+
}
|
|
1398
|
+
sectionValue(field) {
|
|
1399
|
+
return this.snapshotOf().value?.[field];
|
|
1400
|
+
}
|
|
1401
|
+
baseValue(field) {
|
|
1402
|
+
return this.snapshotOf().base?.[field];
|
|
1403
|
+
}
|
|
1404
|
+
userLayer() {
|
|
1405
|
+
return this.snapshotOf().user;
|
|
1406
|
+
}
|
|
1407
|
+
stored(field) {
|
|
1408
|
+
const user = this.userLayer();
|
|
1409
|
+
return user !== void 0 && Object.hasOwn(user, field);
|
|
1410
|
+
}
|
|
1411
|
+
publish() {
|
|
1412
|
+
for (const listener of this.listeners) listener();
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
//#endregion
|
|
1416
|
+
//#region src/client/LiangShenSettingsCard.tsx
|
|
1417
|
+
/** Wire presentations the tool catalog accepts (mirrors the Host schema). */
|
|
1418
|
+
const PRESENTATION_CHOICES = [
|
|
1419
|
+
"ptc",
|
|
1420
|
+
"native",
|
|
1421
|
+
"both"
|
|
1422
|
+
];
|
|
1423
|
+
/** Sensitivity presets for the circuit breaker (mirrors the Host schema). */
|
|
1424
|
+
const SENSITIVITY_CHOICES = [
|
|
1425
|
+
"conservative",
|
|
1426
|
+
"balanced",
|
|
1427
|
+
"aggressive"
|
|
1428
|
+
];
|
|
1429
|
+
/** Bridges the `liangshen` settings form onto the card's staged form. */
|
|
1430
|
+
var LiangShenSettingsCardController = class {
|
|
1431
|
+
form;
|
|
1432
|
+
store;
|
|
1433
|
+
/** @param scope - the bound configuration form of the entry that owns this namespace. */
|
|
1434
|
+
constructor(scope) {
|
|
1435
|
+
this.form = new CardForm(scope, [
|
|
1436
|
+
booleanField("enabled"),
|
|
1437
|
+
booleanField("announceToAgent"),
|
|
1438
|
+
choiceField("presentation", PRESENTATION_CHOICES),
|
|
1439
|
+
booleanField("guardEnabled"),
|
|
1440
|
+
choiceField("guardSensitivity", SENSITIVITY_CHOICES),
|
|
1441
|
+
numberField("guardStallReasoningChars", {
|
|
1442
|
+
integer: true,
|
|
1443
|
+
min: 200
|
|
1444
|
+
}),
|
|
1445
|
+
numberField("guardGlobalStallCap", {
|
|
1446
|
+
integer: true,
|
|
1447
|
+
min: 2
|
|
1448
|
+
}),
|
|
1449
|
+
numberField("guardEchoFailures", {
|
|
1450
|
+
integer: true,
|
|
1451
|
+
min: 2
|
|
1452
|
+
})
|
|
1453
|
+
]);
|
|
1454
|
+
this.store = this.form.bind(() => this.projection());
|
|
1455
|
+
}
|
|
1456
|
+
projection() {
|
|
1457
|
+
return {
|
|
1458
|
+
...this.form.shell(),
|
|
1459
|
+
enabled: this.form.field("enabled"),
|
|
1460
|
+
announceToAgent: this.form.field("announceToAgent"),
|
|
1461
|
+
presentation: this.form.field("presentation"),
|
|
1462
|
+
guardEnabled: this.form.field("guardEnabled"),
|
|
1463
|
+
guardSensitivity: this.form.field("guardSensitivity"),
|
|
1464
|
+
guardStallReasoningChars: this.form.field("guardStallReasoningChars"),
|
|
1465
|
+
guardGlobalStallCap: this.form.field("guardGlobalStallCap"),
|
|
1466
|
+
guardEchoFailures: this.form.field("guardEchoFailures")
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Build the face the card's slot registration injects.
|
|
1471
|
+
* @returns the card's snapshot and its form actions.
|
|
1472
|
+
*/
|
|
1473
|
+
inject() {
|
|
1474
|
+
return {
|
|
1475
|
+
hooks: { liangShenSettingsCard: this.store },
|
|
1476
|
+
...this.form.actions()
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
/** Release the card's scope subscription and bound stores. */
|
|
1480
|
+
dispose() {
|
|
1481
|
+
this.form.dispose();
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
/**
|
|
1485
|
+
* Render the LiangShen card.
|
|
1486
|
+
* @param props - locale copy, the card snapshot, and its form actions.
|
|
1487
|
+
* @returns the card.
|
|
1488
|
+
*/
|
|
1489
|
+
function LiangShenSettingsCard(props) {
|
|
1490
|
+
const { t } = props;
|
|
1491
|
+
const state = props.useLiangShenSettingsCard((snapshot) => snapshot);
|
|
1492
|
+
const fieldProps = {
|
|
1493
|
+
overriddenLabel: t("settings.overridden"),
|
|
1494
|
+
resetLabel: t("settings.reset"),
|
|
1495
|
+
invalidLabel: t("settings.invalidValue"),
|
|
1496
|
+
disabled: !state.writable,
|
|
1497
|
+
inheritLabel: t("settings.inherit")
|
|
1498
|
+
};
|
|
1499
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(PluginSettingsCard, {
|
|
1500
|
+
t,
|
|
1501
|
+
titleKey: "settings.title",
|
|
1502
|
+
descriptionKey: "settings.description",
|
|
1503
|
+
defaultOpen: false,
|
|
1504
|
+
state,
|
|
1505
|
+
renderChildrenWhenNotExposed: true,
|
|
1506
|
+
hideNotExposedNotice: true,
|
|
1507
|
+
onSave: props.save,
|
|
1508
|
+
onDiscard: props.discard,
|
|
1509
|
+
children: [
|
|
1510
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BooleanField, {
|
|
1511
|
+
id: "settings-liangshen-enabled",
|
|
1512
|
+
label: t("settings.enabled"),
|
|
1513
|
+
hint: t("settings.enabledHint"),
|
|
1514
|
+
onLabel: t("settings.on"),
|
|
1515
|
+
offLabel: t("settings.off"),
|
|
1516
|
+
...fieldProps,
|
|
1517
|
+
...state.enabled,
|
|
1518
|
+
onEdit: (text) => {
|
|
1519
|
+
props.edit("enabled", text);
|
|
1520
|
+
},
|
|
1521
|
+
onReset: () => {
|
|
1522
|
+
props.resetField("enabled");
|
|
1523
|
+
}
|
|
1524
|
+
}),
|
|
1525
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BooleanField, {
|
|
1526
|
+
id: "settings-liangshen-announce",
|
|
1527
|
+
label: t("settings.announceToAgent"),
|
|
1528
|
+
hint: t("settings.announceToAgentHint"),
|
|
1529
|
+
onLabel: t("settings.on"),
|
|
1530
|
+
offLabel: t("settings.off"),
|
|
1531
|
+
...fieldProps,
|
|
1532
|
+
...state.announceToAgent,
|
|
1533
|
+
onEdit: (text) => {
|
|
1534
|
+
props.edit("announceToAgent", text);
|
|
1535
|
+
},
|
|
1536
|
+
onReset: () => {
|
|
1537
|
+
props.resetField("announceToAgent");
|
|
1538
|
+
}
|
|
1539
|
+
}),
|
|
1540
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChoiceField, {
|
|
1541
|
+
id: "settings-liangshen-presentation",
|
|
1542
|
+
label: t("settings.presentation"),
|
|
1543
|
+
hint: t("settings.presentationHint"),
|
|
1544
|
+
choices: PRESENTATION_CHOICES.map((choice) => ({
|
|
1545
|
+
value: choice,
|
|
1546
|
+
label: t(`presentation.${choice}`)
|
|
1547
|
+
})),
|
|
1548
|
+
...fieldProps,
|
|
1549
|
+
...state.presentation,
|
|
1550
|
+
onEdit: (text) => {
|
|
1551
|
+
props.edit("presentation", text);
|
|
1552
|
+
},
|
|
1553
|
+
onReset: () => {
|
|
1554
|
+
props.resetField("presentation");
|
|
1555
|
+
}
|
|
1556
|
+
}),
|
|
1557
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BooleanField, {
|
|
1558
|
+
id: "settings-liangshen-guard-enabled",
|
|
1559
|
+
label: t("settings.guardEnabled"),
|
|
1560
|
+
hint: t("settings.guardEnabledHint"),
|
|
1561
|
+
onLabel: t("settings.on"),
|
|
1562
|
+
offLabel: t("settings.off"),
|
|
1563
|
+
...fieldProps,
|
|
1564
|
+
...state.guardEnabled,
|
|
1565
|
+
onEdit: (text) => {
|
|
1566
|
+
props.edit("guardEnabled", text);
|
|
1567
|
+
},
|
|
1568
|
+
onReset: () => {
|
|
1569
|
+
props.resetField("guardEnabled");
|
|
1570
|
+
}
|
|
1571
|
+
}),
|
|
1572
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChoiceField, {
|
|
1573
|
+
id: "settings-liangshen-guard-sensitivity",
|
|
1574
|
+
label: t("settings.guardSensitivity"),
|
|
1575
|
+
hint: t("settings.guardSensitivityHint"),
|
|
1576
|
+
choices: SENSITIVITY_CHOICES.map((choice) => ({
|
|
1577
|
+
value: choice,
|
|
1578
|
+
label: t(`sensitivity.${choice}`)
|
|
1579
|
+
})),
|
|
1580
|
+
...fieldProps,
|
|
1581
|
+
...state.guardSensitivity,
|
|
1582
|
+
onEdit: (text) => {
|
|
1583
|
+
props.edit("guardSensitivity", text);
|
|
1584
|
+
},
|
|
1585
|
+
onReset: () => {
|
|
1586
|
+
props.resetField("guardSensitivity");
|
|
1587
|
+
}
|
|
1588
|
+
}),
|
|
1589
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
|
|
1590
|
+
id: "settings-liangshen-guard-stall-chars",
|
|
1591
|
+
numeric: true,
|
|
1592
|
+
label: t("settings.guardStallChars"),
|
|
1593
|
+
hint: t("settings.guardStallCharsHint"),
|
|
1594
|
+
placeholder: "8000",
|
|
1595
|
+
...fieldProps,
|
|
1596
|
+
...state.guardStallReasoningChars,
|
|
1597
|
+
onEdit: (text) => {
|
|
1598
|
+
props.edit("guardStallReasoningChars", text);
|
|
1599
|
+
},
|
|
1600
|
+
onReset: () => {
|
|
1601
|
+
props.resetField("guardStallReasoningChars");
|
|
1602
|
+
}
|
|
1603
|
+
}),
|
|
1604
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
|
|
1605
|
+
id: "settings-liangshen-guard-global-cap",
|
|
1606
|
+
numeric: true,
|
|
1607
|
+
label: t("settings.guardGlobalCap"),
|
|
1608
|
+
hint: t("settings.guardGlobalCapHint"),
|
|
1609
|
+
placeholder: "4",
|
|
1610
|
+
...fieldProps,
|
|
1611
|
+
...state.guardGlobalStallCap,
|
|
1612
|
+
onEdit: (text) => {
|
|
1613
|
+
props.edit("guardGlobalStallCap", text);
|
|
1614
|
+
},
|
|
1615
|
+
onReset: () => {
|
|
1616
|
+
props.resetField("guardGlobalStallCap");
|
|
1617
|
+
}
|
|
1618
|
+
}),
|
|
1619
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ValueField, {
|
|
1620
|
+
id: "settings-liangshen-guard-echo",
|
|
1621
|
+
numeric: true,
|
|
1622
|
+
label: t("settings.guardEchoFailures"),
|
|
1623
|
+
hint: t("settings.guardEchoFailuresHint"),
|
|
1624
|
+
placeholder: "3",
|
|
1625
|
+
...fieldProps,
|
|
1626
|
+
...state.guardEchoFailures,
|
|
1627
|
+
onEdit: (text) => {
|
|
1628
|
+
props.edit("guardEchoFailures", text);
|
|
1629
|
+
},
|
|
1630
|
+
onReset: () => {
|
|
1631
|
+
props.resetField("guardEchoFailures");
|
|
1632
|
+
}
|
|
1633
|
+
})
|
|
1634
|
+
]
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
//#endregion
|
|
531
1638
|
//#region src/client/locales.ts
|
|
532
1639
|
/**
|
|
533
1640
|
* Lever copy: zh-first dictionary with an English counterpart. The zh side is
|
|
@@ -550,7 +1657,46 @@ window.__ModuleLoader__.load({
|
|
|
550
1657
|
"lever.failed.timeout": "切换超时,请重试",
|
|
551
1658
|
"lever.failed.failed": "切换失败:{reason}",
|
|
552
1659
|
"burst.line1": "三秒,三辈子的代码",
|
|
553
|
-
"burst.line2": "文言文 · 二进制 · 摩斯电码"
|
|
1660
|
+
"burst.line2": "文言文 · 二进制 · 摩斯电码",
|
|
1661
|
+
"settings.title": "梁神模式",
|
|
1662
|
+
"settings.description": "控制本插件与工具面呈现方式。",
|
|
1663
|
+
"settings.enabled": "启用梁神模式",
|
|
1664
|
+
"settings.enabledHint": "关闭后不声明预设、也不发 agent 公告。",
|
|
1665
|
+
"settings.announceToAgent": "向 agent 公告本插件",
|
|
1666
|
+
"settings.announceToAgentHint": "开启后向每一轮 agent 系统提示注入本插件公告;默认关闭以保持提示词干净。",
|
|
1667
|
+
"settings.presentation": "工具面呈现方式",
|
|
1668
|
+
"settings.presentationHint": "写入本插件声明的预设的 tool-catalog 行:both(出厂默认)让原生清单与 run_code 同驻(原生直调优先);native 保持原生工具清单;ptc 把 wire 收拢为 run_code。改动立即生效,但已开始的会话保持其已声明的组合。",
|
|
1669
|
+
"settings.on": "开",
|
|
1670
|
+
"settings.off": "关",
|
|
1671
|
+
"settings.inherit": "继承(跟随部署默认)",
|
|
1672
|
+
"settings.overridden": "已覆盖",
|
|
1673
|
+
"settings.reset": "重置",
|
|
1674
|
+
"settings.notExposed": "当前 DSH 版本未向设置页暴露本插件的配置命名空间,表单不可用。可编辑 ~/.dsh/settings.yaml 直接配置,或将本命名空间加入 Host 设置白名单后重启。",
|
|
1675
|
+
"settings.readOnly": "当前部署的设置只读。",
|
|
1676
|
+
"settings.expand": "展开设置",
|
|
1677
|
+
"settings.collapse": "收起设置",
|
|
1678
|
+
"settings.save": "保存",
|
|
1679
|
+
"settings.saving": "保存中…",
|
|
1680
|
+
"settings.discard": "放弃",
|
|
1681
|
+
"settings.unsaved": "未保存",
|
|
1682
|
+
"settings.saveFailed": "部署未接受这些值,已保留供你修改。",
|
|
1683
|
+
"settings.invalidValue": "该取值不被接受",
|
|
1684
|
+
"presentation.ptc": "ptc(仅 run_code)",
|
|
1685
|
+
"presentation.native": "native(原生工具清单)",
|
|
1686
|
+
"presentation.both": "both(两者同驻)",
|
|
1687
|
+
"settings.guardEnabled": "启用退化熔断器",
|
|
1688
|
+
"settings.guardEnabledHint": "运行时检测思考退化(连续零产出长思考 / 同参重复失败),触发时注入熔断提示并临时下调推理档位。关闭后不干预任何请求。",
|
|
1689
|
+
"settings.guardStallChars": "单步暴走字符阈值",
|
|
1690
|
+
"settings.guardStallCharsHint": "单条推理达到该字符数且零产出即触发熔断(按 V4.1 官方 384K 最大输出校准;默认 8000,约 2-4K 思考 token)。",
|
|
1691
|
+
"settings.guardGlobalCap": "慢烧连续步数",
|
|
1692
|
+
"settings.guardGlobalCapHint": "连续多少步有真实推理但零产出触发慢烧熔断(默认 4;步数越小越敏感,真实长调查建议调大)。",
|
|
1693
|
+
"settings.guardSensitivity": "熔断灵敏度",
|
|
1694
|
+
"settings.guardSensitivityHint": "整体缩放熔断阈值:保守(更少打断,阈值×1.5)、均衡(出厂校准值)、激进(更早触发,阈值×0.5)。阈值随推理档位自适应:max 档 8000 / high 档 12000 / low 档 20000 字符。",
|
|
1695
|
+
"sensitivity.conservative": "保守(少打断)",
|
|
1696
|
+
"sensitivity.balanced": "均衡(默认)",
|
|
1697
|
+
"sensitivity.aggressive": "激进(早触发)",
|
|
1698
|
+
"settings.guardEchoFailures": "同参连续失败次数",
|
|
1699
|
+
"settings.guardEchoFailuresHint": "同一工具以相同参数连续失败多少次触发空转熔断(默认 3)。"
|
|
554
1700
|
};
|
|
555
1701
|
/** English counterpart; the key set mirrors {@link zh} exactly. */
|
|
556
1702
|
const en = {
|
|
@@ -568,22 +1714,211 @@ window.__ModuleLoader__.load({
|
|
|
568
1714
|
"lever.failed.timeout": "The switch timed out; try again",
|
|
569
1715
|
"lever.failed.failed": "Switch failed: {reason}",
|
|
570
1716
|
"burst.line1": "Three seconds, three lifetimes of code",
|
|
571
|
-
"burst.line2": "Classical Chinese · Binary · Morse code"
|
|
1717
|
+
"burst.line2": "Classical Chinese · Binary · Morse code",
|
|
1718
|
+
"settings.title": "LiangShen mode",
|
|
1719
|
+
"settings.description": "Controls this plugin and the wire presentation.",
|
|
1720
|
+
"settings.enabled": "Enable LiangShen mode",
|
|
1721
|
+
"settings.enabledHint": "When off, the preset is not declared and the agent announcement does not run.",
|
|
1722
|
+
"settings.announceToAgent": "Announce this plugin to agents",
|
|
1723
|
+
"settings.announceToAgentHint": "Adds this plugin announcement to every agent system prompt; off by default so prompts stay clean.",
|
|
1724
|
+
"settings.presentation": "Wire presentation",
|
|
1725
|
+
"settings.presentationHint": "Written into the tool-catalog row of the preset this plugin declares: both (the shipped default) keeps the roster and run_code co-resident (direct native calls first); native keeps the native roster; ptc collapses the wire to run_code. A change re-declares the preset immediately; sessions that already started keep the composition they declared.",
|
|
1726
|
+
"settings.on": "On",
|
|
1727
|
+
"settings.off": "Off",
|
|
1728
|
+
"settings.inherit": "Inherit (deployment default)",
|
|
1729
|
+
"settings.overridden": "Overridden",
|
|
1730
|
+
"settings.reset": "Reset",
|
|
1731
|
+
"settings.notExposed": "This DSH version does not expose this plugin's settings namespace to the configuration page, so the form is unavailable. Edit ~/.dsh/settings.yaml directly, or add the namespace to the Host settings allowlist and restart.",
|
|
1732
|
+
"settings.readOnly": "This deployment serves settings read-only.",
|
|
1733
|
+
"settings.expand": "Show settings",
|
|
1734
|
+
"settings.collapse": "Hide settings",
|
|
1735
|
+
"settings.save": "Save",
|
|
1736
|
+
"settings.saving": "Saving…",
|
|
1737
|
+
"settings.discard": "Discard",
|
|
1738
|
+
"settings.unsaved": "Unsaved",
|
|
1739
|
+
"settings.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
|
|
1740
|
+
"settings.invalidValue": "The value is not accepted",
|
|
1741
|
+
"presentation.ptc": "ptc (run_code only)",
|
|
1742
|
+
"presentation.native": "native (native tool roster)",
|
|
1743
|
+
"presentation.both": "both (both co-resident)",
|
|
1744
|
+
"settings.guardEnabled": "Degeneration circuit breaker",
|
|
1745
|
+
"settings.guardEnabledHint": "Detects reasoning degeneration at runtime (consecutive zero-output long reasoning / repeated identical-argument failures), injecting a breaker message and stepping the reasoning effort down when it fires. Disabled means requests are never touched.",
|
|
1746
|
+
"settings.guardStallChars": "Runaway reasoning character floor",
|
|
1747
|
+
"settings.guardStallCharsHint": "One reasoning block reaching this many characters with no output fires the breaker (calibrated against V4.1's official 384K max output; default 8000, roughly 2-4K thinking tokens).",
|
|
1748
|
+
"settings.guardGlobalCap": "Slow-burn step count",
|
|
1749
|
+
"settings.guardGlobalCapHint": "Consecutive output-free steps of real reasoning that fire the slow-burn ladder (default 4; lower is more sensitive — raise it for genuinely long investigations).",
|
|
1750
|
+
"settings.guardSensitivity": "Breaker sensitivity",
|
|
1751
|
+
"settings.guardSensitivityHint": "Scales every breaker threshold: conservative (fewer interruptions, x1.5), balanced (the calibrated defaults), aggressive (fires earlier, x0.5). Thresholds adapt to the reasoning effort: 8000 at max / 12000 at high / 20000 at low.",
|
|
1752
|
+
"sensitivity.conservative": "Conservative (fewer interruptions)",
|
|
1753
|
+
"sensitivity.balanced": "Balanced (default)",
|
|
1754
|
+
"sensitivity.aggressive": "Aggressive (fires earlier)",
|
|
1755
|
+
"settings.guardEchoFailures": "Identical-argument failures",
|
|
1756
|
+
"settings.guardEchoFailuresHint": "Identical-argument failures of the same tool in a row that fire the echo ladder (default 3)."
|
|
572
1757
|
};
|
|
573
1758
|
//#endregion
|
|
1759
|
+
//#region src/client/plugin-card-seat.ts
|
|
1760
|
+
/**
|
|
1761
|
+
* Family plugin-card seat.
|
|
1762
|
+
*
|
|
1763
|
+
* A family plugin contributes its settings card to whichever plugin-card seat
|
|
1764
|
+
* the running host actually renders:
|
|
1765
|
+
*
|
|
1766
|
+
* - `web-ui.plugin.item` — the list seat declared by the dsh-web-settings
|
|
1767
|
+
* group section (this family's own first-level "Web UI plugins" section);
|
|
1768
|
+
* - `plugins.bundle.config` — the official keyed seat of the harness's plugin
|
|
1769
|
+
* manager page, keyed by the bundle's package name and rendered on that
|
|
1770
|
+
* bundle's page. alpha.2 removed the `settings.plugin.item` keyed seat of the
|
|
1771
|
+
* `ui-settings-plugins` tab that this helper used before, so a card keyed by
|
|
1772
|
+
* its settings namespace has no seat to land in any more.
|
|
1773
|
+
*
|
|
1774
|
+
* SEAT SELECTION IS NOT A DECLARATION PROBE. The official plugin surface
|
|
1775
|
+
* belongs to the harness bundle and declares its seats before any external
|
|
1776
|
+
* plugin's `apply()` runs, so "is the official seat declared?" answers yes even
|
|
1777
|
+
* in the deployment whose whole point is the family group. Choosing on that
|
|
1778
|
+
* probe sends every family card to the official page and leaves the group's own
|
|
1779
|
+
* section permanently empty — the family of reports where the section renders
|
|
1780
|
+
* its heading and zero cards.
|
|
1781
|
+
*
|
|
1782
|
+
* The signal that actually distinguishes the two deployments is whether
|
|
1783
|
+
* dsh-web-settings is loaded: it is the package that owns the group section and
|
|
1784
|
+
* it publishes the `webUiSettings` service during `apply()`, which every
|
|
1785
|
+
* family plugin already reads for its settings form. Group loaded -> the family
|
|
1786
|
+
* seat; group absent -> the official seat.
|
|
1787
|
+
*
|
|
1788
|
+
* The decision is re-evaluated on every `slots/changed` because the group may
|
|
1789
|
+
* apply after this plugin (the family aggregate orders it first, a profile that
|
|
1790
|
+
* installs the group separately need not): the initial contribution goes to the
|
|
1791
|
+
* official seat, then moves to the family seat the moment the group's section
|
|
1792
|
+
* registers. The entry is disposed before the replacement is registered, so a
|
|
1793
|
+
* card is never in two seats at once.
|
|
1794
|
+
*
|
|
1795
|
+
* The shared tree has no client-SDK dependency, so this module reads its
|
|
1796
|
+
* context through the structural shape below; callers pass the plugin's own
|
|
1797
|
+
* `ctx`.
|
|
1798
|
+
*/
|
|
1799
|
+
/** The family list seat key. */
|
|
1800
|
+
const FAMILY_PLUGIN_CARD_SEAT = "web-ui.plugin.item";
|
|
1801
|
+
/** The official keyed plugin-card seat key (the alpha.2 bundle-configuration seat). */
|
|
1802
|
+
const OFFICIAL_PLUGIN_CARD_SEAT = "plugins.bundle.config";
|
|
1803
|
+
/** The service dsh-web-settings publishes while it is loaded. */
|
|
1804
|
+
const FAMILY_GROUP_SERVICE = "webUiSettings";
|
|
1805
|
+
/**
|
|
1806
|
+
* Whether the family group (dsh-web-settings) is loaded in this page. The
|
|
1807
|
+
* service is the group package's own contract, so the probe cannot be fooled
|
|
1808
|
+
* by a harness release that starts declaring the official seat differently.
|
|
1809
|
+
*/
|
|
1810
|
+
function familyGroupLoaded(ctx) {
|
|
1811
|
+
const get = ctx.get;
|
|
1812
|
+
if (typeof get !== "function") return false;
|
|
1813
|
+
try {
|
|
1814
|
+
return get.call(ctx, FAMILY_GROUP_SERVICE) !== void 0;
|
|
1815
|
+
} catch {
|
|
1816
|
+
return false;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
/** Report a refused registration instead of leaving the user with no card. */
|
|
1820
|
+
function warnRefusedSeat(seat, error) {
|
|
1821
|
+
try {
|
|
1822
|
+
console.warn(`[dsh-web] plugin card registration into "${seat}" was refused; the card will not render`, error);
|
|
1823
|
+
} catch {}
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Contribute one family plugin card to the seat this host renders, following
|
|
1827
|
+
* the group if it loads later. The entry is disposed and re-registered on a
|
|
1828
|
+
* seat change, never duplicated.
|
|
1829
|
+
* @param ctx - client context (its slot registry decides the seat).
|
|
1830
|
+
* @param seat - the card contribution.
|
|
1831
|
+
*/
|
|
1832
|
+
function installPluginCard(ctx, seat) {
|
|
1833
|
+
const slots = ctx.slots;
|
|
1834
|
+
const component = seat.component;
|
|
1835
|
+
const inject = seat.inject;
|
|
1836
|
+
let dispose;
|
|
1837
|
+
let current;
|
|
1838
|
+
/**
|
|
1839
|
+
* Re-entrancy latch. The registry emits a change event synchronously from
|
|
1840
|
+
* inside both `register` and the previous entry's disposer, so an unguarded
|
|
1841
|
+
* reconcile would re-enter itself mid-move and register the card twice into
|
|
1842
|
+
* the seat it is leaving ("already has an entry for key ...").
|
|
1843
|
+
*/
|
|
1844
|
+
let reconciling = false;
|
|
1845
|
+
/** Reconcile the contribution with the currently live seat (no-op when unchanged). */
|
|
1846
|
+
const reconcile = () => {
|
|
1847
|
+
if (reconciling) return;
|
|
1848
|
+
const target = familyGroupLoaded(ctx) ? FAMILY_PLUGIN_CARD_SEAT : OFFICIAL_PLUGIN_CARD_SEAT;
|
|
1849
|
+
if (current === target) return;
|
|
1850
|
+
reconciling = true;
|
|
1851
|
+
const previous = dispose;
|
|
1852
|
+
dispose = void 0;
|
|
1853
|
+
current = void 0;
|
|
1854
|
+
previous?.();
|
|
1855
|
+
try {
|
|
1856
|
+
dispose = slots.register(target === "web-ui.plugin.item" ? {
|
|
1857
|
+
name: FAMILY_PLUGIN_CARD_SEAT,
|
|
1858
|
+
id: seat.id,
|
|
1859
|
+
...seat.order === void 0 ? {} : { order: seat.order },
|
|
1860
|
+
...seat.label === void 0 ? {} : { label: seat.label },
|
|
1861
|
+
locale: seat.locale,
|
|
1862
|
+
...seat.inject === void 0 ? {} : { inject }
|
|
1863
|
+
} : {
|
|
1864
|
+
name: OFFICIAL_PLUGIN_CARD_SEAT,
|
|
1865
|
+
key: seat.bundle,
|
|
1866
|
+
locale: seat.locale,
|
|
1867
|
+
...seat.inject === void 0 ? {} : { inject }
|
|
1868
|
+
}, component);
|
|
1869
|
+
current = target;
|
|
1870
|
+
} catch (error) {
|
|
1871
|
+
warnRefusedSeat(target, error);
|
|
1872
|
+
} finally {
|
|
1873
|
+
reconciling = false;
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
if (typeof ctx.on === "function") try {
|
|
1877
|
+
ctx.on("slots/changed", () => {
|
|
1878
|
+
reconcile();
|
|
1879
|
+
});
|
|
1880
|
+
} catch {}
|
|
1881
|
+
reconcile();
|
|
1882
|
+
}
|
|
1883
|
+
//#endregion
|
|
574
1884
|
//#region src/client/index.ts
|
|
575
1885
|
/** Locale namespace this half owns. */
|
|
576
1886
|
const NS = "liangshen";
|
|
577
1887
|
/**
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
1888
|
+
* Settings namespace the settings card edits. Under the 0.1.7 settings
|
|
1889
|
+
* contract the namespace IS the Host profile entry id, so this names the
|
|
1890
|
+
* standalone row; the aggregate install mounts the generated
|
|
1891
|
+
* `web-ui-liangshen` row instead and the family binder resolves between the
|
|
1892
|
+
* two. Without that binder the card binds the entry id directly.
|
|
1893
|
+
*/
|
|
1894
|
+
const SETTINGS_NAMESPACE = "liangshen";
|
|
1895
|
+
const LIANGSHEN_ENTRY_IDS = [
|
|
1896
|
+
"web-ui-liangshen",
|
|
1897
|
+
"ui-liangshen",
|
|
1898
|
+
SETTINGS_NAMESPACE
|
|
1899
|
+
];
|
|
1900
|
+
function servedEntryId(forms) {
|
|
1901
|
+
let served;
|
|
1902
|
+
try {
|
|
1903
|
+
served = forms.describe().getSnapshot().view?.namespaces.map((view) => view.ns);
|
|
1904
|
+
} catch {
|
|
1905
|
+
served = void 0;
|
|
1906
|
+
}
|
|
1907
|
+
if (!served || served.length === 0) return SETTINGS_NAMESPACE;
|
|
1908
|
+
return LIANGSHEN_ENTRY_IDS.find((id) => served.includes(id)) ?? "liangshen";
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Required client services: the slot registry, locale, sessions, the shared
|
|
1912
|
+
* configuration forms, and the roster Remote. Both `remote` and
|
|
1913
|
+
* `remote.agentPresets` are declared: the context proxy refuses an uninjected
|
|
1914
|
+
* service, and a nested service name does not imply its parent, so reading
|
|
1915
|
+
* `ctx.remote.agentPresets` needs `remote` as well.
|
|
582
1916
|
*/
|
|
583
1917
|
const inject = [
|
|
584
1918
|
"slots",
|
|
585
1919
|
"locale",
|
|
586
1920
|
"sessions",
|
|
1921
|
+
"configForms",
|
|
587
1922
|
"remote",
|
|
588
1923
|
"remote.agentPresets"
|
|
589
1924
|
];
|
|
@@ -608,6 +1943,21 @@ window.__ModuleLoader__.load({
|
|
|
608
1943
|
try {
|
|
609
1944
|
controller.start();
|
|
610
1945
|
} catch {}
|
|
1946
|
+
try {
|
|
1947
|
+
const binder = ctx.get("webUiSettings");
|
|
1948
|
+
const settingsCard = new LiangShenSettingsCardController(binder !== void 0 && typeof binder.bind === "function" ? binder.bind({ namespace: SETTINGS_NAMESPACE }) : ctx.configForms.get(servedEntryId(ctx.configForms)));
|
|
1949
|
+
installPluginCard(ctx, {
|
|
1950
|
+
bundle: "@linxin666/dsh-liangshen",
|
|
1951
|
+
id: "liangshen",
|
|
1952
|
+
order: 120,
|
|
1953
|
+
locale: NS,
|
|
1954
|
+
inject: () => settingsCard.inject(),
|
|
1955
|
+
component: LiangShenSettingsCard
|
|
1956
|
+
});
|
|
1957
|
+
ctx.effect(() => () => {
|
|
1958
|
+
settingsCard.dispose();
|
|
1959
|
+
}, "liangshen: settings card");
|
|
1960
|
+
} catch {}
|
|
611
1961
|
ctx.slots.inject("conversation.input.right", () => {
|
|
612
1962
|
try {
|
|
613
1963
|
const unregister = ctx.slots.register({
|
|
@@ -629,6 +1979,7 @@ window.__ModuleLoader__.load({
|
|
|
629
1979
|
exports.LeverController = LeverController;
|
|
630
1980
|
exports.LiangShenLever = LiangShenLever;
|
|
631
1981
|
exports.NS = NS;
|
|
1982
|
+
exports.SETTINGS_NAMESPACE = SETTINGS_NAMESPACE;
|
|
632
1983
|
exports.apply = apply;
|
|
633
1984
|
exports.inject = inject;
|
|
634
1985
|
exports.leverState = leverState;
|