feat: 可配置方案引擎通用原型(Mock 检索)

需求未定稿时可先跑通追问/判定/出方案;槽位与判定树外置 YAML,后续可接 Ragflow。

Co-authored-by: haijd <haijd@163.com>
This commit is contained in:
Cursor Agent
2026-09-18 09:12:18 +00:00
co-authored by haijd
parent 93b0867eb3
commit 9c6afcb61a
24 changed files with 978 additions and 24 deletions
+73
View File
@@ -0,0 +1,73 @@
let sessionId = null;
const logEl = document.getElementById("log");
const slotsEl = document.getElementById("slots");
const schemeEl = document.getElementById("scheme");
const metaEl = document.getElementById("meta");
const form = document.getElementById("form");
const input = document.getElementById("input");
const resetBtn = document.getElementById("reset");
function addBubble(role, text) {
const div = document.createElement("div");
div.className = `bubble ${role}`;
div.textContent = text;
logEl.appendChild(div);
logEl.scrollTop = logEl.scrollHeight;
}
async function ensureSession() {
if (sessionId) return sessionId;
const res = await fetch("/api/sessions", { method: "POST" });
const data = await res.json();
sessionId = data.session_id;
metaEl.textContent = `session: ${sessionId.slice(0, 8)}…`;
return sessionId;
}
async function sendMessage(message) {
await ensureSession();
addBubble("user", message);
const res = await fetch("/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ session_id: sessionId, message }),
});
if (!res.ok) {
addBubble("sys", `错误:${res.status}`);
return;
}
const data = await res.json();
addBubble("bot", data.reply);
slotsEl.textContent = JSON.stringify(data.slots || {}, null, 2);
schemeEl.textContent = data.scheme
? JSON.stringify(data.scheme, null, 2)
: "尚未生成";
metaEl.textContent = `session: ${sessionId.slice(0, 8)}… · phase: ${data.phase}`;
}
form.addEventListener("submit", async (e) => {
e.preventDefault();
const text = input.value.trim();
if (!text) return;
input.value = "";
form.querySelector("button").disabled = true;
try {
await sendMessage(text);
} finally {
form.querySelector("button").disabled = false;
input.focus();
}
});
resetBtn.addEventListener("click", () => {
sessionId = null;
logEl.innerHTML = "";
slotsEl.textContent = "{}";
schemeEl.textContent = "尚未生成";
metaEl.textContent = "";
addBubble("bot", "新会话已开始。可以直接说场景,例如:「产线检测,偏向 B 类」。");
input.focus();
});
addBubble("bot", "你好,我是鲜境方案引擎原型。先收集几个关键信息,再给出产品组合草稿。\n试试:「我们在户外做监测,指标还不确定」。");
+43
View File
@@ -0,0 +1,43 @@
<!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="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600;700&family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="/static/styles.css" />
</head>
<body>
<div class="page">
<header class="hero">
<p class="brand">鲜境物联 · 方案引擎原型</p>
<h1>先跑通「追问 → 判定 → 出方案」</h1>
<p class="sub">槽位与判定树在 <code>knowledge/*.yaml</code>,需求变了改配置即可。当前检索为 Mock,可后再接 Ragflow。</p>
</header>
<main class="layout">
<section class="chat panel">
<div id="log" class="log" aria-live="polite"></div>
<form id="form" class="composer">
<input id="input" type="text" placeholder="描述需求,或直接回答追问…" autocomplete="off" required />
<button type="submit">发送</button>
</form>
<div class="toolbar">
<button type="button" id="reset" class="ghost">新会话</button>
<span id="meta" class="meta"></span>
</div>
</section>
<aside class="side panel">
<h2>当前槽位</h2>
<pre id="slots">{}</pre>
<h2>最近方案</h2>
<pre id="scheme">尚未生成</pre>
</aside>
</main>
</div>
<script src="/static/app.js"></script>
</body>
</html>
+144
View File
@@ -0,0 +1,144 @@
:root {
--bg0: #0f1c17;
--bg1: #163528;
--panel: rgba(248, 250, 246, 0.94);
--ink: #14231c;
--muted: #5c7268;
--accent: #1f7a4c;
--accent-2: #c4f06a;
--line: rgba(20, 35, 28, 0.12);
--bot: #e7f2ea;
--user: #1f7a4c;
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
font-family: "Noto Sans SC", "DM Sans", sans-serif;
color: var(--ink);
background:
radial-gradient(1200px 600px at 10% -10%, #2f6b4f 0%, transparent 55%),
radial-gradient(900px 500px at 100% 0%, #8fd36a 0%, transparent 45%),
linear-gradient(160deg, var(--bg0), var(--bg1));
}
.page { max-width: 1100px; margin: 0 auto; padding: 32px 20px 48px; }
.hero { color: #f4faf6; margin-bottom: 22px; }
.brand {
margin: 0 0 8px;
font-family: "DM Sans", sans-serif;
letter-spacing: 0.04em;
font-weight: 700;
font-size: 14px;
color: var(--accent-2);
}
.hero h1 {
margin: 0 0 10px;
font-size: clamp(1.6rem, 3vw, 2.2rem);
line-height: 1.25;
font-weight: 700;
}
.sub { margin: 0; max-width: 52rem; color: rgba(244, 250, 246, 0.82); }
.sub code {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 0.9em;
background: rgba(0,0,0,0.25);
padding: 0.1em 0.35em;
border-radius: 4px;
}
.layout {
display: grid;
grid-template-columns: 1.4fr 0.9fr;
gap: 16px;
}
@media (max-width: 860px) {
.layout { grid-template-columns: 1fr; }
}
.panel {
background: var(--panel);
border-radius: 18px;
border: 1px solid rgba(255,255,255,0.35);
box-shadow: 0 18px 50px rgba(0,0,0,0.22);
}
.chat { display: flex; flex-direction: column; min-height: 560px; overflow: hidden; }
.log {
flex: 1;
padding: 18px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 10px;
}
.bubble {
max-width: 92%;
padding: 10px 12px;
border-radius: 12px;
white-space: pre-wrap;
line-height: 1.5;
font-size: 14px;
}
.bubble.bot { align-self: flex-start; background: var(--bot); }
.bubble.user { align-self: flex-end; background: var(--user); color: #fff; }
.bubble.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.composer {
display: flex;
gap: 8px;
padding: 12px 14px;
border-top: 1px solid var(--line);
}
.composer input {
flex: 1;
border: 1px solid var(--line);
border-radius: 10px;
padding: 12px 14px;
font: inherit;
}
.composer button, .ghost {
border: 0;
border-radius: 10px;
padding: 12px 16px;
font: inherit;
font-weight: 600;
cursor: pointer;
background: var(--accent);
color: #fff;
}
.ghost {
background: transparent;
color: var(--accent);
border: 1px solid var(--line);
padding: 8px 12px;
}
.toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 0 14px 14px;
}
.meta { color: var(--muted); font-size: 12px; }
.side { padding: 16px 18px 20px; }
.side h2 {
margin: 12px 0 8px;
font-size: 13px;
letter-spacing: 0.04em;
text-transform: uppercase;
color: var(--muted);
}
.side h2:first-child { margin-top: 0; }
.side pre {
margin: 0;
padding: 12px;
background: #eef5f0;
border-radius: 10px;
font-size: 12px;
line-height: 1.45;
overflow: auto;
max-height: 220px;
}