feat: implement SQLite backend for stripThinkingParts via HTTP DELETE
This commit is contained in:
parent
3fe0e0c7ae
commit
049a259332
@ -1,12 +1,15 @@
|
|||||||
import { existsSync, readdirSync, readFileSync, unlinkSync } from "node:fs"
|
import { existsSync, readdirSync, readFileSync, unlinkSync } from "node:fs"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
import type { PluginInput } from "@opencode-ai/plugin"
|
||||||
import { PART_STORAGE, THINKING_TYPES } from "../constants"
|
import { PART_STORAGE, THINKING_TYPES } from "../constants"
|
||||||
import type { StoredPart } from "../types"
|
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 {
|
export function stripThinkingParts(messageID: string): boolean {
|
||||||
if (isSqliteBackend()) {
|
if (isSqliteBackend()) {
|
||||||
log("[session-recovery] Disabled on SQLite backend: stripThinkingParts")
|
log("[session-recovery] Disabled on SQLite backend: stripThinkingParts (use async variant)")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,3 +34,33 @@ export function stripThinkingParts(messageID: string): boolean {
|
|||||||
|
|
||||||
return anyRemoved
|
return anyRemoved
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function stripThinkingPartsAsync(
|
||||||
|
client: OpencodeClient,
|
||||||
|
sessionID: string,
|
||||||
|
messageID: string
|
||||||
|
): Promise<boolean> {
|
||||||
|
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<string, unknown>)["info"] as Record<string, unknown> | 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user