@context-chef/ai-sdk-middleware 1.0.4 → 1.0.5

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.md CHANGED
@@ -98,6 +98,36 @@ const model = withContextChef(openai('gpt-4o'), {
98
98
 
99
99
  The middleware automatically extracts token usage from `generateText` and `streamText` responses and feeds it back to the compression engine. No manual `reportTokenUsage()` calls needed.
100
100
 
101
+ ### Compact (Mechanical Clearing)
102
+
103
+ Zero-LLM-cost content clearing for thinking blocks and tool results:
104
+
105
+ ```typescript
106
+ const model = withContextChef(openai('gpt-4o'), {
107
+ contextWindow: 128_000,
108
+ compact: {
109
+ clear: ['thinking', { target: 'tool-result', keepRecent: 5 }],
110
+ },
111
+ });
112
+ ```
113
+
114
+ > **Important: compact + compress interaction**
115
+ >
116
+ > When using `compact` together with `compress`, only clear `thinking` in compact:
117
+ >
118
+ > ```typescript
119
+ > const model = withContextChef(openai('gpt-4o'), {
120
+ > contextWindow: 128_000,
121
+ > compact: { clear: ['thinking'] }, // thinking only
122
+ > compress: { model: openai('gpt-4o-mini') },
123
+ > });
124
+ > ```
125
+ >
126
+ > Clearing `tool-result` before compression causes the compression model to receive
127
+ > empty placeholders instead of actual tool outputs, producing low-quality summaries.
128
+ > Compression's turn-based splitting already manages history length — use `compact`
129
+ > for `tool-result` clearing only when `compress` is **not** configured.
130
+
101
131
  ## API
102
132
 
103
133
  ### `withContextChef(model, options)`
@@ -123,6 +153,7 @@ const wrappedModel = withContextChef(model, options);
123
153
  | `truncate.headChars` | `number` | No | Characters to preserve from start (default: `0`) |
124
154
  | `truncate.tailChars` | `number` | No | Characters to preserve from end (default: `1000`) |
125
155
  | `truncate.storage` | `VFSStorageAdapter` | No | Storage adapter to persist original content before truncation |
156
+ | `compact` | `CompactConfig` | No | Mechanical content clearing (thinking, tool-result). When combined with `compress`, use `clear: ['thinking']` only |
126
157
  | `tokenizer` | `(msgs) => number` | No | Custom tokenizer for precise counting |
127
158
  | `onCompress` | `(summary, count) => void` | No | Hook called after compression |
128
159
 
package/dist/index.d.cts CHANGED
@@ -27,6 +27,12 @@ interface CompressOptions {
27
27
  /**
28
28
  * Mechanical compaction options — zero LLM cost.
29
29
  * Runs before LLM-based compression to reduce token usage at no cost.
30
+ *
31
+ * **Important:** When using together with `compress`, only clear `thinking`.
32
+ * Clearing `tool-result` before compression causes the compression model to
33
+ * receive empty placeholders instead of actual tool outputs, producing
34
+ * low-quality summaries. Leave tool-result management to compression's
35
+ * turn-based splitting.
30
36
  */
31
37
  interface CompactConfig {
32
38
  /** Which content types to clear from history. */
@@ -60,6 +66,9 @@ interface ContextChefOptions {
60
66
  /**
61
67
  * Mechanical compaction before LLM compression.
62
68
  * Clears specified content types (tool-result, thinking) at zero LLM cost.
69
+ *
70
+ * When combined with `compress`, use `clear: ['thinking']` only.
71
+ * See CompactConfig for details.
63
72
  */
64
73
  compact?: CompactConfig;
65
74
  /**
package/dist/index.d.mts CHANGED
@@ -27,6 +27,12 @@ interface CompressOptions {
27
27
  /**
28
28
  * Mechanical compaction options — zero LLM cost.
29
29
  * Runs before LLM-based compression to reduce token usage at no cost.
30
+ *
31
+ * **Important:** When using together with `compress`, only clear `thinking`.
32
+ * Clearing `tool-result` before compression causes the compression model to
33
+ * receive empty placeholders instead of actual tool outputs, producing
34
+ * low-quality summaries. Leave tool-result management to compression's
35
+ * turn-based splitting.
30
36
  */
31
37
  interface CompactConfig {
32
38
  /** Which content types to clear from history. */
@@ -60,6 +66,9 @@ interface ContextChefOptions {
60
66
  /**
61
67
  * Mechanical compaction before LLM compression.
62
68
  * Clears specified content types (tool-result, thinking) at zero LLM cost.
69
+ *
70
+ * When combined with `compress`, use `clear: ['thinking']` only.
71
+ * See CompactConfig for details.
63
72
  */
64
73
  compact?: CompactConfig;
65
74
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-chef/ai-sdk-middleware",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -39,7 +39,7 @@
39
39
  "url": "https://github.com/MyPrototypeWhat/context-chef/issues"
40
40
  },
41
41
  "dependencies": {
42
- "@context-chef/core": "3.0.1"
42
+ "@context-chef/core": "3.0.2"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@ai-sdk/provider": ">=3",