Skip to content

Commit 963a235

Browse files
committed
fix(api parse)从tos中恢复内部错误
1 parent c177d73 commit 963a235

1 file changed

Lines changed: 15 additions & 81 deletions

File tree

server/mcp_server_supabase/src/mcp_server_supabase/platform/aidap_client.py

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
from ..utils import pick_value
1010

1111
logger = logging.getLogger(__name__)
12-
<<<<<<< main
13-
=======
14-
ENDPOINT_SCHEME_FALLBACK = os.getenv("SUPABASE_ENDPOINT_SCHEME", "http").strip().lower() or "http"
15-
>>>>>>> main
1612

1713
try:
1814
import volcenginesdkcore
@@ -72,7 +68,6 @@ def _branch_error_code(self, error_text: str) -> str:
7268
def _pick_value(self, source: Any, *field_names: str) -> Any:
7369
return pick_value(source, *field_names)
7470

75-
<<<<<<< main
7671
def _normalize_port(self, port: Any) -> Optional[int]:
7772
if port is None:
7873
return None
@@ -82,14 +77,6 @@ def _normalize_port(self, port: Any) -> Optional[int]:
8277
logger.warning("Invalid endpoint port from AIDAP: %s", port)
8378
return None
8479

85-
def _normalize_scheme(self, scheme: Any) -> Optional[str]:
86-
if not isinstance(scheme, str):
87-
return None
88-
normalized = scheme.strip().lower()
89-
if normalized in {"http", "https"}:
90-
return normalized
91-
return None
92-
9380
def _scheme_from_port(self, port: Optional[int]) -> str:
9481
return "https" if port == 443 else "http"
9582

@@ -101,15 +88,13 @@ def _host_has_port(self, host: str) -> bool:
10188

10289
def _endpoint_url(self, address: dict[str, Any]) -> str:
10390
domain = address["domain"]
104-
parsed_scheme = None
10591
host = domain.strip().rstrip("/")
10692
if "://" in host:
10793
parsed = urlsplit(host)
108-
parsed_scheme = self._normalize_scheme(parsed.scheme)
10994
host = parsed.netloc or parsed.path
11095

11196
port = self._normalize_port(address.get("port"))
112-
scheme = address.get("scheme") or parsed_scheme or self._scheme_from_port(port)
97+
scheme = self._scheme_from_port(port)
11398
if port is not None and not self._host_has_port(host):
11499
host = f"{host}:{port}"
115100
return f"{scheme}://{host}"
@@ -121,64 +106,27 @@ def _endpoint_address_payload(self, addr: Any) -> Optional[dict[str, Any]]:
121106
return {
122107
"domain": domain,
123108
"port": self._pick_value(addr, "address_port", "AddressPort", "port", "Port"),
124-
"scheme": self._normalize_scheme(
125-
self._pick_value(
126-
addr,
127-
"address_scheme",
128-
"AddressScheme",
129-
"scheme",
130-
"Scheme",
131-
"protocol",
132-
"Protocol",
133-
)
134-
),
135109
"address_type": self._pick_value(addr, "address_type", "AddressType"),
136110
}
137111

138-
def _is_public_address(self, address: dict[str, Any]) -> bool:
112+
def _address_type_priority(self, address: dict[str, Any]) -> int:
139113
address_type = address.get("address_type")
140114
if isinstance(address_type, str) and address_type.lower() == "public":
141-
return True
142-
domain = address["domain"]
143-
return "volces.com" in domain and "ivolces.com" not in domain
144-
=======
145-
def _build_endpoint_from_address(self, address: Any) -> Optional[str]:
146-
domain = self._pick_value(address, "address_domain", "AddressDomain")
147-
if not domain:
148-
return None
149-
150-
raw_port = self._pick_value(address, "address_port", "AddressPort")
151-
try:
152-
port = int(raw_port) if raw_port is not None else None
153-
except (TypeError, ValueError):
154-
port = None
155-
156-
if port == 80:
157-
scheme = "http"
158-
elif port == 443:
159-
scheme = "https"
160-
else:
161-
scheme = ENDPOINT_SCHEME_FALLBACK
115+
return 0
116+
if isinstance(address_type, str) and address_type.lower() == "private":
117+
return 1
118+
return 2
162119

163-
if port is None:
164-
return f"{scheme}://{domain}"
165-
return f"{scheme}://{domain}:{port}"
166-
167-
def _endpoint_priority(self, endpoint: Any, address: Any) -> tuple[int, int, int]:
120+
def _endpoint_priority(self, endpoint: Any, address: dict[str, Any]) -> tuple[int, int, int]:
168121
endpoint_type = str(self._pick_value(endpoint, "endpoint_type", "EndpointType") or "").lower()
169-
address_type = str(self._pick_value(address, "address_type", "AddressType") or "").lower()
170-
domain = str(self._pick_value(address, "address_domain", "AddressDomain") or "").lower()
171-
172-
is_public = address_type == "public" or ("volces.com" in domain and "ivolces.com" not in domain)
173122
is_dashboard = endpoint_type == "dashboard"
174-
has_domain = bool(domain)
123+
has_domain = bool(address.get("domain"))
175124

176125
return (
177-
0 if is_public else 1,
126+
self._address_type_priority(address),
178127
0 if is_dashboard else 1,
179128
0 if has_domain else 1,
180129
)
181-
>>>>>>> main
182130

183131
def _branch_payload(self, branch: Any, fallback_name: Optional[str] = None) -> dict:
184132
parent_branch = self._pick_value(branch, "parent_branch")
@@ -400,35 +348,21 @@ async def get_endpoint(self, workspace_id: str, branch_id: Optional[str] = None)
400348
response = self.client.describe_workspace_endpoint(request)
401349

402350
if hasattr(response, 'endpoints') and response.endpoints:
403-
<<<<<<< main
404-
addresses = []
405-
for endpoint in response.endpoints:
406-
if hasattr(endpoint, 'addresses') and endpoint.addresses:
407-
for addr in endpoint.addresses:
408-
address = self._endpoint_address_payload(addr)
409-
if address:
410-
addresses.append(address)
411-
412-
for address in addresses:
413-
if self._is_public_address(address):
414-
return self._endpoint_url(address)
415-
416-
if addresses:
417-
return self._endpoint_url(addresses[0])
418-
=======
419351
candidates: list[tuple[tuple[int, int, int], str]] = []
420352
for endpoint in response.endpoints:
421353
if hasattr(endpoint, 'addresses') and endpoint.addresses:
422354
for addr in endpoint.addresses:
423-
resolved_endpoint = self._build_endpoint_from_address(addr)
424-
if not resolved_endpoint:
355+
address = self._endpoint_address_payload(addr)
356+
if not address:
425357
continue
426-
candidates.append((self._endpoint_priority(endpoint, addr), resolved_endpoint))
358+
candidates.append((
359+
self._endpoint_priority(endpoint, address),
360+
self._endpoint_url(address),
361+
))
427362

428363
if candidates:
429364
candidates.sort(key=lambda item: item[0])
430365
return candidates[0][1]
431-
>>>>>>> main
432366

433367
return None
434368
except Exception as e:

0 commit comments

Comments
 (0)