clawd-code-sdk 1.2.6__tar.gz → 1.2.8__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.6 → clawd_code_sdk-1.2.8}/PKG-INFO +1 -1
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/pyproject.toml +1 -1
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/client.py +59 -2
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/__init__.py +6 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/messages.py +25 -0
- clawd_code_sdk-1.2.8/tests/test_steer.py +89 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/.gitignore +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/LICENSE +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/README.md +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_errors.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/query.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/session_mutations.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/sessions.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_version.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/anthropic_stream.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/instrumentation.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/list_sessions.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/mcp_utils.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/agents.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/base.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/content_blocks.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/context_usage.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/control.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/hooks.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/input_types.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/mcp.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/options.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/output_types.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/permissions.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/prompts.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/server_info.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/session.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/settings.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/system_messages.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/thinking.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/models/usage.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/py.typed +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/session.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/storage/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/storage/helpers.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/storage/models.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/storage/replay.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/conftest.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/__init__.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_agents_and_settings.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_dynamic_control.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_hook_events.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_hooks.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_include_partial_messages.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_sdk_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_sdk_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_slash_commands.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_stderr_callback.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_storage_parsing.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_structured_output.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_subagent_invocation.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/e2e/test_tool_permissions.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/mcp_server.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/mock_claude_server.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_api_content_blocks.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_apply_flag_settings.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_changelog.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_client.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_elicitation_mcp_conversion.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_errors.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_get_usage.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_image.png +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_integration.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_line_framing.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_message_parser.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_result_error.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_sandbox_settings.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_sdk_0_3_types.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_sdk_mcp_integration.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_session.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_session_mutations.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_sessions.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_streaming_client.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_subprocess_buffering.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_tool_callbacks.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/tests/test_transport.py +0 -0
- {clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/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.8
|
|
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
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import os
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
from typing import TYPE_CHECKING, Any, Literal, Self, cast
|
|
8
|
+
from uuid import uuid4
|
|
8
9
|
|
|
9
10
|
import anyenv
|
|
10
11
|
from pydantic import ValidationError
|
|
@@ -272,8 +273,9 @@ class ClaudeSDKClient:
|
|
|
272
273
|
):
|
|
273
274
|
self.query_usage.accumulate(usage)
|
|
274
275
|
self.session_usage.accumulate(usage)
|
|
275
|
-
# total_cost_usd is cumulative;
|
|
276
|
-
|
|
276
|
+
# total_cost_usd is cumulative; a query adds the delta of each of its
|
|
277
|
+
# results (a steered query has one per cycle)
|
|
278
|
+
self.query_cost += total_cost - self.session_cost
|
|
277
279
|
self.session_cost = total_cost
|
|
278
280
|
yield message
|
|
279
281
|
|
|
@@ -284,9 +286,12 @@ class ClaudeSDKClient:
|
|
|
284
286
|
parent_tool_use_id: str | None = None,
|
|
285
287
|
should_query: bool = True,
|
|
286
288
|
priority: MessagePriority | None = None,
|
|
289
|
+
uuid: str | None = None,
|
|
287
290
|
) -> None:
|
|
288
291
|
"""Send a new user message with one or more content blocks.
|
|
289
292
|
|
|
293
|
+
Starts a new query: ``query_usage`` and ``query_cost`` count from here.
|
|
294
|
+
|
|
290
295
|
Args:
|
|
291
296
|
*prompts: One or more content blocks. Strings are converted to
|
|
292
297
|
UserTextPrompt automatically. Pass multiple to combine, e.g.
|
|
@@ -295,11 +300,61 @@ class ClaudeSDKClient:
|
|
|
295
300
|
parent_tool_use_id: If responding to a tool use, the tool_use block ID.
|
|
296
301
|
should_query: Whether to query the model for a response. Defaults to True.
|
|
297
302
|
priority: The priority of the message. Defaults to None.
|
|
303
|
+
uuid: ID of the message; the CLI then reports its progress as
|
|
304
|
+
``CommandLifecycleMessage`` frames and names it in results.
|
|
298
305
|
"""
|
|
299
306
|
prompt = prompts[0] if prompts else None
|
|
300
307
|
self._logfire_prompt = str(prompt)
|
|
301
308
|
self.query_usage.reset()
|
|
302
309
|
self.query_cost = 0.0
|
|
310
|
+
await self._send_user_message(
|
|
311
|
+
prompts,
|
|
312
|
+
session_id=session_id,
|
|
313
|
+
parent_tool_use_id=parent_tool_use_id,
|
|
314
|
+
should_query=should_query,
|
|
315
|
+
priority=priority,
|
|
316
|
+
uuid=uuid,
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
async def steer(
|
|
320
|
+
self,
|
|
321
|
+
*prompts: str | UserPrompt,
|
|
322
|
+
priority: MessagePriority = "now",
|
|
323
|
+
session_id: str = "default",
|
|
324
|
+
) -> str:
|
|
325
|
+
"""Send a user message into the running query instead of starting a new one.
|
|
326
|
+
|
|
327
|
+
``query_usage`` and ``query_cost`` keep counting the running query. With
|
|
328
|
+
``"now"`` the CLI takes the message in at once: it ends the cycle that is
|
|
329
|
+
generating (which reports a result of its own) or moves a running foreground
|
|
330
|
+
tool to the background, and works on the message in the same query. ``"later"``
|
|
331
|
+
waits for the running cycle (e.g. while a permission request is open).
|
|
332
|
+
|
|
333
|
+
Args:
|
|
334
|
+
*prompts: Content blocks of the message (strings become text blocks).
|
|
335
|
+
priority: When the CLI takes the message in.
|
|
336
|
+
session_id: Session identifier for the message.
|
|
337
|
+
|
|
338
|
+
Returns:
|
|
339
|
+
The message's uuid, which ``CommandLifecycleMessage.command_uuid`` and the
|
|
340
|
+
results' ``user_message_uuids`` refer to.
|
|
341
|
+
"""
|
|
342
|
+
message_uuid = str(uuid4())
|
|
343
|
+
await self._send_user_message(
|
|
344
|
+
prompts, session_id=session_id, priority=priority, uuid=message_uuid
|
|
345
|
+
)
|
|
346
|
+
return message_uuid
|
|
347
|
+
|
|
348
|
+
async def _send_user_message(
|
|
349
|
+
self,
|
|
350
|
+
prompts: tuple[str | UserPrompt, ...],
|
|
351
|
+
*,
|
|
352
|
+
session_id: str,
|
|
353
|
+
parent_tool_use_id: str | None = None,
|
|
354
|
+
should_query: bool = True,
|
|
355
|
+
priority: MessagePriority | None = None,
|
|
356
|
+
uuid: str | None = None,
|
|
357
|
+
) -> None:
|
|
303
358
|
self._ensure_connected()
|
|
304
359
|
if not self._query:
|
|
305
360
|
raise CLIConnectionError("Not connected. Call connect() first.")
|
|
@@ -322,6 +377,8 @@ class ClaudeSDKClient:
|
|
|
322
377
|
"shouldQuery": should_query,
|
|
323
378
|
"priority": priority,
|
|
324
379
|
}
|
|
380
|
+
if uuid is not None:
|
|
381
|
+
wire_message["uuid"] = uuid
|
|
325
382
|
if self.options.verbatim_prompts:
|
|
326
383
|
wire_message["client_composed"] = True
|
|
327
384
|
await self._query.write_json(wire_message)
|
|
@@ -348,6 +348,8 @@ from .messages import (
|
|
|
348
348
|
SDKPermissionDenial,
|
|
349
349
|
StreamEvent,
|
|
350
350
|
AuthStatusMessage,
|
|
351
|
+
CommandLifecycleMessage,
|
|
352
|
+
CommandLifecycleState,
|
|
351
353
|
ConversationResetMessage,
|
|
352
354
|
SDKMessageOrigin,
|
|
353
355
|
ToolProgressMessage,
|
|
@@ -472,6 +474,7 @@ MessageUnion = (
|
|
|
472
474
|
| AuthStatusMessage
|
|
473
475
|
| PromptSuggestionMessage
|
|
474
476
|
| ConversationResetMessage
|
|
477
|
+
| CommandLifecycleMessage
|
|
475
478
|
| SystemMessageUnion
|
|
476
479
|
)
|
|
477
480
|
|
|
@@ -487,6 +490,7 @@ Message = Annotated[
|
|
|
487
490
|
| Annotated[AuthStatusMessage, Tag("auth_status")]
|
|
488
491
|
| Annotated[PromptSuggestionMessage, Tag("prompt_suggestion")]
|
|
489
492
|
| Annotated[ConversationResetMessage, Tag("conversation_reset")]
|
|
493
|
+
| Annotated[CommandLifecycleMessage, Tag("command_lifecycle")]
|
|
490
494
|
| Annotated[SystemMessageUnion, Tag("system")],
|
|
491
495
|
Discriminator(_message_discriminator),
|
|
492
496
|
]
|
|
@@ -552,6 +556,8 @@ __all__ = [
|
|
|
552
556
|
"ClaudeCodeSettings",
|
|
553
557
|
"ClaudeOAuthWaitForCompletionResponse",
|
|
554
558
|
"CommandHookHandler",
|
|
559
|
+
"CommandLifecycleMessage",
|
|
560
|
+
"CommandLifecycleState",
|
|
555
561
|
"CommandsChangedMessage",
|
|
556
562
|
"CompactBoundarySystemMessage",
|
|
557
563
|
"ConfigOutput",
|
|
@@ -530,6 +530,8 @@ class BaseResultMessage(BaseMessage):
|
|
|
530
530
|
"""UUID of the user message that started this turn."""
|
|
531
531
|
user_message_uuids: list[str] | None = None
|
|
532
532
|
"""UUIDs of all user messages handled in this turn."""
|
|
533
|
+
begun_message_ids: list[str] | None = None
|
|
534
|
+
"""API message IDs (``msg_...``) the turn began (undocumented, CLI 2.1.330+)."""
|
|
533
535
|
resume_reason: str | None = None
|
|
534
536
|
result_index: int | None = None
|
|
535
537
|
credential_expires_at: str | None = None
|
|
@@ -775,6 +777,28 @@ class ConversationResetMessage(BaseMessage):
|
|
|
775
777
|
timestamp: str | None = None
|
|
776
778
|
|
|
777
779
|
|
|
780
|
+
CommandLifecycleState = Literal[
|
|
781
|
+
"queued", "started", "completed", "cancelled", "discarded", "refused"
|
|
782
|
+
]
|
|
783
|
+
"""Where a uuid-stamped user message is in the CLI's command queue."""
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
class CommandLifecycleMessage(BaseMessage):
|
|
787
|
+
"""Progress of a user message that was sent with a ``uuid`` (capability ``msg_lifecycle_v1``).
|
|
788
|
+
|
|
789
|
+
``queued``: waiting behind the running work. ``started``: taken in (the cycle it starts,
|
|
790
|
+
or the running cycle it was folded into). ``completed``: its work ended (after the
|
|
791
|
+
result for a message that started a cycle, before it for one folded into a cycle).
|
|
792
|
+
``cancelled``: an interrupt stopped it. ``discarded`` / ``refused``: dropped before it ran.
|
|
793
|
+
"""
|
|
794
|
+
|
|
795
|
+
type: Literal["command_lifecycle"] = "command_lifecycle"
|
|
796
|
+
command_uuid: str
|
|
797
|
+
"""The ``uuid`` the message was sent with."""
|
|
798
|
+
state: CommandLifecycleState
|
|
799
|
+
session_id: str
|
|
800
|
+
|
|
801
|
+
|
|
778
802
|
class PromptSuggestionMessage(BaseMessage):
|
|
779
803
|
"""Predicted next user prompt, emitted after each turn when promptSuggestions is enabled."""
|
|
780
804
|
|
|
@@ -818,6 +842,7 @@ MiscMessages = (
|
|
|
818
842
|
| AuthStatusMessage
|
|
819
843
|
| PromptSuggestionMessage
|
|
820
844
|
| ConversationResetMessage
|
|
845
|
+
| CommandLifecycleMessage
|
|
821
846
|
| StreamlinedTextMessage
|
|
822
847
|
| StreamlinedToolUseSummaryMessage
|
|
823
848
|
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Steering a running query: uuid-stamped messages, lifecycle frames, cost per query."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
6
|
+
|
|
7
|
+
from clawd_code_sdk import ClaudeAgentOptions, ClaudeSDKClient
|
|
8
|
+
from clawd_code_sdk.models import CommandLifecycleMessage, message_adapter
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from collections.abc import AsyncIterator
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _FakeQuery:
|
|
16
|
+
"""Records written messages and replays the given CLI messages."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, messages: list[dict[str, Any]] | None = None) -> None:
|
|
19
|
+
self.written: list[dict[str, Any]] = []
|
|
20
|
+
self.messages = messages or []
|
|
21
|
+
|
|
22
|
+
async def write_json(self, data: dict[str, Any]) -> None:
|
|
23
|
+
self.written.append(data)
|
|
24
|
+
|
|
25
|
+
async def receive_messages(self) -> AsyncIterator[dict[str, Any]]:
|
|
26
|
+
for message in self.messages:
|
|
27
|
+
yield message
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _client(query: _FakeQuery) -> ClaudeSDKClient:
|
|
31
|
+
client = ClaudeSDKClient(ClaudeAgentOptions())
|
|
32
|
+
client._query = cast(Any, query)
|
|
33
|
+
return client
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _result(total_cost: float, output_tokens: int) -> dict[str, Any]:
|
|
37
|
+
return {
|
|
38
|
+
"type": "result",
|
|
39
|
+
"subtype": "success",
|
|
40
|
+
"uuid": "r",
|
|
41
|
+
"session_id": "s",
|
|
42
|
+
"duration_ms": 1,
|
|
43
|
+
"duration_api_ms": 1,
|
|
44
|
+
"is_error": False,
|
|
45
|
+
"num_turns": 1,
|
|
46
|
+
"total_cost_usd": total_cost,
|
|
47
|
+
"usage": {"input_tokens": 1, "output_tokens": output_tokens},
|
|
48
|
+
"stop_reason": "end_turn",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def test_steer_keeps_counting_the_running_query() -> None:
|
|
53
|
+
# The interrupted cycle's result, then the steered message's cycle
|
|
54
|
+
query = _FakeQuery([_result(0.25, 10), _result(0.75, 5)])
|
|
55
|
+
client = _client(query)
|
|
56
|
+
await client.query("count to 300")
|
|
57
|
+
message_uuid = await client.steer("stop and say BANANA")
|
|
58
|
+
|
|
59
|
+
async for _ in client.receive_messages():
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
first, steered = query.written
|
|
63
|
+
assert "uuid" not in first
|
|
64
|
+
assert steered["uuid"] == message_uuid
|
|
65
|
+
assert steered["priority"] == "now"
|
|
66
|
+
assert steered["message"]["content"] == [{"type": "text", "text": "stop and say BANANA"}]
|
|
67
|
+
# Both cycles count for the query
|
|
68
|
+
assert client.query_cost == 0.75
|
|
69
|
+
assert client.query_usage.output_tokens == 15
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async def test_query_with_uuid() -> None:
|
|
73
|
+
query = _FakeQuery()
|
|
74
|
+
await _client(query).query("hi", uuid="u1", priority="next")
|
|
75
|
+
assert query.written[0]["uuid"] == "u1"
|
|
76
|
+
assert query.written[0]["priority"] == "next"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_command_lifecycle_frame() -> None:
|
|
80
|
+
frame = {
|
|
81
|
+
"type": "command_lifecycle",
|
|
82
|
+
"command_uuid": "c9c43ffb",
|
|
83
|
+
"state": "queued",
|
|
84
|
+
"uuid": "7751841f",
|
|
85
|
+
"session_id": "466f26ed",
|
|
86
|
+
}
|
|
87
|
+
assert message_adapter.validate_python(frame) == CommandLifecycleMessage(
|
|
88
|
+
uuid="7751841f", command_uuid="c9c43ffb", state="queued", session_id="466f26ed"
|
|
89
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py
RENAMED
|
File without changes
|
{clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/session_mutations.py
RENAMED
|
File without changes
|
|
File without changes
|
{clawd_code_sdk-1.2.6 → clawd_code_sdk-1.2.8}/src/clawd_code_sdk/_internal/transport/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|