messaging

This commit is contained in:
Dallin Romney 2024-12-20 16:46:19 -08:00
parent 82fd94d6b1
commit 9c1220228b
4 changed files with 47 additions and 34 deletions

View file

@ -193,8 +193,15 @@ export default class DocsService {
this.docsIndexingQueue.delete(startUrl);
}
isAborted(startUrl: string) {
return this.statuses.get(startUrl)?.status === "aborted";
shouldCancel(startUrl: string) {
const isAborted = this.statuses.get(startUrl)?.status === "aborted";
if (isAborted) {
return true;
}
if (this.config.disableIndexing) {
this.abort(startUrl);
return true;
}
}
// NOTE Pausing not supported for docs yet
@ -421,7 +428,7 @@ export default class DocsService {
estimatedProgress += 1 / 2 ** (processedPages + 1);
// NOTE - during "indexing" phase, check if aborted before each status update
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({
@ -459,7 +466,7 @@ export default class DocsService {
for (let i = 0; i < articles.length; i++) {
const article = articles[i];
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({
@ -496,7 +503,7 @@ export default class DocsService {
`No embeddings were created for site: ${siteIndexingConfig.startUrl}\n Num chunks: ${chunks.length}`,
);
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({
@ -514,7 +521,7 @@ export default class DocsService {
// Add docs to databases
console.log(`Adding ${embeddings.length} embeddings to db`);
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({
@ -532,7 +539,7 @@ export default class DocsService {
const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl));
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({
@ -551,7 +558,7 @@ export default class DocsService {
this.docsIndexingQueue.delete(startUrl);
if (this.isAborted(startUrl)) {
if (this.shouldCancel(startUrl)) {
return;
}
this.handleStatusUpdate({

View file

@ -28,6 +28,7 @@ const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
};
function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
const config = useAppSelector((store) => store.config.config);
const ideMessenger = useContext(IdeMessengerContext);
const dispatch = useAppDispatch();
@ -146,28 +147,30 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
<div className="flex flex-row items-center justify-between gap-4">
<span
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 underline`}
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 ${config.disableIndexing ? "" : "underline"}`}
onClick={
{
complete: reIndex,
indexing: abort,
failed: reIndex,
aborted: reIndex,
paused: () => {},
pending: () => {},
}[status?.status]
config.disableIndexing
? undefined
: {
complete: reIndex,
indexing: abort,
failed: reIndex,
aborted: reIndex,
paused: () => {},
pending: () => {},
}[status?.status]
}
>
{
{
complete: "Click to re-index",
indexing: "Cancel indexing",
failed: "Click to retry",
aborted: "Click to index",
paused: "",
pending: "",
}[status?.status]
}
{config.disableIndexing
? "Indexing disabled"
: {
complete: "Click to re-index",
indexing: "Cancel indexing",
failed: "Click to retry",
aborted: "Click to index",
paused: "",
pending: "",
}[status?.status]}
</span>
<span className="lines lines-1 text-right text-xs text-stone-500">

View file

@ -41,12 +41,13 @@ function DocsIndexingStatuses() {
) : null}
</div>
<span className="text-xs text-stone-500">
{configDocs.length
? "Manage your documentation sources"
: "No docs yet"}
</span>
<div className="flex max-h-[170px] flex-col gap-1 overflow-x-hidden overflow-y-scroll pr-2">
{!hasDocsProvider && (
{hasDocsProvider ? (
configDocs.length ? (
"Manage your documentation sources"
) : (
"No docs yet"
)
) : (
<div className="flex flex-col gap-1 text-xs">
<div className="flex flex-row gap-1">
<div>
@ -69,6 +70,8 @@ function DocsIndexingStatuses() {
</span>
</div>
)}
</span>
<div className="flex max-h-[170px] flex-col gap-1 overflow-x-hidden overflow-y-scroll pr-2">
<div>
{configDocs.length === 0 && (
<SecondaryButton

View file

@ -14,7 +14,7 @@ const STATUS_TO_SUBTITLE_TEXT: Record<
indexing: "Click to pause",
paused: "Click to resume",
failed: "Click to retry",
disabled: "Click to open config.json and enable indexing (requires reload)",
disabled: "Click to open config",
cancelled: "Click to restart",
};