feat: ✨ set static urls for contextprovider
This commit is contained in:
parent
fb7d5d9aad
commit
d2b1aedced
2 changed files with 30 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from .util import remove_meilisearch_disallowed_chars
|
||||
from ...core.main import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
|
@ -8,8 +8,24 @@ from ...core.context import ContextProvider
|
|||
class URLContextProvider(ContextProvider):
|
||||
title = "url"
|
||||
|
||||
url: Optional[str] = None
|
||||
display_name: Optional[str] = None
|
||||
URL_CONTEXT_ITEM_ID = "url"
|
||||
|
||||
@property
|
||||
def optional_url_item_id(self) -> str:
|
||||
return remove_meilisearch_disallowed_chars(self.url)
|
||||
|
||||
@property
|
||||
def optional_url_item(self) -> ContextItem:
|
||||
cp = self.BASE_CONTEXT_ITEM.copy()
|
||||
if self.display_name:
|
||||
cp.description.name = self.display_name
|
||||
cp.description.description = f"Contents of {self.url}"
|
||||
cp.description.id.item_id = self.optional_url_item_id
|
||||
|
||||
return cp
|
||||
|
||||
@property
|
||||
def BASE_CONTEXT_ITEM(self):
|
||||
return ContextItem(
|
||||
|
|
@ -33,14 +49,22 @@ class URLContextProvider(ContextProvider):
|
|||
return soup.get_text()
|
||||
|
||||
async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]:
|
||||
return [self.BASE_CONTEXT_ITEM]
|
||||
items = [self.BASE_CONTEXT_ITEM]
|
||||
if self.url:
|
||||
items.append(self.optional_url_item)
|
||||
|
||||
return items
|
||||
|
||||
async def get_item(self, id: ContextItemId, query: str) -> ContextItem:
|
||||
if id.item_id == self.optional_url_item_id:
|
||||
item = self.optional_url_item
|
||||
item.content = self._get_url_text_contents(self.url)
|
||||
return item
|
||||
|
||||
if not id.item_id == self.URL_CONTEXT_ITEM_ID:
|
||||
raise Exception("Invalid item id")
|
||||
|
||||
query = query.lstrip("url ")
|
||||
url = query.strip()
|
||||
url = query.lstrip("url ").strip()
|
||||
content = self._get_url_text_contents(url)
|
||||
|
||||
ctx_item = self.BASE_CONTEXT_ITEM.copy()
|
||||
|
|
@ -48,5 +72,5 @@ class URLContextProvider(ContextProvider):
|
|||
ctx_item.description.name = url.replace(
|
||||
"https://", "").replace("http://", "")
|
||||
ctx_item.description.id.item_id = remove_meilisearch_disallowed_chars(
|
||||
query)
|
||||
url)
|
||||
return ctx_item
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ const BottomMessageDiv = styled.div<{ displayOnBottom: boolean }>`
|
|||
padding: 12px;
|
||||
z-index: 100;
|
||||
box-shadow: 0px 0px 2px 0px ${vscForeground};
|
||||
max-height: 50vh;
|
||||
max-height: 35vh;
|
||||
overflow: scroll;
|
||||
`;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue