Skip to content

Commit f2ad4b6

Browse files
committed
Add 'enabled' field validation to endpoint configuration and filter disabled endpoints
1 parent 9197a94 commit f2ad4b6

7 files changed

Lines changed: 86 additions & 18 deletions

File tree

code_assistant_manager/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
import logging
5-
import os
65
import time
76
from pathlib import Path
87
from typing import Any, Dict, List, Optional, Tuple
@@ -475,7 +474,7 @@ def validate_config(self) -> Tuple[bool, List[str]]:
475474
# Return cached result if still valid
476475
if self._is_validation_cache_valid(current_time):
477476
logger.debug("Using cached validation result")
478-
return self._validation_cache
477+
return self._validation_cache # type: ignore
479478

480479
logger.debug("Performing fresh config validation")
481480
errors = []
@@ -592,7 +591,7 @@ def _validate_endpoint(endpoint_name: str, endpoint_config: dict) -> List[str]:
592591
errors.append(f"Invalid model ID in list_of_models for {endpoint_name}: {model}")
593592

594593
# Validate boolean fields
595-
boolean_fields = ["keep_proxy_config", "use_proxy"]
594+
boolean_fields = ["keep_proxy_config", "use_proxy", "enabled"]
596595
for field_name in boolean_fields:
597596
value = endpoint_config.get(field_name, "")
598597
if value and not validate_boolean(value):

code_assistant_manager/endpoints.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ def select_endpoint(
165165
print("Error: No endpoints configured in settings.conf")
166166
return False, None
167167

168+
# Filter out disabled endpoints
169+
enabled_endpoints = []
170+
for ep in endpoints:
171+
ep_config = self.config.get_endpoint_config(ep)
172+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
173+
if enabled:
174+
enabled_endpoints.append(ep)
175+
endpoints = enabled_endpoints
176+
177+
if not endpoints:
178+
print("Error: No enabled endpoints configured in settings.conf")
179+
return False, None
180+
168181
# Filter endpoints by client if specified
169182
if client_name:
170183
filtered = []
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"endpoints": {
3+
"example-openai": {
4+
"endpoint": "https://api.openai.com/v1",
5+
"api_key_env": "OPENAI_API_KEY",
6+
"supported_client": "openai",
7+
"list_models_cmd": "curl -s -H \"Authorization: Bearer $API_KEY\" $endpoint/models | jq -r '.data[].id'",
8+
"list_of_models": ["gpt-4", "gpt-3.5-turbo"],
9+
"keep_proxy_config": false,
10+
"use_proxy": true,
11+
"enabled": true
12+
},
13+
"example-anthropic": {
14+
"endpoint": "https://api.anthropic.com",
15+
"api_key_env": "ANTHROPIC_API_KEY",
16+
"supported_client": "claude",
17+
"list_models_cmd": "curl -s -H \"x-api-key: $API_KEY\" -H \"anthropic-version: 2023-06-01\" $endpoint/v1/messages --data '{\"model\": \"claude-3-haiku-20240307\", \"max_tokens\": 1}' | jq -r '.model // \"claude-3-haiku-20240307\"'",
18+
"list_of_models": ["claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307"],
19+
"keep_proxy_config": false,
20+
"use_proxy": false,
21+
"enabled": true
22+
},
23+
"disabled-example": {
24+
"endpoint": "https://disabled.example.com",
25+
"api_key_env": "DISABLED_API_KEY",
26+
"supported_client": "openai",
27+
"list_models_cmd": "echo 'gpt-4'",
28+
"list_of_models": ["gpt-4"],
29+
"keep_proxy_config": false,
30+
"use_proxy": false,
31+
"enabled": false
32+
}
33+
},
34+
"common": {
35+
"http_proxy": "",
36+
"https_proxy": "",
37+
"cache_ttl_seconds": "3600"
38+
}
39+
}

code_assistant_manager/tools/codex.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ def run(self, args: List[str] = None) -> int:
112112
return 1
113113

114114
endpoints = self.config.get_sections(exclude_common=True)
115-
endpoints = [
116-
ep for ep in endpoints if self.endpoint_manager._is_client_supported(ep, "codex")
117-
]
115+
filtered_endpoints = []
116+
for ep in endpoints:
117+
# Check if endpoint is enabled
118+
ep_config = self.config.get_endpoint_config(ep)
119+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
120+
if enabled and self.endpoint_manager._is_client_supported(ep, "codex"):
121+
filtered_endpoints.append(ep)
122+
endpoints = filtered_endpoints
118123
if not endpoints:
119124
return self._handle_error("No endpoints configured for codex")
120125

code_assistant_manager/tools/continue_tool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ class ContinueTool(CLITool):
1717
def _get_filtered_endpoints(self) -> List[str]:
1818
"""Collect endpoints that support the continue client."""
1919
endpoints = self.config.get_sections(exclude_common=True)
20-
return [
21-
ep
22-
for ep in endpoints
23-
if self.endpoint_manager._is_client_supported(ep, "continue")
24-
]
20+
filtered = []
21+
for ep in endpoints:
22+
# Check if endpoint is enabled
23+
ep_config = self.config.get_endpoint_config(ep)
24+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
25+
if enabled and self.endpoint_manager._is_client_supported(ep, "continue"):
26+
filtered.append(ep)
27+
return filtered
2528

2629
def _process_endpoint(self, endpoint_name: str) -> Optional[List[str]]:
2730
"""Process a single endpoint and return selected models if successful."""

code_assistant_manager/tools/endpoint_display.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def display_tool_endpoints(config_manager: ConfigManager, client_name: str = Non
2323
if client_name:
2424
filtered = []
2525
for ep in endpoints:
26-
if endpoint_manager._is_client_supported(ep, client_name):
26+
# Check if endpoint is enabled
27+
ep_config = config_manager.get_endpoint_config(ep)
28+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
29+
if enabled and endpoint_manager._is_client_supported(ep, client_name):
2730
filtered.append(ep)
2831
endpoints = filtered
2932

@@ -77,7 +80,10 @@ def display_all_tool_endpoints(config_manager: ConfigManager):
7780
# Filter endpoints by client
7881
if tool != "copilot": # Copilot doesn't use endpoint selection
7982
for ep in endpoints:
80-
if endpoint_manager._is_client_supported(ep, tool):
83+
# Check if endpoint is enabled
84+
ep_config = config_manager.get_endpoint_config(ep)
85+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
86+
if enabled and endpoint_manager._is_client_supported(ep, tool):
8187
tool_endpoints.append(ep)
8288

8389
if tool_endpoints:

code_assistant_manager/tools/goose.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,14 @@ def _determine_engine_type(self, endpoint_config: Dict[str, str], endpoint_name:
117117
def _get_filtered_endpoints(self) -> List[str]:
118118
"""Collect endpoints that support the goose client."""
119119
endpoints = self.config.get_sections(exclude_common=True)
120-
return [
121-
ep
122-
for ep in endpoints
123-
if self.endpoint_manager._is_client_supported(ep, "goose")
124-
]
120+
filtered = []
121+
for ep in endpoints:
122+
# Check if endpoint is enabled
123+
ep_config = self.config.get_endpoint_config(ep)
124+
enabled = ep_config.get("enabled", "true").lower() in ("true", "1", "yes")
125+
if enabled and self.endpoint_manager._is_client_supported(ep, "goose"):
126+
filtered.append(ep)
127+
return filtered
125128

126129
def _validate_and_fix_config(self) -> None:
127130
"""Validate that config.yaml references valid custom providers.

0 commit comments

Comments
 (0)