mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-24 02:45:49 +08:00
Compare commits
3 Commits
feat/provi
...
feat/pendi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63a4869325 | ||
|
|
f6326c8082 | ||
|
|
c5fe127958 |
@@ -76,6 +76,19 @@ const __dirname = getModuleDir(import.meta.url);
|
||||
// Resolving the app root once keeps every repo-level lookup below aligned across both layouts.
|
||||
const APP_ROOT = findAppRoot(__dirname);
|
||||
const installMode = fs.existsSync(path.join(APP_ROOT, '.git')) ? 'git' : 'npm';
|
||||
// Version of the code that is actually running, captured once at process
|
||||
// startup. This intentionally does NOT re-read package.json per request: after
|
||||
// an update replaces the files on disk, package.json reflects the NEW version
|
||||
// while this long-lived process still runs the OLD code. The frontend bundle is
|
||||
// rebuilt on update, so a mismatch between this value and the frontend's
|
||||
// build-time version means the server was updated but not restarted.
|
||||
const RUNNING_VERSION = (() => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path.join(APP_ROOT, 'package.json'), 'utf8')).version || null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
const MAX_FILE_UPLOAD_SIZE_MB = 200;
|
||||
const MAX_FILE_UPLOAD_SIZE_BYTES = MAX_FILE_UPLOAD_SIZE_MB * 1024 * 1024;
|
||||
const MAX_FILE_UPLOAD_COUNT = 20;
|
||||
@@ -156,7 +169,8 @@ app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
installMode
|
||||
installMode,
|
||||
version: RUNNING_VERSION
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
||||
|
||||
import type { ServerEvent } from '../../../contexts/WebSocketContext';
|
||||
import { showCompletionTitleIndicator } from '../../../utils/pageTitleNotification';
|
||||
import { playChatCompletionSound } from '../../../utils/notificationSound';
|
||||
import { playChatCompletionSound, playNotificationSound } from '../../../utils/notificationSound';
|
||||
import type { MarkSessionIdle, MarkSessionProcessing } from '../../../hooks/useSessionProtection';
|
||||
import type { PendingPermissionRequest } from '../types/types';
|
||||
import type { ProjectSession, LLMProvider } from '../../../types/app';
|
||||
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
|
||||
|
||||
const isActionablePermissionRequest = (request: { toolName?: unknown } | null | undefined): boolean => {
|
||||
return request?.toolName !== 'ExitPlanMode' && request?.toolName !== 'exit_plan_mode';
|
||||
};
|
||||
|
||||
const hasActionablePermissionRequests = (requests: Array<{ toolName?: unknown }> | null | undefined): boolean => {
|
||||
return Array.isArray(requests) && requests.some((request) => isActionablePermissionRequest(request));
|
||||
};
|
||||
|
||||
interface UseChatRealtimeHandlersArgs {
|
||||
subscribe: (listener: (event: ServerEvent) => void) => () => void;
|
||||
provider: LLMProvider;
|
||||
selectedSession: ProjectSession | null;
|
||||
currentSessionId: string | null;
|
||||
setTokenBudget: (budget: Record<string, unknown> | null) => void;
|
||||
pendingPermissionRequests: PendingPermissionRequest[];
|
||||
setPendingPermissionRequests: Dispatch<SetStateAction<PendingPermissionRequest[]>>;
|
||||
streamTimerRef: MutableRefObject<number | null>;
|
||||
accumulatedStreamRef: MutableRefObject<string>;
|
||||
@@ -52,6 +61,7 @@ export function useChatRealtimeHandlers({
|
||||
selectedSession,
|
||||
currentSessionId,
|
||||
setTokenBudget,
|
||||
pendingPermissionRequests,
|
||||
setPendingPermissionRequests,
|
||||
streamTimerRef,
|
||||
accumulatedStreamRef,
|
||||
@@ -62,6 +72,15 @@ export function useChatRealtimeHandlers({
|
||||
onWebSocketReconnect,
|
||||
sessionStore,
|
||||
}: UseChatRealtimeHandlersArgs) {
|
||||
// Keep the latest pending-permission snapshot available to the websocket
|
||||
// listener so back-to-back permission events can dedupe and re-arm the
|
||||
// notification sound before React finishes a rerender.
|
||||
const pendingPermissionRequestsRef = useRef(pendingPermissionRequests);
|
||||
|
||||
useEffect(() => {
|
||||
pendingPermissionRequestsRef.current = pendingPermissionRequests;
|
||||
}, [pendingPermissionRequests]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleEvent = (msg: ServerEvent) => {
|
||||
if (!msg.kind) {
|
||||
@@ -101,7 +120,16 @@ export function useChatRealtimeHandlers({
|
||||
|
||||
const isViewedSession = sid === activeViewSessionId;
|
||||
if (isViewedSession && Array.isArray(msg.pendingPermissions)) {
|
||||
setPendingPermissionRequests(msg.pendingPermissions as PendingPermissionRequest[]);
|
||||
const nextPendingPermissionRequests = msg.pendingPermissions as PendingPermissionRequest[];
|
||||
const hadActionablePermissionRequests = hasActionablePermissionRequests(pendingPermissionRequestsRef.current);
|
||||
const hasPendingActionablePermissionRequests = hasActionablePermissionRequests(nextPendingPermissionRequests);
|
||||
|
||||
pendingPermissionRequestsRef.current = nextPendingPermissionRequests;
|
||||
setPendingPermissionRequests(nextPendingPermissionRequests);
|
||||
|
||||
if (hasPendingActionablePermissionRequests && !hadActionablePermissionRequests) {
|
||||
void playNotificationSound();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -203,6 +231,7 @@ export function useChatRealtimeHandlers({
|
||||
// hides it immediately and atomically.
|
||||
onSessionIdle?.(sid);
|
||||
if (sid === activeViewSessionId) {
|
||||
pendingPermissionRequestsRef.current = [];
|
||||
setPendingPermissionRequests([]);
|
||||
}
|
||||
|
||||
@@ -235,9 +264,9 @@ export function useChatRealtimeHandlers({
|
||||
case 'permission_request': {
|
||||
if (!msg.requestId) break;
|
||||
if (sid === activeViewSessionId) {
|
||||
setPendingPermissionRequests((prev) => {
|
||||
if (prev.some((r: PendingPermissionRequest) => r.requestId === msg.requestId)) return prev;
|
||||
return [...prev, {
|
||||
const previousPendingPermissionRequests = pendingPermissionRequestsRef.current;
|
||||
if (!previousPendingPermissionRequests.some((request) => request.requestId === msg.requestId)) {
|
||||
const nextPendingPermissionRequests = [...previousPendingPermissionRequests, {
|
||||
requestId: msg.requestId as string,
|
||||
toolName: (msg.toolName as string) || 'UnknownTool',
|
||||
input: msg.input,
|
||||
@@ -245,7 +274,17 @@ export function useChatRealtimeHandlers({
|
||||
sessionId: sid || null,
|
||||
receivedAt: new Date(),
|
||||
}];
|
||||
});
|
||||
|
||||
pendingPermissionRequestsRef.current = nextPendingPermissionRequests;
|
||||
setPendingPermissionRequests(nextPendingPermissionRequests);
|
||||
|
||||
if (
|
||||
isActionablePermissionRequest({ toolName: msg.toolName })
|
||||
&& !hasActionablePermissionRequests(previousPendingPermissionRequests)
|
||||
) {
|
||||
void playNotificationSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sid) {
|
||||
onSessionProcessing?.(sid);
|
||||
@@ -255,7 +294,12 @@ export function useChatRealtimeHandlers({
|
||||
|
||||
case 'permission_cancelled': {
|
||||
if (msg.requestId && sid === activeViewSessionId) {
|
||||
setPendingPermissionRequests((prev) => prev.filter((r: PendingPermissionRequest) => r.requestId !== msg.requestId));
|
||||
const nextPendingPermissionRequests = pendingPermissionRequestsRef.current.filter(
|
||||
(request: PendingPermissionRequest) => request.requestId !== msg.requestId,
|
||||
);
|
||||
|
||||
pendingPermissionRequestsRef.current = nextPendingPermissionRequests;
|
||||
setPendingPermissionRequests(nextPendingPermissionRequests);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -286,6 +330,7 @@ export function useChatRealtimeHandlers({
|
||||
selectedSession,
|
||||
currentSessionId,
|
||||
setTokenBudget,
|
||||
pendingPermissionRequests,
|
||||
setPendingPermissionRequests,
|
||||
streamTimerRef,
|
||||
accumulatedStreamRef,
|
||||
|
||||
@@ -239,6 +239,7 @@ function ChatInterface({
|
||||
selectedSession,
|
||||
currentSessionId,
|
||||
setTokenBudget,
|
||||
pendingPermissionRequests,
|
||||
setPendingPermissionRequests,
|
||||
streamTimerRef,
|
||||
accumulatedStreamRef,
|
||||
|
||||
@@ -43,7 +43,7 @@ function Sidebar({
|
||||
}: SidebarProps) {
|
||||
const { t } = useTranslation(['sidebar', 'common']);
|
||||
const { isPWA } = useDeviceSettings({ trackMobile: false });
|
||||
const { updateAvailable, latestVersion, currentVersion, releaseInfo, installMode } = useVersionCheck(
|
||||
const { updateAvailable, restartRequired, latestVersion, currentVersion, releaseInfo, installMode } = useVersionCheck(
|
||||
'siteboon',
|
||||
'claudecodeui',
|
||||
);
|
||||
@@ -224,6 +224,7 @@ function Sidebar({
|
||||
onExpand={handleExpandSidebar}
|
||||
onShowSettings={onShowSettings}
|
||||
updateAvailable={updateAvailable}
|
||||
restartRequired={restartRequired}
|
||||
onShowVersionModal={() => setShowVersionModal(true)}
|
||||
t={t}
|
||||
/>
|
||||
@@ -296,6 +297,7 @@ function Sidebar({
|
||||
onCreateProject={() => setShowNewProject(true)}
|
||||
onCollapseSidebar={handleCollapseSidebar}
|
||||
updateAvailable={updateAvailable}
|
||||
restartRequired={restartRequired}
|
||||
releaseInfo={releaseInfo}
|
||||
latestVersion={latestVersion}
|
||||
currentVersion={currentVersion}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Settings, Sparkles, PanelLeftOpen, Bug } from 'lucide-react';
|
||||
import { Settings, Sparkles, PanelLeftOpen, Bug, AlertTriangle } from 'lucide-react';
|
||||
import type { TFunction } from 'i18next';
|
||||
|
||||
const DISCORD_INVITE_URL = 'https://discord.gg/buxwujPNRE';
|
||||
@@ -16,6 +16,7 @@ type SidebarCollapsedProps = {
|
||||
onExpand: () => void;
|
||||
onShowSettings: () => void;
|
||||
updateAvailable: boolean;
|
||||
restartRequired: boolean;
|
||||
onShowVersionModal: () => void;
|
||||
t: TFunction;
|
||||
};
|
||||
@@ -24,6 +25,7 @@ export default function SidebarCollapsed({
|
||||
onExpand,
|
||||
onShowSettings,
|
||||
updateAvailable,
|
||||
restartRequired,
|
||||
onShowVersionModal,
|
||||
t,
|
||||
}: SidebarCollapsedProps) {
|
||||
@@ -75,6 +77,18 @@ export default function SidebarCollapsed({
|
||||
<DiscordIcon className="h-4 w-4 text-muted-foreground transition-colors group-hover:text-foreground" />
|
||||
</a>
|
||||
|
||||
{/* Restart-required indicator */}
|
||||
{restartRequired && (
|
||||
<div
|
||||
className="relative flex h-8 w-8 items-center justify-center rounded-lg"
|
||||
aria-label={t('version.restartRequired')}
|
||||
title={t('version.restartRequired')}
|
||||
>
|
||||
<AlertTriangle className="h-4 w-4 text-amber-500" />
|
||||
<span className="absolute right-1.5 top-1.5 h-1.5 w-1.5 animate-pulse rounded-full bg-amber-500" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Update indicator */}
|
||||
{updateAvailable && (
|
||||
<button
|
||||
|
||||
@@ -141,6 +141,7 @@ type SidebarContentProps = {
|
||||
onCreateProject: () => void;
|
||||
onCollapseSidebar: () => void;
|
||||
updateAvailable: boolean;
|
||||
restartRequired: boolean;
|
||||
releaseInfo: ReleaseInfo | null;
|
||||
latestVersion: string | null;
|
||||
currentVersion: string;
|
||||
@@ -178,6 +179,7 @@ export default function SidebarContent({
|
||||
onCreateProject,
|
||||
onCollapseSidebar,
|
||||
updateAvailable,
|
||||
restartRequired,
|
||||
releaseInfo,
|
||||
latestVersion,
|
||||
currentVersion,
|
||||
@@ -553,6 +555,7 @@ export default function SidebarContent({
|
||||
|
||||
<SidebarFooter
|
||||
updateAvailable={updateAvailable}
|
||||
restartRequired={restartRequired}
|
||||
releaseInfo={releaseInfo}
|
||||
latestVersion={latestVersion}
|
||||
currentVersion={currentVersion}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Settings, ArrowUpCircle, Bug } from 'lucide-react';
|
||||
import { Settings, ArrowUpCircle, Bug, AlertTriangle } from 'lucide-react';
|
||||
import type { TFunction } from 'i18next';
|
||||
import { IS_PLATFORM } from '../../../../constants/config';
|
||||
import type { ReleaseInfo } from '../../../../types/sharedTypes';
|
||||
@@ -18,6 +18,7 @@ function DiscordIcon({ className }: { className?: string }) {
|
||||
|
||||
type SidebarFooterProps = {
|
||||
updateAvailable: boolean;
|
||||
restartRequired: boolean;
|
||||
releaseInfo: ReleaseInfo | null;
|
||||
latestVersion: string | null;
|
||||
currentVersion: string;
|
||||
@@ -28,6 +29,7 @@ type SidebarFooterProps = {
|
||||
|
||||
export default function SidebarFooter({
|
||||
updateAvailable,
|
||||
restartRequired,
|
||||
releaseInfo,
|
||||
latestVersion,
|
||||
currentVersion,
|
||||
@@ -37,6 +39,22 @@ export default function SidebarFooter({
|
||||
}: SidebarFooterProps) {
|
||||
return (
|
||||
<div className="flex-shrink-0" style={{ paddingBottom: 'env(safe-area-inset-bottom, 0)' }}>
|
||||
{/* Restart-required banner: the running server version differs from the
|
||||
installed/frontend version (updated but not restarted). */}
|
||||
{restartRequired && (
|
||||
<>
|
||||
<div className="nav-divider" />
|
||||
<div className="px-2 py-1.5 md:px-2 md:py-1.5">
|
||||
<div className="flex items-center gap-2.5 rounded-lg border border-amber-300/60 bg-amber-50/80 px-2.5 py-2 dark:border-amber-700/40 dark:bg-amber-900/15">
|
||||
<AlertTriangle className="h-4 w-4 flex-shrink-0 text-amber-500 dark:text-amber-400" />
|
||||
<span className="min-w-0 flex-1 text-xs font-medium text-amber-700 dark:text-amber-300">
|
||||
{t('version.restartRequired')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Update banner */}
|
||||
{updateAvailable && (
|
||||
<>
|
||||
|
||||
@@ -28,20 +28,31 @@ export const useVersionCheck = (owner: string, repo: string) => {
|
||||
const [latestVersion, setLatestVersion] = useState<string | null>(null);
|
||||
const [releaseInfo, setReleaseInfo] = useState<ReleaseInfo | null>(null);
|
||||
const [installMode, setInstallMode] = useState<InstallMode>('git');
|
||||
const [runningVersion, setRunningVersion] = useState<string | null>(null);
|
||||
const [restartRequired, setRestartRequired] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchInstallMode = async () => {
|
||||
const fetchHealth = async () => {
|
||||
try {
|
||||
const response = await fetch('/health');
|
||||
const data = await response.json();
|
||||
if (data.installMode === 'npm' || data.installMode === 'git') {
|
||||
setInstallMode(data.installMode);
|
||||
}
|
||||
// `data.version` is the version the server process is actually running.
|
||||
// This module's `version` is baked into the frontend bundle at build
|
||||
// time, so it reflects the installed (on-disk) package. If they differ,
|
||||
// the package was updated but the server process was not restarted, and
|
||||
// DB-backed actions may silently fail until it is.
|
||||
if (typeof data.version === 'string' && data.version.length > 0) {
|
||||
setRunningVersion(data.version);
|
||||
setRestartRequired(data.version !== version);
|
||||
}
|
||||
} catch {
|
||||
// Default to git on error
|
||||
// Default to git / no restart hint on error
|
||||
}
|
||||
};
|
||||
fetchInstallMode();
|
||||
fetchHealth();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -84,5 +95,5 @@ export const useVersionCheck = (owner: string, repo: string) => {
|
||||
return () => clearInterval(interval);
|
||||
}, [owner, repo]);
|
||||
|
||||
return { updateAvailable, latestVersion, currentVersion: version, releaseInfo, installMode };
|
||||
return { updateAvailable, latestVersion, currentVersion: version, releaseInfo, installMode, runningVersion, restartRequired };
|
||||
};
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Fehler beim Wiederherstellen der Sitzung. Bitte erneut versuchen."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Update verfügbar"
|
||||
"updateAvailable": "Update verfügbar",
|
||||
"restartRequired": "Update installiert – zum Anwenden Server neu starten"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Projekte",
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
},
|
||||
"sound": {
|
||||
"title": "Sound",
|
||||
"description": "Play a short tone when a chat run finishes.",
|
||||
"description": "Play a short tone when a chat run finishes or needs tool approval.",
|
||||
"enabled": "Enabled",
|
||||
"test": "Test sound"
|
||||
},
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Error restoring session. Please try again."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Update available"
|
||||
"updateAvailable": "Update available",
|
||||
"restartRequired": "Update installed — restart the server to apply"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Projects",
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Erreur lors de la restauration de la session. Veuillez réessayer."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Mise à jour disponible"
|
||||
"updateAvailable": "Mise à jour disponible",
|
||||
"restartRequired": "Mise à jour installée — redémarrez le serveur pour l'appliquer"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Projets",
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Errore durante il ripristino della sessione. Riprova."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Aggiornamento disponibile"
|
||||
"updateAvailable": "Aggiornamento disponibile",
|
||||
"restartRequired": "Aggiornamento installato — riavvia il server per applicarlo"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Progetti",
|
||||
|
||||
@@ -114,7 +114,8 @@
|
||||
"restoreSessionError": "セッションの復元でエラーが発生しました。もう一度お試しください。"
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "アップデートあり"
|
||||
"updateAvailable": "アップデートあり",
|
||||
"restartRequired": "更新が適用されていません。サーバーを再起動してください"
|
||||
},
|
||||
"deleteConfirmation": {
|
||||
"deleteProject": "プロジェクトを除去",
|
||||
|
||||
@@ -114,7 +114,8 @@
|
||||
"restoreSessionError": "세션 복원 오류. 다시 시도해주세요."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "업데이트 가능"
|
||||
"updateAvailable": "업데이트 가능",
|
||||
"restartRequired": "업데이트가 설치됨 — 적용하려면 서버를 재시작하세요"
|
||||
},
|
||||
"deleteConfirmation": {
|
||||
"deleteProject": "프로젝트 제거",
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Ошибка при восстановлении сеанса. Попробуйте снова."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Доступно обновление"
|
||||
"updateAvailable": "Доступно обновление",
|
||||
"restartRequired": "Обновление установлено — перезапустите сервер для применения"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Проекты",
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "Oturum geri yüklenirken hata oluştu. Lütfen tekrar dene."
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "Güncelleme mevcut"
|
||||
"updateAvailable": "Güncelleme mevcut",
|
||||
"restartRequired": "Güncelleme yüklendi — uygulamak için sunucuyu yeniden başlatın"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "Projeler",
|
||||
|
||||
@@ -115,7 +115,8 @@
|
||||
"restoreSessionError": "恢复会话时出错,请重试。"
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "有可用更新"
|
||||
"updateAvailable": "有可用更新",
|
||||
"restartRequired": "已安装更新 — 请重启服务器以生效"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "项目",
|
||||
|
||||
@@ -114,7 +114,8 @@
|
||||
"restoreSessionError": "還原工作階段時出錯,請重試。"
|
||||
},
|
||||
"version": {
|
||||
"updateAvailable": "有可用更新"
|
||||
"updateAvailable": "有可用更新",
|
||||
"restartRequired": "已安裝更新 — 請重新啟動伺服器以套用"
|
||||
},
|
||||
"search": {
|
||||
"modeProjects": "專案",
|
||||
|
||||
@@ -58,7 +58,7 @@ const playTone = (
|
||||
oscillator.stop(startsAt + duration + 0.02);
|
||||
};
|
||||
|
||||
export const playChatCompletionSound = async ({ force = false } = {}): Promise<void> => {
|
||||
export const playNotificationSound = async ({ force = false } = {}): Promise<void> => {
|
||||
if (!force && !isNotificationSoundEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -81,3 +81,5 @@ export const playChatCompletionSound = async ({ force = false } = {}): Promise<v
|
||||
console.warn('Unable to play notification sound:', error);
|
||||
}
|
||||
};
|
||||
|
||||
export const playChatCompletionSound = (options = {}): Promise<void> => playNotificationSound(options);
|
||||
|
||||
Reference in New Issue
Block a user