gui strict null checks p1
This commit is contained in:
parent
7bfea237ec
commit
e66b79d7bd
21 changed files with 103 additions and 65 deletions
|
|
@ -6,9 +6,9 @@
|
|||
"project": "gui/tsconfig.json"
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
||||
// "eslint:recommended",
|
||||
// "plugin:@typescript-eslint/recommended",
|
||||
// "plugin:@typescript-eslint/recommended-requiring-type-checking"
|
||||
// "plugin:react/recommended"
|
||||
],
|
||||
"overrides": [
|
||||
|
|
|
|||
17
gui/package-lock.json
generated
17
gui/package-lock.json
generated
|
|
@ -24,6 +24,7 @@
|
|||
"@tiptap/react": "^2.1.13",
|
||||
"@tiptap/starter-kit": "^2.1.13",
|
||||
"@tiptap/suggestion": "^2.1.13",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@types/vscode-webview": "^1.57.1",
|
||||
"core": "file:../core",
|
||||
"dompurify": "^3.0.6",
|
||||
|
|
@ -70,6 +71,7 @@
|
|||
"@testing-library/jest-dom": "^6.5.0",
|
||||
"@testing-library/react": "^16.0.1",
|
||||
"@testing-library/user-event": "^14.5.2",
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/lodash": "^4.17.6",
|
||||
"@types/mustache": "^4.2.5",
|
||||
"@types/node": "^20.5.6",
|
||||
|
|
@ -2893,6 +2895,16 @@
|
|||
"@types/ms": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/dompurify": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/dompurify/-/dompurify-3.2.0.tgz",
|
||||
"integrity": "sha512-Fgg31wv9QbLDA0SpTOXO3MaxySc4DKGLi8sna4/Utjo4r3ZRPdCt4UQee8BWr+Q5z21yifghREPJGYaEOEIACg==",
|
||||
"deprecated": "This is a stub types definition. dompurify provides its own type definitions, so you do not need this installed.",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"dompurify": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz",
|
||||
|
|
@ -3076,6 +3088,11 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
|
||||
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg=="
|
||||
},
|
||||
"node_modules/@types/uuid": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz",
|
||||
"integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ=="
|
||||
},
|
||||
"node_modules/@types/vscode-webview": {
|
||||
"version": "1.57.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/vscode-webview/-/vscode-webview-1.57.5.tgz",
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
"@tiptap/react": "^2.1.13",
|
||||
"@tiptap/starter-kit": "^2.1.13",
|
||||
"@tiptap/suggestion": "^2.1.13",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@types/vscode-webview": "^1.57.1",
|
||||
"core": "file:../core",
|
||||
"dompurify": "^3.0.6",
|
||||
|
|
@ -78,6 +79,7 @@
|
|||
"@testing-library/jest-dom": "^6.5.0",
|
||||
"@testing-library/react": "^16.0.1",
|
||||
"@testing-library/user-event": "^14.5.2",
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/lodash": "^4.17.6",
|
||||
"@types/mustache": "^4.2.5",
|
||||
"@types/node": "^20.5.6",
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import FileIcon from "../FileIcon";
|
|||
import { useAppSelector } from "../../redux/hooks";
|
||||
|
||||
export interface AddFileComboboxProps {
|
||||
onSelect: (filepaths: string[]) => void;
|
||||
onEscape: () => void;
|
||||
onSelect: (filepaths: string[]) => void | Promise<void>;
|
||||
onEscape: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
export default function AddFileCombobox({
|
||||
|
|
@ -50,7 +50,7 @@ export default function AddFileCombobox({
|
|||
value={selectedFiles}
|
||||
onChange={(files) => {
|
||||
setSelectedFiles(files);
|
||||
onSelect(files.map((file) => file.id));
|
||||
void onSelect(files.map((file) => file.id));
|
||||
buttonRef.current?.click();
|
||||
}}
|
||||
>
|
||||
|
|
@ -72,7 +72,7 @@ export default function AddFileCombobox({
|
|||
placeholder="Type to search files..."
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape" && !open) {
|
||||
onEscape();
|
||||
void onEscape();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useContext, useState } from "react";
|
|||
import { useDispatch } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import CodeToEditListItem from "./CodeToEditListItem";
|
||||
import type { CodeToEdit, RangeInFileWithContents } from "core";
|
||||
import type { CodeToEdit } from "core";
|
||||
import AddFileButton from "./AddFileButton";
|
||||
import AddFileCombobox from "./AddFileCombobox";
|
||||
import { PlusIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
|
|
@ -25,19 +25,19 @@ export default function CodeToEditCard() {
|
|||
? "Code to edit (1 item)"
|
||||
: `Code to edit (${codeToEdit.length} items)`;
|
||||
|
||||
function onDelete(rif: RangeInFileWithContents) {
|
||||
function onDelete(rif: CodeToEdit) {
|
||||
dispatch(removeCodeToEdit(rif));
|
||||
}
|
||||
|
||||
function onClickFilename(code: CodeToEdit) {
|
||||
async function onClickFilename(code: CodeToEdit) {
|
||||
if ("range" in code) {
|
||||
ideMessenger.ide.showLines(
|
||||
await ideMessenger.ide.showLines(
|
||||
code.filepath,
|
||||
code.range.start.line,
|
||||
code.range.end.line,
|
||||
);
|
||||
} else {
|
||||
ideMessenger.ide.openFile(code.filepath);
|
||||
await ideMessenger.ide.openFile(code.filepath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +93,10 @@ export default function CodeToEditCard() {
|
|||
/>
|
||||
</div>
|
||||
<XMarkIcon
|
||||
onClick={(e) => {
|
||||
onClick={() => {
|
||||
setShowAddFileCombobox(false);
|
||||
}}
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground mb-2 h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground mb-2 h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import {
|
|||
|
||||
export interface CodeToEditListItemProps {
|
||||
code: CodeToEdit;
|
||||
onDelete: (codeToEdit: CodeToEdit) => void;
|
||||
onClickFilename: (codeToEdit: CodeToEdit) => void;
|
||||
onDelete: (codeToEdit: CodeToEdit) => void | Promise<void>;
|
||||
onClickFilename: (codeToEdit: CodeToEdit) => void | Promise<void>;
|
||||
}
|
||||
|
||||
const NoPaddingWrapper = styled.div`
|
||||
|
|
@ -87,7 +87,7 @@ export default function CodeToEditListItem({
|
|||
className="flex-shrink-0 text-xs hover:underline"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onClickFilename(code);
|
||||
void onClickFilename(code);
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
|
|
@ -122,7 +122,7 @@ export default function CodeToEditListItem({
|
|||
<XMarkIcon
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onDelete(code);
|
||||
void onDelete(code);
|
||||
}}
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ function BestExperienceConfigForm({
|
|||
<div className="mb-1 flex flex-row justify-between gap-4 text-lg font-bold">
|
||||
<label className="text-lg font-bold">Chat model</label>
|
||||
<div
|
||||
className="flex hidden items-center justify-end text-xs font-semibold sm:flex"
|
||||
className="hidden items-center justify-end text-xs font-semibold sm:flex"
|
||||
style={{ color: lightGray }}
|
||||
>
|
||||
<CubeIcon className="mr-1 h-4 w-4 flex-shrink-0" />
|
||||
|
|
|
|||
|
|
@ -66,11 +66,12 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = {
|
|||
"/cmd": CommandLineIcon,
|
||||
};
|
||||
|
||||
export function getIconFromDropdownItem(id: string, type: ComboBoxItemType) {
|
||||
return (
|
||||
ICONS_FOR_DROPDOWN[id] ??
|
||||
(type === "contextProvider" ? AtSymbolIcon : BoltIcon)
|
||||
);
|
||||
export function getIconFromDropdownItem(
|
||||
id: string | undefined,
|
||||
type: ComboBoxItemType,
|
||||
) {
|
||||
const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon;
|
||||
return id ? (ICONS_FOR_DROPDOWN[id] ?? typeIcon) : typeIcon;
|
||||
}
|
||||
|
||||
function DropdownIcon(props: { className?: string; item: ComboBoxItem }) {
|
||||
|
|
@ -238,7 +239,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
}
|
||||
}, [querySubmenuItem]);
|
||||
|
||||
const selectItem = (index) => {
|
||||
const selectItem = (index: number) => {
|
||||
const item = allItems[index];
|
||||
|
||||
if (item.type === "action" && item.action) {
|
||||
|
|
@ -251,7 +252,9 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
item.contextProvider?.type === "submenu"
|
||||
) {
|
||||
setSubMenuTitle(item.description);
|
||||
props.enterSubmenu(props.editor, item.id);
|
||||
if (item.id) {
|
||||
props.enterSubmenu?.(props.editor, item.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -359,6 +362,9 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
ref={queryInputRef}
|
||||
placeholder={querySubmenuItem.description}
|
||||
onKeyDown={(e) => {
|
||||
if (!queryInputRef.current) {
|
||||
return;
|
||||
}
|
||||
if (e.key === "Enter") {
|
||||
if (e.shiftKey) {
|
||||
queryInputRef.current.innerText += "\n";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
PlusIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { MouseEvent, useContext, useEffect, useRef, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
|
|
@ -144,7 +144,7 @@ function ModelOption({
|
|||
const dispatch = useDispatch();
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
function onClickDelete(e) {
|
||||
function onClickDelete(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ function ModelOption({
|
|||
);
|
||||
}
|
||||
|
||||
function onClickGear(e) {
|
||||
function onClickGear(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ function ModelOption({
|
|||
});
|
||||
}
|
||||
|
||||
function handleOptionClick(e) {
|
||||
function handleOptionClick(e: MouseEvent) {
|
||||
if (showMissingApiKeyMsg) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
|
@ -287,7 +287,7 @@ function ModelSelect() {
|
|||
setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow);
|
||||
}
|
||||
|
||||
function onClickAddModel(e) {
|
||||
function onClickAddModel(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
|
|
|
|||
|
|
@ -82,8 +82,6 @@ export const SubmenuContextProvidersProvider = ({
|
|||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [autoLoadTriggered, setAutoLoadTriggered] = useState(false);
|
||||
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const getOpenFilesItems = useCallback(async () => {
|
||||
|
|
@ -102,7 +100,7 @@ export const SubmenuContextProvidersProvider = ({
|
|||
}));
|
||||
}, [ideMessenger]);
|
||||
|
||||
useWebviewListener("refreshSubmenuItems", async (data) => {
|
||||
useWebviewListener("refreshSubmenuItems", async () => {
|
||||
if (!isLoading) {
|
||||
setInitialLoadComplete(false);
|
||||
setAutoLoadTriggered((prev) => !prev); // Toggle to trigger effect
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ function constructTheme(
|
|||
): Record<string, string> {
|
||||
const rules = tmTheme?.["rules"] || [];
|
||||
|
||||
const tokenToForeground = {};
|
||||
const tokenToForeground: Record<string, string> = {};
|
||||
rules.forEach(({ token, foreground }) => {
|
||||
if (!foreground || !token) {
|
||||
return;
|
||||
|
|
@ -66,7 +66,7 @@ function constructTheme(
|
|||
tokenToForeground[token] = foreground;
|
||||
});
|
||||
|
||||
const theme = {};
|
||||
const theme: Record<string, string> = {};
|
||||
Object.keys(hljsToTextMate).forEach((className) => {
|
||||
const tokens = hljsToTextMate[className];
|
||||
for (const scope of tokens) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ function AddModelForm({
|
|||
|
||||
const allProviders = Object.entries(providers)
|
||||
.filter(([key]) => !["freetrial", "openai-aiohttp"].includes(key))
|
||||
.map(([, provider]) => provider);
|
||||
.map(([, provider]) => provider)
|
||||
.filter((provider) => !!provider);
|
||||
|
||||
const popularProviders = allProviders
|
||||
.filter((provider) => popularProviderTitles.includes(provider.title))
|
||||
|
|
@ -187,8 +188,9 @@ function AddModelForm({
|
|||
setSelectedProvider={setSelectedModel}
|
||||
otherOptions={
|
||||
Object.entries(providers).find(
|
||||
([, provider]) => provider.title === selectedProvider.title,
|
||||
)?.[1].packages
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -220,9 +222,14 @@ function AddModelForm({
|
|||
<InputSubtext className="mb-0">
|
||||
<a
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit"
|
||||
onClick={() =>
|
||||
ideMessenger.post("openUrl", selectedProviderApiKeyUrl)
|
||||
}
|
||||
onClick={() => {
|
||||
if (selectedProviderApiKeyUrl) {
|
||||
ideMessenger.post(
|
||||
"openUrl",
|
||||
selectedProviderApiKeyUrl,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Click here
|
||||
</a>{" "}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ export function useWebviewListener<T extends keyof ToWebviewProtocol>(
|
|||
|
||||
useEffect(
|
||||
() => {
|
||||
let listener;
|
||||
let listener: (event: { data: Message }) => Promise<void>;
|
||||
|
||||
if (!skip) {
|
||||
listener = async (event: { data: Message }) => {
|
||||
listener = async (event) => {
|
||||
if (event.data.messageType === messageType) {
|
||||
const result = await handler(event.data.data);
|
||||
ideMessenger.respond(messageType, result, event.data.messageId);
|
||||
|
|
|
|||
|
|
@ -407,9 +407,8 @@ export function Chat() {
|
|||
return (
|
||||
<div key={i}>
|
||||
<ToolCallDiv
|
||||
reactKey={toolCall.id}
|
||||
toolCallState={item.toolCallState}
|
||||
toolCall={toolCall as any}
|
||||
toolCall={toolCall}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -44,15 +44,18 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
|
|||
let statusCode: undefined | number = undefined;
|
||||
|
||||
// Attempt to get error message and status code from error
|
||||
if (error && (error instanceof Error || typeof error === "object")) {
|
||||
if (error["message"]) {
|
||||
message = error["message"];
|
||||
const status = message?.split(" ")[0];
|
||||
if (status) {
|
||||
const code = Number(status);
|
||||
if (!Number.isNaN(statusCode)) {
|
||||
statusCode = code;
|
||||
}
|
||||
if (
|
||||
error &&
|
||||
(error instanceof Error || typeof error === "object") &&
|
||||
"message" in error &&
|
||||
typeof error["message"] === "string"
|
||||
) {
|
||||
message = error["message"];
|
||||
const status = message?.split(" ")[0];
|
||||
if (status) {
|
||||
const code = Number(status);
|
||||
if (!Number.isNaN(statusCode)) {
|
||||
statusCode = code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ interface ThreadDivProps {
|
|||
icon: React.ReactNode;
|
||||
toolCall: ToolCall;
|
||||
toolCallState: ToolCallState;
|
||||
reactKey: string;
|
||||
}
|
||||
|
||||
const Container = styled.div`
|
||||
|
|
@ -48,7 +47,7 @@ export function ThreadDiv(props: ThreadDivProps) {
|
|||
}
|
||||
|
||||
return (
|
||||
<Container key={props.reactKey}>
|
||||
<Container>
|
||||
<HeaderDiv>
|
||||
<div
|
||||
style={{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import { ThreadDiv } from "./ThreadDiv";
|
|||
interface ToolCallDivProps {
|
||||
toolCall: ToolCall;
|
||||
toolCallState: ToolCallState;
|
||||
reactKey: string;
|
||||
}
|
||||
|
||||
export function ToolCallDiv(props: ToolCallDivProps) {
|
||||
|
|
@ -32,7 +31,6 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
|
||||
return (
|
||||
<ThreadDiv
|
||||
reactKey={props.reactKey}
|
||||
icon={getIcon(props.toolCallState.status)}
|
||||
toolCall={props.toolCall}
|
||||
toolCallState={props.toolCallState}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ export const selectLastToolCall = createSelector(
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!lastToolCallHistoryItem) return null;
|
||||
return lastToolCallHistoryItem.toolCallState;
|
||||
return lastToolCallHistoryItem?.toolCallState ?? null;
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -116,7 +116,10 @@ export const sessionSlice = createSlice({
|
|||
state.isStreaming = true;
|
||||
},
|
||||
setIsGatheringContext: (state, { payload }: PayloadAction<boolean>) => {
|
||||
state.history.at(-1).isGatheringContext = payload;
|
||||
const curMessage = state.history.at(-1);
|
||||
if (curMessage) {
|
||||
curMessage.isGatheringContext = payload;
|
||||
}
|
||||
},
|
||||
clearLastEmptyResponse: (state) => {
|
||||
if (state.history.length < 2) {
|
||||
|
|
@ -472,8 +475,10 @@ export const sessionSlice = createSlice({
|
|||
state,
|
||||
{ payload }: PayloadAction<{ filepath: string; content: string }>,
|
||||
) => {
|
||||
state.history[state.curCheckpointIndex].checkpoint[payload.filepath] =
|
||||
payload.content;
|
||||
const checkpoint = state.history[state.curCheckpointIndex].checkpoint;
|
||||
if (checkpoint) {
|
||||
checkpoint[payload.filepath] = payload.content;
|
||||
}
|
||||
},
|
||||
updateApplyState: (state, { payload }: PayloadAction<ApplyState>) => {
|
||||
const applyState = state.codeBlockApplyStates.states.find(
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export const streamNormalInput = createAsyncThunk<
|
|||
(tool) => tool.function.name === toolName,
|
||||
),
|
||||
)
|
||||
.filter(Boolean)
|
||||
.filter((tool) => !!tool)
|
||||
: undefined,
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ export const streamResponseAfterToolCall = createAsyncThunk<
|
|||
const initialHistory = state.session.history;
|
||||
const defaultModel = selectDefaultModel(state);
|
||||
|
||||
if (!defaultModel) {
|
||||
console.error("No default model found");
|
||||
return;
|
||||
}
|
||||
|
||||
resetStateForNewMessage();
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue