mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
feat: 支持折叠破限设置
This commit is contained in:
1 parent
7bee8d7cd4
commit
da7d76f829
6 files changed
+371
-143
No files matched your search
@@ -42,53 +42,72 @@ export function UnrestrictedCard(props: UnrestrictedCardProps) {
|
||||
const { t } = props
|
||||
const view = props.useView(snapshot => snapshot)
|
||||
const status = view.status
|
||||
const hasIncompatibleMode = status !== null
|
||||
&& Object.values(status.modes).some(mode => mode.state === 'incompatible')
|
||||
const summaryKey: UnrestrictedLocaleKey = view.settingsStatus === 'loading'
|
||||
? 'summaryLoading'
|
||||
: view.settingsStatus === 'unavailable'
|
||||
? 'summaryUnavailable'
|
||||
: hasIncompatibleMode
|
||||
? 'summaryIncompatible'
|
||||
: view.enabled ? 'summaryEnabled' : 'summaryDisabled'
|
||||
const summaryState = view.settingsStatus === 'ready'
|
||||
? hasIncompatibleMode ? 'error' : view.enabled ? 'active' : 'off'
|
||||
: 'pending'
|
||||
return (
|
||||
<section className="dsh-unrestricted-card">
|
||||
<h3 className="dsh-unrestricted-title">{t('title')}</h3>
|
||||
<p className="dsh-unrestricted-description">{t('description')}</p>
|
||||
<label className="dsh-unrestricted-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={view.enabled}
|
||||
disabled={!view.writable || view.settingsStatus !== 'ready'}
|
||||
onChange={(event) => { void props.setEnabled(event.target.checked) }}
|
||||
/>
|
||||
<span>{t('toggle')}</span>
|
||||
</label>
|
||||
{view.settingsStatus === 'unavailable' && (
|
||||
<p className="dsh-unrestricted-note">{t('settingsUnavailable')}</p>
|
||||
)}
|
||||
{view.message !== undefined && (
|
||||
<p className="dsh-unrestricted-error">{t('operationFailed')}{view.message}</p>
|
||||
)}
|
||||
<h4 className="dsh-unrestricted-statusTitle">{t('statusTitle')}</h4>
|
||||
<ul className="dsh-unrestricted-modes">
|
||||
{MODE_ROWS.map((row) => {
|
||||
const mode = status?.modes[row.id]
|
||||
return (
|
||||
<li key={row.id} className="dsh-unrestricted-mode">
|
||||
<span className="dsh-unrestricted-dot" data-state={mode?.state ?? 'off'} />
|
||||
<span className="dsh-unrestricted-modeName">{t(row.labelKey)}</span>
|
||||
<span className="dsh-unrestricted-modeState">{t(stateKey(mode))}</span>
|
||||
{mode !== undefined && mode.issues.length > 0 && (
|
||||
<span className="dsh-unrestricted-issues">{mode.issues.join('; ')}</span>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
<p className="dsh-unrestricted-note">{t('subagentNote')}</p>
|
||||
{status !== null && (
|
||||
<p className="dsh-unrestricted-note">
|
||||
{t('supported')}
|
||||
{` DSH ${status.supported.version}(${status.supported.commit.slice(0, 7)})。`}
|
||||
</p>
|
||||
)}
|
||||
<p className="dsh-unrestricted-note">{t('scopeNote')}</p>
|
||||
<div className="dsh-unrestricted-actions">
|
||||
<button type="button" onClick={() => { void props.recheck() }}>{t('recheck')}</button>
|
||||
<button type="button" onClick={() => { void props.refresh() }}>{t('refresh')}</button>
|
||||
<details className="dsh-unrestricted-card">
|
||||
<summary className="dsh-unrestricted-summary">
|
||||
<span className="dsh-unrestricted-summaryText">
|
||||
<span className="dsh-unrestricted-title" role="heading" aria-level={3}>{t('title')}</span>
|
||||
<span className="dsh-unrestricted-summaryStatus" data-state={summaryState}>{t(summaryKey)}</span>
|
||||
</span>
|
||||
</summary>
|
||||
<div className="dsh-unrestricted-content">
|
||||
<p className="dsh-unrestricted-description">{t('description')}</p>
|
||||
<label className="dsh-unrestricted-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={view.enabled}
|
||||
disabled={!view.writable || view.settingsStatus !== 'ready'}
|
||||
onChange={(event) => { void props.setEnabled(event.target.checked) }}
|
||||
/>
|
||||
<span>{t('toggle')}</span>
|
||||
</label>
|
||||
{view.settingsStatus === 'unavailable' && (
|
||||
<p className="dsh-unrestricted-note">{t('settingsUnavailable')}</p>
|
||||
)}
|
||||
{view.message !== undefined && (
|
||||
<p className="dsh-unrestricted-error">{t('operationFailed')}{view.message}</p>
|
||||
)}
|
||||
<h4 className="dsh-unrestricted-statusTitle">{t('statusTitle')}</h4>
|
||||
<ul className="dsh-unrestricted-modes">
|
||||
{MODE_ROWS.map((row) => {
|
||||
const mode = status?.modes[row.id]
|
||||
return (
|
||||
<li key={row.id} className="dsh-unrestricted-mode">
|
||||
<span className="dsh-unrestricted-dot" data-state={mode?.state ?? 'off'} />
|
||||
<span className="dsh-unrestricted-modeName">{t(row.labelKey)}</span>
|
||||
<span className="dsh-unrestricted-modeState">{t(stateKey(mode))}</span>
|
||||
{mode !== undefined && mode.issues.length > 0 && (
|
||||
<span className="dsh-unrestricted-issues">{mode.issues.join('; ')}</span>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
<p className="dsh-unrestricted-note">{t('subagentNote')}</p>
|
||||
{status !== null && (
|
||||
<p className="dsh-unrestricted-note">
|
||||
{t('supported')}
|
||||
{` DSH ${status.supported.version}(${status.supported.commit.slice(0, 7)})。`}
|
||||
</p>
|
||||
)}
|
||||
<p className="dsh-unrestricted-note">{t('scopeNote')}</p>
|
||||
<div className="dsh-unrestricted-actions">
|
||||
<button type="button" onClick={() => { void props.recheck() }}>{t('recheck')}</button>
|
||||
<button type="button" onClick={() => { void props.refresh() }}>{t('refresh')}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</details>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,11 @@
|
||||
/** Simplified Chinese dictionary and key source of truth. */
|
||||
export const zh = {
|
||||
title: '破限模式',
|
||||
summaryEnabled: '已开启',
|
||||
summaryDisabled: '已关闭',
|
||||
summaryLoading: '读取中',
|
||||
summaryUnavailable: '设置不可用',
|
||||
summaryIncompatible: '部分模式不兼容',
|
||||
description: '开启后,各模式的系统提示词整体替换为以当前原版为底稿、融合破限规则的完整版本;关闭即恢复 DSH 原版提示词。从下一次请求和新建子代理开始生效,不改动正在执行的请求、工具定义、权限配置与会话历史。',
|
||||
toggle: '启用破限',
|
||||
scopeNote: '提示词仅由 DSH 生成时才受本插件控制;模型平台或宿主环境中更高优先级的规则不在覆盖范围内。',
|
||||
@@ -30,6 +35,11 @@ export type UnrestrictedLocaleKey = keyof typeof zh
|
||||
/** English dictionary checked against the Chinese key set. */
|
||||
export const en = {
|
||||
title: 'Unrestricted mode',
|
||||
summaryEnabled: 'Enabled',
|
||||
summaryDisabled: 'Disabled',
|
||||
summaryLoading: 'Loading',
|
||||
summaryUnavailable: 'Settings unavailable',
|
||||
summaryIncompatible: 'Some modes incompatible',
|
||||
description: 'When enabled, each mode\'s system prompt is replaced wholesale by a fused prompt built on its current original; disabling restores the stock DSH prompt. Applies from the next request and new subagents; in-flight requests, tool definitions, permissions, and session history are never touched.',
|
||||
toggle: 'Enable unrestricted mode',
|
||||
scopeNote: 'This plugin can only rewrite prompts DSH generates itself; higher-priority rules from the model platform or host environment are out of scope.',
|
||||
|
||||
+90
-4
@@ -6,19 +6,96 @@
|
||||
|
||||
const CSS = `
|
||||
.dsh-unrestricted-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 760px;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 10px;
|
||||
padding: 14px;
|
||||
overflow: hidden;
|
||||
background: var(--dsw-alias-bg-layer-3);
|
||||
color: var(--dsw-alias-label-primary);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summary {
|
||||
display: flex;
|
||||
min-height: 48px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
box-sizing: border-box;
|
||||
padding: 12px 14px;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
touch-action: manipulation;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summary::-webkit-details-marker { display: none; }
|
||||
|
||||
.dsh-unrestricted-summary:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
||||
|
||||
.dsh-unrestricted-summary:focus-visible {
|
||||
outline: 2px solid var(--dsw-alias-state-business-primary);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summary::after {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
flex: none;
|
||||
border-right: 2px solid var(--dsw-alias-label-tertiary);
|
||||
border-bottom: 2px solid var(--dsw-alias-label-tertiary);
|
||||
content: '';
|
||||
transform: rotate(45deg);
|
||||
transition: transform 160ms ease;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-card[open] > .dsh-unrestricted-summary {
|
||||
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-card[open] > .dsh-unrestricted-summary::after {
|
||||
transform: rotate(225deg);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summaryText {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summaryStatus {
|
||||
border: 1px solid var(--dsw-alias-border-l2);
|
||||
border-radius: 999px;
|
||||
padding: 1px 7px;
|
||||
background: var(--dsw-alias-bg-layer-2);
|
||||
color: var(--dsw-alias-label-tertiary);
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summaryStatus[data-state='active'] {
|
||||
color: var(--dsw-alias-state-success-primary);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summaryStatus[data-state='pending'] {
|
||||
color: var(--dsw-alias-state-business-primary);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-summaryStatus[data-state='error'] {
|
||||
color: var(--dsw-alias-state-error-primary);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.dsh-unrestricted-title {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
@@ -147,6 +224,15 @@ const CSS = `
|
||||
.dsh-unrestricted-actions button:hover:not(:disabled) {
|
||||
background: var(--dsw-alias-interactive-bg-hover);
|
||||
}
|
||||
|
||||
.dsh-unrestricted-actions button:focus-visible {
|
||||
outline: 2px solid var(--dsw-alias-state-business-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.dsh-unrestricted-summary::after { transition: none; }
|
||||
}
|
||||
`
|
||||
|
||||
/** Inject the stylesheet once; the tag id doubles as the re-evaluation guard. */
|
||||
|
||||
Reference in new issue
Block a user