dsh-context-compression-improved 0.6.0 → 0.6.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.
- package/package.json +6 -6
- package/packages/selector/lib/client.d.ts +27 -19
- package/packages/selector/lib/client.js +5 -5
- package/packages/selector/lib/pruner.d.ts +7 -0
- package/packages/selector/lib/pruner.js +20 -33
- package/packages/selector/lib/tail-trim.js +3 -6
- package/packages/selector/package.json +1 -1
- package/packages/selector/src/client/CompressionProfileControls.tsx +2 -2
- package/packages/selector/src/client/CompressionProfileSelector.tsx +1 -1
- package/packages/selector/src/client/index.ts +7 -8
- package/packages/selector/src/client/scope-face.ts +21 -0
- package/packages/selector/src/pruner/content.ts +0 -3
- package/packages/selector/src/pruner/session.ts +4 -2
- package/packages/selector/src/pruner.ts +26 -15
- package/packages/selector/src/runtime/measurement.ts +3 -8
- package/packages/selector/src/runtime/retrieve.ts +3 -3
- package/packages/selector/src/runtime/tail-trim.ts +4 -5
- package/packages/selector/tests/code-skeleton.client.spec.ts +93 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
- package/packages/selector/tests/helpers/legacy-namespace.ts +31 -31
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +1 -1
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -206
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -3
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -20
- package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
- package/packages/selector/tests/standing-generation.host.spec.ts +704 -704
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/pnpm-workspace.yaml +42 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-compression-improved",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"tag": "dsh-0.1.7"
|
|
6
6
|
},
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"packageManager": "pnpm@11.7.0",
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": "^22.19.0 || >=24.0.0",
|
|
56
|
-
"dsh": ">=0.1.
|
|
56
|
+
"dsh": ">=0.1.7-rc.1 <0.1.8-0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "pnpm -r --if-present run bundle",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"pack:dry-run": "pnpm -r --if-present run pack:dry-run"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@deepseek-ai/dsh-client-locale": ">=0.1.
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.1.
|
|
75
|
-
"@deepseek-ai/dsh-client-ui-settings": ">=0.1.
|
|
76
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.
|
|
73
|
+
"@deepseek-ai/dsh-client-locale": ">=0.1.7-rc.1 <0.1.8-0",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.1.7-rc.1 <0.1.8-0",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.1.7-rc.1 <0.1.8-0",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.7-rc.1 <0.1.8-0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependenciesMeta": {
|
|
79
79
|
"@deepseek-ai/dsh-client-locale": {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { i as PresetOptionsSettings, n as ContextCompressionSettings, r as CustomCompressionPolicy, t as CompressionProfile } from "./profiles.js";
|
|
2
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
3
3
|
import "@deepseek-ai/dsh-settings/types";
|
|
4
|
-
import { SettingsScope } from "@deepseek-ai/dsh-client-ui-settings/client";
|
|
5
4
|
import { InjectFace, PropsLocale } from "@deepseek-ai/dsh-client-ui-slots";
|
|
6
5
|
//#region src/client/preset-options.d.ts
|
|
7
6
|
/** One partial edit of `presetOptions`; `undefined` clears the named field. */
|
|
@@ -107,6 +106,33 @@ declare const zh: {
|
|
|
107
106
|
/** Locale keys that every context-compression selector dictionary must provide. */
|
|
108
107
|
type ContextCompressionLocaleKey = keyof typeof zh;
|
|
109
108
|
//#endregion
|
|
109
|
+
//#region src/client/scope-face.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* 0.1.7-rc.2 stopped exporting `SettingsScope` from
|
|
112
|
+
* `@deepseek-ai/dsh-client-ui-settings/client`; the structural face the
|
|
113
|
+
* selector consumes lives here instead (getSnapshot shape mirrors the 0.1.7
|
|
114
|
+
* `ConfigFormSnapshot` minus the parts the components never read).
|
|
115
|
+
*/
|
|
116
|
+
interface SettingsScope<T> {
|
|
117
|
+
getSnapshot(): {
|
|
118
|
+
status: 'loading' | 'ready' | 'unavailable';
|
|
119
|
+
value: T | undefined;
|
|
120
|
+
revision: number | undefined;
|
|
121
|
+
writable: boolean;
|
|
122
|
+
base: unknown;
|
|
123
|
+
user: unknown;
|
|
124
|
+
mode: 'host' | 'memory';
|
|
125
|
+
};
|
|
126
|
+
subscribe(listener: () => void): () => void;
|
|
127
|
+
set(field: string, value: unknown): Promise<boolean>;
|
|
128
|
+
unset(field: string): Promise<boolean>;
|
|
129
|
+
mutate?(ops: readonly {
|
|
130
|
+
path: readonly string[];
|
|
131
|
+
op: string;
|
|
132
|
+
value?: unknown;
|
|
133
|
+
}[]): Promise<boolean>;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
110
136
|
//#region src/client/CompressionProfileSelector.d.ts
|
|
111
137
|
interface CompressionSelectorInjected {
|
|
112
138
|
hooks: {
|
|
@@ -151,27 +177,9 @@ interface SlotsService {
|
|
|
151
177
|
declare module '@deepseek-ai/cordis' {
|
|
152
178
|
interface Context {
|
|
153
179
|
slots: SlotsService;
|
|
154
|
-
configForms: ConfigFormsFace;
|
|
155
180
|
}
|
|
156
181
|
}
|
|
157
182
|
declare const inject: string[];
|
|
158
|
-
/** The configForms face this client consumes (structural; 0.1.7 ui-settings). */
|
|
159
|
-
interface ConfigFormsFace {
|
|
160
|
-
get<T>(entryId: string): {
|
|
161
|
-
getSnapshot(): {
|
|
162
|
-
status: 'loading' | 'ready' | 'unavailable';
|
|
163
|
-
value: T | undefined;
|
|
164
|
-
revision: number | undefined;
|
|
165
|
-
writable: boolean;
|
|
166
|
-
base: unknown;
|
|
167
|
-
user: unknown;
|
|
168
|
-
mode: 'host' | 'memory';
|
|
169
|
-
};
|
|
170
|
-
subscribe(listener: () => void): () => void;
|
|
171
|
-
set(field: string, value: unknown): Promise<boolean>;
|
|
172
|
-
unset(field: string): Promise<boolean>;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
183
|
declare function apply(ctx: Context): void;
|
|
176
184
|
//#endregion
|
|
177
185
|
export { type CompressionProfile, type CompressionProfileSelectorProps, type CompressionSelectorInjected, type ContextCompressionSettings, apply, inject };
|
|
@@ -1492,24 +1492,24 @@ window.__ModuleLoader__.load({
|
|
|
1492
1492
|
set: async (field, value) => {
|
|
1493
1493
|
const next = { ...readDoc() ?? {} };
|
|
1494
1494
|
next[field] = value;
|
|
1495
|
-
|
|
1495
|
+
return form.set("settings", next);
|
|
1496
1496
|
},
|
|
1497
1497
|
unset: async (field) => {
|
|
1498
1498
|
const next = { ...readDoc() ?? {} };
|
|
1499
1499
|
delete next[field];
|
|
1500
|
-
|
|
1500
|
+
return form.set("settings", next);
|
|
1501
1501
|
},
|
|
1502
1502
|
mutate: async (ops) => {
|
|
1503
1503
|
const doc = { ...readDoc() ?? {} };
|
|
1504
1504
|
for (const op of ops) {
|
|
1505
1505
|
const [head, key] = op.path;
|
|
1506
|
-
if (head !== "presetOptions") return;
|
|
1506
|
+
if (head !== "presetOptions") return false;
|
|
1507
1507
|
const section = { ...doc.presetOptions ?? {} };
|
|
1508
1508
|
if (op.op === "unset") delete section[key];
|
|
1509
1509
|
else section[key] = op.value;
|
|
1510
1510
|
doc.presetOptions = section;
|
|
1511
1511
|
}
|
|
1512
|
-
|
|
1512
|
+
return form.set("settings", doc);
|
|
1513
1513
|
}
|
|
1514
1514
|
};
|
|
1515
1515
|
const writeAndConfirm = async (write, accepts) => {
|
|
@@ -1528,7 +1528,7 @@ window.__ModuleLoader__.load({
|
|
|
1528
1528
|
savePresetOptions: (options) => {
|
|
1529
1529
|
const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options);
|
|
1530
1530
|
if (ops.length === 0) return Promise.resolve();
|
|
1531
|
-
return writeAndConfirm(() => scope.mutate(ops), (settings) => presetOptionsOpsAccepted(settings.presetOptions, ops));
|
|
1531
|
+
return writeAndConfirm(() => scope.mutate?.(ops) ?? Promise.resolve(false), (settings) => presetOptionsOpsAccepted(settings.presetOptions, ops));
|
|
1532
1532
|
}
|
|
1533
1533
|
};
|
|
1534
1534
|
};
|
|
@@ -693,6 +693,13 @@ interface CompactionTokenView extends TokenMeasurement {
|
|
|
693
693
|
declare function measureForCompaction(ctx: Context, session: Session): CompactionTokenView;
|
|
694
694
|
//#endregion
|
|
695
695
|
//#region src/pruner.d.ts
|
|
696
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
697
|
+
interface MessageSourceMap {
|
|
698
|
+
'dsh-context-compression': {
|
|
699
|
+
readonly kind: 'dsh-context-compression';
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
}
|
|
696
703
|
declare module '@deepseek-ai/cordis' {
|
|
697
704
|
interface Context {
|
|
698
705
|
toolResultPruner: ToolResultPruner;
|
|
@@ -407,9 +407,6 @@ function pressureCost(blocks) {
|
|
|
407
407
|
case "tool-call":
|
|
408
408
|
cost += 256 + codePointLength(block.name) + codePointLength(block.arguments);
|
|
409
409
|
break;
|
|
410
|
-
case "tool-result":
|
|
411
|
-
cost += 256 + pressureCost(block.content);
|
|
412
|
-
break;
|
|
413
410
|
default: {
|
|
414
411
|
const serialized = JSON.stringify(block);
|
|
415
412
|
cost += Math.max(256, codePointLength(serialized));
|
|
@@ -481,8 +478,7 @@ function emptyResult() {
|
|
|
481
478
|
* @returns character pressure in Unicode code points, plus rich-block costs.
|
|
482
479
|
*/
|
|
483
480
|
function nodeCharacterPressure(content) {
|
|
484
|
-
|
|
485
|
-
return pressureCost(only?.type === "tool-result" ? only.content : content);
|
|
481
|
+
return pressureCost(content);
|
|
486
482
|
}
|
|
487
483
|
const VISION_MODEL_ID = DEEPSEEK_VISION_TOKENIZER_ARTIFACT.modelIds[0];
|
|
488
484
|
/**
|
|
@@ -587,9 +583,6 @@ function countCanonicalContent(blocks, counter, subject) {
|
|
|
587
583
|
if (!absorb(counter.countText(block.name))) return false;
|
|
588
584
|
if (!absorb(counter.countText(block.arguments))) return false;
|
|
589
585
|
break;
|
|
590
|
-
case "tool-result":
|
|
591
|
-
if (!walk(block.content)) return false;
|
|
592
|
-
break;
|
|
593
586
|
case "image":
|
|
594
587
|
if (!absorb(counter.countImage(block.attachment))) return false;
|
|
595
588
|
break;
|
|
@@ -688,7 +681,7 @@ function intrinsicImageDiagnostic(blocks, target) {
|
|
|
688
681
|
paddingMinimumTokens += estimate.paddingMinimumTokens;
|
|
689
682
|
paddingMaximumTokens += estimate.paddingMaximumTokens;
|
|
690
683
|
seen = true;
|
|
691
|
-
}
|
|
684
|
+
}
|
|
692
685
|
};
|
|
693
686
|
walk(blocks);
|
|
694
687
|
return seen ? Object.freeze({
|
|
@@ -805,7 +798,7 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
805
798
|
const event = sessionEvents(exec.agent.session)[seq];
|
|
806
799
|
if (event?.type !== "tool/result") throw new Error(`context_compression_retrieve: event ${String(seq)} is not a tool/result in the current session`);
|
|
807
800
|
const maxLines = resolveMaxLines(args.max_lines);
|
|
808
|
-
const scan = scanBlocks(event.data.message.content
|
|
801
|
+
const scan = scanBlocks(event.data.message.content, maxScanChars);
|
|
809
802
|
const scannedLines = splitScannedLines(scan);
|
|
810
803
|
const lines = scannedLines.lines;
|
|
811
804
|
const query = args.query;
|
|
@@ -814,8 +807,8 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
814
807
|
const total = scan.complete ? String(lines.length) : `at least ${String(lines.length)}`;
|
|
815
808
|
const output = `${[
|
|
816
809
|
`source: ${args.ref}`,
|
|
817
|
-
`tool_call_id: ${event.data.message.
|
|
818
|
-
`status: ${event.data.message.
|
|
810
|
+
`tool_call_id: ${event.data.message.toolCallId}`,
|
|
811
|
+
`status: ${event.data.message.isError === true ? "error" : "completed"}`,
|
|
819
812
|
`lines: ${String(selected.start)}-${String(selected.end)} of ${total}`,
|
|
820
813
|
scan.complete ? "" : "note: source scan limit reached; later lines were not inspected",
|
|
821
814
|
selected.partialLine === void 0 ? "" : `note: line ${String(selected.partialLine)} is a partial prefix ending at the source scan limit`,
|
|
@@ -1111,7 +1104,7 @@ function tokenizerAuditFact(route) {
|
|
|
1111
1104
|
}
|
|
1112
1105
|
/** Check whether a snapshot candidate represents an error result. */
|
|
1113
1106
|
function isError(candidate) {
|
|
1114
|
-
return candidate.event.data.message.
|
|
1107
|
+
return candidate.event.data.message.isError === true || candidate.event.data.error !== void 0;
|
|
1115
1108
|
}
|
|
1116
1109
|
/** Wrap a plan list into a HistoryPlanOutcome. */
|
|
1117
1110
|
function historyOutcome(plans) {
|
|
@@ -4244,10 +4237,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4244
4237
|
lastText.text = `${lastText.text}\n\n${block}`;
|
|
4245
4238
|
const replacement = createUserMessage({
|
|
4246
4239
|
content,
|
|
4247
|
-
source: {
|
|
4248
|
-
kind: "plugin",
|
|
4249
|
-
plugin: "dsh-context-compression-improved-runtime"
|
|
4250
|
-
}
|
|
4240
|
+
source: { kind: "dsh-context-compression" }
|
|
4251
4241
|
});
|
|
4252
4242
|
session.append("user/message", replacement, {
|
|
4253
4243
|
surfaceOp: {
|
|
@@ -4842,11 +4832,11 @@ var ToolResultPruner = class extends Service {
|
|
|
4842
4832
|
if (event?.type !== "tool/result") continue;
|
|
4843
4833
|
const shadowedHeuristicTokenCount = projectionPrices.get(seq);
|
|
4844
4834
|
if (shadowedHeuristicTokenCount === void 0) throw new Error(`surface node ${String(seq)} is absent from the atomic legacy projection`);
|
|
4845
|
-
const content = event.data.message.content
|
|
4835
|
+
const content = event.data.message.content;
|
|
4846
4836
|
candidates.push({
|
|
4847
4837
|
seq,
|
|
4848
4838
|
event,
|
|
4849
|
-
call: calls.get(event.data.message.
|
|
4839
|
+
call: calls.get(event.data.message.toolCallId) ?? {
|
|
4850
4840
|
name: "unknown",
|
|
4851
4841
|
arguments: "{}"
|
|
4852
4842
|
},
|
|
@@ -4860,7 +4850,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4860
4850
|
planNative(candidate, session, stage, policy, view) {
|
|
4861
4851
|
if (this.isRecoveryExempt(session, candidate)) return null;
|
|
4862
4852
|
if (candidate.characterPressure <= charsForTokens(policy.nativeTriggerTokens)) return null;
|
|
4863
|
-
const result = candidate.event.data.message
|
|
4853
|
+
const result = candidate.event.data.message;
|
|
4864
4854
|
if (onlyTextBlocks(result.content) === null) return null;
|
|
4865
4855
|
const sourceSeq = rootToolResultSeq(session, candidate.seq);
|
|
4866
4856
|
const marker = (startLine) => recoveryMarker(sourceRef(session, sourceSeq), "tool result middle pruned", startLine);
|
|
@@ -4887,7 +4877,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4887
4877
|
*/
|
|
4888
4878
|
planDedupe(candidate, session, policy, view) {
|
|
4889
4879
|
if (typeof candidate.event.surfaceOp === "object") return null;
|
|
4890
|
-
const result = candidate.event.data.message
|
|
4880
|
+
const result = candidate.event.data.message;
|
|
4891
4881
|
const text = flattenPlainText(result.content);
|
|
4892
4882
|
if (text === void 0) return null;
|
|
4893
4883
|
if (candidate.characterPressure <= charsForTokens(policy.freshTriggerTokens)) return null;
|
|
@@ -4917,7 +4907,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4917
4907
|
}
|
|
4918
4908
|
planFresh(candidate, session, policy, view) {
|
|
4919
4909
|
if (typeof candidate.event.surfaceOp === "object") return null;
|
|
4920
|
-
const result = candidate.event.data.message
|
|
4910
|
+
const result = candidate.event.data.message;
|
|
4921
4911
|
if (candidate.characterPressure <= charsForTokens(policy.freshTriggerTokens)) return null;
|
|
4922
4912
|
const sourceSeq = candidate.seq;
|
|
4923
4913
|
const sourceRef$1 = sourceRef(session, sourceSeq);
|
|
@@ -4955,7 +4945,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4955
4945
|
if (isError(candidate)) return this.planErrorEvidence(candidate, session, view, stage, targetTokens, component, historyMode);
|
|
4956
4946
|
const sourceSeq = rootToolResultSeq(session, candidate.seq);
|
|
4957
4947
|
const sourceRef$2 = sourceRef(session, sourceSeq);
|
|
4958
|
-
const redacted = candidate.event.data.message
|
|
4948
|
+
const redacted = candidate.event.data.message;
|
|
4959
4949
|
if (onlyTextBlocks(redacted.content) === null) return null;
|
|
4960
4950
|
const text = [
|
|
4961
4951
|
"[Tool result reduced to satisfy the completed-step aggregate budget]",
|
|
@@ -4972,7 +4962,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4972
4962
|
/** Preserve bounded diagnostic evidence whenever an all-text error is reduced. */
|
|
4973
4963
|
planErrorEvidence(candidate, session, view, stage, targetTokens, component = "aggregate", historyMode) {
|
|
4974
4964
|
if (!isError(candidate)) return null;
|
|
4975
|
-
const result = candidate.event.data.message
|
|
4965
|
+
const result = candidate.event.data.message;
|
|
4976
4966
|
const blocks = onlyTextBlocks(result.content);
|
|
4977
4967
|
if (blocks === null) return null;
|
|
4978
4968
|
const text = blocks.map((block) => block.text).join("\n");
|
|
@@ -5011,7 +5001,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5011
5001
|
const protectedSeqs = this.protectedHistoryCandidateSeqs(candidates, policy);
|
|
5012
5002
|
const isUnsafe = (candidate) => {
|
|
5013
5003
|
if (this.isRecoveryExempt(session, candidate)) return true;
|
|
5014
|
-
const result = candidate.event.data.message
|
|
5004
|
+
const result = candidate.event.data.message;
|
|
5015
5005
|
return onlyTextBlock(result.content)?.text.includes("[Old tool result content cleared from active context]") === true;
|
|
5016
5006
|
};
|
|
5017
5007
|
const safe = candidates.filter((candidate) => !isUnsafe(candidate));
|
|
@@ -5024,7 +5014,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5024
5014
|
const required = Math.max(minReclaimChars, total - trigger, ...microTarget === void 0 ? [] : [charsForTokens(view.totalTokens) - microTarget]);
|
|
5025
5015
|
const batchTarget = microTarget === void 0 ? minReclaimChars : required;
|
|
5026
5016
|
for (const candidate of eligible) {
|
|
5027
|
-
const result = candidate.event.data.message
|
|
5017
|
+
const result = candidate.event.data.message;
|
|
5028
5018
|
const block = onlyTextBlock(result.content);
|
|
5029
5019
|
if (policy.presetOptions?.readState === true && block !== null) {
|
|
5030
5020
|
const readPath = toolCallPath(candidate.call.arguments);
|
|
@@ -5165,7 +5155,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5165
5155
|
const results = resultSeqs.map((seq) => events[seq]);
|
|
5166
5156
|
if (results.some((event) => {
|
|
5167
5157
|
if (event?.type !== "tool/result" || event.data.turn !== assistant.data.turn || event.data.step !== assistant.data.step || event.data.error !== void 0) return true;
|
|
5168
|
-
const block = event.data.message
|
|
5158
|
+
const block = event.data.message;
|
|
5169
5159
|
if (block.isError === true) return true;
|
|
5170
5160
|
return block.content.some((contentBlock) => contentBlock.type !== "text");
|
|
5171
5161
|
})) continue;
|
|
@@ -5312,7 +5302,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5312
5302
|
const tokensBefore = exact ? countBefore.tokens : charsToTokens(charsBefore);
|
|
5313
5303
|
const tokensAfter = exact ? countAfter.tokens : charsToTokens(charsAfter);
|
|
5314
5304
|
if (options.noNetSavingsGuard === true) {
|
|
5315
|
-
const originalBlocks = onlyTextBlocks(candidate.event.data.message.content
|
|
5305
|
+
const originalBlocks = onlyTextBlocks(candidate.event.data.message.content);
|
|
5316
5306
|
const replacementBlocks = onlyTextBlocks(content);
|
|
5317
5307
|
if (originalBlocks !== null && replacementBlocks !== null) {
|
|
5318
5308
|
const originalChars = originalBlocks.reduce((sum, block) => sum + codePointLength(block.text), 0);
|
|
@@ -5339,13 +5329,10 @@ var ToolResultPruner = class extends Service {
|
|
|
5339
5329
|
}
|
|
5340
5330
|
land(session, plan) {
|
|
5341
5331
|
const { candidate } = plan;
|
|
5342
|
-
|
|
5332
|
+
candidate.event.data.message;
|
|
5343
5333
|
const message = freezeMessage({
|
|
5344
5334
|
...candidate.event.data.message,
|
|
5345
|
-
content:
|
|
5346
|
-
...result,
|
|
5347
|
-
content: plan.content
|
|
5348
|
-
}]
|
|
5335
|
+
content: plan.content
|
|
5349
5336
|
});
|
|
5350
5337
|
const manifest = session.append("compaction/prune", {
|
|
5351
5338
|
shadowedRange: {
|
|
@@ -59,10 +59,7 @@ function tailTrimMessage(stub) {
|
|
|
59
59
|
type: "text",
|
|
60
60
|
text: stub
|
|
61
61
|
}],
|
|
62
|
-
source: {
|
|
63
|
-
kind: "plugin",
|
|
64
|
-
plugin: "dsh-context-compression-improved-runtime"
|
|
65
|
-
}
|
|
62
|
+
source: { kind: "dsh-context-compression" }
|
|
66
63
|
});
|
|
67
64
|
}
|
|
68
65
|
/** Validate the standard prune, adjacent replacement, append roots and stub. */
|
|
@@ -71,7 +68,7 @@ function validatePublishedTailTrim(session, manifestSeq) {
|
|
|
71
68
|
const manifest = events[manifestSeq];
|
|
72
69
|
if (manifest?.type !== "compaction/prune" || manifest.data.shadowedSeqs.length < 2 || manifest.data.shadowedSeqs.length > MAX_ROOTS || manifest.data.shadowedSeqs[0] !== Number(manifest.data.shadowedRange.start) || manifest.data.shadowedSeqs.at(-1) !== Number(manifest.data.shadowedRange.end) || new Set(manifest.data.shadowedSeqs).size !== manifest.data.shadowedSeqs.length) return null;
|
|
73
70
|
const replacement = events[manifestSeq + 1];
|
|
74
|
-
if (replacement?.type !== "user/message" || replacement.seq !== manifest.seq + 1 || replacement.data.source.kind !== "
|
|
71
|
+
if (replacement?.type !== "user/message" || replacement.seq !== manifest.seq + 1 || replacement.data.source.kind !== "dsh-context-compression" || replacement.surfaceOp === void 0 || replacement.surfaceOp === "append" || replacement.surfaceOp.startSeq !== manifest.data.shadowedRange.start || replacement.surfaceOp.endSeq !== manifest.data.shadowedRange.end || !sameNumbers(replacement.sourceEventSeqs, [manifest.seq, ...manifest.data.shadowedSeqs]) || replacement.data.content.length !== 1 || replacement.data.content[0]?.type !== "text") return null;
|
|
75
72
|
const tracedRoots = manifest.data.shadowedSeqs.map((seq) => uniqueAppendRoot(session, seq, manifestSeq));
|
|
76
73
|
if (tracedRoots.some((root) => root === null)) return null;
|
|
77
74
|
const sourceEventSeqs = tracedRoots;
|
|
@@ -134,7 +131,7 @@ function validRootGroup(roots, manifestSeq) {
|
|
|
134
131
|
if (new Set(callIds).size !== callIds.length || roots.length !== callIds.length + 1) return false;
|
|
135
132
|
for (const [index, root] of roots.slice(1).entries()) {
|
|
136
133
|
if (root.type !== "tool/result" || root.seq >= manifestSeq || root.surfaceOp !== "append") return false;
|
|
137
|
-
if (root.data.message.
|
|
134
|
+
if (root.data.message.isError === true || root.data.error !== void 0 || root.data.turn !== assistant.data.turn || root.data.step !== assistant.data.step || String(root.data.message.toolCallId) !== String(callIds[index])) return false;
|
|
138
135
|
}
|
|
139
136
|
return true;
|
|
140
137
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { useEffect, useId, useState } from 'react'
|
|
11
|
-
import {
|
|
11
|
+
import { IconChevronDownOutlineMedium, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
12
12
|
import type { ContextCompressionLocaleKey } from './locales.ts'
|
|
13
13
|
import css from './CompressionProfileSelector.module.css'
|
|
14
14
|
import {
|
|
@@ -90,7 +90,7 @@ export function CompressionProfileControls({
|
|
|
90
90
|
<span className={css.label}>{t('label')}</span>
|
|
91
91
|
<span className={css.value}>{label}</span>
|
|
92
92
|
</span>
|
|
93
|
-
<
|
|
93
|
+
<IconChevronDownOutlineMedium className={css.chevron} />
|
|
94
94
|
</button>
|
|
95
95
|
)}
|
|
96
96
|
/>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module dsh-context-compression-improved/client/CompressionProfileSelector
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import type { SettingsScope } from '
|
|
11
|
+
import type { SettingsScope } from './scope-face.ts'
|
|
12
12
|
import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
13
13
|
import {
|
|
14
14
|
COMPRESSION_PROFILES,
|
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../profiles.ts'
|
|
12
12
|
import { decodeSettings } from './decode.ts'
|
|
13
13
|
import { en, zh } from './locales.ts'
|
|
14
|
-
import type { SettingsScope } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
15
14
|
import { planPresetOptionsOps, presetOptionsOpsAccepted } from './preset-options.ts'
|
|
15
|
+
import type { SettingsScope } from './scope-face.ts'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Harness 0.1.5 mounts the web core's `slots` service on the client context
|
|
@@ -29,7 +29,6 @@ interface SlotsService {
|
|
|
29
29
|
declare module '@deepseek-ai/cordis' {
|
|
30
30
|
interface Context {
|
|
31
31
|
slots: SlotsService
|
|
32
|
-
configForms: ConfigFormsFace
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -115,28 +114,28 @@ export function apply(ctx: ClientContext): void {
|
|
|
115
114
|
set: async (field, value) => {
|
|
116
115
|
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
117
116
|
next[field] = value
|
|
118
|
-
|
|
117
|
+
return form.set('settings', next)
|
|
119
118
|
},
|
|
120
119
|
unset: async (field) => {
|
|
121
120
|
const next = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
122
121
|
delete next[field]
|
|
123
|
-
|
|
122
|
+
return form.set('settings', next)
|
|
124
123
|
},
|
|
125
124
|
mutate: async (ops) => {
|
|
126
125
|
const doc = { ...(readDoc() ?? {}) } as Record<string, unknown>
|
|
127
126
|
for (const op of ops) {
|
|
128
127
|
const [head, key] = op.path as [string, string]
|
|
129
|
-
if (head !== 'presetOptions') return
|
|
128
|
+
if (head !== 'presetOptions') return false
|
|
130
129
|
const section = { ...((doc.presetOptions ?? {}) as Record<string, unknown>) }
|
|
131
130
|
if (op.op === 'unset') delete section[key]
|
|
132
131
|
else section[key] = (op as { value?: unknown }).value
|
|
133
132
|
doc.presetOptions = section
|
|
134
133
|
}
|
|
135
|
-
|
|
134
|
+
return form.set('settings', doc)
|
|
136
135
|
},
|
|
137
136
|
}
|
|
138
137
|
const writeAndConfirm = async (
|
|
139
|
-
write: () => Promise<
|
|
138
|
+
write: () => Promise<unknown>,
|
|
140
139
|
accepts: (settings: ContextCompressionSettings) => boolean,
|
|
141
140
|
): Promise<void> => {
|
|
142
141
|
const beforeRevision = scope.getSnapshot().revision
|
|
@@ -182,7 +181,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
182
181
|
const ops = planPresetOptionsOps(scope.getSnapshot().value?.presetOptions, options)
|
|
183
182
|
if (ops.length === 0) return Promise.resolve()
|
|
184
183
|
return writeAndConfirm(
|
|
185
|
-
() => scope.mutate(ops),
|
|
184
|
+
() => scope.mutate?.(ops) ?? Promise.resolve(false),
|
|
186
185
|
settings => presetOptionsOpsAccepted(settings.presetOptions, ops),
|
|
187
186
|
)
|
|
188
187
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export interface SettingsScope<T> {
|
|
8
|
+
getSnapshot(): {
|
|
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
|
+
subscribe(listener: () => void): () => void
|
|
18
|
+
set(field: string, value: unknown): Promise<boolean>
|
|
19
|
+
unset(field: string): Promise<boolean>
|
|
20
|
+
mutate?(ops: readonly { path: readonly string[]; op: string; value?: unknown }[]): Promise<boolean>
|
|
21
|
+
}
|
|
@@ -105,9 +105,6 @@ function pressureCost(blocks: readonly ContentBlock[]): number {
|
|
|
105
105
|
+ codePointLength(block.name)
|
|
106
106
|
+ codePointLength(block.arguments)
|
|
107
107
|
break
|
|
108
|
-
case 'tool-result':
|
|
109
|
-
cost += RICH_BLOCK_PRESSURE_COST + pressureCost(block.content)
|
|
110
|
-
break
|
|
111
108
|
default: {
|
|
112
109
|
// ContentBlockMap is merge-extensible. Unknown model-visible blocks
|
|
113
110
|
// scale with their durable JSON payload instead of receiving a fixed
|
|
@@ -73,8 +73,10 @@ function tokenizerAuditFact(route: { provider: string, model: string }): { token
|
|
|
73
73
|
|
|
74
74
|
/** Check whether a snapshot candidate represents an error result. */
|
|
75
75
|
function isError(candidate: SnapshotCandidate): boolean {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// 0.1.7-rc.2: tool results are first-class `tool`-role messages — `isError`
|
|
77
|
+
// moved from the result block onto the message itself.
|
|
78
|
+
const message = candidate.event.data.message as { isError?: boolean }
|
|
79
|
+
return message.isError === true || candidate.event.data.error !== undefined
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/** Wrap a plan list into a HistoryPlanOutcome. */
|