Import ECS deployed relay source and historical patches (2026-10-27)

This commit is contained in:
ex_tianzy
2026-10-27 17:26:58 +08:00
commit 011a7797ee
319 changed files with 34265 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
"use strict";
const byId = id => document.getElementById(id);
const statusNode = byId("status");
let sending = false;
let loggedIn = false;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
function note(text) { statusNode.textContent = text; }
function addMessage(text, role) {
const item = document.createElement("div");
item.className = "message " + role;
item.textContent = text;
byId("messages").appendChild(item);
item.scrollIntoView({block:"nearest"});
}
async function refresh() {
try {
const response = await fetch("/web/session", {cache:"no-store", credentials:"same-origin"});
if (!response.ok) {
loggedIn = false;
byId("pair-panel").hidden = false;
byId("chat-panel").hidden = true;
note(response.status === 401 ? "请使用PC上的一次性配对码连接。" : "会话服务暂不可用。");
return;
}
const data = await response.json();
loggedIn = true;
byId("pair-panel").hidden = true;
byId("chat-panel").hidden = false;
byId("device-state").textContent = data.online ? "你的电脑已在线" : "你的电脑当前离线";
if (!sending) note(data.online ? "已连接本人设备,可以开始对话。" : "请在PC启动桥接端,随后再发送消息。");
} catch (_) { if (!sending) note("网络连接失败,请检查到中继的连接。"); }
}
byId("pair-form").addEventListener("submit", async event => {
event.preventDefault();
byId("pair-button").disabled = true;
try {
const response = await fetch("/web/claim", {method:"POST", credentials:"same-origin",
headers:{"Content-Type":"application/json"}, body:JSON.stringify({code:byId("code").value.trim()})});
if (!response.ok) throw new Error(response.status === 404 ? "配对码已过期或已使用,请在PC重新生成。" : "配对失败,请确认地址、配对码和设备绑定。");
byId("code").value = "";
await refresh();
} catch (error) { note(error.message); }
finally { byId("pair-button").disabled = false; }
});
byId("chat-form").addEventListener("submit", async event => {
event.preventDefault();
if (sending || !loggedIn) return;
const text = byId("message").value.trim();
if (!text) return;
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
const requestId = Array.from(bytes, n => n.toString(16).padStart(2,"0")).join("");
sending = true;
byId("send").disabled = true;
byId("logout").disabled = true;
addMessage(text, "user");
byId("message").value = "";
note("正在等待你的电脑和模型返回结果…");
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 200000);
try {
const response = await fetch("/web/chat", {method:"POST", credentials:"same-origin", signal:controller.signal,
headers:{"Content-Type":"application/json"}, body:JSON.stringify({text, request_id:requestId})});
if (!response.ok) throw new Error(response.status === 401 ? "网页会话已失效,请重新配对。" : "请求失败,HTTP " + response.status + "。请核查执行状态后再决定是否重发。");
const data = await response.json();
addMessage(data.result || "未收到文本结果。", data.status === "completed" ? "assistant" : "notice");
note("请求状态:" + data.status);
} catch (error) {
addMessage(error.name === "AbortError" ? "等待超时,执行状态未知。系统没有自动重发。" : error.message, "notice");
note("请求ID:" + requestId + "。请保留此ID排查,勿盲目重发。");
} finally {
clearTimeout(timer); sending = false;
byId("send").disabled = false; byId("logout").disabled = false;
}
});
byId("logout").addEventListener("click", async () => {
try {
const response = await fetch("/web/logout", {method:"POST", credentials:"same-origin"});
if (!response.ok) throw new Error("退出失败,请稍后重试。");
byId("messages").replaceChildren();
await refresh();
} catch (error) { note(error.message); }
});
byId("login").addEventListener("click", async () => {
const popup = window.open("about:blank", "hainuo_authorize");
if (!popup) { note("请允许打开授权窗口。"); return; }
popup.opener = null;
byId("login").disabled = true;
try {
const started = await fetch("/oauth/start", {method:"POST", headers:{"Content-Type":"application/json"}, body:"{}", cache:"no-store"});
if (!started.ok) throw new Error("海能Work授权尚未配置,可先使用PC配对码。");
const transaction = await started.json();
const url = new URL(transaction.authorization_url);
if (url.protocol !== "https:") throw new Error("授权地址必须使用HTTPS。");
popup.location = url.href;
note("请在授权窗口完成登录。");
const until = Date.now() + transaction.expires_in * 1000;
let token;
while (Date.now() < until) {
await sleep(2000);
const response = await fetch("/oauth/claim?state=" + encodeURIComponent(transaction.state), {
headers:{"X-OAuth-Claim-Secret":transaction.claim_secret}, cache:"no-store"});
if (response.status === 202) continue;
if (!response.ok) throw new Error("授权已失效,请重新开始。");
token = (await response.json()).user_access_token;
break;
}
if (!token) throw new Error("等待授权超时。");
const response = await fetch("/web/platform-session", {method:"POST", headers:{Authorization:"Bearer " + token}});
token = null;
if (!response.ok) throw new Error("请先在海能Work完成本人设备绑定。");
await refresh();
} catch (error) { note(error.message); try { popup.close(); } catch (_) {} }
finally { byId("login").disabled = false; }
});
refresh();
setInterval(() => { if (!sending) refresh(); }, 15000);
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>海诺 · 我的工作电脑</title><link rel="stylesheet" href="/assets/style.css"><script defer src="/assets/app.js"></script></head>
<body><main><div class="mark">海诺 HAINUO <span class="badge">试点 · 纯文本</span></div>
<h1>连接你的<br>工作电脑。</h1><p class="intro">电脑上的助手,随时与你对话。先完成本人设备配对,再开始工作。</p>
<section class="card" id="pair-panel"><span class="step">01 / 连接本人设备</span><h2>输入电脑上的配对码</h2>
<p>在已绑定的PC运行网页配对命令,将生成的一次性配对码填在这里。有效期两分钟,请勿转发。</p>
<form id="pair-form"><label for="code">网页配对码</label><input id="code" name="code" autocomplete="off" spellcheck="false" required maxlength="128" placeholder="粘贴PC生成的配对码"><button type="submit" id="pair-button">连接我的电脑 <span>↗</span></button></form>
<details><summary>使用海能Work授权</summary><p>需要管理员已配置平台应用与OAuth回调。</p><button id="login" type="button">通过海能Work登录</button></details></section>
<section class="card" id="chat-panel" hidden><div class="chat-head"><div><span class="step">02 / 本人设备会话</span><h2 id="device-state">正在连接</h2></div><button id="logout" type="button" class="secondary">解除网页登录</button></div>
<p class="hint">当前为纯文本推理。可发送“17加25是多少”,或使用 /主机名 验证目标电脑。暂不开放文件操作。</p>
<div id="messages" role="log" aria-live="polite"></div><form id="chat-form"><label for="message">给你的助手发消息</label><textarea id="message" rows="3" maxlength="8000" placeholder="描述你的问题…" required></textarea><button id="send" type="submit">发送消息 <span>↑</span></button></form></section>
<p id="status" role="status" aria-live="polite">正在检查网页会话…</p>
<footer>PC需保持开机、联网,并运行原生API和桥接端。试点网页由中继在内存中转发正文,不保存聊天记录;当前页关闭后消息不保留。</footer>
</main></body></html>
@@ -0,0 +1,3 @@
:root{color-scheme:light;font-family:system-ui,-apple-system,"Segoe UI","Microsoft YaHei",sans-serif;color:#17372c;background:#f2f4ed}*{box-sizing:border-box}body{margin:0}main{max-width:820px;margin:0 auto;padding:60px 26px}.mark{font-size:13px;letter-spacing:.16em;color:#557764;font-weight:700}h1{font-size:clamp(42px,8vw,70px);letter-spacing:-.05em;line-height:1.12;font-weight:650;margin:40px 0 22px}.intro{font-size:17px;line-height:1.8;color:#56675a;max-width:520px}.card{background:#fff;border:1px solid #dbe3d8;border-radius:20px;padding:30px;margin:40px 0 24px;box-shadow:0 12px 44px #18372c06}.step{font-size:12px;letter-spacing:.1em;color:#6d806c}h2{font-size:24px;margin:16px 0}.card p{line-height:1.8;color:#5b6c60}button{background:#214e3a;color:white;border:0;border-radius:10px;font:inherit;font-weight:600;padding:16px 20px;width:100%;text-align:left;cursor:pointer;margin-top:16px}button span{float:right}button:disabled{opacity:.5;cursor:wait}button:focus-visible,a:focus-visible{outline:3px solid #d0a349;outline-offset:4px}#status{font-size:13px;margin-bottom:0}#open{display:block;margin-top:22px;color:#214e3a;font-weight:600}#open[hidden]{display:none}footer{color:#768373;font-size:12px;line-height:1.8}@media(max-width:480px){main{padding-top:36px}.card{padding:22px}h1{margin-top:28px}}
[hidden]{display:none!important}.badge{float:right;font-size:11px;letter-spacing:0;background:#e4ebdf;border-radius:20px;padding:6px 10px}label{display:block;font-size:13px;color:#526c5b;margin:12px 0 8px}input,textarea{font:inherit;width:100%;border:1px solid #ccd8ce;border-radius:10px;padding:14px;color:#17372c;background:#fafcf8;resize:vertical}input:focus,textarea:focus{outline:2px solid #6c987b;outline-offset:2px}details{margin-top:24px;font-size:13px;color:#587561}summary{cursor:pointer}.chat-head{display:flex;align-items:center;justify-content:space-between;gap:20px}.secondary{width:auto;background:#edf2e9;color:#31523f;padding:9px 12px;font-size:12px;margin:0}.hint{font-size:13px}#messages{display:flex;flex-direction:column;gap:12px;margin:22px 0;max-height:420px;overflow:auto}.message{padding:14px 16px;border-radius:12px;line-height:1.8;white-space:pre-wrap;overflow-wrap:anywhere;font-size:15px}.message.user{background:#e5eee2;margin-left:36px}.message.assistant{background:#f2f5ef;margin-right:24px}.message.notice{background:#fbf4e5;color:#735c2e}#status{font-size:13px;color:#5f745f;line-height:1.8}#chat-panel h2{font-size:20px}footer{max-width:640px}