@crazx/dsh-compaction-basic 0.1.1-rc.1.zw.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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +172 -0
- package/README.zh.md +172 -0
- package/lib/index.js +1580 -0
- package/lib/invariant.js +23 -0
- package/lib/types/config.d.ts +37 -0
- package/lib/types/hierarchical-planner.d.ts +40 -0
- package/lib/types/hierarchical-prompts.d.ts +40 -0
- package/lib/types/hierarchical.d.ts +27 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/region.d.ts +63 -0
- package/lib/types/summarizer.d.ts +74 -0
- package/lib/types/types.d.ts +90 -0
- package/package.json +70 -0
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-compaction-basic`.
|
|
4
|
+
* @module @deepseek-ai/dsh-compaction-basic/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-compaction-basic";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "compaction-basic-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: this package exposes no independent event sequence or mutable data relation
|
|
13
|
+
* beyond contracts enforced at its owning seam.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => {};
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load-time validation and routed-model policy resolution for compaction-basic.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-compaction-basic/config
|
|
5
|
+
*/
|
|
6
|
+
import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
import type { BasicCompactionConfig, ResolvedCompactSpec, ResolvedConfig, ResolvedTargetPolicy } from './types.ts';
|
|
8
|
+
/** Target-specific pressure configuration failure eligible for warning suppression. */
|
|
9
|
+
export declare class TargetPressureConfigError extends Error {
|
|
10
|
+
readonly targetKey: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param targetKey - exact provider/model route used as the warning key.
|
|
13
|
+
* @param message - actionable configuration failure detail.
|
|
14
|
+
*/
|
|
15
|
+
constructor(targetKey: string, message: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve and validate service defaults plus exact-target partial overrides.
|
|
19
|
+
* @param config - untrusted plugin configuration after Loader normalization.
|
|
20
|
+
* @returns detached immutable defaults and validated exact-target overrides.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveConfig(config?: BasicCompactionConfig): ResolvedConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Merge the exact provider/model override over the validated default policy.
|
|
25
|
+
* @param config - validated service defaults and override table.
|
|
26
|
+
* @param target - exact durable provider/model route to match.
|
|
27
|
+
* @returns detached immutable policy before model-capacity scaling.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveTargetPolicy(config: ResolvedConfig, target: Pick<LlmCallConfig, 'provider' | 'model'>): ResolvedTargetPolicy;
|
|
30
|
+
/**
|
|
31
|
+
* Scale one routed policy into concrete token budgets for its model capacity.
|
|
32
|
+
* @param policy - merged policy for the exact routed target.
|
|
33
|
+
* @param contextWindow - positive adapter-owned capacity for that target.
|
|
34
|
+
* @returns detached immutable pressure and retention budgets.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveCompactSpec(policy: ResolvedTargetPolicy, contextWindow: number): ResolvedCompactSpec;
|
|
37
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Pure tool-balanced grouping and greedy token-budget planning. */
|
|
2
|
+
import type { Message } from '@deepseek-ai/dsh-llm';
|
|
3
|
+
/** A selected message unit cannot fit one auxiliary model call. */
|
|
4
|
+
export declare class OversizedCompactionUnitError extends Error {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
/** Callback matching the shared token meter's message estimator. */
|
|
8
|
+
export type EstimateMessage = (message: Message) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Sum estimated tokens for an ordered message list.
|
|
11
|
+
* @param messages - model-visible messages to price.
|
|
12
|
+
* @param estimate - shared message estimator.
|
|
13
|
+
* @returns non-negative estimated tokens.
|
|
14
|
+
*/
|
|
15
|
+
export declare function estimateMessages(messages: readonly Message[], estimate: EstimateMessage): number;
|
|
16
|
+
/**
|
|
17
|
+
* Group messages into units whose boundaries never split tool calls from results.
|
|
18
|
+
* @param messages - messages in provider order.
|
|
19
|
+
* @returns balanced, non-empty units in the same order.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toolBalancedUnits(messages: readonly Message[]): Message[][];
|
|
22
|
+
/**
|
|
23
|
+
* Greedily pack tool-balanced units under one message-token budget.
|
|
24
|
+
* @param messages - messages in provider order.
|
|
25
|
+
* @param budgetTokens - tokens available after header and instruction reserves.
|
|
26
|
+
* @param estimate - shared message estimator.
|
|
27
|
+
* @returns non-empty chunks in the same order.
|
|
28
|
+
*/
|
|
29
|
+
export declare function planMessageChunks(messages: readonly Message[], budgetTokens: number, estimate: EstimateMessage): Message[][];
|
|
30
|
+
/**
|
|
31
|
+
* Bisect one provider-rejected chunk at a tool-balanced unit boundary.
|
|
32
|
+
* The selected boundary minimizes estimated token imbalance, then unit-count
|
|
33
|
+
* imbalance when zero-priced units tie. Returning null proves the chunk is one
|
|
34
|
+
* indivisible unit and cannot make further progress.
|
|
35
|
+
* @param messages - one failed chronological chunk.
|
|
36
|
+
* @param estimate - shared message estimator.
|
|
37
|
+
* @returns two non-empty balanced halves, or null for one indivisible unit.
|
|
38
|
+
*/
|
|
39
|
+
export declare function splitMessageChunk(messages: readonly Message[], estimate: EstimateMessage): [Message[], Message[]] | null;
|
|
40
|
+
//# sourceMappingURL=hierarchical-planner.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Structured map/reduce prompts and partial-summary framing. */
|
|
2
|
+
/** Required final checkpoint sections, in durable order. */
|
|
3
|
+
export declare const SUMMARY_SECTIONS: readonly ["Primary Request and Intent", "Key Technical Concepts", "Files and Code", "Errors and Fixes", "Pending Jobs", "Current Work", "Next Step", "Critical Context"];
|
|
4
|
+
/**
|
|
5
|
+
* Build the instruction for one chronological source span.
|
|
6
|
+
* Source-unit coordinates remain stable when a rejected span is bisected.
|
|
7
|
+
* @param start - inclusive one-based source-unit ordinal.
|
|
8
|
+
* @param end - inclusive one-based source-unit ordinal.
|
|
9
|
+
* @param total - total source units in the map stage.
|
|
10
|
+
* @returns final user instruction for the auxiliary call.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mapInstruction(start: number, end: number, total: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build the instruction for one recursive reduction span.
|
|
15
|
+
* @param round - one-based reduce round.
|
|
16
|
+
* @param start - inclusive one-based source-unit ordinal represented by the group.
|
|
17
|
+
* @param end - inclusive one-based source-unit ordinal represented by the group.
|
|
18
|
+
* @param total - total source units represented by the complete map stage.
|
|
19
|
+
* @returns final user instruction for the auxiliary call.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reduceInstruction(round: number, start: number, end: number, total: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Frame one partial checkpoint as reducer data.
|
|
24
|
+
* @param text - validated checkpoint Markdown.
|
|
25
|
+
* @param start - inclusive one-based source-unit ordinal represented by the summary.
|
|
26
|
+
* @param end - inclusive one-based source-unit ordinal represented by the summary.
|
|
27
|
+
* @returns tagged reducer input text.
|
|
28
|
+
*/
|
|
29
|
+
export declare function framePartialSummary(text: string, start: number, end: number): string;
|
|
30
|
+
/**
|
|
31
|
+
* Validate the fixed checkpoint section set and return normalized text.
|
|
32
|
+
* @param blocks - text blocks produced by one stage.
|
|
33
|
+
* @param stage - diagnostic stage label.
|
|
34
|
+
* @returns joined non-empty Markdown.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateStructuredSummary(blocks: readonly {
|
|
37
|
+
type: 'text';
|
|
38
|
+
text: string;
|
|
39
|
+
}[], stage: string): string;
|
|
40
|
+
//# sourceMappingURL=hierarchical-prompts.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Bounded map-reduce fallback for oversized compaction inputs. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
4
|
+
import type { TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
import type { ResolvedConfig, ResolvedTargetPolicy } from './types.ts';
|
|
6
|
+
import type { SummarizationInput, SummaryResult } from './summarizer.ts';
|
|
7
|
+
type OneShotSummarize = () => Promise<SummaryResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Preserve the cache-reusing one-shot path when it fits and otherwise summarize
|
|
10
|
+
* bounded chronological chunks followed by recursive reductions.
|
|
11
|
+
* @param ctx - compaction provider context.
|
|
12
|
+
* @param config - resolved basic and hierarchy policy.
|
|
13
|
+
* @param input - selected replay input owned by the stock region transaction.
|
|
14
|
+
* @param agent - agent whose route and session own the auxiliary calls.
|
|
15
|
+
* @param oneShot - existing stock summarizer used for fitting inputs.
|
|
16
|
+
* @param signal - optional operation cancellation.
|
|
17
|
+
* @returns one final checkpoint summary for the stock transaction.
|
|
18
|
+
*/
|
|
19
|
+
export declare function summarizeWithHierarchy(ctx: Context, config: ResolvedConfig | ResolvedTargetPolicy, input: SummarizationInput, agent: Agent, oneShot: OneShotSummarize, signal?: AbortSignal): Promise<SummaryResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Sum disjoint provider usage across every successful map and reduce call.
|
|
22
|
+
* @param usages - stage usage values in call order.
|
|
23
|
+
* @returns aggregate usage, or undefined when any stage omitted usage.
|
|
24
|
+
*/
|
|
25
|
+
export declare function aggregateUsage(usages: readonly (TokenUsage | undefined)[]): TokenUsage | undefined;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=hierarchical.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic replay-aware compaction backend.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-compaction-basic
|
|
5
|
+
*/
|
|
6
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
|
+
import { CompactionEngine } from '@deepseek-ai/dsh-compaction';
|
|
9
|
+
import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction';
|
|
10
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
11
|
+
import type { CommandId } from '@deepseek-ai/dsh-commands/brand';
|
|
12
|
+
import type { SummarizationInput, SummaryResult } from './summarizer.ts';
|
|
13
|
+
import type { BasicCompactionConfig, ResolvedConfig } from './types.ts';
|
|
14
|
+
export type { BasicCompactionConfig, CompactionPolicyConfig, ModelCompactPolicyConfig, ResolvedCompactSpec, ResolvedConfig, ResolvedRetention, ResolvedTargetPolicy, } from './types.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Dependency-light compaction backend using `ctx.tokenMeter` for pressure,
|
|
17
|
+
* retention, cited source events, and summary-convergence pricing.
|
|
18
|
+
*
|
|
19
|
+
* `summarize()` is the sole subclass customization hook; the replay and durable
|
|
20
|
+
* mutation strategy stays fixed so every pricing decision uses the singleton
|
|
21
|
+
* token meter.
|
|
22
|
+
*/
|
|
23
|
+
export declare class BasicCompactionEngine extends CompactionEngine {
|
|
24
|
+
static inject: string[];
|
|
25
|
+
static Config: z<BasicCompactionConfig>;
|
|
26
|
+
/** Resolved and validated compaction configuration. */
|
|
27
|
+
readonly config: ResolvedConfig;
|
|
28
|
+
private readonly warnedPressureConfigTargets;
|
|
29
|
+
private readonly overflowRetries;
|
|
30
|
+
private readonly overflowAgents;
|
|
31
|
+
constructor(ctx: Context, config?: BasicCompactionConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Register automatic between-step pressure and model-request overflow
|
|
34
|
+
* recovery. `compactIfNeeded` stays dynamically dispatched so subclass
|
|
35
|
+
* overrides are honored at event time.
|
|
36
|
+
*/
|
|
37
|
+
private _registerAutomaticCompaction;
|
|
38
|
+
/**
|
|
39
|
+
* Summarize the replayed conversation through the cache-reusing one-shot
|
|
40
|
+
* request when it fits, or bounded hierarchical calls when it cannot fit or
|
|
41
|
+
* the Provider confirms a context overflow. Override this sole hook for a
|
|
42
|
+
* template or remote summarizer.
|
|
43
|
+
* @param input - replayed conversation prefix (system, tools, and leading messages) to condense.
|
|
44
|
+
* @param agent - supplies routed-model history, fallback model, and session id.
|
|
45
|
+
* @param signal - optional cancellation forwarded to the adapter.
|
|
46
|
+
* @returns safe text summary blocks and the exact auxiliary call envelope and output.
|
|
47
|
+
*/
|
|
48
|
+
protected summarize(input: SummarizationInput, agent: Agent, signal?: AbortSignal): Promise<SummaryResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Compact for replayed step-boundary pressure or one provider-confirmed context
|
|
51
|
+
* overflow. Both triggers price the latest durable routed request envelope;
|
|
52
|
+
* overflow bypasses the normal threshold and retained-tail policy so it can
|
|
53
|
+
* force one useful balanced reduction.
|
|
54
|
+
* @param agent - agent whose latest durable routed request is measured.
|
|
55
|
+
* @param trigger - normal step-boundary pressure or context-overflow recovery.
|
|
56
|
+
* @param signal - live turn cancellation signal forwarded to summarization.
|
|
57
|
+
* @returns the latest summary compaction result, or `null` when no summary ran.
|
|
58
|
+
*/
|
|
59
|
+
compactIfNeeded(agent: Agent, trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Compact one inclusive positional range from the agent-owned surface using
|
|
62
|
+
* the effective token meter for all retention and shrink pricing.
|
|
63
|
+
* @param start - inclusive first surface-node seq.
|
|
64
|
+
* @param end - inclusive last surface-node seq.
|
|
65
|
+
* @param agent - owner of the target session, used by the summarizer.
|
|
66
|
+
* @param signal - optional summarization cancellation signal.
|
|
67
|
+
* @returns the successful durable compaction result.
|
|
68
|
+
*/
|
|
69
|
+
compactRegion(start: number, end: number, agent: Agent, signal?: AbortSignal): Promise<CompactionResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Force one useful idle-session compaction below the pressure threshold, and
|
|
72
|
+
* resolve only after its standalone marker pair is durably checkpointed.
|
|
73
|
+
* @param agent - idle agent whose next-turn admission this call reserves.
|
|
74
|
+
* @param signal - cancellation scoped to this compaction request.
|
|
75
|
+
* @param sourceCommandId - initiating command identity for presentation correlation.
|
|
76
|
+
* @returns the committed result, or `null` when no safe useful range exists.
|
|
77
|
+
*/
|
|
78
|
+
compactNow(agent: Agent, signal: AbortSignal, sourceCommandId?: CommandId): Promise<CompactionResult | null>;
|
|
79
|
+
/** Bind the effective token meter and dynamically dispatched summarizer hook. */
|
|
80
|
+
private regionDependencies;
|
|
81
|
+
}
|
|
82
|
+
export default BasicCompactionEngine;
|
|
83
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-compaction-basic`.
|
|
3
|
+
* @module @deepseek-ai/dsh-compaction-basic/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "compaction-basic-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface retention selection and the shared log-recorded compaction
|
|
3
|
+
* transaction for automatic open-turn and manual idle-session compaction.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-compaction-basic/region
|
|
6
|
+
*/
|
|
7
|
+
import type { CompactionResult } from '@deepseek-ai/dsh-compaction';
|
|
8
|
+
import type { CommandId } from '@deepseek-ai/dsh-commands/brand';
|
|
9
|
+
import type { TokenMeasurement, TokenMeter } from '@deepseek-ai/dsh-token-meter';
|
|
10
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
11
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
12
|
+
import type { SummarizationInput, SummaryResult } from './summarizer.ts';
|
|
13
|
+
interface RegionDependencies {
|
|
14
|
+
readonly meter: TokenMeter;
|
|
15
|
+
summarize(input: SummarizationInput, agent: Agent, signal?: AbortSignal): Promise<SummaryResult>;
|
|
16
|
+
}
|
|
17
|
+
interface CompactionTransactionOptions {
|
|
18
|
+
/** `current-turn` derives a numbered owner; `null` writes a standalone bracket. */
|
|
19
|
+
readonly owner: 'current-turn' | null;
|
|
20
|
+
/** Surface relationship that must survive asynchronous summarization. */
|
|
21
|
+
readonly stability: 'whole-surface' | 'selected-span';
|
|
22
|
+
/** Optional durability checkpoint after a successfully closed bracket. */
|
|
23
|
+
readonly flush?: () => Promise<void>;
|
|
24
|
+
/** Manual command that initiated this transaction, when present. */
|
|
25
|
+
readonly sourceCommandId?: CommandId;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the next head-anchored range while retaining a priced recent tail
|
|
29
|
+
* and never splitting an assistant tool-call/result pair.
|
|
30
|
+
* @param session - session supplying authoritative current surface positions.
|
|
31
|
+
* @param measurement - unified pressure and surface measurement from the conversation meter.
|
|
32
|
+
* @param retainTokens - minimum recent tail budget retained verbatim.
|
|
33
|
+
* @returns the inclusive positional seq range to compact, or `null`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function selectCompactableRange(session: Session, measurement: TokenMeasurement, retainTokens: number): {
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
} | null;
|
|
39
|
+
/**
|
|
40
|
+
* Run the single compaction transaction over one selected positional span.
|
|
41
|
+
* Selection and validation are read-only. Idle/log validation and
|
|
42
|
+
* `compaction/start` are synchronously adjacent, so the durable opening marker is
|
|
43
|
+
* the compaction lock before summarization yields. Every later failure makes
|
|
44
|
+
* exactly one `compaction/end` attempt; a failed close deliberately leaves the
|
|
45
|
+
* unmatched start detectable.
|
|
46
|
+
* @param dependencies - conversation meter and dynamically dispatched summarizer hook.
|
|
47
|
+
* @param session - session whose surface is mutated.
|
|
48
|
+
* @param start - inclusive first surface-node seq.
|
|
49
|
+
* @param end - inclusive last surface-node seq.
|
|
50
|
+
* @param agent - agent used by the summarizer.
|
|
51
|
+
* @param options - bracket owner, stability rule, and optional durability checkpoint.
|
|
52
|
+
* @param signal - optional summarization cancellation signal.
|
|
53
|
+
* @returns the successful durable compaction result.
|
|
54
|
+
*/
|
|
55
|
+
export declare function compactSurfaceRegion(dependencies: RegionDependencies, session: Session, start: number, end: number, agent: Agent, options: CompactionTransactionOptions, signal?: AbortSignal): Promise<CompactionResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Recheck the durable compaction lock after an asynchronous policy decision.
|
|
58
|
+
* @param session - session whose latest marker state is inspected.
|
|
59
|
+
* @param stage - operation label included in the busy diagnostic.
|
|
60
|
+
*/
|
|
61
|
+
export declare function assertNoActiveCompaction(session: Session, stage: string): void;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=region.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default one-shot summarization and durable checkpoint framing.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-compaction-basic/summarizer
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import type { ContentBlock, Message, TokenUsage, ToolSchema } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
9
|
+
interface SummaryConfig {
|
|
10
|
+
readonly summarizationProvider: string;
|
|
11
|
+
readonly summarizationModel: string;
|
|
12
|
+
readonly maxTokens: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The summarization directive, delivered as the FINAL user message after the
|
|
16
|
+
* replayed conversation rather than as a distinct summarizer system prompt.
|
|
17
|
+
* Keeping the conversation's own system prompt, tools, and message prefix in
|
|
18
|
+
* front of it makes the auxiliary call a genuine prefix of the last routed
|
|
19
|
+
* request, so the provider's KV cache is reused instead of invalidated.
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMPACTION_INSTRUCTION: string;
|
|
22
|
+
/**
|
|
23
|
+
* The replayed conversation surface the summarizer condenses. Reproducing the
|
|
24
|
+
* last routed request's system prompt, tools, and leading messages verbatim
|
|
25
|
+
* lets the auxiliary call reuse the provider's warm prefix cache; the trailing
|
|
26
|
+
* compaction instruction is then the only novel input.
|
|
27
|
+
*/
|
|
28
|
+
export interface SummarizationInput {
|
|
29
|
+
/** The conversation's own system prompt, reused for prefix-cache alignment; absent for a system-less request. */
|
|
30
|
+
readonly system?: string;
|
|
31
|
+
/** The conversation's tool schemas, reused for prefix-cache alignment; absent when the request carried none. */
|
|
32
|
+
readonly tools?: readonly ToolSchema[];
|
|
33
|
+
/** The shadowed region, in surface order, that precedes the compaction instruction. */
|
|
34
|
+
readonly messages: readonly Message[];
|
|
35
|
+
}
|
|
36
|
+
/** Safe summary content plus the exact auxiliary call envelope recorded with it. */
|
|
37
|
+
export type SummaryResult = {
|
|
38
|
+
summary: ContentBlock[];
|
|
39
|
+
provider: string;
|
|
40
|
+
model: string;
|
|
41
|
+
maxTokens?: number;
|
|
42
|
+
/** Provider-reported usage for this summarization request. */
|
|
43
|
+
usage?: TokenUsage;
|
|
44
|
+
} & ({
|
|
45
|
+
/** Complete provider output before the text-only summary projection. */
|
|
46
|
+
rawOutput: ContentBlock[];
|
|
47
|
+
/** Identifies exactly one call through this context's `ctx.llm.stream()`. */
|
|
48
|
+
llmStreamCall: true;
|
|
49
|
+
} | {
|
|
50
|
+
/** Optional complete output from an unmarked template, remote, or other summarizer. */
|
|
51
|
+
rawOutput?: ContentBlock[];
|
|
52
|
+
/** An unmarked result does not identify a call through this context's LLM seam. */
|
|
53
|
+
llmStreamCall?: never;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Run the default cache-reusing `ctx.llm.stream()` summarization call: replay
|
|
57
|
+
* the conversation prefix, then append the compaction instruction as the final
|
|
58
|
+
* user message so the provider's warm prefix cache is reused.
|
|
59
|
+
* @param ctx - context providing the LLM service.
|
|
60
|
+
* @param config - resolved backend configuration.
|
|
61
|
+
* @param input - replayed conversation prefix (system, tools, and leading messages) to condense.
|
|
62
|
+
* @param agent - supplies routed-model history, fallback model, and session id.
|
|
63
|
+
* @param signal - optional cancellation forwarded to the adapter.
|
|
64
|
+
* @returns safe text-only summary blocks and the exact call envelope and output.
|
|
65
|
+
*/
|
|
66
|
+
export declare function summarizeWithLlm(ctx: Context, config: SummaryConfig, input: SummarizationInput, agent: Agent, signal?: AbortSignal): Promise<SummaryResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Wrap raw summary blocks in the durable checkpoint framing.
|
|
69
|
+
* @param summary - safe text-only model output.
|
|
70
|
+
* @returns content for the synthesized replacement user message.
|
|
71
|
+
*/
|
|
72
|
+
export declare function frameSummary(summary: readonly ContentBlock[]): ContentBlock[];
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=summarizer.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration vocabulary for the replay-aware basic compaction backend.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-compaction-basic/types
|
|
5
|
+
*/
|
|
6
|
+
import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
/** Policy fields shared by the default policy and exact model overrides. */
|
|
8
|
+
export interface CompactionPolicyConfig {
|
|
9
|
+
/** Compact at this fraction of the model's context window. Defaults to `0.8`. */
|
|
10
|
+
thresholdRatio?: number;
|
|
11
|
+
/** Recent context retained as a fraction of the model's window. Defaults to `0.16`. */
|
|
12
|
+
retainRatio?: number;
|
|
13
|
+
/** Absolute recent-context budget; mutually exclusive with `retainRatio`. */
|
|
14
|
+
retainTokens?: number;
|
|
15
|
+
/** Summary provider; set together with `summarizationModel`, or inherit the conversation target. */
|
|
16
|
+
summarizationProvider?: string;
|
|
17
|
+
/** Summary model; set together with `summarizationProvider`, or inherit the conversation target. */
|
|
18
|
+
summarizationModel?: string;
|
|
19
|
+
/** Provider generation cap for summarization. Defaults to `8192`. */
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
/** Extra attempts after the first compaction when pressure remains above threshold. Defaults to `1`. */
|
|
22
|
+
compactionRetries?: number;
|
|
23
|
+
/** Maximum retries after canonical context overflow; `0` disables recovery. Defaults to `1`. */
|
|
24
|
+
maxOverflowRetries?: number;
|
|
25
|
+
/** Fraction of the summary model window available to each hierarchical stage input. Defaults to `0.6`. */
|
|
26
|
+
chunkInputRatio?: number;
|
|
27
|
+
/** Generation cap for one hierarchical map call. Defaults to `4096`. */
|
|
28
|
+
mapMaxTokens?: number;
|
|
29
|
+
/** Generation cap for one hierarchical reduce call. Defaults to `8192`. */
|
|
30
|
+
reduceMaxTokens?: number;
|
|
31
|
+
/** Maximum recursive reduce rounds after mapping. Defaults to `4`. */
|
|
32
|
+
maxDepth?: number;
|
|
33
|
+
/** Replay tool schemas in hierarchical stages. Defaults to `false`. */
|
|
34
|
+
replayTools?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** Exact provider/model override merged over the default compaction policy. */
|
|
37
|
+
export interface ModelCompactPolicyConfig extends CompactionPolicyConfig {
|
|
38
|
+
/** Registered provider route to match. */
|
|
39
|
+
provider: string;
|
|
40
|
+
/** Exact routed model id to match within `provider`. */
|
|
41
|
+
model: string;
|
|
42
|
+
}
|
|
43
|
+
/** Basic compaction configuration with an optional exact-target policy table. */
|
|
44
|
+
export interface BasicCompactionConfig extends CompactionPolicyConfig {
|
|
45
|
+
/** Exact provider/model overrides; duplicate targets fail plugin load. */
|
|
46
|
+
modelPolicies?: ModelCompactPolicyConfig[];
|
|
47
|
+
/** Enable automatic step-boundary pressure and overflow-recovery listeners. Defaults to `true`. */
|
|
48
|
+
auto?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** Exactly one validated retention form. */
|
|
51
|
+
export type ResolvedRetention = {
|
|
52
|
+
readonly retainRatio: number;
|
|
53
|
+
readonly retainTokens?: never;
|
|
54
|
+
} | {
|
|
55
|
+
readonly retainRatio?: never;
|
|
56
|
+
readonly retainTokens: number;
|
|
57
|
+
};
|
|
58
|
+
/** Validated policy fields shared before and after exact-target matching. */
|
|
59
|
+
interface ResolvedPolicyFields {
|
|
60
|
+
readonly thresholdRatio: number;
|
|
61
|
+
readonly summarizationProvider: string;
|
|
62
|
+
readonly summarizationModel: string;
|
|
63
|
+
readonly maxTokens: number;
|
|
64
|
+
readonly compactionRetries: number;
|
|
65
|
+
readonly maxOverflowRetries: number;
|
|
66
|
+
readonly chunkInputRatio: number;
|
|
67
|
+
readonly mapMaxTokens: number;
|
|
68
|
+
readonly reduceMaxTokens: number;
|
|
69
|
+
readonly maxDepth: number;
|
|
70
|
+
readonly replayTools: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** Validated hierarchy policy used by one summary target. */
|
|
73
|
+
export type ResolvedHierarchyConfig = Pick<ResolvedPolicyFields, 'chunkInputRatio' | 'mapMaxTokens' | 'reduceMaxTokens' | 'maxDepth' | 'replayTools'>;
|
|
74
|
+
/** Validated immutable config whose target-specific defaults remain unresolved. */
|
|
75
|
+
export type ResolvedConfig = ResolvedPolicyFields & ResolvedRetention & {
|
|
76
|
+
readonly modelPolicies: readonly Readonly<ModelCompactPolicyConfig>[];
|
|
77
|
+
readonly auto: boolean;
|
|
78
|
+
};
|
|
79
|
+
/** Fully merged policy for one routed conversation target, before capacity scaling. */
|
|
80
|
+
export type ResolvedTargetPolicy = ResolvedPolicyFields & ResolvedRetention & {
|
|
81
|
+
readonly target: Pick<LlmCallConfig, 'provider' | 'model'>;
|
|
82
|
+
};
|
|
83
|
+
/** One routed model's concrete pressure and retention budget. */
|
|
84
|
+
export type ResolvedCompactSpec = Omit<ResolvedTargetPolicy, 'retainRatio' | 'retainTokens'> & {
|
|
85
|
+
readonly contextWindow: number;
|
|
86
|
+
readonly thresholdTokens: number;
|
|
87
|
+
readonly retainTokens: number;
|
|
88
|
+
};
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crazx/dsh-compaction-basic",
|
|
3
|
+
"description": "Token-meter-driven compaction policy and LLM summarization backend for the DeepSeek Harness",
|
|
4
|
+
"version": "0.1.1-rc.1.zw.2",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/aka-danielZhang/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/compaction/compaction-basic"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./src/*": "./src/*",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib/index.js",
|
|
30
|
+
"lib/invariant.js",
|
|
31
|
+
"lib/types/**/*.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@deepseek-ai/dsh-agent": "^0.1.1-rc.1",
|
|
36
|
+
"@deepseek-ai/dsh-compaction": "^0.1.1-rc.1",
|
|
37
|
+
"@deepseek-ai/dsh-commands": "^0.1.1-rc.1",
|
|
38
|
+
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.1",
|
|
39
|
+
"@deepseek-ai/dsh-llm": "^0.1.1-rc.1",
|
|
40
|
+
"@deepseek-ai/dsh-session": "^0.1.1-rc.1",
|
|
41
|
+
"@deepseek-ai/dsh-token-meter": "^0.1.1-rc.1",
|
|
42
|
+
"@deepseek-ai/dsh-compaction-tool-result-pruner": "^0.1.1-rc.1",
|
|
43
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@deepseek-ai/dsh-compaction-tool-result-pruner": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@deepseek-ai/schemastery": "^3.18.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@deepseek-ai/cordis-plugin-include": "^1.0.6",
|
|
55
|
+
"@deepseek-ai/cordis-plugin-loader": "^1.0.2",
|
|
56
|
+
"@deepseek-ai/dsh-agent": "^0.1.1-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-agent-loop": "^0.1.1-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "^0.1.1-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-compaction": "^0.1.1-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-commands": "^0.1.1-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-llm": "^0.1.1-rc.1",
|
|
63
|
+
"@deepseek-ai/dsh-llm-retry": "^0.1.1-rc.1",
|
|
64
|
+
"@deepseek-ai/dsh-session": "^0.1.1-rc.1",
|
|
65
|
+
"@deepseek-ai/dsh-token-meter": "^0.1.1-rc.1",
|
|
66
|
+
"@deepseek-ai/dsh-compaction-tool-result-pruner": "^0.1.1-rc.1",
|
|
67
|
+
"@deepseek-ai/dsh-tools": "^0.1.1-rc.1",
|
|
68
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
69
|
+
}
|
|
70
|
+
}
|