ccproxy.core.async_utils¶
ccproxy.core.async_utils
¶
Async utilities for the CCProxy API.
patched_typing
¶
Fix for typing.TypedDict not supported in older Python versions.
This patches typing.TypedDict to use typing_extensions.TypedDict.
Source code in ccproxy/core/async_utils.py
get_package_dir
¶
Get the package directory path.
Returns:
Type | Description |
---|---|
Path
|
Path to the package directory |
Source code in ccproxy/core/async_utils.py
get_root_package_name
¶
run_in_executor
async
¶
Run a synchronous function in an executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., T]
|
The synchronous function to run |
required |
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
Type | Description |
---|---|
T
|
The result of the function call |
Source code in ccproxy/core/async_utils.py
safe_await
async
¶
Safely await an awaitable with optional timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
awaitable
|
Awaitable[T]
|
The awaitable to wait for |
required |
timeout
|
float | None
|
Optional timeout in seconds |
None
|
Returns:
Type | Description |
---|---|
T | None
|
The result of the awaitable or None if timeout/error |
Source code in ccproxy/core/async_utils.py
gather_with_concurrency
async
¶
Gather awaitables with concurrency limit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit
|
int
|
Maximum number of concurrent operations |
required |
*awaitables
|
Awaitable[T]
|
Awaitables to execute |
()
|
return_exceptions
|
bool
|
Whether to return exceptions as results |
False
|
Returns:
Type | Description |
---|---|
list[T | BaseException] | list[T]
|
List of results from the awaitables |
Source code in ccproxy/core/async_utils.py
async_timer
async
¶
Context manager for timing async operations.
Yields:
Type | Description |
---|---|
AsyncIterator[Callable[[], float]]
|
Function that returns elapsed time in seconds |
Source code in ccproxy/core/async_utils.py
retry_async
async
¶
retry_async(
func,
*args,
max_retries=3,
delay=1.0,
backoff=2.0,
exceptions=(Exception,),
**kwargs,
)
Retry an async function with exponential backoff.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Awaitable[T]]
|
The async function to retry |
required |
*args
|
Any
|
Positional arguments to pass to the function |
()
|
max_retries
|
int
|
Maximum number of retries |
3
|
delay
|
float
|
Initial delay between retries |
1.0
|
backoff
|
float
|
Backoff multiplier |
2.0
|
exceptions
|
tuple[type[Exception], ...]
|
Exception types to catch and retry on |
(Exception,)
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
Type | Description |
---|---|
T
|
The result of the successful function call |
Source code in ccproxy/core/async_utils.py
wait_for_condition
async
¶
Wait for a condition to become true.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition
|
Callable[[], bool | Awaitable[bool]]
|
Function that returns True when condition is met |
required |
timeout
|
float
|
Maximum time to wait in seconds |
30.0
|
interval
|
float
|
Check interval in seconds |
0.1
|
Returns:
Type | Description |
---|---|
bool
|
True if condition was met, False if timeout occurred |
Source code in ccproxy/core/async_utils.py
async_cache_result
async
¶
Cache the result of an async function call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Awaitable[T]]
|
The async function to cache |
required |
cache_key
|
str
|
Unique key for caching |
required |
cache_duration
|
float
|
Cache duration in seconds |
300.0
|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
Type | Description |
---|---|
T
|
The cached or computed result |
Source code in ccproxy/core/async_utils.py
parse_version
¶
Parse version string into components.
Handles various formats: - 1.2.3 - 1.2.3-dev - 1.2.3.dev59+g1624e1e.d19800101 - 0.1.dev59+g1624e1e.d19800101
Source code in ccproxy/core/async_utils.py
get_claude_docker_home_dir
¶
Get the Claude Docker home directory path.
Returns:
Type | Description |
---|---|
str
|
Path to Claude Docker home directory |
Source code in ccproxy/core/async_utils.py
generate_schema_files
¶
Generate JSON Schema files for TOML configuration validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir
|
Path | None
|
Directory to write schema files to. If None, uses current directory. |
None
|
Returns:
Type | Description |
---|---|
list[Path]
|
List of generated schema file paths |
Raises:
Type | Description |
---|---|
ImportError
|
If required dependencies are not available |
OSError
|
If unable to write files |
Source code in ccproxy/core/async_utils.py
generate_taplo_config
¶
Generate taplo configuration for TOML editor support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir
|
Path | None
|
Directory to write taplo config to. If None, uses current directory. |
None
|
Returns:
Type | Description |
---|---|
Path
|
Path to generated .taplo.toml file |
Raises:
Type | Description |
---|---|
OSError
|
If unable to write file |
Source code in ccproxy/core/async_utils.py
validate_config_with_schema
¶
Validate a config file against the schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path
|
Path to configuration file to validate |
required |
schema_path
|
Path | None
|
Optional path to schema file. If None, generates schema from Settings |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if validation passes, False otherwise |
Raises:
Type | Description |
---|---|
ImportError
|
If check-jsonschema is not available |
FileNotFoundError
|
If config file doesn't exist |
TOMLDecodeError
|
If TOML file has invalid syntax |
ValueError
|
For other validation errors |
Source code in ccproxy/core/async_utils.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
generate_json_schema
¶
Generate JSON Schema from Settings model.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
JSON Schema dictionary |
Raises:
Type | Description |
---|---|
ImportError
|
If required dependencies are not available |
Source code in ccproxy/core/async_utils.py
save_schema_file
¶
Save JSON Schema to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
dict[str, Any]
|
JSON Schema dictionary to save |
required |
output_path
|
Path
|
Path to write schema file to |
required |
Raises:
Type | Description |
---|---|
OSError
|
If unable to write file |
Source code in ccproxy/core/async_utils.py
validate_toml_with_schema
¶
Validate a TOML config file against JSON Schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
Path
|
Path to TOML configuration file |
required |
schema_path
|
Path | None
|
Optional path to schema file. If None, generates schema from Settings |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if validation passes, False otherwise |
Raises:
Type | Description |
---|---|
ImportError
|
If check-jsonschema is not available |
FileNotFoundError
|
If config file doesn't exist |
ValueError
|
If unable to parse or validate file |