gui strict null checks p3
This commit is contained in:
parent
e66b79d7bd
commit
02ab561b01
9 changed files with 49 additions and 38 deletions
|
|
@ -30,7 +30,7 @@ export function isTerminalCodeBlock(
|
|||
text: string,
|
||||
) {
|
||||
return (
|
||||
terminalLanguages.includes(language) ||
|
||||
(language && terminalLanguages.includes(language)) ||
|
||||
((!language || language?.length === 0) &&
|
||||
(text.trim().split("\n").length === 1 ||
|
||||
commonTerminalCommands.some((c) => text.trim().startsWith(c))))
|
||||
|
|
|
|||
|
|
@ -164,18 +164,22 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
cancelToken?: AbortSignal,
|
||||
): AsyncGenerator<unknown[]> {
|
||||
// ): FromWebviewProtocol[T][1] {
|
||||
): AsyncGenerator<FromWebviewProtocol[T][1][]> {
|
||||
const messageId = uuidv4();
|
||||
|
||||
this.post(messageType, data, messageId);
|
||||
|
||||
const buffer: any[] = [];
|
||||
const buffer: FromWebviewProtocol[T][1][] = [];
|
||||
let index = 0;
|
||||
let done = false;
|
||||
let returnVal = undefined;
|
||||
|
||||
const handler = (event: { data: Message }) => {
|
||||
const handler = (event: {
|
||||
data: Message<{
|
||||
done: boolean;
|
||||
content: FromWebviewProtocol[T][1];
|
||||
}>;
|
||||
}) => {
|
||||
if (event.data.messageId === messageId) {
|
||||
const responseData = event.data.data;
|
||||
if (responseData.done) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,9 @@ export const SubmenuContextProvidersProvider = ({
|
|||
[minisearches],
|
||||
);
|
||||
|
||||
const lastOpenFilesRef = useRef([]);
|
||||
const lastOpenFilesRef = useRef<
|
||||
Awaited<ReturnType<typeof getOpenFilesItems>>
|
||||
>([]);
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
const refreshOpenFiles = async () => {
|
||||
|
|
@ -214,12 +216,14 @@ export const SubmenuContextProvidersProvider = ({
|
|||
try {
|
||||
const results = getSubmenuSearchResults(providerTitle, query);
|
||||
if (results.length === 0) {
|
||||
const fallbackItems = (fallbackResults[providerTitle] ?? [])
|
||||
const fallbackItems = (
|
||||
providerTitle ? (fallbackResults[providerTitle] ?? []) : []
|
||||
)
|
||||
.slice(0, limit)
|
||||
.map((result) => {
|
||||
return {
|
||||
...result,
|
||||
providerTitle,
|
||||
providerTitle: providerTitle || "unknown",
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -281,16 +281,16 @@ export const sessionSlice = createSlice({
|
|||
},
|
||||
streamUpdate: (state, action: PayloadAction<ChatMessage[]>) => {
|
||||
if (state.history.length) {
|
||||
const lastItem = state.history[state.history.length - 1];
|
||||
const lastMessage = lastItem.message;
|
||||
for (const message of action.payload) {
|
||||
const lastMessage = state.history[state.history.length - 1];
|
||||
|
||||
if (
|
||||
message.role &&
|
||||
(lastMessage.message.role !== message.role ||
|
||||
(lastMessage.role !== message.role ||
|
||||
// This is when a tool call comes after assistant text
|
||||
(lastMessage.message.content !== "" &&
|
||||
message.role === "assistant" &&
|
||||
message.toolCalls?.length))
|
||||
(lastMessage.content !== "" &&
|
||||
message.role === "assistant"
|
||||
))
|
||||
) {
|
||||
// Create a new message
|
||||
const historyItem: ChatHistoryItemWithMessageId = {
|
||||
|
|
@ -300,8 +300,8 @@ export const sessionSlice = createSlice({
|
|||
},
|
||||
contextItems: [],
|
||||
};
|
||||
|
||||
if (message.role === "assistant" && message.toolCalls) {
|
||||
const toolCalls =
|
||||
if (message.role === "assistant" && message.toolCalls?.[0]) {
|
||||
const [_, parsedArgs] = incrementalParseJson(
|
||||
message.toolCalls[0].function.arguments,
|
||||
);
|
||||
|
|
@ -316,34 +316,29 @@ export const sessionSlice = createSlice({
|
|||
state.history.push(historyItem);
|
||||
} else {
|
||||
// Add to the existing message
|
||||
const msg = state.history[state.history.length - 1].message;
|
||||
if (message.content) {
|
||||
msg.content += renderChatMessage(message);
|
||||
lastMessage.content += renderChatMessage(message);
|
||||
} else if (
|
||||
message.role === "assistant" &&
|
||||
message.toolCalls &&
|
||||
msg.role === "assistant"
|
||||
lastMessage.role === "assistant"
|
||||
) {
|
||||
if (!msg.toolCalls) {
|
||||
msg.toolCalls = [];
|
||||
if (!lastMessage.toolCalls) {
|
||||
lastMessage.toolCalls = [];
|
||||
}
|
||||
message.toolCalls.forEach((toolCall, i) => {
|
||||
if (msg.toolCalls.length <= i) {
|
||||
msg.toolCalls.push(toolCall);
|
||||
if (lastMessage.toolCalls!.length <= i) {
|
||||
lastMessage.toolCalls!.push(toolCall);
|
||||
} else {
|
||||
msg.toolCalls[i].function.arguments +=
|
||||
lastMessage.toolCalls[i].function.arguments +=
|
||||
toolCall.function.arguments;
|
||||
|
||||
const [_, parsedArgs] = incrementalParseJson(
|
||||
msg.toolCalls[i].function.arguments,
|
||||
lastMessage.toolCalls[i].function.arguments,
|
||||
);
|
||||
|
||||
state.history[
|
||||
state.history.length - 1
|
||||
].toolCallState.parsedArgs = parsedArgs;
|
||||
state.history[
|
||||
state.history.length - 1
|
||||
].toolCallState.toolCall.function.arguments +=
|
||||
lastItem.toolCallState.parsedArgs = parsedArgs;
|
||||
lastItem.toolCallState.toolCall.function.arguments +=
|
||||
toolCall.function.arguments;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -63,7 +63,10 @@ const persistConfig = {
|
|||
migrate: createMigrate(migrations, { debug: false }),
|
||||
};
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||
const persistedReducer = persistReducer<ReturnType<typeof rootReducer>>(
|
||||
persistConfig,
|
||||
rootReducer,
|
||||
);
|
||||
|
||||
export function setupStore() {
|
||||
return configureStore({
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
const state = getState();
|
||||
const toolCallState = selectCurrentToolCall(state);
|
||||
|
||||
console.log("calling tool", toolCallState.toolCall);
|
||||
if (!toolCallState) {
|
||||
return;
|
||||
}
|
||||
console.log("calling tool", toolCallState.toolCall);
|
||||
|
||||
if (toolCallState.status !== "generated") {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,10 @@ export const gatherContext = createAsyncThunk<
|
|||
state.config.config.experimental?.defaultContext ?? [];
|
||||
|
||||
if (!state.config.defaultModelTitle) {
|
||||
console.error("Failed to gather context, no model selected");
|
||||
return;
|
||||
console.error(
|
||||
"gatherContext thunk: Cannot gather context, no model selected",
|
||||
);
|
||||
throw new Error("No chat model selected");
|
||||
}
|
||||
|
||||
// Resolve context providers and construct new history
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ export const saveCurrentSession = createAsyncThunk<
|
|||
}
|
||||
// Fallbacks if above doesn't work out or getChatTitles = false
|
||||
if (title === NEW_SESSION_TITLE) {
|
||||
title = getChatTitleFromMessage(history[0].message);
|
||||
title = getChatTitleFromMessage(state.session.history[0].message);
|
||||
}
|
||||
}
|
||||
// More fallbacks in case of no title
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
const slashCommands = state.config.config.slashCommands || [];
|
||||
const inputIndex = index ?? state.session.history.length;
|
||||
|
||||
if (!defaultModel) {
|
||||
throw new Error("No chat model selected");
|
||||
}
|
||||
|
||||
dispatch(submitEditorAndInitAtIndex({ index, editorState }));
|
||||
resetStateForNewMessage();
|
||||
|
||||
|
|
@ -115,7 +119,6 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
unwrapResult(await dispatch(streamNormalInput(messages)));
|
||||
} else {
|
||||
const [slashCommand, commandInput] = commandAndInput;
|
||||
let updatedContextItems = [];
|
||||
posthog.capture("step run", {
|
||||
step_name: slashCommand.name,
|
||||
params: {},
|
||||
|
|
@ -132,7 +135,7 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
input: commandInput,
|
||||
historyIndex: inputIndex,
|
||||
selectedCode,
|
||||
contextItems: updatedContextItems,
|
||||
contextItems: [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue