|
|
@@ -5,6 +5,7 @@ from types import MappingProxyType
|
|
|
from typing import Literal, TypeAlias
|
|
|
from urllib.parse import urlsplit
|
|
|
|
|
|
+import httpx
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
|
|
|
|
from agent_lab.application.contracts import (
|
|
|
@@ -72,7 +73,6 @@ def _validate_base_url(value: str) -> str:
|
|
|
try:
|
|
|
parsed = urlsplit(value)
|
|
|
hostname = parsed.hostname
|
|
|
- parsed.port
|
|
|
except ValueError as exc:
|
|
|
raise ValueError("base_url must be a valid HTTP(S) URL") from exc
|
|
|
if parsed.scheme not in {"http", "https"} or not parsed.netloc or not hostname:
|
|
|
@@ -83,6 +83,11 @@ def _validate_base_url(value: str) -> str:
|
|
|
raise ValueError("base_url must not contain a query")
|
|
|
if "#" in value:
|
|
|
raise ValueError("base_url must not contain a fragment")
|
|
|
+ try:
|
|
|
+ transport_url = httpx.URL(value)
|
|
|
+ _ = (transport_url.host, transport_url.port, parsed.port)
|
|
|
+ except (httpx.InvalidURL, ValueError) as exc:
|
|
|
+ raise ValueError("base_url must be a valid HTTP(S) URL") from exc
|
|
|
return value
|
|
|
|
|
|
|