fix: handle array-shaped SDK responses in getSdkMessages & dedup getMessageDir

- getSdkMessages now handles both response.data and direct array
  responses from SDK
- Consolidated getMessageDir: storage.ts now re-exports from shared
  opencode-message-dir.ts (with path traversal guards)
This commit is contained in:
YeonGyu-Kim
2026-02-16 15:54:29 +09:00
parent 5a6a9e9800
commit 9889ac0dd9
2 changed files with 6 additions and 23 deletions
+3 -22
View File
@@ -1,9 +1,10 @@
import { existsSync, readdirSync } from "node:fs"
import { existsSync } from "node:fs"
import { readdir, readFile } from "node:fs/promises"
import { join } from "node:path"
import type { PluginInput } from "@opencode-ai/plugin"
import { MESSAGE_STORAGE, PART_STORAGE, SESSION_STORAGE, TODO_DIR, TRANSCRIPT_DIR } from "./constants"
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
import { getMessageDir } from "../../shared/opencode-message-dir"
import type { SessionMessage, SessionInfo, TodoItem, SessionMetadata } from "./types"
export interface GetMainSessionsOptions {
@@ -116,27 +117,7 @@ export async function getAllSessions(): Promise<string[]> {
return [...new Set(sessions)]
}
export function getMessageDir(sessionID: string): string | null {
if (!existsSync(MESSAGE_STORAGE)) return null
const directPath = join(MESSAGE_STORAGE, sessionID)
if (existsSync(directPath)) {
return directPath
}
try {
for (const dir of readdirSync(MESSAGE_STORAGE)) {
const sessionPath = join(MESSAGE_STORAGE, dir, sessionID)
if (existsSync(sessionPath)) {
return sessionPath
}
}
} catch {
return null
}
return null
}
export { getMessageDir } from "../../shared/opencode-message-dir"
export async function sessionExists(sessionID: string): Promise<boolean> {
if (isSqliteBackend() && sdkClient) {