feat: add SDK path for getMessageIds in context-window recovery

This commit is contained in:
YeonGyu-Kim
2026-02-15 14:50:15 +09:00
parent 450a5bf954
commit 0c6fe3873c

View File

@@ -1,8 +1,29 @@
import { existsSync, readdirSync } from "node:fs"
import type { PluginInput } from "@opencode-ai/plugin"
import { getMessageDir } from "../../shared/opencode-message-dir"
export { getMessageDir }
type OpencodeClient = PluginInput["client"]
interface SDKMessage {
info: { id: string }
parts: unknown[]
}
export async function getMessageIdsFromSDK(
client: OpencodeClient,
sessionID: string
): Promise<string[]> {
try {
const response = await client.session.messages({ path: { id: sessionID } })
const messages = (response.data ?? []) as SDKMessage[]
return messages.map(msg => msg.info.id)
} catch {
return []
}
}
export function getMessageIds(sessionID: string): string[] {
const messageDir = getMessageDir(sessionID)
if (!messageDir || !existsSync(messageDir)) return []