Skip to content

Commit 2f2968f

Browse files
committed
refactor(ui): WebUI modernization PR5 — ES module split
Split the ~2.4k-line app.js IIFE into native ES modules under cmd/odek/ui/js/ (no build step, no dependencies). app.js stays the /app.js entry and now just imports ./js/main.js. - js/state.js: single mutable state object S (all former module-level globals) + session-token persistence helpers - js/dom.js / js/net.js: import-free leaves (getElementById refs, getWsToken/apiHeaders) - js/utils.js / js/markdown.js: pure helpers and markdownToHtml - js/render.js: streaming, thinking, tool blocks, sub-agents, session history, collapse/copy, loading indicator; addMessage monkey-patch dissolved into direct addCopyButton/checkCollapse calls - js/approvals.js / js/sessions.js / js/input.js / js/ws.js / js/main.js: approval queue, sidebar, prompt/attachments/@-completion, WebSocket dispatch, init sequence - All inline onclick/onchange handlers (index.html and generated HTML) replaced with addEventListener / click delegation on #messages; window.* exports removed - serve.go handleStatic: sanitized /js/<file>.js route (rejects .., subdirs, non-.js) served from the embedded uiFS
1 parent 7cee1d5 commit 2f2968f

15 files changed

Lines changed: 2556 additions & 2419 deletions

File tree

cmd/odek/serve.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,17 @@ func handleStatic(wsToken string) http.HandlerFunc {
17621762
return
17631763
}
17641764
entry, ok := staticFiles[r.URL.Path]
1765+
if !ok && strings.HasPrefix(r.URL.Path, "/js/") {
1766+
// ES modules under /js/ are served from the embedded ui/js
1767+
// directory. Sanitize to a flat .js file name so path traversal
1768+
// is impossible.
1769+
name := strings.TrimPrefix(r.URL.Path, "/js/")
1770+
if name != "" && !strings.Contains(name, "..") &&
1771+
!strings.ContainsAny(name, "/\\") && strings.HasSuffix(name, ".js") {
1772+
entry = [2]string{"ui/js/" + name, "application/javascript; charset=utf-8"}
1773+
ok = true
1774+
}
1775+
}
17651776
if !ok {
17661777
http.NotFound(w, r)
17671778
return

0 commit comments

Comments
 (0)