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,49 +1,57 @@
|
|
|
1
|
-
/** Browser-safe settings decoding shared by the client entry and node tests. */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
canonicalizeCustomPolicy,
|
|
5
|
-
COMPRESSION_PROFILES,
|
|
6
|
-
decodeAutoCompactSettings,
|
|
7
|
-
decodeCodeSkeletonSettings,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1
|
+
/** Browser-safe settings decoding shared by the client entry and node tests. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
canonicalizeCustomPolicy,
|
|
5
|
+
COMPRESSION_PROFILES,
|
|
6
|
+
decodeAutoCompactSettings,
|
|
7
|
+
decodeCodeSkeletonSettings,
|
|
8
|
+
decodeIntentSummarySettings,
|
|
9
|
+
decodeMonitorPanelSettings,
|
|
10
|
+
decodePresetOptionsSettings,
|
|
11
|
+
isCustomCompressionPolicy,
|
|
12
|
+
isPlainRecord,
|
|
13
|
+
type CompressionProfile,
|
|
14
|
+
type ContextCompressionSettings,
|
|
15
|
+
} from '../profiles.ts'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decode one stored context-compression settings document with exactly the
|
|
19
|
+
* runtime schema's strictness: a plain object with only `profile`, `custom`,
|
|
20
|
+
* `autoCompact`, `codeSkeleton`, and `intentSummary` keys, a supported profile, a valid Custom
|
|
21
|
+
* document canonicalized to v3 exactly as the runtime resolver would, a
|
|
22
|
+
* strictly-shaped autoCompact section (absent inherits the 80% default), and
|
|
23
|
+
* a strictly-shaped codeSkeleton gate (absent inherits off). Anything else
|
|
24
|
+
* decodes to `undefined` so the UI reports the document as unreadable instead
|
|
25
|
+
* of silently disagreeing with the runtime.
|
|
26
|
+
*/
|
|
27
|
+
export function decodeSettings(value: unknown): ContextCompressionSettings | undefined {
|
|
28
|
+
if (!isPlainRecord(value)) return undefined
|
|
29
|
+
const keys = Object.keys(value)
|
|
30
|
+
if (keys.some(key => key !== 'profile' && key !== 'custom' && key !== 'autoCompact' && key !== 'codeSkeleton' && key !== 'intentSummary' && key !== 'monitorPanel' && key !== 'presetOptions')) {
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
const profile = (value as { profile?: unknown }).profile
|
|
34
|
+
const custom = (value as { custom?: unknown }).custom
|
|
35
|
+
const autoCompact = decodeAutoCompactSettings((value as { autoCompact?: unknown }).autoCompact)
|
|
36
|
+
const codeSkeleton = decodeCodeSkeletonSettings((value as { codeSkeleton?: unknown }).codeSkeleton)
|
|
37
|
+
const intentSummary = decodeIntentSummarySettings((value as { intentSummary?: unknown }).intentSummary)
|
|
38
|
+
const monitorPanel = decodeMonitorPanelSettings((value as { monitorPanel?: unknown }).monitorPanel)
|
|
39
|
+
const presetOptions = decodePresetOptionsSettings((value as { presetOptions?: unknown }).presetOptions)
|
|
40
|
+
return typeof profile === 'string'
|
|
41
|
+
&& (COMPRESSION_PROFILES as readonly string[]).includes(profile)
|
|
42
|
+
&& isCustomCompressionPolicy(custom)
|
|
43
|
+
&& autoCompact !== undefined
|
|
44
|
+
&& codeSkeleton !== undefined
|
|
45
|
+
&& intentSummary !== undefined
|
|
46
|
+
&& monitorPanel !== undefined
|
|
47
|
+
? {
|
|
48
|
+
profile: profile as CompressionProfile,
|
|
49
|
+
custom: canonicalizeCustomPolicy(custom),
|
|
50
|
+
autoCompact,
|
|
51
|
+
codeSkeleton,
|
|
52
|
+
intentSummary,
|
|
53
|
+
...monitorPanel === undefined ? {} : { monitorPanel },
|
|
54
|
+
...presetOptions === undefined ? {} : { presetOptions },
|
|
55
|
+
}
|
|
56
|
+
: undefined
|
|
57
|
+
}
|
|
@@ -1,149 +1,240 @@
|
|
|
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 { en, zh } from './locales.ts'
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
&& left.
|
|
60
|
-
&& left.
|
|
61
|
-
&& left.
|
|
62
|
-
&& left.
|
|
63
|
-
&& left.
|
|
64
|
-
&& left.
|
|
65
|
-
&& left.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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 { en, zh } from './locales.ts'
|
|
14
|
+
import { de } from './locales/de.ts'
|
|
15
|
+
import { es } from './locales/es.ts'
|
|
16
|
+
import { fr } from './locales/fr.ts'
|
|
17
|
+
import { it } from './locales/it.ts'
|
|
18
|
+
import { ja } from './locales/ja.ts'
|
|
19
|
+
import { ko } from './locales/ko.ts'
|
|
20
|
+
import { ru } from './locales/ru.ts'
|
|
21
|
+
import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
|
|
22
|
+
import { initMonitorFab } from './monitor-fab.ts'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Harness 0.1.5 mounts the web core's `slots` service on the client context
|
|
26
|
+
* but no longer ships a public type for it; declare the face this plugin
|
|
27
|
+
* consumes (same shape dsh-thinking-levels and dsh-prime-memory rely on).
|
|
28
|
+
* `inject` factories may be sync (return a disposer) or generator (yield the
|
|
29
|
+
* registration); slot options are validated at runtime per slot kind, which
|
|
30
|
+
* lets one entry supply both `id` (Desktop, list) and `key` (CLI, keyed).
|
|
31
|
+
*/
|
|
32
|
+
interface SlotsService {
|
|
33
|
+
inject(slot: string, register: () => (() => void) | Generator<() => void>): () => void
|
|
34
|
+
register(options: Record<string, unknown>, component: unknown): () => void
|
|
35
|
+
}
|
|
36
|
+
declare module '@deepseek-ai/cordis' {
|
|
37
|
+
interface Context {
|
|
38
|
+
slots: SlotsService
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Declare all consumed services (the official client-plugin pattern, and the
|
|
43
|
+
// shape dsh-thinking-levels proves on this same 0.1.5 host line): cordis holds
|
|
44
|
+
// apply until `locale` / `settingsScope` are provided, so registration can use
|
|
45
|
+
// them directly. Resolving them lazily via ctx.get() instead races the settings
|
|
46
|
+
// client's activation — on a loss the apply early-returned and EVERY settings
|
|
47
|
+
// entry (the standalone section, the plugins-tab card, the item card) silently
|
|
48
|
+
// vanished.
|
|
49
|
+
export const inject = ['slots', 'locale', 'settingsScope']
|
|
50
|
+
const NS = 'context-compression'
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function sameCustomPolicy(
|
|
54
|
+
left: ContextCompressionSettings['custom'],
|
|
55
|
+
right: ContextCompressionSettings['custom'],
|
|
56
|
+
): boolean {
|
|
57
|
+
if (left.version !== 3 || right.version !== 3) return false
|
|
58
|
+
return left.version === right.version
|
|
59
|
+
&& left.unit === right.unit
|
|
60
|
+
&& left.prefixPolicy === right.prefixPolicy
|
|
61
|
+
&& left.fresh.enabled === right.fresh.enabled
|
|
62
|
+
&& left.fresh.trigger === right.fresh.trigger
|
|
63
|
+
&& left.fresh.target === right.fresh.target
|
|
64
|
+
&& left.aggregate.enabled === right.aggregate.enabled
|
|
65
|
+
&& left.aggregate.trigger === right.aggregate.trigger
|
|
66
|
+
&& left.aggregate.target === right.aggregate.target
|
|
67
|
+
&& left.history.enabled === right.history.enabled
|
|
68
|
+
&& left.history.trigger === right.history.trigger
|
|
69
|
+
&& left.history.keepRecentToolCalls === right.history.keepRecentToolCalls
|
|
70
|
+
&& left.history.keepRecentTokens === right.history.keepRecentTokens
|
|
71
|
+
&& left.history.minReclaim === right.history.minReclaim
|
|
72
|
+
&& left.tailTrim.enabled === right.tailTrim.enabled
|
|
73
|
+
&& left.tailTrim.trigger === right.tailTrim.trigger
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function apply(ctx: ClientContext): void {
|
|
77
|
+
ctx.locale.register(NS, { zh, en })
|
|
78
|
+
// de/es/fr/it/ja/ko/ru are not host built-ins (`BuiltInLocaleId` is zh|en), so
|
|
79
|
+
// their dictionaries ride the single-locale untyped register overload, and each
|
|
80
|
+
// needs an `addLanguage` definition to become selectable. Labels are
|
|
81
|
+
// self-described in their own language; the fallback chain ends at English.
|
|
82
|
+
// One occupied locale must not sink activation, hence the per-language guard.
|
|
83
|
+
const languages = [
|
|
84
|
+
{ id: 'de', label: 'Deutsch', dict: de },
|
|
85
|
+
{ id: 'es', label: 'Español', dict: es },
|
|
86
|
+
{ id: 'fr', label: 'Français', dict: fr },
|
|
87
|
+
{ id: 'it', label: 'Italiano', dict: it },
|
|
88
|
+
{ id: 'ja', label: '日本語', dict: ja },
|
|
89
|
+
{ id: 'ko', label: '한국어', dict: ko },
|
|
90
|
+
{ id: 'ru', label: 'Русский', dict: ru },
|
|
91
|
+
] as const
|
|
92
|
+
for (const language of languages) {
|
|
93
|
+
try {
|
|
94
|
+
ctx.locale.register(NS, language.id, language.dict)
|
|
95
|
+
ctx.locale.addLanguage({ id: language.id, label: language.label, fallback: 'en' })
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.warn(`[dsh-context-compression-improved] locale "${language.id}" registration failed:`, error)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Section label translator, captured EAGERLY: the settings shell evaluates
|
|
101
|
+
// `label()` during its own render; a lazy ctx.locale accessor inside the
|
|
102
|
+
// thunk would throw there if `locale` ever left this module's inject list.
|
|
103
|
+
const localeSvc = ctx.locale as { bind?: (n: string) => (key: string) => string } | undefined
|
|
104
|
+
const tNav = localeSvc?.bind?.(NS) ?? ((key: string) => key)
|
|
105
|
+
|
|
106
|
+
// 浮动监控面板(FAB): body 级幂等单例。enabled 读取走 0.1.5 的 settingsScope
|
|
107
|
+
// 文档——注入工厂内再刷新读取闭包(bind 发生在 settings.section 工厂里)。
|
|
108
|
+
let readMonitorPanelEnabled = (): boolean => false
|
|
109
|
+
// 浮动面板会话绑定:跟随输入栏座位的 inject 回调(裸 sessionId,pm longtask 同款)。
|
|
110
|
+
let latestSessionId: string | undefined
|
|
111
|
+
try {
|
|
112
|
+
initMonitorFab({
|
|
113
|
+
t: tNav,
|
|
114
|
+
sessionIdOf: () => latestSessionId,
|
|
115
|
+
enabledOf: () => readMonitorPanelEnabled(),
|
|
116
|
+
fetchSnapshot: async (sessionId) => {
|
|
117
|
+
const query = sessionId === undefined ? '' : `?sessionId=${encodeURIComponent(sessionId)}`
|
|
118
|
+
const response = await fetch(`/api/dsh-context-compression-improved/monitor${query}`, { headers: { 'cache-control': 'no-cache' } })
|
|
119
|
+
if (!response.ok) throw new Error(`monitor snapshot ${response.status}`)
|
|
120
|
+
return await response.json() as Parameters<typeof initMonitorFab>[0]['fetchSnapshot'] extends (...args: never[]) => Promise<infer T> ? T : never
|
|
121
|
+
},
|
|
122
|
+
applyOverride: async (sessionId, action) => {
|
|
123
|
+
const query = sessionId === undefined ? '' : `?sessionId=${encodeURIComponent(sessionId)}`
|
|
124
|
+
await fetch(`/api/dsh-context-compression-improved/monitor${query}`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: { 'content-type': 'application/json' },
|
|
127
|
+
body: JSON.stringify({ action }),
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn('[dsh-context-compression-improved] 监控浮动球挂载失败(不影响设置分节):', error)
|
|
133
|
+
}
|
|
134
|
+
const injected = (): CompressionSelectorInjected => {
|
|
135
|
+
// Bind per factory call on the caller's fiber (0.1.5: activation must
|
|
136
|
+
// never block on the settings transport; the scope disposer belongs to
|
|
137
|
+
// the calling registration's lifecycle).
|
|
138
|
+
const scope = ctx.settingsScope.bind<ContextCompressionSettings>({ namespace: NS, decode: decodeSettings })
|
|
139
|
+
readMonitorPanelEnabled = (): boolean =>
|
|
140
|
+
scope.getSnapshot().value?.monitorPanel?.enabled ?? false
|
|
141
|
+
const writeAndConfirm = async (
|
|
142
|
+
write: () => Promise<void>,
|
|
143
|
+
accepts: (settings: ContextCompressionSettings) => boolean,
|
|
144
|
+
): Promise<void> => {
|
|
145
|
+
const beforeRevision = scope.getSnapshot().revision
|
|
146
|
+
await write()
|
|
147
|
+
const after = scope.getSnapshot()
|
|
148
|
+
if (
|
|
149
|
+
after.status !== 'ready'
|
|
150
|
+
|| after.value === undefined
|
|
151
|
+
|| after.revision === beforeRevision
|
|
152
|
+
|| !accepts(after.value)
|
|
153
|
+
) {
|
|
154
|
+
throw new Error('Context compression settings were not saved.')
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
hooks: { compression: scope },
|
|
159
|
+
select: profile => writeAndConfirm(
|
|
160
|
+
() => scope.set('profile', profile),
|
|
161
|
+
settings => settings.profile === profile,
|
|
162
|
+
),
|
|
163
|
+
saveCustom: custom => writeAndConfirm(
|
|
164
|
+
() => scope.set('custom', custom),
|
|
165
|
+
settings => isCustomCompressionPolicy(settings.custom)
|
|
166
|
+
&& sameCustomPolicy(settings.custom, custom),
|
|
167
|
+
),
|
|
168
|
+
resetCustom: () => writeAndConfirm(
|
|
169
|
+
() => scope.set('custom', structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)),
|
|
170
|
+
settings => isCustomCompressionPolicy(settings.custom)
|
|
171
|
+
&& sameCustomPolicy(settings.custom, DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
172
|
+
),
|
|
173
|
+
saveAutoCompact: thresholdPercent => writeAndConfirm(
|
|
174
|
+
() => scope.set('autoCompact', { thresholdPercent }),
|
|
175
|
+
settings => settings.autoCompact.thresholdPercent === thresholdPercent,
|
|
176
|
+
),
|
|
177
|
+
saveCodeSkeleton: enabled => writeAndConfirm(
|
|
178
|
+
() => scope.set('codeSkeleton', { enabled }),
|
|
179
|
+
settings => settings.codeSkeleton.enabled === enabled,
|
|
180
|
+
),
|
|
181
|
+
saveIntentSummary: enabled => writeAndConfirm(
|
|
182
|
+
() => scope.set('intentSummary', { enabled }),
|
|
183
|
+
settings => settings.intentSummary.enabled === enabled,
|
|
184
|
+
),
|
|
185
|
+
saveMonitorPanel: enabled => writeAndConfirm(
|
|
186
|
+
() => scope.set('monitorPanel', { enabled }),
|
|
187
|
+
settings => settings.monitorPanel?.enabled === enabled,
|
|
188
|
+
),
|
|
189
|
+
savePresetOptions: options => {
|
|
190
|
+
// Path-addressed so one field write cannot delete its siblings: the
|
|
191
|
+
// previous whole-section set erased estimatorMode (and every other
|
|
192
|
+
// override) whenever the user touched a second field.
|
|
193
|
+
const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
|
|
194
|
+
if (ops.length === 0) return Promise.resolve()
|
|
195
|
+
return writeAndConfirm(
|
|
196
|
+
() => scope.mutate(ops),
|
|
197
|
+
settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
|
|
198
|
+
)
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// 设置 → 上下文压缩 直挂分节(0.1.1 契约;0.1.5 官方分节也注册在此,未声明槽
|
|
203
|
+
// 的注册会在激活期抛错,故 try/catch 守卫 —— 同 dsh-prime-memory 的双槽冗余)。
|
|
204
|
+
// 只挂这一处:再注册 `settings.plugins.tab` / `settings.plugin.item` 会在
|
|
205
|
+
// 设置里同时出现独立分节和插件卡片,重复展示同一张面板。
|
|
206
|
+
try {
|
|
207
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
208
|
+
name: 'settings.section',
|
|
209
|
+
id: 'context-compression',
|
|
210
|
+
order: 17,
|
|
211
|
+
label: () => ctx.locale.bind(NS)('nav'),
|
|
212
|
+
locale: NS,
|
|
213
|
+
inject: injected,
|
|
214
|
+
}, ContextCompressionSettingsSection))
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.warn('[dsh-context-compression-improved] settings.section 注册失败(新宿主已收编):', error)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 输入栏左座(0.1.5+ 宿主):组件刻意空渲染——注册此座位只为接收宿主的
|
|
220
|
+
// sessionId 注入回调,供浮动监控面板绑定会话(pm longtask 同款)。旧宿主
|
|
221
|
+
// 未声明该槽时激活期会抛错,try/catch 守卫(同上双槽冗余先例)。
|
|
222
|
+
try {
|
|
223
|
+
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
224
|
+
name: 'conversation.input.left',
|
|
225
|
+
id: 'context-compression-session-bind',
|
|
226
|
+
order: 170,
|
|
227
|
+
inject: (sessionId: string) => {
|
|
228
|
+
latestSessionId = sessionId
|
|
229
|
+
return {}
|
|
230
|
+
},
|
|
231
|
+
}, () => null))
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.warn('[dsh-context-compression-improved] conversation.input.left 注册失败(旧宿主无该槽,浮动面板保持聚合口径):', error)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export type {
|
|
238
|
+
CompressionProfile, CompressionProfileSelectorProps, CompressionSelectorInjected,
|
|
239
|
+
ContextCompressionSettings,
|
|
240
|
+
} from './CompressionProfileSelector.tsx'
|