适配 DSH alpha.4 并发布 0.2.3 会话与预览同步修复

This commit is contained in:
yexi committed 2026-10-15 23:37:43 +08:00
1 parent 945b9624d6
commit e884f740e3
21 files changed
+441 -122

No files matched your search

+89 -14
View File
@@ -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();
},
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"client.js","names":["useState"],"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 polls the host half's private RPC for\n * per-preset fusion state. Mirrors the card-controller pattern: the apply\n * closure owns the controller, the slot inject face hands hooks and callbacks\n * to the component.\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}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'checking' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n /** Fingerprint of the contract bytes the host half deploys. */\n contract: 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 contract: 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 /** Why no preview could be built; present 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 message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; undefined until the settings scope first syncs. */\n enabled: 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 /** 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 /** Re-run the host-side anchor checks and refresh. */\n recheck: () => Promise<void>\n /** Re-read host status. */\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 = '/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 writable: false,\n settingsStatus: 'loading',\n status: null,\n previews: {},\n }\n const listeners = new Set<() => void>()\n\n const view: UnrestrictedViewSource = {\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n }\n\n function publish(): void {\n const settingsSnapshot = settings.getSnapshot()\n Line truncated
{"version":3,"file":"client.js","names":["useState"],"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 polls the host half's private RPC for\n * per-preset fusion state. Mirrors the card-controller pattern: the apply\n * closure owns the controller, the slot inject face hands hooks and callbacks\n * to the component.\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}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'checking' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n /** Fingerprint of the contract bytes the host half deploys. */\n contract: 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 contract: 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 /** Why no preview could be built; present 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 message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; undefined until the settings scope first syncs. */\n enabled: 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 status refresh or recheck RPC is currently 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 /** Re-run the host-side anchor checks 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 = '/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 writable: false,\n settingsStatus: 'loading',\n status: null,\n previews: {},\n busy: false,\n }\n const listeners = new Set<() => void>()\n\n const view: UnrestrictedViewSource = {\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener)\n Line truncated