@oneciel-ai/ciel-runtime 0.1.1 → 0.2.0
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.
- package/README.md +132 -0
- package/ciel-runtime-menu.py +56 -6
- package/ciel_runtime.py +9379 -35909
- package/ciel_runtime_support/advisor_client.py +193 -0
- package/ciel_runtime_support/advisor_policy.py +320 -0
- package/ciel_runtime_support/advisor_refinement.py +160 -0
- package/ciel_runtime_support/advisor_request_builder.py +261 -0
- package/ciel_runtime_support/agy_installer.py +169 -0
- package/ciel_runtime_support/agy_mcp_restore.py +182 -0
- package/ciel_runtime_support/anthropic_model_policy.py +186 -0
- package/ciel_runtime_support/anthropic_response_writer.py +255 -0
- package/ciel_runtime_support/anthropic_tool_turns.py +130 -0
- package/ciel_runtime_support/api_key_cooldown.py +159 -0
- package/ciel_runtime_support/architecture.py +488 -1
- package/ciel_runtime_support/architecture_budget.py +42 -0
- package/ciel_runtime_support/channel_backlog.py +90 -0
- package/ciel_runtime_support/channel_cli.py +119 -0
- package/ciel_runtime_support/channel_compact_injection.py +82 -0
- package/ciel_runtime_support/channel_compact_poll.py +67 -0
- package/ciel_runtime_support/channel_compact_request_repository.py +113 -0
- package/ciel_runtime_support/channel_config_service.py +281 -0
- package/ciel_runtime_support/channel_connection_lifecycle.py +180 -0
- package/ciel_runtime_support/channel_connection_registry.py +128 -0
- package/ciel_runtime_support/channel_connection_worker.py +284 -0
- package/ciel_runtime_support/channel_cursor_recovery.py +92 -0
- package/ciel_runtime_support/channel_cursor_repository.py +89 -0
- package/ciel_runtime_support/channel_cursor_service.py +178 -0
- package/ciel_runtime_support/channel_event_identity.py +212 -0
- package/ciel_runtime_support/channel_event_projection.py +315 -0
- package/ciel_runtime_support/channel_inflight.py +127 -0
- package/ciel_runtime_support/channel_injection.py +115 -0
- package/ciel_runtime_support/channel_launch_guard_repository.py +58 -0
- package/ciel_runtime_support/channel_launch_policy.py +180 -0
- package/ciel_runtime_support/channel_llm_context.py +156 -0
- package/ciel_runtime_support/channel_mcp_discovery.py +186 -0
- package/ciel_runtime_support/channel_mcp_http_controller.py +239 -0
- package/ciel_runtime_support/channel_mcp_ownership.py +148 -0
- package/ciel_runtime_support/channel_mcp_tools.py +240 -0
- package/ciel_runtime_support/channel_mcp_transport.py +394 -0
- package/ciel_runtime_support/channel_message_dedupe.py +65 -0
- package/ciel_runtime_support/channel_message_policy.py +256 -0
- package/ciel_runtime_support/channel_message_prompt.py +305 -0
- package/ciel_runtime_support/channel_message_repository.py +234 -0
- package/ciel_runtime_support/channel_notification_projection.py +217 -0
- package/ciel_runtime_support/channel_panel.py +162 -0
- package/ciel_runtime_support/channel_pending_injection.py +209 -0
- package/ciel_runtime_support/channel_pending_poll.py +109 -0
- package/ciel_runtime_support/channel_probe_cache.py +433 -0
- package/ciel_runtime_support/channel_probe_report.py +101 -0
- package/ciel_runtime_support/channel_runtime_environment.py +181 -0
- package/ciel_runtime_support/channel_session_lifecycle.py +114 -0
- package/ciel_runtime_support/channel_session_repository.py +90 -0
- package/ciel_runtime_support/channel_terminal_dispatch.py +115 -0
- package/ciel_runtime_support/channel_terminal_input.py +277 -0
- package/ciel_runtime_support/channel_terminal_proxy.py +447 -0
- package/ciel_runtime_support/channel_tool_context.py +166 -0
- package/ciel_runtime_support/channel_transcript.py +414 -0
- package/ciel_runtime_support/channel_transcript_repository.py +96 -0
- package/ciel_runtime_support/channel_wake_claim_repository.py +126 -0
- package/ciel_runtime_support/channel_wake_delivery_repository.py +88 -0
- package/ciel_runtime_support/chat_files.py +138 -0
- package/ciel_runtime_support/chat_http_controller.py +235 -0
- package/ciel_runtime_support/claude_environment.py +375 -0
- package/ciel_runtime_support/claude_router.py +247 -193
- package/ciel_runtime_support/cli_dispatch.py +792 -0
- package/ciel_runtime_support/cli_parser.py +165 -0
- package/ciel_runtime_support/cli_usage.py +100 -0
- package/ciel_runtime_support/codex_app_server.py +20 -5
- package/ciel_runtime_support/codex_channel_sse_launch.py +87 -0
- package/ciel_runtime_support/codex_cli.py +42 -6
- package/ciel_runtime_support/codex_config.py +323 -0
- package/ciel_runtime_support/codex_launch_configuration.py +240 -0
- package/ciel_runtime_support/codex_launch_policy.py +66 -0
- package/ciel_runtime_support/codex_mcp_integration.py +195 -0
- package/ciel_runtime_support/codex_mcp_restore.py +304 -0
- package/ciel_runtime_support/codex_model_catalog.py +133 -0
- package/ciel_runtime_support/codex_process_lifecycle.py +271 -0
- package/ciel_runtime_support/codex_router.py +147 -1
- package/ciel_runtime_support/codex_session_repository.py +115 -0
- package/ciel_runtime_support/codex_session_selection.py +114 -0
- package/ciel_runtime_support/command_asset_installer.py +103 -0
- package/ciel_runtime_support/compatibility_probe.py +295 -0
- package/ciel_runtime_support/compatibility_protocol.py +251 -0
- package/ciel_runtime_support/compatibility_runtime.py +166 -0
- package/ciel_runtime_support/compatibility_test.py +370 -0
- package/ciel_runtime_support/config_migrations.py +307 -0
- package/ciel_runtime_support/config_repository.py +175 -0
- package/ciel_runtime_support/config_value_codec.py +64 -0
- package/ciel_runtime_support/configuration_cli.py +374 -0
- package/ciel_runtime_support/context_compaction.py +280 -0
- package/ciel_runtime_support/context_setup.py +208 -0
- package/ciel_runtime_support/context_summary_policy.py +392 -0
- package/ciel_runtime_support/credential_cli.py +104 -0
- package/ciel_runtime_support/credential_management.py +261 -0
- package/ciel_runtime_support/credentials.py +269 -0
- package/ciel_runtime_support/executable_discovery.py +141 -0
- package/ciel_runtime_support/github_copilot_oauth.py +335 -0
- package/ciel_runtime_support/github_copilot_oauth_runtime.py +213 -0
- package/ciel_runtime_support/header_forwarding.py +73 -0
- package/ciel_runtime_support/headless_config.py +221 -0
- package/ciel_runtime_support/http_response.py +129 -0
- package/ciel_runtime_support/install_diagnostics.py +149 -0
- package/ciel_runtime_support/kimi_identity.py +123 -0
- package/ciel_runtime_support/launch_diagnostics.py +204 -0
- package/ciel_runtime_support/launch_state.py +127 -0
- package/ciel_runtime_support/live_api_key_controller.py +58 -0
- package/ciel_runtime_support/llm_config_http.py +148 -0
- package/ciel_runtime_support/llm_option_config.py +259 -0
- package/ciel_runtime_support/llm_presentation_data.py +447 -0
- package/ciel_runtime_support/llm_presets.py +773 -0
- package/ciel_runtime_support/lm_studio_runtime.py +401 -0
- package/ciel_runtime_support/managed_mcp_config.py +144 -0
- package/ciel_runtime_support/managed_mcp_discovery.py +151 -0
- package/ciel_runtime_support/managed_service_cleanup.py +89 -0
- package/ciel_runtime_support/mcp_config_reader.py +230 -0
- package/ciel_runtime_support/mcp_http_proxy.py +607 -0
- package/ciel_runtime_support/mcp_inventory.py +59 -0
- package/ciel_runtime_support/mcp_notification_wait_policy.py +159 -0
- package/ciel_runtime_support/mcp_probe_codec.py +136 -0
- package/ciel_runtime_support/mcp_probe_transport.py +328 -0
- package/ciel_runtime_support/mcp_proxy_codec.py +345 -0
- package/ciel_runtime_support/mcp_proxy_config.py +107 -0
- package/ciel_runtime_support/mcp_proxy_notifications.py +261 -0
- package/ciel_runtime_support/mcp_proxy_process.py +560 -0
- package/ciel_runtime_support/mcp_split_proxy_http.py +165 -0
- package/ciel_runtime_support/mcp_stdio_probe.py +240 -0
- package/ciel_runtime_support/mcp_transport.py +146 -0
- package/ciel_runtime_support/model_cache_lifecycle.py +78 -0
- package/ciel_runtime_support/model_catalog_projection.py +61 -0
- package/ciel_runtime_support/model_context_hints.py +109 -0
- package/ciel_runtime_support/model_panel.py +147 -0
- package/ciel_runtime_support/model_registry_repository.py +231 -0
- package/ciel_runtime_support/npm_runtime.py +191 -0
- package/ciel_runtime_support/ollama_catalog.py +462 -0
- package/ciel_runtime_support/ollama_catalog_cli.py +41 -0
- package/ciel_runtime_support/ollama_catalog_repository.py +75 -0
- package/ciel_runtime_support/ollama_context_sync.py +87 -0
- package/ciel_runtime_support/ollama_forwarding.py +449 -0
- package/ciel_runtime_support/openai_chat_passthrough.py +67 -0
- package/ciel_runtime_support/openai_chat_router.py +64 -0
- package/ciel_runtime_support/openai_forwarding.py +194 -0
- package/ciel_runtime_support/openai_responses_router.py +291 -0
- package/ciel_runtime_support/openai_responses_stream.py +135 -0
- package/ciel_runtime_support/output_budget.py +89 -0
- package/ciel_runtime_support/package_lifecycle.py +217 -0
- package/ciel_runtime_support/plan_artifact_controller.py +104 -0
- package/ciel_runtime_support/prelaunch.py +959 -0
- package/ciel_runtime_support/prelaunch_launch_preference.py +75 -0
- package/ciel_runtime_support/prelaunch_panel_projection.py +396 -0
- package/ciel_runtime_support/prelaunch_terminal.py +764 -0
- package/ciel_runtime_support/process_control.py +708 -0
- package/ciel_runtime_support/prompt_compaction.py +322 -0
- package/ciel_runtime_support/prompt_injection.py +176 -0
- package/ciel_runtime_support/protocols/__init__.py +24 -0
- package/ciel_runtime_support/protocols/anthropic_content.py +29 -0
- package/ciel_runtime_support/protocols/anthropic_thinking_policy.py +336 -0
- package/ciel_runtime_support/protocols/chat_projection.py +315 -0
- package/ciel_runtime_support/protocols/conversation_policy.py +217 -0
- package/ciel_runtime_support/protocols/conversation_turn_policy.py +972 -0
- package/ciel_runtime_support/protocols/ollama_chat.py +111 -0
- package/ciel_runtime_support/protocols/ollama_response.py +231 -0
- package/ciel_runtime_support/protocols/openai_reasoning.py +75 -0
- package/ciel_runtime_support/protocols/openai_responses.py +271 -0
- package/ciel_runtime_support/protocols/pseudo_tool_history.py +248 -0
- package/ciel_runtime_support/protocols/tool_result_projection.py +112 -0
- package/ciel_runtime_support/provider_adapters.py +160 -0
- package/ciel_runtime_support/provider_catalog_sources.py +316 -0
- package/ciel_runtime_support/provider_choice.py +201 -0
- package/ciel_runtime_support/provider_compatibility.py +165 -0
- package/ciel_runtime_support/provider_config_mutations.py +361 -0
- package/ciel_runtime_support/provider_configuration_service.py +162 -0
- package/ciel_runtime_support/provider_context.py +308 -0
- package/ciel_runtime_support/provider_contract_projection.py +73 -0
- package/ciel_runtime_support/provider_descriptor.py +82 -0
- package/ciel_runtime_support/provider_endpoint_policy.py +130 -0
- package/ciel_runtime_support/provider_endpoint_probe.py +165 -0
- package/ciel_runtime_support/provider_launch_endpoint.py +109 -0
- package/ciel_runtime_support/provider_limits.py +457 -0
- package/ciel_runtime_support/provider_model_identity.py +139 -0
- package/ciel_runtime_support/provider_model_selection.py +431 -0
- package/ciel_runtime_support/provider_model_specs.py +142 -0
- package/ciel_runtime_support/provider_models.py +263 -0
- package/ciel_runtime_support/provider_network.py +176 -0
- package/ciel_runtime_support/provider_option_cli.py +238 -0
- package/ciel_runtime_support/provider_option_panel.py +275 -0
- package/ciel_runtime_support/provider_option_status.py +192 -0
- package/ciel_runtime_support/provider_policy.py +101 -0
- package/ciel_runtime_support/provider_query_policy.py +67 -0
- package/ciel_runtime_support/provider_readiness.py +112 -0
- package/ciel_runtime_support/provider_request_access.py +131 -0
- package/ciel_runtime_support/provider_request_builder.py +250 -0
- package/ciel_runtime_support/provider_responses_passthrough.py +81 -0
- package/ciel_runtime_support/provider_runtime_info.py +113 -0
- package/ciel_runtime_support/provider_runtime_modes.py +150 -0
- package/ciel_runtime_support/provider_sampling_policy.py +46 -0
- package/ciel_runtime_support/provider_status.py +145 -0
- package/ciel_runtime_support/provider_timeout_policy.py +184 -0
- package/ciel_runtime_support/provider_tool_policy.py +145 -0
- package/ciel_runtime_support/providers/__init__.py +65 -0
- package/ciel_runtime_support/providers/anthropic.py +160 -0
- package/ciel_runtime_support/providers/anthropic_catalog.py +119 -0
- package/ciel_runtime_support/providers/base.py +232 -0
- package/ciel_runtime_support/providers/catalog.py +326 -0
- package/ciel_runtime_support/providers/cloud.py +194 -0
- package/ciel_runtime_support/providers/constants.py +54 -0
- package/ciel_runtime_support/providers/deepseek.py +115 -0
- package/ciel_runtime_support/providers/fireworks.py +158 -0
- package/ciel_runtime_support/providers/github_copilot_oauth.py +199 -0
- package/ciel_runtime_support/providers/kimi.py +297 -0
- package/ciel_runtime_support/providers/lm_studio.py +76 -0
- package/ciel_runtime_support/providers/meta.py +257 -0
- package/ciel_runtime_support/providers/native.py +194 -0
- package/ciel_runtime_support/providers/nim.py +69 -0
- package/ciel_runtime_support/providers/nvidia.py +158 -0
- package/ciel_runtime_support/providers/nvidia_runtime.py +285 -0
- package/ciel_runtime_support/providers/ollama.py +181 -0
- package/ciel_runtime_support/providers/ollama_context.py +195 -0
- package/ciel_runtime_support/providers/ollama_runtime.py +213 -0
- package/ciel_runtime_support/providers/opencode.py +220 -0
- package/ciel_runtime_support/providers/opencode_go.py +37 -0
- package/ciel_runtime_support/providers/openrouter.py +57 -0
- package/ciel_runtime_support/providers/vllm.py +65 -0
- package/ciel_runtime_support/providers/zai.py +119 -0
- package/ciel_runtime_support/pseudo_tool_parser.py +115 -0
- package/ciel_runtime_support/rate_limit_policy.py +117 -0
- package/ciel_runtime_support/rate_limit_repository.py +154 -0
- package/ciel_runtime_support/registry.py +46 -0
- package/ciel_runtime_support/request_shortcuts.py +253 -0
- package/ciel_runtime_support/request_trace.py +323 -0
- package/ciel_runtime_support/response_collection.py +209 -0
- package/ciel_runtime_support/router_access.py +238 -0
- package/ciel_runtime_support/router_client_lifecycle.py +366 -0
- package/ciel_runtime_support/router_health_policy.py +101 -0
- package/ciel_runtime_support/router_http.py +513 -0
- package/ciel_runtime_support/router_process_lifecycle.py +401 -0
- package/ciel_runtime_support/router_rate_limit_service.py +285 -0
- package/ciel_runtime_support/router_server_runtime.py +103 -0
- package/ciel_runtime_support/router_shortcuts.py +201 -0
- package/ciel_runtime_support/routing_fallback.py +73 -0
- package/ciel_runtime_support/runtime_activity_repository.py +143 -0
- package/ciel_runtime_support/runtime_adapters.py +104 -0
- package/ciel_runtime_support/runtime_command_factory.py +73 -0
- package/ciel_runtime_support/runtime_compatibility.py +50 -0
- package/ciel_runtime_support/runtime_constants.py +178 -0
- package/ciel_runtime_support/runtime_launch.py +1602 -0
- package/ciel_runtime_support/runtime_llm_options.py +312 -0
- package/ciel_runtime_support/runtime_logging.py +161 -0
- package/ciel_runtime_support/runtime_paths.py +157 -0
- package/ciel_runtime_support/runtime_restart.py +84 -0
- package/ciel_runtime_support/runtime_upgrade.py +149 -0
- package/ciel_runtime_support/secure_json_repository.py +55 -0
- package/ciel_runtime_support/session_import.py +356 -0
- package/ciel_runtime_support/settings_repository.py +8 -0
- package/ciel_runtime_support/slash_command_assets.py +211 -0
- package/ciel_runtime_support/sse_stream.py +57 -0
- package/ciel_runtime_support/sse_trace.py +225 -0
- package/ciel_runtime_support/statusline_script.py +593 -0
- package/ciel_runtime_support/statusline_settings.py +53 -0
- package/ciel_runtime_support/stream_chunk_policy.py +18 -0
- package/ciel_runtime_support/streaming_anthropic.py +1955 -0
- package/ciel_runtime_support/synthetic_tool_policy.py +105 -0
- package/ciel_runtime_support/terminal_platform_io.py +127 -0
- package/ciel_runtime_support/timeout_profile.py +196 -0
- package/ciel_runtime_support/tool_dialects.py +85 -0
- package/ciel_runtime_support/tool_exposure_policy.py +63 -0
- package/ciel_runtime_support/tool_guard_hooks.py +218 -0
- package/ciel_runtime_support/tool_request_projection.py +96 -0
- package/ciel_runtime_support/tool_schema.py +483 -0
- package/ciel_runtime_support/tool_side_effect_dedupe.py +95 -0
- package/ciel_runtime_support/ui_text.py +266 -0
- package/ciel_runtime_support/upstream_error_policy.py +104 -0
- package/ciel_runtime_support/upstream_retry.py +419 -0
- package/ciel_runtime_support/upstream_stream_io.py +106 -0
- package/ciel_runtime_support/usage_events.py +96 -0
- package/ciel_runtime_support/visible_stream_filters.py +130 -0
- package/ciel_runtime_support/web_endpoints.py +447 -0
- package/ciel_runtime_support/web_ui.py +915 -0
- package/ciel_runtime_support/web_ui_controller.py +189 -0
- package/ciel_runtime_support/windows_console_input.py +137 -0
- package/ciel_runtime_support/windows_console_mode.py +112 -0
- package/docs/Architecture.md +54 -0
- package/docs/Configuration.md +17 -0
- package/docs/Module-Map.md +1093 -26
- package/docs/Providers.md +46 -1
- package/docs/adr/0001-runtime-bounded-contexts.md +295 -0
- package/npm-bin/run-ciel-runtime.js +22 -2
- package/package.json +9 -2
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"""Declarative adapters for standard OpenAI-compatible API providers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from functools import partial
|
|
7
|
+
from typing import Callable
|
|
8
|
+
|
|
9
|
+
from ..architecture import (
|
|
10
|
+
MessageProtocol,
|
|
11
|
+
ProviderAdapter,
|
|
12
|
+
ProviderCapabilities,
|
|
13
|
+
ProviderConfig,
|
|
14
|
+
ProviderContextPolicy,
|
|
15
|
+
ProviderModelCatalogPolicy,
|
|
16
|
+
ProviderRequestPolicy,
|
|
17
|
+
)
|
|
18
|
+
from ..runtime_constants import DEFAULT_REQUEST_TIMEOUT_MS
|
|
19
|
+
from .base import OpenAICompatibleProviderAdapter, provider_configuration
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class CompatibleProviderSpec:
|
|
24
|
+
"""Immutable transport and discovery policy for one compatible provider."""
|
|
25
|
+
|
|
26
|
+
name: str
|
|
27
|
+
label: str
|
|
28
|
+
base_url: str
|
|
29
|
+
models: tuple[str, ...] = ()
|
|
30
|
+
aliases: tuple[str, ...] = ()
|
|
31
|
+
chat_path: str = "/v1/chat/completions"
|
|
32
|
+
models_path: str = "/v1/models"
|
|
33
|
+
authorization_header: str = "Authorization"
|
|
34
|
+
include_x_api_key: bool = False
|
|
35
|
+
requires_api_key: bool = True
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class CatalogOpenAIProviderAdapter(OpenAICompatibleProviderAdapter):
|
|
39
|
+
"""Concrete Strategy assembled from a validated compatible-provider spec."""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
spec: CompatibleProviderSpec,
|
|
44
|
+
*,
|
|
45
|
+
base_url: str = "",
|
|
46
|
+
) -> None:
|
|
47
|
+
self.spec = spec
|
|
48
|
+
default_model = spec.models[0] if spec.models else ""
|
|
49
|
+
super().__init__(
|
|
50
|
+
name=spec.name,
|
|
51
|
+
base_url=base_url or spec.base_url,
|
|
52
|
+
configuration_defaults_value=provider_configuration(
|
|
53
|
+
default_model,
|
|
54
|
+
custom_models=spec.models,
|
|
55
|
+
native_compat=False,
|
|
56
|
+
context_window=131072,
|
|
57
|
+
max_output_tokens=8192,
|
|
58
|
+
context_reserve_tokens=4096,
|
|
59
|
+
request_timeout_ms=DEFAULT_REQUEST_TIMEOUT_MS,
|
|
60
|
+
stream_enabled=True,
|
|
61
|
+
stream_word_chunking=False,
|
|
62
|
+
),
|
|
63
|
+
authorization_header=spec.authorization_header,
|
|
64
|
+
include_x_api_key=spec.include_x_api_key,
|
|
65
|
+
require_api_key=spec.requires_api_key,
|
|
66
|
+
api_key_display_name_value=spec.label,
|
|
67
|
+
api_key_launch_error_value=(
|
|
68
|
+
f"Launch blocked: {spec.label} requires an API key."
|
|
69
|
+
if spec.requires_api_key
|
|
70
|
+
else ""
|
|
71
|
+
),
|
|
72
|
+
capabilities_value=ProviderCapabilities(
|
|
73
|
+
upstream_protocol="openai_chat",
|
|
74
|
+
requires_api_key=spec.requires_api_key,
|
|
75
|
+
),
|
|
76
|
+
request_policy_value=ProviderRequestPolicy(
|
|
77
|
+
chat_path=spec.chat_path,
|
|
78
|
+
models_path=spec.models_path,
|
|
79
|
+
),
|
|
80
|
+
model_catalog_policy_value=ProviderModelCatalogPolicy(
|
|
81
|
+
kind="openai",
|
|
82
|
+
fallback_models=spec.models,
|
|
83
|
+
allow_configured_fallback=True,
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def context_policy(self, config: ProviderConfig) -> ProviderContextPolicy:
|
|
88
|
+
del config
|
|
89
|
+
return ProviderContextPolicy(
|
|
90
|
+
capacity_strategy="configured_first",
|
|
91
|
+
settings_strategy="standard",
|
|
92
|
+
hosted_timeout=True,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def router_native_anthropic_enabled(
|
|
96
|
+
self,
|
|
97
|
+
config: ProviderConfig,
|
|
98
|
+
model: str | None = None,
|
|
99
|
+
) -> bool:
|
|
100
|
+
del config, model
|
|
101
|
+
return False
|
|
102
|
+
|
|
103
|
+
def supported_protocols(
|
|
104
|
+
self,
|
|
105
|
+
config: ProviderConfig,
|
|
106
|
+
model: str | None = None,
|
|
107
|
+
) -> frozenset[MessageProtocol]:
|
|
108
|
+
del config, model
|
|
109
|
+
return frozenset({"openai_chat"})
|
|
110
|
+
|
|
111
|
+
def select_protocol(
|
|
112
|
+
self,
|
|
113
|
+
operation: MessageProtocol,
|
|
114
|
+
config: ProviderConfig,
|
|
115
|
+
model: str | None = None,
|
|
116
|
+
) -> MessageProtocol:
|
|
117
|
+
del operation, config, model
|
|
118
|
+
return "openai_chat"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def catalog_provider_factory(
|
|
122
|
+
spec: CompatibleProviderSpec,
|
|
123
|
+
) -> Callable[..., ProviderAdapter]:
|
|
124
|
+
"""Return a descriptor-compatible factory bound to one immutable spec."""
|
|
125
|
+
|
|
126
|
+
return partial(CatalogOpenAIProviderAdapter, spec)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
COMPATIBLE_PROVIDER_SPECS: tuple[CompatibleProviderSpec, ...] = (
|
|
130
|
+
CompatibleProviderSpec(
|
|
131
|
+
"alicode-intl", "Alibaba Coding International",
|
|
132
|
+
"https://coding-intl.dashscope.aliyuncs.com/v1",
|
|
133
|
+
("qwen3.5-plus", "kimi-k2.5", "glm-5", "qwen3-coder-next"),
|
|
134
|
+
("alibaba-coding-intl",),
|
|
135
|
+
),
|
|
136
|
+
CompatibleProviderSpec(
|
|
137
|
+
"alicode", "Alibaba Coding", "https://coding.dashscope.aliyuncs.com/v1",
|
|
138
|
+
("qwen3.5-plus", "kimi-k2.5", "glm-5", "qwen3-coder-next"),
|
|
139
|
+
("alibaba-coding",),
|
|
140
|
+
),
|
|
141
|
+
CompatibleProviderSpec(
|
|
142
|
+
"alims-intl", "Alibaba Model Studio International",
|
|
143
|
+
"https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
|
|
144
|
+
("qwen3.5-plus", "kimi-k2.5", "glm-5", "qwen3-coder-next"),
|
|
145
|
+
("dashscope-intl",),
|
|
146
|
+
),
|
|
147
|
+
CompatibleProviderSpec(
|
|
148
|
+
"blackbox", "Blackbox AI", "https://api.blackbox.ai/v1",
|
|
149
|
+
("claude-sonnet-4.6", "gpt-5.4", "gpt-5.3-codex", "deepseek-v4-flash"),
|
|
150
|
+
("bb",),
|
|
151
|
+
),
|
|
152
|
+
CompatibleProviderSpec(
|
|
153
|
+
"byteplus", "BytePlus ModelArk",
|
|
154
|
+
"https://ark.ap-southeast.bytepluses.com/api/coding/v3",
|
|
155
|
+
("seed-2-0-code-preview-260328", "seed-2-0-pro-260328", "glm-4-7-251222"),
|
|
156
|
+
("bpm",), chat_path="/chat/completions", models_path="/models",
|
|
157
|
+
),
|
|
158
|
+
CompatibleProviderSpec(
|
|
159
|
+
"cerebras", "Cerebras", "https://api.cerebras.ai/v1",
|
|
160
|
+
("gpt-oss-120b", "zai-glm-4.7", "llama-3.3-70b"),
|
|
161
|
+
),
|
|
162
|
+
CompatibleProviderSpec(
|
|
163
|
+
"chutes", "Chutes AI", "https://llm.chutes.ai/v1", aliases=("ch",),
|
|
164
|
+
),
|
|
165
|
+
CompatibleProviderSpec(
|
|
166
|
+
"cohere", "Cohere", "https://api.cohere.ai/v1",
|
|
167
|
+
("command-a-03-2025", "command-r-plus-08-2024", "command-r-08-2024"),
|
|
168
|
+
),
|
|
169
|
+
CompatibleProviderSpec(
|
|
170
|
+
"cloudflare-ai", "Cloudflare Workers AI", "",
|
|
171
|
+
aliases=("workers-ai",), chat_path="/chat/completions",
|
|
172
|
+
models_path="/models",
|
|
173
|
+
),
|
|
174
|
+
CompatibleProviderSpec(
|
|
175
|
+
"cline", "Cline", "https://api.cline.bot/api/v1",
|
|
176
|
+
aliases=("cline-oauth",),
|
|
177
|
+
),
|
|
178
|
+
CompatibleProviderSpec(
|
|
179
|
+
"clinepass", "Cline Pass", "https://api.cline.bot/api/v1",
|
|
180
|
+
aliases=("cline-pass",),
|
|
181
|
+
),
|
|
182
|
+
CompatibleProviderSpec(
|
|
183
|
+
"featherless", "Featherless", "https://api.featherless.ai/v1",
|
|
184
|
+
("deepseek-ai/DeepSeek-V4-Pro", "zai-org/GLM-5.2", "moonshotai/Kimi-K2.7-Code"),
|
|
185
|
+
("fl",),
|
|
186
|
+
),
|
|
187
|
+
CompatibleProviderSpec(
|
|
188
|
+
"glm-cn", "GLM China", "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
189
|
+
("glm-5.2", "glm-5.1", "glm-5", "glm-4.7"),
|
|
190
|
+
("bigmodel-cn",), chat_path="/chat/completions", models_path="/models",
|
|
191
|
+
),
|
|
192
|
+
CompatibleProviderSpec(
|
|
193
|
+
"gemini", "Google Gemini", "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
194
|
+
("gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"),
|
|
195
|
+
("google-gemini",),
|
|
196
|
+
),
|
|
197
|
+
CompatibleProviderSpec(
|
|
198
|
+
"groq", "Groq", "https://api.groq.com/openai/v1",
|
|
199
|
+
("llama-3.3-70b-versatile", "qwen/qwen3-32b", "openai/gpt-oss-120b"),
|
|
200
|
+
),
|
|
201
|
+
CompatibleProviderSpec(
|
|
202
|
+
"github", "GitHub Copilot API key", "https://api.githubcopilot.com",
|
|
203
|
+
aliases=("github-copilot", "copilot"),
|
|
204
|
+
chat_path="/chat/completions", models_path="/models",
|
|
205
|
+
),
|
|
206
|
+
CompatibleProviderSpec(
|
|
207
|
+
"gitlab", "GitLab Duo", "https://gitlab.com/api/v4",
|
|
208
|
+
aliases=("gitlab-duo",), chat_path="/chat/completions",
|
|
209
|
+
models_path="/models",
|
|
210
|
+
),
|
|
211
|
+
CompatibleProviderSpec(
|
|
212
|
+
"hyperbolic", "Hyperbolic", "https://api.hyperbolic.xyz/v1",
|
|
213
|
+
("deepseek-ai/DeepSeek-R1", "deepseek-ai/DeepSeek-V3", "Qwen/Qwen2.5-Coder-32B-Instruct"),
|
|
214
|
+
("hyp",),
|
|
215
|
+
),
|
|
216
|
+
CompatibleProviderSpec(
|
|
217
|
+
"huggingface", "Hugging Face Inference", "https://router.huggingface.co/v1",
|
|
218
|
+
aliases=("hf", "hugging-face"),
|
|
219
|
+
),
|
|
220
|
+
CompatibleProviderSpec(
|
|
221
|
+
"iflow", "iFlow", "https://apis.iflow.cn/v1",
|
|
222
|
+
aliases=("iflow-oauth",),
|
|
223
|
+
),
|
|
224
|
+
CompatibleProviderSpec(
|
|
225
|
+
"kilocode", "Kilo Code", "https://api.kilo.ai/api/openrouter",
|
|
226
|
+
aliases=("kilo", "kilo-code"),
|
|
227
|
+
),
|
|
228
|
+
CompatibleProviderSpec(
|
|
229
|
+
"kimchi", "Kimchi", "https://llm.kimchi.dev/openai/v1",
|
|
230
|
+
aliases=("kimchi-oauth",),
|
|
231
|
+
),
|
|
232
|
+
CompatibleProviderSpec(
|
|
233
|
+
"mistral", "Mistral", "https://api.mistral.ai/v1",
|
|
234
|
+
("codestral-latest", "mistral-large-latest", "mistral-medium-latest"),
|
|
235
|
+
),
|
|
236
|
+
CompatibleProviderSpec(
|
|
237
|
+
"mimo-free", "Xiaomi MiMo Free", "https://api.xiaomimimo.com/api/free-ai/openai",
|
|
238
|
+
("mimo-v2-flash",), aliases=("mimo-free-api",), requires_api_key=False,
|
|
239
|
+
),
|
|
240
|
+
CompatibleProviderSpec(
|
|
241
|
+
"mmf", "Xiaomi MiMo Free API", "https://api.xiaomimimo.com/api/free-ai/openai",
|
|
242
|
+
("mimo-v2-flash",), aliases=("xiaomi-mmf",),
|
|
243
|
+
),
|
|
244
|
+
CompatibleProviderSpec(
|
|
245
|
+
"nebius", "Nebius AI", "https://api.studio.nebius.ai/v1",
|
|
246
|
+
("meta-llama/Llama-3.3-70B-Instruct",),
|
|
247
|
+
),
|
|
248
|
+
CompatibleProviderSpec(
|
|
249
|
+
"openai", "OpenAI API", "https://api.openai.com/v1",
|
|
250
|
+
("gpt-5.4", "gpt-5.4-mini", "gpt-5.2", "gpt-5.1", "gpt-4.1", "o3", "o4-mini"),
|
|
251
|
+
("openai-api",),
|
|
252
|
+
),
|
|
253
|
+
CompatibleProviderSpec(
|
|
254
|
+
"perplexity", "Perplexity", "https://api.perplexity.ai",
|
|
255
|
+
("sonar-pro", "sonar"), ("pplx",),
|
|
256
|
+
chat_path="/chat/completions", models_path="/models",
|
|
257
|
+
),
|
|
258
|
+
CompatibleProviderSpec(
|
|
259
|
+
"qwen", "Qwen Code", "https://portal.qwen.ai/v1",
|
|
260
|
+
aliases=("qwen-oauth", "qwen-code"),
|
|
261
|
+
),
|
|
262
|
+
CompatibleProviderSpec(
|
|
263
|
+
"siliconflow", "SiliconFlow", "https://api.siliconflow.com/v1",
|
|
264
|
+
("deepseek-ai/DeepSeek-V4-Pro", "Qwen/Qwen3.5-397B-A17B", "zai-org/GLM-5.1", "moonshotai/Kimi-K2.6"),
|
|
265
|
+
("silicon-flow",),
|
|
266
|
+
),
|
|
267
|
+
CompatibleProviderSpec(
|
|
268
|
+
"together", "Together AI", "https://api.together.xyz/v1",
|
|
269
|
+
("meta-llama/Llama-3.3-70B-Instruct-Turbo", "deepseek-ai/DeepSeek-R1", "Qwen/Qwen3-235B-A22B"),
|
|
270
|
+
("together-ai",),
|
|
271
|
+
),
|
|
272
|
+
CompatibleProviderSpec(
|
|
273
|
+
"venice", "Venice AI", "https://api.venice.ai/api/v1",
|
|
274
|
+
("venice-uncensored-1-2", "zai-org-glm-5", "deepseek-v4-pro", "qwen3-coder-480b-a35b-instruct-turbo"),
|
|
275
|
+
("vn",),
|
|
276
|
+
),
|
|
277
|
+
CompatibleProviderSpec(
|
|
278
|
+
"vertex", "Google Vertex AI", "",
|
|
279
|
+
aliases=("vertex-ai",), chat_path="/chat/completions",
|
|
280
|
+
models_path="/models",
|
|
281
|
+
),
|
|
282
|
+
CompatibleProviderSpec(
|
|
283
|
+
"vertex-partner", "Google Vertex AI Partner Models", "",
|
|
284
|
+
aliases=("vertex-maas",), chat_path="/chat/completions",
|
|
285
|
+
models_path="/models",
|
|
286
|
+
),
|
|
287
|
+
CompatibleProviderSpec(
|
|
288
|
+
"vercel-ai-gateway", "Vercel AI Gateway", "https://ai-gateway.vercel.sh/v1",
|
|
289
|
+
aliases=("vercel", "vercel-ai"),
|
|
290
|
+
),
|
|
291
|
+
CompatibleProviderSpec(
|
|
292
|
+
"volcengine-ark", "Volcengine Ark",
|
|
293
|
+
"https://ark.cn-beijing.volces.com/api/coding/v3",
|
|
294
|
+
("Doubao-Seed-2.0-Code", "DeepSeek-V4-Pro", "GLM-5.1", "Kimi-K2.6"),
|
|
295
|
+
("ark", "volcengine"), chat_path="/chat/completions", models_path="/models",
|
|
296
|
+
),
|
|
297
|
+
CompatibleProviderSpec(
|
|
298
|
+
"xai", "xAI", "https://api.x.ai/v1",
|
|
299
|
+
("grok-4", "grok-4-fast-reasoning", "grok-code-fast-1", "grok-3"),
|
|
300
|
+
("grok",),
|
|
301
|
+
),
|
|
302
|
+
CompatibleProviderSpec(
|
|
303
|
+
"xiaomi-mimo", "Xiaomi MiMo", "https://api.xiaomimimo.com/v1",
|
|
304
|
+
("mimo-v2.5-pro", "mimo-v2.5", "mimo-v2-omni", "mimo-v2-flash"),
|
|
305
|
+
("mimo",),
|
|
306
|
+
),
|
|
307
|
+
CompatibleProviderSpec(
|
|
308
|
+
"xiaomi-tokenplan", "Xiaomi MiMo Token Plan",
|
|
309
|
+
"https://token-plan-sgp.xiaomimimo.com/v1",
|
|
310
|
+
("mimo-v2.5-pro", "mimo-v2.5-pro-claude", "mimo-v2.5", "mimo-v2-pro"),
|
|
311
|
+
("xmtp", "xiaomi-token-plan"),
|
|
312
|
+
),
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
CATALOG_PROVIDER_BASE_URLS = {
|
|
316
|
+
spec.name: spec.base_url for spec in COMPATIBLE_PROVIDER_SPECS
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
__all__ = [
|
|
321
|
+
"CATALOG_PROVIDER_BASE_URLS",
|
|
322
|
+
"COMPATIBLE_PROVIDER_SPECS",
|
|
323
|
+
"CatalogOpenAIProviderAdapter",
|
|
324
|
+
"CompatibleProviderSpec",
|
|
325
|
+
"catalog_provider_factory",
|
|
326
|
+
]
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Adapters for cloud providers whose endpoint is deployment-specific."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Mapping
|
|
7
|
+
|
|
8
|
+
from ..architecture import (
|
|
9
|
+
ProviderCapabilities,
|
|
10
|
+
ProviderConfig,
|
|
11
|
+
ProviderModelCatalogPolicy,
|
|
12
|
+
ProviderRequestPolicy,
|
|
13
|
+
)
|
|
14
|
+
from .base import OpenAICompatibleProviderAdapter, provider_configuration
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class AzureOpenAIProviderAdapter(OpenAICompatibleProviderAdapter):
|
|
19
|
+
"""Azure OpenAI deployment transport with raw ``api-key`` authentication."""
|
|
20
|
+
|
|
21
|
+
name: str = "azure"
|
|
22
|
+
base_url: str = ""
|
|
23
|
+
configuration_defaults_value: dict = field(
|
|
24
|
+
default_factory=lambda: provider_configuration(
|
|
25
|
+
"",
|
|
26
|
+
native_compat=False,
|
|
27
|
+
api_version="2024-10-21",
|
|
28
|
+
context_window=128000,
|
|
29
|
+
max_output_tokens=8192,
|
|
30
|
+
context_reserve_tokens=4096,
|
|
31
|
+
request_timeout_ms=300000,
|
|
32
|
+
stream_enabled=True,
|
|
33
|
+
stream_word_chunking=False,
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
require_api_key: bool = True
|
|
37
|
+
api_key_display_name_value: str = "Azure OpenAI"
|
|
38
|
+
api_key_launch_error_value: str = (
|
|
39
|
+
"Launch blocked: Azure OpenAI requires a deployment endpoint and API key."
|
|
40
|
+
)
|
|
41
|
+
capabilities_value: ProviderCapabilities = field(
|
|
42
|
+
default_factory=lambda: ProviderCapabilities(
|
|
43
|
+
upstream_protocol="openai_chat",
|
|
44
|
+
requires_api_key=True,
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
request_policy_value: ProviderRequestPolicy = field(
|
|
48
|
+
default_factory=lambda: ProviderRequestPolicy(
|
|
49
|
+
chat_path="/chat/completions",
|
|
50
|
+
models_path="/models",
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
model_catalog_policy_value: ProviderModelCatalogPolicy = field(
|
|
54
|
+
default_factory=lambda: ProviderModelCatalogPolicy(
|
|
55
|
+
kind="configured",
|
|
56
|
+
allow_configured_fallback=True,
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def build_headers(
|
|
61
|
+
self,
|
|
62
|
+
config: ProviderConfig,
|
|
63
|
+
api_key: str | None,
|
|
64
|
+
) -> Mapping[str, str]:
|
|
65
|
+
del config
|
|
66
|
+
key = str(api_key or "").strip()
|
|
67
|
+
if not key:
|
|
68
|
+
raise RuntimeError("azure requires a configured API key.")
|
|
69
|
+
return {"api-key": key}
|
|
70
|
+
|
|
71
|
+
def build_model_headers(
|
|
72
|
+
self,
|
|
73
|
+
config: ProviderConfig,
|
|
74
|
+
api_key: str | None,
|
|
75
|
+
) -> Mapping[str, str]:
|
|
76
|
+
return self.build_headers(config, api_key)
|
|
77
|
+
|
|
78
|
+
def resolve_endpoint(self, operation: str, config: ProviderConfig) -> str:
|
|
79
|
+
policy = self.request_policy(config)
|
|
80
|
+
paths = {
|
|
81
|
+
"chat": policy.chat_path,
|
|
82
|
+
"openai_chat": policy.chat_path,
|
|
83
|
+
"models": policy.models_path,
|
|
84
|
+
}
|
|
85
|
+
path = paths.get(operation)
|
|
86
|
+
if path is None:
|
|
87
|
+
return super().resolve_endpoint(operation, config)
|
|
88
|
+
version = str(config.options.get("api_version") or "2024-10-21").strip()
|
|
89
|
+
if operation in {"chat", "openai_chat", "models"} and version:
|
|
90
|
+
separator = "&" if "?" in path else "?"
|
|
91
|
+
return f"{path}{separator}api-version={version}"
|
|
92
|
+
return path
|
|
93
|
+
|
|
94
|
+
def router_native_anthropic_enabled(
|
|
95
|
+
self,
|
|
96
|
+
config: ProviderConfig,
|
|
97
|
+
model: str | None = None,
|
|
98
|
+
) -> bool:
|
|
99
|
+
del config, model
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass(frozen=True)
|
|
104
|
+
class CodeBuddyCnProviderAdapter(OpenAICompatibleProviderAdapter):
|
|
105
|
+
"""Tencent CodeBuddy OpenAI-compatible transport."""
|
|
106
|
+
|
|
107
|
+
name: str = "codebuddy-cn"
|
|
108
|
+
base_url: str = "https://copilot.tencent.com/v2"
|
|
109
|
+
configuration_defaults_value: dict = field(
|
|
110
|
+
default_factory=lambda: provider_configuration(
|
|
111
|
+
"glm-5.2",
|
|
112
|
+
custom_models=(
|
|
113
|
+
"glm-5.2",
|
|
114
|
+
"glm-5.1",
|
|
115
|
+
"minimax-m2.7",
|
|
116
|
+
"kimi-k2.7",
|
|
117
|
+
"deepseek-v4-pro",
|
|
118
|
+
),
|
|
119
|
+
native_compat=False,
|
|
120
|
+
context_window=200000,
|
|
121
|
+
max_output_tokens=8192,
|
|
122
|
+
context_reserve_tokens=4096,
|
|
123
|
+
request_timeout_ms=300000,
|
|
124
|
+
stream_enabled=True,
|
|
125
|
+
stream_word_chunking=False,
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
require_api_key: bool = True
|
|
129
|
+
include_x_api_key: bool = False
|
|
130
|
+
api_key_display_name_value: str = "CodeBuddy CN"
|
|
131
|
+
api_key_launch_error_value: str = (
|
|
132
|
+
"Launch blocked: CodeBuddy CN requires an API key or access token."
|
|
133
|
+
)
|
|
134
|
+
capabilities_value: ProviderCapabilities = field(
|
|
135
|
+
default_factory=lambda: ProviderCapabilities(
|
|
136
|
+
upstream_protocol="openai_chat",
|
|
137
|
+
requires_api_key=True,
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
request_policy_value: ProviderRequestPolicy = field(
|
|
141
|
+
default_factory=lambda: ProviderRequestPolicy(
|
|
142
|
+
chat_path="/chat/completions",
|
|
143
|
+
models_path="/models",
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
model_catalog_policy_value: ProviderModelCatalogPolicy = field(
|
|
147
|
+
default_factory=lambda: ProviderModelCatalogPolicy(
|
|
148
|
+
kind="openai",
|
|
149
|
+
fallback_models=(
|
|
150
|
+
"glm-5.2",
|
|
151
|
+
"glm-5.1",
|
|
152
|
+
"minimax-m2.7",
|
|
153
|
+
"kimi-k2.7",
|
|
154
|
+
"deepseek-v4-pro",
|
|
155
|
+
),
|
|
156
|
+
allow_configured_fallback=True,
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def build_headers(
|
|
161
|
+
self,
|
|
162
|
+
config: ProviderConfig,
|
|
163
|
+
api_key: str | None,
|
|
164
|
+
) -> Mapping[str, str]:
|
|
165
|
+
headers = dict(super().build_headers(config, api_key))
|
|
166
|
+
headers.update(
|
|
167
|
+
{
|
|
168
|
+
"User-Agent": "Ciel-Runtime",
|
|
169
|
+
"X-Product": "SaaS",
|
|
170
|
+
"X-IDE-Type": "CLI",
|
|
171
|
+
"X-IDE-Name": "CLI",
|
|
172
|
+
"x-requested-with": "XMLHttpRequest",
|
|
173
|
+
"x-codebuddy-request": "1",
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
return headers
|
|
177
|
+
|
|
178
|
+
def build_model_headers(
|
|
179
|
+
self,
|
|
180
|
+
config: ProviderConfig,
|
|
181
|
+
api_key: str | None,
|
|
182
|
+
) -> Mapping[str, str]:
|
|
183
|
+
return self.build_headers(config, api_key)
|
|
184
|
+
|
|
185
|
+
def router_native_anthropic_enabled(
|
|
186
|
+
self,
|
|
187
|
+
config: ProviderConfig,
|
|
188
|
+
model: str | None = None,
|
|
189
|
+
) -> bool:
|
|
190
|
+
del config, model
|
|
191
|
+
return False
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
__all__ = ["AzureOpenAIProviderAdapter", "CodeBuddyCnProviderAdapter"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Provider-owned endpoint and catalog constants."""
|
|
2
|
+
|
|
3
|
+
from .catalog import CATALOG_PROVIDER_BASE_URLS
|
|
4
|
+
from .anthropic_catalog import ANTHROPIC_CATALOG_PROVIDER_BASE_URLS
|
|
5
|
+
|
|
6
|
+
PROVIDER_DEFAULT_BASE_URLS: dict[str, str] = {
|
|
7
|
+
"anthropic": "https://api.anthropic.com",
|
|
8
|
+
"agy": "https://antigravity.google",
|
|
9
|
+
"codex": "https://api.openai.com",
|
|
10
|
+
"ollama": "http://127.0.0.1:11434",
|
|
11
|
+
"ollama-cloud": "https://ollama.com",
|
|
12
|
+
"deepseek": "https://api.deepseek.com/anthropic",
|
|
13
|
+
"opencode": "https://opencode.ai/zen",
|
|
14
|
+
"opencode-go": "https://opencode.ai/zen/go",
|
|
15
|
+
"kimi": "https://api.kimi.com/coding",
|
|
16
|
+
"zai": "https://api.z.ai/api/anthropic",
|
|
17
|
+
"vllm": "http://127.0.0.1:8000",
|
|
18
|
+
"lm-studio": "http://127.0.0.1:1234/v1",
|
|
19
|
+
"nvidia-hosted": "https://integrate.api.nvidia.com/v1",
|
|
20
|
+
"self-hosted-nim": "http://127.0.0.1:8000",
|
|
21
|
+
"openrouter": "https://openrouter.ai/api/v1",
|
|
22
|
+
"fireworks": "https://api.fireworks.ai/inference",
|
|
23
|
+
"meta": "https://api.meta.ai/v1",
|
|
24
|
+
}
|
|
25
|
+
PROVIDER_DEFAULT_BASE_URLS.update(CATALOG_PROVIDER_BASE_URLS)
|
|
26
|
+
PROVIDER_DEFAULT_BASE_URLS.update(ANTHROPIC_CATALOG_PROVIDER_BASE_URLS)
|
|
27
|
+
|
|
28
|
+
DEFAULT_REQUEST_TIMEOUT_MS = 300000
|
|
29
|
+
OPENCODE_PROVIDER_NAMES = ("opencode", "opencode-go")
|
|
30
|
+
|
|
31
|
+
ZAI_MODEL_FALLBACK_IDS: tuple[str, ...] = (
|
|
32
|
+
"glm-5.2[1m]",
|
|
33
|
+
"glm-5.2",
|
|
34
|
+
"glm-5.1",
|
|
35
|
+
"glm-5",
|
|
36
|
+
"glm-5-turbo",
|
|
37
|
+
"glm-4.7",
|
|
38
|
+
"glm-4.7-flashx",
|
|
39
|
+
"glm-4.7-flash",
|
|
40
|
+
"glm-4.6",
|
|
41
|
+
"glm-4.5",
|
|
42
|
+
"glm-4.5-x",
|
|
43
|
+
"glm-4.5-airx",
|
|
44
|
+
"glm-4.5-air",
|
|
45
|
+
"glm-4.5-flash",
|
|
46
|
+
"glm-4-32b-0414-128k",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"DEFAULT_REQUEST_TIMEOUT_MS",
|
|
51
|
+
"OPENCODE_PROVIDER_NAMES",
|
|
52
|
+
"PROVIDER_DEFAULT_BASE_URLS",
|
|
53
|
+
"ZAI_MODEL_FALLBACK_IDS",
|
|
54
|
+
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""DeepSeek provider adapter."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
from ..architecture import (
|
|
6
|
+
ProviderCapabilities,
|
|
7
|
+
ProviderConfig,
|
|
8
|
+
ProviderContextPolicy,
|
|
9
|
+
ProviderModelCatalogPolicy,
|
|
10
|
+
ProviderOptionPresentationPolicy,
|
|
11
|
+
ProviderRequestPolicy,
|
|
12
|
+
ProviderStatusPolicy,
|
|
13
|
+
)
|
|
14
|
+
from .base import HttpBearerProviderAdapter, provider_configuration
|
|
15
|
+
from .constants import DEFAULT_REQUEST_TIMEOUT_MS, PROVIDER_DEFAULT_BASE_URLS
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class DeepSeekProviderAdapter(HttpBearerProviderAdapter):
|
|
20
|
+
name: str = "deepseek"
|
|
21
|
+
base_url: str = PROVIDER_DEFAULT_BASE_URLS["deepseek"]
|
|
22
|
+
configuration_defaults_value: dict = field(
|
|
23
|
+
default_factory=lambda: provider_configuration(
|
|
24
|
+
"deepseek-v4-pro[1m]",
|
|
25
|
+
custom_models=("deepseek-v4-pro[1m]", "deepseek-v4-flash"),
|
|
26
|
+
native_compat=True,
|
|
27
|
+
context_window=1048576,
|
|
28
|
+
max_output_tokens=8192,
|
|
29
|
+
context_reserve_tokens=8192,
|
|
30
|
+
request_timeout_ms=DEFAULT_REQUEST_TIMEOUT_MS,
|
|
31
|
+
stream_enabled=True,
|
|
32
|
+
stream_word_chunking=False,
|
|
33
|
+
effort_level="max",
|
|
34
|
+
haiku_model="deepseek-v4-flash",
|
|
35
|
+
subagent_model="deepseek-v4-flash",
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
send_placeholder_key: bool = True
|
|
39
|
+
api_key_display_name_value: str = "DeepSeek"
|
|
40
|
+
api_key_launch_error_value: str = (
|
|
41
|
+
"Launch blocked: DeepSeek.com requires a DeepSeek API key."
|
|
42
|
+
)
|
|
43
|
+
capabilities_value: ProviderCapabilities = field(
|
|
44
|
+
default_factory=lambda: ProviderCapabilities(
|
|
45
|
+
upstream_protocol="anthropic_messages",
|
|
46
|
+
supports_thinking=True,
|
|
47
|
+
requires_api_key=True,
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
request_policy_value: ProviderRequestPolicy = field(
|
|
51
|
+
default_factory=lambda: ProviderRequestPolicy(
|
|
52
|
+
chat_path="/v1/messages", models_path="/v1/models"
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
model_catalog_policy_value: ProviderModelCatalogPolicy = field(
|
|
56
|
+
default_factory=lambda: ProviderModelCatalogPolicy(
|
|
57
|
+
kind="configured",
|
|
58
|
+
fallback_models=("deepseek-v4-pro[1m]", "deepseek-v4-flash"),
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def advisor_model_badge(self, config: ProviderConfig, model: str) -> str:
|
|
63
|
+
del config
|
|
64
|
+
return "recommended for long context" if model == "deepseek-v4-pro" else ""
|
|
65
|
+
|
|
66
|
+
def normalize_model_id(self, model_id: str) -> str:
|
|
67
|
+
return str(model_id or "").strip()
|
|
68
|
+
|
|
69
|
+
def context_policy(self, config: ProviderConfig) -> ProviderContextPolicy:
|
|
70
|
+
del config
|
|
71
|
+
return ProviderContextPolicy(
|
|
72
|
+
capacity_strategy="configured_first",
|
|
73
|
+
settings_strategy="standard",
|
|
74
|
+
hosted_timeout=True,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def router_native_anthropic_enabled(
|
|
78
|
+
self, config: ProviderConfig, model: str | None = None
|
|
79
|
+
) -> bool:
|
|
80
|
+
del model
|
|
81
|
+
return bool(config.options.get("native_compat", True))
|
|
82
|
+
|
|
83
|
+
def option_presentation_policy(
|
|
84
|
+
self, config: ProviderConfig
|
|
85
|
+
) -> ProviderOptionPresentationPolicy:
|
|
86
|
+
del config
|
|
87
|
+
return ProviderOptionPresentationPolicy(
|
|
88
|
+
show_native=True,
|
|
89
|
+
show_tool_choice=True,
|
|
90
|
+
show_stream=True,
|
|
91
|
+
show_rate_limit_controls=True,
|
|
92
|
+
show_sampling_controls=True,
|
|
93
|
+
show_ip_family_control=True,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def status_policy(self, config: ProviderConfig) -> ProviderStatusPolicy:
|
|
97
|
+
del config
|
|
98
|
+
return ProviderStatusPolicy(
|
|
99
|
+
kind="configured",
|
|
100
|
+
configured_description="DeepSeek Anthropic API configured",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
def supports_tool_choice(
|
|
104
|
+
self, config: ProviderConfig, model: str | None = None
|
|
105
|
+
) -> bool:
|
|
106
|
+
configured = config.options.get("supports_tool_choice")
|
|
107
|
+
if configured is not None:
|
|
108
|
+
return bool(configured)
|
|
109
|
+
return (
|
|
110
|
+
"deepseek-v4"
|
|
111
|
+
not in str(model or config.model or "").split("[", 1)[0].lower()
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
__all__ = ["DeepSeekProviderAdapter"]
|