mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
🌿 feat: Fork Messages/Conversations (#2617)
* typedef for ImportBatchBuilder * feat: first pass, fork conversations * feat: fork - getMessagesUpToTargetLevel * fix: additional tests and fix getAllMessagesUpToParent * chore: arrow function return * refactor: fork 3 options * chore: remove unused genbuttons * chore: remove unused hover buttons code * feat: fork first pass * wip: fork remember setting * style: user icon * chore: move clear chats to data tab * WIP: fork UI options * feat: data-provider fork types/services/vars and use generic MutationOptions * refactor: use single param for fork option, use enum, fix mongo errors, use Date.now(), add records flag for testing, use endpoint from original convo and messages, pass originalConvo to finishConversation * feat: add fork mutation hook and consolidate type imports * refactor: use enum * feat: first pass, fork mutation * chore: add enum for target level fork option * chore: add enum for target level fork option * show toast when checking remember selection * feat: splitAtTarget * feat: split at target option * feat: navigate to new fork, show toasts, set result query data * feat: hover info for all fork options * refactor: add Messages settings tab * fix(Fork): remember text info * ci: test for single message and is target edge case * feat: additional tests for getAllMessagesUpToParent * ci: additional tests and cycle detection for getMessagesUpToTargetLevel * feat: circular dependency checks for getAllMessagesUpToParent * fix: getMessagesUpToTargetLevel circular dep. check * ci: more tests for getMessagesForConversation * style: hover text for checkbox fork items * refactor: add statefulness to conversation import
This commit is contained in:
parent
c8baceac76
commit
25fceb78b7
37 changed files with 1831 additions and 523 deletions
|
|
@ -34,6 +34,8 @@ export const deleteConversation = () => `${conversationsRoot}/clear`;
|
|||
|
||||
export const importConversation = () => `${conversationsRoot}/import`;
|
||||
|
||||
export const forkConversation = () => `${conversationsRoot}/fork`;
|
||||
|
||||
export const importConversationJobStatus = (jobId: string) =>
|
||||
`${conversationsRoot}/import/jobs/${jobId}`;
|
||||
|
||||
|
|
|
|||
|
|
@ -653,6 +653,10 @@ export enum SettingsTabValues {
|
|||
* Tab for General Settings
|
||||
*/
|
||||
GENERAL = 'general',
|
||||
/**
|
||||
* Tab for Messages Settings
|
||||
*/
|
||||
MESSAGES = 'messages',
|
||||
/**
|
||||
* Tab for Beta Features
|
||||
*/
|
||||
|
|
@ -698,6 +702,21 @@ export enum LocalStorageKeys {
|
|||
FILES_TO_DELETE = 'filesToDelete',
|
||||
/** Prefix key for the last selected assistant ID by index */
|
||||
ASST_ID_PREFIX = 'assistant_id__',
|
||||
/** Key for the last selected fork setting */
|
||||
FORK_SETTING = 'forkSetting',
|
||||
/** Key for remembering the last selected option, instead of manually selecting */
|
||||
REMEMBER_FORK_OPTION = 'rememberForkOption',
|
||||
/** Key for remembering the split at target fork option modifier */
|
||||
FORK_SPLIT_AT_TARGET = 'splitAtTarget',
|
||||
}
|
||||
|
||||
export enum ForkOptions {
|
||||
/** Key for direct path option */
|
||||
DIRECT_PATH = 'directPath',
|
||||
/** Key for including branches */
|
||||
INCLUDE_BRANCHES = 'includeBranches',
|
||||
/** Key for target level fork (default) */
|
||||
TARGET_LEVEL = '',
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -261,6 +261,10 @@ export const deleteAction = async (
|
|||
|
||||
/* conversations */
|
||||
|
||||
export function forkConversation(payload: t.TForkConvoRequest): Promise<t.TForkConvoResponse> {
|
||||
return request.post(endpoints.forkConversation(), payload);
|
||||
}
|
||||
|
||||
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
||||
//todo: this should be a DELETE request
|
||||
return request.post(endpoints.deleteConversation(), { arg: payload });
|
||||
|
|
|
|||
|
|
@ -125,6 +125,19 @@ export type TDeleteConversationResponse = {
|
|||
};
|
||||
};
|
||||
|
||||
export type TForkConvoRequest = {
|
||||
messageId: string;
|
||||
conversationId: string;
|
||||
option?: string;
|
||||
splitAtTarget?: boolean;
|
||||
latestMessageId?: string;
|
||||
};
|
||||
|
||||
export type TForkConvoResponse = {
|
||||
conversation: TConversation;
|
||||
messages: TMessage[];
|
||||
};
|
||||
|
||||
export type TSearchResults = {
|
||||
conversations: TConversation[];
|
||||
messages: TMessage[];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { TPreset, TDeleteConversationResponse, TDeleteConversationRequest } from '../types';
|
||||
import type * as types from '../types';
|
||||
import {
|
||||
Assistant,
|
||||
AssistantCreateParams,
|
||||
|
|
@ -9,6 +9,18 @@ import {
|
|||
Action,
|
||||
} from './assistants';
|
||||
|
||||
export type MutationOptions<
|
||||
Response,
|
||||
Request,
|
||||
Context = unknown,
|
||||
Error = unknown,
|
||||
Snapshot = void,
|
||||
> = {
|
||||
onSuccess?: (data: Response, variables: Request, context?: Context) => void;
|
||||
onMutate?: (variables: Request) => Snapshot | Promise<Snapshot>;
|
||||
onError?: (error: Error, variables: Request, context?: Context, snapshot?: Snapshot) => void;
|
||||
};
|
||||
|
||||
export type TGenTitleRequest = {
|
||||
conversationId: string;
|
||||
};
|
||||
|
|
@ -22,27 +34,11 @@ export type PresetDeleteResponse = {
|
|||
deletedCount: number;
|
||||
};
|
||||
|
||||
export type UpdatePresetOptions = {
|
||||
onSuccess?: (data: TPreset, variables: TPreset, context?: unknown) => void;
|
||||
onMutate?: (variables: TPreset) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: TPreset, context?: unknown) => void;
|
||||
};
|
||||
export type UpdatePresetOptions = MutationOptions<types.TPreset, types.TPreset>;
|
||||
|
||||
export type DeletePresetOptions = {
|
||||
onSuccess?: (
|
||||
data: PresetDeleteResponse,
|
||||
variables: TPreset | undefined,
|
||||
context?: unknown,
|
||||
) => void;
|
||||
onMutate?: (variables: TPreset | undefined) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: TPreset | undefined, context?: unknown) => void;
|
||||
};
|
||||
export type DeletePresetOptions = MutationOptions<PresetDeleteResponse, types.TPreset | undefined>;
|
||||
|
||||
export type LogoutOptions = {
|
||||
onSuccess?: (data: unknown, variables: undefined, context?: unknown) => void;
|
||||
onMutate?: (variables: undefined) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: undefined, context?: unknown) => void;
|
||||
};
|
||||
export type LogoutOptions = MutationOptions<unknown, undefined>;
|
||||
|
||||
export type AssistantAvatarVariables = {
|
||||
assistant_id: string;
|
||||
|
|
@ -59,53 +55,26 @@ export type UpdateActionVariables = {
|
|||
model: string;
|
||||
};
|
||||
|
||||
export type UploadAssistantAvatarOptions = {
|
||||
onSuccess?: (data: Assistant, variables: AssistantAvatarVariables, context?: unknown) => void;
|
||||
onMutate?: (variables: AssistantAvatarVariables) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: AssistantAvatarVariables, context?: unknown) => void;
|
||||
export type UploadAssistantAvatarOptions = MutationOptions<Assistant, AssistantAvatarVariables>;
|
||||
|
||||
export type CreateAssistantMutationOptions = MutationOptions<Assistant, AssistantCreateParams>;
|
||||
|
||||
export type UpdateAssistantVariables = {
|
||||
assistant_id: string;
|
||||
data: AssistantUpdateParams;
|
||||
};
|
||||
|
||||
export type CreateAssistantMutationOptions = {
|
||||
onSuccess?: (data: Assistant, variables: AssistantCreateParams, context?: unknown) => void;
|
||||
onMutate?: (variables: AssistantCreateParams) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: AssistantCreateParams, context?: unknown) => void;
|
||||
};
|
||||
|
||||
export type UpdateAssistantMutationOptions = {
|
||||
onSuccess?: (
|
||||
data: Assistant,
|
||||
variables: { assistant_id: string; data: AssistantUpdateParams },
|
||||
context?: unknown,
|
||||
) => void;
|
||||
onMutate?: (variables: {
|
||||
assistant_id: string;
|
||||
data: AssistantUpdateParams;
|
||||
}) => void | Promise<unknown>;
|
||||
onError?: (
|
||||
error: unknown,
|
||||
variables: { assistant_id: string; data: AssistantUpdateParams },
|
||||
context?: unknown,
|
||||
) => void;
|
||||
};
|
||||
export type UpdateAssistantMutationOptions = MutationOptions<Assistant, UpdateAssistantVariables>;
|
||||
|
||||
export type DeleteAssistantBody = { assistant_id: string; model: string };
|
||||
|
||||
export type DeleteAssistantMutationOptions = {
|
||||
onSuccess?: (data: void, variables: { assistant_id: string }, context?: unknown) => void;
|
||||
onMutate?: (variables: { assistant_id: string }) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: { assistant_id: string }, context?: unknown) => void;
|
||||
};
|
||||
export type DeleteAssistantMutationOptions = MutationOptions<
|
||||
void,
|
||||
Pick<DeleteAssistantBody, 'assistant_id'>
|
||||
>;
|
||||
|
||||
export type UpdateActionResponse = [AssistantDocument, Assistant, Action];
|
||||
export type UpdateActionOptions = {
|
||||
onSuccess?: (
|
||||
data: UpdateActionResponse,
|
||||
variables: UpdateActionVariables,
|
||||
context?: unknown,
|
||||
) => void;
|
||||
onMutate?: (variables: UpdateActionVariables) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: UpdateActionVariables, context?: unknown) => void;
|
||||
};
|
||||
export type UpdateActionOptions = MutationOptions<UpdateActionResponse, UpdateActionVariables>;
|
||||
|
||||
export type DeleteActionVariables = {
|
||||
assistant_id: string;
|
||||
|
|
@ -113,18 +82,11 @@ export type DeleteActionVariables = {
|
|||
model: string;
|
||||
};
|
||||
|
||||
export type DeleteActionOptions = {
|
||||
onSuccess?: (data: void, variables: DeleteActionVariables, context?: unknown) => void;
|
||||
onMutate?: (variables: DeleteActionVariables) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: DeleteActionVariables, context?: unknown) => void;
|
||||
};
|
||||
export type DeleteActionOptions = MutationOptions<void, DeleteActionVariables>;
|
||||
|
||||
export type DeleteConversationOptions = {
|
||||
onSuccess?: (
|
||||
data: TDeleteConversationResponse,
|
||||
variables: TDeleteConversationRequest,
|
||||
context?: unknown,
|
||||
) => void;
|
||||
onMutate?: (variables: TDeleteConversationRequest) => void | Promise<unknown>;
|
||||
onError?: (error: unknown, variables: TDeleteConversationRequest, context?: unknown) => void;
|
||||
};
|
||||
export type DeleteConversationOptions = MutationOptions<
|
||||
types.TDeleteConversationResponse,
|
||||
types.TDeleteConversationRequest
|
||||
>;
|
||||
|
||||
export type ForkConvoOptions = MutationOptions<types.TForkConvoResponse, types.TForkConvoRequest>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue