mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🛠️ fix: Restrict Editable Content Types & Consolidate Typing (#9173)
* fix: only allow editing expected content types & align typing app-wide * chore: update TPayload to use TEditedContent type for editedContent
This commit is contained in:
parent
da4aa37493
commit
49cd3894aa
5 changed files with 39 additions and 18 deletions
|
|
@ -336,6 +336,7 @@ export type TAskProps = {
|
||||||
|
|
||||||
export type TOptions = {
|
export type TOptions = {
|
||||||
editedMessageId?: string | null;
|
editedMessageId?: string | null;
|
||||||
|
editedContent?: t.TEditedContent;
|
||||||
editedText?: string | null;
|
editedText?: string | null;
|
||||||
isRegenerate?: boolean;
|
isRegenerate?: boolean;
|
||||||
isContinued?: boolean;
|
isContinued?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,12 @@ const ContentParts = memo(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isToolCall =
|
||||||
|
part.type === ContentTypes.TOOL_CALL || part['tool_call_ids'] != null;
|
||||||
|
if (isToolCall) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditTextPart
|
<EditTextPart
|
||||||
index={idx}
|
index={idx}
|
||||||
|
|
|
||||||
|
|
@ -62,17 +62,26 @@ const EditTextPart = ({
|
||||||
const messages = getMessages();
|
const messages = getMessages();
|
||||||
const parentMessage = messages?.find((msg) => msg.messageId === message?.parentMessageId);
|
const parentMessage = messages?.find((msg) => msg.messageId === message?.parentMessageId);
|
||||||
|
|
||||||
|
const editedContent =
|
||||||
|
part.type === ContentTypes.THINK
|
||||||
|
? {
|
||||||
|
index,
|
||||||
|
type: ContentTypes.THINK as const,
|
||||||
|
[ContentTypes.THINK]: data.text,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
index,
|
||||||
|
type: ContentTypes.TEXT as const,
|
||||||
|
[ContentTypes.TEXT]: data.text,
|
||||||
|
};
|
||||||
|
|
||||||
if (!parentMessage) {
|
if (!parentMessage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ask(
|
ask(
|
||||||
{ ...parentMessage },
|
{ ...parentMessage },
|
||||||
{
|
{
|
||||||
editedContent: {
|
editedContent,
|
||||||
index,
|
|
||||||
text: data.text,
|
|
||||||
type: part.type,
|
|
||||||
},
|
|
||||||
editedMessageId: messageId,
|
editedMessageId: messageId,
|
||||||
isRegenerate: true,
|
isRegenerate: true,
|
||||||
isEdited: true,
|
isEdited: true,
|
||||||
|
|
|
||||||
|
|
@ -267,13 +267,13 @@ export default function useChatFunctions({
|
||||||
|
|
||||||
if (editedContent && latestMessage?.content) {
|
if (editedContent && latestMessage?.content) {
|
||||||
initialResponse.content = cloneDeep(latestMessage.content);
|
initialResponse.content = cloneDeep(latestMessage.content);
|
||||||
const { index, text, type } = editedContent;
|
const { index, type, ...part } = editedContent;
|
||||||
if (initialResponse.content && index >= 0 && index < initialResponse.content.length) {
|
if (initialResponse.content && index >= 0 && index < initialResponse.content.length) {
|
||||||
const contentPart = initialResponse.content[index];
|
const contentPart = initialResponse.content[index];
|
||||||
if (type === ContentTypes.THINK && contentPart.type === ContentTypes.THINK) {
|
if (type === ContentTypes.THINK && contentPart.type === ContentTypes.THINK) {
|
||||||
contentPart[ContentTypes.THINK] = text;
|
contentPart[ContentTypes.THINK] = part[ContentTypes.THINK];
|
||||||
} else if (type === ContentTypes.TEXT && contentPart.type === ContentTypes.TEXT) {
|
} else if (type === ContentTypes.TEXT && contentPart.type === ContentTypes.TEXT) {
|
||||||
contentPart[ContentTypes.TEXT] = text;
|
contentPart[ContentTypes.TEXT] = part[ContentTypes.TEXT];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import type {
|
||||||
} from './schemas';
|
} from './schemas';
|
||||||
import type { SettingDefinition } from './generate';
|
import type { SettingDefinition } from './generate';
|
||||||
import type { TMinimalFeedback } from './feedback';
|
import type { TMinimalFeedback } from './feedback';
|
||||||
|
import type { ContentTypes } from './types/runs';
|
||||||
import type { Agent } from './types/assistants';
|
import type { Agent } from './types/assistants';
|
||||||
|
|
||||||
export * from './schemas';
|
export * from './schemas';
|
||||||
|
|
@ -108,13 +109,21 @@ export type TPayload = Partial<TMessage> &
|
||||||
messages?: TMessages;
|
messages?: TMessages;
|
||||||
isTemporary: boolean;
|
isTemporary: boolean;
|
||||||
ephemeralAgent?: TEphemeralAgent | null;
|
ephemeralAgent?: TEphemeralAgent | null;
|
||||||
editedContent?: {
|
editedContent?: TEditedContent | null;
|
||||||
index: number;
|
|
||||||
text: string;
|
|
||||||
type: 'text' | 'think';
|
|
||||||
} | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TEditedContent =
|
||||||
|
| {
|
||||||
|
index: number;
|
||||||
|
type: ContentTypes.THINK;
|
||||||
|
[ContentTypes.THINK]: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
index: number;
|
||||||
|
type: ContentTypes.TEXT;
|
||||||
|
[ContentTypes.TEXT]: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type TSubmission = {
|
export type TSubmission = {
|
||||||
plugin?: TResPlugin;
|
plugin?: TResPlugin;
|
||||||
plugins?: TResPlugin[];
|
plugins?: TResPlugin[];
|
||||||
|
|
@ -129,11 +138,7 @@ export type TSubmission = {
|
||||||
endpointOption: TEndpointOption;
|
endpointOption: TEndpointOption;
|
||||||
clientTimestamp?: string;
|
clientTimestamp?: string;
|
||||||
ephemeralAgent?: TEphemeralAgent | null;
|
ephemeralAgent?: TEphemeralAgent | null;
|
||||||
editedContent?: {
|
editedContent?: TEditedContent | null;
|
||||||
index: number;
|
|
||||||
text: string;
|
|
||||||
type: 'text' | 'think';
|
|
||||||
} | null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EventSubmission = Omit<TSubmission, 'initialResponse'> & { initialResponse: TMessage };
|
export type EventSubmission = Omit<TSubmission, 'initialResponse'> & { initialResponse: TMessage };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue