dsh-context-compression-improved 0.7.0-beta.2 → 0.7.0
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/CHANGELOG.md +9 -0
- package/package.json +17 -18
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.d.ts +44 -0
- package/packages/selector/lib/client.js +1007 -13
- package/packages/selector/lib/{intent-gate.js → config.js} +799 -136
- package/packages/selector/lib/index.d.ts +13 -1
- package/packages/selector/lib/index.js +204 -3
- package/packages/selector/lib/profiles.d.ts +6 -0
- package/packages/selector/lib/pruner.d.ts +6 -0
- package/packages/selector/lib/pruner.js +90 -258
- package/packages/selector/lib/style.css +42 -0
- 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/decode.ts +5 -1
- package/packages/selector/src/client/index.ts +307 -243
- package/packages/selector/src/client/locales/de.ts +43 -0
- package/packages/selector/src/client/locales/es.ts +43 -0
- package/packages/selector/src/client/locales/fr.ts +43 -0
- package/packages/selector/src/client/locales/it.ts +43 -0
- package/packages/selector/src/client/locales/ja.ts +43 -0
- package/packages/selector/src/client/locales/ko.ts +43 -0
- package/packages/selector/src/client/locales/ru.ts +43 -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/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -124
- package/packages/selector/src/index.ts +207 -5
- package/packages/selector/src/profiles.ts +17 -0
- package/packages/selector/src/pruner.ts +96 -2
- package/packages/selector/src/runtime/config.ts +26 -1
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/types.ts +7 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +2 -2
- package/packages/selector/tests/custom-contract.client.spec.ts +2 -2
- package/packages/selector/tests/estimator-channel.client.spec.tsx +2 -0
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -188
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +301 -0
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +177 -165
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +1 -1
|
@@ -1,243 +1,307 @@
|
|
|
1
|
-
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
2
|
-
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
-
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
4
|
-
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
5
|
-
import type {} from '@deepseek-ai/dsh-client-ui-workspace/client'
|
|
6
|
-
import {
|
|
7
|
-
isCustomCompressionPolicy,
|
|
8
|
-
ContextCompressionSettingsSection,
|
|
9
|
-
type CompressionSelectorInjected, type ContextCompressionSettings,
|
|
10
|
-
} from './CompressionProfileSelector.tsx'
|
|
11
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
|
|
12
|
-
import { decodeSettings } from './decode.ts'
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
&& left.
|
|
62
|
-
&& left.
|
|
63
|
-
&& left.fresh.
|
|
64
|
-
&& left.fresh.
|
|
65
|
-
&& left.
|
|
66
|
-
&& left.aggregate.
|
|
67
|
-
&& left.aggregate.
|
|
68
|
-
&& left.
|
|
69
|
-
&& left.history.
|
|
70
|
-
&& left.history.
|
|
71
|
-
&& left.history.
|
|
72
|
-
&& left.history.
|
|
73
|
-
&& left.
|
|
74
|
-
&& left.tailTrim.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{ id: '
|
|
88
|
-
{ id: '
|
|
89
|
-
{ id: '
|
|
90
|
-
{ id: '
|
|
91
|
-
{ id: '
|
|
92
|
-
{ id: '
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
ctx.locale.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
1
|
+
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
2
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
+
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
4
|
+
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
5
|
+
import type {} from '@deepseek-ai/dsh-client-ui-workspace/client'
|
|
6
|
+
import {
|
|
7
|
+
isCustomCompressionPolicy,
|
|
8
|
+
ContextCompressionSettingsSection,
|
|
9
|
+
type CompressionSelectorInjected, type ContextCompressionSettings,
|
|
10
|
+
} from './CompressionProfileSelector.tsx'
|
|
11
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
|
|
12
|
+
import { decodeSettings } from './decode.ts'
|
|
13
|
+
import { initMonitorFab } from './monitor-fab.ts'
|
|
14
|
+
import { en, zh } from './locales.ts'
|
|
15
|
+
import { de } from './locales/de.ts'
|
|
16
|
+
import { es } from './locales/es.ts'
|
|
17
|
+
import { fr } from './locales/fr.ts'
|
|
18
|
+
import { it } from './locales/it.ts'
|
|
19
|
+
import { ja } from './locales/ja.ts'
|
|
20
|
+
import { ko } from './locales/ko.ts'
|
|
21
|
+
import { ru } from './locales/ru.ts'
|
|
22
|
+
import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
|
|
23
|
+
import type { ScopeSnapshot, SettingsScope } from './scope-face.ts'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Harness 0.1.5 mounts the web core's `slots` service on the client context
|
|
27
|
+
* but no longer ships a public type for it; declare the face this plugin
|
|
28
|
+
* consumes (same shape dsh-thinking-levels and dsh-prime-memory rely on).
|
|
29
|
+
* `inject` factories may be sync (return a disposer) or generator (yield the
|
|
30
|
+
* registration); slot options are validated at runtime per slot kind, which
|
|
31
|
+
* lets one entry supply both `id` (Desktop, list) and `key` (CLI, keyed).
|
|
32
|
+
*/
|
|
33
|
+
interface SlotsService {
|
|
34
|
+
inject(slot: string, register: () => (() => void) | Generator<() => void>): () => void
|
|
35
|
+
register(options: Record<string, unknown>, component: unknown): () => void
|
|
36
|
+
}
|
|
37
|
+
declare module '@deepseek-ai/cordis' {
|
|
38
|
+
interface Context {
|
|
39
|
+
slots: SlotsService
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Declare all consumed services (the official client-plugin pattern, and the
|
|
44
|
+
// shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
|
|
45
|
+
// apply until `locale` / `configForms` are provided, so registration can use
|
|
46
|
+
// them directly. Resolving them lazily via ctx.get() instead races the settings
|
|
47
|
+
// client's activation — on a loss the apply early-returned and EVERY settings
|
|
48
|
+
// entry silently vanished.
|
|
49
|
+
export const inject = ['slots', 'locale', 'configForms']
|
|
50
|
+
const NS = 'context-compression'
|
|
51
|
+
|
|
52
|
+
/** 0.1.7: the profile entry whose config carries the compression settings doc. */
|
|
53
|
+
const ENTRY_ID = 'context-compression-improved-bundle'
|
|
54
|
+
|
|
55
|
+
function sameCustomPolicy(
|
|
56
|
+
left: ContextCompressionSettings['custom'],
|
|
57
|
+
right: ContextCompressionSettings['custom'],
|
|
58
|
+
): boolean {
|
|
59
|
+
if (left.version !== 3 || right.version !== 3) return false
|
|
60
|
+
return left.version === right.version
|
|
61
|
+
&& left.unit === right.unit
|
|
62
|
+
&& left.prefixPolicy === right.prefixPolicy
|
|
63
|
+
&& left.fresh.enabled === right.fresh.enabled
|
|
64
|
+
&& left.fresh.trigger === right.fresh.trigger
|
|
65
|
+
&& left.fresh.target === right.fresh.target
|
|
66
|
+
&& left.aggregate.enabled === right.aggregate.enabled
|
|
67
|
+
&& left.aggregate.trigger === right.aggregate.trigger
|
|
68
|
+
&& left.aggregate.target === right.aggregate.target
|
|
69
|
+
&& left.history.enabled === right.history.enabled
|
|
70
|
+
&& left.history.trigger === right.history.trigger
|
|
71
|
+
&& left.history.keepRecentToolCalls === right.history.keepRecentToolCalls
|
|
72
|
+
&& left.history.keepRecentTokens === right.history.keepRecentTokens
|
|
73
|
+
&& left.history.minReclaim === right.history.minReclaim
|
|
74
|
+
&& left.tailTrim.enabled === right.tailTrim.enabled
|
|
75
|
+
&& left.tailTrim.trigger === right.tailTrim.trigger
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function apply(ctx: ClientContext): void {
|
|
79
|
+
ctx.locale.register(NS, { zh, en })
|
|
80
|
+
// de/es/fr/it/ja/ko/ru are not host built-ins (`BuiltInLocaleId` is zh|en), so
|
|
81
|
+
// their dictionaries ride the single-locale untyped register overload, and each
|
|
82
|
+
// needs an `addLanguage` definition to become selectable — the catalog owns
|
|
83
|
+
// setLocale and the Language settings row, and a definition's fallback chain
|
|
84
|
+
// must end at English. Labels are self-described in their own language. One
|
|
85
|
+
// occupied locale must not sink activation, hence the per-language guard.
|
|
86
|
+
const languages = [
|
|
87
|
+
{ id: 'de', label: 'Deutsch', dict: de },
|
|
88
|
+
{ id: 'es', label: 'Español', dict: es },
|
|
89
|
+
{ id: 'fr', label: 'Français', dict: fr },
|
|
90
|
+
{ id: 'it', label: 'Italiano', dict: it },
|
|
91
|
+
{ id: 'ja', label: '日本語', dict: ja },
|
|
92
|
+
{ id: 'ko', label: '한국어', dict: ko },
|
|
93
|
+
{ id: 'ru', label: 'Русский', dict: ru },
|
|
94
|
+
] as const
|
|
95
|
+
for (const language of languages) {
|
|
96
|
+
try {
|
|
97
|
+
ctx.locale.register(NS, language.id, language.dict)
|
|
98
|
+
ctx.locale.addLanguage({ id: language.id, label: language.label, fallback: 'en' })
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn(`[dsh-context-compression-improved] locale "${language.id}" registration failed:`, error)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Section label translator, captured EAGERLY: the settings shell evaluates
|
|
104
|
+
// `label()` during its own render; a lazy ctx.locale accessor inside the
|
|
105
|
+
// thunk would throw there if `locale` ever left this module's inject list
|
|
106
|
+
// (the search-index 0.5.3 family-tab incident). bind() returns a live
|
|
107
|
+
// binder, so locale switches are still followed.
|
|
108
|
+
const localeSvc = ctx.locale as { bind?: (n: string) => (key: string) => string } | undefined
|
|
109
|
+
const tNav = localeSvc?.bind?.(NS) ?? ((key: string) => key)
|
|
110
|
+
|
|
111
|
+
// 浮动监控面板(FAB): body 级幂等单例。enabled 读取走设置文档——表单句柄的
|
|
112
|
+
// 激活规则与旧 bind 相同,故 apply 侧 try/catch 兜底,注入工厂内再刷新读取闭包。
|
|
113
|
+
let readMonitorPanelEnabled = (): boolean => {
|
|
114
|
+
try {
|
|
115
|
+
const form = ctx.configForms.get<Record<string, unknown>>(ENTRY_ID)
|
|
116
|
+
return decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false
|
|
117
|
+
} catch {
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 浮动面板会话绑定:跟随输入栏座位的 inject 回调(裸 sessionId,pm longtask 同款)。
|
|
122
|
+
let latestSessionId: string | undefined
|
|
123
|
+
try {
|
|
124
|
+
initMonitorFab({
|
|
125
|
+
t: tNav,
|
|
126
|
+
sessionIdOf: () => latestSessionId,
|
|
127
|
+
enabledOf: () => readMonitorPanelEnabled(),
|
|
128
|
+
fetchSnapshot: async (sessionId) => {
|
|
129
|
+
const query = sessionId === undefined ? '' : `?sessionId=${encodeURIComponent(sessionId)}`
|
|
130
|
+
const response = await fetch(`/api/dsh-context-compression-improved/monitor${query}`, { headers: { 'cache-control': 'no-cache' } })
|
|
131
|
+
if (!response.ok) throw new Error(`monitor snapshot ${response.status}`)
|
|
132
|
+
return await response.json() as Parameters<typeof initMonitorFab>[0]['fetchSnapshot'] extends (...args: never[]) => Promise<infer T> ? T : never
|
|
133
|
+
},
|
|
134
|
+
applyOverride: async (sessionId, action) => {
|
|
135
|
+
const query = sessionId === undefined ? '' : `?sessionId=${encodeURIComponent(sessionId)}`
|
|
136
|
+
await fetch(`/api/dsh-context-compression-improved/monitor${query}`, {
|
|
137
|
+
method: 'POST',
|
|
138
|
+
headers: { 'content-type': 'application/json' },
|
|
139
|
+
body: JSON.stringify({ action }),
|
|
140
|
+
})
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.warn('[dsh-context-compression-improved] 监控浮动球挂载失败(不影响设置分节):', error)
|
|
145
|
+
}
|
|
146
|
+
const injected = (): CompressionSelectorInjected => {
|
|
147
|
+
// 0.1.7: the compression document rides the selector row's entry config as
|
|
148
|
+
// the volatile `settings` field. The form handle is fetched per factory
|
|
149
|
+
// call on the caller's fiber (same activation rule as the old bind); the
|
|
150
|
+
// wrapper below decodes the stored doc and converts per-field writes into
|
|
151
|
+
// whole-doc commits (a volatile object replaces as one snapshot).
|
|
152
|
+
const form = ctx.configForms.get<Record<string, unknown>>(ENTRY_ID)
|
|
153
|
+
const readDoc = (): ContextCompressionSettings | undefined =>
|
|
154
|
+
decodeSettings(form.getSnapshot().value?.settings)
|
|
155
|
+
readMonitorPanelEnabled = (): boolean =>
|
|
156
|
+
decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false
|
|
157
|
+
// useSyncExternalStore requires a getSnapshot that returns a STABLE
|
|
158
|
+
// reference between changes — a fresh object per call is React error #185
|
|
159
|
+
// (maximum update depth exceeded). Cache the projection keyed on the form
|
|
160
|
+
// snapshot's identity: ConfigFormSnapshot is documented stable until the
|
|
161
|
+
// next accepted change.
|
|
162
|
+
let projectedSource: object | undefined
|
|
163
|
+
let projected: ScopeSnapshot<ContextCompressionSettings> = {
|
|
164
|
+
status: 'loading', value: undefined, revision: undefined,
|
|
165
|
+
writable: false, base: undefined, user: undefined, mode: 'host',
|
|
166
|
+
}
|
|
167
|
+
const scope: SettingsScope<ContextCompressionSettings> = {
|
|
168
|
+
getSnapshot() {
|
|
169
|
+
const snap = form.getSnapshot()
|
|
170
|
+
if (snap !== projectedSource) {
|
|
171
|
+
projectedSource = snap
|
|
172
|
+
projected = {
|
|
173
|
+
status: snap.status,
|
|
174
|
+
value: decodeSettings(snap.value?.settings),
|
|
175
|
+
revision: snap.revision,
|
|
176
|
+
writable: snap.writable,
|
|
177
|
+
base: snap.base,
|
|
178
|
+
user: snap.user,
|
|
179
|
+
mode: snap.mode,
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return projected
|
|
183
|
+
},
|
|
184
|
+
subscribe: (listener) => form.subscribe(listener),
|
|
185
|
+
set: async (field, value) => {
|
|
186
|
+
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
187
|
+
next[field] = value
|
|
188
|
+
return form.set('settings', next)
|
|
189
|
+
},
|
|
190
|
+
unset: async (field) => {
|
|
191
|
+
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
192
|
+
delete next[field]
|
|
193
|
+
return form.set('settings', next)
|
|
194
|
+
},
|
|
195
|
+
mutate: async (ops) => {
|
|
196
|
+
const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
197
|
+
for (const op of ops) {
|
|
198
|
+
const [head, key] = op.path as [string, string]
|
|
199
|
+
if (head !== 'presetOptions') return false
|
|
200
|
+
const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
|
|
201
|
+
if (op.op === 'unset') delete section[key]
|
|
202
|
+
else section[key] = (op as { value?: unknown }).value
|
|
203
|
+
doc.presetOptions = section
|
|
204
|
+
}
|
|
205
|
+
return form.set('settings', doc)
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
const writeAndConfirm = async (
|
|
209
|
+
write: () => Promise<unknown>,
|
|
210
|
+
accepts: (settings: ContextCompressionSettings) => boolean,
|
|
211
|
+
): Promise<void> => {
|
|
212
|
+
const beforeRevision = scope.getSnapshot().revision
|
|
213
|
+
await write()
|
|
214
|
+
const after = scope.getSnapshot()
|
|
215
|
+
if (
|
|
216
|
+
after.status !== 'ready'
|
|
217
|
+
|| after.value === undefined
|
|
218
|
+
|| after.revision === beforeRevision
|
|
219
|
+
|| !accepts(after.value)
|
|
220
|
+
) {
|
|
221
|
+
throw new Error('Context compression settings were not saved.')
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
hooks: { compression: scope },
|
|
226
|
+
select: profile => writeAndConfirm(
|
|
227
|
+
() => scope.set('profile', profile),
|
|
228
|
+
settings => settings.profile === profile,
|
|
229
|
+
),
|
|
230
|
+
saveCustom: custom => writeAndConfirm(
|
|
231
|
+
() => scope.set('custom', custom),
|
|
232
|
+
settings => isCustomCompressionPolicy(settings.custom)
|
|
233
|
+
&& sameCustomPolicy(settings.custom, custom),
|
|
234
|
+
),
|
|
235
|
+
resetCustom: () => writeAndConfirm(
|
|
236
|
+
() => scope.set('custom', structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)),
|
|
237
|
+
settings => isCustomCompressionPolicy(settings.custom)
|
|
238
|
+
&& sameCustomPolicy(settings.custom, DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
239
|
+
),
|
|
240
|
+
saveAutoCompact: thresholdPercent => writeAndConfirm(
|
|
241
|
+
() => scope.set('autoCompact', { thresholdPercent }),
|
|
242
|
+
settings => settings.autoCompact.thresholdPercent === thresholdPercent,
|
|
243
|
+
),
|
|
244
|
+
saveCodeSkeleton: enabled => writeAndConfirm(
|
|
245
|
+
() => scope.set('codeSkeleton', { enabled }),
|
|
246
|
+
settings => settings.codeSkeleton.enabled === enabled,
|
|
247
|
+
),
|
|
248
|
+
saveIntentSummary: enabled => writeAndConfirm(
|
|
249
|
+
() => scope.set('intentSummary', { enabled }),
|
|
250
|
+
settings => settings.intentSummary.enabled === enabled,
|
|
251
|
+
),
|
|
252
|
+
saveMonitorPanel: enabled => writeAndConfirm(
|
|
253
|
+
() => scope.set('monitorPanel', { enabled }),
|
|
254
|
+
settings => settings.monitorPanel?.enabled === enabled,
|
|
255
|
+
),
|
|
256
|
+
savePresetOptions: options => {
|
|
257
|
+
// Path-addressed so one field write cannot delete its siblings: the
|
|
258
|
+
// previous whole-section set erased estimatorMode (and every other
|
|
259
|
+
// override) whenever the user touched a second field.
|
|
260
|
+
const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
|
|
261
|
+
if (ops.length === 0) return Promise.resolve()
|
|
262
|
+
return writeAndConfirm(
|
|
263
|
+
() => scope.mutate?.(ops) ?? Promise.resolve(false),
|
|
264
|
+
settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
|
|
265
|
+
)
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// 设置 → 上下文压缩 直挂分节(0.1.1 契约;0.1.5 官方分节也注册在此,未声明槽
|
|
270
|
+
// 的注册会在激活期抛错,故 try/catch 守卫 —— 同 dsh-prime-memory 的双槽冗余)。
|
|
271
|
+
// 只挂这一处:再注册 `settings.plugins.tab` / `settings.plugin.item` 会在
|
|
272
|
+
// 设置里同时出现独立分节和插件卡片,重复展示同一张面板。
|
|
273
|
+
try {
|
|
274
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
275
|
+
name: 'settings.section',
|
|
276
|
+
id: 'context-compression',
|
|
277
|
+
order: 17,
|
|
278
|
+
label: () => tNav('nav'),
|
|
279
|
+
locale: NS,
|
|
280
|
+
inject: injected,
|
|
281
|
+
}, ContextCompressionSettingsSection))
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.warn('[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):', error)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 输入栏左座(0.1.5+ 宿主):组件刻意空渲染——注册此座位只为接收宿主的
|
|
287
|
+
// sessionId 注入回调,供浮动监控面板绑定会话(pm longtask 同款)。旧宿主
|
|
288
|
+
// 未声明该槽时激活期会抛错,try/catch 守卫(同上双槽冗余先例)。
|
|
289
|
+
try {
|
|
290
|
+
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
291
|
+
name: 'conversation.input.left',
|
|
292
|
+
id: 'context-compression-session-bind',
|
|
293
|
+
order: 170,
|
|
294
|
+
inject: (sessionId: string) => {
|
|
295
|
+
latestSessionId = sessionId
|
|
296
|
+
return {}
|
|
297
|
+
},
|
|
298
|
+
}, () => null))
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.warn('[dsh-context-compression-improved] conversation.input.left 注册失败(旧宿主无该槽,浮动面板保持聚合口径):', error)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export type {
|
|
305
|
+
CompressionProfile, CompressionProfileSelectorProps, CompressionSelectorInjected,
|
|
306
|
+
ContextCompressionSettings,
|
|
307
|
+
} from './CompressionProfileSelector.tsx'
|
|
@@ -64,6 +64,34 @@ export const de = {
|
|
|
64
64
|
'codeSkeleton.enabled': 'Code-Skelettkomprimierung',
|
|
65
65
|
'codeSkeleton.enabled.on': 'Ein',
|
|
66
66
|
'codeSkeleton.enabled.off': 'Aus (Standard)',
|
|
67
|
+
'intentSummary.title': 'Abschluss-Zusammenfassung (Turn-Tail)',
|
|
68
|
+
'intentSummary.description': 'Aktiviert faltet der Turn-Abschluss den verbrauchten Zuwachs nach semantischen Rollen zu Intent-Zusammenfassungsblöcken: Lese-Tool-Ergebnisse werden zu Einzeilern mit Ziel/Umfang, die Schreibklasse behält Skelettköpfe plus wörtliche Fehlerzeilen; die Landung erfolgt in der nächsten Druckrunde über die gewöhnliche Falt-Pipeline. Zündet nur, wenn die Wachstumsschwelle passiert ist (live Oberfläche >45 % und >50K Token seit der letzten Faltung). Gilt für neue Sitzungen; die aktuelle lässt sich mit /ctx-summary off|on|status übersteuern.',
|
|
69
|
+
'intentSummary.enabled': 'Abschluss-Zusammenfassung',
|
|
70
|
+
'intentSummary.enabled.on': 'Ein',
|
|
71
|
+
'intentSummary.enabled.off': 'Aus (Standard)',
|
|
72
|
+
'monitor.fab.title': 'Komprimierungs-Monitor',
|
|
73
|
+
'monitor.panel.title': 'Komprimierungs-Monitor',
|
|
74
|
+
'monitor.panel.net': 'Nettoeinsparung',
|
|
75
|
+
'monitor.panel.gross': 'Bruttoeinsparung',
|
|
76
|
+
'monitor.panel.offsets': 'Ausgleiche',
|
|
77
|
+
'monitor.panel.context': 'Kontextbelegung',
|
|
78
|
+
'monitor.panel.suggest': 'Kontextbelegung bei {pct}% — nahe der katastrophalen Vergessenszone; Komprimieren oder Kürzen des Verlaufs empfohlen',
|
|
79
|
+
'monitor.panel.cacheHit': 'Cache-Trefferquote',
|
|
80
|
+
'monitor.panel.cost': 'Kosten (ist / gespart gesch.)',
|
|
81
|
+
'monitor.panel.intent': 'Intent-Zusammenfassung',
|
|
82
|
+
'monitor.panel.overrideHint': 'Sitzungs-Übersteuerung',
|
|
83
|
+
'monitor.panel.resume': 'Fortsetzen',
|
|
84
|
+
'monitor.panel.disable': 'Deaktivieren',
|
|
85
|
+
'monitor.panel.stateOn': 'ein',
|
|
86
|
+
'monitor.panel.stateOff': 'aus',
|
|
87
|
+
'monitor.panel.gateUnknown': 'noch nicht bewertet',
|
|
88
|
+
'monitor.panel.lastFold': 'Letzte Faltung',
|
|
89
|
+
'monitor.panel.stale': 'Snapshot nicht erreichbar — letzte Daten',
|
|
90
|
+
'monitorPanel.title': 'Komprimierungs-Monitorpanel',
|
|
91
|
+
'monitorPanel.description': 'Aktiviert erscheint neben dem Eingabebereich eine ziehbare Schwebekugel — öffne sie, um den Live-Komprimierungszustand zu beobachten: Nettoeinsparung (exakte Basis), Cache-Trefferquote, Kostenschätzung, das Turn-Tail-Gate und letzte Ausgleiche. Das Panel kann den Intent-Zusammenfassungsschalter der aktuellen Sitzung temporär übersteuern. Das Konto ist prozesslokal (Reset bei Host-Neustart).',
|
|
92
|
+
'monitorPanel.enabled': 'Monitorpanel',
|
|
93
|
+
'monitorPanel.enabled.on': 'Ein',
|
|
94
|
+
'monitorPanel.enabled.off': 'Aus (Standard)',
|
|
67
95
|
'custom.title': 'Eigene Strategie',
|
|
68
96
|
'custom.settingsHint': 'Detaillierte Parameter unter Einstellungen > Kontextkomprimierung wählen bearbeiten.',
|
|
69
97
|
'custom.sessionScope': 'Gespeicherte Änderungen greifen, wenn die aktuelle Compression-Runtime eine Sitzung zum ersten Mal beobachtet. Eine von dieser Runtime bereits beobachtete Sitzung behält ihre eingefrorene Strategie.',
|
|
@@ -95,4 +123,19 @@ export const de = {
|
|
|
95
123
|
'custom.save': 'Eigene Strategie speichern',
|
|
96
124
|
'custom.reset': 'Eigene Strategie zurücksetzen',
|
|
97
125
|
'custom.invalid': 'Werte der eigenen Strategie sind ungültig.',
|
|
126
|
+
'savings.title': 'Einsparungen (dieser Prozess)',
|
|
127
|
+
'savings.netExact': 'Netto gespeichert (exakte Basis)',
|
|
128
|
+
'savings.netEstimated': 'Netto gespeichert (geschätzte Basis)',
|
|
129
|
+
'savings.gross': 'Brutto gespeichert (bei Veröffentlichung)',
|
|
130
|
+
'savings.offsets': 'Abschläge (komprimiert, später vollständig gelesen)',
|
|
131
|
+
'savings.empty': 'Noch keine Komprimierung — Nettoeinsparungen erscheinen nach der ersten Reduktion.',
|
|
132
|
+
'savings.basisExact': 'exakt',
|
|
133
|
+
'savings.basisEstimated': 'geschätzt',
|
|
134
|
+
'savings.basisNote': 'Basen werden getrennt ausgewiesen, nie gemischt: exakt = DeepSeek-Tokenizer; geschätzt = chars/4. Erst Skelett, dann Volltext zählt als negative Einsparung (Netto kann unter null fallen).',
|
|
135
|
+
'savings.requests': 'Requests',
|
|
136
|
+
'savings.cacheHit': 'Cache hit rate',
|
|
137
|
+
'savings.actualCost': 'Actual cost (official prices)',
|
|
138
|
+
'savings.savedMoney': 'Estimated saved cost (input price)',
|
|
139
|
+
'savings.perSession': 'Session',
|
|
140
|
+
|
|
98
141
|
} satisfies Record<ContextCompressionLocaleKey, string>
|