fix: address Cubic round-2 P2 issues
- target-token-truncation: eliminate redundant SDK messages fetch by extracting tool results from already-fetched toolPartsByKey map - recover-thinking-block-order: wrap SDK message fetches in try/catch so recovery continues gracefully on API errors - thinking-strip: guard against missing part.id before calling deletePart to prevent invalid HTTP requests
This commit is contained in:
@@ -74,8 +74,13 @@ async function findMessagesWithOrphanThinkingFromSDK(
|
||||
client: Client,
|
||||
sessionID: string
|
||||
): Promise<string[]> {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
const messages = (response.data ?? []) as MessageData[]
|
||||
let messages: MessageData[]
|
||||
try {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
messages = (response.data ?? []) as MessageData[]
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
const result: string[] = []
|
||||
for (const msg of messages) {
|
||||
@@ -103,8 +108,13 @@ async function findMessageByIndexNeedingThinkingFromSDK(
|
||||
sessionID: string,
|
||||
targetIndex: number
|
||||
): Promise<string | null> {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
const messages = (response.data ?? []) as MessageData[]
|
||||
let messages: MessageData[]
|
||||
try {
|
||||
const response = await client.session.messages({ path: { id: sessionID } })
|
||||
messages = (response.data ?? []) as MessageData[]
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
if (targetIndex < 0 || targetIndex >= messages.length) return null
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function stripThinkingPartsAsync(
|
||||
|
||||
let anyRemoved = false
|
||||
for (const part of targetMsg.parts) {
|
||||
if (THINKING_TYPES.has(part.type)) {
|
||||
if (THINKING_TYPES.has(part.type) && part.id) {
|
||||
const deleted = await deletePart(client, sessionID, messageID, part.id)
|
||||
if (deleted) anyRemoved = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user