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.
Files changed (148) hide show
  1. ccproxy/__init__.py +4 -0
  2. ccproxy/__main__.py +7 -0
  3. ccproxy/_version.py +21 -0
  4. ccproxy/adapters/__init__.py +11 -0
  5. ccproxy/adapters/base.py +80 -0
  6. ccproxy/adapters/openai/__init__.py +43 -0
  7. ccproxy/adapters/openai/adapter.py +915 -0
  8. ccproxy/adapters/openai/models.py +412 -0
  9. ccproxy/adapters/openai/streaming.py +449 -0
  10. ccproxy/api/__init__.py +28 -0
  11. ccproxy/api/app.py +225 -0
  12. ccproxy/api/dependencies.py +140 -0
  13. ccproxy/api/middleware/__init__.py +11 -0
  14. ccproxy/api/middleware/auth.py +0 -0
  15. ccproxy/api/middleware/cors.py +55 -0
  16. ccproxy/api/middleware/errors.py +703 -0
  17. ccproxy/api/middleware/headers.py +51 -0
  18. ccproxy/api/middleware/logging.py +175 -0
  19. ccproxy/api/middleware/request_id.py +69 -0
  20. ccproxy/api/middleware/server_header.py +62 -0
  21. ccproxy/api/responses.py +84 -0
  22. ccproxy/api/routes/__init__.py +16 -0
  23. ccproxy/api/routes/claude.py +181 -0
  24. ccproxy/api/routes/health.py +489 -0
  25. ccproxy/api/routes/metrics.py +1033 -0
  26. ccproxy/api/routes/proxy.py +238 -0
  27. ccproxy/auth/__init__.py +75 -0
  28. ccproxy/auth/bearer.py +68 -0
  29. ccproxy/auth/credentials_adapter.py +93 -0
  30. ccproxy/auth/dependencies.py +229 -0
  31. ccproxy/auth/exceptions.py +79 -0
  32. ccproxy/auth/manager.py +102 -0
  33. ccproxy/auth/models.py +118 -0
  34. ccproxy/auth/oauth/__init__.py +26 -0
  35. ccproxy/auth/oauth/models.py +49 -0
  36. ccproxy/auth/oauth/routes.py +396 -0
  37. ccproxy/auth/oauth/storage.py +0 -0
  38. ccproxy/auth/storage/__init__.py +12 -0
  39. ccproxy/auth/storage/base.py +57 -0
  40. ccproxy/auth/storage/json_file.py +159 -0
  41. ccproxy/auth/storage/keyring.py +192 -0
  42. ccproxy/claude_sdk/__init__.py +20 -0
  43. ccproxy/claude_sdk/client.py +169 -0
  44. ccproxy/claude_sdk/converter.py +331 -0
  45. ccproxy/claude_sdk/options.py +120 -0
  46. ccproxy/cli/__init__.py +14 -0
  47. ccproxy/cli/commands/__init__.py +8 -0
  48. ccproxy/cli/commands/auth.py +553 -0
  49. ccproxy/cli/commands/config/__init__.py +14 -0
  50. ccproxy/cli/commands/config/commands.py +766 -0
  51. ccproxy/cli/commands/config/schema_commands.py +119 -0
  52. ccproxy/cli/commands/serve.py +630 -0
  53. ccproxy/cli/docker/__init__.py +34 -0
  54. ccproxy/cli/docker/adapter_factory.py +157 -0
  55. ccproxy/cli/docker/params.py +278 -0
  56. ccproxy/cli/helpers.py +144 -0
  57. ccproxy/cli/main.py +193 -0
  58. ccproxy/cli/options/__init__.py +14 -0
  59. ccproxy/cli/options/claude_options.py +216 -0
  60. ccproxy/cli/options/core_options.py +40 -0
  61. ccproxy/cli/options/security_options.py +48 -0
  62. ccproxy/cli/options/server_options.py +117 -0
  63. ccproxy/config/__init__.py +40 -0
  64. ccproxy/config/auth.py +154 -0
  65. ccproxy/config/claude.py +124 -0
  66. ccproxy/config/cors.py +79 -0
  67. ccproxy/config/discovery.py +87 -0
  68. ccproxy/config/docker_settings.py +265 -0
  69. ccproxy/config/loader.py +108 -0
  70. ccproxy/config/observability.py +158 -0
  71. ccproxy/config/pricing.py +88 -0
  72. ccproxy/config/reverse_proxy.py +31 -0
  73. ccproxy/config/scheduler.py +89 -0
  74. ccproxy/config/security.py +14 -0
  75. ccproxy/config/server.py +81 -0
  76. ccproxy/config/settings.py +534 -0
  77. ccproxy/config/validators.py +231 -0
  78. ccproxy/core/__init__.py +274 -0
  79. ccproxy/core/async_utils.py +675 -0
  80. ccproxy/core/constants.py +97 -0
  81. ccproxy/core/errors.py +256 -0
  82. ccproxy/core/http.py +328 -0
  83. ccproxy/core/http_transformers.py +428 -0
  84. ccproxy/core/interfaces.py +247 -0
  85. ccproxy/core/logging.py +189 -0
  86. ccproxy/core/middleware.py +114 -0
  87. ccproxy/core/proxy.py +143 -0
  88. ccproxy/core/system.py +38 -0
  89. ccproxy/core/transformers.py +259 -0
  90. ccproxy/core/types.py +129 -0
  91. ccproxy/core/validators.py +288 -0
  92. ccproxy/docker/__init__.py +67 -0
  93. ccproxy/docker/adapter.py +588 -0
  94. ccproxy/docker/docker_path.py +207 -0
  95. ccproxy/docker/middleware.py +103 -0
  96. ccproxy/docker/models.py +228 -0
  97. ccproxy/docker/protocol.py +192 -0
  98. ccproxy/docker/stream_process.py +264 -0
  99. ccproxy/docker/validators.py +173 -0
  100. ccproxy/models/__init__.py +123 -0
  101. ccproxy/models/errors.py +42 -0
  102. ccproxy/models/messages.py +243 -0
  103. ccproxy/models/requests.py +85 -0
  104. ccproxy/models/responses.py +227 -0
  105. ccproxy/models/types.py +102 -0
  106. ccproxy/observability/__init__.py +51 -0
  107. ccproxy/observability/access_logger.py +400 -0
  108. ccproxy/observability/context.py +447 -0
  109. ccproxy/observability/metrics.py +539 -0
  110. ccproxy/observability/pushgateway.py +366 -0
  111. ccproxy/observability/sse_events.py +303 -0
  112. ccproxy/observability/stats_printer.py +755 -0
  113. ccproxy/observability/storage/__init__.py +1 -0
  114. ccproxy/observability/storage/duckdb_simple.py +665 -0
  115. ccproxy/observability/storage/models.py +55 -0
  116. ccproxy/pricing/__init__.py +19 -0
  117. ccproxy/pricing/cache.py +212 -0
  118. ccproxy/pricing/loader.py +267 -0
  119. ccproxy/pricing/models.py +106 -0
  120. ccproxy/pricing/updater.py +309 -0
  121. ccproxy/scheduler/__init__.py +39 -0
  122. ccproxy/scheduler/core.py +335 -0
  123. ccproxy/scheduler/exceptions.py +34 -0
  124. ccproxy/scheduler/manager.py +186 -0
  125. ccproxy/scheduler/registry.py +150 -0
  126. ccproxy/scheduler/tasks.py +484 -0
  127. ccproxy/services/__init__.py +10 -0
  128. ccproxy/services/claude_sdk_service.py +614 -0
  129. ccproxy/services/credentials/__init__.py +55 -0
  130. ccproxy/services/credentials/config.py +105 -0
  131. ccproxy/services/credentials/manager.py +562 -0
  132. ccproxy/services/credentials/oauth_client.py +482 -0
  133. ccproxy/services/proxy_service.py +1536 -0
  134. ccproxy/static/.keep +0 -0
  135. ccproxy/testing/__init__.py +34 -0
  136. ccproxy/testing/config.py +148 -0
  137. ccproxy/testing/content_generation.py +197 -0
  138. ccproxy/testing/mock_responses.py +262 -0
  139. ccproxy/testing/response_handlers.py +161 -0
  140. ccproxy/testing/scenarios.py +241 -0
  141. ccproxy/utils/__init__.py +6 -0
  142. ccproxy/utils/cost_calculator.py +210 -0
  143. ccproxy/utils/streaming_metrics.py +199 -0
  144. ccproxy_api-0.1.0.dist-info/METADATA +253 -0
  145. ccproxy_api-0.1.0.dist-info/RECORD +148 -0
  146. ccproxy_api-0.1.0.dist-info/WHEEL +4 -0
  147. ccproxy_api-0.1.0.dist-info/entry_points.txt +2 -0
  148. 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