dsh-context-compression-improved 0.10.0 → 0.10.2

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.
Files changed (262) hide show
  1. package/README.md +15 -110
  2. package/README.zh.md +14 -104
  3. package/THIRD_PARTY_NOTICES.md +25 -7
  4. package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
  5. package/{packages/selector/lib → lib}/client.js +73 -12
  6. package/package.json +129 -116
  7. package/screenshots.json +3 -6
  8. package/.agents/plans/improve/checklist.md +0 -32
  9. package/.agents/plans/improve/findings.md +0 -102
  10. package/.agents/plans/improve/spec.md +0 -53
  11. package/.agents/plans/improve/tasks.md +0 -70
  12. package/.gitattributes +0 -2
  13. package/.githooks/pre-push +0 -37
  14. package/.github/workflows/ci.yml +0 -39
  15. package/CHANGELOG.de.md +0 -580
  16. package/CHANGELOG.es.md +0 -588
  17. package/CHANGELOG.fr.md +0 -576
  18. package/CHANGELOG.it.md +0 -577
  19. package/CHANGELOG.ja.md +0 -261
  20. package/CHANGELOG.ko.md +0 -254
  21. package/CHANGELOG.md +0 -544
  22. package/CHANGELOG.ru.md +0 -554
  23. package/CHANGELOG.zh.md +0 -238
  24. package/CONTRIBUTING.md +0 -22
  25. package/README.de.md +0 -96
  26. package/README.es.md +0 -96
  27. package/README.fr.md +0 -96
  28. package/README.it.md +0 -96
  29. package/README.ja.md +0 -102
  30. package/README.ko.md +0 -102
  31. package/README.ru.md +0 -96
  32. package/SECURITY.md +0 -18
  33. package/assets/board.png +0 -0
  34. package/assets/context.png +0 -0
  35. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  36. package/docs/assets/context-compression-selector-settings.png +0 -0
  37. package/docs/compat-0.1.5-report.md +0 -77
  38. package/docs/installation.de.md +0 -104
  39. package/docs/installation.es.md +0 -104
  40. package/docs/installation.fr.md +0 -104
  41. package/docs/installation.it.md +0 -104
  42. package/docs/installation.ja.md +0 -78
  43. package/docs/installation.ko.md +0 -78
  44. package/docs/installation.md +0 -103
  45. package/docs/installation.ru.md +0 -104
  46. package/docs/installation.zh.md +0 -100
  47. package/docs/repair-log.md +0 -657
  48. package/eslint.config.js +0 -30
  49. package/packages/selector/LICENSE +0 -21
  50. package/packages/selector/README.md +0 -26
  51. package/packages/selector/README.zh.md +0 -24
  52. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  53. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  54. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  55. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  56. package/packages/selector/lib/style.css +0 -350
  57. package/packages/selector/package.json +0 -178
  58. package/packages/selector/screenshots.json +0 -3
  59. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
  60. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  61. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
  62. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  63. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  64. package/packages/selector/src/client/bridge-scope.ts +0 -125
  65. package/packages/selector/src/client/decode.ts +0 -57
  66. package/packages/selector/src/client/index.ts +0 -424
  67. package/packages/selector/src/client/locales/de.ts +0 -158
  68. package/packages/selector/src/client/locales/es.ts +0 -158
  69. package/packages/selector/src/client/locales/fr.ts +0 -158
  70. package/packages/selector/src/client/locales/it.ts +0 -158
  71. package/packages/selector/src/client/locales/ja.ts +0 -158
  72. package/packages/selector/src/client/locales/ko.ts +0 -158
  73. package/packages/selector/src/client/locales/ru.ts +0 -158
  74. package/packages/selector/src/client/locales.ts +0 -316
  75. package/packages/selector/src/client/monitor-fab.ts +0 -419
  76. package/packages/selector/src/client/preset-options.ts +0 -88
  77. package/packages/selector/src/client/savings-card.tsx +0 -269
  78. package/packages/selector/src/client/scope-face.ts +0 -24
  79. package/packages/selector/src/client/settings-section.tsx +0 -140
  80. package/packages/selector/src/compat/host-generation.ts +0 -96
  81. package/packages/selector/src/compat/llm-messages.ts +0 -50
  82. package/packages/selector/src/compat/settings-lease.ts +0 -108
  83. package/packages/selector/src/compat/tool-result.ts +0 -91
  84. package/packages/selector/src/css-modules.d.ts +0 -6
  85. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  86. package/packages/selector/src/estimator-catalog.ts +0 -104
  87. package/packages/selector/src/index.ts +0 -890
  88. package/packages/selector/src/invariant.ts +0 -113
  89. package/packages/selector/src/preset-overlay.ts +0 -749
  90. package/packages/selector/src/profiles.ts +0 -431
  91. package/packages/selector/src/pruner/content.ts +0 -198
  92. package/packages/selector/src/pruner/session.ts +0 -97
  93. package/packages/selector/src/pruner/state.ts +0 -61
  94. package/packages/selector/src/pruner/tuning.ts +0 -23
  95. package/packages/selector/src/pruner/types.ts +0 -78
  96. package/packages/selector/src/pruner.ts +0 -2914
  97. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  98. package/packages/selector/src/runtime/audit.ts +0 -320
  99. package/packages/selector/src/runtime/config.ts +0 -756
  100. package/packages/selector/src/runtime/custom-policy.ts +0 -278
  101. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  102. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  103. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  104. package/packages/selector/src/runtime/measurement.ts +0 -444
  105. package/packages/selector/src/runtime/monitor.ts +0 -310
  106. package/packages/selector/src/runtime/panel-command.ts +0 -213
  107. package/packages/selector/src/runtime/reducers.ts +0 -1754
  108. package/packages/selector/src/runtime/retrieve.ts +0 -503
  109. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  110. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  111. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  112. package/packages/selector/src/runtime/savings.ts +0 -526
  113. package/packages/selector/src/runtime/session-events.ts +0 -30
  114. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  115. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  116. package/packages/selector/src/runtime/stats-db.ts +0 -492
  117. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  118. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  119. package/packages/selector/src/runtime/summary-command.ts +0 -127
  120. package/packages/selector/src/runtime/tail-trim.ts +0 -176
  121. package/packages/selector/src/runtime/token-count.ts +0 -72
  122. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  123. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  124. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  125. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  126. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
  127. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  128. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  129. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  130. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  131. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  132. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -128
  133. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  134. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  135. package/packages/selector/src/runtime/toolclass.ts +0 -103
  136. package/packages/selector/src/runtime/types.ts +0 -365
  137. package/packages/selector/src/runtime/value.ts +0 -48
  138. package/packages/selector/src/settings-bridge.ts +0 -175
  139. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  140. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  141. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  142. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  143. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  144. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  145. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  146. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  147. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  148. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  149. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  150. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  151. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  152. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  153. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  154. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  155. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  156. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -220
  157. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  158. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  159. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  160. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  161. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
  162. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  163. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  164. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  165. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  166. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  167. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  168. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  169. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  170. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  171. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  172. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  173. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  174. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  175. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  176. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  177. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  178. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  179. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  180. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  181. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  182. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  183. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  184. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  185. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  186. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  187. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  188. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2781
  189. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  190. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  191. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  192. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  193. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  194. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  195. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  196. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  197. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  198. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  199. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  200. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  201. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -348
  202. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  203. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  204. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  205. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  206. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  207. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  208. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  209. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  210. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  211. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  212. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
  213. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  214. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  215. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  216. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  217. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  218. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  219. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  220. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  221. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  222. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  223. package/packages/selector/tsconfig.json +0 -11
  224. package/packages/selector/tsdown.client.config.ts +0 -102
  225. package/packages/selector/tsdown.config.ts +0 -20
  226. package/pnpm-workspace.yaml +0 -76
  227. package/scripts/capture-profile-baseline.mjs +0 -42
  228. package/scripts/cell-browser-e2e.mjs +0 -354
  229. package/scripts/generate-tokenizer-fixtures.py +0 -81
  230. package/scripts/generate-vision-fixtures.py +0 -208
  231. package/scripts/hosts.mjs +0 -78
  232. package/scripts/packed-components-smoke.mjs +0 -763
  233. package/scripts/packed-install-e2e.mjs +0 -1346
  234. package/scripts/sync-hosts.mjs +0 -174
  235. package/scripts/toolclass-corpus-replay.mjs +0 -281
  236. package/scripts/verify-release.mjs +0 -338
  237. package/tests/TEST_INVENTORY.md +0 -41
  238. package/tsconfig.base.json +0 -18
  239. package/tsconfig.json +0 -7
  240. package/tsconfig.tests.json +0 -15
  241. package/vitest.built.config.ts +0 -9
  242. package/vitest.config.ts +0 -54
  243. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  244. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  245. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  246. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  247. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  248. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  249. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  250. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  251. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  252. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  253. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  254. /package/{packages/selector/lib → lib}/index.js +0 -0
  255. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  256. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  257. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  258. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  259. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  260. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  261. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  262. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
