From 049a259332ee6aec75204b0fc76db55a328f49a0 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 15 Feb 2026 14:53:24 +0900 Subject: [PATCH] feat: implement SQLite backend for stripThinkingParts via HTTP DELETE --- .../storage/thinking-strip.ts | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/hooks/session-recovery/storage/thinking-strip.ts b/src/hooks/session-recovery/storage/thinking-strip.ts index 97b32d5c8..27295b186 100644 --- a/src/hooks/session-recovery/storage/thinking-strip.ts +++ b/src/hooks/session-recovery/storage/thinking-strip.ts @@ -1,12 +1,15 @@ import { existsSync, readdirSync, readFileSync, unlinkSync } from "node:fs" import { join } from "node:path" +import type { PluginInput } from "@opencode-ai/plugin" import { PART_STORAGE, THINKING_TYPES } from "../constants" import type { StoredPart } from "../types" -import { log, isSqliteBackend } from "../../../shared" +import { log, isSqliteBackend, deletePart } from "../../../shared" + +type OpencodeClient = PluginInput["client"] export function stripThinkingParts(messageID: string): boolean { if (isSqliteBackend()) { - log("[session-recovery] Disabled on SQLite backend: stripThinkingParts") + log("[session-recovery] Disabled on SQLite backend: stripThinkingParts (use async variant)") return false } @@ -31,3 +34,33 @@ export function stripThinkingParts(messageID: string): boolean { return anyRemoved } + +export async function stripThinkingPartsAsync( + client: OpencodeClient, + sessionID: string, + messageID: string +): Promise { + try { + const response = await client.session.messages({ path: { id: sessionID } }) + const messages = (response.data ?? []) as Array<{ parts?: Array<{ type: string; id: string }> }> + + const targetMsg = messages.find((m) => { + const info = (m as Record)["info"] as Record | undefined + return info?.["id"] === messageID + }) + if (!targetMsg?.parts) return false + + let anyRemoved = false + for (const part of targetMsg.parts) { + if (THINKING_TYPES.has(part.type)) { + const deleted = await deletePart(client, sessionID, messageID, part.id) + if (deleted) anyRemoved = true + } + } + + return anyRemoved + } catch (error) { + log("[session-recovery] stripThinkingPartsAsync failed", { error: String(error) }) + return false + } +}