1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// KEEP IN SYNC WITH crates/trusty-{analyze,search}/ui/src/lib/base.js
/*
* Why: When the SPA is served through the trusty-console reverse-proxy at
* `/proxy/memory/`, absolute fetch paths like `/health` or EventSource URLs
* like `/sse` would resolve to the console host root instead of the daemon.
* This helper derives the correct base URL from the document's actual location
* so that all API calls work both when served directly by the daemon
* (base = origin/) and when served under a proxy sub-path
* (base = origin/proxy/memory/).
* What: Returns an absolute base URL string by snapshotting document.baseURI
* once at module load (before any navigation), stripping the trailing
* `index.html` if present. Checks `window.__MEMORY_BASE__` first so
* deployments that inject that global keep working.
* Test: In a browser at http://127.0.0.1:7788/proxy/memory/ the return value
* should be "http://127.0.0.1:7788/proxy/memory/"; at http://127.0.0.1:7079/
* it should be "http://127.0.0.1:7079/".
* Verify proxy mode: open the SPA at /proxy/memory/ and confirm api.health()
* fetches /proxy/memory/health not /health.
*
* NOTE: The base is snapshotted once at module-init time (see API_BASE
* below). All three SPAs use hash-based routing, so location.pathname never
* changes after load — but snapshotting makes the helper robust if that
* ever changes.
*/
/**
* Compute the base URL once from the current document location.
* Checks (in order):
* 1. `window.__MEMORY_BASE__` (override, for deployment flexibility).
* 2. `document.baseURI` stripped of trailing `index.html`.
* 3. "/" as a final fallback for non-browser environments.
* @returns {string}
*/
// Snapshot the base once at module load. This runs before any client-side
// navigation, guaranteeing the proxy sub-path is captured correctly even if
// routing ever switches to pathname-based navigation in the future.
const API_BASE = ;
/**
* Returns the snapshotted base URL for API calls.
* @returns {string}
*/
export
/**
* Resolves an API path relative to the derived base URL.
* Paths starting with "/" are treated as relative to the base, NOT to the
* origin, so "/health" under base "http://host/proxy/memory/" becomes
* "http://host/proxy/memory/health".
* @param {string} path Absolute-looking path, e.g. "/health" or "/api/v1/status"
* @returns {string} Fully-qualified URL string
*/
export