<!doctype html>
|
<html lang="en">
|
<head>
|
<meta charset="utf-8">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<title>LLM Command Palette</title>
|
<style>
|
:root {
|
color-scheme: dark;
|
font-family: "Segoe UI", system-ui, sans-serif;
|
background: transparent;
|
}
|
|
* {
|
box-sizing: border-box;
|
}
|
|
html,
|
body {
|
width: 100%;
|
min-height: 100%;
|
margin: 0;
|
background: transparent;
|
overflow: hidden;
|
}
|
|
body {
|
padding: 8px;
|
}
|
|
.shell {
|
width: 100%;
|
color: rgba(255, 255, 255, 0.92);
|
}
|
|
.bar,
|
.output {
|
width: 100%;
|
border: 1px solid rgba(255, 255, 255, 0.16);
|
background: rgba(30, 28, 27, 0.74);
|
box-shadow: 0 18px 42px rgba(0, 0, 0, 0.24);
|
backdrop-filter: blur(18px);
|
}
|
|
.bar {
|
display: grid;
|
grid-template-columns: 24px minmax(0, 1fr) 128px;
|
align-items: center;
|
gap: 14px;
|
min-height: 56px;
|
padding: 0 18px;
|
border-radius: 20px;
|
}
|
|
.mark {
|
width: 18px;
|
height: 18px;
|
color: #ff8258;
|
display: grid;
|
place-items: center;
|
font-size: 20px;
|
line-height: 1;
|
transform-origin: center;
|
}
|
|
.mark.busy {
|
animation: spin 1.1s linear infinite;
|
}
|
|
@keyframes spin {
|
to { transform: rotate(360deg); }
|
}
|
|
textarea {
|
width: 100%;
|
min-height: 24px;
|
max-height: 78px;
|
resize: none;
|
border: 0;
|
outline: none;
|
color: rgba(255, 255, 255, 0.94);
|
background: transparent;
|
font: 600 16px/1.35 "Segoe UI", system-ui, sans-serif;
|
letter-spacing: 0;
|
overflow-y: auto;
|
}
|
|
textarea::placeholder {
|
color: rgba(255, 255, 255, 0.46);
|
}
|
|
select {
|
width: 100%;
|
height: 34px;
|
border: 0;
|
outline: none;
|
color: rgba(255, 255, 255, 0.82);
|
background: rgba(255, 255, 255, 0.08);
|
border-radius: 8px;
|
padding: 0 8px;
|
font: 600 13px/1 "Segoe UI", system-ui, sans-serif;
|
}
|
|
.output {
|
display: none;
|
margin-top: 8px;
|
max-height: 50vh;
|
overflow: auto;
|
border-radius: 16px;
|
padding: 16px 18px 14px;
|
font-size: 14px;
|
line-height: 1.55;
|
white-space: pre-wrap;
|
}
|
|
.output.open {
|
display: block;
|
}
|
|
.actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 8px;
|
margin-top: 12px;
|
}
|
|
button {
|
width: 30px;
|
height: 30px;
|
border: 0;
|
border-radius: 8px;
|
color: rgba(255, 255, 255, 0.84);
|
background: rgba(255, 255, 255, 0.08);
|
cursor: pointer;
|
}
|
|
.error {
|
color: #ffad9b;
|
}
|
</style>
|
</head>
|
<body>
|
<main class="shell">
|
<section class="bar">
|
<div id="mark" class="mark" aria-hidden="true">*</div>
|
<textarea id="prompt" rows="1" placeholder="What can I help you with today?"></textarea>
|
<select id="model" title="Model"></select>
|
</section>
|
<section id="output" class="output" aria-live="polite">
|
<div id="text"></div>
|
<div class="actions">
|
<button id="copy" title="Copy">C</button>
|
<button id="collapse" title="Collapse">-</button>
|
</div>
|
</section>
|
</main>
|
|
<script>
|
const promptInput = document.getElementById("prompt");
|
const modelSelect = document.getElementById("model");
|
const output = document.getElementById("output");
|
const text = document.getElementById("text");
|
const mark = document.getElementById("mark");
|
const copy = document.getElementById("copy");
|
const collapse = document.getElementById("collapse");
|
let activeRequestId = null;
|
let currentText = "";
|
|
function setBusy(busy) {
|
mark.classList.toggle("busy", busy);
|
mark.textContent = busy ? "*" : "*";
|
}
|
|
function openOutput() {
|
output.classList.add("open");
|
window.moliDesktop?.requestResize?.({ width: document.body.scrollWidth, height: Math.min(window.innerHeight, document.body.scrollHeight) }).catch(() => {});
|
}
|
|
function setError(message) {
|
currentText = message;
|
text.className = "error";
|
text.textContent = message;
|
openOutput();
|
}
|
|
async function loadModels() {
|
try {
|
const models = await window.moliDesktop.llm.getModels();
|
modelSelect.innerHTML = "";
|
for (const model of models) {
|
const option = document.createElement("option");
|
option.value = model.id;
|
option.textContent = model.label || model.id;
|
option.title = `${model.provider} / ${model.id}`;
|
modelSelect.appendChild(option);
|
}
|
|
if (models.length === 0) {
|
const option = document.createElement("option");
|
option.textContent = "No models";
|
option.value = "";
|
modelSelect.appendChild(option);
|
}
|
} catch {
|
modelSelect.innerHTML = "<option value=\"\">No models</option>";
|
}
|
}
|
|
async function submitPrompt() {
|
const content = promptInput.value.trim();
|
const modelId = modelSelect.value;
|
if (!content || !modelId || activeRequestId) return;
|
|
currentText = "";
|
text.className = "";
|
text.textContent = "";
|
openOutput();
|
setBusy(true);
|
|
try {
|
const response = await window.moliDesktop.llm.streamChat({
|
modelId,
|
messages: [{ role: "user", content }],
|
options: {}
|
});
|
activeRequestId = response.requestId;
|
} catch (error) {
|
activeRequestId = null;
|
setBusy(false);
|
setError(error?.message || "LLM request could not be started.");
|
}
|
}
|
|
promptInput.addEventListener("keydown", (event) => {
|
if (event.key === "Enter" && !event.shiftKey) {
|
event.preventDefault();
|
submitPrompt();
|
}
|
|
if (event.key === "Escape") {
|
output.classList.remove("open");
|
}
|
});
|
|
promptInput.addEventListener("input", () => {
|
promptInput.style.height = "0";
|
promptInput.style.height = `${Math.min(promptInput.scrollHeight, 78)}px`;
|
});
|
|
collapse.addEventListener("click", () => output.classList.remove("open"));
|
copy.addEventListener("click", () => navigator.clipboard?.writeText(currentText).catch(() => {}));
|
|
window.addEventListener("DOMContentLoaded", loadModels);
|
window.moliDesktop?.llm?.onDelta?.((event) => {
|
if (event.requestId !== activeRequestId) return;
|
currentText += event.delta || "";
|
text.textContent = currentText;
|
output.scrollTop = output.scrollHeight;
|
});
|
window.moliDesktop?.llm?.onCompleted?.((event) => {
|
if (event.requestId !== activeRequestId) return;
|
activeRequestId = null;
|
setBusy(false);
|
});
|
window.moliDesktop?.llm?.onError?.((event) => {
|
if (event.requestId !== activeRequestId) return;
|
activeRequestId = null;
|
setBusy(false);
|
setError(event.message || "LLM request failed.");
|
});
|
</script>
|
</body>
|
</html>
|