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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Schema-related config commands for CCProxy API."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from ccproxy.cli.helpers import get_rich_toolkit
|
|
8
|
+
from ccproxy.core.async_utils import (
|
|
9
|
+
generate_schema_files,
|
|
10
|
+
generate_taplo_config,
|
|
11
|
+
validate_config_with_schema,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def config_schema(
|
|
16
|
+
output_dir: Path | None = typer.Option(
|
|
17
|
+
None,
|
|
18
|
+
"--output-dir",
|
|
19
|
+
"-o",
|
|
20
|
+
help="Output directory for schema files (default: current directory)",
|
|
21
|
+
),
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Generate JSON Schema files and taplo configuration for TOML validation.
|
|
24
|
+
|
|
25
|
+
This command generates JSON Schema files that can be used by editors
|
|
26
|
+
for configuration file validation, autocomplete, and syntax highlighting.
|
|
27
|
+
Supports TOML, JSON, and YAML configuration files. Automatically generates
|
|
28
|
+
taplo configuration for enhanced TOML editor support.
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
ccproxy config schema # Generate schema files and taplo config in current directory
|
|
32
|
+
ccproxy config schema --output-dir ./schemas # Generate in specific directory
|
|
33
|
+
"""
|
|
34
|
+
toolkit = get_rich_toolkit()
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
# Generate schema files
|
|
38
|
+
if output_dir is None:
|
|
39
|
+
output_dir = Path.cwd()
|
|
40
|
+
|
|
41
|
+
toolkit.print(
|
|
42
|
+
"Generating JSON Schema files for TOML configuration...", tag="info"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
generated_files = generate_schema_files(output_dir)
|
|
46
|
+
|
|
47
|
+
for file_path in generated_files:
|
|
48
|
+
toolkit.print(f"Generated: {file_path}", tag="success")
|
|
49
|
+
|
|
50
|
+
toolkit.print("Generating taplo configuration...", tag="info")
|
|
51
|
+
taplo_config = generate_taplo_config(output_dir)
|
|
52
|
+
toolkit.print(f"Generated: {taplo_config}", tag="success")
|
|
53
|
+
|
|
54
|
+
toolkit.print_line()
|
|
55
|
+
toolkit.print("Schema files generated successfully!", tag="success")
|
|
56
|
+
toolkit.print_line()
|
|
57
|
+
toolkit.print("To use in VS Code:", tag="info")
|
|
58
|
+
toolkit.print("1. Install the 'Even Better TOML' extension", tag="info")
|
|
59
|
+
toolkit.print(
|
|
60
|
+
"2. The schema will be automatically applied to ccproxy TOML files",
|
|
61
|
+
tag="info",
|
|
62
|
+
)
|
|
63
|
+
toolkit.print_line()
|
|
64
|
+
toolkit.print("To use with taplo CLI:", tag="info")
|
|
65
|
+
toolkit.print(" taplo check your-config.toml", tag="command")
|
|
66
|
+
|
|
67
|
+
except Exception as e:
|
|
68
|
+
toolkit.print(f"Error generating schema: {e}", tag="error")
|
|
69
|
+
raise typer.Exit(1) from e
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def config_validate(
|
|
73
|
+
config_file: Path = typer.Argument(
|
|
74
|
+
...,
|
|
75
|
+
help="Configuration file to validate (TOML, JSON, or YAML)",
|
|
76
|
+
),
|
|
77
|
+
) -> None:
|
|
78
|
+
"""Validate a configuration file against the schema.
|
|
79
|
+
|
|
80
|
+
This command validates a configuration file (TOML, JSON, or YAML) against
|
|
81
|
+
the JSON Schema to ensure it follows the correct structure and data types.
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
ccproxy config validate config.toml # Validate a TOML config
|
|
85
|
+
ccproxy config validate config.yaml # Validate a YAML config
|
|
86
|
+
ccproxy config validate config.json # Validate a JSON config
|
|
87
|
+
"""
|
|
88
|
+
toolkit = get_rich_toolkit()
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
# Validate the config file
|
|
92
|
+
if not config_file.exists():
|
|
93
|
+
toolkit.print(f"Error: File {config_file} does not exist.", tag="error")
|
|
94
|
+
raise typer.Exit(1)
|
|
95
|
+
|
|
96
|
+
toolkit.print(f"Validating {config_file}...", tag="info")
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
is_valid = validate_config_with_schema(config_file)
|
|
100
|
+
if is_valid:
|
|
101
|
+
toolkit.print(
|
|
102
|
+
"Configuration file is valid according to schema.", tag="success"
|
|
103
|
+
)
|
|
104
|
+
else:
|
|
105
|
+
toolkit.print("Configuration file validation failed.", tag="error")
|
|
106
|
+
raise typer.Exit(1)
|
|
107
|
+
except ImportError as e:
|
|
108
|
+
toolkit.print(f"Error: {e}", tag="error")
|
|
109
|
+
toolkit.print(
|
|
110
|
+
"Install check-jsonschema: pip install check-jsonschema", tag="error"
|
|
111
|
+
)
|
|
112
|
+
raise typer.Exit(1) from e
|
|
113
|
+
except Exception as e:
|
|
114
|
+
toolkit.print(f"Validation error: {e}", tag="error")
|
|
115
|
+
raise typer.Exit(1) from e
|
|
116
|
+
|
|
117
|
+
except Exception as e:
|
|
118
|
+
toolkit.print(f"Error validating configuration: {e}", tag="error")
|
|
119
|
+
raise typer.Exit(1) from e
|