billion-context-pi 0.1.38 → 0.1.40

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/dist/config.d.ts CHANGED
@@ -12,9 +12,11 @@ export interface DelegateConfig {
12
12
  * counted as part of the main session totals. */
13
13
  displayUsage?: "merged" | "separate";
14
14
  }
15
- /** Compression tuning. All fields accept a ratio (0.75) or percent string
16
- * ("75%") where noted. */
17
- export interface CompressConfig {
15
+ /** Compression tuning fields, shared by all three levels (global, provider,
16
+ * model). Percentage fields accept a ratio (0.75) or percent string ("75%").
17
+ * Resolution is per-field, deepest-wins (model > provider > global); an
18
+ * undefined field at a deeper level does NOT clear a shallower value. */
19
+ export interface CompressSettings {
18
20
  /** Context usage percentage that triggers forced compression nudges
19
21
  * (bypasses growth-gate + cadence). Accepts a ratio (0.75) or percent
20
22
  * string ("75%"). Default: 0.75. Maps to kernel nudge.maxContextLimitPct. */
@@ -28,6 +30,23 @@ export interface CompressConfig {
28
30
  * Maps to kernel nudge.growthFloor + nudge.growthCap. */
29
31
  nudgeGrowthTokens?: number;
30
32
  }
33
+ /** Per-provider compression overrides. Carries the same tuning fields as the
34
+ * global level, plus an optional per-model map keyed by model id. */
35
+ export interface ProviderCompress extends CompressSettings {
36
+ /** Per-model overrides within this provider, keyed by model id
37
+ * (e.g. "claude-sonnet-4-5"). */
38
+ models?: Record<string, CompressSettings>;
39
+ }
40
+ /** Compression tuning. Top-level fields are global defaults; `providers`
41
+ * optionally narrows them per Pi provider name and per model id. The active
42
+ * entry is resolved live each turn from the current model
43
+ * (`ctx.model.provider` / `ctx.model.id`). */
44
+ export interface CompressConfig extends CompressSettings {
45
+ /** Per-provider (and per-model) overrides, keyed by Pi provider name
46
+ * (e.g. "anthropic", "openai", "zhipu") — the same name used in
47
+ * models.json and `pi --provider`. */
48
+ providers?: Record<string, ProviderCompress>;
49
+ }
31
50
  /**
32
51
  * Adapter configuration. Maps onto acp-kernel's `Config` plus Pi-specific knobs
33
52
  * (live model context window, protected tools, state persistence).
@@ -91,5 +110,15 @@ export declare function resolveDelegate(adapter: AdapterConfig): {
91
110
  enabled: boolean;
92
111
  displayUsage: "merged" | "separate";
93
112
  };
94
- export declare function resolveConfig(adapter: AdapterConfig, liveContextLimit: number): Config;
113
+ /** Per-field deepest-wins merge of the three compression levels (global →
114
+ * provider → model). An undefined field at a deeper level does NOT clear a
115
+ * value set at a shallower level — only a defined value overrides. */
116
+ export declare function mergeCompress(global?: CompressSettings, provider?: CompressSettings, model?: CompressSettings): CompressSettings;
117
+ /** Resolve the effective compression settings for the active model: global →
118
+ * provider (matched by Pi provider name) → model (matched by model id).
119
+ * Returns a CompressSettings whose fields are undefined when nothing is set
120
+ * at any level. The Pi adapter keys providers by name (ctx.model.provider),
121
+ * not URL — it never sees the upstream URL the way the proxy does. */
122
+ export declare function resolveCompress(compress: CompressConfig | undefined, provider: string | undefined, modelId: string | undefined): CompressSettings;
123
+ export declare function resolveConfig(adapter: AdapterConfig, liveContextLimit: number, provider?: string, modelId?: string): Config;
95
124
  export declare function parsePercent(v: number | string): number;
@@ -81,6 +81,11 @@ export declare function makeEventApplier(opts: {
81
81
  onUsage?: (usage: Usage) => void;
82
82
  onSettled?: () => void;
83
83
  }, writers: EventApplierWriters): EventApplier;
84
+ /** Resolve a wait timeout to ms. Agents frequently pass seconds (e.g. 180)
85
+ * instead of milliseconds; values below the 1s floor make no sense as a wait
86
+ * duration, so rescale them to seconds before clamping — otherwise 180 clamps
87
+ * to 1000ms and the wait times out in 1s. */
88
+ export declare function resolveWaitTimeoutMs(raw: number | undefined): number;
84
89
  declare const DelegateParams: Type.TObject<{
85
90
  agent: Type.TString;
86
91
  task: Type.TString;
@@ -0,0 +1,19 @@
1
+ export declare const DENSITY_MIN = 0.5;
2
+ export declare const DENSITY_MAX = 2.5;
3
+ export declare const MIN_DELTA_EST = 50;
4
+ export declare const CONFIRM_RATIO = 0.2;
5
+ export declare const INITIAL_DENSITY = 1;
6
+ export declare class DensityEstimator {
7
+ private models;
8
+ /** 重置指定模型(模型切换/会话开始时调用)。 */
9
+ resetModel(modelId: string): void;
10
+ /** 返回当前密度系数(未知模型返回初始 1)。 */
11
+ densityFor(modelId: string): number;
12
+ /**
13
+ * 每轮 context 事件调用。realTotal 为 provider 真实 usage(可空),
14
+ * estTotal 为本地估算总 token。postCompression 为压缩刚发生标志。
15
+ */
16
+ update(modelId: string, realTotal: number | null, estTotal: number, postCompression?: boolean): void;
17
+ /** 注入器:估算文本 token = defaultCountTokens × density。 */
18
+ estimateWithDensity(modelId: string, text: string): number;
19
+ }