feat: 支持自由编辑破限提示词与一键恢复默认(v0.2.17)

This commit is contained in:
yexi-by committed 2026-11-28 04:47:29 +08:00
1 parent 3d7177dcb9
commit ccc61fac4c
17 files changed
+1122 -246

No files matched your search

+545 -215
View File
@@ -11,6 +11,10 @@ window.__ModuleLoader__.load({
const RPC_CHANNEL = "/api";
const RPC_NAMESPACE = "dsh-unrestricted";
const SETTINGS_NS = "unrestricted";
/** Normalize line endings so YAML/browser values compare identically across OSes. */
function normalizePromptText(value) {
return typeof value === "string" ? value.replace(/\r\n?/g, "\n") : "";
}
/** Human-readable error text for the banner. */
function messageOf(error) {
return error instanceof Error ? error.message : String(error);
@@ -26,6 +30,9 @@ window.__ModuleLoader__.load({
let snapshot = {
enabled: false,
stripHostIdentity: false,
customPrompt: "",
defaultPrompt: "",
isCustomPrompt: false,
writable: false,
settingsStatus: "loading",
status: null,
@@ -47,10 +54,16 @@ window.__ModuleLoader__.load({
const settingsSnapshot = settings.getSnapshot();
const enabled = settingsSnapshot.value?.enabled === true;
const stripHostIdentity = settingsSnapshot.value?.stripHostIdentity === true;
if (enabled !== snapshot.enabled || stripHostIdentity !== snapshot.stripHostIdentity) invalidatePreviews();
const customPrompt = normalizePromptText(settingsSnapshot.value?.customPrompt);
const defaultPrompt = normalizePromptText(snapshot.status?.defaultPrompt);
const isCustomPrompt = customPrompt.trim() !== "" && (defaultPrompt === "" || customPrompt !== defaultPrompt);
if (enabled !== snapshot.enabled || stripHostIdentity !== snapshot.stripHostIdentity || customPrompt !== snapshot.customPrompt) invalidatePreviews();
snapshot = {
enabled,
stripHostIdentity,
customPrompt,
defaultPrompt,
isCustomPrompt,
writable: settingsSnapshot.writable,
settingsStatus: settingsSnapshot.status,
status: snapshot.status,
@@ -106,24 +119,52 @@ window.__ModuleLoader__.load({
function refresh(clearPreviews = false) {
return readStatus("status", clearPreviews);
}
function updateSetting(field, value) {
return whileBusy(async () => {
async function updateSetting(field, value) {
let accepted = false;
await whileBusy(async () => {
try {
await settings.set(field, value);
accepted = await settings.set(field, value) !== false;
await refresh(true);
} catch (error) {
snapshot = {
...snapshot,
message: messageOf(error)
};
accepted = false;
}
});
return accepted;
}
function setEnabled(enabled) {
return updateSetting("enabled", enabled);
async function clearCustomPrompt() {
let accepted = false;
await whileBusy(async () => {
try {
accepted = (typeof settings.unset === "function" ? await settings.unset("customPrompt") : await settings.set("customPrompt", "")) !== false;
await refresh(true);
} catch (error) {
snapshot = {
...snapshot,
message: messageOf(error)
};
accepted = false;
}
});
return accepted;
}
function setStripHostIdentity(strip) {
return updateSetting("stripHostIdentity", strip);
async function setEnabled(enabled) {
await updateSetting("enabled", enabled);
}
async function setStripHostIdentity(strip) {
await updateSetting("stripHostIdentity", strip);
}
function setCustomPrompt(prompt) {
const normalized = normalizePromptText(prompt);
const defaultPrompt = normalizePromptText(snapshot.status?.defaultPrompt);
if (normalized.trim() === "" || defaultPrompt !== "" && normalized === defaultPrompt) return clearCustomPrompt();
return updateSetting("customPrompt", normalized);
}
function resetCustomPrompt() {
return clearCustomPrompt();
}
function recheck() {
return readStatus("recheck", true);
@@ -182,6 +223,8 @@ window.__ModuleLoader__.load({
hooks: { view },
setEnabled,
setStripHostIdentity,
setCustomPrompt,
resetCustomPrompt,
recheck,
refresh: () => refresh(true),
loadPreview
@@ -201,9 +244,27 @@ window.__ModuleLoader__.load({
description: "开启后,各运行模式与委派子代理的系统提示词将自动融合无限制本地执行契约;关闭即恢复 DSH 原版提示词。切换从下一次请求生效,不改动正在执行的请求、工具定义、权限配置与会话历史。",
toggle: "启用破限模式",
stripHostBadge: "已隐去宿主标识",
customPromptBadge: "已自定义提示词",
stripHostTitle: "隐藏宿主品牌标识",
stripHostDesc: "移除系统提示词与运行时上下文中的 DeepSeek Harness / DSH 身份段落及开发界面路径,避免第三方路由(适用于 Google Antigravity 反重力反代、Google AI Studio PG 渠道等)因检测到客户端特征而返回 429 拦截(可独立于破限开关生效)。",
scopeNote: "仅作用于由 DSH 组装的系统提示词;模型平台或外部网关的远端策略不在本插件覆盖范围内。",
promptEditorTitle: "破限提示词",
promptEditorDesc: "默认内置英文破限契约;支持自由删改敏感关键词或替换为自定义规则,保存后从下一次请求生效。",
promptStateDefault: "内置默认",
promptStateCustom: "已自定义",
promptStateUnsaved: "未保存",
openPromptEditor: "编辑提示词",
closePromptEditor: "收起编辑",
promptEditorLoading: "正在加载内置提示词内容…",
promptEditorPlaceholder: "输入要注入到 unrestricted:execution-mode 段落的提示词内容…",
promptEditorChars: "字符",
promptEditorShortcutHint: "Ctrl/Cmd + Enter 保存",
promptEditorEmptyHint: "提示词不能为空;如需使用内置内容,请点击「恢复默认」。",
promptEditorSaved: "已保存,下一次请求生效",
promptEditorResetDone: "已恢复内置默认提示词",
promptEditorSave: "保存更改",
promptEditorDiscard: "放弃更改",
promptEditorReset: "恢复默认",
statusTitle: "模式覆盖与提示词预览",
statusSubtitle: "覆盖全部 4 种预设及委派子代理,可随时展开核对或复制融合后的完整提示词。",
modeStandard: "Standard 标准模式",
@@ -252,9 +313,27 @@ window.__ModuleLoader__.load({
description: "When enabled, system prompts across all modes and delegated subagents are fused with the unrestricted local execution contract; disabling restores the stock DSH prompt immediately. Takes effect from the next request without altering in-flight turns, tool schemas, permissions, or session history.",
toggle: "Enable unrestricted mode",
stripHostBadge: "Host identity stripped",
customPromptBadge: "Custom prompt",
stripHostTitle: "Strip host brand identity",
stripHostDesc: "Remove DeepSeek Harness / DSH identity sections and Web GUI checkout context from assembled prompts to prevent HTTP 429 client-fingerprinting blocks on third-party routes such as Google Antigravity proxies and Google AI Studio PG channels (works independently of the main toggle).",
scopeNote: "Applies only to system prompts assembled by DSH; upstream model provider policies outside the prompt are out of scope.",
promptEditorTitle: "Execution Prompt",
promptEditorDesc: "Built-in English contract tuned for reliability. Freely edit keywords or replace with custom rules; saved changes apply on the next request.",
promptStateDefault: "Default",
promptStateCustom: "Customized",
promptStateUnsaved: "Unsaved",
openPromptEditor: "Edit prompt",
closePromptEditor: "Hide editor",
promptEditorLoading: "Loading built-in prompt…",
promptEditorPlaceholder: "Enter the prompt text injected into the unrestricted:execution-mode section…",
promptEditorChars: "chars",
promptEditorShortcutHint: "Ctrl/Cmd + Enter to save",
promptEditorEmptyHint: "Prompt cannot be empty. Click \"Reset to default\" to restore the built-in prompt.",
promptEditorSaved: "Saved — applies on next request",
promptEditorResetDone: "Restored built-in default prompt",
promptEditorSave: "Save changes",
promptEditorDiscard: "Discard",
promptEditorReset: "Reset to default",
statusTitle: "Mode Coverage & Prompt Preview",
statusSubtitle: "Covers all 4 built-in presets and delegated subagents. Expand any mode to inspect or copy the full fused prompt.",
modeStandard: "Standard",
@@ -543,6 +622,67 @@ window.__ModuleLoader__.load({
overflow-wrap: anywhere;
}
.dsh-unrestricted-editor {
display: flex;
flex-direction: column;
gap: 8px;
padding-top: 10px;
border-top: 1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2));
}
.dsh-unrestricted-editorInput {
width: 100%;
min-height: 240px;
max-height: 520px;
box-sizing: border-box;
margin: 0;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: var(--dsw-radius-md, 8px);
padding: 10px 12px;
background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-layer-2));
color: var(--dsw-alias-label-primary);
font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, monospace);
font-size: 12px;
line-height: 18px;
resize: vertical;
outline: none;
transition: border-color 120ms ease;
}
.dsh-unrestricted-editorInput:focus {
border-color: var(--dsw-alias-state-business-primary, var(--dsw-alias-border-l1));
}
.dsh-unrestricted-editorInput:disabled {
opacity: 0.65;
cursor: not-allowed;
}
.dsh-unrestricted-editorFooter {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px 12px;
}
.dsh-unrestricted-editorStatus {
flex: 1;
min-width: 160px;
margin: 0;
font-size: 12px;
line-height: 18px;
color: var(--dsw-alias-label-tertiary);
}
.dsh-unrestricted-editorStatus[data-tone='success'] {
color: var(--dsw-alias-state-success-primary);
}
.dsh-unrestricted-editorStatus[data-tone='warning'] {
color: var(--dsw-alias-state-warning-primary, var(--dsw-alias-state-error-primary));
}
@media (max-width: 640px) {
.dsh-unrestricted-card {
padding: 14px;
@@ -575,6 +715,7 @@ window.__ModuleLoader__.load({
/**
* The unrestricted settings view:
* - Master toggle card with native Switch, status Tag, and scope boundary notes
* - Editable execution-mode prompt card with save, discard, and reset-to-default
* - Per-preset coverage list with StateDot, Tag, preview drawer, and one-click copy
*/
/** Mode rows in display order, with their locale label and description keys. */
@@ -648,6 +789,10 @@ window.__ModuleLoader__.load({
const detail = entry.preview?.reason ?? entry.message;
return detail !== void 0 && detail.trim() !== "" ? `${t("previewUnavailable")}${detail}` : t("errorPreviewFailed");
}
/** UTF-8 byte length of a string in browser environments. */
function utf8ByteLength(text) {
return new TextEncoder().encode(text).length;
}
/**
* Render the unrestricted configuration cards.
*/
@@ -657,7 +802,26 @@ window.__ModuleLoader__.load({
const status = view.status;
const [openPreview, setOpenPreview] = (0, react.useState)(null);
const [copiedPreset, setCopiedPreset] = (0, react.useState)(null);
const [editorOpen, setEditorOpen] = (0, react.useState)(false);
const [draft, setDraft] = (0, react.useState)("");
const [hasLocalEdit, setHasLocalEdit] = (0, react.useState)(false);
const [promptFeedback, setPromptFeedback] = (0, react.useState)(null);
const feedbackTimerRef = (0, react.useRef)(null);
const openEntry = openPreview === null ? void 0 : view.previews[openPreview];
const effectivePrompt = view.customPrompt.trim() !== "" ? view.customPrompt : view.defaultPrompt;
const normalizedDraft = draft.replace(/\r\n?/g, "\n");
const isDirty = hasLocalEdit && normalizedDraft !== effectivePrompt;
const isDraftEmpty = normalizedDraft.trim() === "";
const editorReady = effectivePrompt !== "" || view.status !== null;
const controlsEditable = view.writable && view.settingsStatus === "ready" && !view.busy;
const canSave = controlsEditable && isDirty && !isDraftEmpty;
const canReset = controlsEditable && (view.isCustomPrompt || view.defaultPrompt !== "" && normalizedDraft !== view.defaultPrompt);
(0, react.useEffect)(() => {
if (!hasLocalEdit) setDraft(effectivePrompt);
}, [effectivePrompt, hasLocalEdit]);
(0, react.useEffect)(() => () => {
if (feedbackTimerRef.current !== null) clearTimeout(feedbackTimerRef.current);
}, []);
(0, react.useEffect)(() => {
if (openPreview !== null && openEntry === void 0) loadPreview(openPreview);
}, [
@@ -665,6 +829,35 @@ window.__ModuleLoader__.load({
openEntry,
loadPreview
]);
function showPromptFeedback(kind) {
setPromptFeedback(kind);
if (feedbackTimerRef.current !== null) clearTimeout(feedbackTimerRef.current);
feedbackTimerRef.current = setTimeout(() => {
setPromptFeedback(null);
feedbackTimerRef.current = null;
}, 2600);
}
async function handleSavePrompt() {
if (!canSave) return;
if (!await props.setCustomPrompt(draft)) return;
const matchedDefault = view.defaultPrompt !== "" && normalizedDraft === view.defaultPrompt;
setHasLocalEdit(false);
showPromptFeedback(matchedDefault ? "reset" : "saved");
}
function handleDiscardPrompt() {
setDraft(effectivePrompt);
setHasLocalEdit(false);
setPromptFeedback(null);
}
async function handleResetPrompt() {
if (!canReset) return;
if (view.isCustomPrompt) {
if (!await props.resetCustomPrompt()) return;
}
setDraft(view.defaultPrompt);
setHasLocalEdit(false);
showPromptFeedback("reset");
}
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 summaryTone = view.settingsStatus !== "ready" ? "neutral" : hasFailedMode ? "warning" : view.enabled ? "success" : "neutral";
@@ -697,219 +890,356 @@ window.__ModuleLoader__.load({
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-root",
"aria-busy": view.busy,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
className: "dsh-unrestricted-card",
"aria-labelledby": "dsh-unrestricted-main-title",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-header",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerTitle",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
id: "dsh-unrestricted-main-title",
className: "dsh-unrestricted-title",
children: t("title")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: summaryTone,
children: t(summaryKey)
}),
view.settingsStatus === "ready" && view.stripHostIdentity && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "outline",
children: t("stripHostBadge")
})
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerControls",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-switchLabel",
children: t("toggle")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
checked: view.enabled,
disabled: !view.writable || view.settingsStatus !== "ready" || view.busy,
label: t("toggle"),
onChange: (checked) => {
props.setEnabled(checked);
}
})]
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-description",
children: t("description")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("scopeNote")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-optionRow",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-optionCopy",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-modeName",
children: t("stripHostTitle")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("stripHostDesc")
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
checked: view.stripHostIdentity,
disabled: !view.writable || view.settingsStatus !== "ready" || view.busy,
label: t("stripHostTitle"),
onChange: (checked) => {
props.setStripHostIdentity(checked);
}
})]
}),
view.settingsStatus === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
role: "status",
children: t("settingsLoading")
}),
view.settingsStatus === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "info",
role: "status",
children: t("settingsUnavailable")
}),
view.message !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "error",
role: "alert",
children: localizeBannerError(view.message, t)
})
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
className: "dsh-unrestricted-card",
"aria-labelledby": "dsh-unrestricted-modes-title",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-header",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerTitle",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
id: "dsh-unrestricted-modes-title",
className: "dsh-unrestricted-subtitle",
children: t("statusTitle")
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerControls",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "outline",
size: "sm",
disabled: view.busy,
onClick: () => {
props.refresh();
},
children: t("refresh")
})
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("statusSubtitle")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
className: "dsh-unrestricted-modes",
children: MODE_ROWS.map((row) => {
const mode = status?.modes[row.id];
const entry = view.previews[row.id];
const isOpen = openPreview === row.id;
const previewText = entry?.preview?.text;
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
className: "dsh-unrestricted-mode",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
className: "dsh-unrestricted-card",
"aria-labelledby": "dsh-unrestricted-main-title",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-header",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerTitle",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeMain",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeInfo",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeHeading",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: dotStateOf(mode) }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-modeName",
children: t(row.labelKey)
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "outline",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-mono",
children: t(row.presetKey)
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: modeTagTone(mode),
children: t(stateKey(mode))
})
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-modeDesc",
children: t(row.descKey)
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerControls",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: isOpen ? "toolbar" : "outline",
size: "sm",
onClick: () => {
togglePreview(row.id);
},
children: t(isOpen ? "hidePreview" : "showPreview")
})
})]
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
id: "dsh-unrestricted-main-title",
className: "dsh-unrestricted-title",
children: t("title")
}),
mode !== void 0 && mode.issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-issues",
children: formatIssues(mode.issues)
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: summaryTone,
children: t(summaryKey)
}),
isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-preview",
children: entry === void 0 || entry.status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
role: "status",
children: t("previewLoading")
}) : entry.status === "failed" || entry.preview?.available === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "error",
role: "alert",
children: localizePreviewError(entry, t)
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-previewHeader",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
className: "dsh-unrestricted-previewMeta",
children: [
entry.preview?.lines,
" ",
t("previewSize"),
entry.preview?.bytes !== void 0 && ` · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(entry.preview.bytes)}`,
entry.preview?.source !== void 0 && ` · ${t(entry.preview.source === "live" ? "previewSourceLive" : "previewSourceStanding")}`
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "ghost",
size: "sm",
onClick: () => {
handleCopyPreview(row.id, previewText);
},
children: t(copiedPreset === row.id ? "copiedPreview" : "copyPreview")
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
className: "dsh-unrestricted-previewText",
children: previewText
})] })
view.settingsStatus === "ready" && view.stripHostIdentity && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "outline",
children: t("stripHostBadge")
}),
view.settingsStatus === "ready" && view.isCustomPrompt && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "info",
children: t("customPromptBadge")
})
]
}, row.id);
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerControls",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-switchLabel",
children: t("toggle")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
checked: view.enabled,
disabled: !view.writable || view.settingsStatus !== "ready" || view.busy,
label: t("toggle"),
onChange: (checked) => {
props.setEnabled(checked);
}
})]
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-description",
children: t("description")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("scopeNote")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-optionRow",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-optionCopy",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-modeName",
children: t("stripHostTitle")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("stripHostDesc")
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
checked: view.stripHostIdentity,
disabled: !view.writable || view.settingsStatus !== "ready" || view.busy,
label: t("stripHostTitle"),
onChange: (checked) => {
props.setStripHostIdentity(checked);
}
})]
}),
view.settingsStatus === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
role: "status",
children: t("settingsLoading")
}),
view.settingsStatus === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "info",
role: "status",
children: t("settingsUnavailable")
}),
view.message !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "error",
role: "alert",
children: localizeBannerError(view.message, t)
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("subagentNote")
})
]
})]
]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
className: "dsh-unrestricted-card",
"aria-labelledby": "dsh-unrestricted-prompt-title",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-header",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerTitle",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
id: "dsh-unrestricted-prompt-title",
className: "dsh-unrestricted-subtitle",
children: t("promptEditorTitle")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: view.isCustomPrompt ? "info" : "neutral",
children: t(view.isCustomPrompt ? "promptStateCustom" : "promptStateDefault")
}),
isDirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "warning",
children: t("promptStateUnsaved")
})
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerControls",
children: [view.isCustomPrompt && !editorOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "ghost",
size: "sm",
disabled: !controlsEditable,
onClick: () => {
handleResetPrompt();
},
children: t("promptEditorReset")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: editorOpen ? "toolbar" : "outline",
size: "sm",
onClick: () => {
setEditorOpen((open) => !open);
},
children: t(editorOpen ? "closePromptEditor" : "openPromptEditor")
})]
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("promptEditorDesc")
}),
editorOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-editor",
children: !editorReady ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
role: "status",
children: t("promptEditorLoading")
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-previewHeader",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
className: "dsh-unrestricted-previewMeta",
children: [
draft === "" ? 0 : draft.split("\n").length,
" ",
t("previewSize"),
` · ${draft.length} ${t("promptEditorChars")} · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(utf8ByteLength(draft))}`
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-previewMeta",
children: t("promptEditorShortcutHint")
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
className: "dsh-unrestricted-editorInput",
"aria-label": t("promptEditorTitle"),
placeholder: t("promptEditorPlaceholder"),
spellCheck: false,
value: draft,
disabled: !controlsEditable,
onChange: (event) => {
setDraft(event.target.value);
setHasLocalEdit(true);
setPromptFeedback(null);
},
onKeyDown: (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === "Enter" && canSave) {
event.preventDefault();
handleSavePrompt();
}
}
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-editorFooter",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-editorStatus",
"data-tone": isDraftEmpty ? "warning" : promptFeedback !== null ? "success" : void 0,
role: "status",
children: isDraftEmpty ? t("promptEditorEmptyHint") : promptFeedback === "saved" ? t("promptEditorSaved") : promptFeedback === "reset" ? t("promptEditorResetDone") : ""
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-headerControls",
children: [
isDirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "ghost",
size: "sm",
disabled: view.busy,
onClick: handleDiscardPrompt,
children: t("promptEditorDiscard")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "outline",
size: "sm",
disabled: !canReset,
onClick: () => {
handleResetPrompt();
},
children: t("promptEditorReset")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "primary",
size: "sm",
disabled: !canSave,
onClick: () => {
handleSavePrompt();
},
children: t("promptEditorSave")
})
]
})]
})
] })
})
]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
className: "dsh-unrestricted-card",
"aria-labelledby": "dsh-unrestricted-modes-title",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-header",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerTitle",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
id: "dsh-unrestricted-modes-title",
className: "dsh-unrestricted-subtitle",
children: t("statusTitle")
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerControls",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "outline",
size: "sm",
disabled: view.busy,
onClick: () => {
props.refresh();
},
children: t("refresh")
})
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("statusSubtitle")
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
className: "dsh-unrestricted-modes",
children: MODE_ROWS.map((row) => {
const mode = status?.modes[row.id];
const entry = view.previews[row.id];
const isOpen = openPreview === row.id;
const previewText = entry?.preview?.text;
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
className: "dsh-unrestricted-mode",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeMain",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeInfo",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-modeHeading",
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: dotStateOf(mode) }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-modeName",
children: t(row.labelKey)
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: "outline",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
className: "dsh-unrestricted-mono",
children: t(row.presetKey)
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
tone: modeTagTone(mode),
children: t(stateKey(mode))
})
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-modeDesc",
children: t(row.descKey)
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-headerControls",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: isOpen ? "toolbar" : "outline",
size: "sm",
onClick: () => {
togglePreview(row.id);
},
children: t(isOpen ? "hidePreview" : "showPreview")
})
})]
}),
mode !== void 0 && mode.issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-issues",
children: formatIssues(mode.issues)
}),
isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
className: "dsh-unrestricted-preview",
children: entry === void 0 || entry.status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
role: "status",
children: t("previewLoading")
}) : entry.status === "failed" || entry.preview?.available === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-banner",
"data-tone": "error",
role: "alert",
children: localizePreviewError(entry, t)
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "dsh-unrestricted-previewHeader",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
className: "dsh-unrestricted-previewMeta",
children: [
entry.preview?.lines,
" ",
t("previewSize"),
entry.preview?.bytes !== void 0 && ` · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(entry.preview.bytes)}`,
entry.preview?.source !== void 0 && ` · ${t(entry.preview.source === "live" ? "previewSourceLive" : "previewSourceStanding")}`
]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
variant: "ghost",
size: "sm",
onClick: () => {
handleCopyPreview(row.id, previewText);
},
children: t(copiedPreset === row.id ? "copiedPreview" : "copyPreview")
})]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
className: "dsh-unrestricted-previewText",
children: previewText
})] })
})
]
}, row.id);
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "dsh-unrestricted-note",
children: t("subagentNote")
})
]
})
]
});
}
//#endregion
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"client.js","names":["useState","writeClipboard","Tag","Switch","Button","StateDot","fileSizeText"],"sources":["../src/client/controller.ts","../src/client/locales.ts","../src/client/styles.ts","../src/client/UnrestrictedCard.tsx","../src/client/index.tsx"],"sourcesContent":["/**\n * Browser-half controller for the unrestricted card: binds the `unrestricted`\n * settings namespace (the toggle) and reads per-preset state and previews.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: the ctx.remote Context merge and the forwarded-event key face.\nimport type {} from '@deepseek-ai/dsh-api-remotes/client'\n// Type-only: the ctx.configForms Context merge.\nimport type {} from '@deepseek-ai/dsh-client-ui-settings/client'\n\n/** The toggle section stored in the `unrestricted` settings namespace. */\nexport interface UnrestrictedSettings {\n enabled?: boolean\n stripHostIdentity?: boolean\n}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n stripHostIdentity?: boolean\n /** Current plugin version reported by the host half. */\n version?: string\n modes: Record<string, UnrestrictedModeState>\n}\n\n/** Deploy preview for one preset: what switching on would actually assemble. */\nexport interface UnrestrictedPreview {\n presetId: string\n available: boolean\n /** `live` = bytes a live agent received; `standing` = preset scope, no agent bound. */\n source?: 'live' | 'standing'\n /** Fused prompt text; present when available. */\n text?: string\n bytes?: number\n lines?: number\n /** Structured error code when unavailable. */\n errorCode?: string\n /** Diagnostic reason when unavailable. */\n reason?: string\n}\n\n/** One fetched preview, keyed by preset, plus its in-flight/error state. */\nexport interface UnrestrictedPreviewEntry {\n status: 'loading' | 'ready' | 'failed'\n preview?: UnrestrictedPreview\n errorCode?: string\n message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; false until the settings scope first syncs. */\n enabled: boolean\n /** Persisted host-brand stripping toggle; false until synced. */\n stripHostIdentity: boolean\n /** Whether the Host document accepts writes. */\n writable: boolean\n /** Settings scope sync state. */\n settingsStatus: 'loading' | 'ready' | 'unavailable'\n /** Live host status; null until the first RPC answer. */\n status: UnrestrictedStatus | null\n /** presetId -> fetched deploy preview. */\n previews: Record<string, UnrestrictedPreviewEntry>\n /** Whether a settings write or status refresh is in flight. */\n busy: boolean\n /** Last transport/business failure, if any. */\n message?: string\n}\n\n/** Minimal RPC wire shape (structural copy of the host RpcResult). */\ntype RpcResult<T> = { ok: true; value: T } | { ok: false; error: { code: string; message: string } }\n\n/** Minimal observable contract consumed by the slot renderer's hook binding. */\nexport interface UnrestrictedViewSource {\n getSnapshot(): UnrestrictedViewSnapshot\n subscribe(listener: () => void): () => void\n}\n\n/** Inject face handed to the card at registration. */\nexport interface UnrestrictedCardInjected {\n hooks: {\n /** Reactive card view. */\n view: UnrestrictedViewSource\n }\n /** Persist the toggle. */\n setEnabled: (enabled: boolean) => Promise<void>\n /** Persist whether host identity branding is stripped from prompts. */\n setStripHostIdentity: (strip: boolean) => Promise<void>\n /** Re-validate runtime state and refresh. */\n recheck: () => Promise<void>\n /** Re-read host status and invalidate cached previews. */\n refresh: () => Promise<void>\n /** Fetch the exact fused prompt this preset would deploy. */\n loadPreview: (presetId: string) => Promise<void>\n}\n\nconst RPC_CHANNEL = '/api'\nconst RPC_NAMESPACE = 'dsh-unrestricted'\nconst SETTINGS_NS = 'unrestricted'\n\n/** Human-readable error text for the banner. */\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n/**\n * Create the card controller bound to the calling plugin's context.\n * @param ctx - the browser plugin context (connection + remote + configForms injected).\n * @returns the controller whose face() feeds the slot inject share.\n */\nexport function createUnrestrictedController(ctx: Context) {\n const connection = ctx.get('connection') as ConnectionHandle\n const settings = ctx.configForms.get<UnrestrictedSettings>(SETTINGS_NS)\n\n let snapshot: UnrestrictedViewSnapshot = {\n enabled: false,\n stripHostIdentity: false,\n writable: false,\n settingsStatus: 'loadinLine truncated
{"version":3,"file":"client.js","names":["useState","useRef","writeClipboard","Tag","Switch","Button","fileSizeText","StateDot"],"sources":["../src/client/controller.ts","../src/client/locales.ts","../src/client/styles.ts","../src/client/UnrestrictedCard.tsx","../src/client/index.tsx"],"sourcesContent":["/**\n * Browser-half controller for the unrestricted card: binds the `unrestricted`\n * settings namespace (the toggle) and reads per-preset state and previews.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: the ctx.remote Context merge and the forwarded-event key face.\nimport type {} from '@deepseek-ai/dsh-api-remotes/client'\n// Type-only: the ctx.configForms Context merge.\nimport type {} from '@deepseek-ai/dsh-client-ui-settings/client'\n\n/** The toggle section stored in the `unrestricted` settings namespace. */\nexport interface UnrestrictedSettings {\n enabled?: boolean\n stripHostIdentity?: boolean\n customPrompt?: string\n}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n stripHostIdentity?: boolean\n /** Persisted custom execution-mode prompt override, empty when using built-in default. */\n customPrompt?: string\n /** Built-in default execution-mode prompt text owned by the host half. */\n defaultPrompt?: string\n /** Whether a non-default custom execution-mode prompt is currently active. */\n isCustomPrompt?: boolean\n /** Current plugin version reported by the host half. */\n version?: string\n modes: Record<string, UnrestrictedModeState>\n}\n\n/** Deploy preview for one preset: what switching on would actually assemble. */\nexport interface UnrestrictedPreview {\n presetId: string\n available: boolean\n /** `live` = bytes a live agent received; `standing` = preset scope, no agent bound. */\n source?: 'live' | 'standing'\n /** Fused prompt text; present when available. */\n text?: string\n bytes?: number\n lines?: number\n /** Structured error code when unavailable. */\n errorCode?: string\n /** Diagnostic reason when unavailable. */\n reason?: string\n}\n\n/** One fetched preview, keyed by preset, plus its in-flight/error state. */\nexport interface UnrestrictedPreviewEntry {\n status: 'loading' | 'ready' | 'failed'\n preview?: UnrestrictedPreview\n errorCode?: string\n message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; false until the settings scope first syncs. */\n enabled: boolean\n /** Persisted host-brand stripping toggle; false until synced. */\n stripHostIdentity: boolean\n /** Persisted custom prompt override (LF-normalized); empty when using built-in default. */\n customPrompt: string\n /** Built-in default execution-mode prompt text returned by the host status RPC. */\n defaultPrompt: string\n /** Whether a custom execution-mode prompt is currently overriding the default. */\n isCustomPrompt: boolean\n /** Whether the Host document accepts writes. */\n writable: boolean\n /** Settings scope sync state. */\n settingsStatus: 'loading' | 'ready' | 'unavailable'\n /** Live host status; null until the first RPC answer. */\n status: UnrestrictedStatus | null\n /** presetId -> fetched deploy preview. */\n previews: Record<string, UnrestrictedPreviewEntry>\n /** Whether a settings write or status refresh is in flight. */\n busy: boolean\n /** Last transport/business failure, if any. */\n message?: string\n}\n\n/** Minimal RPC wire shape (structural copy of the host RpcResult). */\ntype RpcResult<T> = { ok: true; value: T } | { ok: false; error: { code: string; message: string } }\n\n/** Minimal observable contract consumed by the slot renderer's hook binding. */\nexport interface UnrestrictedViewSource {\n getSnapshot(): UnrestrictedViewSnapshot\n subscribe(listener: () => void): () => void\n}\n\n/** Inject face handed to the card at registration. */\nexport interface UnrestrictedCardInjected {\n hooks: {\n /** Reactive card view. */\n view: UnrestrictedViewSource\n }\n /** Persist the toggle. */\n setEnabled: (enabled: boolean) => Promise<void>\n /** Persist whether host identity branding is stripped from prompts. */\n setStripHostIdentity: (strip: boolean) => Promise<void>\n /** Persist a user-edited execution-mode prompt (clears override when equal to default). */\n setCustomPrompt: (prompt: string) => Promise<boolean>\n /** Clear any custom prompt override and restore the built-in default. */\n resetCustomPrompt: () => Promise<boolean>\n /** Re-validate runtime state and refresh. */\n recheck: () => Promise<void>\n /** Re-read host status and invalidate cached previews. */\n refresh: () => Promise<void>\n Line truncated