Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chatlas/_live_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def __init__(
self.vertical_overflow = vertical_overflow
self._shape: Optional[Tuple[int, int]] = None

@property
def last_render_height(self) -> int:
"""The number of lines in the last render (0 if nothing was rendered)."""
if self._shape is None:
return 0
return self._shape[1]

def set_renderable(self, renderable: RenderableType) -> None:
"""Set a new renderable.

Expand Down
33 changes: 23 additions & 10 deletions chatlas/_provider_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,32 +825,45 @@ def _as_turn(self, completion: Message, has_data_model=False) -> AssistantTurn:
urls: list[str] = []
if isinstance(content.content, list):
urls = [x.url for x in content.content]
# Manually construct the extra dict to avoid SDK-internal
# fields (e.g., "caller") that the API doesn't accept
extra = {
"type": content.type,
"tool_use_id": content.tool_use_id,
"content": [
x.model_dump() for x in content.content
]
if isinstance(content.content, list)
else content.content.model_dump(),
}
contents.append(
ContentToolResponseSearch(
urls=urls,
extra=content.model_dump(),
extra=extra,
)
)
elif content.type == "web_fetch_tool_result":
# N.B. type checker thinks this is unreachable due to
# ToolUnionParam not including BetaWebFetchTool20250910Param
# yet. Also, at run-time, the SDK is currently giving non-sense
# of type(content) == TextBlock, but it doesn't even fit that
# shape?!? Anyway, content.content has a dict with the content
# we want.
content_fetch = cast("dict", getattr(content, "content", {}))
if not content_fetch:
# yet.
content_fetch = getattr(content, "content", None)
if content_fetch is None:
raise ValueError(
"web_fetch_tool_result content is empty. Please report this issue."
)
# content_fetch is a BetaWebFetchBlock (has .url) or
# BetaWebFetchToolResultErrorBlock (error case)
url = getattr(content_fetch, "url", "failed")
# Manually construct the extra dict to avoid SDK-internal
# fields (e.g., "caller") that the API doesn't accept
extra = {
"type": "web_fetch_tool_result",
"type": content.type,
"tool_use_id": content.tool_use_id, # type: ignore
"content": content_fetch,
"content": content_fetch.model_dump(exclude_none=True),
}
contents.append(
ContentToolResponseFetch(
url=content_fetch.get("url", "failed"),
url=url,
extra=extra,
)
)
Expand Down
34 changes: 34 additions & 0 deletions chatlas/types/anthropic/_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
from typing import Iterable, Literal, Mapping, Optional, Sequence, TypedDict, Union

import anthropic
import anthropic.types.cache_control_ephemeral_param
import anthropic.types.code_execution_tool_20250522_param
import anthropic.types.code_execution_tool_20250825_param
import anthropic.types.code_execution_tool_20260120_param
import anthropic.types.memory_tool_20250818_param
import anthropic.types.message_param
import anthropic.types.output_config_param
import anthropic.types.text_block_param
import anthropic.types.thinking_config_adaptive_param
import anthropic.types.thinking_config_disabled_param
import anthropic.types.thinking_config_enabled_param
import anthropic.types.tool_bash_20250124_param
Expand All @@ -16,17 +23,24 @@
import anthropic.types.tool_choice_none_param
import anthropic.types.tool_choice_tool_param
import anthropic.types.tool_param
import anthropic.types.tool_search_tool_bm25_20251119_param
import anthropic.types.tool_search_tool_regex_20251119_param
import anthropic.types.tool_text_editor_20250124_param
import anthropic.types.tool_text_editor_20250429_param
import anthropic.types.tool_text_editor_20250728_param
import anthropic.types.web_fetch_tool_20250910_param
import anthropic.types.web_fetch_tool_20260209_param
import anthropic.types.web_search_tool_20250305_param
import anthropic.types.web_search_tool_20260209_param


class SubmitInputArgs(TypedDict, total=False):
max_tokens: int
messages: Iterable[anthropic.types.message_param.MessageParam]
model: Union[
Literal[
"claude-opus-4-6",
"claude-sonnet-4-6",
"claude-opus-4-5-20251101",
"claude-opus-4-5",
"claude-3-7-sonnet-latest",
Expand All @@ -50,6 +64,16 @@ class SubmitInputArgs(TypedDict, total=False):
],
str,
]
cache_control: Union[
anthropic.types.cache_control_ephemeral_param.CacheControlEphemeralParam,
None,
anthropic.Omit,
]
container: Union[str, None, anthropic.Omit]
inference_geo: Union[str, None, anthropic.Omit]
output_config: (
anthropic.types.output_config_param.OutputConfigParam | anthropic.Omit
)
service_tier: Union[Literal["auto", "standard_only"], anthropic.Omit]
stop_sequences: Union[Sequence[str], anthropic.Omit]
stream: Union[Literal[False], Literal[True], anthropic.Omit]
Expand All @@ -60,6 +84,7 @@ class SubmitInputArgs(TypedDict, total=False):
thinking: Union[
anthropic.types.thinking_config_enabled_param.ThinkingConfigEnabledParam,
anthropic.types.thinking_config_disabled_param.ThinkingConfigDisabledParam,
anthropic.types.thinking_config_adaptive_param.ThinkingConfigAdaptiveParam,
anthropic.Omit,
]
tool_choice: Union[
Expand All @@ -74,10 +99,19 @@ class SubmitInputArgs(TypedDict, total=False):
Union[
anthropic.types.tool_param.ToolParam,
anthropic.types.tool_bash_20250124_param.ToolBash20250124Param,
anthropic.types.code_execution_tool_20250522_param.CodeExecutionTool20250522Param,
anthropic.types.code_execution_tool_20250825_param.CodeExecutionTool20250825Param,
anthropic.types.code_execution_tool_20260120_param.CodeExecutionTool20260120Param,
anthropic.types.memory_tool_20250818_param.MemoryTool20250818Param,
anthropic.types.tool_text_editor_20250124_param.ToolTextEditor20250124Param,
anthropic.types.tool_text_editor_20250429_param.ToolTextEditor20250429Param,
anthropic.types.tool_text_editor_20250728_param.ToolTextEditor20250728Param,
anthropic.types.web_search_tool_20250305_param.WebSearchTool20250305Param,
anthropic.types.web_fetch_tool_20250910_param.WebFetchTool20250910Param,
anthropic.types.web_search_tool_20260209_param.WebSearchTool20260209Param,
anthropic.types.web_fetch_tool_20260209_param.WebFetchTool20260209Param,
anthropic.types.tool_search_tool_bm25_20251119_param.ToolSearchToolBm25_20251119Param,
anthropic.types.tool_search_tool_regex_20251119_param.ToolSearchToolRegex20251119Param,
]
],
anthropic.Omit,
Expand Down
5 changes: 5 additions & 0 deletions chatlas/types/openai/_submit_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@

class SubmitInputArgs(TypedDict, total=False):
background: Union[bool, None, openai.Omit]
context_management: Union[
Iterable[openai.types.responses.response_create_params.ContextManagement],
None,
openai.Omit,
]
conversation: Union[
str,
openai.types.responses.response_conversation_param.ResponseConversationParam,
Expand Down