Skip to content
Open
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
23 changes: 21 additions & 2 deletions src/claude_agent_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,22 @@ class ServerToolResultBlock:


# Message types
# Order follows SDKAssistantMessageError in the TypeScript SDK's sdk.d.ts, so
# the two can be diffed by eye when the CLI adds a value.
AssistantMessageError = Literal[
"authentication_failed",
"oauth_org_not_allowed",
"account_on_hold",
"verification_required",
"billing_error",
"rate_limit",
"overloaded",
"invalid_request",
"model_not_found",
"server_error",
"unknown",
"max_output_tokens",
"cloud_credential_error",
]


Expand All @@ -1059,7 +1068,12 @@ class ServerToolResultBlock:
"""Known values of ``MessageOrigin["kind"]``. Newer CLI versions may emit
kinds not listed here; treat anything unrecognized as "not human"."""

TaskNotificationOriginSubkind = Literal["scheduled-trigger", "peer-send-message"]
TaskNotificationOriginSubkind = Literal[
"scheduled-trigger",
"peer-send-message",
"projects-relay",
"session-inbox",
]
"""Values of ``MessageOrigin["subkind"]`` for ``kind == "task-notification"``."""

# Functional syntax because ``from`` is a keyword.
Expand Down Expand Up @@ -1390,7 +1404,12 @@ class StreamEvent:
# Rate limit types — see https://docs.claude.com/en/docs/claude-code/rate-limits
RateLimitStatus = Literal["allowed", "allowed_warning", "rejected"]
RateLimitType = Literal[
"five_hour", "seven_day", "seven_day_opus", "seven_day_sonnet", "overage"
"five_hour",
"seven_day",
"seven_day_opus",
"seven_day_sonnet",
"seven_day_overage_included",
"overage",
]


Expand Down
43 changes: 43 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
SubagentStartHookSpecificOutput,
)
from claude_agent_sdk.types import (
AssistantMessageError,
PermissionRuleValue,
PermissionUpdate,
PostToolUseHookSpecificOutput,
PreToolUseHookSpecificOutput,
RateLimitType,
TaskNotificationOriginSubkind,
TextBlock,
ThinkingBlock,
ToolResultBlock,
Expand All @@ -32,6 +35,46 @@ def test_effort_level_is_exported():
assert set(get_args(EffortLevel)) == {"low", "medium", "high", "xhigh", "max"}


def test_literal_unions_cover_what_the_cli_sends():
"""These three carry every value the CLI can put in the field.

message_parser passes them through without validating, so a value missing
here is one a type checker calls impossible while it arrives at runtime.
The reference is the TypeScript SDK published alongside the same CLI:
SDKAssistantMessageError, the SDKRateLimitInfo rateLimitType union and the
MessageOrigin subkind union in sdk.d.ts.
"""
assert set(get_args(AssistantMessageError)) == {
"authentication_failed",
"oauth_org_not_allowed",
"account_on_hold",
"verification_required",
"billing_error",
"rate_limit",
"overloaded",
"invalid_request",
"model_not_found",
"server_error",
"unknown",
"max_output_tokens",
"cloud_credential_error",
}
assert set(get_args(RateLimitType)) == {
"five_hour",
"seven_day",
"seven_day_opus",
"seven_day_sonnet",
"seven_day_overage_included",
"overage",
}
assert set(get_args(TaskNotificationOriginSubkind)) == {
"scheduled-trigger",
"peer-send-message",
"projects-relay",
"session-inbox",
}


class TestPermissionUpdate:
"""Test PermissionUpdate wire-format conversion."""

Expand Down