mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
适配 DSH alpha.4 并发布 0.2.3 会话与预览同步修复
This commit is contained in:
1 parent
945b9624d6
commit
e884f740e3
21 files changed
+441
-122
No files matched your search
+89
-14
@@ -26,7 +26,8 @@ window.__ModuleLoader__.load({
|
||||
writable: false,
|
||||
settingsStatus: "loading",
|
||||
status: null,
|
||||
previews: {}
|
||||
previews: {},
|
||||
busy: false
|
||||
};
|
||||
const listeners = /* @__PURE__ */ new Set();
|
||||
const view = {
|
||||
@@ -44,6 +45,7 @@ window.__ModuleLoader__.load({
|
||||
settingsStatus: settingsSnapshot.status,
|
||||
status: snapshot.status,
|
||||
previews: snapshot.previews,
|
||||
busy: snapshot.busy,
|
||||
message: snapshot.message
|
||||
};
|
||||
for (const listener of listeners) listener();
|
||||
@@ -53,41 +55,69 @@ window.__ModuleLoader__.load({
|
||||
if (!result.ok) throw new Error(result.error.message);
|
||||
return result.value;
|
||||
}
|
||||
async function refresh() {
|
||||
async function refresh(invalidatePreviews = false) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
publish();
|
||||
try {
|
||||
const status = await call("status", {});
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
previews: invalidatePreviews ? {} : snapshot.previews,
|
||||
busy: false,
|
||||
message: void 0
|
||||
};
|
||||
publish();
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
publish();
|
||||
}
|
||||
}
|
||||
async function setEnabled(enabled) {
|
||||
await settings.set("enabled", enabled);
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
publish();
|
||||
setTimeout(() => void refresh(), 300);
|
||||
try {
|
||||
await settings.set("enabled", enabled);
|
||||
await refresh(true);
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
publish();
|
||||
}
|
||||
}
|
||||
async function recheck() {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: true
|
||||
};
|
||||
publish();
|
||||
try {
|
||||
const status = await call("recheck", {});
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
status,
|
||||
previews: {},
|
||||
busy: false,
|
||||
message: void 0
|
||||
};
|
||||
publish();
|
||||
} catch (error) {
|
||||
snapshot = {
|
||||
...snapshot,
|
||||
busy: false,
|
||||
message: messageOf(error)
|
||||
};
|
||||
publish();
|
||||
@@ -135,7 +165,7 @@ window.__ModuleLoader__.load({
|
||||
}
|
||||
ctx.effect(() => settings.subscribe(publish), "dsh-unrestricted: settings mirror");
|
||||
ctx.effect(() => ctx.remote.$on("settings/document-updated", (namespace) => {
|
||||
if (namespace === void 0 || namespace === SETTINGS_NS) refresh();
|
||||
if (namespace === void 0 || namespace === SETTINGS_NS) refresh(true);
|
||||
}), "dsh-unrestricted: settings invalidations");
|
||||
publish();
|
||||
refresh();
|
||||
@@ -143,7 +173,7 @@ window.__ModuleLoader__.load({
|
||||
hooks: { view },
|
||||
setEnabled,
|
||||
recheck,
|
||||
refresh,
|
||||
refresh: () => refresh(true),
|
||||
loadPreview
|
||||
}) };
|
||||
}
|
||||
@@ -186,9 +216,16 @@ window.__ModuleLoader__.load({
|
||||
previewLoading: "正在组装当前提示词…",
|
||||
previewUnavailable: "暂不可预览:",
|
||||
previewSize: "行",
|
||||
previewSourceLive: "实时会话",
|
||||
previewSourceStanding: "静态预设",
|
||||
settingsUnavailable: "当前连接不可写设置(远程浏览器只读)。",
|
||||
settingsLoading: "正在读取设置…",
|
||||
operationFailed: "操作失败:"
|
||||
operationFailed: "操作失败:",
|
||||
issueIdentity: "DSH 身份开场白已变更",
|
||||
issuePersona: "预设角色前缀已变更",
|
||||
issuePlan: "计划模式段落已变更",
|
||||
issuePtcOnly: "PTC 模式 run_code 规则已变更",
|
||||
issueStructuredOutput: "结构化输出指令已变更"
|
||||
};
|
||||
/** English dictionary checked against the Chinese key set. */
|
||||
const en = {
|
||||
@@ -226,9 +263,16 @@ window.__ModuleLoader__.load({
|
||||
previewLoading: "Assembling the current prompt…",
|
||||
previewUnavailable: "No preview available: ",
|
||||
previewSize: "lines",
|
||||
previewSourceLive: "live session",
|
||||
previewSourceStanding: "standing preset",
|
||||
settingsUnavailable: "This connection cannot write settings (remote browser is read-only).",
|
||||
settingsLoading: "Reading settings…",
|
||||
operationFailed: "Operation failed: "
|
||||
operationFailed: "Operation failed: ",
|
||||
issueIdentity: "harness identity opening changed",
|
||||
issuePersona: "preset persona changed",
|
||||
issuePlan: "plan-mode section changed",
|
||||
issuePtcOnly: "ptc-mode run_code rule changed",
|
||||
issueStructuredOutput: "structured-output instruction changed"
|
||||
};
|
||||
/** Dictionary namespace owned by this plugin. */
|
||||
const NS = "settings.unrestricted";
|
||||
@@ -523,6 +567,11 @@ window.__ModuleLoader__.load({
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-actions button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-actions button:focus-visible {
|
||||
outline: 2px solid var(--dsw-alias-state-business-primary);
|
||||
outline-offset: 2px;
|
||||
@@ -572,6 +621,14 @@ window.__ModuleLoader__.load({
|
||||
presetKey: "presetMinimal"
|
||||
}
|
||||
];
|
||||
/** Known host issue strings mapped to localized dictionary keys. */
|
||||
const ISSUE_LOCALE_KEYS = {
|
||||
"harness identity opening changed": "issueIdentity",
|
||||
"preset persona changed": "issuePersona",
|
||||
"plan-mode section changed": "issuePlan",
|
||||
"ptc-mode run_code rule changed": "issuePtcOnly",
|
||||
"structured-output instruction changed": "issueStructuredOutput"
|
||||
};
|
||||
/** Locale key for one mode state. */
|
||||
function stateKey(mode) {
|
||||
switch (mode?.state) {
|
||||
@@ -587,10 +644,18 @@ window.__ModuleLoader__.load({
|
||||
* @returns the card.
|
||||
*/
|
||||
function UnrestrictedCard(props) {
|
||||
const { t } = props;
|
||||
const { t, loadPreview } = props;
|
||||
const view = props.useView((snapshot) => snapshot);
|
||||
const status = view.status;
|
||||
const [openPreview, setOpenPreview] = (0, react.useState)(null);
|
||||
const openEntry = openPreview === null ? void 0 : view.previews[openPreview];
|
||||
(0, react.useEffect)(() => {
|
||||
if (openPreview !== null && openEntry === void 0) loadPreview(openPreview);
|
||||
}, [
|
||||
openPreview,
|
||||
openEntry,
|
||||
loadPreview
|
||||
]);
|
||||
const hasFailedMode = status !== null && Object.values(status.modes).some((mode) => mode.state === "failed");
|
||||
const summaryKey = view.settingsStatus === "loading" ? "summaryLoading" : view.settingsStatus === "unavailable" ? "summaryUnavailable" : hasFailedMode ? "summaryValidationFailed" : view.enabled ? "summaryEnabled" : "summaryDisabled";
|
||||
const summaryState = view.settingsStatus === "ready" ? hasFailedMode ? "error" : view.enabled ? "active" : "off" : "pending";
|
||||
@@ -604,6 +669,13 @@ window.__ModuleLoader__.load({
|
||||
const entry = view.previews[presetId];
|
||||
if (entry === void 0 || entry.status === "failed") props.loadPreview(presetId);
|
||||
}
|
||||
/** Localize known anchor issues; pass dynamic probe errors through as-is. */
|
||||
function formatIssues(issues) {
|
||||
return issues.map((issue) => {
|
||||
const key = ISSUE_LOCALE_KEYS[issue];
|
||||
return key !== void 0 ? t(key) : issue;
|
||||
}).join("; ");
|
||||
}
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
||||
open: true,
|
||||
className: "dsh-unrestricted-card",
|
||||
@@ -634,7 +706,7 @@ window.__ModuleLoader__.load({
|
||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
||||
type: "checkbox",
|
||||
checked: view.enabled,
|
||||
disabled: !view.writable || view.settingsStatus !== "ready",
|
||||
disabled: !view.writable || view.settingsStatus !== "ready" || view.busy,
|
||||
onChange: (event) => {
|
||||
props.setEnabled(event.target.checked);
|
||||
}
|
||||
@@ -687,7 +759,7 @@ window.__ModuleLoader__.load({
|
||||
}),
|
||||
mode !== void 0 && mode.issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
||||
className: "dsh-unrestricted-issues",
|
||||
children: mode.issues.join("; ")
|
||||
children: formatIssues(mode.issues)
|
||||
}),
|
||||
isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: "dsh-unrestricted-preview",
|
||||
@@ -703,12 +775,13 @@ window.__ModuleLoader__.load({
|
||||
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
||||
className: "dsh-unrestricted-note",
|
||||
children: [
|
||||
t("previewSize"),
|
||||
" ",
|
||||
entry.preview?.lines,
|
||||
" ",
|
||||
t("previewSize"),
|
||||
" · ",
|
||||
entry.preview?.bytes,
|
||||
" B"
|
||||
" B",
|
||||
entry.preview?.source !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [" · ", t(entry.preview.source === "live" ? "previewSourceLive" : "previewSourceStanding")] })
|
||||
]
|
||||
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
||||
className: "dsh-unrestricted-previewText",
|
||||
@@ -750,12 +823,14 @@ window.__ModuleLoader__.load({
|
||||
className: "dsh-unrestricted-actions",
|
||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
||||
type: "button",
|
||||
disabled: view.busy,
|
||||
onClick: () => {
|
||||
props.recheck();
|
||||
},
|
||||
children: t("recheck")
|
||||
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
||||
type: "button",
|
||||
disabled: view.busy,
|
||||
onClick: () => {
|
||||
props.refresh();
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user