mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-04-16 02:21:31 +00: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>
242 lines
8.3 KiB
TypeScript
242 lines
8.3 KiB
TypeScript
import { Check, ChevronLeft, ChevronRight, Loader2 } from 'lucide-react';
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
import type { LLMProvider } from '../../../types/app';
|
|
import { authenticatedFetch } from '../../../utils/api';
|
|
import { useProviderAuthStatus } from '../../provider-auth/hooks/useProviderAuthStatus';
|
|
import ProviderLoginModal from '../../provider-auth/view/ProviderLoginModal';
|
|
import AgentConnectionsStep from './subcomponents/AgentConnectionsStep';
|
|
import GitConfigurationStep from './subcomponents/GitConfigurationStep';
|
|
import OnboardingStepProgress from './subcomponents/OnboardingStepProgress';
|
|
import {
|
|
gitEmailPattern,
|
|
readErrorMessageFromResponse,
|
|
} from './utils';
|
|
|
|
type OnboardingProps = {
|
|
onComplete?: () => void | Promise<void>;
|
|
};
|
|
|
|
export default function Onboarding({ onComplete }: OnboardingProps) {
|
|
const [currentStep, setCurrentStep] = useState(0);
|
|
const [gitName, setGitName] = useState('');
|
|
const [gitEmail, setGitEmail] = useState('');
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
const [errorMessage, setErrorMessage] = useState('');
|
|
const [activeLoginProvider, setActiveLoginProvider] = useState<LLMProvider | null>(null);
|
|
const {
|
|
providerAuthStatus,
|
|
checkProviderAuthStatus,
|
|
refreshProviderAuthStatuses,
|
|
} = useProviderAuthStatus();
|
|
|
|
const previousActiveLoginProviderRef = useRef<LLMProvider | null | undefined>(undefined);
|
|
|
|
const loadGitConfig = useCallback(async () => {
|
|
try {
|
|
const response = await authenticatedFetch('/api/user/git-config');
|
|
if (!response.ok) {
|
|
return;
|
|
}
|
|
|
|
const payload = (await response.json()) as { gitName?: string; gitEmail?: string };
|
|
if (payload.gitName) {
|
|
setGitName(payload.gitName);
|
|
}
|
|
if (payload.gitEmail) {
|
|
setGitEmail(payload.gitEmail);
|
|
}
|
|
} catch (caughtError) {
|
|
console.error('Error loading git config:', caughtError);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
void loadGitConfig();
|
|
void refreshProviderAuthStatuses();
|
|
}, [loadGitConfig, refreshProviderAuthStatuses]);
|
|
|
|
useEffect(() => {
|
|
const previousProvider = previousActiveLoginProviderRef.current;
|
|
previousActiveLoginProviderRef.current = activeLoginProvider;
|
|
|
|
const didCloseModal = previousProvider !== undefined
|
|
&& previousProvider !== null
|
|
&& activeLoginProvider === null;
|
|
|
|
// Refresh statuses after the login modal is closed.
|
|
if (didCloseModal) {
|
|
void refreshProviderAuthStatuses();
|
|
}
|
|
}, [activeLoginProvider, refreshProviderAuthStatuses]);
|
|
|
|
const handleProviderLoginOpen = (provider: LLMProvider) => {
|
|
setActiveLoginProvider(provider);
|
|
};
|
|
|
|
const handleLoginComplete = (exitCode: number) => {
|
|
if (exitCode === 0 && activeLoginProvider) {
|
|
void checkProviderAuthStatus(activeLoginProvider);
|
|
}
|
|
};
|
|
|
|
const handleNextStep = async () => {
|
|
setErrorMessage('');
|
|
|
|
if (currentStep !== 0) {
|
|
setCurrentStep((previous) => previous + 1);
|
|
return;
|
|
}
|
|
|
|
if (!gitName.trim() || !gitEmail.trim()) {
|
|
setErrorMessage('Both git name and email are required.');
|
|
return;
|
|
}
|
|
|
|
if (!gitEmailPattern.test(gitEmail)) {
|
|
setErrorMessage('Please enter a valid email address.');
|
|
return;
|
|
}
|
|
|
|
setIsSubmitting(true);
|
|
try {
|
|
const response = await authenticatedFetch('/api/user/git-config', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ gitName, gitEmail }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const message = await readErrorMessageFromResponse(response, 'Failed to save git configuration');
|
|
throw new Error(message);
|
|
}
|
|
|
|
setCurrentStep((previous) => previous + 1);
|
|
} catch (caughtError) {
|
|
setErrorMessage(caughtError instanceof Error ? caughtError.message : 'Failed to save git configuration');
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
const handlePreviousStep = () => {
|
|
setErrorMessage('');
|
|
setCurrentStep((previous) => previous - 1);
|
|
};
|
|
|
|
const handleFinish = async () => {
|
|
setIsSubmitting(true);
|
|
setErrorMessage('');
|
|
|
|
try {
|
|
const response = await authenticatedFetch('/api/user/complete-onboarding', { method: 'POST' });
|
|
if (!response.ok) {
|
|
const message = await readErrorMessageFromResponse(response, 'Failed to complete onboarding');
|
|
throw new Error(message);
|
|
}
|
|
|
|
await onComplete?.();
|
|
} catch (caughtError) {
|
|
setErrorMessage(caughtError instanceof Error ? caughtError.message : 'Failed to complete onboarding');
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
const isCurrentStepValid = currentStep === 0
|
|
? Boolean(gitName.trim() && gitEmail.trim() && gitEmailPattern.test(gitEmail))
|
|
: true;
|
|
|
|
return (
|
|
<>
|
|
<div className="flex min-h-screen items-center justify-center bg-background p-4">
|
|
<div className="w-full max-w-2xl">
|
|
<OnboardingStepProgress currentStep={currentStep} />
|
|
|
|
<div className="rounded-lg border border-border bg-card p-8 shadow-lg">
|
|
{currentStep === 0 ? (
|
|
<GitConfigurationStep
|
|
gitName={gitName}
|
|
gitEmail={gitEmail}
|
|
isSubmitting={isSubmitting}
|
|
onGitNameChange={setGitName}
|
|
onGitEmailChange={setGitEmail}
|
|
/>
|
|
) : (
|
|
<AgentConnectionsStep
|
|
providerStatuses={providerAuthStatus}
|
|
onOpenProviderLogin={handleProviderLoginOpen}
|
|
/>
|
|
)}
|
|
|
|
{errorMessage && (
|
|
<div className="mt-6 rounded-lg border border-red-300 bg-red-100 p-4 dark:border-red-800 dark:bg-red-900/20">
|
|
<p className="text-sm text-red-700 dark:text-red-400">{errorMessage}</p>
|
|
</div>
|
|
)}
|
|
|
|
<div className="mt-8 flex items-center justify-between border-t border-border pt-6">
|
|
<button
|
|
onClick={handlePreviousStep}
|
|
disabled={currentStep === 0 || isSubmitting}
|
|
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-muted-foreground transition-colors duration-200 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
|
>
|
|
<ChevronLeft className="h-4 w-4" />
|
|
Previous
|
|
</button>
|
|
|
|
<div className="flex items-center gap-3">
|
|
{currentStep < 1 ? (
|
|
<button
|
|
onClick={handleNextStep}
|
|
disabled={!isCurrentStepValid || isSubmitting}
|
|
className="flex items-center gap-2 rounded-lg bg-blue-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-blue-400"
|
|
>
|
|
{isSubmitting ? (
|
|
<>
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
Saving...
|
|
</>
|
|
) : (
|
|
<>
|
|
Next
|
|
<ChevronRight className="h-4 w-4" />
|
|
</>
|
|
)}
|
|
</button>
|
|
) : (
|
|
<button
|
|
onClick={handleFinish}
|
|
disabled={isSubmitting}
|
|
className="flex items-center gap-2 rounded-lg bg-green-600 px-6 py-3 font-medium text-white transition-colors duration-200 hover:bg-green-700 disabled:cursor-not-allowed disabled:bg-green-400"
|
|
>
|
|
{isSubmitting ? (
|
|
<>
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
Completing...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Check className="h-4 w-4" />
|
|
Complete Setup
|
|
</>
|
|
)}
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{activeLoginProvider && (
|
|
<ProviderLoginModal
|
|
isOpen={Boolean(activeLoginProvider)}
|
|
onClose={() => setActiveLoginProvider(null)}
|
|
provider={activeLoginProvider}
|
|
onComplete={handleLoginComplete}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|