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:
@@ -32,7 +32,7 @@ export async function findToolResultsBySizeFromSDK(
|
||||
): Promise<ToolResultInfo[]> {
|
||||
try {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
const messages = (response.data ?? []) as SDKMessage[]
|
||||
const messages = ((response.data ?? response) as unknown as SDKMessage[]) ?? []
|
||||
const results: ToolResultInfo[] = []
|
||||
|
||||
for (const msg of messages) {
|
||||
@@ -98,7 +98,7 @@ export async function countTruncatedResultsFromSDK(
|
||||
): Promise<number> {
|
||||
try {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
const messages = (response.data ?? []) as SDKMessage[]
|
||||
const messages = ((response.data ?? response) as unknown as SDKMessage[]) ?? []
|
||||
let count = 0
|
||||
|
||||
for (const msg of messages) {
|
||||
|
||||
Reference in New Issue
Block a user