Changeset 0.24.3 (#159)

This commit is contained in:
2026-03-07 20:49:23 +00:00
parent ea082e2016
commit 937be26578
20 changed files with 836 additions and 29 deletions

View File

@@ -0,0 +1,162 @@
{{define "workflow.html"}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Data.ChannelTitle}} — {{.InstanceName}}</title>
<link rel="icon" type="image/svg+xml" href="{{.BasePath}}/favicon.svg?v={{.Version}}">
<link rel="icon" type="image/x-icon" href="{{.BasePath}}/favicon.ico?v={{.Version}}">
<link rel="stylesheet" href="{{.BasePath}}/css/variables.css?v={{.Version}}">
<link rel="stylesheet" href="{{.BasePath}}/css/primitives.css?v={{.Version}}">
<link rel="stylesheet" href="{{.BasePath}}/css/chat.css?v={{.Version}}">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); }
.wf-shell { display: flex; flex-direction: column; height: 100vh; }
.wf-header {
padding: 16px 24px;
border-bottom: 1px solid var(--border);
background: var(--bg-surface);
}
.wf-header h1 { font-size: 18px; font-weight: 600; }
.wf-header p { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.wf-chat {
flex: 1; overflow-y: auto; padding: 16px 24px;
}
.wf-chat .message {
margin-bottom: 12px; padding: 10px 14px;
border-radius: 8px; max-width: 80%;
}
.wf-chat .message.user { background: var(--accent-dim); margin-left: auto; }
.wf-chat .message.assistant { background: var(--bg-raised); }
.wf-chat .message .meta { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.wf-chat .message .content { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.wf-input {
padding: 12px 24px; border-top: 1px solid var(--border);
background: var(--bg-surface); display: flex; gap: 8px;
}
.wf-input textarea {
flex: 1; resize: none; background: var(--input-bg); color: var(--text);
border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
font-family: var(--font); font-size: 14px; min-height: 42px; max-height: 160px;
}
.wf-input textarea:focus { outline: none; border-color: var(--accent); }
.wf-input button {
background: var(--accent); color: #fff; border: none; border-radius: 8px;
padding: 0 20px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.wf-input button:hover { background: var(--accent-hover); }
.wf-input button:disabled { opacity: 0.5; cursor: default; }
.wf-session-info {
padding: 8px 24px; font-size: 12px; color: var(--text-3);
border-top: 1px solid var(--border); background: var(--bg);
}
</style>
<script>
(function() {
try {
var p = JSON.parse(localStorage.getItem('cs-appearance') || '{}');
var mode = p.theme || 'system';
var resolved = mode;
if (mode === 'system') resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', resolved);
} catch(e) {}
})();
</script>
</head>
<body>
<div class="wf-shell">
<div class="wf-header">
<h1>{{.Data.ChannelTitle}}</h1>
{{if .Data.ChannelDescription}}<p>{{.Data.ChannelDescription}}</p>{{end}}
</div>
<div class="wf-chat" id="chatMessages"></div>
<div class="wf-input">
<textarea id="chatInput" placeholder="Type a message…" rows="1"
onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();sendMessage()}"></textarea>
<button id="sendBtn" onclick="sendMessage()">Send</button>
</div>
<div class="wf-session-info">
Chatting as <strong>{{.Data.SessionName}}</strong>
</div>
</div>
<script>
(function() {
const BASE = '{{.BasePath}}';
const CHAN_ID = '{{.Data.ChannelID}}';
const SESSION_ID = '{{.Data.SessionID}}';
const chatEl = document.getElementById('chatMessages');
const inputEl = document.getElementById('chatInput');
const sendBtn = document.getElementById('sendBtn');
let sending = false;
function addMessage(role, content, name) {
const div = document.createElement('div');
div.className = 'message ' + role;
const meta = name ? '<div class="meta">' + escHtml(name) + '</div>' : '';
div.innerHTML = meta + '<div class="content">' + escHtml(content) + '</div>';
chatEl.appendChild(div);
chatEl.scrollTop = chatEl.scrollHeight;
}
function escHtml(s) {
const d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
window.sendMessage = async function() {
const text = inputEl.value.trim();
if (!text || sending) return;
sending = true;
sendBtn.disabled = true;
inputEl.value = '';
addMessage('user', text, '{{.Data.SessionName}}');
// The completion endpoint persists the user message and generates the response
try {
const resp = await fetch(BASE + '/api/v1/w/' + CHAN_ID + '/completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ channel_id: CHAN_ID, content: text, stream: false }),
});
if (resp.ok) {
const data = await resp.json();
if (data.content) {
addMessage('assistant', data.content, data.persona_name || 'Assistant');
}
} else {
const err = await resp.json().catch(() => ({}));
addMessage('assistant', 'Error: ' + (err.error || resp.statusText));
}
} catch(e) {
addMessage('assistant', 'Network error: ' + e.message);
}
sending = false;
sendBtn.disabled = false;
inputEl.focus();
};
// Auto-resize textarea
inputEl.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = Math.min(this.scrollHeight, 160) + 'px';
});
})();
</script>
</body>
</html>
{{end}}