Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
✂️ refactor: Move the Markdown Block Splitter and Editable Part Checks Into the Chat Package (#17579)
Marco Beretta608ab0795610
diff --git a/bun.lock b/bun.lockindex 162a43f8b9..9d808a8752 100644--- a/bun.lock+++ b/bun.lock@@ -461,6 +461,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0","react-dom": "^18.2.0","react-i18next": "^15.4.0",@@ -476,6 +483,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0","uuid": "^11.1.1",},diff --git a/client/src/components/Chat/Messages/Content/EditContentParts.tsx b/client/src/components/Chat/Messages/Content/EditContentParts.tsxindex b56366a5e1..538a573c95 100644--- a/client/src/components/Chat/Messages/Content/EditContentParts.tsx+++ b/client/src/components/Chat/Messages/Content/EditContentParts.tsx@@ -1,7 +1,7 @@import { useCallback, useEffect, useMemo, useRef, useState } from 'react';-import { findRerunParent } from '@librechat/chat';import { Alert, Button, TextareaAutosize } from '@librechat/client';import { useUpdateMessageContentMutation } from 'librechat-data-provider/react-query';+import { findRerunParent, getPartText, isEditablePart, withPartText } from '@librechat/chat';import {ContentTypes,findMessageById,@@ -9,7 +9,6 @@ import {} from 'librechat-data-provider';import type { TMessageContentParts } from 'librechat-data-provider';import type { ReactNode } from 'react';-import { getPartText, isEditablePart, withPartText } from './editableParts';import { useMessagePartsHost } from '~/Providers/MessagePartsHostContext';import useGetAddedConvo from '~/hooks/Conversations/useGetAddedConvo';import { useLocalize } from '~/hooks';diff --git a/client/src/components/Chat/Messages/Content/MarkdownBlocks.bench.tsx b/client/src/components/Chat/Messages/Content/MarkdownBlocks.bench.tsxindex abde32408c..c4700ba0c0 100644--- a/client/src/components/Chat/Messages/Content/MarkdownBlocks.bench.tsx+++ b/client/src/components/Chat/Messages/Content/MarkdownBlocks.bench.tsx@@ -1,8 +1,8 @@import React, { Profiler } from 'react';import ReactMarkdown from 'react-markdown';import { render } from '@testing-library/react';+import { splitMarkdownIntoBlocks, splitMarkdownIntoBlocksUncached } from '@librechat/chat';import { getRemarkPlugins, getRehypePlugins, getMarkdownComponents } from './markdownConfig';-import { splitMarkdownIntoBlocks, splitMarkdownIntoBlocksUncached } from './splitMarkdown';import { ArtifactProvider, CodeBlockProvider, MessageContext } from '~/Providers';import CodeBlock from '~/components/Messages/Content/CodeBlock';import MarkdownBlocks from './MarkdownBlocks';diff --git a/client/src/components/Chat/Messages/Content/MarkdownBlocks.tsx b/client/src/components/Chat/Messages/Content/MarkdownBlocks.tsxindex 3d93da5b50..7089497f6c 100644--- a/client/src/components/Chat/Messages/Content/MarkdownBlocks.tsx+++ b/client/src/components/Chat/Messages/Content/MarkdownBlocks.tsx@@ -1,10 +1,10 @@import React, { memo, useMemo, useState, useLayoutEffect } from 'react';import ReactMarkdown from 'react-markdown';+import { createMarkdownSplitter } from '@librechat/chat';+import type { MarkdownSplitter } from '@librechat/chat';import type { PluggableList } from 'unified';import type { ElementType } from 'react';-import type { MarkdownSplitter } from './splitMarkdown';import { ArtifactProvider, CodeBlockProvider } from '~/Providers';-import { createMarkdownSplitter } from './splitMarkdown';import { createFadePlugin } from './animate';type SharedProps = {diff --git a/client/src/components/Chat/Messages/Content/__tests__/MarkdownBlocks.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/MarkdownBlocks.test.tsxindex c8fb5eac72..5bec1315f9 100644--- a/client/src/components/Chat/Messages/Content/__tests__/MarkdownBlocks.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/MarkdownBlocks.test.tsx@@ -2,11 +2,11 @@ import React from 'react';import { RecoilRoot } from 'recoil';import ReactMarkdown from 'react-markdown';import { MemoryRouter } from 'react-router-dom';+import { splitMarkdownIntoBlocks } from '@librechat/chat';import { render, screen, within } from '@testing-library/react';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { getRemarkPlugins, getRehypePlugins, getMarkdownComponents } from '../markdownConfig';import { MessageContext, ArtifactProvider, CodeBlockProvider } from '~/Providers';-import { splitMarkdownIntoBlocks } from '../splitMarkdown';import Markdown from '../Markdown';/**@@ -71,8 +71,8 @@ jest.mock('~/components/Messages/Content/CodeBlock', () => ({}));/** The real splitter, observed: whether a render paid for the block-boundary parse. */-jest.mock('../splitMarkdown', () => {- const actual = jest.requireActual<typeof import('../splitMarkdown')>('../splitMarkdown');+jest.mock('@librechat/chat', () => {+ const actual = jest.requireActual<typeof import('@librechat/chat')>('@librechat/chat');const splitSpy = jest.fn(actual.splitMarkdownIntoBlocks);return {...actual,diff --git a/client/src/components/Chat/Messages/HoverButtons.tsx b/client/src/components/Chat/Messages/HoverButtons.tsxindex 5186d7af95..fd3f549115 100644--- a/client/src/components/Chat/Messages/HoverButtons.tsx+++ b/client/src/components/Chat/Messages/HoverButtons.tsx@@ -2,6 +2,7 @@ import React, { useState, useMemo, useCallback, memo } from 'react';import { Copy, Check } from 'lucide';import { useAtomValue } from 'jotai';import { useRecoilState } from 'recoil';+import { hasEditablePart } from '@librechat/chat';import { hoverButtonClasses } from '@librechat/chat/components';import { revealedQueuedTurnFamily } from '@librechat/chat/react';import { getSpeechText, findMessageById, isUserInitiatedCompaction } from 'librechat-data-provider';@@ -16,7 +17,6 @@ import {import type { TConversation, TMessage, TFeedback } from 'librechat-data-provider';import { useMessagesIsSubmitting, useOptionalMessagesOperations } from '~/Providers';import { useGenerationsByLatest, useLocalize } from '~/hooks';-import { hasEditablePart } from './Content/editableParts';import { Fork } from '~/components/Conversations';import MessageAudio from './MessageAudio';import Feedback from './Feedback';diff --git a/package-lock.json b/package-lock.jsonindex 251b0a0171..923d3f2250 100644--- a/package-lock.json+++ b/package-lock.json@@ -41466,6 +41466,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0","react-dom": "^18.2.0","react-i18next": "^15.4.0",@@ -41482,6 +41489,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0","uuid": "^11.1.1"}diff --git a/packages/chat/jest.config.js b/packages/chat/jest.config.jsindex b627d8dfc9..dff802c5c8 100644--- a/packages/chat/jest.config.js+++ b/packages/chat/jest.config.js@@ -6,10 +6,10 @@ module.exports = {coverageReporters: ['text', 'cobertura'],maxWorkers,restoreMocks: true,- // sse.js and some of @librechat/client's dependencies ship ES modules only, so jest transforms- // them like the package's own sources.+ // sse.js, some of @librechat/client's dependencies and the micromark/mdast markdown parser+ // ship ES modules only, so jest transforms them like the package's own sources.transformIgnorePatterns: [- '/node_modules/(?!(sse\\.js|@dicebear|lucide|lucide-react|morphicons|@ariakit/(react-components|react-utils|react-store|components|store|utils))/)',+ '/node_modules/(?!(sse\\.js|@dicebear|lucide|lucide-react|morphicons|@ariakit/(react-components|react-utils|react-store|components|store|utils)|micromark.*|mdast-.*|unist-.*|decode-named-character-reference|character-.*|devlop|ccount|longest-streak|markdown-table|zwitch|escape-string-regexp|parse-entities|stringify-entities|is-.*)/)',],// The component library's resolver: its ESM-only @ariakit packages need the `import` condition.resolver: '<rootDir>/../client/jest.resolver.cjs',diff --git a/packages/chat/package.json b/packages/chat/package.jsonindex 5f7c8eabb3..a6c43ce49f 100644--- a/packages/chat/package.json+++ b/packages/chat/package.json@@ -65,6 +65,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0 || ^19.1.0","uuid": "^11.1.1"},@@ -90,6 +97,13 @@"librechat-data-provider": "*","lucide": "^0.528.0","lucide-react": "^0.528.0",+ "mdast-util-directive": "^3.0.0",+ "mdast-util-from-markdown": "^2.0.1",+ "mdast-util-gfm": "^3.0.0",+ "mdast-util-math": "^3.0.0",+ "micromark-extension-directive": "^3.0.1",+ "micromark-extension-gfm": "^3.0.0",+ "micromark-extension-math": "^3.1.0","react": "^18.2.0","react-dom": "^18.2.0","react-i18next": "^15.4.0",diff --git a/client/src/components/Chat/Messages/Content/__tests__/editableParts.spec.ts b/packages/chat/src/core/parts/__tests__/editableParts.spec.tssimilarity index 100%rename from client/src/components/Chat/Messages/Content/__tests__/editableParts.spec.tsrename to packages/chat/src/core/parts/__tests__/editableParts.spec.tsdiff --git a/client/src/components/Chat/Messages/Content/__tests__/splitMarkdown.test.ts b/packages/chat/src/core/parts/__tests__/splitMarkdown.spec.tssimilarity index 100%rename from client/src/components/Chat/Messages/Content/__tests__/splitMarkdown.test.tsrename to packages/chat/src/core/parts/__tests__/splitMarkdown.spec.tsdiff --git a/client/src/components/Chat/Messages/Content/editableParts.ts b/packages/chat/src/core/parts/editableParts.tssimilarity index 100%rename from client/src/components/Chat/Messages/Content/editableParts.tsrename to packages/chat/src/core/parts/editableParts.tsdiff --git a/packages/chat/src/core/parts/index.ts b/packages/chat/src/core/parts/index.tsindex 163730451c..17d3c881c5 100644--- a/packages/chat/src/core/parts/index.ts+++ b/packages/chat/src/core/parts/index.ts@@ -6,3 +6,5 @@ export * from './command';export * from './routing';export * from './params';export * from './rerunParent';+export * from './splitMarkdown';+export * from './editableParts';diff --git a/client/src/components/Chat/Messages/Content/splitMarkdown.ts b/packages/chat/src/core/parts/splitMarkdown.tssimilarity index 99%rename from client/src/components/Chat/Messages/Content/splitMarkdown.tsrename to packages/chat/src/core/parts/splitMarkdown.tsindex af2b59c234..fc2b2a5d89 100644--- a/client/src/components/Chat/Messages/Content/splitMarkdown.ts+++ b/packages/chat/src/core/parts/splitMarkdown.ts@@ -235,7 +235,7 @@ export function createMarkdownSplitter(): MarkdownSplitter {};}-export const splitMarkdownIntoBlocks = createMarkdownSplitter();+export const splitMarkdownIntoBlocks: MarkdownSplitter = createMarkdownSplitter();const blockCounts = (children: MdastNode[],