gui strict null checks finish up
This commit is contained in:
parent
9a9e43d084
commit
98c2b7a39f
10 changed files with 89 additions and 35 deletions
|
|
@ -421,7 +421,6 @@ export class Core {
|
|||
|
||||
const chunk = next.value;
|
||||
|
||||
// @ts-ignore
|
||||
yield { content: chunk };
|
||||
next = await gen.next();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,26 @@ import type {
|
|||
} from "../";
|
||||
import { ConfigResult } from "../config/load";
|
||||
|
||||
export type ProtocolGeneratorType<T> = AsyncGenerator<{
|
||||
export type ProtocolGeneratorYield<T> = {
|
||||
done?: boolean;
|
||||
content: T;
|
||||
}>;
|
||||
};
|
||||
export type ProtocolGeneratorType<Y> = AsyncGenerator<
|
||||
ProtocolGeneratorYield<Y>
|
||||
>;
|
||||
|
||||
export type AsyncGeneratorYieldType<T> =
|
||||
T extends AsyncGenerator<infer Y, any, any>
|
||||
? Y extends ProtocolGeneratorYield<infer PR>
|
||||
? PR
|
||||
: never
|
||||
: never;
|
||||
// export type AsyncGeneratorReturnType<T> =
|
||||
// T extends AsyncGenerator<any, infer R, any>
|
||||
// ? R extends ProtocolGeneratorYield<infer PR>
|
||||
// ? PR
|
||||
// : never
|
||||
// : never;
|
||||
|
||||
export type OnboardingModes =
|
||||
| "Local"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { v4 as uuidv4 } from "uuid";
|
|||
|
||||
import type { IProtocol } from "../index";
|
||||
|
||||
export interface Message<T = any> {
|
||||
export interface Message<T = unknown> {
|
||||
messageType: string;
|
||||
messageId: string;
|
||||
data: T;
|
||||
|
|
|
|||
|
|
@ -103,10 +103,8 @@ export const StyledListboxOption = styled(Listbox.Option)<{
|
|||
`;
|
||||
|
||||
interface ModelSelectionListboxProps {
|
||||
selectedProvider: DisplayInfo | ProviderInfo | ModelPackage;
|
||||
setSelectedProvider: Dispatch<
|
||||
SetStateAction<DisplayInfo | ProviderInfo | ModelPackage>
|
||||
>;
|
||||
selectedProvider: DisplayInfo;
|
||||
setSelectedProvider: (val: DisplayInfo) => void;
|
||||
topOptions?: DisplayInfo[];
|
||||
otherOptions?: DisplayInfo[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import { createContext } from "react";
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import "vscode-webview";
|
||||
import { isJetBrains } from "../util";
|
||||
import {
|
||||
AsyncGeneratorYieldType,
|
||||
ProtocolGeneratorYield,
|
||||
} from "core/protocol/core";
|
||||
|
||||
interface vscode {
|
||||
postMessage(message: any): vscode;
|
||||
|
|
@ -164,24 +168,28 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
messageType: T,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
cancelToken?: AbortSignal,
|
||||
): AsyncGenerator<unknown[]> {
|
||||
// ): FromWebviewProtocol[T][1] {
|
||||
): AsyncGenerator<AsyncGeneratorYieldType<FromWebviewProtocol[T][1]>[], any> {
|
||||
type GenYield = AsyncGeneratorYieldType<FromWebviewProtocol[T][1]>;
|
||||
// type GenReturn = AsyncGeneratorReturnType<FromWebviewProtocol[T][1]>;
|
||||
|
||||
const messageId = uuidv4();
|
||||
|
||||
this.post(messageType, data, messageId);
|
||||
|
||||
const buffer: any[] = [];
|
||||
const buffer: GenYield[] = [];
|
||||
let index = 0;
|
||||
let done = false;
|
||||
let returnVal = undefined;
|
||||
|
||||
const handler = (event: { data: Message }) => {
|
||||
const handler = (event: {
|
||||
data: Message<ProtocolGeneratorYield<GenYield>>;
|
||||
}) => {
|
||||
if (event.data.messageId === messageId) {
|
||||
const responseData = event.data.data;
|
||||
if (responseData.done) {
|
||||
window.removeEventListener("message", handler);
|
||||
done = true;
|
||||
returnVal = responseData;
|
||||
returnVal = responseData.content;
|
||||
} else {
|
||||
buffer.push(responseData.content);
|
||||
}
|
||||
|
|
@ -239,8 +247,8 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
next = await gen.next();
|
||||
}
|
||||
|
||||
if (next.value.error) {
|
||||
throw new Error(next.value.error);
|
||||
if (!next.done) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
import { FREE_TRIAL_LIMIT_REQUESTS, hasPassedFTL } from "../util/freeTrial";
|
||||
import { completionParamsInputs } from "../pages/AddNewModel/configs/completionParamsInputs";
|
||||
import { setDefaultModel } from "../redux/slices/configSlice";
|
||||
import { DisplayInfo } from "../pages/AddNewModel/configs/models";
|
||||
|
||||
interface QuickModelSetupProps {
|
||||
onDone: () => void;
|
||||
|
|
@ -149,7 +150,14 @@ function AddModelForm({
|
|||
<label className="block text-sm font-medium">Provider</label>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedProvider}
|
||||
setSelectedProvider={setSelectedProvider}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
const match = [...popularProviders, ...otherProviders].find(
|
||||
(provider) => provider.title === val.title,
|
||||
);
|
||||
if (match) {
|
||||
setSelectedProvider(match);
|
||||
}
|
||||
}}
|
||||
topOptions={popularProviders}
|
||||
otherOptions={otherProviders}
|
||||
/>
|
||||
|
|
@ -186,7 +194,19 @@ function AddModelForm({
|
|||
<label className="block text-sm font-medium">Model</label>
|
||||
<ModelSelectionListbox
|
||||
selectedProvider={selectedModel}
|
||||
setSelectedProvider={setbSelectedModel}
|
||||
setSelectedProvider={(val: DisplayInfo) => {
|
||||
const options =
|
||||
Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
provider?.title === selectedProvider.title,
|
||||
)?.[1]?.packages ?? [];
|
||||
const match = options.find(
|
||||
(option) => option.title === val.title,
|
||||
);
|
||||
if (match) {
|
||||
setSelectedModel(match);
|
||||
}
|
||||
}}
|
||||
otherOptions={
|
||||
Object.entries(providers).find(
|
||||
([, provider]) =>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export function useWebviewListener<T extends keyof ToWebviewProtocol>(
|
|||
|
||||
useEffect(
|
||||
() => {
|
||||
let listener: (event: { data: Message }) => Promise<void>;
|
||||
let listener: (event: { data: Message<ToWebviewProtocol[T][0]>}) => Promise<void>;
|
||||
|
||||
if (!skip) {
|
||||
listener = async (event) => {
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ export function Chat() {
|
|||
return (
|
||||
<div key={i}>
|
||||
<ToolCallDiv
|
||||
toolCallState={item.toolCallState}
|
||||
toolCallState={item.toolCallState!}
|
||||
toolCall={toolCall}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -288,7 +288,9 @@ 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" &&
|
||||
message.toolCalls?.length))
|
||||
) {
|
||||
// Create a new message
|
||||
const historyItem: ChatHistoryItemWithMessageId = {
|
||||
|
|
@ -302,12 +304,12 @@ export const sessionSlice = createSlice({
|
|||
const toolCalls = message.toolCalls?.[0];
|
||||
if (toolCalls) {
|
||||
const [_, parsedArgs] = incrementalParseJson(
|
||||
message.toolCalls[0].function.arguments,
|
||||
message.toolCalls[0].function?.arguments ?? "{}",
|
||||
);
|
||||
historyItem.toolCallState = {
|
||||
status: "generating",
|
||||
toolCall: message.toolCalls[0],
|
||||
toolCallId: message.toolCalls[0].id,
|
||||
toolCall: message.toolCalls[0] as ToolCall,
|
||||
toolCallId: message.toolCalls[0].id as ToolCall["id"],
|
||||
parsedArgs,
|
||||
};
|
||||
}
|
||||
|
|
@ -330,16 +332,28 @@ export const sessionSlice = createSlice({
|
|||
if (lastMessage.toolCalls!.length <= i) {
|
||||
lastMessage.toolCalls!.push(toolCall);
|
||||
} else {
|
||||
lastMessage.toolCalls[i].function.arguments +=
|
||||
toolCall.function.arguments;
|
||||
if (
|
||||
toolCall?.function?.arguments &&
|
||||
lastMessage?.toolCalls?.[i]?.function?.arguments &&
|
||||
lastItem.toolCallState
|
||||
) {
|
||||
lastMessage.toolCalls[i].function!.arguments +=
|
||||
toolCall.function.arguments;
|
||||
|
||||
const [_, parsedArgs] = incrementalParseJson(
|
||||
lastMessage.toolCalls[i].function.arguments,
|
||||
);
|
||||
const [_, parsedArgs] = incrementalParseJson(
|
||||
lastMessage.toolCalls[i].function!.arguments!,
|
||||
);
|
||||
|
||||
lastItem.toolCallState.parsedArgs = parsedArgs;
|
||||
lastItem.toolCallState.toolCall.function.arguments +=
|
||||
toolCall.function.arguments;
|
||||
lastItem.toolCallState.parsedArgs = parsedArgs;
|
||||
lastItem.toolCallState.toolCall.function.arguments +=
|
||||
toolCall.function.arguments;
|
||||
} else {
|
||||
console.error(
|
||||
"Unexpected tool call format received - this message added during gui strict null checks",
|
||||
message,
|
||||
lastMessage,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,15 +55,14 @@ export const streamNormalInput = createAsyncThunk<
|
|||
break;
|
||||
}
|
||||
|
||||
const updates = next.value as ChatMessage[];
|
||||
const updates = next.value;
|
||||
dispatch(streamUpdate(updates));
|
||||
next = await gen.next();
|
||||
}
|
||||
|
||||
// Attach prompt log
|
||||
let returnVal = next.value as PromptLog;
|
||||
if (returnVal) {
|
||||
dispatch(addPromptCompletionPair([returnVal]));
|
||||
if (next.done) {
|
||||
dispatch(addPromptCompletionPair([next.value]));
|
||||
}
|
||||
|
||||
// If it's a tool call that is automatically accepted, we should call it
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue