chat error popup v1: in chat
This commit is contained in:
parent
04df03d86f
commit
30584e9f6f
10 changed files with 206 additions and 31 deletions
|
|
@ -35,7 +35,7 @@ import { Telemetry } from "./util/posthog";
|
|||
import { getSymbolsForManyFiles } from "./util/treeSitter";
|
||||
import { TTS } from "./util/tts";
|
||||
|
||||
import type { ContextItemId, IDE, IndexingProgressUpdate } from ".";
|
||||
import { type ContextItemId, type IDE, type IndexingProgressUpdate } from ".";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ export class Core {
|
|||
data: FromCoreProtocol[T][0],
|
||||
messageId?: string,
|
||||
): string {
|
||||
return this.messenger.send(messageType, data);
|
||||
return this.messenger.send(messageType, data, messageId);
|
||||
}
|
||||
|
||||
// TODO: It shouldn't actually need an IDE type, because this can happen
|
||||
|
|
@ -182,6 +182,8 @@ export class Core {
|
|||
|
||||
const on = this.messenger.on.bind(this.messenger);
|
||||
|
||||
// Note, VsCode's in-process messenger doesn't do anything with this
|
||||
// It will only show for jetbrains
|
||||
this.messenger.onError((err) => {
|
||||
console.error(err);
|
||||
void Telemetry.capture("core_messenger_error", {
|
||||
|
|
|
|||
|
|
@ -1 +1,5 @@
|
|||
export const NEW_SESSION_TITLE = "New Session";
|
||||
|
||||
export const GITHUB_LINK =
|
||||
"https://github.com/continuedev/continue/issues/new/choose";
|
||||
export const DISCORD_LINK = "https://discord.com/invite/EfJEfdFnDQ";
|
||||
|
|
|
|||
|
|
@ -415,11 +415,11 @@ export class VsCodeMessenger {
|
|||
/** PASS THROUGH FROM WEBVIEW TO CORE AND BACK **/
|
||||
WEBVIEW_TO_CORE_PASS_THROUGH.forEach((messageType) => {
|
||||
this.onWebview(messageType, async (msg) => {
|
||||
return (await this.inProcessMessenger.externalRequest(
|
||||
return await this.inProcessMessenger.externalRequest(
|
||||
messageType,
|
||||
msg.data,
|
||||
msg.messageId,
|
||||
)) as TODO;
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -103,16 +103,21 @@ export class VsCodeWebviewProtocol
|
|||
respond({ done: true, content: response || {}, status: "success" });
|
||||
}
|
||||
} catch (e: any) {
|
||||
respond({ done: true, error: e, status: "error" });
|
||||
respond({ done: true, error: e.message, status: "error" });
|
||||
|
||||
const stringified = JSON.stringify({ msg }, null, 2);
|
||||
console.error(
|
||||
`Error handling webview message: ${JSON.stringify(
|
||||
{ msg },
|
||||
null,
|
||||
2,
|
||||
)}\n\n${e}`,
|
||||
`Error handling webview message: ${stringified}\n\n${e}`,
|
||||
);
|
||||
|
||||
if (
|
||||
stringified.includes("llm/streamChat") ||
|
||||
stringified.includes("chatDescriber/describe")
|
||||
) {
|
||||
// handle these errors in the GUI
|
||||
return;
|
||||
}
|
||||
|
||||
let message = e.message;
|
||||
if (e.cause) {
|
||||
if (e.cause.name === "ConnectTimeoutError") {
|
||||
|
|
|
|||
|
|
@ -76,8 +76,7 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
);
|
||||
throw new Error("postIntellijMessage is undefined");
|
||||
}
|
||||
messageId = messageId ?? uuidv4();
|
||||
window.postIntellijMessage?.(messageType, data, messageId);
|
||||
window.postIntellijMessage?.(messageType, data, messageId ?? uuidv4());
|
||||
return;
|
||||
} else {
|
||||
console.log(
|
||||
|
|
@ -235,6 +234,7 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
}
|
||||
|
||||
if (next.value.error) {
|
||||
console.log("FROM IDEMESS", next.value);
|
||||
throw new Error(next.value.error);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ import { useContext, useEffect, useState } from "react";
|
|||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { Button, SecondaryButton } from "../components";
|
||||
import { ArrowPathIcon, FlagIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
const GITHUB_LINK = "https://github.com/continuedev/continue/issues/new/choose";
|
||||
const DISCORD_LINK = "https://discord.com/invite/EfJEfdFnDQ";
|
||||
import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants";
|
||||
|
||||
const ErrorPage: React.FC = () => {
|
||||
const error: any = useRouteError();
|
||||
|
|
|
|||
|
|
@ -454,7 +454,11 @@ export function Chat() {
|
|||
trackVisibility={isStreaming}
|
||||
/>
|
||||
</StepsDiv>
|
||||
|
||||
{history.length > 0 ? (
|
||||
<div className="flex flex-col">
|
||||
<StreamError slideDirection="up" />
|
||||
</div>
|
||||
) : null}
|
||||
<div className={`relative`}>
|
||||
<div className="absolute -top-8 right-2 z-30">
|
||||
{ttsActive && (
|
||||
|
|
@ -535,8 +539,12 @@ export function Chat() {
|
|||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{history.length === 0 && (
|
||||
<>
|
||||
<div className="flex flex-col">
|
||||
<StreamError slideDirection="down" />
|
||||
</div>
|
||||
{onboardingCard.show && (
|
||||
<div className="mx-2 mt-10">
|
||||
<OnboardingCard activeTab={onboardingCard.activeTab} />
|
||||
|
|
@ -552,9 +560,7 @@ export function Chat() {
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<StreamError />
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`${history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,154 @@
|
|||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { Cog8ToothIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { setStreamError } from "../../redux/slices/sessionSlice";
|
||||
import { useContext, useEffect, useMemo } from "react";
|
||||
import { GithubIcon } from "../../components/svg/GithubIcon";
|
||||
import { DiscordIcon } from "../../components/svg/DiscordIcon";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants";
|
||||
import {
|
||||
selectDefaultModel,
|
||||
setDefaultModel,
|
||||
} from "../../redux/slices/configSlice";
|
||||
import { ToolTip } from "../../components/gui/Tooltip";
|
||||
import { providers } from "../AddNewModel/configs/providers";
|
||||
import { Button, SecondaryButton } from "../../components";
|
||||
|
||||
const StreamError = () => {
|
||||
interface StreamErrorProps {
|
||||
slideDirection: "up" | "down";
|
||||
}
|
||||
const StreamError = ({ slideDirection }: StreamErrorProps) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const streamError = useAppSelector((state) => state.session.streamError);
|
||||
const selectedModel = useAppSelector(selectDefaultModel);
|
||||
|
||||
if (streamError) {
|
||||
return null;
|
||||
}
|
||||
return <div className="flex flex-col px-3">Hello</div>;
|
||||
useEffect(() => {
|
||||
dispatch(setStreamError(undefined));
|
||||
}, [selectedModel]);
|
||||
|
||||
const errorContent = useMemo(() => {
|
||||
// TODO use updated LLM-INFO strategy to get this info
|
||||
|
||||
let modelTitle = "Chat model";
|
||||
let providerName = "the model provider";
|
||||
let apiKeyUrl: string | undefined = undefined;
|
||||
if (selectedModel) {
|
||||
modelTitle = selectedModel.title;
|
||||
providerName = selectedModel.provider;
|
||||
|
||||
// If there's a matching provider from add model form provider info
|
||||
// We can get more info
|
||||
const foundProvider = Object.values(providers).find(
|
||||
(p) => p?.provider === selectedModel.provider,
|
||||
);
|
||||
if (foundProvider) {
|
||||
providerName = foundProvider.title;
|
||||
if (foundProvider.apiKeyUrl) {
|
||||
apiKeyUrl = foundProvider.apiKeyUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return streamError
|
||||
? ({
|
||||
429: (
|
||||
<div className="flex flex-col gap-2">
|
||||
<span>
|
||||
{`${modelTitle} has been rate limited
|
||||
by ${providerName}.`}
|
||||
</span>
|
||||
{apiKeyUrl ? (
|
||||
<Button
|
||||
className="cursor-pointer hover:underline"
|
||||
onClick={() => {
|
||||
ideMessenger.post("openUrl", apiKeyUrl!);
|
||||
}}
|
||||
>
|
||||
Check your keys
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
}[streamError.statusCode] ?? (
|
||||
<span>There was an error completing"</span>
|
||||
))
|
||||
: null;
|
||||
}, [streamError, selectedModel]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col overflow-hidden">
|
||||
<div
|
||||
className={`flex flex-col gap-1 overflow-hidden px-3 pb-2 pt-1 transition-all ${!!streamError ? "" : slideDirection === "up" ? "translate-y-full" : ""}`}
|
||||
style={
|
||||
{
|
||||
// height: streamError ? 100 : 0,
|
||||
}
|
||||
}
|
||||
>
|
||||
<div className="relative flex flex-row justify-between">
|
||||
<div className="text-lg text-red-500">Chat Error</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-80"
|
||||
onClick={() => {
|
||||
dispatch(setStreamError(undefined));
|
||||
}}
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5 text-stone-500" />
|
||||
</div>
|
||||
</div>
|
||||
<div>{errorContent}</div>
|
||||
<div className="flex flex-row flex-wrap items-center justify-end">
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
<span
|
||||
className="flex cursor-pointer flex-row items-center gap-1.5 hover:underline"
|
||||
onClick={() => {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<div className="hidden h-5 w-5 sm:block">
|
||||
<Cog8ToothIcon />
|
||||
</div>
|
||||
<span>Config</span>
|
||||
</span>
|
||||
<span className="font-bold">|</span>
|
||||
|
||||
<div
|
||||
className="flex cursor-pointer flex-row items-center text-center hover:underline"
|
||||
onClick={() => {
|
||||
ideMessenger.post("toggleDevTools", undefined);
|
||||
}}
|
||||
>
|
||||
<span>Logs</span>
|
||||
</div>
|
||||
<span className="font-bold">|</span>
|
||||
<span className="hidden sm:flex">Report:</span>
|
||||
<div>
|
||||
<GithubIcon
|
||||
data-tooltip-id={"github-report"}
|
||||
className="h-5 w-5 cursor-pointer hover:opacity-80"
|
||||
onClick={() => {
|
||||
ideMessenger.post("openUrl", GITHUB_LINK);
|
||||
}}
|
||||
/>
|
||||
<ToolTip id={"github-report"}>Github</ToolTip>
|
||||
</div>
|
||||
<div>
|
||||
<DiscordIcon
|
||||
data-tooltip-id={"discord-report"}
|
||||
className="h-5 w-5 cursor-pointer hover:opacity-80"
|
||||
onClick={() => {
|
||||
ideMessenger.post("openUrl", DISCORD_LINK);
|
||||
}}
|
||||
/>
|
||||
<ToolTip id={"discord-report"}>Discord</ToolTip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StreamError;
|
||||
|
|
|
|||
|
|
@ -354,13 +354,12 @@ export const sessionSlice = createSlice({
|
|||
},
|
||||
setStreamError: (
|
||||
state,
|
||||
{ payload }: PayloadAction<{ statusCode: number; message: string }>,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{ statusCode: number; message: string } | undefined>,
|
||||
) => {
|
||||
state.streamError = payload;
|
||||
},
|
||||
clearStreamError: (state) => {
|
||||
state.streamError = undefined;
|
||||
},
|
||||
newSession: (state, { payload }: PayloadAction<Session | undefined>) => {
|
||||
state.lastSessionId = state.id;
|
||||
|
||||
|
|
@ -652,6 +651,7 @@ export const {
|
|||
addSessionMetadata,
|
||||
updateSessionMetadata,
|
||||
deleteSessionMetadata,
|
||||
setStreamError,
|
||||
} = sessionSlice.actions;
|
||||
|
||||
export const {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { clearLastEmptyResponse, setInactive } from "../slices/sessionSlice";
|
||||
import {
|
||||
clearLastEmptyResponse,
|
||||
setInactive,
|
||||
setStreamError,
|
||||
} from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { saveCurrentSession } from "./session";
|
||||
|
||||
|
|
@ -9,10 +13,24 @@ export const streamThunkWrapper = createAsyncThunk<
|
|||
ThunkApiType
|
||||
>("chat/streamWrapper", async (runStream, { dispatch, extra }) => {
|
||||
try {
|
||||
dispatch(setStreamError(undefined));
|
||||
await runStream();
|
||||
} catch (e: any) {
|
||||
// NOTE - streaming errors are shown as ide toasts in core, don't show duplicate here
|
||||
console.debug("Error streaming response: ", e);
|
||||
// console.debug("Error streaming response: ", e);
|
||||
if (e.message) {
|
||||
const status = e.message.split(" ")[0];
|
||||
if (status) {
|
||||
console.log("STATUS", status);
|
||||
const statusCode = Number(status);
|
||||
dispatch(
|
||||
setStreamError({
|
||||
message: e.message,
|
||||
statusCode: Number.isNaN(statusCode) ? 500 : statusCode,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
dispatch(clearLastEmptyResponse());
|
||||
} finally {
|
||||
dispatch(setInactive());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue