@lll9p/pi-better-compaction 0.2.1 → 0.4.0

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/src/types.ts CHANGED
@@ -10,6 +10,7 @@ export const REDACTED_VALUE = "[REDACTED]";
10
10
  */
11
11
  export const RESPONSES_COMPACT_CAPABLE_APIS = ["openai-responses", "openai-codex-responses"] as const;
12
12
  export const NATIVE_COMPACTION_STRATEGY = "openai-native-compact-v1";
13
+ export const NATIVE_COMPACTION_STRATEGY_V2 = "openai-native-compact-v2";
13
14
  /** Used as CompactionEntry.summary only when no summary text could be extracted from the compact response. */
14
15
  export const NATIVE_COMPACTION_FALLBACK_SUMMARY = "[OpenAI native compaction checkpoint]";
15
16
 
@@ -23,6 +24,9 @@ export const THINKING_LEVELS: readonly ThinkingLevel[] = [
23
24
  "max",
24
25
  ];
25
26
 
27
+ export type CompactionVersion = "v1" | "v2";
28
+ export const COMPACTION_VERSIONS: readonly CompactionVersion[] = ["v1", "v2"];
29
+
26
30
  export type DebugArtifactKind =
27
31
  | "provider-request"
28
32
  | "compact-response"
@@ -45,6 +49,13 @@ export type ExtensionConfig = {
45
49
  compactionThinkingLevel: ThinkingLevel;
46
50
  /** Subset of RESPONSES_COMPACT_CAPABLE_APIS that should use the compact endpoint. */
47
51
  responsesCompactApis: string[];
52
+ /**
53
+ * Which compaction protocol to use for Responses-family APIs.
54
+ * - "v2" (default): streaming CompactionTrigger via /responses endpoint.
55
+ * - "v1": POST /responses/compact endpoint.
56
+ * V2 failures automatically fall back to V1.
57
+ */
58
+ compactionVersion: CompactionVersion;
48
59
  notifyOnLoad: boolean;
49
60
  debug: boolean;
50
61
  logProviderPayloads: boolean;
@@ -97,6 +108,7 @@ export type RedactOptions = {
97
108
  };
98
109
 
99
110
  export type NativeCompactionStrategy = typeof NATIVE_COMPACTION_STRATEGY;
111
+ export type NativeCompactionStrategyV2 = typeof NATIVE_COMPACTION_STRATEGY_V2;
100
112
 
101
113
  export type NativeCompactionRequestMeta = {
102
114
  tokensBefore?: number;
@@ -111,7 +123,7 @@ export type NativeCompactionIdentity = {
111
123
  };
112
124
 
113
125
  export type NativeCompactionDetails = NativeCompactionIdentity & {
114
- strategy: NativeCompactionStrategy;
126
+ strategy: NativeCompactionStrategy | NativeCompactionStrategyV2;
115
127
  compactedWindow: unknown[];
116
128
  compactResponseId?: string;
117
129
  createdAt: string;
@@ -240,7 +252,7 @@ export function isNativeCompactionDetails(value: unknown): value is NativeCompac
240
252
  }
241
253
 
242
254
  return (
243
- value.strategy === NATIVE_COMPACTION_STRATEGY &&
255
+ (value.strategy === NATIVE_COMPACTION_STRATEGY || value.strategy === NATIVE_COMPACTION_STRATEGY_V2) &&
244
256
  isNativeCompactionIdentity(value) &&
245
257
  Array.isArray(value.compactedWindow) &&
246
258
  value.compactedWindow.every(isCompactedWindowItem) &&
@@ -254,9 +266,12 @@ export function isNativeCompactionEntry(value: unknown): value is NativeCompacti
254
266
  return isRecord(value) && value.type === "compaction" && isNativeCompactionDetails(value.details);
255
267
  }
256
268
 
257
- export function createNativeCompactionDetails(input: CreateNativeCompactionDetailsInput): NativeCompactionDetails {
269
+ export function createNativeCompactionDetails(
270
+ input: CreateNativeCompactionDetailsInput,
271
+ strategy: NativeCompactionStrategy | NativeCompactionStrategyV2 = NATIVE_COMPACTION_STRATEGY,
272
+ ): NativeCompactionDetails {
258
273
  return {
259
- strategy: NATIVE_COMPACTION_STRATEGY,
274
+ strategy,
260
275
  provider: normalizeString(input.provider),
261
276
  api: normalizeString(input.api),
262
277
  model: normalizeString(input.model),
@@ -293,6 +308,7 @@ export const DEFAULT_EXTENSION_CONFIG: ExtensionConfig = {
293
308
  compactionModel: undefined,
294
309
  compactionThinkingLevel: "off",
295
310
  responsesCompactApis: [...RESPONSES_COMPACT_CAPABLE_APIS],
311
+ compactionVersion: "v2",
296
312
  notifyOnLoad: false,
297
313
  debug: false,
298
314
  logProviderPayloads: false,