mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 09:40:22 +08:00
feat: 发布 1.1.12,测试版 Skill 进入正式版
正式版带上 Skill 导入,并保留不再钉上一轮全文、按提交号标当前和拒绝跨站请求。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
9c1a002cf5
9 files changed
+1389
-108
No files matched your search
@@ -45,6 +45,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const method = String((init && init.method) || "GET").toUpperCase();
|
||||
if (path.indexOf("/dsh-purge/update") !== -1) return method === "POST" ? 180000 : 45000;
|
||||
if (path.indexOf("/dsh-purge/uninstall") !== -1) return 90000;
|
||||
if (path.indexOf("/dsh-purge/skill") !== -1) return method === "POST" ? 120000 : 20000;
|
||||
return 20000;
|
||||
}
|
||||
function isAbortError(e) {
|
||||
@@ -110,6 +111,22 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
});
|
||||
}
|
||||
|
||||
function skillsRouteMissing(e) {
|
||||
return /\b404\b|\b405\b|non-json/i.test(String((e && e.message) || e || ""));
|
||||
}
|
||||
|
||||
function skillsApi(op, extra) {
|
||||
const init = {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(Object.assign({ op: op }, extra || {})),
|
||||
};
|
||||
return apiJson("/dsh-purge/skills", init).catch((e) => {
|
||||
if (!skillsRouteMissing(e)) throw e;
|
||||
return apiJson("/dsh-purge/skill", init);
|
||||
});
|
||||
}
|
||||
|
||||
const TARGETS = ["AGENTS.md", "CLAUDE.md"];
|
||||
const PATCH_GROUPS = [
|
||||
{ key: "prompt", ids: [1, 2, 3, 4, 5, 26, 27, 28, 29, 33] },
|
||||
@@ -139,7 +156,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"apply.hint": "待应用=原文还在。跳过=没装或官方已改写,再点也不会变。",
|
||||
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符,不要用官方 dsh 去清桌面端。",
|
||||
"warn.noRoot.desktop": "未定位到当前桌面应用里的 @deepseek-ai。请退出托盘后重新打开 DSH Desktop.exe,再在桌面端设置页点「应用」。安装目录不限盘符。",
|
||||
"warn.noInject": "提示词优先;为空则注入当前启用的规则集。两边都空会提示必须添加。",
|
||||
"warn.noInject": "提示词优先;为空则注入当前启用的规则集。两边都空会提示必须添加。Skill 不顶替提示词。",
|
||||
"need.prompt": "提示词和规则集都是空的,必须先添加提示词,或启用一条有内容的规则集。",
|
||||
"btn.restoreInject": "恢复默认",
|
||||
"saved.restoreInject": "已填入默认提示词,点保存写入",
|
||||
@@ -168,17 +185,17 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"channel.beta": "测试版",
|
||||
"channel.useStable": "切换到正式版",
|
||||
"channel.useBeta": "切换到测试版",
|
||||
"channel.now": "当前通道",
|
||||
"channel.other": "可切换",
|
||||
"channel.local": "本机",
|
||||
"update.checking": "正在检测更新…",
|
||||
"update.applying": "正在更新…",
|
||||
"update.switching": "正在切换版本…",
|
||||
"update.latest": "已是最新({version})",
|
||||
"update.available": "有新版本 {remote},当前 {local}",
|
||||
"update.pinned": "已固定在 {version},通道最新是 {remote}",
|
||||
"update.done": "已更新到 {version},请重启",
|
||||
"update.switched": "已切换到 {version},请重启",
|
||||
"update.autoDone": "已自动更新到 {version},请重启",
|
||||
"update.done": "已更新到 {version}",
|
||||
"update.switched": "已切换到 {version}",
|
||||
"update.autoDone": "已自动更新到 {version}",
|
||||
"update.reloading": "正在刷新设置页…",
|
||||
"update.dirty": "有新版本,本地有改动未自动覆盖",
|
||||
"update.fail": "更新失败: {error}",
|
||||
"update.timeout": "检测超时,请再点一次检测更新",
|
||||
@@ -220,6 +237,28 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"need.id": "需要 id",
|
||||
"ph.content": "",
|
||||
"btn.saveRule": "保存",
|
||||
"skills.title": "Skill",
|
||||
"skills.hint": "导入到官方目录后,由 DSH 调用:聊天输入 /名称 立即加载;任务对上 description 或 whenToUse 时模型会调 skill 工具。正文写「激活」不会触发。",
|
||||
"skills.hint.desktop": "当前桌面宿主的官方 Skill 目录。聊天输入 /名称 立即加载;任务对上 description 时模型会调 skill 工具。",
|
||||
"skills.empty": "暂无用户 Skill",
|
||||
"btn.importZip": "导入压缩包",
|
||||
"btn.importFolder": "导入文件夹",
|
||||
"skills.importing": "正在导入…",
|
||||
"saved.import": "已导入 {count} 个 Skill",
|
||||
"need.import": "请选择压缩包或文件夹",
|
||||
"err.import.folder": "没读到文件夹里的文件,请直接选 Skill 目录(里面要有 SKILL.md)",
|
||||
"skills.pick": "选择 Skill",
|
||||
"skills.invalid": "官方会忽略:格式不对",
|
||||
"skills.call.slash": "聊天输入 {cmd}",
|
||||
"skills.call.model": "模型可调",
|
||||
"skills.call.modelOff": "模型不可调",
|
||||
"skills.call.userOff": "不可 /名称",
|
||||
"ph.skill.desc": "description(何时用)",
|
||||
"btn.saveSkill": "保存",
|
||||
"need.skill.id": "id 必须是 kebab-case,例如 code-review",
|
||||
"confirm.delete.skill": "从官方 $DSH_HOME/skills 删除 {id}?宿主会自动从目录拿掉。",
|
||||
"err.skills": "读取失败: {error}",
|
||||
"err.skills.needRestart": "Skill 接口未加载,请先重启当前宿主",
|
||||
"btn.restart": "重启",
|
||||
"btn.restart.busy": "重启中…",
|
||||
"restarting": "重启中…",
|
||||
@@ -327,7 +366,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"apply.hint": "Pending = original text still present. Skipped = missing or already rewritten.",
|
||||
"warn.noRoot": "Could not find this host’s @deepseek-ai tree, so Apply will not patch anything. Fully quit and reopen this host, then Apply here. Desktop may live on any drive; do not use official dsh to purge Desktop.",
|
||||
"warn.noRoot.desktop": "Could not find @deepseek-ai inside this desktop app. Quit the tray, reopen DSH Desktop.exe, then Apply on the desktop Settings page. The install folder can be on any drive.",
|
||||
"warn.noInject": "The prompt box wins. If it is empty, the enabled rule set is injected. If both are empty you will be asked to add a prompt.",
|
||||
"warn.noInject": "The prompt box wins. If it is empty, the enabled rule set is injected. If both are empty you will be asked to add a prompt. Skills do not replace the prompt.",
|
||||
"need.prompt": "Both the prompt and the rule set are empty. Add a prompt, or enable a rule that has content.",
|
||||
"btn.restoreInject": "Reset default",
|
||||
"saved.restoreInject": "Default prompt loaded. Save to write.",
|
||||
@@ -356,17 +395,17 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"channel.beta": "Beta",
|
||||
"channel.useStable": "Switch to stable",
|
||||
"channel.useBeta": "Switch to beta",
|
||||
"channel.now": "Current channel",
|
||||
"channel.other": "Available",
|
||||
"channel.local": "This copy",
|
||||
"update.checking": "Checking for updates…",
|
||||
"update.applying": "Updating…",
|
||||
"update.switching": "Switching version…",
|
||||
"update.latest": "Up to date ({version})",
|
||||
"update.available": "Update {remote} available (now {local})",
|
||||
"update.pinned": "Pinned at {version}; channel latest is {remote}",
|
||||
"update.done": "Updated to {version}. Restart to apply.",
|
||||
"update.switched": "Switched to {version}. Restart to apply.",
|
||||
"update.autoDone": "Auto-updated to {version}. Restart to apply.",
|
||||
"update.done": "Updated to {version}.",
|
||||
"update.switched": "Switched to {version}.",
|
||||
"update.autoDone": "Auto-updated to {version}.",
|
||||
"update.reloading": "Refreshing settings…",
|
||||
"update.dirty": "Update available; local edits were not overwritten.",
|
||||
"update.fail": "Update failed: {error}",
|
||||
"update.timeout": "Check timed out. Click Check update again.",
|
||||
@@ -408,6 +447,28 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"need.id": "id required",
|
||||
"ph.content": "",
|
||||
"btn.saveRule": "Save",
|
||||
"skills.title": "Skills",
|
||||
"skills.hint": "After import, DSH calls it: type /name in chat to load now; the model calls the skill tool when the task matches description or whenToUse. Writing「激活」in the body does nothing.",
|
||||
"skills.hint.desktop": "This desktop host’s official skill catalog. Type /name in chat to load; the model calls the skill tool when the task matches the description.",
|
||||
"skills.empty": "No user skills",
|
||||
"btn.importZip": "Import zip",
|
||||
"btn.importFolder": "Import folder",
|
||||
"skills.importing": "Importing…",
|
||||
"saved.import": "Imported {count} skill(s)",
|
||||
"need.import": "Choose a zip or folder",
|
||||
"err.import.folder": "No files were read. Select the skill folder itself (it must contain SKILL.md).",
|
||||
"skills.pick": "Select a skill",
|
||||
"skills.invalid": "Official catalog will ignore this: invalid format",
|
||||
"skills.call.slash": "Type {cmd} in chat",
|
||||
"skills.call.model": "Model can load",
|
||||
"skills.call.modelOff": "Hidden from model",
|
||||
"skills.call.userOff": "/name disabled",
|
||||
"ph.skill.desc": "description (when to use)",
|
||||
"btn.saveSkill": "Save",
|
||||
"need.skill.id": "id must be kebab-case, e.g. code-review",
|
||||
"confirm.delete.skill": "Delete {id} from official $DSH_HOME/skills? The host will drop it from the catalog.",
|
||||
"err.skills": "Read failed: {error}",
|
||||
"err.skills.needRestart": "Skill API is not loaded. Restart this host first.",
|
||||
"btn.restart": "Restart",
|
||||
"btn.restart.busy": "Restarting…",
|
||||
"restarting": "Restarting…",
|
||||
@@ -555,23 +616,20 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
.dshp-cr-row label{display:inline-flex;align-items:center;gap:6px;color:var(--dshp-ink)}
|
||||
.dshp-cr-num{width:64px;min-width:64px;height:28px;padding:0 8px}
|
||||
.dshp-cr-text{width:120px;min-width:88px;height:28px;padding:0 8px}
|
||||
.dshp-ver{width:100%;min-width:0;max-width:none;height:34px;padding:0 10px;font-size:12px}
|
||||
.dshp-lanes{display:grid;grid-template-columns:1fr 1fr;gap:1px;margin:0 0 16px;background:var(--dshp-line);border:1px solid var(--dshp-line);border-radius:8px;overflow:hidden}
|
||||
.dshp-lane{display:flex;flex-direction:column;gap:0;min-width:0;padding:14px 14px 12px;background:var(--dshp-paper);transition:background .2s var(--dshp-ease)}
|
||||
.dshp-lane.is-on{background:var(--dshp-bg)}
|
||||
.dshp-lane-kicker{margin:0 0 4px;font-family:var(--dshp-mono);font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--dshp-mute)}
|
||||
.dshp-lane.is-on .dshp-lane-kicker{color:var(--dshp-accent)}
|
||||
.dshp-lane.is-beta .dshp-lane-kicker{color:var(--dshp-warn)}
|
||||
.dshp-lane.is-on.is-beta .dshp-lane-kicker{color:var(--dshp-warn)}
|
||||
.dshp-lane-h{display:flex;align-items:baseline;gap:10px;margin:0 0 12px;padding-bottom:10px;border-bottom:1px solid var(--dshp-line)}
|
||||
.dshp-lane-h strong{font-family:var(--dshp-display);font-size:18px;font-weight:500;letter-spacing:.02em}
|
||||
.dshp-lane-ver{margin-left:auto;font-family:var(--dshp-mono);font-size:12px;color:var(--dshp-mute);white-space:nowrap}
|
||||
.dshp-lane-ops{display:flex;flex-direction:column;gap:8px}
|
||||
.dshp-lane-ops .dshp-btn{width:100%}
|
||||
.dshp-ver{width:100%;min-width:0;max-width:none;height:32px;padding:0 10px;font-size:12px}
|
||||
.dshp-rel{margin:0 0 14px}
|
||||
.dshp-now{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;margin:0 0 4px}
|
||||
.dshp-now-label{font-family:var(--dshp-mono);font-size:11px;letter-spacing:.12em;text-transform:uppercase;color:var(--dshp-mute)}
|
||||
.dshp-now-ver{font-family:var(--dshp-display);font-size:20px;font-weight:500;letter-spacing:.01em}
|
||||
.dshp-now-mark{display:inline-flex;align-items:center;margin-left:6px;padding:1px 7px;border-radius:99px;font-family:var(--dshp-mono);font-size:11px;font-style:normal;font-weight:500;line-height:1.5;color:var(--dshp-ok);border:1px solid color-mix(in srgb,var(--dshp-ok) 38%,var(--dshp-line));background:color-mix(in srgb,var(--dshp-ok) 14%,var(--dshp-bg))}
|
||||
.dshp-editions{display:flex;flex-direction:column;margin:10px 0 0;border-top:1px solid var(--dshp-line)}
|
||||
.dshp-edition{display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:10px;padding:10px 0;border-bottom:1px solid var(--dshp-line)}
|
||||
.dshp-edition-name{display:inline-flex;align-items:center;gap:0;font-family:var(--dshp-display);font-size:15px;font-weight:500;white-space:nowrap}
|
||||
.dshp-edition.is-on .dshp-edition-name{color:var(--dshp-ink)}
|
||||
.dshp-edition:not(.is-on) .dshp-edition-name{color:var(--dshp-mute)}
|
||||
.dshp-edition .dshp-btn{min-width:118px}
|
||||
.dshp-rel .dshp-notice{display:block;margin-top:8px;min-height:16px}
|
||||
@media (max-width:640px){.dshp-lanes{grid-template-columns:1fr}}
|
||||
@media (prefers-reduced-motion:reduce){.dshp-lane{transition:none}}
|
||||
@media (max-width:560px){.dshp-edition{grid-template-columns:1fr auto;grid-template-areas:"name btn" "sel sel"}.dshp-edition-name{grid-area:name}.dshp-edition .dshp-ver{grid-area:sel}.dshp-edition .dshp-btn{grid-area:btn}}
|
||||
.dshp-area{min-height:220px;resize:vertical}
|
||||
.dshp-field:focus,.dshp-area:focus{outline:none;border-color:var(--dshp-accent);box-shadow:0 0 0 3px var(--dshp-accent-soft)}
|
||||
.dshp-field:disabled,.dshp-area:disabled{opacity:.5}
|
||||
@@ -807,6 +865,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const [overrideLoaded, setOverrideLoaded] = useState(false);
|
||||
const [patchBusy, setPatchBusy] = useState(false);
|
||||
const [updateBusy, setUpdateBusy] = useState(false);
|
||||
const [canApplyUpdate, setCanApplyUpdate] = useState(false);
|
||||
const [updateJob, setUpdateJob] = useState(null);
|
||||
const [askRestart, setAskRestart] = useState(false);
|
||||
const [askUninstall, setAskUninstall] = useState(false);
|
||||
const [uninstallBusy, setUninstallBusy] = useState(false);
|
||||
@@ -821,7 +881,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const versions = (d && d.versions) || [];
|
||||
const next = { stable: "", beta: "" };
|
||||
for (const id of ["stable", "beta"]) {
|
||||
const list = versions.filter((item) => item.channel === id);
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item));
|
||||
const cur = list.find((item) => item.current);
|
||||
const latest = list.find((item) => item.latest);
|
||||
next[id] = (cur || latest || {}).ref || "";
|
||||
@@ -838,34 +898,44 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
|
||||
const applyUpdateInfo = useCallback((d, tr, kind) => {
|
||||
if (d.channel) setChannel(d.channel);
|
||||
setUpdateInfo(d);
|
||||
syncPicks(d);
|
||||
setUpdateInfo((prev) => {
|
||||
const versions = (d.versions && d.versions.length) ? d.versions : ((prev && prev.versions) || []);
|
||||
return Object.assign({}, prev || {}, d, { versions });
|
||||
});
|
||||
if (d.versions && d.versions.length) syncPicks(d);
|
||||
if (kind === "check") setCanApplyUpdate(Boolean(d.hasUpdate) && !d.error);
|
||||
else if (kind === "done" || kind === "switched" || kind === "channel") setCanApplyUpdate(false);
|
||||
const version = d.localVersion || d.localSha || "—";
|
||||
const remote = d.remoteVersion || d.remoteSha || "—";
|
||||
let text = tr("update.latest", { version });
|
||||
if (d.hasUpdate) text = tr("update.available", { remote, local: version });
|
||||
if (d.pinned && d.hasUpdate) text = tr("update.pinned", { version, remote });
|
||||
if (kind === "switched") text = tr("update.switched", { version: d.localVersion || d.remoteVersion || "—" });
|
||||
if (kind === "switched" || kind === "channel") text = tr("update.switched", { version: d.localVersion || d.remoteVersion || "—" });
|
||||
if (kind === "done") text = tr("update.done", { version: d.localVersion || d.remoteVersion || "—" });
|
||||
if (d.error) text = d.error;
|
||||
setUpdateNotice({ kind: d.ok === false || d.error ? "error" : "ok", text });
|
||||
}, []);
|
||||
|
||||
const checkUpdate = useCallback(() => {
|
||||
const checkUpdate = useCallback((id) => {
|
||||
setUpdateBusy(true);
|
||||
setUpdateJob({ id: id || "", kind: "check" });
|
||||
const tr = tRef.current;
|
||||
setUpdateNotice({ kind: "ok", text: tr("update.checking") });
|
||||
apiJson("/dsh-purge/update")
|
||||
.then((d) => {
|
||||
if (!d || (!d.ok && !d.channel)) throw new Error((d && d.error) || "check failed");
|
||||
applyUpdateInfo(d, tr);
|
||||
applyUpdateInfo(d, tr, "check");
|
||||
})
|
||||
.catch((e) => setUpdateNotice({ kind: "error", text: updateErrorText(tr, e) }))
|
||||
.finally(() => setUpdateBusy(false));
|
||||
.finally(() => {
|
||||
setUpdateBusy(false);
|
||||
setUpdateJob(null);
|
||||
});
|
||||
}, [applyUpdateInfo]);
|
||||
|
||||
const postUpdate = useCallback((body, kind) => {
|
||||
const postUpdate = useCallback((body, kind, id) => {
|
||||
setUpdateBusy(true);
|
||||
setUpdateJob({ id: id || "", kind });
|
||||
const tr = tRef.current;
|
||||
setUpdateNotice({ kind: "ok", text: kind === "switched" || kind === "channel" ? tr("update.switching") : tr("update.applying") });
|
||||
return apiJson("/dsh-purge/update", {
|
||||
@@ -875,28 +945,45 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
})
|
||||
.then((d) => {
|
||||
if (!d || (d.ok === false && d.error)) throw new Error((d && d.error) || "update failed");
|
||||
applyUpdateInfo(d, tr, kind === "channel" ? "switched" : kind);
|
||||
if (d.applied || d.needRestart) setAskRestart(true);
|
||||
applyUpdateInfo(d, tr, kind);
|
||||
if (d.applied && d.reloadClient !== false) {
|
||||
setUpdateNotice({ kind: "ok", text: tr("update.reloading") });
|
||||
setTimeout(() => {
|
||||
try { window.location.reload(); } catch { /* ignore */ }
|
||||
}, 280);
|
||||
} else if (d.needRestart) {
|
||||
setAskRestart(true);
|
||||
}
|
||||
return d;
|
||||
})
|
||||
.catch((e) => {
|
||||
setUpdateNotice({ kind: "error", text: updateErrorText(tr, e) });
|
||||
throw e;
|
||||
})
|
||||
.finally(() => setUpdateBusy(false));
|
||||
.finally(() => {
|
||||
setUpdateBusy(false);
|
||||
setUpdateJob(null);
|
||||
});
|
||||
}, [applyUpdateInfo]);
|
||||
|
||||
const doUpdate = useCallback((id) => {
|
||||
const lane = id === "beta" ? "beta" : "stable";
|
||||
postUpdate({ op: "apply", ref: lane === "beta" ? "beta" : "master", channel: lane }, "done").catch(() => {});
|
||||
postUpdate({ op: "apply", ref: lane === "beta" ? "beta" : "master", channel: lane }, "done", id).catch(() => {});
|
||||
}, [postUpdate]);
|
||||
|
||||
const changeChannel = useCallback((next) => {
|
||||
if (!next) return;
|
||||
const tr = tRef.current;
|
||||
if (!window.confirm(tr("update.confirmChannel", { version: tr("channel." + next) }))) return;
|
||||
postUpdate({ op: "channel", channel: next }, "channel").catch(() => {});
|
||||
}, [postUpdate]);
|
||||
const prevChannel = channel;
|
||||
const prevInfo = updateInfo;
|
||||
setChannel(next);
|
||||
setUpdateInfo((cur) => Object.assign({}, cur || {}, { channel: next }));
|
||||
postUpdate({ op: "channel", channel: next }, "channel", next).catch(() => {
|
||||
setChannel(prevChannel);
|
||||
setUpdateInfo(prevInfo);
|
||||
});
|
||||
}, [channel, postUpdate, updateInfo]);
|
||||
|
||||
const switchSelected = useCallback((id) => {
|
||||
const tr = tRef.current;
|
||||
@@ -906,8 +993,17 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const label = (hit && (hit.label || hit.version)) || ref;
|
||||
if (!ref) return;
|
||||
if (!window.confirm(tr("update.confirmSwitch", { version: label }))) return;
|
||||
postUpdate({ op: "switch", ref }, "switched").catch(() => {});
|
||||
}, [pick, postUpdate, updateInfo]);
|
||||
const prevChannel = channel;
|
||||
const prevInfo = updateInfo;
|
||||
if (hit && hit.channel) {
|
||||
setChannel(hit.channel);
|
||||
setUpdateInfo((cur) => Object.assign({}, cur || {}, { channel: hit.channel }));
|
||||
}
|
||||
postUpdate({ op: "switch", ref }, "switched", id).catch(() => {
|
||||
setChannel(prevChannel);
|
||||
setUpdateInfo(prevInfo);
|
||||
});
|
||||
}, [channel, pick, postUpdate, updateInfo]);
|
||||
|
||||
const loadAll = useCallback(() => {
|
||||
const tr = tRef.current;
|
||||
@@ -1152,17 +1248,19 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const hostSurface = hostSurfaceOf(s);
|
||||
const versions = (updateInfo && updateInfo.versions) || [];
|
||||
const channelNow = (updateInfo && updateInfo.channel) || channel || "stable";
|
||||
const renderLane = (id) => {
|
||||
const localVer = (s && s.plugin_version) || (updateInfo && updateInfo.localVersion) || "";
|
||||
const renderEdition = (id) => {
|
||||
const lane = (updateInfo && updateInfo.lanes && updateInfo.lanes[id]) || {};
|
||||
const list = versions.filter((item) => item.channel === id);
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item));
|
||||
const selectedRef = pick[id] || "";
|
||||
const hit = list.find((item) => item.ref === selectedRef) || list.find((item) => item.current) || list.find((item) => item.latest);
|
||||
const onLane = channelNow === id;
|
||||
const noBeta = id === "beta" && updateInfo && updateInfo.hasBeta === false && !list.length;
|
||||
const pickedOther = Boolean(hit && selectedRef && !hit.current);
|
||||
const thisJob = updateJob && updateJob.id === id ? updateJob : null;
|
||||
let actionLabel = t("btn.checkUpdate");
|
||||
let actionKind;
|
||||
let actionClick = checkUpdate;
|
||||
let actionClick = () => checkUpdate(id);
|
||||
let actionDisabled = updateBusy || Boolean(noBeta);
|
||||
if (noBeta) {
|
||||
actionLabel = t("update.noBeta");
|
||||
@@ -1175,43 +1273,39 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
actionLabel = id === "beta" ? t("channel.useBeta") : t("channel.useStable");
|
||||
actionKind = "primary";
|
||||
actionClick = () => changeChannel(id);
|
||||
} else if (lane.hasUpdate) {
|
||||
} else if (canApplyUpdate && lane.hasUpdate) {
|
||||
actionLabel = t("btn.doUpdate");
|
||||
actionKind = "primary";
|
||||
actionClick = () => doUpdate(id);
|
||||
}
|
||||
if (updateBusy) {
|
||||
if (pickedOther || !onLane) actionLabel = t("update.switching");
|
||||
else if (lane.hasUpdate && onLane) actionLabel = t("btn.doUpdate.busy");
|
||||
else actionLabel = t("btn.checkUpdate.busy");
|
||||
if (thisJob) {
|
||||
if (thisJob.kind === "check") actionLabel = t("btn.checkUpdate.busy");
|
||||
else if (thisJob.kind === "done") actionLabel = t("btn.doUpdate.busy");
|
||||
else actionLabel = t("update.switching");
|
||||
}
|
||||
const verText = lane.version ? "v" + lane.version : (hit && hit.version ? "v" + hit.version : "—");
|
||||
return h("div", {
|
||||
className: "dshp-lane" + (onLane ? " is-on" : "") + (id === "beta" ? " is-beta" : ""),
|
||||
className: "dshp-edition" + (onLane ? " is-on" : ""),
|
||||
"aria-label": t("channel." + id),
|
||||
},
|
||||
h("p", { className: "dshp-lane-kicker" }, onLane ? t("channel.now") : t("channel.other")),
|
||||
h("div", { className: "dshp-lane-h" },
|
||||
h("strong", null, t("channel." + id)),
|
||||
h("span", { className: "dshp-lane-ver" }, verText),
|
||||
h("span", { className: "dshp-edition-name" },
|
||||
t("channel." + id),
|
||||
onLane ? h("em", { className: "dshp-now-mark" }, t("update.current")) : null,
|
||||
),
|
||||
h("div", { className: "dshp-lane-ops" },
|
||||
h("select", {
|
||||
className: "dshp-field dshp-ver",
|
||||
value: selectedRef || (hit && hit.ref) || "",
|
||||
disabled: updateBusy || !list.length,
|
||||
onChange: (e) => setPick((prev) => Object.assign({}, prev, { [id]: e.target.value })),
|
||||
"aria-label": t("update.pick"),
|
||||
},
|
||||
list.length
|
||||
? list.map((item) => h("option", {
|
||||
key: item.ref + (item.sha || ""),
|
||||
value: item.ref,
|
||||
}, (item.version ? "v" + item.version : item.label) + (item.current ? " · " + t("update.current") : item.latest ? " · " + t("update.tip") : "")))
|
||||
: h("option", { value: "" }, noBeta ? t("update.noBeta") : t("update.pick")),
|
||||
),
|
||||
h(Btn, { kind: actionKind, disabled: actionDisabled, onClick: actionClick }, actionLabel),
|
||||
h("select", {
|
||||
className: "dshp-field dshp-ver",
|
||||
value: selectedRef || (hit && hit.ref) || "",
|
||||
disabled: updateBusy || !list.length,
|
||||
onChange: (e) => setPick((prev) => Object.assign({}, prev, { [id]: e.target.value })),
|
||||
"aria-label": t("update.pick"),
|
||||
},
|
||||
list.length
|
||||
? list.map((item) => h("option", {
|
||||
key: item.ref + (item.sha || ""),
|
||||
value: item.ref,
|
||||
}, (item.version ? "v" + item.version : item.label) + (item.latest && !item.current ? " · " + t("update.tip") : "")))
|
||||
: h("option", { value: "" }, noBeta ? t("update.noBeta") : t("update.pick")),
|
||||
),
|
||||
h(Btn, { tiny: true, kind: actionKind, disabled: actionDisabled, onClick: actionClick }, actionLabel),
|
||||
);
|
||||
};
|
||||
return h("section", { className: "dshp-panel", "aria-label": t("purge.title") },
|
||||
@@ -1220,9 +1314,14 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
h("span", { className: "dshp-pill" }, t("surface." + hostSurface)),
|
||||
),
|
||||
h("div", { className: "dshp-rel" },
|
||||
h("div", { className: "dshp-lanes" },
|
||||
renderLane("stable"),
|
||||
renderLane("beta"),
|
||||
h("div", { className: "dshp-now" },
|
||||
h("span", { className: "dshp-now-label" }, t("channel.local")),
|
||||
h("b", { className: "dshp-now-ver" }, localVer ? "v" + localVer : "—"),
|
||||
h("em", { className: "dshp-now-mark" }, t("update.current")),
|
||||
),
|
||||
h("div", { className: "dshp-editions" },
|
||||
renderEdition("stable"),
|
||||
renderEdition("beta"),
|
||||
),
|
||||
noticeNode(updateNotice),
|
||||
),
|
||||
@@ -1520,6 +1619,311 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
);
|
||||
}
|
||||
|
||||
function skillUiAllowed(d) {
|
||||
if (!d) return false;
|
||||
const ver = String(d.plugin_version || d.localVersion || "").replace(/^v/i, "");
|
||||
if (/^1\.1\.11(?:-|$)/.test(ver)) return false;
|
||||
const parts = ver.match(/^(\d+)\.(\d+)\.(\d+)/);
|
||||
if (!parts) return false;
|
||||
if (+parts[1] !== 1) return +parts[1] > 1;
|
||||
if (+parts[2] !== 1) return +parts[2] > 1;
|
||||
return +parts[3] >= 12;
|
||||
}
|
||||
|
||||
function keepListedVersion(item) {
|
||||
return !/^1\.1\.11-beta/i.test(String((item && item.version) || "").replace(/^v/i, ""));
|
||||
}
|
||||
|
||||
function SkillsSection() {
|
||||
const t = useT();
|
||||
const tRef = useRef(t);
|
||||
tRef.current = t;
|
||||
const [onBeta, setOnBeta] = useState(false);
|
||||
const [st, setSt] = useState(null);
|
||||
const [editId, setEditId] = useState(null);
|
||||
const [editDesc, setEditDesc] = useState("");
|
||||
const [content, setContent] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [notice, setNotice] = useState({ kind: "idle", text: "" });
|
||||
const zipRef = useRef(null);
|
||||
const folderRef = useRef(null);
|
||||
|
||||
const loadStatus = useCallback(() => {
|
||||
const tr = tRef.current;
|
||||
const fail = (e) => {
|
||||
setSt({ ok: false, skills: [] });
|
||||
setNotice({
|
||||
kind: "error",
|
||||
text: skillsRouteMissing(e) ? tr("err.skills.needRestart") : tr("err.skills", { error: (e && e.message) || e || "bad response" }),
|
||||
});
|
||||
};
|
||||
const apply = (d) => {
|
||||
if (d && d.ok) setSt({ ok: true, skills: d.skills || [] });
|
||||
else fail({ message: (d && d.error) || "bad response" });
|
||||
};
|
||||
apiJson("/dsh-purge/status")
|
||||
.then((d) => {
|
||||
const allowed = skillUiAllowed(d);
|
||||
setOnBeta(allowed);
|
||||
if (!allowed) {
|
||||
setSt(null);
|
||||
return;
|
||||
}
|
||||
if (d.skills) {
|
||||
apply({ ok: true, skills: d.skills });
|
||||
return;
|
||||
}
|
||||
skillsApi("status").then(apply).catch(fail);
|
||||
})
|
||||
.catch(() => {
|
||||
setOnBeta(false);
|
||||
setSt(null);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => { loadStatus(); }, [loadStatus]);
|
||||
|
||||
const doPost = useCallback((action, payload, after) => {
|
||||
setBusy(true);
|
||||
setNotice({ kind: "idle", text: "" });
|
||||
skillsApi(action, payload)
|
||||
.then((d) => {
|
||||
if (d && d.ok) {
|
||||
setNotice({ kind: "ok", text: t("ok.done") });
|
||||
loadStatus();
|
||||
if (after) after(d);
|
||||
} else {
|
||||
setNotice({ kind: "error", text: t("err.action", { error: (d && d.error) || "" }) });
|
||||
}
|
||||
})
|
||||
.catch((e) => setNotice({
|
||||
kind: "error",
|
||||
text: skillsRouteMissing(e) ? t("err.skills.needRestart") : t("err.action", { error: e.message }),
|
||||
}))
|
||||
.finally(() => setBusy(false));
|
||||
}, [loadStatus, t]);
|
||||
|
||||
const openSkill = useCallback((id) => {
|
||||
setBusy(true);
|
||||
skillsApi("read", { id: id })
|
||||
.then((d) => {
|
||||
if (d.ok) {
|
||||
setEditId(id);
|
||||
setEditDesc(d.description || "");
|
||||
setContent(typeof d.content === "string" ? d.content : "");
|
||||
} else setNotice({ kind: "error", text: t("err.read", { error: d.error || "" }) });
|
||||
})
|
||||
.catch((e) => setNotice({ kind: "error", text: t("err.read", { error: e.message }) }))
|
||||
.finally(() => setBusy(false));
|
||||
}, [t]);
|
||||
|
||||
const clearEditor = () => {
|
||||
setEditId(null);
|
||||
setEditDesc("");
|
||||
setContent("");
|
||||
};
|
||||
|
||||
const readAsBase64 = (file) => new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const text = String(reader.result || "");
|
||||
const at = text.indexOf(",");
|
||||
resolve(at >= 0 ? text.slice(at + 1) : text);
|
||||
};
|
||||
reader.onerror = () => reject(new Error(t("need.import")));
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
|
||||
const importZip = (file) => {
|
||||
if (!file) {
|
||||
setNotice({ kind: "error", text: t("need.import") });
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setNotice({ kind: "ok", text: t("skills.importing") });
|
||||
readAsBase64(file)
|
||||
.then((data) => skillsApi("import", { data, name: file.name }))
|
||||
.then((d) => {
|
||||
if (!d || !d.ok) throw new Error((d && d.error) || "");
|
||||
setNotice({ kind: "ok", text: t("saved.import", { count: (d.imported || []).length || 1 }) });
|
||||
loadStatus();
|
||||
})
|
||||
.catch((e) => setNotice({
|
||||
kind: "error",
|
||||
text: skillsRouteMissing(e) ? t("err.skills.needRestart") : t("err.action", { error: e.message }),
|
||||
}))
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
|
||||
const keepFolderFile = (file) => {
|
||||
const rel = String(file.webkitRelativePath || file.name || "").replace(/\\/g, "/");
|
||||
if (!rel || rel.includes("..")) return false;
|
||||
if (/(^|\/)(node_modules|\.git|__MACOSX|\.system)(\/|$)/i.test(rel)) return false;
|
||||
if (/(^|\/)\._/.test(rel) || /\/\.DS_Store$/i.test(rel)) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
const importFolder = (list) => {
|
||||
const files = Array.from(list || []).filter(keepFolderFile);
|
||||
if (!files.length) {
|
||||
setNotice({ kind: "error", text: t("err.import.folder") });
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setNotice({ kind: "ok", text: t("skills.importing") });
|
||||
Promise.all(files.map((file) => readAsBase64(file).then((content) => ({
|
||||
path: file.webkitRelativePath || file.name,
|
||||
content,
|
||||
encoding: "base64",
|
||||
}))))
|
||||
.then((payload) => skillsApi("import", {
|
||||
files: payload,
|
||||
name: String(payload[0] && payload[0].path || "").split("/")[0],
|
||||
}))
|
||||
.then((d) => {
|
||||
if (!d || !d.ok) throw new Error((d && d.error) || "");
|
||||
setNotice({ kind: "ok", text: t("saved.import", { count: (d.imported || []).length || 1 }) });
|
||||
loadStatus();
|
||||
})
|
||||
.catch((e) => setNotice({
|
||||
kind: "error",
|
||||
text: skillsRouteMissing(e) ? t("err.skills.needRestart") : t("err.action", { error: e.message }),
|
||||
}))
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
|
||||
if (!onBeta) return null;
|
||||
|
||||
let list;
|
||||
if (!st) {
|
||||
list = h("div", { className: "dshp-skel", style: { height: 80, margin: 12 } });
|
||||
} else if (!st.skills || st.skills.length === 0) {
|
||||
list = h("p", { className: "dshp-empty" }, t("skills.empty"));
|
||||
} else {
|
||||
list = st.skills.map((item) => {
|
||||
const isEdit = item.id === editId;
|
||||
return h("div", {
|
||||
key: item.id,
|
||||
className: "dshp-ruleitem" + (isEdit ? " is-edit" : ""),
|
||||
role: "button",
|
||||
tabIndex: 0,
|
||||
onClick: () => openSkill(item.id),
|
||||
onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); openSkill(item.id); } },
|
||||
},
|
||||
h("div", { className: "dshp-rule-main" },
|
||||
h("span", { className: "dshp-rule-name" }, item.id),
|
||||
h("span", { className: "dshp-rule-meta" },
|
||||
(item.valid ? item.description : t("skills.invalid")) + " · " + formatSize(item.size),
|
||||
),
|
||||
item.valid ? h("span", { className: "dshp-rule-meta" },
|
||||
[
|
||||
item.userInvocable ? t("skills.call.slash", { cmd: "/" + item.id }) : t("skills.call.userOff"),
|
||||
item.modelInvocable ? t("skills.call.model") : t("skills.call.modelOff"),
|
||||
].join(" · "),
|
||||
) : null,
|
||||
),
|
||||
h("div", { className: "dshp-rule-ops" },
|
||||
h(Btn, {
|
||||
tiny: true,
|
||||
kind: "danger",
|
||||
disabled: busy,
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
if (!window.confirm(t("confirm.delete.skill", { id: item.id }))) return;
|
||||
if (editId === item.id) clearEditor();
|
||||
doPost("delete", { id: item.id });
|
||||
},
|
||||
}, t("delete")),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return h("section", { className: "dshp-panel", "aria-label": t("skills.title") },
|
||||
h("div", { className: "dshp-head" },
|
||||
h("h3", { className: "dshp-title" }, t("skills.title")),
|
||||
h("div", { className: "dshp-row", style: { margin: 0 } }, noticeNode(notice)),
|
||||
),
|
||||
h("p", { className: "dshp-hint", style: { margin: "0 0 10px", color: "var(--dshp-mute)", fontSize: 12 } }, hostText(t, "skills.hint", hostSurfaceOf())),
|
||||
h("div", { className: "dshp-split" },
|
||||
h("div", { className: "dshp-rulelist" },
|
||||
h("div", { className: "dshp-rulebody" }, list),
|
||||
h("div", { className: "dshp-create" },
|
||||
h("div", { className: "dshp-create-row" },
|
||||
h("input", {
|
||||
ref: zipRef,
|
||||
type: "file",
|
||||
accept: ".zip,.tgz,.tar.gz,.tar,.skill",
|
||||
style: { display: "none" },
|
||||
onChange: (e) => {
|
||||
const file = e.target.files && e.target.files[0];
|
||||
e.target.value = "";
|
||||
importZip(file);
|
||||
},
|
||||
}),
|
||||
h("input", {
|
||||
ref: (el) => {
|
||||
folderRef.current = el;
|
||||
if (!el) return;
|
||||
el.setAttribute("webkitdirectory", "");
|
||||
el.setAttribute("directory", "");
|
||||
el.multiple = true;
|
||||
},
|
||||
type: "file",
|
||||
multiple: true,
|
||||
style: { display: "none" },
|
||||
onChange: (e) => {
|
||||
const files = Array.from((e.target && e.target.files) || []);
|
||||
e.target.value = "";
|
||||
importFolder(files);
|
||||
},
|
||||
}),
|
||||
h(Btn, {
|
||||
kind: "primary",
|
||||
tiny: true,
|
||||
disabled: busy,
|
||||
onClick: () => zipRef.current && zipRef.current.click(),
|
||||
}, t("btn.importZip")),
|
||||
h(Btn, {
|
||||
tiny: true,
|
||||
disabled: busy,
|
||||
onClick: () => folderRef.current && folderRef.current.click(),
|
||||
}, t("btn.importFolder")),
|
||||
),
|
||||
),
|
||||
),
|
||||
h("div", { className: "dshp-editor" },
|
||||
editId ? [
|
||||
h("div", { key: "meta", className: "dshp-row" },
|
||||
h("input", {
|
||||
className: "dshp-field",
|
||||
placeholder: t("ph.skill.desc"),
|
||||
value: editDesc,
|
||||
onChange: (e) => setEditDesc(e.target.value),
|
||||
}),
|
||||
),
|
||||
h("textarea", {
|
||||
key: "body",
|
||||
className: "dshp-area",
|
||||
value: content,
|
||||
onChange: (e) => setContent(e.target.value),
|
||||
spellCheck: false,
|
||||
placeholder: "",
|
||||
}),
|
||||
h("div", { key: "save", className: "dshp-row" },
|
||||
h(Btn, {
|
||||
kind: "primary",
|
||||
disabled: busy,
|
||||
onClick: () => doPost("save", { id: editId, content, description: editDesc }),
|
||||
}, t("btn.saveSkill")),
|
||||
noticeNode(notice),
|
||||
),
|
||||
] : h("div", { className: "dshp-editor-empty" }, t("skills.pick")),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function reopenAfterRestart() {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete("token");
|
||||
@@ -1661,6 +2065,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
),
|
||||
h(PurgifySection, null),
|
||||
h(RulesSection, null),
|
||||
h(SkillsSection, null),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user