Self-hosted AI workspace.
Python
Merge lab into refactor/settings-panel-modules
Alexandre Teixeira86212bfe99eb
diff --cc static/js/settings/writingStyle.jsindex 042c8723e,000000000..0a0a7e648mode 100644,000000..100644--- a/static/js/settings/writingStyle.js+++ b/static/js/settings/writingStyle.js@@@ -1,71 -1,0 +1,71 @@@+// Document writing-style settings panel.+// Extracted verbatim from static/js/settings.js. Behaviour is unchanged: the+// functions moved, their bodies did not. settings.js imports them and calls+// them from the same places, so load order and init sequence are untouched.++import { byId as el } from './dom.js';+import { postSettings as _postSettings } from './api.js';++export async function initDocumentWritingStyle() {+ const styleEl = el('set-document-style');+ const saveBtn = el('set-document-style-save');+ const extractBtn = el('set-document-style-extract');+ const fileEl = el('set-document-style-file');+ const msg = el('set-document-style-msg');+ if (!styleEl || !saveBtn) return;+ try {+ const res = await fetch('/api/auth/settings', { credentials: 'same-origin' });+ const data = await res.json();+ styleEl.value = String(data.document_writing_style || '');+ } catch (_) {+ if (msg) msg.textContent = 'Failed to load';+ }+ saveBtn.addEventListener('click', async () => {+ if (msg) msg.textContent = 'Saving...';+ try {+ const res = await _postSettings({ document_writing_style: styleEl.value });+ if (!res.ok) throw new Error(`HTTP ${res.status}`);+ if (msg) msg.textContent = '✓ Saved';+ } catch (_) {+ if (msg) msg.textContent = 'Failed to save';+ }+ setTimeout(() => { if (msg) msg.textContent = ''; }, 3000);+ });+ extractBtn?.addEventListener('click', () => fileEl?.click());+ fileEl?.addEventListener('change', async () => {+ const file = fileEl.files?.[0];+ if (!file) return;+ extractBtn.disabled = true;+ let whirlpool = null;+ if (msg) {+ msg.replaceChildren();+ try {- const spinner = window.spinnerModule || (await import('./spinner.js')).default;++ const spinner = window.spinnerModule || (await import('../spinner.js')).default;+ whirlpool = spinner.createWhirlpool(14);+ whirlpool.element.style.cssText = 'display:inline-flex;width:14px;height:14px;margin-right:7px;';+ const label = document.createElement('span');+ label.textContent = 'Analyzing...';+ msg.append(whirlpool.element, label);+ } catch (_) {+ msg.textContent = 'Analyzing...';+ }+ }+ try {+ const body = new FormData();+ body.append('file', file);+ const res = await fetch('/api/auth/settings/document-style/extract', {+ method: 'POST', credentials: 'same-origin', body,+ });+ const data = await res.json().catch(() => ({}));+ if (!res.ok || !data.style) throw new Error(data.detail || data.error || 'Extraction failed');+ styleEl.value = String(data.style);+ if (msg) msg.textContent = '✓ Extracted — review and save';+ } catch (error) {+ if (msg) msg.textContent = error.message || 'Extraction failed';+ } finally {+ whirlpool?.destroy?.();+ extractBtn.disabled = false;+ fileEl.value = '';+ }+ });+}diff --cc tests/test_active_document_visibility_contract.pyindex 0a19ddedc,81bbfdfea..ddb9df847--- a/tests/test_active_document_visibility_contract.py+++ b/tests/test_active_document_visibility_contract.py@@@ -3,15 -4,10 +4,15 @@@ from tests.helpers.document_source impoROOT = Path(__file__).resolve().parents[1]- DOCUMENT_JS = (ROOT / "static/js/document.js").read_text(encoding="utf-8")+ DOCUMENT_JS = document_source()CHAT_JS = (ROOT / "static/js/chat.js").read_text(encoding="utf-8")APP_JS = (ROOT / "static/app.js").read_text(encoding="utf-8")-SETTINGS_JS = (ROOT / "static/js/settings.js").read_text(encoding="utf-8")+# The writing-style panel moved into static/js/settings/writingStyle.js; read+# the whole settings surface so this pins behaviour rather than a filename.+SETTINGS_JS = "\n".join(+ p.read_text(encoding="utf-8")+ for p in [ROOT / "static/js/settings.js", *sorted((ROOT / "static/js/settings").glob("*.js"))]+)INDEX_HTML = (ROOT / "static/index.html").read_text(encoding="utf-8")CHAT_ROUTE = (ROOT / "routes/chat_routes.py").read_text(encoding="utf-8")diff --cc tests/test_settings_module_import_paths.pyindex 000000000,000000000..808ec77a6new file mode 100644--- /dev/null+++ b/tests/test_settings_module_import_paths.py@@@ -1,0 -1,0 +1,49 @@@++"""Relative imports in extracted settings modules must resolve on disk."""++++import re++from pathlib import Path++++++ROOT = Path(__file__).resolve().parents[1]++SETTINGS = ROOT / "static" / "js" / "settings"++++_FROM_IMPORT = re.compile(r"""\bfrom\s+["']([^"']+)["']""")++_DYNAMIC_IMPORT = re.compile(r"""\bimport\s*\(\s*["']([^"']+)["']\s*\)""")++_SIDE_EFFECT_IMPORT = re.compile(++ r"""^\s*import\s+["']([^"']+)["']""",++ re.MULTILINE,++)++++++def _relative_specifiers(source: str) -> set[str]:++ specs = {++ *_FROM_IMPORT.findall(source),++ *_DYNAMIC_IMPORT.findall(source),++ *_SIDE_EFFECT_IMPORT.findall(source),++ }++ return {spec for spec in specs if spec.startswith(".")}++++++def test_settings_relative_imports_resolve() -> None:++ modules = sorted(SETTINGS.glob("*.js"))++ assert modules, "settings module directory unexpectedly empty"++++ unresolved = []++++ for module in modules:++ source = module.read_text(encoding="utf-8")++++ for spec in sorted(_relative_specifiers(source)):++ clean = spec.split("?", 1)[0].split("#", 1)[0]++ target = (module.parent / clean).resolve()++++ if not target.is_file():++ unresolved.append(++ f"{module.relative_to(ROOT)}: {spec} -> "++ f"{target.relative_to(ROOT)}"++ )++++ assert not unresolved, (++ "relative imports from settings modules do not resolve:\n"++ + "\n".join(unresolved)++ )