fix(responses): hoist one cast-ok content block read for the type gates

A Final assignment inside the conversion loop trips
reportGeneralTypeIssues, and per-site casts trip the LIT006 budget;
read the marker through one cast-narrowed local instead.
This commit is contained in:
Yucheng 2026-10-05 00:59:44 -07:00
parent 5160b21974
commit 90daacfe5a

View file

@ -1114,14 +1114,13 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
elif isinstance(item, dict):
# Handle multimodal content
original_type = item.get("type")
content_item = cast( # cast-ok: isinstance confirms the content block is a mapping
dict[str, object], item
)
if original_type == "text":
converted = with_prompt_cache_breakpoint(
self._convert_content_str_to_input_text(item.get("text", ""), role),
cast(
dict[str, object], item
).get( # cast-ok: isinstance confirms the content block is a mapping
"prompt_cache_breakpoint"
),
content_item.get("prompt_cache_breakpoint"),
)
result.append(converted)
verbose_logger.debug("Chat provider: text -> %s", converted)
@ -1134,11 +1133,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
role,
)
),
cast(
dict[str, object], item
).get( # cast-ok: isinstance confirms the content block is a mapping
"prompt_cache_breakpoint"
),
content_item.get("prompt_cache_breakpoint"),
)
result.append(converted)
verbose_logger.debug("Chat provider: image_url -> %s", converted)
@ -1154,11 +1149,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
_input_file_from_file_value(
cast("ChatCompletionFileObject", item).get("file"), # cast-ok: type tag checked
),
cast(
dict[str, object], item
).get( # cast-ok: isinstance confirms the content block is a mapping
"prompt_cache_breakpoint"
),
content_item.get("prompt_cache_breakpoint"),
)
result.append(converted)
verbose_logger.debug("Chat provider: file -> %s", converted)