mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-31 23:58:50 +01:00
* wip: initial client side code * wip: initial api code * refactor: export query keys from own module, export assistant hooks * refactor(SelectDropDown): more customization via props * feat: create Assistant and render real Assistants * refactor: major refactor of UI components to allow multi-chat, working alongside CreationPanel * refactor: move assistant routes to own directory * fix(CreationHeader): state issue with assistant select * refactor: style changes for form, fix setSiblingIdx from useChatHelpers to use latestMessageParentId, fix render issue with ChatView and change location * feat: parseCompactConvo: begin refactor of slimmer JSON payloads between client/api * refactor(endpoints): add assistant endpoint, also use EModelEndpoint as much as possible * refactor(useGetConversationsQuery): use object to access query data easily * fix(MultiMessage): react warning of bad state set, making use of effect during render (instead of useEffect) * fix(useNewConvo): use correct atom key (index instead of convoId) for reset latestMessageFamily * refactor: make routing navigation/conversation change simpler * chore: add removeNullishValues for smaller payloads, remove unused fields, setup frontend pinging of assistant endpoint * WIP: initial complete assistant run handling * fix: CreationPanel form correctly setting internal state * refactor(api/assistants/chat): revise functions to working run handling strategy * refactor(UI): initial major refactor of ChatForm and options * feat: textarea hook * refactor: useAuthRedirect hook and change directory name * feat: add ChatRoute (/c/), make optionsBar absolute and change on textarea height, add temp header * feat: match new toggle Nav open button to ChatGPT's * feat: add OpenAI custom classnames * feat: useOriginNavigate * feat: messages loading view * fix: conversation navigation and effects * refactor: make toggle change nav opacity * WIP: new endpoint menu * feat: NewEndpointsMenu complete * fix: ensure set key dialog shows on endpoint change, and new conversation resets messages * WIP: textarea styling fix, add temp footer, create basic file handling component * feat: image file handling (UI) * feat: PopOver and ModelSelect in Header, remove GenButtons * feat: drop file handling * refactor: bug fixes use SSE at route level add opts to useOriginNavigate delay render of unfinishedMessage to avoid flickering pass params (convoId) to chatHelpers to set messages query data based on param when the route is new (fixes can't continue convo on /new/) style(MessagesView): matches height to official fix(SSE): pass paramId and invalidate convos style(Message): make bg uniform * refactor(useSSE): setStorage within setConversation updates * feat: conversationKeysAtom, allConversationsSelector, update convos query data on created message (if new), correctly handle convo deletion (individual) * feat: add popover select dropdowns to allow options in header while allowing horizontal scroll for mobile * style(pluginsSelect): styling changes * refactor(NewEndpointsMenu): make UI components modular * feat: Presets complete * fix: preset editing, make by index * fix: conversations not setting on inital navigation, fix getMessages() based on query param * fix: changing preset no longer resets latestMessage * feat: useOnClickOutside for OptionsPopover and fix bug that causes selection of preset when deleting * fix: revert /chat/ switchToConvo, also use NewDeleteButton in Convo * fix: Popover correctly closes on close Popover button using custom condition for useOnClickOutside * style: new message and nav styling * style: hover/sibling buttons and preset menu scrolling * feat: new convo header button * style(Textarea): minor style changes to textarea buttons * feat: stop/continue generating and hide hoverbuttons when submitting * feat: compact AI Provider schemas to make json payloads and db saves smaller * style: styling changes for consistency on chat route * fix: created usePresetIndexOptions to prevent bugs between /c/ and /chat/ routes when editing presets, removed redundant code from the new dialog * chore: make /chat/ route default for now since we still lack full image support
185 lines
5.4 KiB
TypeScript
185 lines
5.4 KiB
TypeScript
import * as t from './types';
|
|
import * as s from './schemas';
|
|
/* TODO: fix dependency cycle */
|
|
// eslint-disable-next-line import/no-cycle
|
|
import request from './request';
|
|
import * as endpoints from './api-endpoints';
|
|
|
|
export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
|
|
return request.get(endpoints.conversations(pageNumber));
|
|
}
|
|
|
|
export function abortRequestWithMessage(
|
|
endpoint: string,
|
|
abortKey: string,
|
|
message: string,
|
|
): Promise<void> {
|
|
return request.post(endpoints.abortRequest(endpoint), { arg: { abortKey, message } });
|
|
}
|
|
|
|
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
|
//todo: this should be a DELETE request
|
|
return request.post(endpoints.deleteConversation(), { arg: payload });
|
|
}
|
|
|
|
export function clearAllConversations(): Promise<unknown> {
|
|
return request.post(endpoints.deleteConversation(), { arg: {} });
|
|
}
|
|
|
|
export function revokeUserKey(name: string): Promise<unknown> {
|
|
return request.delete(endpoints.revokeUserKey(name));
|
|
}
|
|
|
|
export function revokeAllUserKeys(): Promise<unknown> {
|
|
return request.delete(endpoints.revokeAllUserKeys());
|
|
}
|
|
|
|
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
if (conversationId === 'new') {
|
|
return Promise.resolve([]);
|
|
}
|
|
return request.get(endpoints.messages(conversationId));
|
|
}
|
|
|
|
export function getConversationById(id: string): Promise<s.TConversation> {
|
|
return request.get(endpoints.conversationById(id));
|
|
}
|
|
|
|
export function updateConversation(
|
|
payload: t.TUpdateConversationRequest,
|
|
): Promise<t.TUpdateConversationResponse> {
|
|
return request.post(endpoints.updateConversation(), { arg: payload });
|
|
}
|
|
|
|
export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
|
|
const { conversationId, messageId, text } = payload;
|
|
if (!conversationId) {
|
|
throw new Error('conversationId is required');
|
|
}
|
|
|
|
return request.put(endpoints.messages(conversationId, messageId), { text });
|
|
}
|
|
|
|
export function updateUserKey(payload: t.TUpdateUserKeyRequest) {
|
|
const { value } = payload;
|
|
if (!value) {
|
|
throw new Error('value is required');
|
|
}
|
|
|
|
return request.put(endpoints.keys(), payload);
|
|
}
|
|
|
|
export function getPresets(): Promise<s.TPreset[]> {
|
|
return request.get(endpoints.presets());
|
|
}
|
|
|
|
export function createPreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
|
return request.post(endpoints.presets(), payload);
|
|
}
|
|
|
|
export function updatePreset(payload: s.TPreset): Promise<s.TPreset[]> {
|
|
return request.post(endpoints.presets(), payload);
|
|
}
|
|
|
|
export function deletePreset(arg: s.TPreset | object): Promise<s.TPreset[]> {
|
|
return request.post(endpoints.deletePreset(), arg);
|
|
}
|
|
|
|
export function getSearchEnabled(): Promise<boolean> {
|
|
return request.get(endpoints.searchEnabled());
|
|
}
|
|
|
|
export function getUser(): Promise<t.TUser> {
|
|
return request.get(endpoints.user());
|
|
}
|
|
|
|
export function getUserBalance(): Promise<string> {
|
|
return request.get(endpoints.balance());
|
|
}
|
|
|
|
export const searchConversations = async (
|
|
q: string,
|
|
pageNumber: string,
|
|
): Promise<t.TSearchResults> => {
|
|
return request.get(endpoints.search(q, pageNumber));
|
|
};
|
|
|
|
export const getAIEndpoints = (): Promise<t.TEndpointsConfig> => {
|
|
return request.get(endpoints.aiEndpoints());
|
|
};
|
|
|
|
export const getModels = async (): Promise<t.TModelsConfig> => {
|
|
return request.get(endpoints.models());
|
|
};
|
|
|
|
export const updateTokenCount = (text: string) => {
|
|
return request.post(endpoints.tokenizer(), { arg: text });
|
|
};
|
|
|
|
export const login = (payload: t.TLoginUser) => {
|
|
return request.post(endpoints.login(), payload);
|
|
};
|
|
|
|
export const logout = () => {
|
|
return request.post(endpoints.logout());
|
|
};
|
|
|
|
export const register = (payload: t.TRegisterUser) => {
|
|
return request.post(endpoints.register(), payload);
|
|
};
|
|
|
|
export const refreshToken = (retry?: boolean) => request.post(endpoints.refreshToken(retry));
|
|
|
|
export const userKeyQuery = (name: string): Promise<t.TCheckUserKeyResponse> =>
|
|
request.get(endpoints.userKeyQuery(name));
|
|
|
|
export const getLoginGoogle = () => {
|
|
return request.get(endpoints.loginGoogle());
|
|
};
|
|
|
|
export const requestPasswordReset = (
|
|
payload: t.TRequestPasswordReset,
|
|
): Promise<t.TRequestPasswordResetResponse> => {
|
|
return request.post(endpoints.requestPasswordReset(), payload);
|
|
};
|
|
|
|
export const resetPassword = (payload: t.TResetPassword) => {
|
|
return request.post(endpoints.resetPassword(), payload);
|
|
};
|
|
|
|
export const getAvailablePlugins = (): Promise<s.TPlugin[]> => {
|
|
return request.get(endpoints.plugins());
|
|
};
|
|
|
|
export const updateUserPlugins = (payload: t.TUpdateUserPlugins) => {
|
|
return request.post(endpoints.userPlugins(), payload);
|
|
};
|
|
|
|
export const getStartupConfig = (): Promise<t.TStartupConfig> => {
|
|
return request.get(endpoints.config());
|
|
};
|
|
|
|
export const createAssistant = (data: t.AssistantCreateParams): Promise<t.Assistant> => {
|
|
return request.post(endpoints.assistants(), data);
|
|
};
|
|
|
|
export const getAssistantById = (assistant_id: string): Promise<t.Assistant> => {
|
|
return request.get(endpoints.assistants(assistant_id));
|
|
};
|
|
|
|
export const updateAssistant = (
|
|
assistant_id: string,
|
|
data: t.AssistantUpdateParams,
|
|
): Promise<t.Assistant> => {
|
|
return request.patch(endpoints.assistants(assistant_id), data);
|
|
};
|
|
|
|
export const deleteAssistant = (assistant_id: string): Promise<void> => {
|
|
return request.delete(endpoints.assistants(assistant_id));
|
|
};
|
|
|
|
export const listAssistants = (
|
|
params?: t.AssistantListParams,
|
|
): Promise<t.AssistantListResponse> => {
|
|
return request.get(endpoints.assistants(), { params });
|
|
};
|