diff options
| author | Adam Malczewski <[email protected]> | 2026-06-22 00:36:52 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-22 00:36:52 +0900 |
| commit | c1bfd62b0c734484efcff09d6cd521acdbab2640 (patch) | |
| tree | f9194ea3214d5f15be6fed659a230997a1309ab9 /packages/cli/src/http.ts | |
| parent | 7ff9f94c41a9870e124a50133cd74b42295ab9ac (diff) | |
| download | dispatch-c1bfd62b0c734484efcff09d6cd521acdbab2640.tar.gz dispatch-c1bfd62b0c734484efcff09d6cd521acdbab2640.zip | |
feat: conversation compacting (manual + automatic)
Implement roadmap item 10: conversation compaction to reclaim context
window without losing the thread.
Wire (0.11.0):
- Add CompactionResult type
- Add ConversationCompactedMessage WS event
Transport-contract (0.15.0):
- Add CompactResponse, CompactThresholdResponse, SetCompactThresholdRequest
- Add ConversationCompactedMessage to WsServerMessage union
- Re-export CompactionResult
Conversation-store:
- replaceHistory: delete all chunks, reset seq, append new messages
- getCompactThreshold / setCompactThreshold (per-conversation setting)
- compactThresholdKey added to keys.ts
Session-orchestrator:
- CompactionService interface + compactionHandle
- conversationCompacted hook descriptor
- createCompactionService: load history, split old/recent, call provider
to summarize, replaceHistory with [system: summary] + recent N
- Auto-trigger: resolveCompaction lazy dep, fires after turn settles
(checks threshold, non-blocking)
- Hook declared in manifest contributes.hooks + services
Transport-http:
- POST /conversations/:id/compact (manual trigger)
- GET /conversations/:id/compact-threshold (read setting)
- PUT /conversations/:id/compact-threshold (set setting)
Transport-ws:
- Subscribe to conversationCompacted hook
- Broadcast conversation.compacted WS message
CLI:
- dispatch compact <conversationId> command
FE handoff: frontend-compaction-handoff.md
Diffstat (limited to 'packages/cli/src/http.ts')
| -rw-r--r-- | packages/cli/src/http.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/cli/src/http.ts b/packages/cli/src/http.ts index 876f570..585c678 100644 --- a/packages/cli/src/http.ts +++ b/packages/cli/src/http.ts @@ -10,6 +10,7 @@ import type { AgentEvent, ChatRequest, + CompactResponse, ConversationListResponse, LastMessageResponse, ModelsResponse, @@ -183,6 +184,26 @@ export async function openConversation( return (await res.json()) as OpenConversationResponse; } +interface CompactConversationOpts { + readonly server: string; + readonly conversationId: string; +} + +export async function compactConversation( + deps: FetchDeps, + opts: CompactConversationOpts, +): Promise<CompactResponse> { + const url = `${opts.server}/conversations/${encodeURIComponent(opts.conversationId)}/compact`; + const res = await deps.fetchImpl(url, { method: "POST" }); + + if (!res.ok) { + const body = await res.text(); + throw new Error(`POST /conversations/:id/compact failed with status ${res.status}: ${body}`); + } + + return (await res.json()) as CompactResponse; +} + /** * The outcome of short-ID resolution: either the full conversation id to use, * or a human-readable error describing why resolution failed. |
