|
1895 | 1895 | applyAttachmentAvailability(false); |
1896 | 1896 |
|
1897 | 1897 | /* ========== UTILITY FUNCTIONS ========== */ |
| 1898 | + function resolveAppUrl(path) { |
| 1899 | + const cleanPath = String(path || '').replace(/^\/+/, ''); |
| 1900 | + |
| 1901 | + if (typeof document !== 'undefined' && document.baseURI) { |
| 1902 | + return new URL(cleanPath, document.baseURI).toString(); |
| 1903 | + } |
| 1904 | + |
| 1905 | + if (typeof window !== 'undefined' && window.location) { |
| 1906 | + return new URL(cleanPath, window.location.href).toString(); |
| 1907 | + } |
| 1908 | + |
| 1909 | + return cleanPath; |
| 1910 | + } |
| 1911 | + |
1898 | 1912 | function isAtBottom() { |
1899 | 1913 | if (!resultsDiv) return true; |
1900 | 1914 | const threshold = 50; // Allow margin for rounding errors |
|
2238 | 2252 | } |
2239 | 2253 |
|
2240 | 2254 | try { |
2241 | | - const response = await fetch('/result', { |
| 2255 | + const response = await fetch(resolveAppUrl('result'), { |
2242 | 2256 | method: 'POST', |
2243 | 2257 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
2244 | 2258 | body: JSON.stringify({ uuid }) |
|
2457 | 2471 | throw new Error('No conversation available to export.'); |
2458 | 2472 | } |
2459 | 2473 |
|
2460 | | - const response = await fetch('/md2html', { |
| 2474 | + const response = await fetch(resolveAppUrl('md2html'), { |
2461 | 2475 | method: 'POST', |
2462 | 2476 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
2463 | 2477 | body: JSON.stringify({ markdown: markdownText }) |
|
2597 | 2611 | resetPlanPanel(); |
2598 | 2612 | try { hljs.highlightAll(); } catch (e) { /* ignore */ } |
2599 | 2613 |
|
2600 | | - const response = await fetch('/prompt', { |
| 2614 | + const response = await fetch(resolveAppUrl('prompt'), { |
2601 | 2615 | method: 'POST', |
2602 | 2616 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
2603 | 2617 | body: JSON.stringify({ prompt: promptForRetry, uuid: retryUuid }) |
|
4304 | 4318 | let shouldEnableMath = false; |
4305 | 4319 |
|
4306 | 4320 | try { |
4307 | | - const response = await fetch('/info', { |
| 4321 | + const response = await fetch(resolveAppUrl('info'), { |
4308 | 4322 | headers: { 'Accept': 'application/json' } |
4309 | 4323 | }); |
4310 | 4324 |
|
|
4379 | 4393 | .filter(uuid => typeof uuid === 'string' && uuid.length > 0); |
4380 | 4394 |
|
4381 | 4395 | await Promise.allSettled(uuidsToClear.map(uuid => { |
4382 | | - return fetch('/clear', { |
| 4396 | + return fetch(resolveAppUrl('clear'), { |
4383 | 4397 | method: 'POST', |
4384 | 4398 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
4385 | 4399 | body: JSON.stringify({ uuid, force: true }) |
|
4421 | 4435 |
|
4422 | 4436 | if (entry && entry.uuid) { |
4423 | 4437 | try { |
4424 | | - await fetch('/clear', { |
| 4438 | + await fetch(resolveAppUrl('clear'), { |
4425 | 4439 | method: 'POST', |
4426 | 4440 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
4427 | 4441 | body: JSON.stringify({ uuid: entry.uuid, force: true }) |
|
4516 | 4530 | } |
4517 | 4531 |
|
4518 | 4532 | try { |
4519 | | - const response = await fetch('/load-history', { |
| 4533 | + const response = await fetch(resolveAppUrl('load-history'), { |
4520 | 4534 | method: 'POST', |
4521 | 4535 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
4522 | 4536 | body: JSON.stringify(payload) |
|
4582 | 4596 | } |
4583 | 4597 |
|
4584 | 4598 | try { |
4585 | | - const response = await fetch('/result', { |
| 4599 | + const response = await fetch(resolveAppUrl('result'), { |
4586 | 4600 | method: 'POST', |
4587 | 4601 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
4588 | 4602 | body: JSON.stringify({ uuid }) |
|
4932 | 4946 | stopStream(); |
4933 | 4947 |
|
4934 | 4948 | if (currentSessionUuid) { |
4935 | | - fetch('/result', { |
| 4949 | + fetch(resolveAppUrl('result'), { |
4936 | 4950 | method: 'POST', |
4937 | 4951 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
4938 | 4952 | body: JSON.stringify({ uuid: currentSessionUuid, request: 'stop' }) |
|
4984 | 4998 | } |
4985 | 4999 |
|
4986 | 5000 | function collectBrowserContext() { |
4987 | | - const colorScheme = (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) |
| 5001 | + const colorScheme = (document.body.classList.contains('markdown-body-dark') || _isD === true || (typeof __isDark !== 'undefined' && __isDark)) |
4988 | 5002 | ? 'dark' |
4989 | 5003 | : 'light'; |
4990 | 5004 | const promptStyles = (typeof window !== 'undefined' && promptInput) ? window.getComputedStyle(promptInput) : null; |
|
5044 | 5058 | lastRawContent += userPromptDiv; |
5045 | 5059 | await renderRawContent(lastRawContent); |
5046 | 5060 |
|
5047 | | - const response = await fetch('/prompt', { |
| 5061 | + const response = await fetch(resolveAppUrl('prompt'), { |
5048 | 5062 | method: 'POST', |
5049 | 5063 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
5050 | 5064 | body: JSON.stringify({ prompt: finalPrompt, uuid: currentSessionUuid, browserContext }) |
|
5067 | 5081 |
|
5068 | 5082 | async function pollOnce() { |
5069 | 5083 | try { |
5070 | | - const response = await fetch('/result', { |
| 5084 | + const response = await fetch(resolveAppUrl('result'), { |
5071 | 5085 | method: 'POST', |
5072 | 5086 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
5073 | 5087 | body: JSON.stringify({ uuid: currentSessionUuid }) |
|
5209 | 5223 | streamActive = true; |
5210 | 5224 | streamBuffer = ''; |
5211 | 5225 |
|
5212 | | - const streamUrl = '/stream?uuid=' + encodeURIComponent(uuid); |
| 5226 | + const streamUrl = resolveAppUrl('stream') + '?uuid=' + encodeURIComponent(uuid); |
5213 | 5227 | streamSource = new EventSource(streamUrl); |
5214 | 5228 | streamSource.addEventListener('stream', (event) => { |
5215 | 5229 | if (!event || !event.data) return; |
|
5264 | 5278 | async function sendPing(uuid) { |
5265 | 5279 | if (!uuid) return; |
5266 | 5280 | try { |
5267 | | - await fetch('/ping', { |
| 5281 | + await fetch(resolveAppUrl('ping'), { |
5268 | 5282 | method: 'POST', |
5269 | 5283 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
5270 | 5284 | body: JSON.stringify({ uuid }) |
|
5284 | 5298 | } |
5285 | 5299 |
|
5286 | 5300 | if (uuidToClear) { |
5287 | | - fetch('/clear', { |
| 5301 | + fetch(resolveAppUrl('clear'), { |
5288 | 5302 | method: 'POST', |
5289 | 5303 | headers: { 'Content-Type': 'application/json; charset=utf-8' }, |
5290 | 5304 | body: JSON.stringify({ uuid: uuidToClear }) |
|
5567 | 5581 | bindThemeListener(window.matchMedia('(prefers-color-scheme: dark)')); |
5568 | 5582 | bindThemeListener(window.matchMedia('(prefers-color-scheme: light)')); |
5569 | 5583 | </script> |
5570 | | -<script src="/js/mdtablesort.js"></script> |
| 5584 | +<script src="js/mdtablesort.js"></script> |
0 commit comments