Merge pull request #6081 from continuedev/dallin/url-tool

Fetch URL Content Tool
This commit is contained in:
Dallin Romney 2025-06-12 10:51:49 -07:00 • committed by GitHub
commit 154b31ba53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 12 deletions

View file

@ -44,8 +44,8 @@ export const AllMediaTypes = [
2. EXTRACT NEW INFORMATION
New information will be pulled from the internet.
If you do not see a web search tool, let me know.
Fetch information from the internet using the search web and read url tools.
If you do not see either of these tools, stop and let me know.
Retrieve the following sites per these providers, and consider these notes on how to extract the information:
- "gemini": https://ai.google.dev/gemini-api/docs/models - maxCompletionTokens is called "Output token limit", contextLength is called "Input token limit"

View file

@ -11,6 +11,7 @@ export enum BuiltInToolNames {
LSTool = "builtin_ls",
CreateRuleBlock = "builtin_create_rule_block",
RequestRule = "builtin_request_rule",
FetchUrlContent = "builtin_fetch_url_content",
// excluded from allTools for now
ViewRepoMap = "builtin_view_repo_map",

View file

@ -5,6 +5,7 @@ import { BuiltInToolNames } from "./builtIn";
import { createNewFileImpl } from "./implementations/createNewFile";
import { createRuleBlockImpl } from "./implementations/createRuleBlock";
import { fetchUrlContentImpl } from "./implementations/fetchUrlContent";
import { fileGlobSearchImpl } from "./implementations/globSearch";
import { grepSearchImpl } from "./implementations/grepSearch";
import { lsToolImpl } from "./implementations/lsTool";
@ -151,6 +152,8 @@ async function callBuiltInTool(
return await runTerminalCommandImpl(args, extras);
case BuiltInToolNames.SearchWeb:
return await searchWebImpl(args, extras);
case BuiltInToolNames.FetchUrlContent:
return await fetchUrlContentImpl(args, extras);
case BuiltInToolNames.ViewDiff:
return await viewDiffImpl(args, extras);
case BuiltInToolNames.LSTool:

View file

@ -14,6 +14,7 @@ export const editFileTool: Tool = {
hasAlready: "edited {{{ filepath }}}",
group: BUILT_IN_GROUP_NAME,
readonly: false,
isInstant: false,
function: {
name: BuiltInToolNames.EditExistingFile,
description:

View file

@ -0,0 +1,28 @@
import { Tool } from "../..";
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
export const fetchUrlContentTool: Tool = {
type: "function",
displayTitle: "Read URL",
wouldLikeTo: "fetch {{{ url }}}",
isCurrently: "fetching {{{ url }}}",
hasAlready: "viewed {{{ url }}}",
readonly: true,
isInstant: true,
group: BUILT_IN_GROUP_NAME,
function: {
name: BuiltInToolNames.FetchUrlContent,
description:
"Can be used to view the contents of a website using a URL. Do NOT use this for files.",
parameters: {
type: "object",
required: ["url"],
properties: {
url: {
type: "string",
description: "The URL to read",
},
},
},
},
};

View file

@ -0,0 +1,6 @@
import { ToolImpl } from ".";
import { getUrlContextItems } from "../../context/providers/URLContextProvider";
export const fetchUrlContentImpl: ToolImpl = async (args, extras) => {
return getUrlContextItems(args.url, extras.fetch);
};

View file

@ -2,6 +2,7 @@ import { ConfigDependentToolParams, Tool } from "..";
import { createNewFileTool } from "./definitions/createNewFile";
import { createRuleBlock } from "./definitions/createRuleBlock";
import { editFileTool } from "./definitions/editFile";
import { fetchUrlContentTool } from "./definitions/fetchUrlContent";
import { globSearchTool } from "./definitions/globSearch";
import { grepSearchTool } from "./definitions/grepSearch";
import { lsTool } from "./definitions/lsTool";
@ -24,6 +25,7 @@ export const baseToolDefinitions = [
readCurrentlyOpenFileTool,
lsTool,
createRuleBlock,
fetchUrlContentTool,
// replacing with ls tool for now
// viewSubdirectoryTool,
// viewRepoMapTool,

View file

@ -33,27 +33,21 @@ export function ContextItemsPeekItem({
function openContextItem() {
const { uri, name, content } = contextItem;
if (isUrl) {
if (uri?.value) {
ideMessenger.post("openUrl", uri.value);
} else {
console.error("Couldn't open url", uri);
}
} else if (uri) {
if (uri && uri?.type === "file") {
const isRangeInFile = name.includes(" (") && name.endsWith(")");
if (isRangeInFile) {
const rif = ctxItemToRifWithContents(contextItem, true);
ideMessenger.ide.showLines(
void ideMessenger.ide.showLines(
rif.filepath,
rif.range.start.line,
rif.range.end.line,
);
} else {
ideMessenger.ide.openFile(uri.value);
void ideMessenger.ide.openFile(uri.value);
}
} else {
ideMessenger.ide.showVirtualFile(name, content);
void ideMessenger.ide.showVirtualFile(name, content);
}
}
@ -136,6 +130,18 @@ export function ContextItemsPeekItem({
</div>
<div
className={`min-w-0 flex-1 overflow-hidden truncate whitespace-nowrap text-xs text-gray-400 ${isUrl ? "hover:underline" : ""}`}
onClick={
isUrl
? (e) => {
if (contextItem.uri?.value) {
e.stopPropagation();
ideMessenger.post("openUrl", contextItem.uri.value);
} else {
console.error("Couldn't open url", contextItem.uri);
}
}
: undefined
}
>
{contextItem.uri?.type === "file"
? getUriPathBasename(contextItem.description)

View file

@ -41,6 +41,7 @@ const toolCallIcons: Record<string, ComponentType> = {
[BuiltInToolNames.LSTool]: FolderIcon,
[BuiltInToolNames.ReadCurrentlyOpenFile]: DocumentTextIcon,
[BuiltInToolNames.ReadFile]: DocumentIcon,
[BuiltInToolNames.FetchUrlContent]: GlobeAltIcon,
[BuiltInToolNames.SearchWeb]: GlobeAltIcon,
[BuiltInToolNames.ViewDiff]: CodeBracketIcon,
[BuiltInToolNames.ViewRepoMap]: MapIcon,

View file

@ -53,6 +53,7 @@ export const uiSlice = createSlice({
[BuiltInToolNames.GrepSearch]: "allowedWithoutPermission",
[BuiltInToolNames.FileGlobSearch]: "allowedWithoutPermission",
[BuiltInToolNames.SearchWeb]: "allowedWithoutPermission",
[BuiltInToolNames.FetchUrlContent]: "allowedWithPermission",
[BuiltInToolNames.ViewDiff]: "allowedWithoutPermission",
[BuiltInToolNames.LSTool]: "allowedWithoutPermission",
[BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission",