dsh-context-compression-improved 0.8.0 → 0.9.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/.gitattributes +2 -2
- package/.githooks/pre-push +37 -37
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.de.md +41 -0
- package/CHANGELOG.es.md +41 -0
- package/CHANGELOG.fr.md +42 -0
- package/CHANGELOG.it.md +41 -0
- package/CHANGELOG.ja.md +35 -0
- package/CHANGELOG.ko.md +34 -0
- package/CHANGELOG.md +40 -0
- package/CHANGELOG.ru.md +37 -0
- package/CHANGELOG.zh.md +32 -0
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +21 -21
- package/README.de.md +7 -9
- package/README.es.md +7 -9
- package/README.fr.md +7 -9
- package/README.it.md +7 -9
- package/README.ja.md +6 -2
- package/README.ko.md +6 -2
- package/README.md +96 -98
- package/README.ru.md +7 -9
- package/README.zh.md +89 -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.de.md +5 -5
- package/docs/installation.es.md +5 -5
- package/docs/installation.fr.md +5 -5
- package/docs/installation.it.md +5 -5
- package/docs/installation.ja.md +5 -5
- package/docs/installation.ko.md +5 -5
- package/docs/installation.md +5 -5
- package/docs/installation.ru.md +5 -5
- package/docs/installation.zh.md +5 -5
- package/docs/repair-log.md +657 -657
- package/package.json +23 -22
- 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.js +178 -21
- package/packages/selector/lib/host-generation.js +62 -0
- package/packages/selector/lib/index.js +208 -1
- package/packages/selector/lib/invariant.js +1 -1
- package/packages/selector/lib/pruner.js +41 -43
- package/packages/selector/lib/style.css +53 -53
- package/packages/selector/lib/tail-trim.js +73 -4
- package/packages/selector/package.json +80 -21
- package/packages/selector/screenshots.json +3 -3
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
- package/packages/selector/src/client/EstimatorControls.tsx +277 -277
- package/packages/selector/src/client/bridge-scope.ts +125 -0
- package/packages/selector/src/client/index.ts +109 -31
- package/packages/selector/src/client/monitor-fab.ts +0 -2
- package/packages/selector/src/client/preset-options.ts +88 -88
- package/packages/selector/src/client/scope-face.ts +24 -24
- package/packages/selector/src/compat/host-generation.ts +96 -0
- package/packages/selector/src/compat/settings-lease.ts +108 -0
- package/packages/selector/src/compat/tool-result.ts +91 -0
- 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 +8 -0
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +626 -626
- package/packages/selector/src/pruner/content.ts +198 -198
- package/packages/selector/src/pruner/session.ts +97 -96
- package/packages/selector/src/pruner/tuning.ts +23 -23
- package/packages/selector/src/pruner/types.ts +78 -78
- package/packages/selector/src/pruner.ts +45 -40
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
- 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 +431 -431
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/retrieve.ts +7 -3
- package/packages/selector/src/runtime/session-events.ts +30 -30
- package/packages/selector/src/runtime/tail-trim.ts +175 -165
- package/packages/selector/src/runtime/token-count.ts +72 -72
- 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/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/value.ts +48 -48
- package/packages/selector/src/settings-bridge.ts +175 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
- package/packages/selector/tests/built/client-artifact.spec.ts +6 -9
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +98 -94
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
- package/packages/selector/tests/custom-contract.client.spec.ts +226 -223
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +199 -194
- package/packages/selector/tests/helpers/legacy-namespace.ts +35 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
- package/packages/selector/tests/preset-options-write.client.spec.ts +192 -188
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
- package/packages/selector/tests/public/package-contract.client.spec.ts +11 -3
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
- 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/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/line-mapping.spec.ts +153 -153
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +3 -3
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
- 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/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 +45 -7
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -269
- 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/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/hosts.mjs +74 -0
- package/scripts/packed-components-smoke.mjs +763 -732
- package/scripts/packed-install-e2e.mjs +1330 -1273
- package/scripts/sync-hosts.mjs +174 -0
- package/scripts/toolclass-corpus-replay.mjs +281 -281
- package/scripts/verify-release.mjs +335 -318
- 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 +46 -43
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge-backed settings scope — the default data plane on legacy hosts
|
|
3
|
+
* (0.1.0–0.1.5), where the client `settingsScope.bind` face never becomes
|
|
4
|
+
* ready (Gate 0: status "unavailable", writes rejected) and configForms does
|
|
5
|
+
* not exist. Speaks HTTP to the settings bridge route (settings-bridge.ts)
|
|
6
|
+
* and implements the same `SettingsScope` face the configForms scope builds,
|
|
7
|
+
* so the selector components stay generation-agnostic.
|
|
8
|
+
*
|
|
9
|
+
* Detection-free by design (audit P1-9): no property probing, no timeouts —
|
|
10
|
+
* the bridge works on every line, and on 0.1.7+ the configForms scoped
|
|
11
|
+
* sub-inject resolves and replaces this scope with the native one.
|
|
12
|
+
*/
|
|
13
|
+
import type { ScopeSnapshot, SettingsScope } from './scope-face.ts'
|
|
14
|
+
import { decodeSettings } from './decode.ts'
|
|
15
|
+
import type { ContextCompressionSettings } from './CompressionProfileSelector.tsx'
|
|
16
|
+
|
|
17
|
+
const SETTINGS_ROUTE = '/api/dsh-context-compression-improved/settings'
|
|
18
|
+
const POLL_MS = 4000
|
|
19
|
+
|
|
20
|
+
export interface BridgeScope extends SettingsScope<ContextCompressionSettings> {
|
|
21
|
+
/** Kick an immediate refresh (called once at apply). */
|
|
22
|
+
refresh(): void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createBridgeScope(): BridgeScope {
|
|
26
|
+
let snapshot: ScopeSnapshot<ContextCompressionSettings> = {
|
|
27
|
+
status: 'loading', value: undefined, revision: undefined,
|
|
28
|
+
writable: true, base: undefined, user: undefined, mode: 'host',
|
|
29
|
+
}
|
|
30
|
+
const listeners = new Set<() => void>()
|
|
31
|
+
let pollTimer: ReturnType<typeof setInterval> | undefined
|
|
32
|
+
|
|
33
|
+
const emit = () => { for (const listener of listeners) listener() }
|
|
34
|
+
|
|
35
|
+
const applyDoc = (doc: unknown, revision: number | undefined): void => {
|
|
36
|
+
const value = decodeSettings(doc)
|
|
37
|
+
const next: ScopeSnapshot<ContextCompressionSettings> = {
|
|
38
|
+
status: value === undefined ? 'unavailable' : 'ready',
|
|
39
|
+
value,
|
|
40
|
+
revision,
|
|
41
|
+
writable: true,
|
|
42
|
+
base: undefined,
|
|
43
|
+
user: undefined,
|
|
44
|
+
mode: 'host',
|
|
45
|
+
}
|
|
46
|
+
if (JSON.stringify(next) !== JSON.stringify(snapshot)) {
|
|
47
|
+
snapshot = next
|
|
48
|
+
emit()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function refresh(): Promise<void> {
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(SETTINGS_ROUTE, { headers: { 'cache-control': 'no-cache' } })
|
|
55
|
+
if (!response.ok) throw new Error(`settings bridge ${response.status}`)
|
|
56
|
+
const body = await response.json() as { doc?: unknown; revision?: number | null }
|
|
57
|
+
applyDoc(body.doc, body.revision ?? undefined)
|
|
58
|
+
} catch {
|
|
59
|
+
if (snapshot.status !== 'unavailable') {
|
|
60
|
+
snapshot = { ...snapshot, status: 'unavailable' }
|
|
61
|
+
emit()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function writeDoc(next: ContextCompressionSettings): Promise<boolean> {
|
|
67
|
+
const response = await fetch(SETTINGS_ROUTE, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: { 'content-type': 'application/json' },
|
|
70
|
+
body: JSON.stringify({ doc: next }),
|
|
71
|
+
})
|
|
72
|
+
if (!response.ok) return false
|
|
73
|
+
const body = await response.json() as { ok?: boolean; doc?: unknown }
|
|
74
|
+
if (body.ok !== true) return false
|
|
75
|
+
applyDoc(body.doc ?? next, (snapshot.revision ?? 0) + 1)
|
|
76
|
+
return true
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cloneDoc = (): ContextCompressionSettings => {
|
|
80
|
+
const value = snapshot.value
|
|
81
|
+
return (value === undefined ? {} : structuredClone(value)) as ContextCompressionSettings
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const scope: BridgeScope = {
|
|
85
|
+
getSnapshot: () => snapshot,
|
|
86
|
+
subscribe: (listener) => {
|
|
87
|
+
listeners.add(listener)
|
|
88
|
+
if (listeners.size === 1) {
|
|
89
|
+
void refresh()
|
|
90
|
+
pollTimer = setInterval(() => { void refresh() }, POLL_MS)
|
|
91
|
+
}
|
|
92
|
+
return () => {
|
|
93
|
+
listeners.delete(listener)
|
|
94
|
+
if (listeners.size === 0 && pollTimer !== undefined) {
|
|
95
|
+
clearInterval(pollTimer)
|
|
96
|
+
pollTimer = undefined
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
set: async (field, value) => {
|
|
101
|
+
const next = cloneDoc() as unknown as Record<string, unknown>
|
|
102
|
+
next[field] = value
|
|
103
|
+
return writeDoc(next as unknown as ContextCompressionSettings)
|
|
104
|
+
},
|
|
105
|
+
unset: async (field) => {
|
|
106
|
+
const next = cloneDoc() as unknown as Record<string, unknown>
|
|
107
|
+
delete next[field]
|
|
108
|
+
return writeDoc(next as unknown as ContextCompressionSettings)
|
|
109
|
+
},
|
|
110
|
+
mutate: async (ops) => {
|
|
111
|
+
const doc = cloneDoc() as unknown as Record<string, unknown>
|
|
112
|
+
for (const op of ops) {
|
|
113
|
+
const [head, key] = op.path as [string, string]
|
|
114
|
+
if (head !== 'presetOptions') return false
|
|
115
|
+
const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
|
|
116
|
+
if (op.op === 'unset') delete section[key]
|
|
117
|
+
else section[key] = (op as { value?: unknown }).value
|
|
118
|
+
doc.presetOptions = section
|
|
119
|
+
}
|
|
120
|
+
return writeDoc(doc as unknown as ContextCompressionSettings)
|
|
121
|
+
},
|
|
122
|
+
refresh: () => { void refresh() },
|
|
123
|
+
}
|
|
124
|
+
return scope
|
|
125
|
+
}
|
|
@@ -3,6 +3,7 @@ import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
|
3
3
|
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
4
4
|
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
5
5
|
import type {} from '@deepseek-ai/dsh-client-ui-workspace/client'
|
|
6
|
+
import { createElement, useSyncExternalStore } from 'react'
|
|
6
7
|
import {
|
|
7
8
|
isCustomCompressionPolicy,
|
|
8
9
|
ContextCompressionSettingsSection,
|
|
@@ -21,6 +22,7 @@ import { ko } from './locales/ko.ts'
|
|
|
21
22
|
import { ru } from './locales/ru.ts'
|
|
22
23
|
import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
|
|
23
24
|
import type { ScopeSnapshot, SettingsScope } from './scope-face.ts'
|
|
25
|
+
import { createBridgeScope } from './bridge-scope.ts'
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Harness 0.1.5 mounts the web core's `slots` service on the client context
|
|
@@ -40,13 +42,16 @@ declare module '@deepseek-ai/cordis' {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
45
|
+
// compat-legacy 单版本(audit B8,实跑实证):顶层 inject 只声明六线通用服务。
|
|
46
|
+
// 顶层放 `configForms` 会在 0.1.0–0.1.5 挂死激活(服务不存在),顶层放
|
|
47
|
+
// `settingsScope` 在 0.1.7-rc.1+ 同样挂死(0.1.7-rc.1 格 "waiting for service:
|
|
48
|
+
// settingsScope" 实证)。数据面选择改为双 scoped 臂:
|
|
49
|
+
// - 桥传输(bridge-scope.ts)为默认——全代际可用的 HTTP 面;
|
|
50
|
+
// - `configForms` scoped 臂在 0.1.7+ resolve 后把 scope 升级为原生
|
|
51
|
+
// configForms 路径(volatile entry 字段的权威写);
|
|
52
|
+
// - `settingsScope` 臂已裁撤:Gate 0 实测 0.1.5 的 bind scope 永远
|
|
53
|
+
// status:"unavailable"(写被拒),接了也是死代码。
|
|
54
|
+
export const inject = ['slots', 'locale']
|
|
50
55
|
const NS = 'context-compression'
|
|
51
56
|
|
|
52
57
|
/** 0.1.7: the profile entry whose config carries the compression settings doc. */
|
|
@@ -109,16 +114,20 @@ export function apply(ctx: ClientContext): void {
|
|
|
109
114
|
const localeSvc = ctx.locale as { bind?: (n: string) => (key: string) => string } | undefined
|
|
110
115
|
const tNav = localeSvc?.bind?.(NS) ?? ((key: string) => key)
|
|
111
116
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
/** Minimal configForms face (scoped sub-inject arm; 0.1.7+ hosts only). */
|
|
118
|
+
interface ConfigFormsHandle {
|
|
119
|
+
get(entryId: string): { getSnapshot(): { status: string; value?: { settings?: unknown }; revision?: number | null; writable?: boolean; base?: unknown; user?: unknown; mode?: string }; subscribe(listener: () => void): () => void; set(field: string, value: unknown): Promise<boolean> }
|
|
120
|
+
getSnapshot(): { status: string; value?: { settings?: unknown }; revision?: number | null; writable?: boolean; base?: unknown; user?: unknown; mode?: string }
|
|
121
|
+
subscribe(listener: () => void): () => void
|
|
122
|
+
set(field: string, value: unknown): Promise<boolean>
|
|
123
|
+
}
|
|
124
|
+
let configFormsHandle: ConfigFormsHandle | undefined
|
|
125
|
+
|
|
126
|
+
/** Last monitorPanel.enabled seen through whichever scope is current (FAB 读数缓存). */
|
|
127
|
+
let monitorPanelEnabledCache = false
|
|
128
|
+
|
|
129
|
+
/** 浮动监控面板(FAB): body 级幂等单例。enabled 读数走双臂 scope 的投影缓存。 */
|
|
130
|
+
let readMonitorPanelEnabled = (): boolean => monitorPanelEnabledCache
|
|
122
131
|
// 浮动面板会话绑定:跟随输入栏座位的 inject 回调(裸 sessionId,pm longtask 同款)。
|
|
123
132
|
let latestSessionId: string | undefined
|
|
124
133
|
try {
|
|
@@ -144,17 +153,39 @@ export function apply(ctx: ClientContext): void {
|
|
|
144
153
|
} catch (error) {
|
|
145
154
|
console.warn('[dsh-context-compression-improved] 监控浮动球挂载失败(不影响设置分节):', error)
|
|
146
155
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
// compat-legacy 双数据面(audit B8/Gate 0):
|
|
157
|
+
// 1) 桥 scope 立即建好并预热(全代际可用的 HTTP 面,apply 期即拉一次文档);
|
|
158
|
+
// 2) `configForms` scoped 臂在 0.1.7+ resolve 后接管为原生权威写路径。
|
|
159
|
+
// 选择发生在 injected() 工厂调用时(宿主渲染期),届时两臂归属已定,无竞态。
|
|
160
|
+
const bridgeScope = createBridgeScope()
|
|
161
|
+
bridgeScope.refresh()
|
|
162
|
+
const bridgeReadEnabled = (): boolean =>
|
|
163
|
+
decodeSettings(bridgeScope.getSnapshot().value)?.monitorPanel?.enabled ?? false
|
|
164
|
+
readMonitorPanelEnabled = (): boolean => (configFormsHandle === undefined ? bridgeReadEnabled() : monitorPanelEnabledCache)
|
|
165
|
+
try {
|
|
166
|
+
ctx.inject(['configForms'], (configFormsArg) => {
|
|
167
|
+
// cordis passes the service's OWNER CONTEXT to inject callbacks (the
|
|
168
|
+
// server-plane lease relies on the same convention: the service rides a
|
|
169
|
+
// property of the delivered ctx). Taking the argument itself made
|
|
170
|
+
// `get(ENTRY_ID)` a Context.get for an entry-shaped service name —
|
|
171
|
+
// undefined, then `form.getSnapshot()` crashed and the host's slot
|
|
172
|
+
// boundary abdicated the whole settings section (0.1.7 dead-cell,
|
|
173
|
+
// measured). Resolve the service off the context; fall back to the raw
|
|
174
|
+
// argument for test seams that hand the service directly.
|
|
175
|
+
const svc = (configFormsArg as { configForms?: unknown } | undefined)?.configForms
|
|
176
|
+
const face = (svc !== undefined && svc !== null ? svc : configFormsArg) as unknown as ConfigFormsHandle
|
|
177
|
+
configFormsHandle = typeof face?.get === 'function' ? face : undefined
|
|
178
|
+
})
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.warn('[dsh-context-compression-improved] configForms 臂挂载失败(桥面继续服务):', error)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** configForms 原生 scope(0.1.7+):volatile entry 字段权威写路径。 */
|
|
184
|
+
const scopeFromConfigForms = (service: ConfigFormsHandle): SettingsScope<ContextCompressionSettings> => {
|
|
185
|
+
// The arm receives the configForms SERVICE; the doc rides the entry form.
|
|
186
|
+
const form = service.get(ENTRY_ID) as unknown as ConfigFormsHandle
|
|
154
187
|
const readDoc = (): ContextCompressionSettings | undefined =>
|
|
155
188
|
decodeSettings(form.getSnapshot().value?.settings)
|
|
156
|
-
readMonitorPanelEnabled = (): boolean =>
|
|
157
|
-
decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false
|
|
158
189
|
// useSyncExternalStore requires a getSnapshot that returns a STABLE
|
|
159
190
|
// reference between changes — a fresh object per call is React error #185
|
|
160
191
|
// (maximum update depth exceeded). Cache the projection keyed on the form
|
|
@@ -165,21 +196,22 @@ export function apply(ctx: ClientContext): void {
|
|
|
165
196
|
status: 'loading', value: undefined, revision: undefined,
|
|
166
197
|
writable: false, base: undefined, user: undefined, mode: 'host',
|
|
167
198
|
}
|
|
168
|
-
|
|
199
|
+
return {
|
|
169
200
|
getSnapshot() {
|
|
170
201
|
const snap = form.getSnapshot()
|
|
171
202
|
if (snap !== projectedSource) {
|
|
172
203
|
projectedSource = snap
|
|
173
204
|
projected = {
|
|
174
|
-
status: snap.status,
|
|
205
|
+
status: (snap.status as ScopeSnapshot<ContextCompressionSettings>['status']) ?? 'loading',
|
|
175
206
|
value: decodeSettings(snap.value?.settings),
|
|
176
|
-
revision: snap.revision,
|
|
177
|
-
writable: snap.writable,
|
|
207
|
+
revision: snap.revision ?? undefined,
|
|
208
|
+
writable: snap.writable ?? false,
|
|
178
209
|
base: snap.base,
|
|
179
210
|
user: snap.user,
|
|
180
|
-
mode: snap.mode,
|
|
211
|
+
mode: (snap.mode as ScopeSnapshot<ContextCompressionSettings>['mode']) ?? 'host',
|
|
181
212
|
}
|
|
182
213
|
}
|
|
214
|
+
monitorPanelEnabledCache = projected.value?.monitorPanel?.enabled ?? false
|
|
183
215
|
return projected
|
|
184
216
|
},
|
|
185
217
|
subscribe: (listener) => form.subscribe(listener),
|
|
@@ -206,6 +238,21 @@ export function apply(ctx: ClientContext): void {
|
|
|
206
238
|
return form.set('settings', doc)
|
|
207
239
|
},
|
|
208
240
|
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const injected = (): CompressionSelectorInjected => {
|
|
244
|
+
// 双臂选择:configForms 臂已 resolve(0.1.7+)→ 原生 scope;否则桥 scope
|
|
245
|
+
// (0.1.0–0.1.5 的唯一活数据面,0.1.7+ resolve 前的过渡读也由它服务)。
|
|
246
|
+
// 臂构建失败(宿主面漂移、entry 未服务等)回落桥面,绝不把分节炸成死格
|
|
247
|
+
// —— 宿主槽边界的 abdicate 是整机退役,0.1.7 实测就是空白分节。
|
|
248
|
+
let scope: SettingsScope<ContextCompressionSettings> = bridgeScope
|
|
249
|
+
if (configFormsHandle !== undefined) {
|
|
250
|
+
try {
|
|
251
|
+
scope = scopeFromConfigForms(configFormsHandle)
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.warn('[dsh-context-compression-improved] configForms scope 构建失败(回落桥面):', error)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
209
256
|
const writeAndConfirm = async (
|
|
210
257
|
write: () => Promise<unknown>,
|
|
211
258
|
accepts: (settings: ContextCompressionSettings) => boolean,
|
|
@@ -300,6 +347,37 @@ export function apply(ctx: ClientContext): void {
|
|
|
300
347
|
} catch (error) {
|
|
301
348
|
console.warn('[dsh-context-compression-improved] conversation.input.left 注册失败(旧宿主无该槽,浮动面板保持聚合口径):', error)
|
|
302
349
|
}
|
|
350
|
+
|
|
351
|
+
// Bundle 详情页设置卡(0.1.7+):plugins.bundle.config keyed 槽,key=包名整卡平铺
|
|
352
|
+
// (searxng compat-legacy 蓝本)。实测契约(0.1.7-rc.1 真机格):
|
|
353
|
+
// ①不能用 entry.inject —— 这条渲染链不带 hookContext,宿主不会把 inject 返回的
|
|
354
|
+
// hooks.compression 映射成组件的 useCompression,组件首帧
|
|
355
|
+
// `useCompression is not a function` 崩进 SlotErrorBoundary → entry 被
|
|
356
|
+
// abdicate 成 data-slot-error 死格,且 abdication 本会话粘滞不再重试;
|
|
357
|
+
// ②locale: NS 必须保留 —— 它是宿主标准包 t(localeSeat)的唯一来源;
|
|
358
|
+
// ③组件闭包自取 injected(),并把 hooks.compression 手工适配成 useCompression
|
|
359
|
+
// (useSyncExternalStore 包装)。读写仍走 configForms 原生臂(宿主桥)。
|
|
360
|
+
// 老宿主无该槽 → 激活期抛错由 try/catch 吞掉,静默缺席。
|
|
361
|
+
try {
|
|
362
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
363
|
+
name: 'plugins.bundle.config',
|
|
364
|
+
key: 'dsh-context-compression-improved',
|
|
365
|
+
locale: NS,
|
|
366
|
+
}, (props: { close?: () => void }) => {
|
|
367
|
+
const inj = injected()
|
|
368
|
+
const scope = inj.hooks?.compression
|
|
369
|
+
const useCompression = <T,>(selector: (snapshot: ScopeSnapshot<ContextCompressionSettings>) => T): T => {
|
|
370
|
+
if (!scope) return selector({ status: 'loading', value: undefined, revision: undefined, writable: false, base: undefined, user: undefined, mode: 'memory' })
|
|
371
|
+
return useSyncExternalStore(
|
|
372
|
+
scope.subscribe,
|
|
373
|
+
() => selector(scope.getSnapshot()),
|
|
374
|
+
)
|
|
375
|
+
}
|
|
376
|
+
return createElement(ContextCompressionSettingsSection, { ...inj, ...props, useCompression } as never)
|
|
377
|
+
}))
|
|
378
|
+
} catch (error) {
|
|
379
|
+
console.warn('[dsh-context-compression-improved] plugins.bundle.config 注册失败(旧宿主无该槽,静默缺席):', error)
|
|
380
|
+
}
|
|
303
381
|
}
|
|
304
382
|
|
|
305
383
|
export type {
|
|
@@ -207,14 +207,12 @@ export function initMonitorFab(deps: MonitorFabDeps): void {
|
|
|
207
207
|
makeDrag(panel.querySelector('h4') as HTMLElement, 'panel');
|
|
208
208
|
|
|
209
209
|
// 状态与轮询
|
|
210
|
-
let last: MonitorSnapshotPayload | undefined;
|
|
211
210
|
let stale = false;
|
|
212
211
|
let busyAction = false;
|
|
213
212
|
|
|
214
213
|
const fmtTokens = (n: unknown): string => num(n).toLocaleString('en-US');
|
|
215
214
|
|
|
216
215
|
const render = (snap: MonitorSnapshotPayload): void => {
|
|
217
|
-
last = snap;
|
|
218
216
|
const net = num(snap.net?.exact) + num(snap.net?.estimated);
|
|
219
217
|
const netEl = panel.querySelector('[data-net]') as HTMLElement;
|
|
220
218
|
netEl.textContent = `${fmtTokens(snap.net?.exact)}${num(snap.net?.estimated) > 0 ? ` (+${fmtTokens(snap.net?.estimated)} est)` : ''}`;
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Path-addressed writes for the `presetOptions` section of the
|
|
3
|
-
* context-compression settings namespace.
|
|
4
|
-
*
|
|
5
|
-
* The settings Host applies a `set` op AT its path, so a field write must name
|
|
6
|
-
* only the field it changes. Writing the whole section — `scope.set(
|
|
7
|
-
* 'presetOptions', patch)` — replaces the section root with the patch, which
|
|
8
|
-
* deleted every sibling field: choosing a provider after choosing a channel
|
|
9
|
-
* erased `estimatorMode` and silently turned the estimator back off, and the
|
|
10
|
-
* saved document kept exactly the last field the user touched.
|
|
11
|
-
*
|
|
12
|
-
* A patch member set to `undefined` means "clear this field" (the section then
|
|
13
|
-
* re-inherits the preset default) rather than "leave it alone"; absent members
|
|
14
|
-
* are untouched by construction.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type { SettingsPathOpView } from '@deepseek-ai/dsh-settings/types'
|
|
18
|
-
import type { PresetOptionsSettings } from '../profiles.ts'
|
|
19
|
-
|
|
20
|
-
/** The namespace key holding every tokenpilot-inspired sub-capability override. */
|
|
21
|
-
const PRESET_OPTIONS_KEY = 'presetOptions'
|
|
22
|
-
|
|
23
|
-
/** Every field a patch may address, in the schema's own order. The retired
|
|
24
|
-
* review-gate keys are deliberately absent: nothing writes them any more, and
|
|
25
|
-
* a stored document that still carries them is tolerated by the decoders. */
|
|
26
|
-
const PRESET_OPTION_KEYS = [
|
|
27
|
-
'dedupeToolResults', 'summaryLocator', 'prefixStabilizer', 'readState', 'estimatorMode',
|
|
28
|
-
'estimatorProvider', 'estimatorModel', 'estimatorBaseUrl', 'estimatorApiKey', 'estimatorTimeoutMs',
|
|
29
|
-
'advisorMode', 'advisorTimeoutMs', 'advisorRefreshTurns', 'advisorScoreThreshold', 'advisorSampleLimit',
|
|
30
|
-
'advisorMinTokens',
|
|
31
|
-
] as const
|
|
32
|
-
|
|
33
|
-
/** One partial edit of `presetOptions`; `undefined` clears the named field. */
|
|
34
|
-
export type PresetOptionsPatch = {
|
|
35
|
-
readonly [K in keyof PresetOptionsSettings]?: PresetOptionsSettings[K] | undefined
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Plan the path ops one patch needs against the section currently stored.
|
|
40
|
-
*
|
|
41
|
-
* Fields already at their requested value produce no op, so a re-selected
|
|
42
|
-
* value neither rewrites the document nor reports a save the Host never
|
|
43
|
-
* committed.
|
|
44
|
-
*
|
|
45
|
-
* @param current - the decoded `presetOptions` section, when one is stored.
|
|
46
|
-
* @param patch - the fields to write or clear.
|
|
47
|
-
* @returns the ordered ops, empty when the patch changes nothing.
|
|
48
|
-
*/
|
|
49
|
-
export function planPresetOptionsOps(
|
|
50
|
-
current: PresetOptionsSettings | undefined,
|
|
51
|
-
patch: PresetOptionsPatch,
|
|
52
|
-
): SettingsPathOpView[] {
|
|
53
|
-
const stored = current as Record<string, unknown> | undefined
|
|
54
|
-
const ops: SettingsPathOpView[] = []
|
|
55
|
-
for (const key of PRESET_OPTION_KEYS) {
|
|
56
|
-
if (!Object.hasOwn(patch, key)) continue
|
|
57
|
-
const value = patch[key]
|
|
58
|
-
const path = [PRESET_OPTIONS_KEY, key]
|
|
59
|
-
if (value === undefined) {
|
|
60
|
-
if (stored?.[key] !== undefined) ops.push({ op: 'unset', path })
|
|
61
|
-
continue
|
|
62
|
-
}
|
|
63
|
-
if (stored?.[key] === value) continue
|
|
64
|
-
ops.push({ op: 'set', path, value })
|
|
65
|
-
}
|
|
66
|
-
return ops
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Test whether one resolved settings document already carries every planned op.
|
|
71
|
-
*
|
|
72
|
-
* @param settings - the resolved namespace section after a write.
|
|
73
|
-
* @param ops - the ops that write submitted.
|
|
74
|
-
* @returns whether every named field holds its requested state.
|
|
75
|
-
*/
|
|
76
|
-
export function presetOptionsOpsAccepted(
|
|
77
|
-
presetOptions: PresetOptionsSettings | undefined,
|
|
78
|
-
ops: readonly SettingsPathOpView[],
|
|
79
|
-
): boolean {
|
|
80
|
-
if (ops.length === 0) return true
|
|
81
|
-
if (presetOptions === undefined) return false
|
|
82
|
-
const stored = presetOptions as Record<string, unknown>
|
|
83
|
-
return ops.every((op) => {
|
|
84
|
-
const key = op.path[op.path.length - 1]
|
|
85
|
-
if (key === undefined) return false
|
|
86
|
-
return op.op === 'set' ? stored[key] === op.value : stored[key] === undefined
|
|
87
|
-
})
|
|
88
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Path-addressed writes for the `presetOptions` section of the
|
|
3
|
+
* context-compression settings namespace.
|
|
4
|
+
*
|
|
5
|
+
* The settings Host applies a `set` op AT its path, so a field write must name
|
|
6
|
+
* only the field it changes. Writing the whole section — `scope.set(
|
|
7
|
+
* 'presetOptions', patch)` — replaces the section root with the patch, which
|
|
8
|
+
* deleted every sibling field: choosing a provider after choosing a channel
|
|
9
|
+
* erased `estimatorMode` and silently turned the estimator back off, and the
|
|
10
|
+
* saved document kept exactly the last field the user touched.
|
|
11
|
+
*
|
|
12
|
+
* A patch member set to `undefined` means "clear this field" (the section then
|
|
13
|
+
* re-inherits the preset default) rather than "leave it alone"; absent members
|
|
14
|
+
* are untouched by construction.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SettingsPathOpView } from '@deepseek-ai/dsh-settings/types'
|
|
18
|
+
import type { PresetOptionsSettings } from '../profiles.ts'
|
|
19
|
+
|
|
20
|
+
/** The namespace key holding every tokenpilot-inspired sub-capability override. */
|
|
21
|
+
const PRESET_OPTIONS_KEY = 'presetOptions'
|
|
22
|
+
|
|
23
|
+
/** Every field a patch may address, in the schema's own order. The retired
|
|
24
|
+
* review-gate keys are deliberately absent: nothing writes them any more, and
|
|
25
|
+
* a stored document that still carries them is tolerated by the decoders. */
|
|
26
|
+
const PRESET_OPTION_KEYS = [
|
|
27
|
+
'dedupeToolResults', 'summaryLocator', 'prefixStabilizer', 'readState', 'estimatorMode',
|
|
28
|
+
'estimatorProvider', 'estimatorModel', 'estimatorBaseUrl', 'estimatorApiKey', 'estimatorTimeoutMs',
|
|
29
|
+
'advisorMode', 'advisorTimeoutMs', 'advisorRefreshTurns', 'advisorScoreThreshold', 'advisorSampleLimit',
|
|
30
|
+
'advisorMinTokens',
|
|
31
|
+
] as const
|
|
32
|
+
|
|
33
|
+
/** One partial edit of `presetOptions`; `undefined` clears the named field. */
|
|
34
|
+
export type PresetOptionsPatch = {
|
|
35
|
+
readonly [K in keyof PresetOptionsSettings]?: PresetOptionsSettings[K] | undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Plan the path ops one patch needs against the section currently stored.
|
|
40
|
+
*
|
|
41
|
+
* Fields already at their requested value produce no op, so a re-selected
|
|
42
|
+
* value neither rewrites the document nor reports a save the Host never
|
|
43
|
+
* committed.
|
|
44
|
+
*
|
|
45
|
+
* @param current - the decoded `presetOptions` section, when one is stored.
|
|
46
|
+
* @param patch - the fields to write or clear.
|
|
47
|
+
* @returns the ordered ops, empty when the patch changes nothing.
|
|
48
|
+
*/
|
|
49
|
+
export function planPresetOptionsOps(
|
|
50
|
+
current: PresetOptionsSettings | undefined,
|
|
51
|
+
patch: PresetOptionsPatch,
|
|
52
|
+
): SettingsPathOpView[] {
|
|
53
|
+
const stored = current as Record<string, unknown> | undefined
|
|
54
|
+
const ops: SettingsPathOpView[] = []
|
|
55
|
+
for (const key of PRESET_OPTION_KEYS) {
|
|
56
|
+
if (!Object.hasOwn(patch, key)) continue
|
|
57
|
+
const value = patch[key]
|
|
58
|
+
const path = [PRESET_OPTIONS_KEY, key]
|
|
59
|
+
if (value === undefined) {
|
|
60
|
+
if (stored?.[key] !== undefined) ops.push({ op: 'unset', path })
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
if (stored?.[key] === value) continue
|
|
64
|
+
ops.push({ op: 'set', path, value })
|
|
65
|
+
}
|
|
66
|
+
return ops
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Test whether one resolved settings document already carries every planned op.
|
|
71
|
+
*
|
|
72
|
+
* @param settings - the resolved namespace section after a write.
|
|
73
|
+
* @param ops - the ops that write submitted.
|
|
74
|
+
* @returns whether every named field holds its requested state.
|
|
75
|
+
*/
|
|
76
|
+
export function presetOptionsOpsAccepted(
|
|
77
|
+
presetOptions: PresetOptionsSettings | undefined,
|
|
78
|
+
ops: readonly SettingsPathOpView[],
|
|
79
|
+
): boolean {
|
|
80
|
+
if (ops.length === 0) return true
|
|
81
|
+
if (presetOptions === undefined) return false
|
|
82
|
+
const stored = presetOptions as Record<string, unknown>
|
|
83
|
+
return ops.every((op) => {
|
|
84
|
+
const key = op.path[op.path.length - 1]
|
|
85
|
+
if (key === undefined) return false
|
|
86
|
+
return op.op === 'set' ? stored[key] === op.value : stored[key] === undefined
|
|
87
|
+
})
|
|
88
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 0.1.7-rc.2 stopped exporting `SettingsScope` from
|
|
3
|
-
* `@deepseek-ai/dsh-client-ui-settings/client`; the structural face the
|
|
4
|
-
* selector consumes lives here instead (getSnapshot shape mirrors the 0.1.7
|
|
5
|
-
* `ConfigFormSnapshot` minus the parts the components never read).
|
|
6
|
-
*/
|
|
7
|
-
/** The projected snapshot shape (identity-stable between changes — React #185). */
|
|
8
|
-
export interface ScopeSnapshot<T> {
|
|
9
|
-
status: 'loading' | 'ready' | 'unavailable'
|
|
10
|
-
value: T | undefined
|
|
11
|
-
revision: number | undefined
|
|
12
|
-
writable: boolean
|
|
13
|
-
base: unknown
|
|
14
|
-
user: unknown
|
|
15
|
-
mode: 'host' | 'memory'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface SettingsScope<T> {
|
|
19
|
-
getSnapshot(): ScopeSnapshot<T>
|
|
20
|
-
subscribe(listener: () => void): () => void
|
|
21
|
-
set(field: string, value: unknown): Promise<boolean>
|
|
22
|
-
unset(field: string): Promise<boolean>
|
|
23
|
-
mutate?(ops: readonly { path: readonly string[]; op: string; value?: unknown }[]): Promise<boolean>
|
|
24
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 0.1.7-rc.2 stopped exporting `SettingsScope` from
|
|
3
|
+
* `@deepseek-ai/dsh-client-ui-settings/client`; the structural face the
|
|
4
|
+
* selector consumes lives here instead (getSnapshot shape mirrors the 0.1.7
|
|
5
|
+
* `ConfigFormSnapshot` minus the parts the components never read).
|
|
6
|
+
*/
|
|
7
|
+
/** The projected snapshot shape (identity-stable between changes — React #185). */
|
|
8
|
+
export interface ScopeSnapshot<T> {
|
|
9
|
+
status: 'loading' | 'ready' | 'unavailable'
|
|
10
|
+
value: T | undefined
|
|
11
|
+
revision: number | undefined
|
|
12
|
+
writable: boolean
|
|
13
|
+
base: unknown
|
|
14
|
+
user: unknown
|
|
15
|
+
mode: 'host' | 'memory'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SettingsScope<T> {
|
|
19
|
+
getSnapshot(): ScopeSnapshot<T>
|
|
20
|
+
subscribe(listener: () => void): () => void
|
|
21
|
+
set(field: string, value: unknown): Promise<boolean>
|
|
22
|
+
unset(field: string): Promise<boolean>
|
|
23
|
+
mutate?(ops: readonly { path: readonly string[]; op: string; value?: unknown }[]): Promise<boolean>
|
|
24
|
+
}
|