mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-03 17:18:51 +01:00
🔀 fix: MCP Improvements, Auto-Save Drafts, Artifact Markup (#7040)
* feat: Update MCP tool creation to use lowercase provider name * refactor: handle MCP image output edge cases where tool outputs must contain string responses * feat: Drop 'anyOf' and 'oneOf' fields from JSON schema conversion * feat: Transform 'oneOf' and 'anyOf' fields to Zod union in JSON schema conversion * fix: artifactPlugin to replace textDirective with expected text, closes #7029 * fix: auto-save functionality to handle conversation transitions from pending drafts, closes #7027 * refactor: improve async handling during user disconnection process * fix: use correct user ID variable for MCP tool calling * fix: improve handling of pending drafts in auto-save functionality * fix: add support for additional model names in getValueKey function * fix: reset form values on agent deletion when no agents remain
This commit is contained in:
parent
150116eefe
commit
7f1d01c35a
12 changed files with 856 additions and 73 deletions
|
|
@ -11,7 +11,16 @@ import ArtifactButton from './ArtifactButton';
|
|||
|
||||
export const artifactPlugin: Pluggable = () => {
|
||||
return (tree) => {
|
||||
visit(tree, ['textDirective', 'leafDirective', 'containerDirective'], (node) => {
|
||||
visit(tree, ['textDirective', 'leafDirective', 'containerDirective'], (node, index, parent) => {
|
||||
if (node.type === 'textDirective') {
|
||||
const replacementText = `:${node.name}`;
|
||||
if (parent && Array.isArray(parent.children) && typeof index === 'number') {
|
||||
parent.children[index] = {
|
||||
type: 'text',
|
||||
value: replacementText,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (node.name !== 'artifact') {
|
||||
return;
|
||||
}
|
||||
|
|
@ -26,7 +35,6 @@ export const artifactPlugin: Pluggable = () => {
|
|||
};
|
||||
|
||||
export function Artifact({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
node,
|
||||
...props
|
||||
}: Artifact & {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { useFormContext } from 'react-hook-form';
|
||||
import { defaultAgentFormValues } from 'librechat-data-provider';
|
||||
import type { Agent, AgentCreateParams } from 'librechat-data-provider';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import { OGDialog, OGDialogTrigger, Label } from '~/components/ui';
|
||||
|
|
@ -18,6 +20,7 @@ export default function DeleteButton({
|
|||
createMutation: UseMutationResult<Agent, Error, AgentCreateParams>;
|
||||
}) {
|
||||
const localize = useLocalize();
|
||||
const { reset } = useFormContext();
|
||||
const { showToast } = useToastContext();
|
||||
const { conversation } = useChatContext();
|
||||
const { setOption } = useSetIndexOptions();
|
||||
|
|
@ -41,6 +44,10 @@ export default function DeleteButton({
|
|||
|
||||
const firstAgent = updatedList[0] as Agent | undefined;
|
||||
if (!firstAgent) {
|
||||
setCurrentAgentId(undefined);
|
||||
reset({
|
||||
...defaultAgentFormValues,
|
||||
});
|
||||
return setOption('agent_id')('');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import debounce from 'lodash/debounce';
|
||||
import { SetterOrUpdater, useRecoilValue } from 'recoil';
|
||||
import { useState, useEffect, useMemo, useCallback } from 'react';
|
||||
import { useState, useEffect, useMemo, useCallback, useRef } from 'react';
|
||||
import { LocalStorageKeys, Constants } from 'librechat-data-provider';
|
||||
import type { TFile } from 'librechat-data-provider';
|
||||
import type { ExtendedFile } from '~/common';
|
||||
|
|
@ -159,6 +159,8 @@ export const useAutoSave = ({
|
|||
};
|
||||
}, [conversationId, saveDrafts, textAreaRef]);
|
||||
|
||||
const prevConversationIdRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// This useEffect is responsible for saving the current conversation's draft and
|
||||
// restoring the new conversation's draft when switching between conversations.
|
||||
|
|
@ -176,7 +178,28 @@ export const useAutoSave = ({
|
|||
setFiles(new Map());
|
||||
|
||||
try {
|
||||
if (currentConversationId != null && currentConversationId) {
|
||||
// Check for transition from PENDING_CONVO to a valid conversationId
|
||||
if (
|
||||
prevConversationIdRef.current === Constants.PENDING_CONVO &&
|
||||
conversationId !== Constants.PENDING_CONVO &&
|
||||
conversationId.length > 3
|
||||
) {
|
||||
const pendingDraft = localStorage.getItem(
|
||||
`${LocalStorageKeys.TEXT_DRAFT}${Constants.PENDING_CONVO}`,
|
||||
);
|
||||
|
||||
// Clear the pending draft, if it exists, and save the current draft to the new conversationId;
|
||||
// otherwise, save the current text area value to the new conversationId
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${Constants.PENDING_CONVO}`);
|
||||
if (pendingDraft) {
|
||||
localStorage.setItem(`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`, pendingDraft);
|
||||
} else if (textAreaRef?.current?.value) {
|
||||
localStorage.setItem(
|
||||
`${LocalStorageKeys.TEXT_DRAFT}${conversationId}`,
|
||||
encodeBase64(textAreaRef.current.value),
|
||||
);
|
||||
}
|
||||
} else if (currentConversationId != null && currentConversationId) {
|
||||
saveText(currentConversationId);
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +209,13 @@ export const useAutoSave = ({
|
|||
console.error(e);
|
||||
}
|
||||
|
||||
prevConversationIdRef.current = conversationId;
|
||||
setCurrentConversationId(conversationId);
|
||||
}, [
|
||||
conversationId,
|
||||
currentConversationId,
|
||||
conversationId,
|
||||
restoreFiles,
|
||||
textAreaRef,
|
||||
restoreText,
|
||||
saveDrafts,
|
||||
saveText,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue