feat(preview): embedded dev-server preview pane + dev shutdown controls (#1062)
* feat: embedded preview proxy for local dev servers Add a same-origin server proxy under /api/preview/proxy/:id and matching UI surfaces so local dev servers (Vite, Next, etc.) can be embedded inside OpenChamber. Server (packages/web/server): - New lib/preview/proxy-runtime.js: cookie-gated HTTP+WebSocket proxy to loopback hosts only, with TTL'd targets and SSRF allowlist. - index.js wires the runtime alongside terminal/event-stream. UI (packages/ui): - ContextPanel preview tab with iframe, reload, and open-in-browser. - Inline html code-block preview in MarkdownRenderer. - Terminal auto-detects loopback URLs and offers to open them. - i18n keys across en, es, pt-BR, uk, zh-CN. * perf(preview): cache proxy targets across PreviewPane remounts Module-scoped Map keyed by upstream URL so tab switches and component remounts within the same page session reuse the existing proxy registration instead of POSTing a fresh target each time. In-memory only by design: the server holds the target map in memory and the auth cookie is HttpOnly + scoped to the proxy id, so a stale persisted entry would 404 after a server restart. Entries are evicted on registration error and on a 30s safety margin before TTL expiry. * feat(preview): surface dev-server-down state with retry overlay Iframes don't expose HTTP status to the parent, so when the proxy returns a 502 (upstream dev server is offline) the iframe just renders the raw JSON error body. Probe the proxy URL out-of-band with HEAD (falling back to GET on 404/405) and replace the iframe with a friendly 'Dev server is not responding' overlay + retry button when the upstream is unreachable. Re-probes on reload, on URL change, and on proxy re-registration. * feat(preview): strip frame-busting response headers Many dev servers (Next.js, others) send X-Frame-Options: SAMEORIGIN and/or a CSP with frame-ancestors that block embedding inside the OpenChamber iframe. The proxy is same-origin and already authenticated per-target, so embedding is otherwise safe. - Drop X-Frame-Options outright on proxied responses. - Surgically remove only the frame-ancestors directive from Content-Security-Policy and Content-Security-Policy-Report-Only, preserving every other directive. Drops the header entirely if no directives remain. - Verified end-to-end: upstream sending both headers comes through with X-Frame-Options removed, CSP retaining default-src/script-src but no frame-ancestors, and unrelated headers untouched. * docs(preview): design for remote-host relay agent Design-only doc for the next phase of the embedded preview feature: when OpenChamber runs remotely (cloud/shared/tunnel) and the user's dev server runs on their local machine. Covers architecture (local agent + outbound control WebSocket + server dispatch), pairing flow, wire protocol, security model, failure modes, open questions, and implementation milestones. No code changes. * feat(preview): auto-open preview pane for loopback URLs in chat Detect http(s) loopback URLs in incoming assistant messages and open the preview pane automatically, deduped per (session, url) pair so re-renders or repeated mentions do not steal focus. Add an inline Preview button next to loopback links in chat markdown as a manual fallback when the auto-open was dismissed or the URL appeared in an older message. - url.ts: isLoopbackHttpUrl / extractLoopbackUrls helpers - ChatContainer: module-level dedupe Set + effect on active session tail - MarkdownRendererImpl: optional onPreviewLoopback in main renderer only (SimpleMarkdownRenderer for tool diffs is intentionally untouched) - Reuses existing terminalView.preview.open i18n keys * feat: preview enhancements, dev shutdown, and reliability fixes Add preview start/stop UI in ContextPanel/Header, improve URL detection (Python HTTP server logs, trailing punctuation, IPv6 loopback), fix proxy path filtering to avoid disrupting non-preview WebSockets. Add dev-only /api/system/dev-shutdown endpoint and Header button to terminate local dev processes and orphaned preview servers. Improve terminal cleanup with process group killing, event pipeline reconnect backoff. Update file read APIs with optional flag and cache control. Add /api/system/free-port endpoint, detectDevServer.ts utility, and preview/shutdown i18n strings for 5 languages. * fix: harden preview support * fix: keep terminal toolbar interactive * fix: keep expanded terminal below header * fix: keep preview iframe under proxy path * fix: respect project action preview urls * fix: rewrite preview asset urls * feat: capture preview console logs * feat: annotate preview elements * feat: attach preview annotation screenshots * fix: improve proxied preview hmr * feat: refine preview action UX * fix: address preview review feedback * fix: show auto-discover preview wait state --------- Co-authored-by: William Biggers <will@Williams-MacBook-Pro.local> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
William Biggers
Bohdan Triapitsyn
parent
67d05a23fc
commit
bd9a91335c
@@ -696,12 +696,26 @@ export const dict: Record<I18nKey, string> = {
|
||||
"contextPanel.mode.diff": "Diff",
|
||||
"contextPanel.mode.plan": "План",
|
||||
"contextPanel.mode.context": "Контекст",
|
||||
"contextPanel.mode.preview": "Перегляд",
|
||||
"contextPanel.tab.closeTabAria": "Закрити вкладку {label}",
|
||||
"contextPanel.actions.collapsePanel": "Згорнути панель",
|
||||
"contextPanel.actions.expandPanel": "Розгорнути панель",
|
||||
"contextPanel.actions.closePanel": "Закрити панель",
|
||||
"contextPanel.actions.resizePanelAria": "Змінити розмір контекстної панелі",
|
||||
"contextPanel.iframe.sessionChatTitle": "Сесійний чат {sessionID}",
|
||||
"contextPanel.preview.actions.reload": "Перезавантажити перегляд",
|
||||
"contextPanel.preview.actions.openExternal": "Відкрити в браузері",
|
||||
"contextPanel.preview.actions.retry": "Повторити",
|
||||
"contextPanel.preview.iframeTitle": "Перегляд",
|
||||
"contextPanel.preview.invalidUrl": "Для перегляду потрібна коректна URL http(s).",
|
||||
"contextPanel.preview.empty": "Немає URL для перегляду",
|
||||
"contextPanel.preview.loading": "Підключення проксі перегляду...",
|
||||
"contextPanel.preview.proxyError": "Не вдалося запустити проксі перегляду.",
|
||||
"contextPanel.preview.upstreamUnreachable": "Сервер розробки не відповідає.",
|
||||
"contextPanel.preview.upstreamUnreachableHint": "Переконайтеся, що сервер розробки все ще працює, і повторіть спробу.",
|
||||
|
||||
"terminalView.preview.open": "Перегляд",
|
||||
"terminalView.preview.openTitle": "Відкрити панель перегляду",
|
||||
"sidebarFilesTree.menu.rename": "Перейменувати",
|
||||
"sidebarFilesTree.menu.copyPath": "Копіювати шлях",
|
||||
"sidebarFilesTree.menu.save": "Зберегти",
|
||||
@@ -958,6 +972,7 @@ export const dict: Record<I18nKey, string> = {
|
||||
"header.services.noRateLimitsReported": "Ліміти запитів не надходять.",
|
||||
"header.services.used": "Використано",
|
||||
"header.services.remaining": "Залишилося",
|
||||
"header.services.shutdownDev": "Зупинити OpenChamber",
|
||||
"header.services.modelFamily.other": "інше",
|
||||
"header.actions.openPlanAria": "Відкрити план",
|
||||
"header.actions.planWithShortcut": "План ({shortcut})",
|
||||
@@ -1330,6 +1345,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
"chat.messageBody.actions.fork": "Відгалузити звідси",
|
||||
"chat.messageBody.actions.copyMessageAria": "Копіювати текст повідомлення",
|
||||
"chat.messageBody.actions.copyMessage": "Копіювати повідомлення",
|
||||
"chat.messageBody.actions.openPreviewAria": "Відкрити попередній перегляд",
|
||||
"chat.messageBody.actions.openPreview": "Відкрити попередній перегляд",
|
||||
"chat.messageBody.actions.copyAnswer": "Скопіювати відповідь",
|
||||
"chat.messageBody.actions.savingImage": "Збереження зображення...",
|
||||
"chat.messageBody.actions.saveAsImage": "Зберегти як зображення",
|
||||
@@ -1383,6 +1400,11 @@ export const dict: Record<I18nKey, string> = {
|
||||
"chat.chatInput.toast.openSessionFirst": "Спочатку відкрийте сесію",
|
||||
"chat.chatInput.toast.togglePermissionAutoAcceptFailed": "Не вдалося ввімкнути автоматичне прийняття дозволів",
|
||||
"chat.chatInput.reviewComments": "Коментарі рев’ю:",
|
||||
"chat.chatInput.devServerLogs": "Логи Dev Server:",
|
||||
"chat.chatInput.devServerLogsRemove": "Прибрати логи Dev Server",
|
||||
"chat.chatInput.previewAnnotations": "Анотації перегляду:",
|
||||
"chat.chatInput.previewContext": "Контекст перегляду:",
|
||||
"chat.chatInput.previewContextRemove": "Прибрати контекст перегляду",
|
||||
"chat.chatInput.projectRoot": "Корінь проєкту",
|
||||
"chat.chatInput.branch": "гілка",
|
||||
"chat.chatInput.worktrees": "Worktree",
|
||||
@@ -1763,7 +1785,9 @@ export const dict: Record<I18nKey, string> = {
|
||||
"projectActions.actions.addActionAria": "Додати дію",
|
||||
"projectActions.actions.addAction": "Додати дію",
|
||||
"projectActions.actions.addNewAction": "Додати нову дію",
|
||||
"projectActions.actions.autoDiscover": "Автовиявлення",
|
||||
"projectActions.actions.chooseActionAria": "Вибрати дію проєкту",
|
||||
"projectActions.actions.openPreview": "Відкрити Preview",
|
||||
"projectActions.actions.runNamedAria": "Запустити {name}",
|
||||
"projectActions.actions.stopNamedAria": "Зупинити {name}",
|
||||
"projectActions.label.fallbackAction": "Дія",
|
||||
@@ -2092,4 +2116,39 @@ export const dict: Record<I18nKey, string> = {
|
||||
"markdownRenderer.mermaid.actions.copySourceTitle": "Копіювати джерело",
|
||||
"markdownRenderer.mermaid.actions.downloadSvgTitle": "Завантажити SVG",
|
||||
"markdownRenderer.mermaid.toast.downloadFailed": "Не вдалося завантажити діаграму",
|
||||
"contextPanel.preview.title": "Попередній перегляд",
|
||||
"contextPanel.preview.description": "Використайте дії проєкту або кнопку Preview у терміналі, щоб відкрити перегляд.",
|
||||
"contextPanel.preview.startPreview": "Почати перегляд",
|
||||
"contextPanel.preview.starting": "Запуск...",
|
||||
"contextPanel.preview.noDevServer": "Команду сервера розробки не знайдено. Налаштуйте дію проекту або додайте скрипт \"dev\" у package.json.",
|
||||
"contextPanel.preview.startFailed": "Не вдалося запустити сервер перегляду.",
|
||||
"contextPanel.preview.serverExited": "Сервер розробки несподівано завершив роботу.",
|
||||
"contextPanel.preview.noUrlDetected": "Сервер розробки запущено, але URL не виявлено у його виводі. Відкрийте вкладку термінала попереднього перегляду, щоб переглянути журнали.",
|
||||
"contextPanel.preview.serverExitedWithLog": "Сервер розробки несподівано завершив роботу. Останній вивід:\n\n{log}",
|
||||
"contextPanel.preview.noUrlDetectedWithLog": "Сервер розробки не став доступним. Останній вивід:\n\n{log}",
|
||||
"contextPanel.preview.startingServer": "Запуск сервера розробки...",
|
||||
"contextPanel.preview.startingServerHint": "Очікуємо, поки сервер почне приймати з'єднання.",
|
||||
"contextPanel.preview.console.open": "Відкрити консоль перегляду",
|
||||
"contextPanel.preview.console.waiting": "Очікування консолі перегляду",
|
||||
"contextPanel.preview.console.title": "Консоль перегляду",
|
||||
"contextPanel.preview.console.attach": "Додати",
|
||||
"contextPanel.preview.console.copy": "Копіювати",
|
||||
"contextPanel.preview.console.clear": "Очистити",
|
||||
"contextPanel.preview.console.empty": "Подій консолі перегляду ще немає.",
|
||||
"contextPanel.preview.console.noFilteredEvents": "Немає подій для цього фільтра.",
|
||||
"contextPanel.preview.console.runtimeError": "Помилка виконання",
|
||||
"contextPanel.preview.console.copied": "Консоль перегляду скопійовано",
|
||||
"contextPanel.preview.console.copyFailed": "Не вдалося скопіювати консоль перегляду",
|
||||
"contextPanel.preview.console.attached": "Консоль перегляду додано до чату",
|
||||
"contextPanel.preview.console.attachNoSession": "Відкрийте чат-сесію перед додаванням логів перегляду",
|
||||
"contextPanel.preview.console.attachAnnotation": "Це браузерні console logs із dev server, що запущений для цього проєкту.",
|
||||
"contextPanel.preview.inspect.toggle": "Інспектувати елемент перегляду",
|
||||
"contextPanel.preview.inspect.attached": "Анотацію перегляду додано до чату",
|
||||
"contextPanel.preview.inspect.attachNoSession": "Відкрийте чат-сесію перед додаванням анотацій перегляду",
|
||||
"contextPanel.preview.inspect.attachAnnotation": "Це вибраний DOM-елемент із вбудованого перегляду.",
|
||||
"contextPanel.preview.inspect.attachAnnotationWithScreenshot": "Це вибраний DOM-елемент із вбудованого перегляду. Скріншот видимої області перегляду з підсвіченим елементом додано як вкладення.",
|
||||
"contextPanel.preview.console.filter.all": "Усі",
|
||||
"contextPanel.preview.console.filter.errors": "Помилки",
|
||||
"contextPanel.preview.console.filter.warnings": "Попередження",
|
||||
"contextPanel.preview.console.filter.logs": "Логи",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user