dsh-context-compression-improved 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/.githooks/pre-push +37 -37
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +169 -169
- package/CHANGELOG.ko.md +167 -167
- package/CHANGELOG.md +323 -304
- package/CHANGELOG.zh.md +152 -152
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +21 -21
- package/README.ja.md +85 -85
- package/README.ko.md +85 -85
- package/README.md +94 -94
- package/README.zh.md +85 -85
- package/SECURITY.md +18 -18
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -77
- package/docs/installation.ja.md +78 -78
- package/docs/installation.ko.md +78 -78
- package/docs/installation.md +103 -103
- package/docs/installation.zh.md +100 -100
- package/docs/repair-log.md +657 -657
- package/eslint.config.js +30 -30
- package/package.json +163 -164
- package/packages/selector/LICENSE +21 -21
- package/packages/selector/README.md +26 -26
- package/packages/selector/README.zh.md +24 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
- package/packages/selector/cordis.patch.yml +27 -27
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +59 -0
- package/packages/selector/lib/client.js +1738 -10
- package/packages/selector/lib/{advisor-state.js → config.js} +816 -65
- package/packages/selector/lib/index.d.ts +13 -1
- package/packages/selector/lib/index.js +295 -3
- package/packages/selector/lib/pruner.d.ts +65 -0
- package/packages/selector/lib/pruner.js +497 -262
- package/packages/selector/lib/style.css +88 -46
- package/packages/selector/package.json +114 -114
- package/packages/selector/screenshots.json +3 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -226
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -83
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
- package/packages/selector/src/client/EstimatorControls.tsx +277 -277
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +240 -149
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -196
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -88
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -124
- package/packages/selector/src/css-modules.d.ts +6 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
- package/packages/selector/src/estimator-catalog.ts +104 -104
- package/packages/selector/src/index.ts +673 -463
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +626 -626
- package/packages/selector/src/profiles.ts +431 -394
- package/packages/selector/src/pruner/content.ts +201 -201
- package/packages/selector/src/pruner/session.ts +94 -94
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner/tuning.ts +23 -23
- package/packages/selector/src/pruner/types.ts +78 -78
- package/packages/selector/src/pruner.ts +2736 -2402
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +756 -706
- package/packages/selector/src/runtime/custom-policy.ts +278 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
- package/packages/selector/src/runtime/measurement.ts +436 -436
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/session-events.ts +30 -30
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/token-count.ts +72 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
- package/packages/selector/src/runtime/toolclass.ts +103 -103
- package/packages/selector/src/runtime/types.ts +365 -346
- package/packages/selector/src/runtime/value.ts +48 -48
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -59
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -90
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -204
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -252
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -206
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -201
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -232
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
- package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2724
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
- package/packages/selector/tests/runtime/value.spec.ts +23 -23
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -118
- package/packages/selector/tests/standing-generation.host.spec.ts +697 -697
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -253
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
- package/packages/selector/tests/support/mock-adapter.ts +37 -37
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/packages/selector/tsconfig.json +11 -11
- package/packages/selector/tsdown.client.config.ts +102 -102
- package/packages/selector/tsdown.config.ts +20 -20
- package/pnpm-workspace.yaml +66 -66
- package/scripts/capture-profile-baseline.mjs +42 -42
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/packed-components-smoke.mjs +732 -732
- package/scripts/packed-install-e2e.mjs +1273 -1273
- package/scripts/toolclass-corpus-replay.mjs +281 -281
- package/scripts/verify-release.mjs +318 -317
- package/tests/TEST_INVENTORY.md +41 -41
- package/tsconfig.base.json +18 -18
- package/tsconfig.json +7 -7
- package/tsconfig.tests.json +15 -15
- package/vitest.built.config.ts +9 -9
- package/vitest.config.ts +43 -43
|
@@ -1,226 +1,293 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CompressionProfileControls: dropdown selector for compression profiles,
|
|
3
|
-
* plus AutoCompactThresholdControls and CodeSkeletonControls sub-components.
|
|
4
|
-
*
|
|
5
|
-
* Extracted from CompressionProfileSelector.tsx to reduce god-module size.
|
|
6
|
-
*
|
|
7
|
-
* @module dsh-context-compression-improved/client/CompressionProfileControls
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { useEffect, useId, useState } from 'react'
|
|
11
|
-
import { IconChevronDownOutline14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
12
|
-
import type { ContextCompressionLocaleKey } from './locales.ts'
|
|
13
|
-
import css from './CompressionProfileSelector.module.css'
|
|
14
|
-
import {
|
|
15
|
-
AUTO_COMPACT_THRESHOLD_LIMITS,
|
|
16
|
-
COMPRESSION_PROFILES,
|
|
17
|
-
isValidAutoCompactThresholdPercent,
|
|
18
|
-
type CompressionProfile,
|
|
19
|
-
type CustomCompressionPolicyV3,
|
|
20
|
-
} from '../profiles.ts'
|
|
21
|
-
import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
|
|
22
|
-
import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
|
|
23
|
-
|
|
24
|
-
export function CompressionProfileControls({
|
|
25
|
-
useCompression, select, saveCustom, resetCustom, t, showCustomEditor,
|
|
26
|
-
}: CompressionProfileSelectorProps & { showCustomEditor: boolean }) {
|
|
27
|
-
const state = useCompression(snapshot => snapshot)
|
|
28
|
-
// Harness 0.1.5 dropped browser-side agentPreset from session summaries; see
|
|
29
|
-
// the section component note. Only Minimal used to block initial
|
|
30
|
-
// configuration, and that signal is no longer available client-side.
|
|
31
|
-
const contextCompressionAvailable = true
|
|
32
|
-
const [open, setOpen] = useState(false)
|
|
33
|
-
const [saving, setSaving] = useState(false)
|
|
34
|
-
const [saveError, setSaveError] = useState<string | null>(null)
|
|
35
|
-
const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
|
|
36
|
-
const unavailableId = useId()
|
|
37
|
-
const current = state.value?.profile ?? 'balanced'
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (state.status === 'ready' && state.writable && contextCompressionAvailable) return
|
|
40
|
-
setOpen(false)
|
|
41
|
-
}, [contextCompressionAvailable, state.status, state.writable])
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const custom = state.value?.custom
|
|
44
|
-
setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
|
|
45
|
-
}, [current, state.value?.custom])
|
|
46
|
-
if (state.status === 'unavailable') return null
|
|
47
|
-
const busy = state.status === 'loading' || saving
|
|
48
|
-
const label = busy ? t('status.loading') : t(`profile.${current}`)
|
|
49
|
-
return (
|
|
50
|
-
<div className={css.root}>
|
|
51
|
-
<Menu
|
|
52
|
-
open={open && contextCompressionAvailable}
|
|
53
|
-
onClose={() => { setOpen(false) }}
|
|
54
|
-
selectedId={current}
|
|
55
|
-
items={COMPRESSION_PROFILES.map(profile => ({
|
|
56
|
-
id: profile,
|
|
57
|
-
label: (
|
|
58
|
-
<span className={css.menuCopy}>
|
|
59
|
-
<span className={css.menuTitle}>{t(`profile.${profile}`)}</span>
|
|
60
|
-
<span className={css.menuDetail}>{t(`detail.${profile}`)}</span>
|
|
61
|
-
</span>
|
|
62
|
-
),
|
|
63
|
-
}))}
|
|
64
|
-
onSelect={(id) => {
|
|
65
|
-
setOpen(false)
|
|
66
|
-
if (id === current || !COMPRESSION_PROFILES.includes(id as CompressionProfile)) return
|
|
67
|
-
setSaveError(null)
|
|
68
|
-
setSaving(true)
|
|
69
|
-
void select(id as CompressionProfile).then(
|
|
70
|
-
() => { setSaving(false) },
|
|
71
|
-
(error: unknown) => {
|
|
72
|
-
setSaving(false)
|
|
73
|
-
setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
|
|
74
|
-
},
|
|
75
|
-
)
|
|
76
|
-
}}
|
|
77
|
-
align="start"
|
|
78
|
-
portal
|
|
79
|
-
anchor={(
|
|
80
|
-
<button
|
|
81
|
-
type="button"
|
|
82
|
-
className={css.button}
|
|
83
|
-
aria-haspopup="menu"
|
|
84
|
-
aria-expanded={open && contextCompressionAvailable}
|
|
85
|
-
aria-describedby={contextCompressionAvailable ? undefined : unavailableId}
|
|
86
|
-
disabled={busy || !state.writable || !contextCompressionAvailable}
|
|
87
|
-
onClick={() => { setOpen(value => !value) }}
|
|
88
|
-
>
|
|
89
|
-
<span className={css.copy}>
|
|
90
|
-
<span className={css.label}>{t('label')}</span>
|
|
91
|
-
<span className={css.value}>{label}</span>
|
|
92
|
-
</span>
|
|
93
|
-
<IconChevronDownOutline14 className={css.chevron} />
|
|
94
|
-
</button>
|
|
95
|
-
)}
|
|
96
|
-
/>
|
|
97
|
-
{contextCompressionAvailable ? null : (
|
|
98
|
-
<div id={unavailableId} className={css.unavailable} role="status">
|
|
99
|
-
{t('status.minimalUnavailable')}
|
|
100
|
-
</div>
|
|
101
|
-
)}
|
|
102
|
-
<div className={css.pricing}>{t('pricing.disclosure')}</div>
|
|
103
|
-
<div className={css.settingsHint}>
|
|
104
|
-
{t('autoCompact.summaryHint').replace('{percent}', String(state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default))}
|
|
105
|
-
</div>
|
|
106
|
-
{current !== 'custom' || showCustomEditor ? null : (
|
|
107
|
-
<div className={css.settingsHint}>{t('custom.settingsHint')}</div>
|
|
108
|
-
)}
|
|
109
|
-
{current !== 'custom' || draft === null || !showCustomEditor ? null : (
|
|
110
|
-
<CustomPolicyEditor
|
|
111
|
-
value={draft}
|
|
112
|
-
disabled={busy || !state.writable || !contextCompressionAvailable}
|
|
113
|
-
setValue={setDraft}
|
|
114
|
-
save={() => saveCustom(structuredClone(draft))}
|
|
115
|
-
reset={resetCustom}
|
|
116
|
-
settle={(operation) => {
|
|
117
|
-
setSaveError(null)
|
|
118
|
-
setSaving(true)
|
|
119
|
-
void operation().then(
|
|
120
|
-
() => { setSaving(false) },
|
|
121
|
-
(error: unknown) => {
|
|
122
|
-
setSaving(false)
|
|
123
|
-
setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
|
|
124
|
-
},
|
|
125
|
-
)
|
|
126
|
-
}}
|
|
127
|
-
t={t}
|
|
128
|
-
/>
|
|
129
|
-
)}
|
|
130
|
-
{saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
|
|
131
|
-
</div>
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
interface AutoCompactThresholdControlsProps {
|
|
136
|
-
value: number
|
|
137
|
-
disabled: boolean
|
|
138
|
-
save: (thresholdPercent: number) => Promise<void>
|
|
139
|
-
settle: (operation: () => Promise<void>) => void
|
|
140
|
-
t: (key: ContextCompressionLocaleKey) => string
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The authoritative Auto Compact threshold editor for the context-compression
|
|
145
|
-
* section. A typed number input and its save path are kept deliberately simple;
|
|
146
|
-
* values outside the recommended 70–85 band warn without blocking.
|
|
147
|
-
*/
|
|
148
|
-
export function AutoCompactThresholdControls({ value, disabled, save, settle, t }: AutoCompactThresholdControlsProps) {
|
|
149
|
-
const [draft, setDraft] = useState(String(value))
|
|
150
|
-
useEffect(() => { setDraft(String(value)) }, [value])
|
|
151
|
-
const parsed = Number(draft)
|
|
152
|
-
// Number inputs legally produce value-equivalent drafts such as '8e1';
|
|
153
|
-
// only the parsed value needs to be a valid threshold.
|
|
154
|
-
const valid = isValidAutoCompactThresholdPercent(parsed)
|
|
155
|
-
const risk = !valid
|
|
156
|
-
? 'autoCompact.invalid'
|
|
157
|
-
: parsed < 70 ? 'autoCompact.riskLow'
|
|
158
|
-
: parsed > 85 ? 'autoCompact.riskHigh'
|
|
159
|
-
: undefined
|
|
160
|
-
return (
|
|
161
|
-
<section className={css.autoCompact} aria-labelledby="context-compression-autocompact-title">
|
|
162
|
-
<h3 id="context-compression-autocompact-title" className={css.autoCompactTitle}>{t('autoCompact.title')}</h3>
|
|
163
|
-
<p className={css.customNote}>{t('autoCompact.description')}</p>
|
|
164
|
-
<label className={css.field}>
|
|
165
|
-
<span>{t('autoCompact.inputLabel')}</span>
|
|
166
|
-
<input
|
|
167
|
-
type="number"
|
|
168
|
-
value={draft}
|
|
169
|
-
min={AUTO_COMPACT_THRESHOLD_LIMITS.min}
|
|
170
|
-
max={AUTO_COMPACT_THRESHOLD_LIMITS.max}
|
|
171
|
-
step={AUTO_COMPACT_THRESHOLD_LIMITS.step}
|
|
172
|
-
disabled={disabled}
|
|
173
|
-
aria-invalid={!valid}
|
|
174
|
-
onChange={(event) => { setDraft(event.currentTarget.value) }}
|
|
175
|
-
/>
|
|
176
|
-
</label>
|
|
177
|
-
{risk === undefined ? null : (
|
|
178
|
-
<div className={risk === 'autoCompact.invalid' ? css.error : css.autoCompactRisk} role={risk === 'autoCompact.invalid' ? 'alert' : 'note'}>
|
|
179
|
-
{t(risk)}
|
|
180
|
-
</div>
|
|
181
|
-
)}
|
|
182
|
-
<div className={css.actions}>
|
|
183
|
-
<button
|
|
184
|
-
type="button"
|
|
185
|
-
disabled={disabled || !valid || parsed === value}
|
|
186
|
-
onClick={() => { settle(() => save(parsed)) }}
|
|
187
|
-
>
|
|
188
|
-
{t('autoCompact.save')}
|
|
189
|
-
</button>
|
|
190
|
-
</div>
|
|
191
|
-
</section>
|
|
192
|
-
)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
interface CodeSkeletonControlsProps {
|
|
196
|
-
value: boolean
|
|
197
|
-
disabled: boolean
|
|
198
|
-
save: (enabled: boolean) => Promise<void>
|
|
199
|
-
settle: (operation: () => Promise<void>) => void
|
|
200
|
-
t: (key: ContextCompressionLocaleKey) => string
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* The authoritative code-skeleton reducer gate for the context-compression
|
|
205
|
-
* section. Deliberately minimal — an on/off select plus its own save path —
|
|
206
|
-
* because the gate is orthogonal to every profile and carries no parameters.
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* CompressionProfileControls: dropdown selector for compression profiles,
|
|
3
|
+
* plus AutoCompactThresholdControls and CodeSkeletonControls sub-components.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from CompressionProfileSelector.tsx to reduce god-module size.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-context-compression-improved/client/CompressionProfileControls
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useEffect, useId, useState } from 'react'
|
|
11
|
+
import { IconChevronDownOutline14, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
12
|
+
import type { ContextCompressionLocaleKey } from './locales.ts'
|
|
13
|
+
import css from './CompressionProfileSelector.module.css'
|
|
14
|
+
import {
|
|
15
|
+
AUTO_COMPACT_THRESHOLD_LIMITS,
|
|
16
|
+
COMPRESSION_PROFILES,
|
|
17
|
+
isValidAutoCompactThresholdPercent,
|
|
18
|
+
type CompressionProfile,
|
|
19
|
+
type CustomCompressionPolicyV3,
|
|
20
|
+
} from '../profiles.ts'
|
|
21
|
+
import type { CompressionProfileSelectorProps } from './CompressionProfileSelector.tsx'
|
|
22
|
+
import { CustomPolicyEditor, editableCustom } from './CustomPolicyEditor.tsx'
|
|
23
|
+
|
|
24
|
+
export function CompressionProfileControls({
|
|
25
|
+
useCompression, select, saveCustom, resetCustom, t, showCustomEditor,
|
|
26
|
+
}: CompressionProfileSelectorProps & { showCustomEditor: boolean }) {
|
|
27
|
+
const state = useCompression(snapshot => snapshot)
|
|
28
|
+
// Harness 0.1.5 dropped browser-side agentPreset from session summaries; see
|
|
29
|
+
// the section component note. Only Minimal used to block initial
|
|
30
|
+
// configuration, and that signal is no longer available client-side.
|
|
31
|
+
const contextCompressionAvailable = true
|
|
32
|
+
const [open, setOpen] = useState(false)
|
|
33
|
+
const [saving, setSaving] = useState(false)
|
|
34
|
+
const [saveError, setSaveError] = useState<string | null>(null)
|
|
35
|
+
const [draft, setDraft] = useState<CustomCompressionPolicyV3 | null>(null)
|
|
36
|
+
const unavailableId = useId()
|
|
37
|
+
const current = state.value?.profile ?? 'balanced'
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (state.status === 'ready' && state.writable && contextCompressionAvailable) return
|
|
40
|
+
setOpen(false)
|
|
41
|
+
}, [contextCompressionAvailable, state.status, state.writable])
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const custom = state.value?.custom
|
|
44
|
+
setDraft(current === 'custom' && custom !== undefined ? editableCustom(custom) : null)
|
|
45
|
+
}, [current, state.value?.custom])
|
|
46
|
+
if (state.status === 'unavailable') return null
|
|
47
|
+
const busy = state.status === 'loading' || saving
|
|
48
|
+
const label = busy ? t('status.loading') : t(`profile.${current}`)
|
|
49
|
+
return (
|
|
50
|
+
<div className={css.root}>
|
|
51
|
+
<Menu
|
|
52
|
+
open={open && contextCompressionAvailable}
|
|
53
|
+
onClose={() => { setOpen(false) }}
|
|
54
|
+
selectedId={current}
|
|
55
|
+
items={COMPRESSION_PROFILES.map(profile => ({
|
|
56
|
+
id: profile,
|
|
57
|
+
label: (
|
|
58
|
+
<span className={css.menuCopy}>
|
|
59
|
+
<span className={css.menuTitle}>{t(`profile.${profile}`)}</span>
|
|
60
|
+
<span className={css.menuDetail}>{t(`detail.${profile}`)}</span>
|
|
61
|
+
</span>
|
|
62
|
+
),
|
|
63
|
+
}))}
|
|
64
|
+
onSelect={(id) => {
|
|
65
|
+
setOpen(false)
|
|
66
|
+
if (id === current || !COMPRESSION_PROFILES.includes(id as CompressionProfile)) return
|
|
67
|
+
setSaveError(null)
|
|
68
|
+
setSaving(true)
|
|
69
|
+
void select(id as CompressionProfile).then(
|
|
70
|
+
() => { setSaving(false) },
|
|
71
|
+
(error: unknown) => {
|
|
72
|
+
setSaving(false)
|
|
73
|
+
setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
}}
|
|
77
|
+
align="start"
|
|
78
|
+
portal
|
|
79
|
+
anchor={(
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
className={css.button}
|
|
83
|
+
aria-haspopup="menu"
|
|
84
|
+
aria-expanded={open && contextCompressionAvailable}
|
|
85
|
+
aria-describedby={contextCompressionAvailable ? undefined : unavailableId}
|
|
86
|
+
disabled={busy || !state.writable || !contextCompressionAvailable}
|
|
87
|
+
onClick={() => { setOpen(value => !value) }}
|
|
88
|
+
>
|
|
89
|
+
<span className={css.copy}>
|
|
90
|
+
<span className={css.label}>{t('label')}</span>
|
|
91
|
+
<span className={css.value}>{label}</span>
|
|
92
|
+
</span>
|
|
93
|
+
<IconChevronDownOutline14 className={css.chevron} />
|
|
94
|
+
</button>
|
|
95
|
+
)}
|
|
96
|
+
/>
|
|
97
|
+
{contextCompressionAvailable ? null : (
|
|
98
|
+
<div id={unavailableId} className={css.unavailable} role="status">
|
|
99
|
+
{t('status.minimalUnavailable')}
|
|
100
|
+
</div>
|
|
101
|
+
)}
|
|
102
|
+
<div className={css.pricing}>{t('pricing.disclosure')}</div>
|
|
103
|
+
<div className={css.settingsHint}>
|
|
104
|
+
{t('autoCompact.summaryHint').replace('{percent}', String(state.value?.autoCompact?.thresholdPercent ?? AUTO_COMPACT_THRESHOLD_LIMITS.default))}
|
|
105
|
+
</div>
|
|
106
|
+
{current !== 'custom' || showCustomEditor ? null : (
|
|
107
|
+
<div className={css.settingsHint}>{t('custom.settingsHint')}</div>
|
|
108
|
+
)}
|
|
109
|
+
{current !== 'custom' || draft === null || !showCustomEditor ? null : (
|
|
110
|
+
<CustomPolicyEditor
|
|
111
|
+
value={draft}
|
|
112
|
+
disabled={busy || !state.writable || !contextCompressionAvailable}
|
|
113
|
+
setValue={setDraft}
|
|
114
|
+
save={() => saveCustom(structuredClone(draft))}
|
|
115
|
+
reset={resetCustom}
|
|
116
|
+
settle={(operation) => {
|
|
117
|
+
setSaveError(null)
|
|
118
|
+
setSaving(true)
|
|
119
|
+
void operation().then(
|
|
120
|
+
() => { setSaving(false) },
|
|
121
|
+
(error: unknown) => {
|
|
122
|
+
setSaving(false)
|
|
123
|
+
setSaveError(error instanceof Error && error.message !== '' ? error.message : t('status.saveFailed'))
|
|
124
|
+
},
|
|
125
|
+
)
|
|
126
|
+
}}
|
|
127
|
+
t={t}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
{saveError === null ? null : <div className={css.error} role="alert">{saveError}</div>}
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface AutoCompactThresholdControlsProps {
|
|
136
|
+
value: number
|
|
137
|
+
disabled: boolean
|
|
138
|
+
save: (thresholdPercent: number) => Promise<void>
|
|
139
|
+
settle: (operation: () => Promise<void>) => void
|
|
140
|
+
t: (key: ContextCompressionLocaleKey) => string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The authoritative Auto Compact threshold editor for the context-compression
|
|
145
|
+
* section. A typed number input and its save path are kept deliberately simple;
|
|
146
|
+
* values outside the recommended 70–85 band warn without blocking.
|
|
147
|
+
*/
|
|
148
|
+
export function AutoCompactThresholdControls({ value, disabled, save, settle, t }: AutoCompactThresholdControlsProps) {
|
|
149
|
+
const [draft, setDraft] = useState(String(value))
|
|
150
|
+
useEffect(() => { setDraft(String(value)) }, [value])
|
|
151
|
+
const parsed = Number(draft)
|
|
152
|
+
// Number inputs legally produce value-equivalent drafts such as '8e1';
|
|
153
|
+
// only the parsed value needs to be a valid threshold.
|
|
154
|
+
const valid = isValidAutoCompactThresholdPercent(parsed)
|
|
155
|
+
const risk = !valid
|
|
156
|
+
? 'autoCompact.invalid'
|
|
157
|
+
: parsed < 70 ? 'autoCompact.riskLow'
|
|
158
|
+
: parsed > 85 ? 'autoCompact.riskHigh'
|
|
159
|
+
: undefined
|
|
160
|
+
return (
|
|
161
|
+
<section className={css.autoCompact} aria-labelledby="context-compression-autocompact-title">
|
|
162
|
+
<h3 id="context-compression-autocompact-title" className={css.autoCompactTitle}>{t('autoCompact.title')}</h3>
|
|
163
|
+
<p className={css.customNote}>{t('autoCompact.description')}</p>
|
|
164
|
+
<label className={css.field}>
|
|
165
|
+
<span>{t('autoCompact.inputLabel')}</span>
|
|
166
|
+
<input
|
|
167
|
+
type="number"
|
|
168
|
+
value={draft}
|
|
169
|
+
min={AUTO_COMPACT_THRESHOLD_LIMITS.min}
|
|
170
|
+
max={AUTO_COMPACT_THRESHOLD_LIMITS.max}
|
|
171
|
+
step={AUTO_COMPACT_THRESHOLD_LIMITS.step}
|
|
172
|
+
disabled={disabled}
|
|
173
|
+
aria-invalid={!valid}
|
|
174
|
+
onChange={(event) => { setDraft(event.currentTarget.value) }}
|
|
175
|
+
/>
|
|
176
|
+
</label>
|
|
177
|
+
{risk === undefined ? null : (
|
|
178
|
+
<div className={risk === 'autoCompact.invalid' ? css.error : css.autoCompactRisk} role={risk === 'autoCompact.invalid' ? 'alert' : 'note'}>
|
|
179
|
+
{t(risk)}
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
<div className={css.actions}>
|
|
183
|
+
<button
|
|
184
|
+
type="button"
|
|
185
|
+
disabled={disabled || !valid || parsed === value}
|
|
186
|
+
onClick={() => { settle(() => save(parsed)) }}
|
|
187
|
+
>
|
|
188
|
+
{t('autoCompact.save')}
|
|
189
|
+
</button>
|
|
190
|
+
</div>
|
|
191
|
+
</section>
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface CodeSkeletonControlsProps {
|
|
196
|
+
value: boolean
|
|
197
|
+
disabled: boolean
|
|
198
|
+
save: (enabled: boolean) => Promise<void>
|
|
199
|
+
settle: (operation: () => Promise<void>) => void
|
|
200
|
+
t: (key: ContextCompressionLocaleKey) => string
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The authoritative code-skeleton reducer gate for the context-compression
|
|
205
|
+
* section. Deliberately minimal — an on/off select plus its own save path —
|
|
206
|
+
* because the gate is orthogonal to every profile and carries no parameters.
|
|
207
|
+
*/
|
|
208
|
+
interface IntentSummaryControlsProps {
|
|
209
|
+
value: boolean
|
|
210
|
+
disabled: boolean
|
|
211
|
+
save: (enabled: boolean) => Promise<void>
|
|
212
|
+
settle: (operation: () => Promise<void>) => void
|
|
213
|
+
t: (key: ContextCompressionLocaleKey) => string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The turn-tail intent summary fold gate. Same deliberately minimal shape as
|
|
218
|
+
* the code-skeleton gate: an on/off select with its own save path; the fold
|
|
219
|
+
* itself is gated by the growth constants and the per-session /ctx-summary
|
|
220
|
+
* override, none of which belong in this card.
|
|
221
|
+
*/
|
|
222
|
+
export function IntentSummaryControls({ value, disabled, save, settle, t }: IntentSummaryControlsProps) {
|
|
223
|
+
return (
|
|
224
|
+
<section className={css.autoCompact} aria-labelledby="context-compression-intentsummary-title">
|
|
225
|
+
<h3 id="context-compression-intentsummary-title" className={css.autoCompactTitle}>{t('intentSummary.title')}</h3>
|
|
226
|
+
<p className={css.customNote}>{t('intentSummary.description')}</p>
|
|
227
|
+
<label className={css.field}>
|
|
228
|
+
<span>{t('intentSummary.enabled')}</span>
|
|
229
|
+
<select
|
|
230
|
+
value={value ? 'on' : 'off'}
|
|
231
|
+
disabled={disabled}
|
|
232
|
+
onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
|
|
233
|
+
>
|
|
234
|
+
<option value="on">{t('intentSummary.enabled.on')}</option>
|
|
235
|
+
<option value="off">{t('intentSummary.enabled.off')}</option>
|
|
236
|
+
</select>
|
|
237
|
+
</label>
|
|
238
|
+
</section>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface MonitorPanelControlsProps {
|
|
243
|
+
value: boolean
|
|
244
|
+
disabled: boolean
|
|
245
|
+
save: (enabled: boolean) => Promise<void>
|
|
246
|
+
settle: (operation: () => Promise<void>) => void
|
|
247
|
+
t: (key: ContextCompressionLocaleKey) => string
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Visibility switch of the floating compression-monitor panel (FAB). The
|
|
252
|
+
* panel itself is a body-level overlay driven by the monitor route; this card
|
|
253
|
+
* only decides whether it mounts.
|
|
254
|
+
*/
|
|
255
|
+
export function MonitorPanelControls({ value, disabled, save, settle, t }: MonitorPanelControlsProps) {
|
|
256
|
+
return (
|
|
257
|
+
<section className={css.autoCompact} aria-labelledby="context-compression-monitorpanel-title">
|
|
258
|
+
<h3 id="context-compression-monitorpanel-title" className={css.autoCompactTitle}>{t('monitorPanel.title')}</h3>
|
|
259
|
+
<p className={css.customNote}>{t('monitorPanel.description')}</p>
|
|
260
|
+
<label className={css.field}>
|
|
261
|
+
<span>{t('monitorPanel.enabled')}</span>
|
|
262
|
+
<select
|
|
263
|
+
value={value ? 'on' : 'off'}
|
|
264
|
+
disabled={disabled}
|
|
265
|
+
onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
|
|
266
|
+
>
|
|
267
|
+
<option value="on">{t('monitorPanel.enabled.on')}</option>
|
|
268
|
+
<option value="off">{t('monitorPanel.enabled.off')}</option>
|
|
269
|
+
</select>
|
|
270
|
+
</label>
|
|
271
|
+
</section>
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function CodeSkeletonControls({ value, disabled, save, settle, t }: CodeSkeletonControlsProps) {
|
|
276
|
+
return (
|
|
277
|
+
<section className={css.autoCompact} aria-labelledby="context-compression-codeskeleton-title">
|
|
278
|
+
<h3 id="context-compression-codeskeleton-title" className={css.autoCompactTitle}>{t('codeSkeleton.title')}</h3>
|
|
279
|
+
<p className={css.customNote}>{t('codeSkeleton.description')}</p>
|
|
280
|
+
<label className={css.field}>
|
|
281
|
+
<span>{t('codeSkeleton.enabled')}</span>
|
|
282
|
+
<select
|
|
283
|
+
value={value ? 'on' : 'off'}
|
|
284
|
+
disabled={disabled}
|
|
285
|
+
onChange={(event) => { settle(() => save(event.currentTarget.value === 'on')) }}
|
|
286
|
+
>
|
|
287
|
+
<option value="on">{t('codeSkeleton.enabled.on')}</option>
|
|
288
|
+
<option value="off">{t('codeSkeleton.enabled.off')}</option>
|
|
289
|
+
</select>
|
|
290
|
+
</label>
|
|
291
|
+
</section>
|
|
292
|
+
)
|
|
293
|
+
}
|