diff --git a/.changeset/spicy-pants-wait.md b/.changeset/spicy-pants-wait.md new file mode 100644 index 00000000..7e7466cb --- /dev/null +++ b/.changeset/spicy-pants-wait.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +fix crashing bug when custom url was incorrect diff --git a/src/core/controller/models/refreshRequestyModels.ts b/src/core/controller/models/refreshRequestyModels.ts index 8b41b4fc..6a810011 100644 --- a/src/core/controller/models/refreshRequestyModels.ts +++ b/src/core/controller/models/refreshRequestyModels.ts @@ -24,7 +24,11 @@ export async function refreshRequestyModels(controller: Controller, _: EmptyRequ const baseUrl = controller.stateManager.getGlobalSettingsKey("requestyBaseUrl") const resolvedUrl = toRequestyServiceUrl(baseUrl) - const url = new URL(`${resolvedUrl.pathname}/models`, resolvedUrl).toString() + const url = resolvedUrl != null ? new URL(`${resolvedUrl.pathname}/models`, resolvedUrl).toString() : undefined + + if (url == null) { + throw new Error("URL is not valid.") + } const headers = { Authorization: `Bearer ${apiKey}`, diff --git a/src/shared/providers/requesty.ts b/src/shared/providers/requesty.ts index 71bfab9c..1cbed9a9 100644 --- a/src/shared/providers/requesty.ts +++ b/src/shared/providers/requesty.ts @@ -10,12 +10,16 @@ const replaceCname = (baseUrl: string, type: URLType): string => { } } -export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): URL => { +export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): URL | undefined => { const url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service) - return new URL(url) + try { + return new URL(url) + } catch (e) { + return undefined + } } -export const toRequestyServiceStringUrl = (baseUrl?: string, service: URLType = "router"): string => { - return toRequestyServiceUrl(baseUrl, service).toString() +export const toRequestyServiceStringUrl = (baseUrl?: string, service: URLType = "router"): string | undefined => { + return toRequestyServiceUrl(baseUrl, service)?.toString() } diff --git a/webview-ui/src/components/settings/RequestyModelPicker.tsx b/webview-ui/src/components/settings/RequestyModelPicker.tsx index 677cd6b8..07a90faa 100644 --- a/webview-ui/src/components/settings/RequestyModelPicker.tsx +++ b/webview-ui/src/components/settings/RequestyModelPicker.tsx @@ -35,7 +35,7 @@ const RequestyModelPicker: React.FC = ({ isPopup, base const dropdownListRef = useRef(null) const resolvedUrl = toRequestyServiceUrl(baseUrl) - const requestyModelListUrl = new URL("models", resolvedUrl) + const requestyModelListUrl = resolvedUrl != null ? new URL("models", resolvedUrl) : undefined const handleModelChange = (newModelId: string) => { // could be setting invalid model id/undefined info but validation will catch it @@ -261,7 +261,7 @@ const RequestyModelPicker: React.FC = ({ isPopup, base }}> <> The extension automatically fetches the latest list of models available on{" "} - + Requesty. If you're unsure which model to choose, Cline works best with{" "} diff --git a/webview-ui/src/components/settings/providers/RequestyProvider.tsx b/webview-ui/src/components/settings/providers/RequestyProvider.tsx index 340337a3..4ec4c112 100644 --- a/webview-ui/src/components/settings/providers/RequestyProvider.tsx +++ b/webview-ui/src/components/settings/providers/RequestyProvider.tsx @@ -27,7 +27,7 @@ export const RequestyProvider = ({ showModelOptions, isPopup, currentMode }: Req const [requestyEndpointSelected, setRequestyEndpointSelected] = useState(!!apiConfiguration?.requestyBaseUrl) const resolvedUrl = toRequestyServiceUrl(apiConfiguration?.requestyBaseUrl, "app") - const apiKeyUrl = new URL("api-keys", resolvedUrl).toString() + const apiKeyUrl = resolvedUrl != null ? new URL("api-keys", resolvedUrl).toString() : undefined return (