/** * 参考信息的文本化渲染(主 agent 与管理 agent 共用) * * 直接 JSON.stringify 的问题: * 1. services 里的 booking / image / icon / tag 是前端配置,模型会把 * booking.sessions(如 08:00—17:00)误读成「可与用户约定的可约时段」,造成错误许诺; * 2. 裸 JSON 更耗 token,且模型解析散文优于 JSON。 * 因此只渲染问答真正需要的字段,公示文案(subtitle / notices)保持逐字原文。 */ export function formatServices(services) { const areas = services?.[0]?.areas; const lines = []; if (areas?.length) { lines.push(`服务区域:${areas.join('、')}`); } lines.push("(以下价格为公示价,单位:元)"); for (const s of services ?? []) { lines.push(""); lines.push(`${s.title}|${s.price} 元|${s.subtitle ?? ""}`.trim()); if (s.description) { lines.push(`适用:${s.description}`); } if (s.flow?.length) { lines.push(`流程:${s.flow.map((step) => step.title).join(" → ")}`); } for (const notice of s.notices ?? []) { lines.push(`· ${notice}`); } } return lines.join("\n"); } export function formatAgreement(agreement) { const lines = [`${agreement.title}(原文摘要)`]; for (const section of agreement.sections ?? []) { lines.push(""); lines.push(`【${section.number}. ${section.title}】`); for (const item of section.items ?? []) { lines.push(`- ${item}`); } if (section.content) { lines.push(section.content); } if (section.table?.rows?.length) { const { headers = [], rows } = section.table; lines.push(headers.join(" / ")); for (const row of rows) { lines.push(row.join(" / ")); } } } return lines.join("\n"); }