fix: defensive SDK response handling & parts-reader normalization

- Replace all response.data ?? [] with (response.data ?? response)
  pattern across 14 files to handle SDK array-shaped responses
- Normalize SDK parts in parts-reader.ts by injecting sessionID/
  messageID before validation (P1: SDK parts lack these fields)
- Treat unknown part types as having content in
  recover-empty-content-message-sdk.ts to prevent false placeholder
  injection on image/file parts
- Replace local isRecord with shared import in parts-reader.ts
This commit is contained in:
YeonGyu-Kim
2026-02-16 15:45:14 +09:00
parent 8edf6ed96f
commit 5a6a9e9800
15 changed files with 25 additions and 23 deletions
@@ -126,7 +126,7 @@ function sdkPartHasContent(part: SdkPart): boolean {
return true
}
return false
return true
}
function sdkMessageHasContent(message: MessageData): boolean {
@@ -136,7 +136,7 @@ function sdkMessageHasContent(message: MessageData): boolean {
async function readMessagesFromSDK(client: Client, sessionID: string): Promise<MessageData[]> {
try {
const response = await client.session.messages({ path: { id: sessionID } })
return (response.data ?? []) as MessageData[]
return ((response.data ?? response) as unknown as MessageData[]) ?? []
} catch {
return []
}