continue-custom/core/context/providers/URLContextProvider.ts
Nate Sesti e1ed7ed0a2 ✨ config.ts
2023-12-14 12:47:01 -08:00

42 lines
1,005 B
TypeScript

import { BaseContextProvider } from "..";
import { ContextItem, ContextProviderDescription } from "../..";
class URLContextProvider extends BaseContextProvider {
static description: ContextProviderDescription = {
title: "url",
displayTitle: "URL",
description: "Attach the contents of a web page",
dynamic: true,
requiresQuery: true,
};
async getContextItems(query: string): Promise<ContextItem[]> {
let url = query.trim();
if (!url.startsWith("http")) {
url = "https://" + url;
}
const response = await fetch(url);
const html = await response.text();
const content = html;
const title = url
.replace("https://", "")
.replace("http://", "")
.replace("www.", "");
return [
{
content,
name: title,
description: title,
id: {
providerTitle: "url",
itemId: query,
},
},
];
}
async load(): Promise<void> {}
}
export default URLContextProvider;