Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

CHANGELOG.md

204 lines17.3 KB

@tanstack/ai-compaction

0.3.1

Patch Changes

  • Updated dependencies [824ee98]:
    • @tanstack/ai@0.71.0

0.3.0

Minor Changes

  • #1728 3292bad - Prepare a compaction summary in the background with withCompaction({ background: { atTokens } }).

    • When the count at a model call is over atTokens and not over maxTokens, the strategy runs on a copy of the messages. The model call does not wait for it.
    • The result waits in the metadata store (namespace @tanstack/ai-compaction:background), or in memory without one. It applies at the first model call of the next run: as a tanstack.compaction record on a durable host, or as the checkpoint.
    • A model call over maxTokens while the summary runs waits for it and applies it. It compacts inline only when the list is still over maxTokens.
    • A result whose kept message is gone, because a newer compaction cut further, is dropped. compaction:ended and onCompact report it with stale: true. A failed summary is reported with error and applies nothing.
    • CompactionReason has a new value, 'background'. Setup throws when atTokens is not below maxTokens.
  • #1728 3292bad - Count with real usage, compact on demand, and keep compaction in a session log.

    • countTokens: 'usage' counts with the usage the provider reported for the last call, plus an estimate of the newer messages.
    • When a model call fails with CONTEXT_OVERFLOW_CODE, withCompaction compacts and calls the model again in the same run, once per model call.
    • compactNext(threadId) compacts at the next model call. auto: false turns off compaction at maxTokens and keeps compactNext, the overflow retry, and the overflow check.
    • durable: true writes a tanstack.compaction record through LogRecordsCapability when the host provides it. Fold the record into the messages with projectCompaction.
    • With countTokens: 'usage' and durable: true, a run checks once more after its last model call. When the usage passed maxTokens or contextWindow, compaction runs right away. contextWindow also counts with auto: false.
    • compaction:ended and onCompact report reason, the summary usage, and an error. continueOnError sends the full messages when the strategy fails.
    • summarizeOldest({ cut: 'turn' }) gives the start of a cut turn its own summary. conversationSummarizer writes a structured summary, updates the older summary, and takes a details hook. The summary message is now wrapped in an <untrusted-conversation-summary> tag, so a later compaction can find and update it.

Patch Changes

0.2.0

Minor Changes

  • #1729 51f72fb - A text adapter can now have an optional compact(options) method. It sends the history to the provider's own compaction endpoint, and resolves to the history for the next calls. The options are TextCompactOptions: messages, model, signal, wrapFetch, and systemPrompts.

    The OpenAI Responses adapters implement compact with POST /responses/compact. The request sends the system prompts as instructions. It sends no tools, because the endpoint does not take them. The encrypted compaction item goes back to the same model as it is on later requests. A compact result with no compaction item throws.

    withCompaction has a new native option. Pass the adapter of the chat() call. When the adapter has compact, it runs in place of strategy. When compact fails, strategy runs, and onCompact and compaction:ended get the failure in error. After a 404, 405, or 501, that adapter and model use the strategy for the rest of the process. After any other failure, the next compaction tries compact again. Without the option, nothing changes.

Patch Changes

0.1.17

Patch Changes

0.1.16

Patch Changes

0.1.15

Patch Changes

  • #1671 2ee30cf - summarizeOldest now fails the compaction when the summarizer returns an empty or whitespace-only summary. Before, it replaced the old messages with an empty summary and saved that result in the checkpoint, so the history was lost. Now the strategy throws an error, the history stays, and no checkpoint is written.

  • Updated dependencies [baafb17]:

    • @tanstack/ai@0.66.1

0.1.14

Patch Changes

0.1.13

Patch Changes

0.1.12

Patch Changes

0.1.11

Patch Changes

0.1.10

Patch Changes

0.1.9

Patch Changes

0.1.8

Patch Changes

  • Updated dependencies [ef0a00f]:
    • @tanstack/ai@0.60.0

0.1.7

Patch Changes

0.1.6

Patch Changes

  • Updated dependencies [796f2b5]:
    • @tanstack/ai@0.58.0

0.1.5

Patch Changes

0.1.4

Patch Changes

0.1.3

Patch Changes

0.1.2

Patch Changes

0.1.1

Patch Changes

  • Updated dependencies [21775ee]:
    • @tanstack/ai@0.53.0

0.1.0

Minor Changes

  • #1235 e04ff6a - Add @tanstack/ai-compaction — context-window compaction as a chat() middleware. withCompaction({ maxTokens, strategy }) runs a pluggable CompactionStrategy before each model call, so compaction is incremental and rolling. Three strategies ship built in: evictOldest (drop old messages, the default), summarizeOldest (replace them with an LLM summary), and clearToolResults (stub old tool output, keep the messages). Combine them with composeStrategies, which escalates through strategies until the transcript is back under budget. Strategies preserve tool-call/result pairing and never touch the system prompt.

  • #1235 e04ff6a - Show compaction in TanStack AI DevTools. withCompaction injects compaction:started, compaction:state, and compaction:ended CUSTOM stream events. State includes before/after counts, the token budget, and dropped vs sent message previews. The chat client re-emits the same three events. The AI panel has a Compaction tab and started/state/ended steps on the iteration.

  • #1235 e04ff6a - Keep canonical chat history separate from compacted provider context. Reuse validated compaction checkpoints through an optional persistence metadata store.

Patch Changes

  • #1235 e04ff6a - Add ctx.emitCustomEvent on chat middleware context. The engine yields CUSTOM chunks while hooks such as onConfig are still running, so a long middleware step can send progress before it finishes. Compaction uses this to emit compaction:started before the strategy returns.
  • Updated dependencies [49fc54c, e04ff6a, e04ff6a]:
    • @tanstack/ai@0.52.0