diff --git a/client/src/common/types.ts b/client/src/common/types.ts index 5e001c758..3035a37b1 100644 --- a/client/src/common/types.ts +++ b/client/src/common/types.ts @@ -336,6 +336,7 @@ export type TAskProps = { export type TOptions = { editedMessageId?: string | null; + editedContent?: t.TEditedContent; editedText?: string | null; isRegenerate?: boolean; isContinued?: boolean; diff --git a/client/src/components/Chat/Messages/Content/ContentParts.tsx b/client/src/components/Chat/Messages/Content/ContentParts.tsx index dcda323c5..5dc9f25f6 100644 --- a/client/src/components/Chat/Messages/Content/ContentParts.tsx +++ b/client/src/components/Chat/Messages/Content/ContentParts.tsx @@ -94,6 +94,12 @@ const ContentParts = memo( return null; } + const isToolCall = + part.type === ContentTypes.TOOL_CALL || part['tool_call_ids'] != null; + if (isToolCall) { + return null; + } + return ( 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) { return; } ask( { ...parentMessage }, { - editedContent: { - index, - text: data.text, - type: part.type, - }, + editedContent, editedMessageId: messageId, isRegenerate: true, isEdited: true, diff --git a/client/src/hooks/Chat/useChatFunctions.ts b/client/src/hooks/Chat/useChatFunctions.ts index cf2f020dd..37f7b5913 100644 --- a/client/src/hooks/Chat/useChatFunctions.ts +++ b/client/src/hooks/Chat/useChatFunctions.ts @@ -267,13 +267,13 @@ export default function useChatFunctions({ if (editedContent && 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) { const contentPart = initialResponse.content[index]; 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) { - contentPart[ContentTypes.TEXT] = text; + contentPart[ContentTypes.TEXT] = part[ContentTypes.TEXT]; } } } else { diff --git a/packages/data-provider/src/types.ts b/packages/data-provider/src/types.ts index 453fad960..55bc376d8 100644 --- a/packages/data-provider/src/types.ts +++ b/packages/data-provider/src/types.ts @@ -11,6 +11,7 @@ import type { } from './schemas'; import type { SettingDefinition } from './generate'; import type { TMinimalFeedback } from './feedback'; +import type { ContentTypes } from './types/runs'; import type { Agent } from './types/assistants'; export * from './schemas'; @@ -108,13 +109,21 @@ export type TPayload = Partial & messages?: TMessages; isTemporary: boolean; ephemeralAgent?: TEphemeralAgent | null; - editedContent?: { - index: number; - text: string; - type: 'text' | 'think'; - } | null; + editedContent?: TEditedContent | null; }; +export type TEditedContent = + | { + index: number; + type: ContentTypes.THINK; + [ContentTypes.THINK]: string; + } + | { + index: number; + type: ContentTypes.TEXT; + [ContentTypes.TEXT]: string; + }; + export type TSubmission = { plugin?: TResPlugin; plugins?: TResPlugin[]; @@ -129,11 +138,7 @@ export type TSubmission = { endpointOption: TEndpointOption; clientTimestamp?: string; ephemeralAgent?: TEphemeralAgent | null; - editedContent?: { - index: number; - text: string; - type: 'text' | 'think'; - } | null; + editedContent?: TEditedContent | null; }; export type EventSubmission = Omit & { initialResponse: TMessage };