mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-15 11:22:10 +08:00
* fix: remove project dependency from settings controller and onboarding * fix(settings): remove onClose prop from useSettingsController args * chore: tailwind classes order * refactor: move provider auth status management to custom hook * refactor: rename SessionProvider to LLMProvider * feat(frontend): support for @ alias based imports) * fix: replace init.sql with schema.js * fix: refactor database initialization to use schema.js for SQL statements * feat(server): add a real backend TypeScript build and enforce module boundaries The backend had started to grow beyond what the frontend-only tooling setup could support safely. We were still running server code directly from /server, linting mainly the client, and relying on path assumptions such as "../.." that only worked in the source layout. That created three problems: - backend alias imports were hard to resolve consistently in the editor, ESLint, and the runtime - server code had no enforced module boundary rules, so cross-module deep imports could bypass intended public entry points - building the backend into a separate output directory would break repo-level lookups for package.json, .env, dist, and public assets because those paths were derived from source-only relative assumptions This change makes the backend tooling explicit and runtime-safe. A dedicated backend TypeScript config now lives in server/tsconfig.json, with tsconfig.server.json reduced to a compatibility shim. This gives the language service and backend tooling a canonical project rooted in /server while still preserving top-level compatibility for any existing references. The backend alias mapping now resolves relative to /server, which avoids colliding with the frontend's "@/..." -> "src/*" mapping. The package scripts were updated so development runs through tsx with the backend tsconfig, build now produces a compiled backend in dist-server, and typecheck/lint cover both client and server. A new build-server.mjs script runs TypeScript and tsc-alias and cleans dist-server first, which prevents stale compiled files from shadowing current source files after refactors. To make the compiled backend behave the same as the source backend, runtime path resolution was centralized in server/utils/runtime-paths.js. Instead of assuming fixed relative paths from each module, server entry points now resolve the actual app root and server root at runtime. That keeps package.json, .env, dist, public, and default database paths stable whether code is executed from /server or from /dist-server/server. ESLint was expanded from a frontend-only setup into a backend-aware one. The backend now uses import resolution tied to the backend tsconfig so aliased imports resolve correctly in linting, import ordering matches the frontend style, and unused/duplicate imports are surfaced consistently. Most importantly, eslint-plugin-boundaries now enforces server module boundaries. Files under server/modules can no longer import another module's internals directly. Cross-module imports must go through that module's barrel file (index.ts/index.js). boundaries/no-unknown was also enabled so alias-resolution gaps cannot silently bypass the rule. Together, these changes make the backend buildable, keep runtime path resolution stable after compilation, align server tooling with the client where appropriate, and enforce a stricter modular architecture for server code. * fix: update package.json to include dist-server in files and remove tsconfig.server.json * refactor: remove build-server.mjs and inline its logic into package.json scripts * fix: update paths in package.json and bin.js to use dist-server directory * feat(eslint): add backend shared types and enforce compile-time contract for imports * fix(eslint): update shared types pattern --------- Co-authored-by: Haileyesus <something@gmail.com>
265 lines
10 KiB
TypeScript
265 lines
10 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { useCallback, useRef } from 'react';
|
|
import type { Dispatch, RefObject, SetStateAction } from 'react';
|
|
import type { ChatMessage } from '../../types/types';
|
|
import type { Project, ProjectSession, LLMProvider } from '../../../../types/app';
|
|
import { getIntrinsicMessageKey } from '../../utils/messageKeys';
|
|
import MessageComponent from './MessageComponent';
|
|
import ProviderSelectionEmptyState from './ProviderSelectionEmptyState';
|
|
|
|
interface ChatMessagesPaneProps {
|
|
scrollContainerRef: RefObject<HTMLDivElement>;
|
|
onWheel: () => void;
|
|
onTouchMove: () => void;
|
|
isLoadingSessionMessages: boolean;
|
|
chatMessages: ChatMessage[];
|
|
selectedSession: ProjectSession | null;
|
|
currentSessionId: string | null;
|
|
provider: LLMProvider;
|
|
setProvider: (provider: LLMProvider) => void;
|
|
textareaRef: RefObject<HTMLTextAreaElement>;
|
|
claudeModel: string;
|
|
setClaudeModel: (model: string) => void;
|
|
cursorModel: string;
|
|
setCursorModel: (model: string) => void;
|
|
codexModel: string;
|
|
setCodexModel: (model: string) => void;
|
|
geminiModel: string;
|
|
setGeminiModel: (model: string) => void;
|
|
tasksEnabled: boolean;
|
|
isTaskMasterInstalled: boolean | null;
|
|
onShowAllTasks?: (() => void) | null;
|
|
setInput: Dispatch<SetStateAction<string>>;
|
|
isLoadingMoreMessages: boolean;
|
|
hasMoreMessages: boolean;
|
|
totalMessages: number;
|
|
sessionMessagesCount: number;
|
|
visibleMessageCount: number;
|
|
visibleMessages: ChatMessage[];
|
|
loadEarlierMessages: () => void;
|
|
loadAllMessages: () => void;
|
|
allMessagesLoaded: boolean;
|
|
isLoadingAllMessages: boolean;
|
|
loadAllJustFinished: boolean;
|
|
showLoadAllOverlay: boolean;
|
|
createDiff: any;
|
|
onFileOpen?: (filePath: string, diffInfo?: unknown) => void;
|
|
onShowSettings?: () => void;
|
|
onGrantToolPermission: (suggestion: { entry: string; toolName: string }) => { success: boolean };
|
|
autoExpandTools?: boolean;
|
|
showRawParameters?: boolean;
|
|
showThinking?: boolean;
|
|
selectedProject: Project;
|
|
}
|
|
|
|
export default function ChatMessagesPane({
|
|
scrollContainerRef,
|
|
onWheel,
|
|
onTouchMove,
|
|
isLoadingSessionMessages,
|
|
chatMessages,
|
|
selectedSession,
|
|
currentSessionId,
|
|
provider,
|
|
setProvider,
|
|
textareaRef,
|
|
claudeModel,
|
|
setClaudeModel,
|
|
cursorModel,
|
|
setCursorModel,
|
|
codexModel,
|
|
setCodexModel,
|
|
geminiModel,
|
|
setGeminiModel,
|
|
tasksEnabled,
|
|
isTaskMasterInstalled,
|
|
onShowAllTasks,
|
|
setInput,
|
|
isLoadingMoreMessages,
|
|
hasMoreMessages,
|
|
totalMessages,
|
|
sessionMessagesCount,
|
|
visibleMessageCount,
|
|
visibleMessages,
|
|
loadEarlierMessages,
|
|
loadAllMessages,
|
|
allMessagesLoaded,
|
|
isLoadingAllMessages,
|
|
loadAllJustFinished,
|
|
showLoadAllOverlay,
|
|
createDiff,
|
|
onFileOpen,
|
|
onShowSettings,
|
|
onGrantToolPermission,
|
|
autoExpandTools,
|
|
showRawParameters,
|
|
showThinking,
|
|
selectedProject,
|
|
}: ChatMessagesPaneProps) {
|
|
const { t } = useTranslation('chat');
|
|
const messageKeyMapRef = useRef<WeakMap<ChatMessage, string>>(new WeakMap());
|
|
const allocatedKeysRef = useRef<Set<string>>(new Set());
|
|
const generatedMessageKeyCounterRef = useRef(0);
|
|
|
|
// Keep keys stable across prepends so existing MessageComponent instances retain local state.
|
|
const getMessageKey = useCallback((message: ChatMessage) => {
|
|
const existingKey = messageKeyMapRef.current.get(message);
|
|
if (existingKey) {
|
|
return existingKey;
|
|
}
|
|
|
|
const intrinsicKey = getIntrinsicMessageKey(message);
|
|
let candidateKey = intrinsicKey;
|
|
|
|
if (!candidateKey || allocatedKeysRef.current.has(candidateKey)) {
|
|
do {
|
|
generatedMessageKeyCounterRef.current += 1;
|
|
candidateKey = intrinsicKey
|
|
? `${intrinsicKey}-${generatedMessageKeyCounterRef.current}`
|
|
: `message-generated-${generatedMessageKeyCounterRef.current}`;
|
|
} while (allocatedKeysRef.current.has(candidateKey));
|
|
}
|
|
|
|
allocatedKeysRef.current.add(candidateKey);
|
|
messageKeyMapRef.current.set(message, candidateKey);
|
|
return candidateKey;
|
|
}, []);
|
|
|
|
return (
|
|
<div
|
|
ref={scrollContainerRef}
|
|
onWheel={onWheel}
|
|
onTouchMove={onTouchMove}
|
|
className="relative flex-1 space-y-3 overflow-y-auto overflow-x-hidden px-0 py-3 sm:space-y-4 sm:p-4"
|
|
>
|
|
{isLoadingSessionMessages && chatMessages.length === 0 ? (
|
|
<div className="mt-8 text-center text-gray-500 dark:text-gray-400">
|
|
<div className="flex items-center justify-center space-x-2">
|
|
<div className="h-4 w-4 animate-spin rounded-full border-b-2 border-gray-400" />
|
|
<p>{t('session.loading.sessionMessages')}</p>
|
|
</div>
|
|
</div>
|
|
) : chatMessages.length === 0 ? (
|
|
<ProviderSelectionEmptyState
|
|
selectedSession={selectedSession}
|
|
currentSessionId={currentSessionId}
|
|
provider={provider}
|
|
setProvider={setProvider}
|
|
textareaRef={textareaRef}
|
|
claudeModel={claudeModel}
|
|
setClaudeModel={setClaudeModel}
|
|
cursorModel={cursorModel}
|
|
setCursorModel={setCursorModel}
|
|
codexModel={codexModel}
|
|
setCodexModel={setCodexModel}
|
|
geminiModel={geminiModel}
|
|
setGeminiModel={setGeminiModel}
|
|
tasksEnabled={tasksEnabled}
|
|
isTaskMasterInstalled={isTaskMasterInstalled}
|
|
onShowAllTasks={onShowAllTasks}
|
|
setInput={setInput}
|
|
/>
|
|
) : (
|
|
<>
|
|
{/* Loading indicator for older messages (hide when load-all is active) */}
|
|
{isLoadingMoreMessages && !isLoadingAllMessages && !allMessagesLoaded && (
|
|
<div className="py-3 text-center text-gray-500 dark:text-gray-400">
|
|
<div className="flex items-center justify-center space-x-2">
|
|
<div className="h-4 w-4 animate-spin rounded-full border-b-2 border-gray-400" />
|
|
<p className="text-sm">{t('session.loading.olderMessages')}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Indicator showing there are more messages to load (hide when all loaded) */}
|
|
{hasMoreMessages && !isLoadingMoreMessages && !allMessagesLoaded && (
|
|
<div className="border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
|
|
{totalMessages > 0 && (
|
|
<span>
|
|
{t('session.messages.showingOf', { shown: sessionMessagesCount, total: totalMessages })}{' '}
|
|
<span className="text-xs">{t('session.messages.scrollToLoad')}</span>
|
|
</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Floating "Load all messages" overlay */}
|
|
{(showLoadAllOverlay || isLoadingAllMessages || loadAllJustFinished) && (
|
|
<div className="pointer-events-none sticky top-2 z-20 flex justify-center">
|
|
{loadAllJustFinished ? (
|
|
<div className="flex items-center space-x-2 rounded-full bg-green-600 px-4 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-green-500">
|
|
<svg className="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={3} d="M5 13l4 4L19 7" />
|
|
</svg>
|
|
<span>{t('session.messages.allLoaded')}</span>
|
|
</div>
|
|
) : (
|
|
<button
|
|
className="pointer-events-auto flex items-center space-x-2 rounded-full bg-blue-600 px-4 py-1.5 text-xs font-medium text-white shadow-lg transition-all duration-200 hover:scale-105 hover:bg-blue-700 disabled:cursor-wait disabled:opacity-75 dark:bg-blue-500 dark:hover:bg-blue-600"
|
|
onClick={loadAllMessages}
|
|
disabled={isLoadingAllMessages}
|
|
>
|
|
{isLoadingAllMessages && (
|
|
<div className="h-3 w-3 animate-spin rounded-full border-2 border-white/30 border-t-white" />
|
|
)}
|
|
<span>
|
|
{isLoadingAllMessages
|
|
? t('session.messages.loadingAll')
|
|
: <>{t('session.messages.loadAll')} {totalMessages > 0 && `(${totalMessages})`}</>
|
|
}
|
|
</span>
|
|
</button>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Performance warning when all messages are loaded */}
|
|
{allMessagesLoaded && (
|
|
<div className="border-b border-amber-200 bg-amber-50 py-1.5 text-center text-xs text-amber-600 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-400">
|
|
{t('session.messages.perfWarning')}
|
|
</div>
|
|
)}
|
|
|
|
{/* Legacy message count indicator (for non-paginated view) */}
|
|
{!hasMoreMessages && chatMessages.length > visibleMessageCount && (
|
|
<div className="border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">
|
|
{t('session.messages.showingLast', { count: visibleMessageCount, total: chatMessages.length })} |
|
|
<button className="ml-1 text-blue-600 underline hover:text-blue-700" onClick={loadEarlierMessages}>
|
|
{t('session.messages.loadEarlier')}
|
|
</button>
|
|
{' | '}
|
|
<button
|
|
className="text-blue-600 underline hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300"
|
|
onClick={loadAllMessages}
|
|
>
|
|
{t('session.messages.loadAll')}
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{visibleMessages.map((message, index) => {
|
|
const prevMessage = index > 0 ? visibleMessages[index - 1] : null;
|
|
return (
|
|
<MessageComponent
|
|
key={getMessageKey(message)}
|
|
message={message}
|
|
prevMessage={prevMessage}
|
|
createDiff={createDiff}
|
|
onFileOpen={onFileOpen}
|
|
onShowSettings={onShowSettings}
|
|
onGrantToolPermission={onGrantToolPermission}
|
|
autoExpandTools={autoExpandTools}
|
|
showRawParameters={showRawParameters}
|
|
showThinking={showThinking}
|
|
selectedProject={selectedProject}
|
|
provider={provider}
|
|
/>
|
|
);
|
|
})}
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|