dsh-model-switch 0.4.20 → 0.4.22

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.
@@ -1,48 +0,0 @@
1
- /**
2
- * Plan-exit compaction vocabulary shared by the card and the Host RPC.
3
- *
4
- * The card decides *when* to ask (only an approval that switches the execution
5
- * model); the Host owns measurement, threshold policy, and the compaction
6
- * itself. Failures are explicit: the Plan stays pending and can be retried,
7
- * while an empty history is a completed attempt that may proceed.
8
- *
9
- * @module dsh-model-switch/picker/plan-compact
10
- */
11
- /** One plan-exit compaction request: the session and its switched-to route. */
12
- export interface PlanCompactRequest {
13
- readonly sessionId: string;
14
- readonly provider: string;
15
- readonly model: string;
16
- }
17
- /**
18
- * Outcome of one plan-exit compaction request.
19
- *
20
- * - `disabled` — the threshold is 0; execution proceeds untouched.
21
- * - `skipped` — the estimate is at or below the threshold (or unknown); proceed.
22
- * - `compacted` — a useful range was summarized with the switched-to model.
23
- * - `empty` — nothing safe could be compacted; proceed with a notice.
24
- * - `error` — compaction did not complete; the Plan must stay pending.
25
- */
26
- export type PlanCompactStatus = 'disabled' | 'skipped' | 'compacted' | 'empty' | 'error';
27
- export interface PlanCompactOutcome {
28
- readonly status: PlanCompactStatus;
29
- /** Estimated next-request input tokens, when measurement succeeded. */
30
- readonly estimate?: number;
31
- /** The token threshold applied to this decision. */
32
- readonly threshold?: number;
33
- /** Failure detail; required only for `error`. */
34
- readonly message?: string;
35
- }
36
- /** Resolve the Host's verdict for one measured context against the threshold. */
37
- export type PlanCompactDecision = 'disabled' | 'skip' | 'compact';
38
- /** Whether the user's threshold arms the plan-exit mechanism at all. */
39
- export declare function planCompactEnabled(threshold: number): boolean;
40
- /**
41
- * Decide whether a plan exit must compact before it switches models.
42
- * @param threshold — user-configured token threshold; 0 disables the mechanism.
43
- * @param estimate — measured next-request input tokens.
44
- * @returns `disabled` when off, `compact` only above the threshold, else `skip`.
45
- */
46
- export declare function planCompactDecision(threshold: number, estimate: number): PlanCompactDecision;
47
- /** Runtime guard for the wire value returned by the Host RPC. */
48
- export declare function isPlanCompactOutcome(value: unknown): value is PlanCompactOutcome;
@@ -1,82 +0,0 @@
1
- /**
2
- * Plan-exit compaction on the Host: measure, threshold, then summarize the
3
- * history with the switched-to model before the approval resumes the session.
4
- *
5
- * The approval answer lands inside a still-open `exit_plan_mode` tool call, so
6
- * the agent phase is `running` and the idle-only `compactNow` seam is off
7
- * limits. This module therefore uses `compactIfNeeded(agent, 'context-overflow')`
8
- * — the same turn-safe, threshold-free operation official overflow recovery
9
- * uses — under an isolated `compaction-basic` engine configured to summarize
10
- * with the route the human just chose. The user's threshold decides *whether*
11
- * to call it; the engine's overflow policy guarantees one useful balanced
12
- * reduction whenever a safe range exists.
13
- *
14
- * @module dsh-model-switch/plan-compact
15
- */
16
- import type { Context } from '@deepseek-ai/cordis';
17
- import type { Agent } from '@deepseek-ai/dsh-agent';
18
- import { type Session } from '@deepseek-ai/dsh-session';
19
- import type { ModelSwitchSettings } from './host-settings.js';
20
- import { type PlanCompactOutcome, type PlanCompactRequest } from './picker/plan-compact.js';
21
- import { type SwitchRoute } from './switch-compact.js';
22
- /** Receives one card-initiated compaction request over the plugin RPC. */
23
- export type PlanCompactRunner = (request: PlanCompactRequest, signal: AbortSignal) => Promise<PlanCompactOutcome>;
24
- /** The compaction engine face this module drives (compaction-basic's service). */
25
- export interface PlanCompactEngine {
26
- compactIfNeeded(agent: Agent, trigger: 'context-overflow', signal: AbortSignal): Promise<unknown>;
27
- }
28
- /** Minimal measurement face so unit tests can price a stubbed session. */
29
- export interface PlanCompactMeter {
30
- measure(session: Session, header?: unknown): {
31
- totalTokens: number;
32
- };
33
- }
34
- /**
35
- * Estimate the next request's input tokens under both envelopes.
36
- *
37
- * Takes the larger of the target-route heuristic price and the previous
38
- * envelope's anchored price — the same conservative stance the send-time
39
- * switch guard takes, so dense histories cannot under-trigger the threshold.
40
- *
41
- * @param meter — replay token meter.
42
- * @param session — session about to resume.
43
- * @param route — the switched-to provider/model.
44
- * @returns Estimated tokens, or undefined when no prior request exists to price.
45
- */
46
- export declare function estimatePlanExitTokens(meter: PlanCompactMeter, session: Session, route: SwitchRoute): number | undefined;
47
- /** Shape compaction-basic's default export exposes to this module. */
48
- export interface PlanCompactEngineModule {
49
- default: new (ctx: Context, config: {
50
- auto: false;
51
- summarizationProvider: string;
52
- summarizationModel: string;
53
- compactionRetries: 0;
54
- }) => unknown;
55
- }
56
- /**
57
- * Drive one compaction through an already-mounted isolated engine.
58
- * @param engine — engine whose overflow policy selects the range.
59
- * @param agent — live agent owning the session.
60
- * @param signal — cancellation scoped to this request.
61
- * @returns `empty` when no safe range exists, `compacted` after a summary, `error` on failure.
62
- */
63
- export declare function planCompactWithEngine(engine: Pick<PlanCompactEngine, 'compactIfNeeded'>, agent: Agent, signal: AbortSignal): Promise<PlanCompactOutcome>;
64
- /**
65
- * Mount an isolated compaction-basic engine pinned to the switched-to route
66
- * and run one overflow-policy reduction over the agent's session.
67
- * @param ctx — host context that owns token metering and session state.
68
- * @param agent — live agent about to resume the approved plan.
69
- * @param route — provider/model whose model must write the summary.
70
- * @param signal — cancellation scoped to this request.
71
- * @param loadEngine — dynamic import seam (tests inject the fake module).
72
- * @returns The compaction outcome for this request.
73
- */
74
- export declare function runPlanCompaction(ctx: Context, agent: Agent, route: SwitchRoute, signal: AbortSignal, loadEngine?: () => Promise<PlanCompactEngineModule>): Promise<PlanCompactOutcome>;
75
- /**
76
- * Build the `plan-compact` RPC runner bound to this host's live settings.
77
- * @param ctx — host context resolving the live agent registry.
78
- * @param settings — live Model Switch settings (`planCompactThreshold`).
79
- * @param loadEngine — dynamic import seam (tests inject the fake module).
80
- * @returns The runner the connection RPC dispatches to.
81
- */
82
- export declare function planCompactRunner(ctx: Context, settings: () => ModelSwitchSettings, loadEngine?: () => Promise<PlanCompactEngineModule>): PlanCompactRunner;