@@ -1,85 +0,0 @@
1
- /**
2
- * CompressionProfileSelector — thin re-export hub.
3
- *
4
- * Component implementations now live in dedicated modules to keep the
5
- * god-module under control. This file preserves the public API surface so
6
- * existing consumers see no change.
7
- *
8
- * @module dsh-context-compression-improved/client/CompressionProfileSelector
9
- */
10
-
11
- import type { SettingsScope } from './scope-face.ts'
12
- import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
13
- import {
14
- COMPRESSION_PROFILES,
15
- isCustomCompressionPolicy,
16
- type CompressionProfile,
17
- type CustomCompressionPolicy,
18
- type ContextCompressionSettings,
19
- type PresetOptionsSettings,
20
- } from '../profiles.ts'
21
-
22
- export { COMPRESSION_PROFILES, isCustomCompressionPolicy }
23
- export type { CompressionProfile, CustomCompressionPolicy, ContextCompressionSettings, PresetOptionsSettings }
24
-
25
- export interface CompressionSelectorInjected {
26
- hooks: { compression: SettingsScope<ContextCompressionSettings> }
27
- select: (profile: CompressionProfile) => Promise<void>
28
- saveCustom: (custom: CustomCompressionPolicy) => Promise<void>
29
- resetCustom: () => Promise<void>
30
- saveAutoCompact: (thresholdPercent: number) => Promise<void>
31
- saveCodeSkeleton: (enabled: boolean) => Promise<void>
32
- saveIntentSummary: (enabled: boolean) => Promise<void>
33
- saveMonitorPanel: (enabled: boolean) => Promise<void>
34
- /** Patch of `presetOptions` members; an explicit `undefined` clears that field. */
35
- savePresetOptions: (options: import('./preset-options.ts').PresetOptionsPatch) => Promise<void>
36
- }
37
-
38
- /**
39
- * Owner-agnostic panel props: the same component registers under the 0.1.5
40
- * `settings.plugins.tab` card (no owner props) and the legacy
41
- * `settings.section` page (whose shell supplies `close`), so the section
42
- * owner share stays optional.
43
- */
44
- export type CompressionProfileSelectorProps =
45
- { close?: () => void }
46
- & PropsLocale<'context-compression'>
47
- & InjectFace<CompressionSelectorInjected>
48
-
49
- // Re-export sub-components from dedicated modules.
50
- export {
51
- ContextCompressionSettingsSection,
52
- SettingsCompressionProfileControls,
53
- } from './settings-section.tsx'
54
-
55
- export {
56
- CompressionProfileControls,
57
- AutoCompactThresholdControls,
58
- CodeSkeletonControls,
59
- } from './CompressionProfileControls.tsx'
60
-
61
- export {
62
- EstimatorControls,
63
- } from './EstimatorControls.tsx'
64
-
65
- export {
66
- CustomPolicyEditor,
67
- StageFields,
68
- editableCustom,
69
- } from './CustomPolicyEditor.tsx'
70
-
71
- // Imported for the wrapper component below; re-exported above.
72
- import { CompressionProfileControls } from './CompressionProfileControls.tsx'
73
-
74
- /** Full-page Settings surface backed by the same durable selector state. */
75
- export function CompressionProfileSelector({
76
- ...props
77
- }: CompressionProfileSelectorProps) {
78
- return <CompressionProfileControls {...props} showCustomEditor={false} />
79
- }
80
-
81
- declare module '@deepseek-ai/dsh-client-ui-slots' {
82
- interface LocaleNamespaceMap {
83
- 'context-compression': import('./locales.ts').ContextCompressionLocaleKey
84
- }
85
- }
@@ -1,216 +0,0 @@
1
- /**
2
- * CustomPolicyEditor: full custom compression policy editor with StageFields.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/CustomPolicyEditor
7
- */
8
-
9
- import type { ContextCompressionLocaleKey } from './locales.ts'
10
- import css from './CompressionProfileSelector.module.css'
11
- import {
12
- isCustomCompressionPolicy,
13
- type CustomCompressionBudget,
14
- type CustomCompressionPolicy,
15
- type CustomCompressionPolicyV3,
16
- type CustomHistoryPolicy,
17
- } from '../profiles.ts'
18
-
19
- interface CustomPolicyEditorProps {
20
- value: CustomCompressionPolicyV3
21
- disabled: boolean
22
- setValue: (value: CustomCompressionPolicyV3) => void
23
- save: () => Promise<void>
24
- reset: () => Promise<void>
25
- settle: (operation: () => Promise<void>) => void
26
- t: (key: ContextCompressionLocaleKey) => string
27
- }
28
-
29
- export function CustomPolicyEditor({ value, disabled, setValue, save, reset, settle, t }: CustomPolicyEditorProps) {
30
- const valid = isCustomCompressionPolicy(value)
31
- const unitStep = value.unit === 'tokens' ? 1 : 0.01
32
- const unitMax = value.unit === 'tokens' ? undefined : 100
33
- const unitBounds = unitMax === undefined ? {} : { max: unitMax }
34
- const setBudget = (
35
- stage: 'fresh' | 'aggregate',
36
- patch: Partial<CustomCompressionBudget>,
37
- ): void => {
38
- setValue({ ...value, [stage]: { ...value[stage], ...patch } })
39
- }
40
- const setHistory = (patch: Partial<CustomHistoryPolicy>): void => {
41
- setValue({ ...value, history: { ...value.history, ...patch } })
42
- }
43
- return (
44
- <section className={css.custom} aria-labelledby="context-compression-custom-title">
45
- <h3 id="context-compression-custom-title" className={css.customTitle}>{t('custom.title')}</h3>
46
- <p className={css.customNote}>{t('custom.sessionScope')}</p>
47
- <p className={css.customNote}>{t('custom.measurement')}</p>
48
- <label className={css.field}>
49
- <span>{t('custom.unit')}</span>
50
- <select
51
- value={value.unit}
52
- disabled={disabled}
53
- onChange={(event) => {
54
- setValue({
55
- ...value,
56
- unit: event.currentTarget.value as CustomCompressionPolicy['unit'],
57
- })
58
- }}
59
- >
60
- <option value="tokens">{t('custom.unit.tokens')}</option>
61
- <option value="context-percent">{t('custom.unit.contextPercent')}</option>
62
- </select>
63
- </label>
64
- <StageFields
65
- t={t}
66
- title={t('custom.fresh.enabled')}
67
- enabled={value.fresh.enabled}
68
- disabled={disabled}
69
- onEnabled={(enabled) => { setBudget('fresh', { enabled }) }}
70
- fields={[
71
- { label: t('custom.fresh.trigger'), value: value.fresh.trigger, set: (trigger) => { setBudget('fresh', { trigger }) }, ...unitBounds },
72
- { label: t('custom.fresh.target'), value: value.fresh.target, set: (target) => { setBudget('fresh', { target }) }, ...unitBounds },
73
- ]}
74
- step={unitStep}
75
- />
76
- <StageFields
77
- t={t}
78
- title={t('custom.aggregate.enabled')}
79
- enabled={value.aggregate.enabled}
80
- disabled={disabled}
81
- onEnabled={(enabled) => { setBudget('aggregate', { enabled }) }}
82
- fields={[
83
- { label: t('custom.aggregate.trigger'), value: value.aggregate.trigger, set: (trigger) => { setBudget('aggregate', { trigger }) }, ...unitBounds },
84
- { label: t('custom.aggregate.target'), value: value.aggregate.target, set: (target) => { setBudget('aggregate', { target }) }, ...unitBounds },
85
- ]}
86
- step={unitStep}
87
- />
88
- <StageFields
89
- t={t}
90
- title={t('custom.history.enabled')}
91
- enabled={value.history.enabled}
92
- disabled={disabled}
93
- onEnabled={(enabled) => { setHistory({ enabled }) }}
94
- fields={[
95
- { label: t('custom.history.trigger'), value: value.history.trigger, set: (trigger) => { setHistory({ trigger }) }, ...unitBounds },
96
- { label: t('custom.history.keepRecentToolCalls'), value: value.history.keepRecentToolCalls, set: (keepRecentToolCalls) => { setHistory({ keepRecentToolCalls }) }, integer: true, allowZero: true },
97
- { label: t('custom.history.keepRecentTokens'), value: value.history.keepRecentTokens, set: (keepRecentTokens) => { setHistory({ keepRecentTokens }) }, allowZero: true, ...unitBounds },
98
- { label: t('custom.history.minReclaim'), value: value.history.minReclaim, set: (minReclaim) => { setHistory({ minReclaim }) }, ...unitBounds },
99
- ]}
100
- step={unitStep}
101
- fieldsEnabled={value.history.enabled || value.tailTrim.enabled}
102
- />
103
- <label className={css.field}>
104
- <span>{t('custom.prefixPolicy')}</span>
105
- <select
106
- value={value.prefixPolicy}
107
- disabled={disabled || !value.history.enabled}
108
- onChange={(event) => {
109
- setValue({
110
- ...value,
111
- prefixPolicy: event.currentTarget.value as CustomCompressionPolicy['prefixPolicy'],
112
- })
113
- }}
114
- >
115
- <option value="preserve">{t('custom.prefixPolicy.preserve')}</option>
116
- <option value="pressure-break">{t('custom.prefixPolicy.pressureBreak')}</option>
117
- </select>
118
- </label>
119
- <div className={css.customNote}>{t('custom.experimental')}</div>
120
- <StageFields
121
- t={t}
122
- title={t('custom.tailTrim.enabled')}
123
- enabled={value.tailTrim.enabled}
124
- disabled={disabled}
125
- onEnabled={(enabled) => {
126
- setValue({ ...value, tailTrim: { ...value.tailTrim, enabled } })
127
- }}
128
- fields={[{
129
- label: t('custom.tailTrim.trigger'),
130
- value: value.tailTrim.trigger,
131
- set: (trigger) => {
132
- setValue({ ...value, tailTrim: { ...value.tailTrim, trigger } })
133
- },
134
- ...unitBounds,
135
- }]}
136
- step={unitStep}
137
- />
138
- <p className={css.customNote}>{t('custom.tailTrim.warning')}</p>
139
- {valid ? null : <div className={css.error} role="alert">{t('custom.invalid')}</div>}
140
- <div className={css.actions}>
141
- <button type="button" disabled={disabled || !valid} onClick={() => { settle(save) }}>{t('custom.save')}</button>
142
- <button type="button" disabled={disabled} onClick={() => { settle(reset) }}>{t('custom.reset')}</button>
143
- </div>
144
- </section>
145
- )
146
- }
147
-
148
- interface StageNumberField {
149
- label: string
150
- value: number
151
- set: (value: number) => void
152
- integer?: boolean
153
- allowZero?: boolean
154
- max?: number
155
- }
156
-
157
- export function StageFields({ title, enabled, disabled, onEnabled, fields, step, fieldsEnabled = enabled, t }: {
158
- title: string
159
- enabled: boolean
160
- disabled: boolean
161
- onEnabled: (enabled: boolean) => void
162
- fields: readonly StageNumberField[]
163
- step: number
164
- fieldsEnabled?: boolean
165
- t: (key: ContextCompressionLocaleKey) => string
166
- }) {
167
- return (
168
- <fieldset className={css.stage} disabled={disabled}>
169
- <legend>{title}</legend>
170
- <label className={css.field}>
171
- <span>{t('custom.enabled')}</span>
172
- <select aria-label={title} value={enabled ? 'on' : 'off'}
173
- onChange={(event) => { onEnabled(event.currentTarget.value === 'on') }}>
174
- <option value="on">{t('custom.enabled.on')}</option>
175
- <option value="off">{t('custom.enabled.off')}</option>
176
- </select>
177
- </label>
178
- <div className={css.fieldGrid}>
179
- {fields.map(field => (
180
- <label className={css.field} key={field.label}>
181
- <span>{field.label}</span>
182
- <input
183
- type="number"
184
- value={field.value}
185
- min={field.allowZero === true ? 0 : field.integer === true ? 1 : step}
186
- max={field.max}
187
- step={field.integer === true ? 1 : step}
188
- disabled={!fieldsEnabled || disabled}
189
- onChange={(event) => { field.set(Number(event.currentTarget.value)) }}
190
- />
191
- </label>
192
- ))}
193
- </div>
194
- </fieldset>
195
- )
196
- }
197
-
198
- /** Convert a legacy custom policy to V3 format. */
199
- export function editableCustom(value: CustomCompressionPolicy): CustomCompressionPolicyV3 {
200
- if (value.version === 3) return structuredClone(value)
201
- return {
202
- version: 3,
203
- unit: value.unit,
204
- fresh: structuredClone(value.fresh),
205
- aggregate: structuredClone(value.aggregate),
206
- history: {
207
- enabled: value.history.enabled,
208
- trigger: value.history.trigger,
209
- keepRecentToolCalls: 10,
210
- keepRecentTokens: value.history.keepRecent,
211
- minReclaim: value.history.minReclaim,
212
- },
213
- prefixPolicy: value.prefixPolicy,
214
- tailTrim: value.version === 1 ? { enabled: false, trigger: 700_000 } : structuredClone(value.tailTrim),
215
- }
216
- }
@@ -1,277 +0,0 @@
1
- /**
2
- * TokenPilot-inspired estimator channel card components.
3
- *
4
- * Extracted from CompressionProfileSelector.tsx to reduce god-module size.
5
- *
6
- * @module dsh-context-compression-improved/client/EstimatorControls
7
- */
8
-
9
- import { useEffect, useState } from 'react'
10
- import type { ContextCompressionLocaleKey } from './locales.ts'
11
- import type { PresetOptionsPatch } from './preset-options.ts'
12
- import type { PresetOptionsSettings } from '../profiles.ts'
13
- import css from './CompressionProfileSelector.module.css'
14
-
15
- interface EstimatorControlsProps {
16
- options: PresetOptionsSettings
17
- disabled: boolean
18
- save: (options: PresetOptionsPatch) => Promise<void>
19
- settle: (operation: () => Promise<void>) => void
20
- t: (key: ContextCompressionLocaleKey) => string
21
- }
22
-
23
- interface EstimatorInactiveNoticeProps {
24
- /** Already-localized label of the profile that currently owns the selector. */
25
- profile: string
26
- t: (key: ContextCompressionLocaleKey) => string
27
- }
28
-
29
- /**
30
- * The estimator card is gated on the tokenpilot-inspired profile, because
31
- * `presetOptions` is merged into that profile alone. A card that merely
32
- * disappears reads as a missing feature — the first real-machine report was
33
- * exactly that — so keep the heading and its anchor id in place and spend them
34
- * on the reason plus the profile that unlocks the card. The gate itself is
35
- * unchanged: no estimator control exists outside tokenpilot-inspired.
36
- *
37
- * Exported from the estimator card's own module so the gated card and its
38
- * explanation cannot drift apart.
39
- */
40
- export function EstimatorInactiveNotice({ profile, t }: EstimatorInactiveNoticeProps) {
41
- return (
42
- <section className={css.autoCompact} aria-labelledby="context-compression-estimator-title">
43
- <h3 id="context-compression-estimator-title" className={css.autoCompactTitle}>{t('estimator.title')}</h3>
44
- <p className={css.customNote}>{t('estimator.inactive').replace('{profile}', profile)}</p>
45
- </section>
46
- )
47
- }
48
-
49
- interface CatalogModelEntry { readonly id: string, readonly name: string }
50
- interface CatalogProviderEntry { readonly id: string, readonly name: string, readonly models: readonly CatalogModelEntry[], readonly error?: string }
51
- interface EstimatorCatalogBody {
52
- readonly ok?: boolean
53
- readonly providers?: readonly CatalogProviderEntry[]
54
- readonly selection?: { readonly provider: string, readonly model: string }
55
- }
56
-
57
- const ESTIMATOR_CATALOG_ROUTE = '/api/dsh-context-compression-improved/estimator-catalog'
58
-
59
- /**
60
- * TokenPilot-inspired estimator channel card. Shown only while the
61
- * tokenpilot-inspired profile is selected, and split by channel:
62
- *
63
- * - `host` reuses the providers and credentials the user already configured in
64
- * DSH through the Harness `llm` service, so this card names a provider and a
65
- * model and accepts NO API key — the key field belongs to the direct channel
66
- * alone.
67
- * - `direct` talks to a native OpenAI-compatible endpoint, which is the only
68
- * channel that carries its own base URL and write-only key.
69
- *
70
- * The whole card is advisory: an unconfigured or failing endpoint keeps every
71
- * consumer on its rule-only fallback.
72
- */
73
- export function EstimatorControls({ options, disabled, save, settle, t }: EstimatorControlsProps) {
74
- const [keyDraft, setKeyDraft] = useState('')
75
- const [baseUrl, setBaseUrl] = useState(options.estimatorBaseUrl ?? '')
76
- const [model, setModel] = useState(options.estimatorModel ?? '')
77
- const [provider, setProvider] = useState(options.estimatorProvider ?? '')
78
- const mode = options.estimatorMode ?? ''
79
- // Host-mode dropdown source: the live provider/model-group catalog served by
80
- // the Bundle entry's estimator-catalog route (dsh-perm-gate receiver
81
- // pattern). The provider/model fields are always comboboxes: an empty
82
- // catalog (route missing / llm service absent) simply offers no suggestions
83
- // while custom typing keeps working, so nothing breaks on hosts without the
84
- // webServer.
85
- const [catalog, setCatalog] = useState<EstimatorCatalogBody | undefined>()
86
- useEffect(() => {
87
- if (mode !== 'host') return
88
- let alive = true
89
- // The catalog route answers once the host webServer/llm services are up;
90
- // poll briefly so the dropdowns fill without reopening the panel.
91
- let attempts = 0
92
- const load = async (): Promise<EstimatorCatalogBody | undefined> => {
93
- try {
94
- const response = await fetch(ESTIMATOR_CATALOG_ROUTE, { headers: { 'cache-control': 'no-cache' } })
95
- return response.ok ? (await response.json()) as EstimatorCatalogBody : undefined
96
- } catch {
97
- return undefined
98
- }
99
- }
100
- const tick = (): void => {
101
- attempts += 1
102
- void load().then((body) => {
103
- if (!alive) return
104
- if (body !== undefined && (body.providers?.length ?? 0) > 0) {
105
- setCatalog(body)
106
- return
107
- }
108
- if (attempts < 10) setTimeout(tick, 3_000)
109
- })
110
- }
111
- tick()
112
- return () => { alive = false }
113
- }, [mode])
114
- const hostProviders = catalog?.providers ?? []
115
- // Model suggestions follow the provider draft exactly like dsh-perm-gate's
116
- // receiver card: an empty provider lists every group's models, a chosen
117
- // provider narrows to its own. The provider error (if any) rides along in
118
- // the option label so a broken group is visible without blocking typing.
119
- const providerDraft = provider
120
- const hostModels = hostProviders
121
- .filter(entry => providerDraft === '' || entry.id === providerDraft)
122
- .flatMap(entry => entry.models.map(model => ({ ...model, provider: entry.id })))
123
- const hostProvider = hostProviders.find(entry => entry.id === providerDraft)
124
- ?? hostProviders.find(entry => entry.id === (options.estimatorProvider ?? ''))
125
- const hasKey = (options.estimatorApiKey ?? '') !== ''
126
- const commit = (patch: PresetOptionsPatch) => {
127
- settle(() => save(patch))
128
- }
129
- // What the host channel would actually call right now: an explicit override
130
- // wins, otherwise the session default the catalog reports. Naming the
131
- // resolved route is the whole point of this channel — the user re-enters
132
- // nothing the Harness already knows.
133
- const overrideProvider = options.estimatorProvider ?? ''
134
- const overrideModel = options.estimatorModel ?? ''
135
- const effectiveProvider = overrideProvider !== '' ? overrideProvider : catalog?.selection?.provider ?? ''
136
- const effectiveModel = overrideModel !== '' ? overrideModel : catalog?.selection?.model ?? ''
137
- const effectiveRoute = effectiveProvider !== '' && effectiveModel !== ''
138
- ? `${effectiveProvider} / ${effectiveModel}`
139
- : t('estimator.hostUnresolved')
140
- return (
141
- <section className={css.autoCompact} aria-labelledby="context-compression-estimator-title">
142
- <h3 id="context-compression-estimator-title" className={css.autoCompactTitle}>{t('estimator.title')}</h3>
143
- <p className={css.customNote}>{t('estimator.description')}</p>
144
- <label className={css.field}>
145
- <span>{t('estimator.mode')}</span>
146
- <select
147
- value={mode}
148
- disabled={disabled}
149
- onChange={(event) => { settle(() => save({ estimatorMode: event.currentTarget.value as '' | 'host' | 'direct' })) }}
150
- >
151
- <option value="">{t('estimator.mode.off')}</option>
152
- <option value="host">{t('estimator.mode.host')}</option>
153
- <option value="direct">{t('estimator.mode.direct')}</option>
154
- </select>
155
- </label>
156
- {mode === '' ? null : mode === 'host' ? (
157
- <>
158
- <label className={css.field}>
159
- <span>{t('estimator.provider')}</span>
160
- <input
161
- type="text"
162
- list="estimator-provider-options"
163
- value={provider}
164
- disabled={disabled}
165
- placeholder={t('estimator.provider.placeholder')}
166
- onChange={(event) => {
167
- const next = event.currentTarget.value
168
- setProvider(next)
169
- // Picking from the datalist fires change without blur: commit
170
- // an exact catalog hit immediately; free typing waits for blur
171
- // so mid-edit keystrokes never disable the panel.
172
- if (next !== '' && hostProviders.some(entry => entry.id === next)) {
173
- commit({ estimatorProvider: next })
174
- }
175
- }}
176
- onBlur={() => { if (provider !== (options.estimatorProvider ?? '')) commit({ estimatorProvider: provider }) }}
177
- />
178
- </label>
179
- {/* Datalists ride outside the labels on purpose: option text inside a
180
- label would leak into its accessible name. */}
181
- <datalist id="estimator-provider-options">
182
- {hostProviders.map(entry => (
183
- <option key={entry.id} value={entry.id}>
184
- {entry.name === '' ? entry.id : entry.name}{entry.error === undefined ? '' : ` (${entry.error})`}
185
- </option>
186
- ))}
187
- </datalist>
188
- <label className={css.field}>
189
- <span>{t('estimator.model')}</span>
190
- <input
191
- type="text"
192
- list="estimator-model-options"
193
- value={model}
194
- disabled={disabled}
195
- placeholder={t('estimator.model.placeholder')}
196
- onChange={(event) => {
197
- const next = event.currentTarget.value
198
- setModel(next)
199
- if (next !== '' && hostModels.some(entry => entry.id === next)) {
200
- commit({ estimatorModel: next })
201
- }
202
- }}
203
- onBlur={() => { if (model !== (options.estimatorModel ?? '')) commit({ estimatorModel: model }) }}
204
- />
205
- </label>
206
- <datalist id="estimator-model-options">
207
- {hostModels.map(entry => (
208
- <option key={`${entry.provider}\0${entry.id}`} value={entry.id}>{entry.name}</option>
209
- ))}
210
- </datalist>
211
- {hostProvider?.error === undefined ? null : (
212
- <p className={css.customNote}>{String(hostProvider.error)}</p>
213
- )}
214
- <p className={css.customNote}>{t('estimator.hostReuse')}</p>
215
- <p className={css.customNote}>{t('estimator.hostRoute').replace('{route}', effectiveRoute)}</p>
216
- </>
217
- ) : (
218
- <>
219
- <label className={css.field}>
220
- <span>{t('estimator.baseUrl')}</span>
221
- <input
222
- type="text"
223
- value={baseUrl}
224
- disabled={disabled}
225
- placeholder="https://127.0.0.1:8000/v1"
226
- onChange={(event) => { setBaseUrl(event.currentTarget.value) }}
227
- onBlur={() => { if (baseUrl !== (options.estimatorBaseUrl ?? '')) commit({ estimatorBaseUrl: baseUrl }) }}
228
- />
229
- </label>
230
- <label className={css.field}>
231
- <span>{t('estimator.model')}</span>
232
- <input
233
- type="text"
234
- value={model}
235
- disabled={disabled}
236
- onChange={(event) => { setModel(event.currentTarget.value) }}
237
- onBlur={() => { if (model !== (options.estimatorModel ?? '')) commit({ estimatorModel: model }) }}
238
- />
239
- </label>
240
- <label className={css.field}>
241
- <span>{t('estimator.apiKey')}</span>
242
- <div style={{ display: 'flex', gap: '6px' }}>
243
- <input
244
- type="password"
245
- autoComplete="off"
246
- spellCheck={false}
247
- value={keyDraft}
248
- disabled={disabled}
249
- placeholder={hasKey ? t('estimator.apiKey.set') : t('estimator.apiKey.placeholder')}
250
- onChange={(event) => { setKeyDraft(event.currentTarget.value) }}
251
- onBlur={() => {
252
- const next = keyDraft.trim()
253
- if (next === '') return
254
- settle(() => save({ estimatorApiKey: next }))
255
- setKeyDraft('')
256
- }}
257
- onKeyDown={(event) => {
258
- if (event.key === 'Enter') event.currentTarget.blur()
259
- }}
260
- />
261
- {hasKey ? (
262
- <button
263
- type="button"
264
- disabled={disabled}
265
- onClick={() => { settle(() => save({ estimatorApiKey: undefined })) }}
266
- >
267
- {t('estimator.apiKey.clear')}
268
- </button>
269
- ) : null}
270
- </div>
271
- {hasKey ? <span className={css.customNote}>{t('estimator.apiKey.overwrite')}</span> : null}
272
- </label>
273
- </>
274
- )}
275
- </section>
276
- )
277
- }