fix: address 5 SDK compatibility issues from Cubic round 8

- P1: Use compacted timestamp check instead of nonexistent truncated
  field in target-token-truncation.ts
- P1: Use defensive (response.data ?? response) pattern in
  hook-message-injector/injector.ts to match codebase convention
- P2: Filter by tool type in countTruncatedResultsFromSDK to avoid
  counting non-tool compacted parts
- P2: Treat thinking/meta-only messages as empty in both
  empty-content-recovery-sdk.ts and message-builder.ts to align
  SDK path with file-based logic
This commit is contained in:
YeonGyu-Kim 2026-02-16 15:33:39 +09:00
parent cfb8164d9a
commit 8edf6ed96f
5 changed files with 14 additions and 10 deletions

View File

@ -64,7 +64,7 @@ export async function findNearestMessageWithFieldsFromSDK(
): Promise<StoredMessage | null> { ): Promise<StoredMessage | null> {
try { try {
const response = await client.session.messages({ path: { id: sessionID } }) const response = await client.session.messages({ path: { id: sessionID } })
const messages = (response.data ?? []) as SDKMessage[] const messages = ((response.data ?? response) as unknown as SDKMessage[]) ?? []
for (let i = messages.length - 1; i >= 0; i--) { for (let i = messages.length - 1; i >= 0; i--) {
const stored = convertSDKMessageToStoredMessage(messages[i]) const stored = convertSDKMessageToStoredMessage(messages[i])
@ -97,7 +97,7 @@ export async function findFirstMessageWithAgentFromSDK(
): Promise<string | null> { ): Promise<string | null> {
try { try {
const response = await client.session.messages({ path: { id: sessionID } }) const response = await client.session.messages({ path: { id: sessionID } })
const messages = (response.data ?? []) as SDKMessage[] const messages = ((response.data ?? response) as unknown as SDKMessage[]) ?? []
for (const msg of messages) { for (const msg of messages) {
const stored = convertSDKMessageToStoredMessage(msg) const stored = convertSDKMessageToStoredMessage(msg)

View File

@ -40,8 +40,9 @@ function messageHasContentFromSDK(message: SDKMessage): boolean {
return true return true
} }
// Messages with only thinking/meta parts are NOT empty — they have content // Messages with only thinking/meta parts are treated as empty
return hasIgnoredParts // to align with file-based logic (messageHasContent)
return false
} }
function getSdkMessages(response: unknown): SDKMessage[] { function getSdkMessages(response: unknown): SDKMessage[] {

View File

@ -51,8 +51,9 @@ function messageHasContentFromSDK(message: SDKMessage): boolean {
return true return true
} }
// Messages with only thinking/meta parts are NOT empty — they have content // Messages with only thinking/meta parts are treated as empty
return hasIgnoredParts // to align with file-based logic (messageHasContent)
return false
} }
async function findEmptyMessageIdsFromSDK( async function findEmptyMessageIdsFromSDK(

View File

@ -10,8 +10,10 @@ interface SDKToolPart {
id: string id: string
type: string type: string
tool?: string tool?: string
state?: { output?: string } state?: {
truncated?: boolean output?: string
time?: { start?: number; end?: number; compacted?: number }
}
originalSize?: number originalSize?: number
} }
@ -81,7 +83,7 @@ export async function truncateUntilTargetTokens(
const results: import("./tool-part-types").ToolResultInfo[] = [] const results: import("./tool-part-types").ToolResultInfo[] = []
for (const [key, part] of toolPartsByKey) { for (const [key, part] of toolPartsByKey) {
if (part.type === "tool" && part.state?.output && !part.truncated && part.tool) { if (part.type === "tool" && part.state?.output && !part.state?.time?.compacted && part.tool) {
results.push({ results.push({
partPath: "", partPath: "",
partId: part.id, partId: part.id,

View File

@ -104,7 +104,7 @@ export async function countTruncatedResultsFromSDK(
for (const msg of messages) { for (const msg of messages) {
if (!msg.parts) continue if (!msg.parts) continue
for (const part of msg.parts) { for (const part of msg.parts) {
if (part.state?.time?.compacted) count++ if (part.type === "tool" && part.state?.time?.compacted) count++
} }
} }