ccproxy-api 0.1.0__py3-none-any.whl
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.
- ccproxy/__init__.py +4 -0
- ccproxy/__main__.py +7 -0
- ccproxy/_version.py +21 -0
- ccproxy/adapters/__init__.py +11 -0
- ccproxy/adapters/base.py +80 -0
- ccproxy/adapters/openai/__init__.py +43 -0
- ccproxy/adapters/openai/adapter.py +915 -0
- ccproxy/adapters/openai/models.py +412 -0
- ccproxy/adapters/openai/streaming.py +449 -0
- ccproxy/api/__init__.py +28 -0
- ccproxy/api/app.py +225 -0
- ccproxy/api/dependencies.py +140 -0
- ccproxy/api/middleware/__init__.py +11 -0
- ccproxy/api/middleware/auth.py +0 -0
- ccproxy/api/middleware/cors.py +55 -0
- ccproxy/api/middleware/errors.py +703 -0
- ccproxy/api/middleware/headers.py +51 -0
- ccproxy/api/middleware/logging.py +175 -0
- ccproxy/api/middleware/request_id.py +69 -0
- ccproxy/api/middleware/server_header.py +62 -0
- ccproxy/api/responses.py +84 -0
- ccproxy/api/routes/__init__.py +16 -0
- ccproxy/api/routes/claude.py +181 -0
- ccproxy/api/routes/health.py +489 -0
- ccproxy/api/routes/metrics.py +1033 -0
- ccproxy/api/routes/proxy.py +238 -0
- ccproxy/auth/__init__.py +75 -0
- ccproxy/auth/bearer.py +68 -0
- ccproxy/auth/credentials_adapter.py +93 -0
- ccproxy/auth/dependencies.py +229 -0
- ccproxy/auth/exceptions.py +79 -0
- ccproxy/auth/manager.py +102 -0
- ccproxy/auth/models.py +118 -0
- ccproxy/auth/oauth/__init__.py +26 -0
- ccproxy/auth/oauth/models.py +49 -0
- ccproxy/auth/oauth/routes.py +396 -0
- ccproxy/auth/oauth/storage.py +0 -0
- ccproxy/auth/storage/__init__.py +12 -0
- ccproxy/auth/storage/base.py +57 -0
- ccproxy/auth/storage/json_file.py +159 -0
- ccproxy/auth/storage/keyring.py +192 -0
- ccproxy/claude_sdk/__init__.py +20 -0
- ccproxy/claude_sdk/client.py +169 -0
- ccproxy/claude_sdk/converter.py +331 -0
- ccproxy/claude_sdk/options.py +120 -0
- ccproxy/cli/__init__.py +14 -0
- ccproxy/cli/commands/__init__.py +8 -0
- ccproxy/cli/commands/auth.py +553 -0
- ccproxy/cli/commands/config/__init__.py +14 -0
- ccproxy/cli/commands/config/commands.py +766 -0
- ccproxy/cli/commands/config/schema_commands.py +119 -0
- ccproxy/cli/commands/serve.py +630 -0
- ccproxy/cli/docker/__init__.py +34 -0
- ccproxy/cli/docker/adapter_factory.py +157 -0
- ccproxy/cli/docker/params.py +278 -0
- ccproxy/cli/helpers.py +144 -0
- ccproxy/cli/main.py +193 -0
- ccproxy/cli/options/__init__.py +14 -0
- ccproxy/cli/options/claude_options.py +216 -0
- ccproxy/cli/options/core_options.py +40 -0
- ccproxy/cli/options/security_options.py +48 -0
- ccproxy/cli/options/server_options.py +117 -0
- ccproxy/config/__init__.py +40 -0
- ccproxy/config/auth.py +154 -0
- ccproxy/config/claude.py +124 -0
- ccproxy/config/cors.py +79 -0
- ccproxy/config/discovery.py +87 -0
- ccproxy/config/docker_settings.py +265 -0
- ccproxy/config/loader.py +108 -0
- ccproxy/config/observability.py +158 -0
- ccproxy/config/pricing.py +88 -0
- ccproxy/config/reverse_proxy.py +31 -0
- ccproxy/config/scheduler.py +89 -0
- ccproxy/config/security.py +14 -0
- ccproxy/config/server.py +81 -0
- ccproxy/config/settings.py +534 -0
- ccproxy/config/validators.py +231 -0
- ccproxy/core/__init__.py +274 -0
- ccproxy/core/async_utils.py +675 -0
- ccproxy/core/constants.py +97 -0
- ccproxy/core/errors.py +256 -0
- ccproxy/core/http.py +328 -0
- ccproxy/core/http_transformers.py +428 -0
- ccproxy/core/interfaces.py +247 -0
- ccproxy/core/logging.py +189 -0
- ccproxy/core/middleware.py +114 -0
- ccproxy/core/proxy.py +143 -0
- ccproxy/core/system.py +38 -0
- ccproxy/core/transformers.py +259 -0
- ccproxy/core/types.py +129 -0
- ccproxy/core/validators.py +288 -0
- ccproxy/docker/__init__.py +67 -0
- ccproxy/docker/adapter.py +588 -0
- ccproxy/docker/docker_path.py +207 -0
- ccproxy/docker/middleware.py +103 -0
- ccproxy/docker/models.py +228 -0
- ccproxy/docker/protocol.py +192 -0
- ccproxy/docker/stream_process.py +264 -0
- ccproxy/docker/validators.py +173 -0
- ccproxy/models/__init__.py +123 -0
- ccproxy/models/errors.py +42 -0
- ccproxy/models/messages.py +243 -0
- ccproxy/models/requests.py +85 -0
- ccproxy/models/responses.py +227 -0
- ccproxy/models/types.py +102 -0
- ccproxy/observability/__init__.py +51 -0
- ccproxy/observability/access_logger.py +400 -0
- ccproxy/observability/context.py +447 -0
- ccproxy/observability/metrics.py +539 -0
- ccproxy/observability/pushgateway.py +366 -0
- ccproxy/observability/sse_events.py +303 -0
- ccproxy/observability/stats_printer.py +755 -0
- ccproxy/observability/storage/__init__.py +1 -0
- ccproxy/observability/storage/duckdb_simple.py +665 -0
- ccproxy/observability/storage/models.py +55 -0
- ccproxy/pricing/__init__.py +19 -0
- ccproxy/pricing/cache.py +212 -0
- ccproxy/pricing/loader.py +267 -0
- ccproxy/pricing/models.py +106 -0
- ccproxy/pricing/updater.py +309 -0
- ccproxy/scheduler/__init__.py +39 -0
- ccproxy/scheduler/core.py +335 -0
- ccproxy/scheduler/exceptions.py +34 -0
- ccproxy/scheduler/manager.py +186 -0
- ccproxy/scheduler/registry.py +150 -0
- ccproxy/scheduler/tasks.py +484 -0
- ccproxy/services/__init__.py +10 -0
- ccproxy/services/claude_sdk_service.py +614 -0
- ccproxy/services/credentials/__init__.py +55 -0
- ccproxy/services/credentials/config.py +105 -0
- ccproxy/services/credentials/manager.py +562 -0
- ccproxy/services/credentials/oauth_client.py +482 -0
- ccproxy/services/proxy_service.py +1536 -0
- ccproxy/static/.keep +0 -0
- ccproxy/testing/__init__.py +34 -0
- ccproxy/testing/config.py +148 -0
- ccproxy/testing/content_generation.py +197 -0
- ccproxy/testing/mock_responses.py +262 -0
- ccproxy/testing/response_handlers.py +161 -0
- ccproxy/testing/scenarios.py +241 -0
- ccproxy/utils/__init__.py +6 -0
- ccproxy/utils/cost_calculator.py +210 -0
- ccproxy/utils/streaming_metrics.py +199 -0
- ccproxy_api-0.1.0.dist-info/METADATA +253 -0
- ccproxy_api-0.1.0.dist-info/RECORD +148 -0
- ccproxy_api-0.1.0.dist-info/WHEEL +4 -0
- ccproxy_api-0.1.0.dist-info/entry_points.txt +2 -0
- ccproxy_api-0.1.0.dist-info/licenses/LICENSE +21 -0
ccproxy/__init__.py
ADDED
ccproxy/__main__.py
ADDED
ccproxy/_version.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '0.1.0'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 0)
|
ccproxy/adapters/base.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Base adapter interface for API format conversion."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from collections.abc import AsyncIterator
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class APIAdapter(ABC):
|
|
9
|
+
"""Abstract base class for API format adapters.
|
|
10
|
+
|
|
11
|
+
Combines all transformation interfaces to provide a complete adapter
|
|
12
|
+
for converting between different API formats.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
async def adapt_request(self, request: dict[str, Any]) -> dict[str, Any]:
|
|
17
|
+
"""Convert a request from one API format to another.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
request: The request data to convert
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
The converted request data
|
|
24
|
+
|
|
25
|
+
Raises:
|
|
26
|
+
ValueError: If the request format is invalid or unsupported
|
|
27
|
+
"""
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
@abstractmethod
|
|
31
|
+
async def adapt_response(self, response: dict[str, Any]) -> dict[str, Any]:
|
|
32
|
+
"""Convert a response from one API format to another.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
response: The response data to convert
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
The converted response data
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ValueError: If the response format is invalid or unsupported
|
|
42
|
+
"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
async def adapt_stream(
|
|
47
|
+
self, stream: AsyncIterator[dict[str, Any]]
|
|
48
|
+
) -> AsyncIterator[dict[str, Any]]:
|
|
49
|
+
"""Convert a streaming response from one API format to another.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
stream: The streaming response data to convert
|
|
53
|
+
|
|
54
|
+
Yields:
|
|
55
|
+
The converted streaming response chunks
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the stream format is invalid or unsupported
|
|
59
|
+
"""
|
|
60
|
+
# This should be implemented as an async generator
|
|
61
|
+
# async def adapt_stream(self, stream):
|
|
62
|
+
# async for item in stream:
|
|
63
|
+
# yield transformed_item
|
|
64
|
+
raise NotImplementedError
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class BaseAPIAdapter(APIAdapter):
|
|
68
|
+
"""Base implementation with common functionality."""
|
|
69
|
+
|
|
70
|
+
def __init__(self, name: str):
|
|
71
|
+
self.name = name
|
|
72
|
+
|
|
73
|
+
def __str__(self) -> str:
|
|
74
|
+
return f"{self.__class__.__name__}({self.name})"
|
|
75
|
+
|
|
76
|
+
def __repr__(self) -> str:
|
|
77
|
+
return self.__str__()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
__all__ = ["APIAdapter", "BaseAPIAdapter"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""OpenAI adapter module for API format conversion.
|
|
2
|
+
|
|
3
|
+
This module provides the OpenAI adapter implementation for converting
|
|
4
|
+
between OpenAI and Anthropic API formats.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .adapter import OpenAIAdapter, map_openai_model_to_claude
|
|
8
|
+
from .models import (
|
|
9
|
+
OpenAIChatCompletionResponse,
|
|
10
|
+
OpenAIChoice,
|
|
11
|
+
OpenAIMessage,
|
|
12
|
+
OpenAIMessageContent,
|
|
13
|
+
OpenAIResponseMessage,
|
|
14
|
+
OpenAIStreamingChatCompletionResponse,
|
|
15
|
+
OpenAIToolCall,
|
|
16
|
+
OpenAIUsage,
|
|
17
|
+
format_openai_tool_call,
|
|
18
|
+
generate_openai_response_id,
|
|
19
|
+
generate_openai_system_fingerprint,
|
|
20
|
+
)
|
|
21
|
+
from .streaming import OpenAISSEFormatter, OpenAIStreamProcessor
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
# Adapter
|
|
26
|
+
"OpenAIAdapter",
|
|
27
|
+
"map_openai_model_to_claude",
|
|
28
|
+
# Models
|
|
29
|
+
"OpenAIMessage",
|
|
30
|
+
"OpenAIMessageContent",
|
|
31
|
+
"OpenAIResponseMessage",
|
|
32
|
+
"OpenAIChoice",
|
|
33
|
+
"OpenAIChatCompletionResponse",
|
|
34
|
+
"OpenAIStreamingChatCompletionResponse",
|
|
35
|
+
"OpenAIToolCall",
|
|
36
|
+
"OpenAIUsage",
|
|
37
|
+
"format_openai_tool_call",
|
|
38
|
+
"generate_openai_response_id",
|
|
39
|
+
"generate_openai_system_fingerprint",
|
|
40
|
+
# Streaming
|
|
41
|
+
"OpenAISSEFormatter",
|
|
42
|
+
"OpenAIStreamProcessor",
|
|
43
|
+
]
|