refactor(client): Refactors recent typescript changes for best practices (#763)

* create common types in client

* remove unnecessary rules from eslint config

* cleanup types

* put back eslintrc rules
This commit is contained in:
Dan Orlando 2023-08-05 13:45:26 -07:00 committed by GitHub
parent 5828200197
commit 96d29f7390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 233 additions and 245 deletions

View file

@ -1,5 +1,5 @@
import { tConversationSchema } from './schemas';
import type { TSubmission, EModelEndpoint } from './types';
import { TSubmission, EModelEndpoint } from './types';
export default function createPayload(submission: TSubmission) {
const { conversation, message, endpointOption } = submission;

View file

@ -1,5 +1,4 @@
import * as React from 'react';
import { TExample, TMessage, EModelEndpoint, TPlugin, TConversation, TPreset } from './schemas';
import { TMessage, EModelEndpoint, TConversation } from './schemas';
export * from './schemas';
@ -49,19 +48,20 @@ export type TPluginAction = {
auth?: unknown;
};
export type TTemplate = {
[key: string]: TPlugin;
};
export type TUpdateUserPlugins = {
pluginKey: string;
action: string;
auth?: unknown;
};
export type TOptionSettings = {
showExamples?: boolean;
isCodeChat?: boolean;
export type TError = {
message: string;
code?: number;
response?: {
data?: {
message?: string;
};
};
};
export type TUser = {
@ -204,143 +204,3 @@ export type TRequestPasswordResetResponse = {
link?: string;
message?: string;
};
export type File = {
name: string;
date: number;
size: number;
};
export type SetOption = (param: number | string) => (newValue: number | string | boolean) => void;
export type SetExample = (
i: number,
type: string,
newValue: number | string | boolean | null,
) => void;
export enum Side {
Top = 'top',
Right = 'right',
Bottom = 'bottom',
Left = 'left',
}
export type OptionHoverProps = {
endpoint: string;
type: string;
side: Side;
};
export type BaseProps = {
conversation: TConversation | TPreset | null;
className?: string;
isPreset?: boolean;
readonly?: boolean;
};
export type SettingsProps = BaseProps & {
setOption: SetOption;
};
export type TModels = {
models: string[];
};
export type ModelSelectProps = SettingsProps & TModels;
export type ExamplesProps = {
readonly?: boolean;
className?: string;
examples: TExample[];
setExample: SetExample;
addExample: () => void;
removeExample: () => void;
};
export type GoogleProps = {
showExamples: boolean;
isCodeChat: boolean;
};
export type GoogleViewProps = SettingsProps & GoogleProps;
export type OptionComponent = React.FC<ModelSelectProps>;
export type MultiViewComponent = React.FC<BaseProps & TModels>;
export type SelectProps = {
conversation: TConversation | null;
setOption: SetOption;
extraProps?: GoogleProps;
};
export type SetOptionsPayload = {
setOption: SetOption;
setExample: SetExample;
addExample: () => void;
removeExample: () => void;
setAgentOption: SetOption;
getConversation: () => TConversation | TPreset | null;
checkPluginSelection: (value: string) => boolean;
setTools: (newValue: string) => void;
};
export type UseSetOptions = (preset?: TPreset | boolean | null) => SetOptionsPayload;
export type UsePresetOptions = (preset?: TPreset | boolean | null) => SetOptionsPayload | boolean;
export type PopoverButton = {
label: string;
buttonClass: string;
handler: () => void;
icon: React.ReactNode;
};
export type EndpointOptionsPopoverProps = {
children: React.ReactNode;
visible: boolean;
endpoint: EModelEndpoint;
saveAsPreset: () => void;
closePopover: () => void;
};
export type EditPresetProps = {
open: boolean;
onOpenChange: React.Dispatch<React.SetStateAction<boolean>>;
preset: TPreset;
title?: string;
};
export type MultiSelectDropDownProps = {
title?: string;
value: Array<{ icon?: string; name?: string; isButton?: boolean }>;
disabled?: boolean;
setSelected: (option: string) => void;
availableValues: TPlugin[];
showAbove?: boolean;
showLabel?: boolean;
containerClassName?: string;
isSelected: (value: string) => boolean;
className?: string;
optionValueKey?: string;
};
export type TError = {
message: string;
code?: number;
response?: {
data?: {
message?: string;
};
};
};
export type CleanupPreset = {
preset: Partial<TPreset>;
endpointsConfig?: TEndpointsConfig | Record<string, unknown>;
};
export type PagesProps = {
pages: number;
pageNumber: number;
setPageNumber: (pageNumber: number) => void;
nextPage: () => Promise<void>;
previousPage: () => Promise<void>;
};