ccproxy.core.interfaces¶
ccproxy.core.interfaces
¶
Core interfaces and abstract base classes for the CCProxy API.
This module consolidates all abstract interfaces used throughout the application, providing a single location for defining contracts and protocols.
RequestTransformer
¶
Bases: ABC
Abstract interface for request transformers.
transform_request
abstractmethod
async
¶
Transform a request from one format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
dict[str, Any]
|
The request data to transform |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The transformed request data |
Raises:
Type | Description |
---|---|
ValueError
|
If the request format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
ResponseTransformer
¶
Bases: ABC
Abstract interface for response transformers.
transform_response
abstractmethod
async
¶
Transform a response from one format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response
|
dict[str, Any]
|
The response data to transform |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The transformed response data |
Raises:
Type | Description |
---|---|
ValueError
|
If the response format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
StreamTransformer
¶
Bases: ABC
Abstract interface for stream transformers.
transform_stream
abstractmethod
async
¶
Transform a streaming response from one format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
AsyncIterator[dict[str, Any]]
|
The streaming response data to transform |
required |
Yields:
Type | Description |
---|---|
AsyncIterator[dict[str, Any]]
|
The transformed streaming response chunks |
Raises:
Type | Description |
---|---|
ValueError
|
If the stream format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
APIAdapter
¶
Bases: ABC
Abstract base class for API format adapters.
Combines all transformation interfaces to provide a complete adapter for converting between different API formats.
adapt_request
abstractmethod
¶
Convert a request from one API format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
dict[str, Any]
|
The request data to convert |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The converted request data |
Raises:
Type | Description |
---|---|
ValueError
|
If the request format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
adapt_response
abstractmethod
¶
Convert a response from one API format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response
|
dict[str, Any]
|
The response data to convert |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The converted response data |
Raises:
Type | Description |
---|---|
ValueError
|
If the response format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
adapt_stream
abstractmethod
¶
Convert a streaming response from one API format to another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream
|
AsyncIterator[dict[str, Any]]
|
The streaming response data to convert |
required |
Yields:
Type | Description |
---|---|
AsyncIterator[dict[str, Any]]
|
The converted streaming response chunks |
Raises:
Type | Description |
---|---|
ValueError
|
If the stream format is invalid or unsupported |
Source code in ccproxy/core/interfaces.py
TokenStorage
¶
Bases: ABC
Abstract interface for token storage backends.
load
abstractmethod
async
¶
Load credentials from storage.
Returns:
Type | Description |
---|---|
ClaudeCredentials | None
|
Parsed credentials if found and valid, None otherwise |
save
abstractmethod
async
¶
Save credentials to storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials
|
ClaudeCredentials
|
Credentials to save |
required |
Returns:
Type | Description |
---|---|
bool
|
True if saved successfully, False otherwise |
exists
abstractmethod
async
¶
Check if credentials exist in storage.
Returns:
Type | Description |
---|---|
bool
|
True if credentials exist, False otherwise |
delete
abstractmethod
async
¶
Delete credentials from storage.
Returns:
Type | Description |
---|---|
bool
|
True if deleted successfully, False otherwise |
MetricExporter
¶
Bases: ABC
Abstract interface for exporting metrics to external systems.
export_metrics
abstractmethod
async
¶
Export metrics to the target system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
dict[str, Any]
|
Dictionary of metrics to export |
required |
Returns:
Type | Description |
---|---|
bool
|
True if export was successful, False otherwise |
Raises:
Type | Description |
---|---|
ConnectionError
|
If unable to connect to the metrics backend |
ValueError
|
If metrics format is invalid |