- 一院一 Markdown 档案(data/hospitals),索引与章节自动维护;读取支持 section 与 24k 截断,写入校验日期与单条长度,别名精确冲突时不新建 - 子代理按 allowWrite 分可写/只读工具集与提示词:管理端与陪诊员可写,就诊人端只读(物理移除写入工具) - 新增 scripts/import_hospitals.js 存量导入:压缩医生为一行、默认前 60 位,支持 dry-run、幂等与冲突报告,生成 112 家医院档案 - 管理端图片识别原文沿用原样回显策略,不再经模型二次整理 - npm test 212 项通过(新增知识库 12 项、导入 3 项)
90 lines
3.3 KiB
JavaScript
90 lines
3.3 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import EscortAgent from "../agent/bots/bot-escort/agent.js";
|
|
import EscortAdminAgent from "../agent/bots/bot-escort-admin/agent.js";
|
|
|
|
// 一份超过护栏 400 字上限的识别原文:用来确认回显分支不再截断长报告
|
|
const IMAGE_TEXT = [
|
|
"【图像识别】检验报告|血常规",
|
|
"",
|
|
"【原文转写】",
|
|
"",
|
|
"白细胞计数 WBC 6.2 10^9/L 3.5-9.5".repeat(30),
|
|
"",
|
|
"【说明】本内容为图像文字识别结果,不构成诊断意见。",
|
|
].join("\n");
|
|
|
|
test("图片识别原文完整回显,不经过模型与输出护栏", async () => {
|
|
const agent = new EscortAgent();
|
|
const chunks = [];
|
|
await agent.streamChat(
|
|
{ _id: "test-user", profile: {}, location: {} },
|
|
[{
|
|
type: "format",
|
|
ts: "2026-11-01 10:00:00",
|
|
content: IMAGE_TEXT,
|
|
id: "req_format",
|
|
}],
|
|
(source, type, content, id) => {
|
|
chunks.push({ source, type, content, id });
|
|
}
|
|
);
|
|
|
|
// 分片回显,拼接后必须与原文完全一致:长报告不能被字符上限截断
|
|
assert.ok(chunks.length > 1);
|
|
assert.equal(chunks.map(item => item.content).join(""), IMAGE_TEXT);
|
|
assert.deepEqual(new Set(chunks.map(item => item.id)), new Set(["req_format"]));
|
|
assert.deepEqual(new Set(chunks.map(item => item.source)), new Set(["main"]));
|
|
assert.deepEqual(new Set(chunks.map(item => item.type)), new Set(["ai"]));
|
|
|
|
// 原文进历史:用户接着问「这项指标什么意思」时模型能看到报告内容
|
|
assert.equal(agent.messages.length, 1);
|
|
assert.match(agent.messages[0].text, /白细胞计数 WBC 6\.2/);
|
|
|
|
// 走回显分支时不构建 agent,也就不会产生模型调用
|
|
assert.equal(agent.agent, undefined);
|
|
});
|
|
|
|
test("空白识别原文不投递", async () => {
|
|
const agent = new EscortAgent();
|
|
const chunks = [];
|
|
await agent.streamChat(
|
|
{ _id: "test-user", profile: {}, location: {} },
|
|
[{ type: "format", ts: "2026-11-01 10:00:00", content: " ", id: "req_empty" }],
|
|
(source, type, content, id) => {
|
|
chunks.push({ source, type, content, id });
|
|
}
|
|
);
|
|
assert.equal(chunks.length, 0);
|
|
assert.equal(agent.messages.length, 0);
|
|
});
|
|
|
|
test("陪诊师端图片识别原文完整回显,不经过模型与输出护栏", async () => {
|
|
const agent = new EscortAdminAgent();
|
|
const chunks = [];
|
|
const user = { _id: "admin-format-user", profile: {}, location: {} };
|
|
|
|
await agent.streamChat(
|
|
user,
|
|
[{ type: "format", ts: "2026-11-01 10:00:00", content: IMAGE_TEXT, id: "req_admin_format" }],
|
|
(source, type, content, id) => {
|
|
chunks.push({ source, type, content, id });
|
|
},
|
|
"admin"
|
|
);
|
|
|
|
assert.ok(chunks.length > 1);
|
|
assert.equal(chunks.map(item => item.content).join(""), IMAGE_TEXT);
|
|
assert.deepEqual(new Set(chunks.map(item => item.id)), new Set(["req_admin_format"]));
|
|
assert.deepEqual(new Set(chunks.map(item => item.source)), new Set(["main"]));
|
|
assert.deepEqual(new Set(chunks.map(item => item.type)), new Set(["ai"]));
|
|
|
|
// 原文进会话历史,后续追问图片内容时模型能看到
|
|
const session = agent.sessions.get(user._id);
|
|
assert.equal(session.messages.length, 1);
|
|
assert.match(session.messages[0].text, /白细胞计数 WBC 6\.2/);
|
|
// 走回显分支时不构建 agent,也就不会产生模型调用
|
|
assert.equal(session.agent, null);
|
|
});
|