feat(host): 浮窗聊天框打通(apiProxy.sessions.prompt)+ 会话控制路由 + 事件直方图自检

This commit is contained in:
2026-09-27 14:25:35 +08:00
parent b58bde162f
commit 5aa92d50da
3 changed files with 126 additions and 5 deletions
+21 -1
View File
@@ -610,8 +610,10 @@
}
let es = null
let ENDPOINT = null
function setEndpoint(ep) {
const live = !!(ep && ep.baseUrl)
ENDPOINT = live ? ep.baseUrl : null
$('dot').className = 'dot ' + (live ? 'live' : 'wait')
$('sub').textContent = live ? ep.baseUrl.replace(/^https?:\/\//, '') : '未连接'
$('input').disabled = !live
@@ -702,8 +704,26 @@
const submit = () => {
const v = $('input').value.trim()
if (!v) return
send({ cmd: 'chat', text: v })
$('input').value = ''; $('input').style.height = 'auto'
if (ENDPOINT) {
// 真实发送:POST 给插件,由它走宿主网关送进会话
fetch(ENDPOINT + '/dsh-float-window/chat', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ text: v }),
}).then((r) => r.json()).then((j) => {
if (!j.ok) toast('发送失败:' + j.error)
}).catch((e) => toast('发送失败:' + e.message))
} else {
send({ cmd: 'chat', text: v })
}
}
function toast(msg) {
const el = document.createElement('div')
el.textContent = msg
el.style.cssText = 'position:fixed;left:8px;right:8px;bottom:44px;background:#3a2028;border:1px solid #7a2b3a;color:#ffd7de;font-size:11.5px;padding:6px 8px;border-radius:8px;z-index:40'
document.body.appendChild(el)
setTimeout(() => el.remove(), 4000)
}
$('send').onclick = submit
$('input').addEventListener('keydown', (e) => {