feat: wire session-recovery callers to async SDK/HTTP variants on SQLite

- recover-thinking-disabled-violation: isSqliteBackend() branch using
  stripThinkingPartsAsync() with SDK message enumeration
- recover-thinking-block-order: isSqliteBackend() branch using
  prependThinkingPartAsync() with SDK orphan thinking detection
- recover-empty-content-message: isSqliteBackend() branch delegating to
  extracted recover-empty-content-message-sdk.ts (200 LOC limit)
- storage.ts barrel: add async variant exports for all SDK functions
This commit is contained in:
YeonGyu-Kim
2026-02-15 15:53:18 +09:00
parent 0a085adcd6
commit dff3a551d8
5 changed files with 347 additions and 3 deletions
@@ -1,14 +1,21 @@
import type { createOpencodeClient } from "@opencode-ai/sdk"
import type { MessageData } from "./types"
import { findMessagesWithThinkingBlocks, stripThinkingParts } from "./storage"
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
import { stripThinkingPartsAsync } from "./storage/thinking-strip"
import { THINKING_TYPES } from "./constants"
type Client = ReturnType<typeof createOpencodeClient>
export async function recoverThinkingDisabledViolation(
_client: Client,
client: Client,
sessionID: string,
_failedAssistantMsg: MessageData
): Promise<boolean> {
if (isSqliteBackend()) {
return recoverThinkingDisabledViolationFromSDK(client, sessionID)
}
const messagesWithThinking = findMessagesWithThinkingBlocks(sessionID)
if (messagesWithThinking.length === 0) {
return false
@@ -23,3 +30,36 @@ export async function recoverThinkingDisabledViolation(
return anySuccess
}
async function recoverThinkingDisabledViolationFromSDK(
client: Client,
sessionID: string
): Promise<boolean> {
const response = await client.session.messages({ path: { id: sessionID } })
const messages = (response.data ?? []) as MessageData[]
const messageIDsWithThinking: string[] = []
for (const msg of messages) {
if (msg.info?.role !== "assistant") continue
if (!msg.info?.id) continue
if (!msg.parts) continue
const hasThinking = msg.parts.some((part) => THINKING_TYPES.has(part.type))
if (hasThinking) {
messageIDsWithThinking.push(msg.info.id)
}
}
if (messageIDsWithThinking.length === 0) {
return false
}
let anySuccess = false
for (const messageID of messageIDsWithThinking) {
if (await stripThinkingPartsAsync(client, sessionID, messageID)) {
anySuccess = true
}
}
return anySuccess
}