clawd-code-sdk 1.2.1__tar.gz → 1.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/PKG-INFO +3 -3
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/pyproject.toml +15 -27
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_errors.py +15 -13
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/query.py +1 -1
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +1 -1
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/anthropic_stream.py +11 -4
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/client.py +2 -2
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/instrumentation.py +2 -2
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/mcp_utils.py +1 -1
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/__init__.py +18 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/content_blocks.py +152 -5
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/input_types.py +1 -1
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/messages.py +9 -1
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/prompts.py +13 -5
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/system_messages.py +2 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/storage/replay.py +66 -3
- clawd_code_sdk-1.2.3/tests/test_api_content_blocks.py +183 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/.gitignore +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/LICENSE +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/README.md +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/session_mutations.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/sessions.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/_version.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/list_sessions.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/agents.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/base.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/context_usage.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/control.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/hooks.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/mcp.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/options.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/output_types.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/permissions.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/server_info.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/session.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/settings.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/thinking.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/models/usage.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/py.typed +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/session.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/storage/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/storage/helpers.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/storage/models.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/src/clawd_code_sdk/usage.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/conftest.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/__init__.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_agents_and_settings.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_dynamic_control.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_hook_events.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_hooks.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_include_partial_messages.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_sdk_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_sdk_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_slash_commands.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_stderr_callback.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_storage_parsing.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_structured_output.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_subagent_invocation.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/e2e/test_tool_permissions.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/mcp_server.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/mock_claude_server.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_changelog.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_client.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_elicitation_mcp_conversion.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_errors.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_image.png +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_integration.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_line_framing.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_message_parser.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_result_error.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_sandbox_settings.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_sdk_0_3_types.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_sdk_mcp_integration.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_session.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_session_mutations.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_sessions.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_streaming_client.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_subprocess_buffering.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_tool_callbacks.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_transport.py +0 -0
- {clawd_code_sdk-1.2.1 → clawd_code_sdk-1.2.3}/tests/test_transport_close.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: clawd-code-sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: Python SDK for Claude Code
|
|
5
5
|
Project-URL: Documentation, https://github.com/phil65/claude-agent-sdk-python
|
|
6
6
|
Project-URL: Homepage, https://github.com/phil65/claude-agent-sdk-python
|
|
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
18
|
Classifier: Typing :: Typed
|
|
19
19
|
Requires-Python: >=3.13
|
|
20
|
-
Requires-Dist: anthropic>=
|
|
20
|
+
Requires-Dist: anthropic>=2.9.0
|
|
21
21
|
Requires-Dist: anyenv>=2.0.15
|
|
22
22
|
Requires-Dist: anyio>=4.0.0
|
|
23
23
|
Requires-Dist: jsonschema>=4.20.0
|
|
@@ -27,12 +27,12 @@ Requires-Dist: python-dotenv>=1.2.1
|
|
|
27
27
|
Provides-Extra: dev
|
|
28
28
|
Requires-Dist: anyio[trio]>=4.0.0; extra == 'dev'
|
|
29
29
|
Requires-Dist: fastmcp>=3.0.0; extra == 'dev'
|
|
30
|
-
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
31
30
|
Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
|
|
32
31
|
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
33
32
|
Requires-Dist: pytest-timeout>=2.4.0; extra == 'dev'
|
|
34
33
|
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
35
34
|
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ty; extra == 'dev'
|
|
36
36
|
Requires-Dist: types-jsonschema>=4.20.0; extra == 'dev'
|
|
37
37
|
Provides-Extra: otel
|
|
38
38
|
Requires-Dist: opentelemetry-api>=1.20.0; extra == 'otel'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "clawd-code-sdk"
|
|
3
|
-
version = "1.2.
|
|
3
|
+
version = "1.2.3"
|
|
4
4
|
description = "Python SDK for Claude Code"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
@@ -19,7 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Typing :: Typed",
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|
|
22
|
-
"anthropic>=
|
|
22
|
+
"anthropic>=2.9.0", # BetaFallbackBlock / BetaMCPToolListingBlock
|
|
23
23
|
"anyenv>=2.0.15",
|
|
24
24
|
"anyio>=4.0.0",
|
|
25
25
|
"logfire>=4.31.0",
|
|
@@ -40,7 +40,7 @@ dev = [
|
|
|
40
40
|
"anyio[trio]>=4.0.0",
|
|
41
41
|
"pytest-cov>=4.0.0",
|
|
42
42
|
"pytest-timeout>=2.4.0",
|
|
43
|
-
"
|
|
43
|
+
"ty",
|
|
44
44
|
"ruff>=0.1.0",
|
|
45
45
|
"fastmcp>=3.0.0",
|
|
46
46
|
"types-jsonschema>=4.20.0",
|
|
@@ -65,23 +65,6 @@ include = [
|
|
|
65
65
|
"/LICENSE",
|
|
66
66
|
]
|
|
67
67
|
|
|
68
|
-
[tool.mypy]
|
|
69
|
-
python_version = "3.13"
|
|
70
|
-
strict = true
|
|
71
|
-
exclude = ["examples/"]
|
|
72
|
-
warn_return_any = true
|
|
73
|
-
warn_unused_configs = true
|
|
74
|
-
disallow_untyped_defs = true
|
|
75
|
-
disallow_incomplete_defs = true
|
|
76
|
-
check_untyped_defs = true
|
|
77
|
-
disallow_untyped_decorators = true
|
|
78
|
-
no_implicit_optional = true
|
|
79
|
-
warn_redundant_casts = true
|
|
80
|
-
warn_unused_ignores = true
|
|
81
|
-
warn_no_return = true
|
|
82
|
-
warn_unreachable = true
|
|
83
|
-
strict_equality = true
|
|
84
|
-
|
|
85
68
|
[tool.pytest]
|
|
86
69
|
addopts = ["-m", "not slow and not acp_snapshot and not e2e"]
|
|
87
70
|
filterwarnings = ["ignore::DeprecationWarning:pydantic.*:"]
|
|
@@ -112,7 +95,7 @@ exclude = ["examples/"]
|
|
|
112
95
|
future-annotations = true
|
|
113
96
|
select = [
|
|
114
97
|
"A", # Flake8-builtins
|
|
115
|
-
|
|
98
|
+
"ANN", # Flake8-Annotations (enforces complete annotations; ty does not)
|
|
116
99
|
# "ASYNC", # Flake8-Async
|
|
117
100
|
# "ARG", # # Flake8-Unused-Arguments
|
|
118
101
|
"B", # flake8-bugbear
|
|
@@ -172,6 +155,7 @@ select = [
|
|
|
172
155
|
"YTT", # flake8-2020
|
|
173
156
|
]
|
|
174
157
|
ignore = [
|
|
158
|
+
"ANN401", # Dynamically typed expressions (Any) are allowed
|
|
175
159
|
"BLE001",
|
|
176
160
|
"C408", # Unnecessary {obj_type} call (rewrite as a literal)
|
|
177
161
|
"C901", # {name} is too complex ({complexity} > {max_complexity})
|
|
@@ -239,21 +223,25 @@ max-complexity = 15
|
|
|
239
223
|
|
|
240
224
|
[tool.ruff.lint.per-file-ignores]
|
|
241
225
|
"__init__.py" = ["E402", "I001"]
|
|
242
|
-
"scripts/*" = ["INP001", "PLR2004"]
|
|
243
|
-
"*tests/*" = ["D100", "PLR2004"]
|
|
226
|
+
"scripts/*" = ["INP001", "PLR2004", "ANN"]
|
|
227
|
+
"*tests/*" = ["D100", "PLR2004", "ANN"] # tests need not be fully annotated
|
|
228
|
+
"duties.py" = ["ANN"] # tooling, not package code
|
|
244
229
|
"src/clawd_code_sdk/models/settings.py" = ["ALL"]
|
|
245
230
|
"docs/examples/**/*.py" = [
|
|
246
231
|
"TC001",
|
|
247
232
|
] # Examples don't need TYPE_CHECKING imports
|
|
248
233
|
|
|
234
|
+
[tool.ty.src]
|
|
235
|
+
# `ty check` (hooks, CI, editors) type-checks the package code only.
|
|
236
|
+
include = ["src"]
|
|
237
|
+
|
|
249
238
|
[tool.ty.environment]
|
|
250
239
|
python-version = "3.13"
|
|
251
240
|
python-platform = "all"
|
|
252
241
|
|
|
253
242
|
[tool.ty.rules]
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
not-subscriptable = "ignore"
|
|
243
|
+
# Narrowing an overridden class attribute (e.g. pydantic discriminators,
|
|
244
|
+
# `Config` attributes) is an intentional pattern.
|
|
245
|
+
incompatible-mutable-override = "ignore"
|
|
258
246
|
possibly-missing-import = "warn"
|
|
259
247
|
division-by-zero = "warn"
|
|
@@ -20,7 +20,7 @@ class CLIConnectionError(ClaudeSDKError):
|
|
|
20
20
|
class CLINotFoundError(CLIConnectionError):
|
|
21
21
|
"""Raised when Claude Code is not found or not installed."""
|
|
22
22
|
|
|
23
|
-
def __init__(self, message: str = "Claude Code not found", cli_path: str | None = None):
|
|
23
|
+
def __init__(self, message: str = "Claude Code not found", cli_path: str | None = None) -> None:
|
|
24
24
|
if cli_path:
|
|
25
25
|
message = f"{message}: {cli_path}"
|
|
26
26
|
super().__init__(message)
|
|
@@ -29,7 +29,9 @@ class CLINotFoundError(CLIConnectionError):
|
|
|
29
29
|
class ProcessError(ClaudeSDKError):
|
|
30
30
|
"""Raised when the CLI process fails."""
|
|
31
31
|
|
|
32
|
-
def __init__(
|
|
32
|
+
def __init__(
|
|
33
|
+
self, message: str, exit_code: int | None = None, stderr: str | None = None
|
|
34
|
+
) -> None:
|
|
33
35
|
self.exit_code = exit_code
|
|
34
36
|
self.stderr = stderr
|
|
35
37
|
|
|
@@ -50,7 +52,7 @@ class ResultError(ProcessError):
|
|
|
50
52
|
``ProcessError`` so existing handlers keep catching it. (Upstream #1198/#1205.)
|
|
51
53
|
"""
|
|
52
54
|
|
|
53
|
-
def __init__(self, message: str, data: dict[str, Any], exit_code: int | None = None):
|
|
55
|
+
def __init__(self, message: str, data: dict[str, Any], exit_code: int | None = None) -> None:
|
|
54
56
|
self.data = data
|
|
55
57
|
super().__init__(message, exit_code=exit_code)
|
|
56
58
|
|
|
@@ -86,7 +88,7 @@ def error_result_text(message: dict[str, Any]) -> str:
|
|
|
86
88
|
class CLIJSONDecodeError(ClaudeSDKError):
|
|
87
89
|
"""Raised when unable to decode JSON from CLI output."""
|
|
88
90
|
|
|
89
|
-
def __init__(self, line: str, original_error: Exception):
|
|
91
|
+
def __init__(self, line: str, original_error: Exception) -> None:
|
|
90
92
|
self.line = line
|
|
91
93
|
self.original_error = original_error
|
|
92
94
|
super().__init__(f"Failed to decode JSON: {line[:100]}...")
|
|
@@ -95,7 +97,7 @@ class CLIJSONDecodeError(ClaudeSDKError):
|
|
|
95
97
|
class MessageParseError(ClaudeSDKError):
|
|
96
98
|
"""Raised when unable to parse a message from CLI output."""
|
|
97
99
|
|
|
98
|
-
def __init__(self, message: str, data: dict[str, Any] | None = None):
|
|
100
|
+
def __init__(self, message: str, data: dict[str, Any] | None = None) -> None:
|
|
99
101
|
self.data = data
|
|
100
102
|
super().__init__(f"{message}: {data}")
|
|
101
103
|
|
|
@@ -137,7 +139,7 @@ class APIError(ClaudeSDKError):
|
|
|
137
139
|
message: str,
|
|
138
140
|
error_type: APIErrorType,
|
|
139
141
|
model: Model | None = None,
|
|
140
|
-
):
|
|
142
|
+
) -> None:
|
|
141
143
|
self.error_type = error_type
|
|
142
144
|
self.model = model
|
|
143
145
|
super().__init__(message)
|
|
@@ -149,7 +151,7 @@ class AuthenticationError(APIError):
|
|
|
149
151
|
This typically indicates an invalid API key or insufficient permissions.
|
|
150
152
|
"""
|
|
151
153
|
|
|
152
|
-
def __init__(self, message: str, model: Model | None = None):
|
|
154
|
+
def __init__(self, message: str, model: Model | None = None) -> None:
|
|
153
155
|
super().__init__(message, "authentication_failed", model)
|
|
154
156
|
|
|
155
157
|
|
|
@@ -160,7 +162,7 @@ class BillingError(APIError):
|
|
|
160
162
|
billing-related issues.
|
|
161
163
|
"""
|
|
162
164
|
|
|
163
|
-
def __init__(self, message: str, model: Model | None = None):
|
|
165
|
+
def __init__(self, message: str, model: Model | None = None) -> None:
|
|
164
166
|
super().__init__(message, "billing_error", model)
|
|
165
167
|
|
|
166
168
|
|
|
@@ -171,7 +173,7 @@ class RateLimitError(APIError):
|
|
|
171
173
|
when handling this exception.
|
|
172
174
|
"""
|
|
173
175
|
|
|
174
|
-
def __init__(self, message: str, model: Model | None = None):
|
|
176
|
+
def __init__(self, message: str, model: Model | None = None) -> None:
|
|
175
177
|
super().__init__(message, "rate_limit", model)
|
|
176
178
|
|
|
177
179
|
|
|
@@ -182,7 +184,7 @@ class InvalidRequestError(APIError):
|
|
|
182
184
|
Check the error message for details about what needs to be corrected.
|
|
183
185
|
"""
|
|
184
186
|
|
|
185
|
-
def __init__(self, message: str, model: Model | None = None):
|
|
187
|
+
def __init__(self, message: str, model: Model | None = None) -> None:
|
|
186
188
|
super().__init__(message, "invalid_request", model)
|
|
187
189
|
|
|
188
190
|
|
|
@@ -193,14 +195,14 @@ class ServerError(APIError):
|
|
|
193
195
|
Applications should implement retry logic for transient server errors.
|
|
194
196
|
"""
|
|
195
197
|
|
|
196
|
-
def __init__(self, message: str, model: Model | None = None):
|
|
198
|
+
def __init__(self, message: str, model: Model | None = None) -> None:
|
|
197
199
|
super().__init__(message, "server_error", model)
|
|
198
200
|
|
|
199
201
|
|
|
200
202
|
class ControlRequestError(ClaudeSDKError):
|
|
201
203
|
"""Raised when a control protocol request fails."""
|
|
202
204
|
|
|
203
|
-
def __init__(self, message: str, subtype: str | None = None):
|
|
205
|
+
def __init__(self, message: str, subtype: str | None = None) -> None:
|
|
204
206
|
self.subtype = subtype
|
|
205
207
|
super().__init__(message)
|
|
206
208
|
|
|
@@ -224,7 +226,7 @@ class McpError(ControlRequestError):
|
|
|
224
226
|
error_code: int | None = None,
|
|
225
227
|
server_name: str | None = None,
|
|
226
228
|
subtype: str | None = None,
|
|
227
|
-
):
|
|
229
|
+
) -> None:
|
|
228
230
|
self.error_code = error_code
|
|
229
231
|
self.server_name = server_name
|
|
230
232
|
super().__init__(message, subtype=subtype)
|
|
@@ -93,7 +93,7 @@ class Query:
|
|
|
93
93
|
on_elicitation: OnElicitation | None = None,
|
|
94
94
|
hooks: dict[HookEvent, list[HookMatcher]] | None = None,
|
|
95
95
|
sdk_mcp_servers: dict[str, McpServer] | None = None,
|
|
96
|
-
):
|
|
96
|
+
) -> None:
|
|
97
97
|
"""Initialize Query with transport and callbacks.
|
|
98
98
|
|
|
99
99
|
Args:
|
|
@@ -64,7 +64,7 @@ atexit.register(_kill_active_children)
|
|
|
64
64
|
class SubprocessCLITransport(Transport):
|
|
65
65
|
"""Subprocess transport using Claude Code CLI."""
|
|
66
66
|
|
|
67
|
-
def __init__(self, options: ClaudeAgentOptions | None = None):
|
|
67
|
+
def __init__(self, options: ClaudeAgentOptions | None = None) -> None:
|
|
68
68
|
self._options = options or ClaudeAgentOptions()
|
|
69
69
|
self._cli_path = str(opts) if (opts := self._options.cli_path) is not None else None
|
|
70
70
|
self._process: Process | None = None
|
|
@@ -42,6 +42,7 @@ from clawd_code_sdk.models.content_blocks import (
|
|
|
42
42
|
TextBlock,
|
|
43
43
|
ThinkingBlock,
|
|
44
44
|
ToolUseBlock,
|
|
45
|
+
is_server_block,
|
|
45
46
|
)
|
|
46
47
|
|
|
47
48
|
|
|
@@ -54,6 +55,7 @@ if TYPE_CHECKING:
|
|
|
54
55
|
)
|
|
55
56
|
|
|
56
57
|
from clawd_code_sdk.models import Message
|
|
58
|
+
from clawd_code_sdk.models.content_blocks import AssistantContentBlock, ServerContentBlock
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
async def to_anthropic_events(
|
|
@@ -171,9 +173,14 @@ def _synthesize_events(
|
|
|
171
173
|
|
|
172
174
|
|
|
173
175
|
def _to_anthropic_block(
|
|
174
|
-
block:
|
|
175
|
-
) -> ATextBlock | AThinkingBlock | AToolUseBlock | None:
|
|
176
|
-
"""Convert a content block to its Anthropic start-event form (empty content).
|
|
176
|
+
block: AssistantContentBlock,
|
|
177
|
+
) -> ATextBlock | AThinkingBlock | AToolUseBlock | ServerContentBlock | None:
|
|
178
|
+
"""Convert a content block to its Anthropic start-event form (empty content).
|
|
179
|
+
|
|
180
|
+
API-produced blocks already are Anthropic models and are sent complete.
|
|
181
|
+
"""
|
|
182
|
+
if is_server_block(block):
|
|
183
|
+
return block
|
|
177
184
|
match block:
|
|
178
185
|
case TextBlock():
|
|
179
186
|
return ATextBlock(type="text", text="")
|
|
@@ -186,7 +193,7 @@ def _to_anthropic_block(
|
|
|
186
193
|
|
|
187
194
|
|
|
188
195
|
def _to_anthropic_delta(
|
|
189
|
-
block:
|
|
196
|
+
block: AssistantContentBlock,
|
|
190
197
|
) -> BetaTextDelta | BetaThinkingDelta | BetaInputJSONDeltaType | None:
|
|
191
198
|
"""Convert a content block's content into a single delta event."""
|
|
192
199
|
from anthropic.types.beta import BetaInputJSONDelta
|
|
@@ -147,7 +147,7 @@ class ClaudeSDKClient:
|
|
|
147
147
|
self,
|
|
148
148
|
options: ClaudeAgentOptions | None = None,
|
|
149
149
|
transport: Transport | None = None,
|
|
150
|
-
):
|
|
150
|
+
) -> None:
|
|
151
151
|
"""Initialize Claude SDK client."""
|
|
152
152
|
options = options or ClaudeAgentOptions()
|
|
153
153
|
self.options = options
|
|
@@ -783,7 +783,7 @@ class ClaudeSDKClient:
|
|
|
783
783
|
input_messages: list[ChatMessage] = []
|
|
784
784
|
if prompt := self._logfire_prompt:
|
|
785
785
|
part = TextPart(type="text", content=prompt)
|
|
786
|
-
input_messages = [ChatMessage(role="user", parts=[part])]
|
|
786
|
+
input_messages = [ChatMessage(role="user", parts=[part])]
|
|
787
787
|
|
|
788
788
|
span_data: dict[str, Any] = {
|
|
789
789
|
OPERATION_NAME: "invoke_agent",
|
|
@@ -63,7 +63,7 @@ class ConversationState:
|
|
|
63
63
|
part = ToolCallResponsePart(
|
|
64
64
|
type="tool_call_response", id=tool_use_id, name=tool_name, response=result
|
|
65
65
|
)
|
|
66
|
-
msg = ChatMessage(role="tool", parts=[part])
|
|
66
|
+
msg = ChatMessage(role="tool", parts=[part])
|
|
67
67
|
self._history.append(msg)
|
|
68
68
|
|
|
69
69
|
def open_chat_span(self) -> None:
|
|
@@ -114,7 +114,7 @@ class ConversationState:
|
|
|
114
114
|
self._current_span.set_attribute(REQUEST_MODEL, model)
|
|
115
115
|
self._current_span.set_attribute(RESPONSE_MODEL, model)
|
|
116
116
|
self._current_span.message = f"chat {model}"
|
|
117
|
-
self._current_span.update_name(f"chat {model}") #
|
|
117
|
+
self._current_span.update_name(f"chat {model}") # ty: ignore[missing-attribute]
|
|
118
118
|
if error := message.error:
|
|
119
119
|
self._current_span.set_attribute(ERROR_TYPE, str(error))
|
|
120
120
|
self._current_span.set_level("error")
|
|
@@ -234,7 +234,7 @@ def build_input_schema(input_schema: type | dict[str, Any]) -> dict[str, Any]:
|
|
|
234
234
|
case type() as tp:
|
|
235
235
|
return TypeAdapter(tp).json_schema()
|
|
236
236
|
case _ as unreachable:
|
|
237
|
-
assert_never(unreachable)
|
|
237
|
+
assert_never(unreachable)
|
|
238
238
|
|
|
239
239
|
|
|
240
240
|
def build_tool_meta(tool_def: SdkMcpTool[Any]) -> dict[str, Any] | None:
|
|
@@ -306,7 +306,16 @@ from .content_blocks import (
|
|
|
306
306
|
AssistantContentBlock,
|
|
307
307
|
AssistantMessageContent,
|
|
308
308
|
ContentBlock,
|
|
309
|
+
Base64PDFSource,
|
|
310
|
+
ContentDocumentSource,
|
|
311
|
+
DocumentBlock,
|
|
312
|
+
DocumentSource,
|
|
313
|
+
FileDocumentSource,
|
|
309
314
|
ImageBlock,
|
|
315
|
+
PlainTextSource,
|
|
316
|
+
SERVER_CONTENT_BLOCK_TYPES,
|
|
317
|
+
ServerContentBlock,
|
|
318
|
+
URLPDFSource,
|
|
310
319
|
ImageSource,
|
|
311
320
|
MessageParam,
|
|
312
321
|
TextBlock,
|
|
@@ -487,6 +496,7 @@ If not provided, elicitation requests will be declined automatically.
|
|
|
487
496
|
"""
|
|
488
497
|
|
|
489
498
|
__all__ = [
|
|
499
|
+
"SERVER_CONTENT_BLOCK_TYPES",
|
|
490
500
|
"TOOL_INPUT_TYPES",
|
|
491
501
|
"TOOL_USE_RESULT_TYPES",
|
|
492
502
|
"APIRetrySystemMessage",
|
|
@@ -518,6 +528,7 @@ __all__ = [
|
|
|
518
528
|
"AsyncHookJSONOutput",
|
|
519
529
|
"AuthStatusMessage",
|
|
520
530
|
"BackgroundTasksChangedMessage",
|
|
531
|
+
"Base64PDFSource",
|
|
521
532
|
"BaseHookInput",
|
|
522
533
|
"BaseResultMessage",
|
|
523
534
|
"BaseSessionConfig",
|
|
@@ -539,6 +550,7 @@ __all__ = [
|
|
|
539
550
|
"CompactBoundarySystemMessage",
|
|
540
551
|
"ConfigOutput",
|
|
541
552
|
"ContentBlock",
|
|
553
|
+
"ContentDocumentSource",
|
|
542
554
|
"ContextUsageAgent",
|
|
543
555
|
"ContextUsageAttachmentBreakdown",
|
|
544
556
|
"ContextUsageCategory",
|
|
@@ -563,7 +575,9 @@ __all__ = [
|
|
|
563
575
|
"CwdChangedHookInput",
|
|
564
576
|
"CwdChangedHookSpecificOutput",
|
|
565
577
|
"DirectoryAddedHookInput",
|
|
578
|
+
"DocumentBlock",
|
|
566
579
|
"DocumentMediaType",
|
|
580
|
+
"DocumentSource",
|
|
567
581
|
"EditOutput",
|
|
568
582
|
"ElicitationAction",
|
|
569
583
|
"ElicitationCompleteMessage",
|
|
@@ -584,6 +598,7 @@ __all__ = [
|
|
|
584
598
|
"FastModeState",
|
|
585
599
|
"FileChangedHookInput",
|
|
586
600
|
"FileChangedHookSpecificOutput",
|
|
601
|
+
"FileDocumentSource",
|
|
587
602
|
"FileEditInput",
|
|
588
603
|
"FileReadInput",
|
|
589
604
|
"FileWriteInput",
|
|
@@ -686,6 +701,7 @@ __all__ = [
|
|
|
686
701
|
"PermissionUpdateDestination",
|
|
687
702
|
"Permissions",
|
|
688
703
|
"PlainTextMediaType",
|
|
704
|
+
"PlainTextSource",
|
|
689
705
|
"PluginInstallSystemMessage",
|
|
690
706
|
"PostCompactHookInput",
|
|
691
707
|
"PostModelSwitchHookInput",
|
|
@@ -792,6 +808,7 @@ __all__ = [
|
|
|
792
808
|
"Sandbox",
|
|
793
809
|
"SdkBeta",
|
|
794
810
|
"SdkPluginConfig",
|
|
811
|
+
"ServerContentBlock",
|
|
795
812
|
"SessionConfig",
|
|
796
813
|
"SessionEndHookInput",
|
|
797
814
|
"SessionKey",
|
|
@@ -853,6 +870,7 @@ __all__ = [
|
|
|
853
870
|
"ToolUseSummaryMessage",
|
|
854
871
|
"ToolsPreset",
|
|
855
872
|
"TriggerMetadata",
|
|
873
|
+
"URLPDFSource",
|
|
856
874
|
"Usage",
|
|
857
875
|
"UserContentBlock",
|
|
858
876
|
"UserDocumentPrompt",
|
|
@@ -8,9 +8,26 @@ therefore serves both purposes, avoiding a redundant conversion layer.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
from collections.abc import Sequence
|
|
11
|
-
from typing import TYPE_CHECKING, Annotated, Any, Literal, assert_never, cast
|
|
11
|
+
from typing import TYPE_CHECKING, Annotated, Any, Literal, TypeIs, assert_never, cast, get_args
|
|
12
12
|
|
|
13
13
|
from anthropic.types import Model
|
|
14
|
+
from anthropic.types.beta import (
|
|
15
|
+
BetaAdvisorToolResultBlock,
|
|
16
|
+
BetaBashCodeExecutionToolResultBlock,
|
|
17
|
+
BetaCodeExecutionToolResultBlock,
|
|
18
|
+
BetaCompactionBlock,
|
|
19
|
+
BetaContainerUploadBlock,
|
|
20
|
+
BetaFallbackBlock,
|
|
21
|
+
BetaMCPToolListingBlock,
|
|
22
|
+
BetaMCPToolResultBlock,
|
|
23
|
+
BetaMCPToolUseBlock,
|
|
24
|
+
BetaRedactedThinkingBlock,
|
|
25
|
+
BetaServerToolUseBlock,
|
|
26
|
+
BetaTextEditorCodeExecutionToolResultBlock,
|
|
27
|
+
BetaToolSearchToolResultBlock,
|
|
28
|
+
BetaWebFetchToolResultBlock,
|
|
29
|
+
BetaWebSearchToolResultBlock,
|
|
30
|
+
)
|
|
14
31
|
from anthropic.types.beta.beta_tool_use_block import Caller
|
|
15
32
|
from pydantic import BaseModel, ConfigDict, Discriminator
|
|
16
33
|
|
|
@@ -21,6 +38,7 @@ from clawd_code_sdk.models.base import ClaudeCodeBaseModel, StopReason, ToolName
|
|
|
21
38
|
if TYPE_CHECKING:
|
|
22
39
|
from logfire._internal.integrations.llm_providers.semconv import (
|
|
23
40
|
BlobPart,
|
|
41
|
+
MessagePart,
|
|
24
42
|
ReasoningPart,
|
|
25
43
|
TextPart,
|
|
26
44
|
ToolCallPart,
|
|
@@ -148,24 +166,153 @@ class ImageBlock(BaseContentBlock):
|
|
|
148
166
|
)
|
|
149
167
|
|
|
150
168
|
|
|
169
|
+
class Base64PDFSource(BaseContentBlock):
|
|
170
|
+
"""Base64-encoded PDF document."""
|
|
171
|
+
|
|
172
|
+
type: Literal["base64"] = "base64"
|
|
173
|
+
media_type: Literal["application/pdf"] = "application/pdf"
|
|
174
|
+
data: str
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class PlainTextSource(BaseContentBlock):
|
|
178
|
+
"""Plain text document."""
|
|
179
|
+
|
|
180
|
+
type: Literal["text"] = "text"
|
|
181
|
+
media_type: Literal["text/plain"] = "text/plain"
|
|
182
|
+
data: str
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class URLPDFSource(BaseContentBlock):
|
|
186
|
+
"""PDF document referenced by URL."""
|
|
187
|
+
|
|
188
|
+
type: Literal["url"] = "url"
|
|
189
|
+
url: str
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class FileDocumentSource(BaseContentBlock):
|
|
193
|
+
"""Document uploaded through the Files API."""
|
|
194
|
+
|
|
195
|
+
type: Literal["file"] = "file"
|
|
196
|
+
file_id: str
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class ContentDocumentSource(BaseContentBlock):
|
|
200
|
+
"""Document made of content blocks (text / images)."""
|
|
201
|
+
|
|
202
|
+
type: Literal["content"] = "content"
|
|
203
|
+
content: str | list[dict[str, Any]]
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
type DocumentSource = Annotated[
|
|
207
|
+
Base64PDFSource | PlainTextSource | URLPDFSource | FileDocumentSource | ContentDocumentSource,
|
|
208
|
+
Discriminator("type"),
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class DocumentBlock(BaseContentBlock):
|
|
213
|
+
"""Document content block (e.g. an attached PDF) in a user message."""
|
|
214
|
+
|
|
215
|
+
type: Literal["document"] = "document"
|
|
216
|
+
source: DocumentSource
|
|
217
|
+
title: str | None = None
|
|
218
|
+
context: str | None = None
|
|
219
|
+
citations: dict[str, Any] | None = None
|
|
220
|
+
|
|
221
|
+
|
|
151
222
|
# =============================================================================
|
|
152
223
|
# Unions and adapters
|
|
153
224
|
# =============================================================================
|
|
154
225
|
|
|
226
|
+
type ServerContentBlock = (
|
|
227
|
+
BetaRedactedThinkingBlock
|
|
228
|
+
| BetaServerToolUseBlock
|
|
229
|
+
| BetaWebSearchToolResultBlock
|
|
230
|
+
| BetaWebFetchToolResultBlock
|
|
231
|
+
| BetaAdvisorToolResultBlock
|
|
232
|
+
| BetaCodeExecutionToolResultBlock
|
|
233
|
+
| BetaBashCodeExecutionToolResultBlock
|
|
234
|
+
| BetaTextEditorCodeExecutionToolResultBlock
|
|
235
|
+
| BetaToolSearchToolResultBlock
|
|
236
|
+
| BetaMCPToolUseBlock
|
|
237
|
+
| BetaMCPToolResultBlock
|
|
238
|
+
| BetaContainerUploadBlock
|
|
239
|
+
| BetaCompactionBlock
|
|
240
|
+
| BetaFallbackBlock
|
|
241
|
+
| BetaMCPToolListingBlock
|
|
242
|
+
)
|
|
243
|
+
"""Assistant content blocks produced by the API itself (server tools, MCP connector, ...).
|
|
244
|
+
|
|
245
|
+
These use the Anthropic SDK's models directly; clawd has no extra behaviour for them.
|
|
246
|
+
"""
|
|
247
|
+
|
|
248
|
+
SERVER_CONTENT_BLOCK_TYPES: tuple[type[BaseModel], ...] = get_args(ServerContentBlock.__value__)
|
|
249
|
+
"""Runtime tuple of :data:`ServerContentBlock` members (for ``isinstance`` checks)."""
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def is_server_block(block: object) -> TypeIs[ServerContentBlock]:
|
|
253
|
+
"""Whether a content block was produced by the API itself (see :data:`ServerContentBlock`)."""
|
|
254
|
+
return isinstance(block, SERVER_CONTENT_BLOCK_TYPES)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def server_block_to_otel(block: ServerContentBlock) -> MessagePart | None:
|
|
258
|
+
"""OpenTelemetry semconv part for an API-produced block (None if it has no equivalent)."""
|
|
259
|
+
from logfire._internal.integrations.llm_providers.semconv import (
|
|
260
|
+
ReasoningPart,
|
|
261
|
+
ToolCallPart,
|
|
262
|
+
ToolCallResponsePart,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
match block:
|
|
266
|
+
case BetaRedactedThinkingBlock():
|
|
267
|
+
return ReasoningPart(type="reasoning", content="[redacted]")
|
|
268
|
+
case (
|
|
269
|
+
BetaServerToolUseBlock(id=tool_id, name=name, input=input_)
|
|
270
|
+
| BetaMCPToolUseBlock(id=tool_id, name=name, input=input_)
|
|
271
|
+
):
|
|
272
|
+
return ToolCallPart(type="tool_call", id=tool_id, name=name, arguments=input_)
|
|
273
|
+
case (
|
|
274
|
+
BetaWebSearchToolResultBlock(tool_use_id=tool_id)
|
|
275
|
+
| BetaWebFetchToolResultBlock(tool_use_id=tool_id)
|
|
276
|
+
| BetaAdvisorToolResultBlock(tool_use_id=tool_id)
|
|
277
|
+
| BetaCodeExecutionToolResultBlock(tool_use_id=tool_id)
|
|
278
|
+
| BetaBashCodeExecutionToolResultBlock(tool_use_id=tool_id)
|
|
279
|
+
| BetaTextEditorCodeExecutionToolResultBlock(tool_use_id=tool_id)
|
|
280
|
+
| BetaToolSearchToolResultBlock(tool_use_id=tool_id)
|
|
281
|
+
| BetaMCPToolResultBlock(tool_use_id=tool_id)
|
|
282
|
+
):
|
|
283
|
+
response = block.model_dump(mode="json", exclude={"type", "tool_use_id"})
|
|
284
|
+
return ToolCallResponsePart(type="tool_call_response", id=tool_id, response=response)
|
|
285
|
+
case (
|
|
286
|
+
BetaContainerUploadBlock()
|
|
287
|
+
| BetaCompactionBlock()
|
|
288
|
+
| BetaFallbackBlock()
|
|
289
|
+
| BetaMCPToolListingBlock()
|
|
290
|
+
):
|
|
291
|
+
return None
|
|
292
|
+
case _ as unreachable:
|
|
293
|
+
assert_never(unreachable)
|
|
294
|
+
|
|
295
|
+
|
|
155
296
|
AssistantContentBlock = Annotated[
|
|
156
|
-
TextBlock | ThinkingBlock | ToolUseBlock,
|
|
297
|
+
TextBlock | ThinkingBlock | ToolUseBlock | ServerContentBlock,
|
|
157
298
|
Discriminator("type"),
|
|
158
299
|
]
|
|
159
|
-
"""Content blocks that appear in assistant messages."""
|
|
300
|
+
"""Content blocks that appear in assistant messages (any Messages API block type)."""
|
|
160
301
|
|
|
161
302
|
UserContentBlock = Annotated[
|
|
162
|
-
TextBlock | ToolResultBlock | ImageBlock,
|
|
303
|
+
TextBlock | ToolResultBlock | ImageBlock | DocumentBlock,
|
|
163
304
|
Discriminator("type"),
|
|
164
305
|
]
|
|
165
306
|
"""Content blocks that appear in user messages."""
|
|
166
307
|
|
|
167
308
|
ContentBlock = Annotated[
|
|
168
|
-
TextBlock
|
|
309
|
+
TextBlock
|
|
310
|
+
| ThinkingBlock
|
|
311
|
+
| ToolUseBlock
|
|
312
|
+
| ToolResultBlock
|
|
313
|
+
| ImageBlock
|
|
314
|
+
| DocumentBlock
|
|
315
|
+
| ServerContentBlock,
|
|
169
316
|
Discriminator("type"),
|
|
170
317
|
]
|
|
171
318
|
"""All content block types (used for storage/JSONL which doesn't distinguish by role)."""
|
|
@@ -197,7 +197,7 @@ GrepInput = TypedDict(
|
|
|
197
197
|
},
|
|
198
198
|
)
|
|
199
199
|
"""Input for the Grep tool. Powerful search built on ripgrep with regex support."""
|
|
200
|
-
GrepInput.__pydantic_config__ = ConfigDict(extra="allow") #
|
|
200
|
+
GrepInput.__pydantic_config__ = ConfigDict(extra="allow") # ty: ignore[missing-attribute]
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
@_extra_allow
|
|
@@ -404,7 +404,15 @@ class AssistantMessage(BaseModel):
|
|
|
404
404
|
"""Convert SDK content block objects into semconv OutputMessages."""
|
|
405
405
|
from logfire._internal.integrations.llm_providers.semconv import OutputMessage
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
from clawd_code_sdk.models.content_blocks import is_server_block, server_block_to_otel
|
|
408
|
+
|
|
409
|
+
parts: list[MessagePart] = []
|
|
410
|
+
for block in self.content:
|
|
411
|
+
if is_server_block(block):
|
|
412
|
+
if (part := server_block_to_otel(block)) is not None:
|
|
413
|
+
parts.append(part)
|
|
414
|
+
else:
|
|
415
|
+
parts.append(block.to_otel())
|
|
408
416
|
return OutputMessage(role="assistant", parts=parts)
|
|
409
417
|
|
|
410
418
|
|