Files
zeekay 677e67ffd7 Serve the UI APIs under /v1
The CLI UI's calls move from /ui/api/* to /ui/v1/*, web-chat's from
/api/* to /v1/*. An unknown UI path now 404s instead of falling back
to index.html, which would answer a stale /api/ call with 200. The
pre-Svelte static files nothing loads are gone.

Claude-Session: https://claude.ai/code/session_01TUxvfuta1Z44KVNYuAz71F
2026-09-24 15:01:47 -07:00

74 lines
1.8 KiB
JavaScript

// Model management functionality
// Global model state
const models = Object.create(null); // name -> kind
let prevModel = null;
/**
* Refresh the list of available models
*/
async function refreshModels() {
const res = await fetch('/v1/list_models');
const data = await res.json();
const modelSelect = document.getElementById('modelSelect');
modelSelect.innerHTML = '';
Object.keys(models).forEach(k => delete models[k]);
data.models.forEach(m => {
models[m.name] = m.kind;
const opt = document.createElement('option');
opt.value = m.name;
// Prefix icon based on model kind
let prefix = '📝 ';
if (m.kind === 'vision') prefix = '🖼️ ';
else if (m.kind === 'speech') prefix = '🔊 ';
opt.textContent = prefix + m.name;
modelSelect.appendChild(opt);
});
if (modelSelect.options.length) {
modelSelect.selectedIndex = 0;
prevModel = modelSelect.value;
updateImageVisibility(models[prevModel]);
await selectModel(prevModel, false);
}
await refreshChatList();
if (!currentChatId) {
document.getElementById('newChatBtn').click();
}
}
/**
* Select a model on the server
*/
async function selectModel(name, notify = true) {
await fetch('/v1/select_model', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name })
});
}
/**
* Handle model selection changes
*/
function initModelSelection() {
const modelSelect = document.getElementById('modelSelect');
modelSelect.addEventListener('change', async () => {
const name = modelSelect.value;
if (name === prevModel) return;
if (!maybeClearChat()) {
modelSelect.value = prevModel;
return;
}
updateImageVisibility(models[name]);
clearImagePreviews();
clearTextFilePreviews();
prevModel = name;
await selectModel(name);
});
}