重构: DRY截断正典改名收尾

- audit/utils.rs truncate_chars→truncate_chars_ellipsis 正典改名(补…语义),re-export 链同步
- record.rs/generate_image.rs/knowledge_inject.rs/tools/knowledge.rs 调用点全链更新
- df-ai context_helpers.rs 私有版跨 crate 不引依赖保留原名,加正典标注注释
- DRY #11 收口,同名不同义陷阱消除
This commit is contained in:
lxy
2026-10-05 00:35:04 +08:00
parent 6a50193b34
commit 753de25696
7 changed files with 17 additions and 15 deletions
+3 -3
View File
@@ -49,7 +49,7 @@ use df_storage::db::Database;
use df_storage::models::AiProviderRecord;
use df_storage::secret::resolve_provider_secret;
use crate::commands::ai::audit::truncate_chars;
use crate::commands::ai::audit::truncate_chars_ellipsis;
use crate::commands::ai::http::{
build_client, execute_with_redirects, resolve_and_check_host, validate_url, MAX_REDIRECTS,
};
@@ -184,7 +184,7 @@ pub(crate) async fn execute_generate_image(
if !status.is_success() {
// 错误响应读 body 摘要(截断 500 chars,截断时尾部补 …)帮助定位
let err_text = resp.text().await.unwrap_or_default();
let snippet: String = truncate_chars(&err_text, 500);
let snippet: String = truncate_chars_ellipsis(&err_text, 500);
anyhow::bail!(
"图像生成端点返回 HTTP {}: {}",
status.as_u16(),
@@ -459,7 +459,7 @@ async fn write_atomic(output_path: &str, data: &[u8]) -> anyhow::Result<()> {
/// 走 audit truncate_chars 正典(截断时尾部补 …);错误文案无硬长度约束,允许多 1 字符。
fn body_snippet(v: &Value) -> String {
let s = v.to_string();
truncate_chars(&s, 500)
truncate_chars_ellipsis(&s, 500)
}
// ============================================================