refactor: create normalizeSDKResponse helper and replace scattered patterns across 37 files

This commit is contained in:
YeonGyu-Kim
2026-02-16 18:20:19 +09:00
parent 6d732fd1f6
commit 1a6810535c
41 changed files with 250 additions and 77 deletions
@@ -1,6 +1,7 @@
import { existsSync, readdirSync } from "node:fs"
import type { PluginInput } from "@opencode-ai/plugin"
import { getMessageDir } from "../../shared/opencode-message-dir"
import { normalizeSDKResponse } from "../../shared"
export { getMessageDir }
@@ -17,7 +18,7 @@ export async function getMessageIdsFromSDK(
): Promise<string[]> {
try {
const response = await client.session.messages({ path: { id: sessionID } })
const messages = ((response.data ?? response) as unknown as SDKMessage[]) ?? []
const messages = normalizeSDKResponse(response, [] as SDKMessage[], { preferResponseOnMissingData: true })
return messages.map(msg => msg.info.id)
} catch {
return []