gui strict null checks continued

This commit is contained in:
Dallin Romney 2025-01-03 16:41:14 +01:00
parent 02ab561b01
commit c7ed2aa62e
7 changed files with 37 additions and 36 deletions

View file

@ -12,9 +12,7 @@ export default function UndoAndRedoButtons() {
const dispatch = useDispatch();
const ideMessenger = useContext(IdeMessengerContext);
const checkpoints = useAppSelector(
(store) => store.session.history.at(-1).checkpoint,
);
const history = useAppSelector((store) => store.session.history);
const curCheckpointIndex = useAppSelector(
(store) => store.session.curCheckpointIndex,
@ -28,10 +26,13 @@ export default function UndoAndRedoButtons() {
type === "undo" ? curCheckpointIndex - 1 : curCheckpointIndex + 1,
);
const checkpoint = checkpoints[checkpointIndex];
const checkpoint = history[checkpointIndex]?.checkpoint ?? {};
for (const [filepath, prevFileContent] of Object.entries(checkpoint)) {
ideMessenger.post("overwriteFile", { filepath, prevFileContent });
for (const [filepath, cachedFileContent] of Object.entries(checkpoint)) {
ideMessenger.post("overwriteFile", {
filepath,
prevFileContent: cachedFileContent,
});
}
dispatch(setCurCheckpointIndex(checkpointIndex));

View file

@ -122,8 +122,8 @@ async function resolveEditorContent({
let contextItems: ContextItemWithId[] = [];
for (const item of contextItemAttrs) {
const result = await ideMessenger.request("context/getContextItems", {
name: item.itemType === "contextProvider" ? item.id : item.itemType,
query: item.query,
name: item.itemType === "contextProvider" ? item.id : item.itemType!,
query: item.query ?? "",
fullInput: stripImages(parts),
selectedCode,
selectedModelTitle,
@ -211,22 +211,22 @@ function resolveParagraph(
p: JSONContent,
): [string, MentionAttrs[], string | undefined] {
let text = "";
const contextItems = [];
const contextItems: MentionAttrs[] = [];
let slashCommand: string | undefined = undefined;
for (const child of p.content || []) {
if (child.type === "text") {
text += text === "" ? child.text.trimStart() : child.text;
text += text === "" ? child.text?.trimStart() : child.text;
} else if (child.type === "mention") {
text +=
typeof child.attrs.renderInlineAs === "string"
typeof child.attrs?.renderInlineAs === "string"
? child.attrs.renderInlineAs
: child.attrs.label;
contextItems.push(child.attrs);
: child.attrs?.label;
contextItems.push(child.attrs as MentionAttrs);
} else if (child.type === "slashcommand") {
if (typeof slashCommand === "undefined") {
slashCommand = child.attrs.id;
slashCommand = child.attrs?.id;
} else {
text += child.attrs.label;
text += child.attrs?.label;
}
} else {
console.warn("Unexpected child type", child.type);

View file

@ -50,7 +50,7 @@ const InnerHoverDiv = styled.div<{ isBottomToolbarPosition: boolean }>`
`;
interface StepContainerPreActionButtonsProps {
language: string;
language: string | null;
codeBlockContent: string;
codeBlockIndex: number;
children: any;

View file

@ -44,7 +44,7 @@ const ToolbarDiv = styled.div<{ isExpanded: boolean }>`
export interface StepContainerPreToolbarProps {
codeBlockContent: string;
language: string;
language: string | null;
relativeFilepath: string;
isGeneratingCodeBlock: boolean;
codeBlockIndex: number; // To track which codeblock we are applying
@ -93,12 +93,12 @@ export default function StepContainerPreToolbar(
if (!defaultModel) {
return;
}
const fileUri = await inferResolvedUriFromRelativePath(
props.relativeFilepath,
ideMessenger.ide,
);
ideMessenger.post("applyToFile", {
streamId: streamIdRef.current,
filepath: fileUri,

View file

@ -228,7 +228,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
],
rehypeReactOptions: {
components: {
a: ({ node, ...aProps }) => {
a: ({ ...aProps }) => {
const tooltipId = uuidv4();
return (
@ -247,7 +247,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
</>
);
},
pre: ({ node, ...preProps }) => {
pre: ({ ...preProps }) => {
const codeBlockIndex = preProps["data-codeblockindex"];
const preChildProps = preProps?.children?.[0]?.props ?? {};
@ -293,7 +293,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
</StepContainerPreToolbar>
);
},
code: ({ node, ...codeProps }) => {
code: ({ ...codeProps }) => {
const content = getCodeChildrenContent(codeProps.children);
if (content && previousFileContextItemsRef.current) {

View file

@ -26,7 +26,7 @@ export function getTerminalCommand(text: string): string {
}
export function isTerminalCodeBlock(
language: string | undefined,
language: string | undefined | null,
text: string,
) {
return (

View file

@ -288,9 +288,7 @@ export const sessionSlice = createSlice({
message.role &&
(lastMessage.role !== message.role ||
// This is when a tool call comes after assistant text
(lastMessage.content !== "" &&
message.role === "assistant"
))
(lastMessage.content !== "" && message.role === "assistant"))
) {
// Create a new message
const historyItem: ChatHistoryItemWithMessageId = {
@ -300,17 +298,19 @@ export const sessionSlice = createSlice({
},
contextItems: [],
};
const toolCalls =
if (message.role === "assistant" && message.toolCalls?.[0]) {
const [_, parsedArgs] = incrementalParseJson(
message.toolCalls[0].function.arguments,
);
historyItem.toolCallState = {
status: "generating",
toolCall: message.toolCalls[0] as ToolCall,
toolCallId: message.toolCalls[0].id,
parsedArgs,
};
const toolCalls = message.toolCalls?.[0];
if (toolCalls) {
const [_, parsedArgs] = incrementalParseJson(
message.toolCalls[0].function.arguments,
);
historyItem.toolCallState = {
status: "generating",
toolCall: message.toolCalls[0] as ToolCall,
toolCallId: message.toolCalls[0].id,
parsedArgs,
};
}
}
state.history.push(historyItem);