小壹钥匙校验改用中性探测模板,不在客户端写死业务模板编号

This commit is contained in:
WuYongJie 2026-11-30 01:48:09 +08:00
parent b144597604
commit 616a729f18

View File

@ -16,7 +16,8 @@ const CREDENTIAL_NAME: &str = "knowledge:enterprise-knowledge-base";
const XIAOYI_CREDENTIAL_NAME: &str = "企业知识库/小壹";
const XIAOYI_OVERRIDE: &str = "EKB_XIAOYI_READ_KEY";
const XIAOYI_BRIDGE: &str = "PHOTOCRAFT_XIAOYI_OVERRIDE_PORT";
const XIAOYI_CURRENT: &str = "/api/xiaoyi/v1/templates/SFY-CHAIR-001/current";
// 校验钥匙用一个不属于任何业务的模板标识:鉴权通过时返回 200,或 404(模板不存在、未发布);钥匙无效时返回 401/403。
const XIAOYI_CURRENT: &str = "/api/xiaoyi/v1/templates/key-check/current";
const ORIGINS: &str = include_str!("../../../../detail-agent-pi/src/enterprise-knowledge-origins.json");
const INVALID: &str = "企业知识库请求边界无效";
const CREDENTIAL: &str = "企业知识库用户凭据未配置或不可读取";
@ -112,12 +113,16 @@ fn configure_xiaoyi_key(
return json!({"status":null,"saved":false,"error":NETWORK});
};
let status = response.status().as_u16();
if status != 200 {
return json!({"status":status,"saved":false,"error":format!("小壹钥匙校验失败(HTTP {status})")});
}
if !response.json::<Value>().is_ok_and(|body| {
body["version"].as_str().is_some_and(|version| !version.trim().is_empty())
}) {
let accepted = match status {
200 => response.json::<Value>().is_ok_and(|body| {
body["version"].as_str().is_some_and(|version| !version.trim().is_empty())
}),
404 => response.json::<Value>().is_ok_and(|body| matches!(body["code"].as_str(), Some("not_found" | "not_published"))),
_ => {
return json!({"status":status,"saved":false,"error":format!("小壹钥匙校验失败(HTTP {status})")});
}
};
if !accepted {
return json!({"status":status,"saved":false,"error":RESPONSE});
}
let saved = vault().and_then(|entry| entry.set_password(&key).map_err(|_| CREDENTIAL.into())).is_ok();