billion-context-dsh 0.2.19 → 0.2.21
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/README.en.md +6 -6
- package/README.md +6 -6
- package/dist/host-tokens.d.ts +24 -5
- package/dist/index.d.ts +25 -1
- package/dist/index.js +132 -19
- package/dist/index.js.map +1 -1
- package/dist/tool-pairing.d.ts +36 -0
- package/dist/window.d.ts +43 -5
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local tool-pairing balance checks over the session surface.
|
|
3
|
+
*
|
|
4
|
+
* UPSTREAM: `@deepseek-ai/dsh-compaction@0.1.2-rc.1` reads the REMOVED
|
|
5
|
+
* `session.events` API in its balance cache — `extendCache` does
|
|
6
|
+
* `const events = session.events` and `eventForSeq` does `events[seq]`, so on
|
|
7
|
+
* every dsh 0.1.2 host the official `toolPairingBalancedBefore/After` helpers
|
|
8
|
+
* throw `TypeError: Cannot read properties of undefined (reading '<seq>')`.
|
|
9
|
+
* The host's API docs require compaction backends to use these helpers for
|
|
10
|
+
* edge checks, and the host's own `dsh-compaction-basic` calls them too, so
|
|
11
|
+
* ALL compaction on a 0.1.2-rc.1 host crashes (reproduced offline and pinned
|
|
12
|
+
* in issue #124; tracked in docs/dsh-porting-verification.md).
|
|
13
|
+
*
|
|
14
|
+
* This module mirrors the host's algorithm line for line (per-session cache
|
|
15
|
+
* keyed by `surface.replaceGeneration`, the `cutBalanced` fold, identical
|
|
16
|
+
* error messages) with ONE deliberate difference: events are read through the
|
|
17
|
+
* cross-version accessor `eventAtOf` (src/session-events.ts), which works on
|
|
18
|
+
* both the 0.1.0/0.1.1 lines (`events[seq]`) and 0.1.2+ (`eventAt(seq)`).
|
|
19
|
+
* DELETE this module and switch `src/region.ts` back to
|
|
20
|
+
* `@deepseek-ai/dsh-compaction`'s helpers the moment the host fix ships.
|
|
21
|
+
*/
|
|
22
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
23
|
+
/**
|
|
24
|
+
* Whether the cut immediately before a current surface sequence is tool-pairing balanced.
|
|
25
|
+
* @param session - session whose surface is checked.
|
|
26
|
+
* @param seq - event sequence whose leading cut is checked.
|
|
27
|
+
* @returns true when no unanswered tool call crosses the cut.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toolPairingBalancedBefore(session: Session, seq: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the cut immediately after a current surface sequence is tool-pairing balanced.
|
|
32
|
+
* @param session - session whose surface is checked.
|
|
33
|
+
* @param seq - event sequence whose trailing cut is checked.
|
|
34
|
+
* @returns true when no unanswered tool call crosses the cut.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toolPairingBalancedAfter(session: Session, seq: number): boolean;
|
package/dist/window.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auto context-window detection — resolve the model's real context window
|
|
3
|
-
* from the host LLM runtime instead of trusting a hardcoded config default
|
|
3
|
+
* from the host LLM runtime instead of trusting a hardcoded config default,
|
|
4
|
+
* plus the adapter's per-request output cap (the output reservation subtracted
|
|
5
|
+
* from it so pressure decisions run against the SUSTAINABLE input budget, not
|
|
6
|
+
* the raw window).
|
|
4
7
|
*
|
|
5
8
|
* `agent.ctx.llm` (the cordis `LlmRuntime` service) exposes
|
|
6
|
-
* `resolveModelInfo(provider, model)` →
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* `resolveModelInfo(provider, model)` →
|
|
10
|
+
* `{ context: { contextWindow }, defaultMaxTokens }` — the exact-route
|
|
11
|
+
* capacity the adapter learned from the provider API (pi-ai reads
|
|
12
|
+
* `context_window`/`context_length` during discovery) plus the output cap it
|
|
13
|
+
* applies when callers omit one. Probing is a standalone capability query —
|
|
14
|
+
* no request is sent.
|
|
10
15
|
* @module billion-context-dsh/window
|
|
11
16
|
*/
|
|
12
17
|
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
@@ -34,6 +39,19 @@ export interface AcpWindow {
|
|
|
34
39
|
* silently fell back to 128K and produced false emergency nudges).
|
|
35
40
|
*/
|
|
36
41
|
readonly probeFailed?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The model's TOTAL context window in tokens, before the output reservation
|
|
44
|
+
* was subtracted. Set only when `outputReserved` is set:
|
|
45
|
+
* `limit = rawLimit - outputReserved`.
|
|
46
|
+
*/
|
|
47
|
+
readonly rawLimit?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The adapter's per-request output cap (`defaultMaxTokens`) in tokens,
|
|
50
|
+
* subtracted from `rawLimit` to yield `limit` — the output reservation the
|
|
51
|
+
* provider guarantees at the end of the window on every request. Set only
|
|
52
|
+
* when the host discloses it and it is smaller than the raw window.
|
|
53
|
+
*/
|
|
54
|
+
readonly outputReserved?: number;
|
|
37
55
|
}
|
|
38
56
|
/** Human label for an AcpWindow's source (used by /acp status). */
|
|
39
57
|
export declare function windowSourceLabel(window: AcpWindow): string;
|
|
@@ -48,6 +66,26 @@ export declare function windowSourceLabel(window: AcpWindow): string;
|
|
|
48
66
|
* Returns null when the host exposes no projection or disclosed no window.
|
|
49
67
|
*/
|
|
50
68
|
export declare function projectedContextWindow(agent: Agent): number | null;
|
|
69
|
+
/** The model window plus the adapter's per-request output cap, in one probe. */
|
|
70
|
+
export interface ModelWindowProbe {
|
|
71
|
+
/** The model's total context window in tokens, when disclosed. */
|
|
72
|
+
readonly contextWindow: number | null;
|
|
73
|
+
/** The adapter's per-request output cap (`defaultMaxTokens`), when disclosed. */
|
|
74
|
+
readonly outputReservation: number | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Probe the model's real context window AND the adapter's per-request output
|
|
78
|
+
* cap in a single `resolveModelInfo` call. The cap is the output reservation
|
|
79
|
+
* the provider guarantees at the end of the window on every request —
|
|
80
|
+
* pressure decisions must run against the SUSTAINABLE input budget (window
|
|
81
|
+
* minus cap), not the raw window: a 96K window with a 16K cap carries at
|
|
82
|
+
* most 80K of input, so the raw denominator understates usage by cap/window
|
|
83
|
+
* (≈17% there — and far worse on short-window models, where the same cap is
|
|
84
|
+
* a quarter or more of the window). Returns nulls — never throws — when the
|
|
85
|
+
* host provides no llm service, discloses nothing, or the probe throws;
|
|
86
|
+
* callers keep the raw-window behavior in those cases.
|
|
87
|
+
*/
|
|
88
|
+
export declare function probeModelWindow(agent: Agent, provider: string, model: string): Promise<ModelWindowProbe>;
|
|
51
89
|
/**
|
|
52
90
|
* Probe the model's real context window. Returns null when the host provides
|
|
53
91
|
* no llm service, the adapter discloses no window, or the probe throws —
|
package/package.json
CHANGED