clawd-code-sdk 0.5.0__tar.gz → 0.5.2__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-0.5.0 → clawd_code_sdk-0.5.2}/PKG-INFO +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/pyproject.toml +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/message_parser.py +5 -7
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/query.py +19 -11
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +15 -11
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/anthropic_types.py +9 -7
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/client.py +17 -11
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/list_sessions.py +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/__init__.py +39 -27
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/agents.py +1 -9
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/base.py +1 -23
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/content_blocks.py +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/mcp.py +2 -2
- clawd_code_sdk-0.5.2/src/clawd_code_sdk/models/messages.py +380 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/options.py +3 -2
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/output_types.py +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/permissions.py +20 -16
- clawd_code_sdk-0.5.2/src/clawd_code_sdk/models/prompt_requests.py +37 -0
- clawd_code_sdk-0.5.2/src/clawd_code_sdk/models/prompts.py +162 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/server_info.py +1 -2
- clawd_code_sdk-0.5.2/src/clawd_code_sdk/models/system_messages.py +252 -0
- clawd_code_sdk-0.5.2/src/clawd_code_sdk/models/thinking.py +30 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/query.py +1 -2
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/session.py +8 -4
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/storage/models.py +1 -1
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/storage/replay.py +6 -9
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_agents_and_settings.py +0 -10
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_dynamic_control.py +0 -3
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_hook_events.py +4 -18
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_hooks.py +0 -3
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_include_partial_messages.py +1 -3
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_mcp_tools.py +2 -5
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_stderr_callback.py +0 -2
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_structured_output.py +1 -5
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_subagent_invocation.py +1 -4
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_tool_permissions.py +1 -2
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_client.py +8 -4
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_integration.py +7 -5
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_sdk_mcp_integration.py +25 -89
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_session.py +2 -2
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_tool_callbacks.py +0 -6
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_transport.py +20 -11
- clawd_code_sdk-0.5.0/src/clawd_code_sdk/models/messages.py +0 -801
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/.gitignore +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/LICENSE +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/README.md +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/__init__.py +3 -3
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_errors.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/__init__.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_version.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/mcp_utils.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/control.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/hooks.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/input_types.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/models/sandbox.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/py.typed +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/storage/__init__.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/storage/helpers.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/usage.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/__init__.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/conftest.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/__init__.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_sdk_mcp_tools.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/e2e/test_slash_commands.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/mcp_server.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/mock_claude_server.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_changelog.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_errors.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_image.png +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_message_parser.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_streaming_client.py +0 -0
- {clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/tests/test_subprocess_buffering.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clawd-code-sdk
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
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
|
{clawd_code_sdk-0.5.0 → clawd_code_sdk-0.5.2}/src/clawd_code_sdk/_internal/message_parser.py
RENAMED
|
@@ -10,20 +10,18 @@ from pydantic import TypeAdapter
|
|
|
10
10
|
from clawd_code_sdk._errors import MessageParseError
|
|
11
11
|
from clawd_code_sdk.models import (
|
|
12
12
|
AssistantMessage,
|
|
13
|
+
AuthStatusMessage,
|
|
14
|
+
PromptSuggestionMessage,
|
|
15
|
+
RateLimitMessage,
|
|
13
16
|
ResultErrorMessage,
|
|
14
17
|
ResultSuccessMessage,
|
|
15
18
|
StreamEvent,
|
|
19
|
+
ToolProgressMessage,
|
|
20
|
+
ToolUseSummaryMessage,
|
|
16
21
|
UserMessage,
|
|
17
22
|
content_block_adapter,
|
|
18
23
|
system_message_adapter,
|
|
19
24
|
)
|
|
20
|
-
from clawd_code_sdk.models.messages import (
|
|
21
|
-
AuthStatusMessage,
|
|
22
|
-
PromptSuggestionMessage,
|
|
23
|
-
RateLimitMessage,
|
|
24
|
-
ToolProgressMessage,
|
|
25
|
-
ToolUseSummaryMessage,
|
|
26
|
-
)
|
|
27
25
|
|
|
28
26
|
|
|
29
27
|
if TYPE_CHECKING:
|
|
@@ -13,8 +13,15 @@ import anyio
|
|
|
13
13
|
|
|
14
14
|
from clawd_code_sdk._errors import ControlRequestError, ControlRequestTimeoutError
|
|
15
15
|
from clawd_code_sdk.models import (
|
|
16
|
+
ClaudeCodeServerInfo,
|
|
17
|
+
ControlErrorResponse,
|
|
16
18
|
ControlResponse,
|
|
19
|
+
ElicitationRequest,
|
|
20
|
+
JSONRPCError,
|
|
21
|
+
JSONRPCErrorResponse,
|
|
22
|
+
JSONRPCResultResponse,
|
|
17
23
|
PermissionResultAllow,
|
|
24
|
+
SDKControlElicitationRequest,
|
|
18
25
|
SDKControlInitializeRequest,
|
|
19
26
|
SDKControlInterruptRequest,
|
|
20
27
|
SDKControlMcpMessageRequest,
|
|
@@ -27,10 +34,6 @@ from clawd_code_sdk.models import (
|
|
|
27
34
|
ToolPermissionContext,
|
|
28
35
|
control_request_adapter,
|
|
29
36
|
)
|
|
30
|
-
from clawd_code_sdk.models.control import ControlErrorResponse, SDKControlElicitationRequest
|
|
31
|
-
from clawd_code_sdk.models.mcp import JSONRPCError, JSONRPCErrorResponse, JSONRPCResultResponse
|
|
32
|
-
from clawd_code_sdk.models.permissions import ElicitationRequest
|
|
33
|
-
from clawd_code_sdk.models.server_info import ClaudeCodeServerInfo
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
if TYPE_CHECKING:
|
|
@@ -41,18 +44,23 @@ if TYPE_CHECKING:
|
|
|
41
44
|
from mcp.types import ContentBlock
|
|
42
45
|
|
|
43
46
|
from clawd_code_sdk._internal.transport import Transport
|
|
44
|
-
from clawd_code_sdk.models import
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
from clawd_code_sdk.models.input_types import AskUserQuestionInput
|
|
48
|
-
from clawd_code_sdk.models.mcp import JSONRPCMessage, JSONRPCResponse, RequestId
|
|
49
|
-
from clawd_code_sdk.models.permissions import (
|
|
47
|
+
from clawd_code_sdk.models import (
|
|
48
|
+
AgentDefinition,
|
|
49
|
+
AskUserQuestionInput,
|
|
50
50
|
CanUseTool,
|
|
51
|
+
ClaudeCodeAgentInfo,
|
|
52
|
+
ControlRequestUnion,
|
|
53
|
+
HookCallback,
|
|
54
|
+
HookEvent,
|
|
55
|
+
HookMatcher,
|
|
56
|
+
JSONRPCMessage,
|
|
57
|
+
JSONRPCResponse,
|
|
51
58
|
OnElicitation,
|
|
52
59
|
OnUserQuestion,
|
|
60
|
+
PermissionMode,
|
|
53
61
|
PermissionResult,
|
|
62
|
+
RequestId,
|
|
54
63
|
)
|
|
55
|
-
from clawd_code_sdk.models.server_info import ClaudeCodeAgentInfo
|
|
56
64
|
|
|
57
65
|
logger = logging.getLogger(__name__)
|
|
58
66
|
|
|
@@ -26,7 +26,7 @@ from clawd_code_sdk._errors import (
|
|
|
26
26
|
)
|
|
27
27
|
from clawd_code_sdk._internal.transport import Transport
|
|
28
28
|
from clawd_code_sdk._version import __version__
|
|
29
|
-
from clawd_code_sdk.models.
|
|
29
|
+
from clawd_code_sdk.models.thinking import (
|
|
30
30
|
ThinkingConfigAdaptive,
|
|
31
31
|
ThinkingConfigDisabled,
|
|
32
32
|
ThinkingConfigEnabled,
|
|
@@ -118,7 +118,7 @@ class SubprocessCLITransport(Transport):
|
|
|
118
118
|
cmd.extend(["--permission-mode", self._options.permission_mode])
|
|
119
119
|
|
|
120
120
|
# Session configuration
|
|
121
|
-
from clawd_code_sdk.models
|
|
121
|
+
from clawd_code_sdk.models import (
|
|
122
122
|
ContinueLatest,
|
|
123
123
|
FromPR,
|
|
124
124
|
NewSession,
|
|
@@ -195,10 +195,10 @@ class SubprocessCLITransport(Transport):
|
|
|
195
195
|
|
|
196
196
|
# Add plugin directories
|
|
197
197
|
for plugin in self._options.plugins:
|
|
198
|
-
if plugin
|
|
199
|
-
cmd.extend(["--plugin-dir", plugin
|
|
198
|
+
if plugin.type == "local":
|
|
199
|
+
cmd.extend(["--plugin-dir", plugin.path])
|
|
200
200
|
else:
|
|
201
|
-
raise ValueError(f"Unsupported plugin type: {plugin
|
|
201
|
+
raise ValueError(f"Unsupported plugin type: {plugin.type}")
|
|
202
202
|
|
|
203
203
|
# Add extra args for future CLI flags
|
|
204
204
|
for flag, value in self._options.extra_args.items():
|
|
@@ -349,14 +349,18 @@ class SubprocessCLITransport(Transport):
|
|
|
349
349
|
await self._stderr_stream.aclose()
|
|
350
350
|
self._stderr_stream = None
|
|
351
351
|
|
|
352
|
-
#
|
|
352
|
+
# Wait for process to exit gracefully after stdin EOF,
|
|
353
|
+
# giving the CLI time to flush the session transcript.
|
|
354
|
+
# Only resort to SIGTERM if it doesn't exit in time.
|
|
353
355
|
if self._process.returncode is None:
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
# Wait for process to finish with timeout
|
|
357
|
-
with suppress(Exception):
|
|
358
|
-
# Just try to wait, but don't block if it fails
|
|
356
|
+
try:
|
|
357
|
+
with anyio.fail_after(10):
|
|
359
358
|
await self._process.wait()
|
|
359
|
+
except TimeoutError:
|
|
360
|
+
with suppress(ProcessLookupError):
|
|
361
|
+
self._process.terminate()
|
|
362
|
+
with suppress(Exception):
|
|
363
|
+
await self._process.wait()
|
|
360
364
|
|
|
361
365
|
self._process = None
|
|
362
366
|
self._stdout_stream = None
|
|
@@ -9,13 +9,13 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
from typing import Annotated
|
|
11
11
|
|
|
12
|
-
from anthropic.types import TextBlock, WebSearchResultBlock, WebSearchToolResultError
|
|
13
12
|
from anthropic.types.beta import (
|
|
14
13
|
BetaBashCodeExecutionResultBlock,
|
|
15
14
|
BetaBashCodeExecutionToolResultError,
|
|
16
15
|
BetaCodeExecutionResultBlock,
|
|
17
16
|
BetaCodeExecutionToolResultError,
|
|
18
17
|
BetaImageBlockParam,
|
|
18
|
+
BetaTextBlock,
|
|
19
19
|
BetaTextEditorCodeExecutionCreateResultBlock,
|
|
20
20
|
BetaTextEditorCodeExecutionStrReplaceResultBlock,
|
|
21
21
|
BetaTextEditorCodeExecutionToolResultError,
|
|
@@ -25,6 +25,8 @@ from anthropic.types.beta import (
|
|
|
25
25
|
BetaToolSearchToolSearchResultBlock,
|
|
26
26
|
BetaWebFetchBlock,
|
|
27
27
|
BetaWebFetchToolResultErrorBlock,
|
|
28
|
+
BetaWebSearchResultBlock,
|
|
29
|
+
BetaWebSearchToolResultError,
|
|
28
30
|
)
|
|
29
31
|
from pydantic import BaseModel, Field, TypeAdapter
|
|
30
32
|
|
|
@@ -52,13 +54,13 @@ from pydantic import BaseModel, Field, TypeAdapter
|
|
|
52
54
|
# - "text_editor_code_execution_str_replace_result" -> BetaTextEditorCodeExecutionStrReplaceResultBlock # noqa: E501
|
|
53
55
|
# - "text_editor_code_execution_tool_result_error" -> BetaTextEditorCodeExecutionToolResultError
|
|
54
56
|
ToolResultContentBlock = Annotated[
|
|
55
|
-
|
|
57
|
+
BetaTextBlock
|
|
56
58
|
| BetaImageBlockParam
|
|
57
59
|
| BetaToolReferenceBlock
|
|
58
60
|
| BetaToolSearchToolSearchResultBlock
|
|
59
61
|
| BetaToolSearchToolResultError
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
+
| BetaWebSearchResultBlock
|
|
63
|
+
| BetaWebSearchToolResultError
|
|
62
64
|
| BetaWebFetchBlock
|
|
63
65
|
| BetaWebFetchToolResultErrorBlock
|
|
64
66
|
| BetaCodeExecutionResultBlock
|
|
@@ -79,9 +81,9 @@ def _get_adapter() -> TypeAdapter[list[ToolResultContentBlock]]:
|
|
|
79
81
|
if _tool_result_content_adapter is None:
|
|
80
82
|
# Force schema build for Anthropic models (deferred by default)
|
|
81
83
|
for model in [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
BetaTextBlock,
|
|
85
|
+
BetaWebSearchResultBlock,
|
|
86
|
+
BetaWebSearchToolResultError,
|
|
85
87
|
BetaBashCodeExecutionResultBlock,
|
|
86
88
|
BetaBashCodeExecutionToolResultError,
|
|
87
89
|
BetaCodeExecutionResultBlock,
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from dataclasses import replace
|
|
6
6
|
import os
|
|
7
|
-
from typing import TYPE_CHECKING, Any, Self
|
|
7
|
+
from typing import TYPE_CHECKING, Any, Literal, Self
|
|
8
8
|
|
|
9
9
|
import anyenv
|
|
10
10
|
from pydantic import TypeAdapter
|
|
@@ -12,17 +12,16 @@ from pydantic import TypeAdapter
|
|
|
12
12
|
from clawd_code_sdk._errors import CLIConnectionError
|
|
13
13
|
from clawd_code_sdk.models import (
|
|
14
14
|
AccumulatedUsage,
|
|
15
|
-
ClaudeAgentOptions,
|
|
16
|
-
ResultMessage,
|
|
17
|
-
)
|
|
18
|
-
from clawd_code_sdk.models.mcp import McpStatusResponse
|
|
19
|
-
from clawd_code_sdk.models.messages import (
|
|
20
15
|
AssistantMessage,
|
|
16
|
+
ClaudeAgentOptions,
|
|
17
|
+
ClaudeCodeAgentInfo, # noqa: TC001
|
|
18
|
+
McpStatusResponse,
|
|
21
19
|
ResultErrorMessage,
|
|
20
|
+
ResultMessage,
|
|
22
21
|
ResultSuccessMessage,
|
|
22
|
+
StatusSystemMessage,
|
|
23
23
|
UserTextPrompt,
|
|
24
24
|
)
|
|
25
|
-
from clawd_code_sdk.models.server_info import ClaudeCodeAgentInfo # noqa: TC001
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
if TYPE_CHECKING:
|
|
@@ -30,10 +29,13 @@ if TYPE_CHECKING:
|
|
|
30
29
|
|
|
31
30
|
from clawd_code_sdk import Transport
|
|
32
31
|
from clawd_code_sdk._internal.query import Query
|
|
33
|
-
from clawd_code_sdk.models import
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
from clawd_code_sdk.models import (
|
|
33
|
+
ClaudeCodeServerInfo,
|
|
34
|
+
McpServerConfig,
|
|
35
|
+
Message,
|
|
36
|
+
PermissionMode,
|
|
37
|
+
UserPrompt,
|
|
38
|
+
)
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
class ClaudeSDKClient:
|
|
@@ -69,6 +71,8 @@ class ClaudeSDKClient:
|
|
|
69
71
|
"""Cumulative token usage across all queries in this session."""
|
|
70
72
|
self.query_usage: AccumulatedUsage = AccumulatedUsage()
|
|
71
73
|
"""Token usage for the current/last query only (reset on each query() call)."""
|
|
74
|
+
self.status: Literal["compacting"] | None = None
|
|
75
|
+
"""Current client status, or None when idle."""
|
|
72
76
|
|
|
73
77
|
def _ensure_connected(self) -> Query:
|
|
74
78
|
"""Return the active Query, raising if not connected."""
|
|
@@ -156,6 +160,8 @@ class ClaudeSDKClient:
|
|
|
156
160
|
match message:
|
|
157
161
|
case AssistantMessage():
|
|
158
162
|
message.raise_if_api_error()
|
|
163
|
+
case StatusSystemMessage(status=status):
|
|
164
|
+
self.status = status
|
|
159
165
|
case ResultSuccessMessage() | ResultErrorMessage():
|
|
160
166
|
self.query_usage.accumulate(message.usage)
|
|
161
167
|
self.session_usage.accumulate(message.usage)
|
|
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING
|
|
|
8
8
|
|
|
9
9
|
import anyenv
|
|
10
10
|
|
|
11
|
-
from clawd_code_sdk.models
|
|
11
|
+
from clawd_code_sdk.models import SDKSessionInfo
|
|
12
12
|
from clawd_code_sdk.storage.helpers import (
|
|
13
13
|
decode_project_path,
|
|
14
14
|
get_claude_projects_dir,
|
|
@@ -15,7 +15,7 @@ Types are organized into submodules:
|
|
|
15
15
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
|
-
from .agents import AgentDefinition, AgentInfo,
|
|
18
|
+
from .agents import AgentDefinition, AgentInfo, ToolsPreset
|
|
19
19
|
from .base import (
|
|
20
20
|
ApiKeySource,
|
|
21
21
|
ElicitationAction,
|
|
@@ -26,6 +26,9 @@ from .base import (
|
|
|
26
26
|
SdkBeta,
|
|
27
27
|
SettingSource,
|
|
28
28
|
StopReason,
|
|
29
|
+
FastModeState,
|
|
30
|
+
)
|
|
31
|
+
from .thinking import (
|
|
29
32
|
ThinkingConfig,
|
|
30
33
|
ThinkingConfigAdaptive,
|
|
31
34
|
ThinkingConfigDisabled,
|
|
@@ -144,6 +147,7 @@ from .mcp import (
|
|
|
144
147
|
McpToolStatus,
|
|
145
148
|
RequestId,
|
|
146
149
|
SdkPluginConfig,
|
|
150
|
+
ExternalMcpServerConfig,
|
|
147
151
|
)
|
|
148
152
|
from .output_types import (
|
|
149
153
|
TOOL_USE_RESULT_TYPES,
|
|
@@ -222,21 +226,8 @@ from .messages import (
|
|
|
222
226
|
AccumulatedUsage,
|
|
223
227
|
AssistantMessage,
|
|
224
228
|
AssistantMessageError,
|
|
225
|
-
BaseSystemMessage,
|
|
226
|
-
CompactBoundarySystemMessage,
|
|
227
|
-
ElicitationCompleteMessage,
|
|
228
|
-
FastModeState,
|
|
229
|
-
HookResponseSystemMessage,
|
|
230
|
-
HookStartedSystemMessage,
|
|
231
|
-
InitSystemMessage,
|
|
232
|
-
LocalCommandOutputMessage,
|
|
233
|
-
McpServerStatus,
|
|
234
|
-
Message,
|
|
235
229
|
ModelUsage,
|
|
236
230
|
BaseResultMessage,
|
|
237
|
-
PromptRequest,
|
|
238
|
-
PromptRequestOption,
|
|
239
|
-
PromptResponse,
|
|
240
231
|
PromptSuggestionMessage,
|
|
241
232
|
RateLimitInfo,
|
|
242
233
|
RateLimitMessage,
|
|
@@ -245,34 +236,29 @@ from .messages import (
|
|
|
245
236
|
ResultSuccessMessage,
|
|
246
237
|
SDKPermissionDenial,
|
|
247
238
|
SDKSessionInfo,
|
|
248
|
-
StatusSystemMessage,
|
|
249
239
|
StreamEvent,
|
|
250
240
|
AuthStatusMessage,
|
|
251
|
-
FilesPersistedSystemMessage,
|
|
252
|
-
HookProgressSystemMessage,
|
|
253
|
-
TaskNotificationSystemMessage,
|
|
254
|
-
TaskProgressSystemMessage,
|
|
255
|
-
TaskProgressUsage,
|
|
256
|
-
TaskStartedSystemMessage,
|
|
257
241
|
ToolProgressMessage,
|
|
258
242
|
ToolUseSummaryMessage,
|
|
259
|
-
TriggerMetadata,
|
|
260
243
|
Usage,
|
|
244
|
+
MiscMessages,
|
|
261
245
|
UserMessage,
|
|
246
|
+
)
|
|
247
|
+
from .prompts import (
|
|
262
248
|
DocumentMediaType,
|
|
263
249
|
ImageMediaType,
|
|
264
|
-
PlainTextMediaType,
|
|
265
250
|
UserDocumentPrompt,
|
|
251
|
+
PlainTextMediaType,
|
|
266
252
|
UserDocumentURLPrompt,
|
|
267
253
|
UserImagePrompt,
|
|
268
254
|
UserImageURLPrompt,
|
|
269
255
|
UserPlainTextDocumentPrompt,
|
|
270
256
|
UserPrompt,
|
|
271
257
|
UserTextPrompt,
|
|
272
|
-
system_message_adapter,
|
|
273
258
|
)
|
|
274
|
-
from .
|
|
259
|
+
from .prompt_requests import PromptRequest, PromptRequestOption, PromptResponse
|
|
275
260
|
from .options import (
|
|
261
|
+
ClaudeAgentOptions,
|
|
276
262
|
BaseSessionConfig,
|
|
277
263
|
ContinueLatest,
|
|
278
264
|
FromPR,
|
|
@@ -297,9 +283,31 @@ from .permissions import (
|
|
|
297
283
|
ToolPermissionContext,
|
|
298
284
|
)
|
|
299
285
|
from .sandbox import SandboxIgnoreViolations, SandboxNetworkConfig, SandboxSettings
|
|
286
|
+
from .server_info import ClaudeCodeAgentInfo, ClaudeCodeServerInfo
|
|
287
|
+
from .system_messages import (
|
|
288
|
+
system_message_adapter,
|
|
289
|
+
TriggerMetadata,
|
|
290
|
+
TaskProgressUsage,
|
|
291
|
+
StatusSystemMessage,
|
|
292
|
+
BaseSystemMessage,
|
|
293
|
+
CompactBoundarySystemMessage,
|
|
294
|
+
HookResponseSystemMessage,
|
|
295
|
+
McpServerStatus,
|
|
296
|
+
HookStartedSystemMessage,
|
|
297
|
+
InitSystemMessage,
|
|
298
|
+
FilesPersistedSystemMessage,
|
|
299
|
+
HookProgressSystemMessage,
|
|
300
|
+
TaskNotificationSystemMessage,
|
|
301
|
+
TaskProgressSystemMessage,
|
|
302
|
+
TaskStartedSystemMessage,
|
|
303
|
+
SystemMessageUnion,
|
|
304
|
+
LocalCommandOutputMessage,
|
|
305
|
+
ElicitationCompleteMessage,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
Message = MiscMessages | SystemMessageUnion
|
|
300
309
|
|
|
301
310
|
__all__ = [
|
|
302
|
-
# mcp
|
|
303
311
|
"JSONRPC_VERSION",
|
|
304
312
|
"TOOL_INPUT_TYPES",
|
|
305
313
|
"TOOL_USE_RESULT_TYPES",
|
|
@@ -338,6 +346,8 @@ __all__ = [
|
|
|
338
346
|
"BashToolUseResult",
|
|
339
347
|
"CanUseTool",
|
|
340
348
|
"ClaudeAgentOptions",
|
|
349
|
+
"ClaudeCodeAgentInfo",
|
|
350
|
+
"ClaudeCodeServerInfo",
|
|
341
351
|
"CommandHookHandler",
|
|
342
352
|
"CompactBoundarySystemMessage",
|
|
343
353
|
"ConfigOutput",
|
|
@@ -363,6 +373,7 @@ __all__ = [
|
|
|
363
373
|
"EnterWorktreeOutput",
|
|
364
374
|
"ExitPlanModeInput",
|
|
365
375
|
"ExitPlanModeOutput",
|
|
376
|
+
"ExternalMcpServerConfig",
|
|
366
377
|
"FastModeState",
|
|
367
378
|
"FileEditInput",
|
|
368
379
|
"FileReadInput",
|
|
@@ -415,6 +426,7 @@ __all__ = [
|
|
|
415
426
|
"McpStdioServerConfig",
|
|
416
427
|
"McpToolStatus",
|
|
417
428
|
"Message",
|
|
429
|
+
"MiscMessages",
|
|
418
430
|
"ModelUsage",
|
|
419
431
|
"NewSession",
|
|
420
432
|
"NotebookEditInput",
|
|
@@ -509,7 +521,7 @@ __all__ = [
|
|
|
509
521
|
"SubscribeMcpResourceOutput",
|
|
510
522
|
"SubscribePollingOutput",
|
|
511
523
|
"SyncHookJSONOutput",
|
|
512
|
-
"
|
|
524
|
+
"SystemMessageUnion",
|
|
513
525
|
"TaskCompletedHookInput",
|
|
514
526
|
"TaskInfo",
|
|
515
527
|
"TaskNotificationSystemMessage",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass, fields
|
|
6
|
-
from typing import Any, Literal,
|
|
6
|
+
from typing import Any, Literal, TypedDict
|
|
7
7
|
|
|
8
8
|
from anthropic.types import Model # noqa: TC002
|
|
9
9
|
|
|
@@ -41,14 +41,6 @@ class AgentInfo:
|
|
|
41
41
|
"""Model alias this agent uses. If omitted, inherits the parent's model."""
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
class SystemPromptPreset(TypedDict):
|
|
45
|
-
"""System prompt preset configuration."""
|
|
46
|
-
|
|
47
|
-
type: Literal["preset"]
|
|
48
|
-
preset: Literal["claude_code"]
|
|
49
|
-
append: NotRequired[str]
|
|
50
|
-
|
|
51
|
-
|
|
52
44
|
class ToolsPreset(TypedDict):
|
|
53
45
|
"""Tools preset configuration."""
|
|
54
46
|
|
|
@@ -25,6 +25,7 @@ TaskStatus = Literal["completed", "failed", "stopped"]
|
|
|
25
25
|
CompactionTrigger = Literal["auto", "manual"]
|
|
26
26
|
ElicitationMode = Literal["form", "url"]
|
|
27
27
|
ElicitationAction = Literal["accept", "decline", "cancel"]
|
|
28
|
+
FastModeState = Literal["off", "cooldown", "on"]
|
|
28
29
|
|
|
29
30
|
StopReason = Literal[
|
|
30
31
|
"end_turn",
|
|
@@ -69,26 +70,3 @@ class ClaudeCodeBaseModel(BaseModel):
|
|
|
69
70
|
alias_generator=to_camel,
|
|
70
71
|
extra="forbid" if IS_DEV else "ignore",
|
|
71
72
|
)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# Thinking configuration types
|
|
75
|
-
class ThinkingConfigAdaptive(ClaudeCodeBaseModel):
|
|
76
|
-
"""Adaptive thinking configuration - model decides thinking budget."""
|
|
77
|
-
|
|
78
|
-
type: Literal["adaptive"] = "adaptive"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class ThinkingConfigEnabled(ClaudeCodeBaseModel):
|
|
82
|
-
"""Enabled thinking configuration with explicit token budget."""
|
|
83
|
-
|
|
84
|
-
type: Literal["enabled"] = "enabled"
|
|
85
|
-
budget_tokens: int
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class ThinkingConfigDisabled(ClaudeCodeBaseModel):
|
|
89
|
-
"""Disabled thinking configuration."""
|
|
90
|
-
|
|
91
|
-
type: Literal["disabled"] = "disabled"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
ThinkingConfig = ThinkingConfigAdaptive | ThinkingConfigEnabled | ThinkingConfigDisabled
|
|
@@ -51,7 +51,7 @@ class ToolResultBlock:
|
|
|
51
51
|
|
|
52
52
|
type: Literal["tool_result"] = field(default="tool_result", repr=False)
|
|
53
53
|
tool_use_id: str = ""
|
|
54
|
-
content: str | list[dict[str, Any]] | None = None
|
|
54
|
+
content: str | list[dict[str, Any]] | None = None # BetaContentBlock
|
|
55
55
|
is_error: bool | None = None
|
|
56
56
|
|
|
57
57
|
def get_parsed_content(self) -> list[ToolResultContentBlock] | str | None:
|
|
@@ -109,13 +109,13 @@ McpServerConfig = (
|
|
|
109
109
|
)
|
|
110
110
|
|
|
111
111
|
|
|
112
|
-
class SdkPluginConfig(
|
|
112
|
+
class SdkPluginConfig(ClaudeCodeBaseModel):
|
|
113
113
|
"""SDK plugin configuration.
|
|
114
114
|
|
|
115
115
|
Currently only local plugins are supported via the 'local' type.
|
|
116
116
|
"""
|
|
117
117
|
|
|
118
|
-
type: Literal["local"]
|
|
118
|
+
type: Literal["local"] = "local"
|
|
119
119
|
path: str
|
|
120
120
|
|
|
121
121
|
|