Merge pull request #4400 from continuedev/dallin/can-parse
canParse URL for tools
This commit is contained in:
commit
c8cb183f66
3 changed files with 16 additions and 16 deletions
|
|
@ -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
11
core/util/url.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue