Merge pull request #4400 from continuedev/dallin/can-parse

canParse URL for tools
This commit is contained in:
Nate Sesti 2025-02-27 21:44:09 -08:00 • committed by GitHub
commit c8cb183f66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 16 deletions

View file

@ -1,5 +1,6 @@
import { ContextItem, Tool, ToolExtras } from "..";
import { MCPManagerSingleton } from "../context/mcp";
import { canParseUrl } from "../util/url";
import { BuiltInToolNames } from "./builtIn";
import { createNewFileImpl } from "./implementations/createNewFile";
@ -55,9 +56,8 @@ async function callToolFromUri(
args: any,
extras: ToolExtras,
): Promise<ContextItem[]> {
// @ts-ignore
const canParse = URL.canParse(uri);
if (!canParse) {
const parseable = canParseUrl(uri);
if (!parseable) {
throw new Error(`Invalid URI: ${uri}`);
}
const parsedUri = new URL(uri);

11
core/util/url.ts Normal file
View file

@ -0,0 +1,11 @@
export function canParseUrl(url: string): boolean {
if ((URL as any)?.canParse) {
return (URL as any).canParse(url);
}
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}

View file

@ -5,6 +5,7 @@ import { EXTENSION_NAME } from "core/control-plane/env";
import { getConfigJsonPathForRemote } from "core/util/paths";
import * as vscode from "vscode";
import { canParseUrl } from "core/util/url";
import { CONTINUE_WORKSPACE_KEY } from "../util/workspaceConfig";
export class RemoteConfigSync {
@ -66,18 +67,6 @@ export class RemoteConfigSync {
};
}
private canParse(url: string): boolean {
if ((URL as any).canParse) {
return (URL as any).canParse(url);
}
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}
async setup() {
if (
this.userToken === null ||
@ -86,7 +75,7 @@ export class RemoteConfigSync {
) {
return;
}
if (!this.canParse(this.remoteConfigServerUrl)) {
if (!canParseUrl(this.remoteConfigServerUrl)) {
vscode.window.showErrorMessage(
"The value set for 'remoteConfigServerUrl' is not valid: ",
this.remoteConfigServerUrl,