重构: 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:
@@ -18,10 +18,10 @@ use super::tools::entity_resolve;
|
||||
|
||||
// utils(audit/utils.rs):RiskLevel ↔ 字符串转换 + 字符串安全截断纯 helper。
|
||||
// 第五批从本文件抽离,行为零变更。pub(crate) use 保持 finalize / restore 子模块
|
||||
// super::risk_str / super::risk_from_str 引用路径不变;truncate_chars 供本文件 process_tool_calls
|
||||
// super::risk_str / super::risk_from_str 引用路径不变;truncate_chars_ellipsis 供本文件 process_tool_calls
|
||||
// DTO 装配 + record.rs 审计面板 IPC 共用。
|
||||
mod utils;
|
||||
pub(crate) use utils::{risk_from_str, risk_str, truncate_chars};
|
||||
pub(crate) use utils::{risk_from_str, risk_str, truncate_chars_ellipsis};
|
||||
|
||||
// diff(audit/diff.rs):write_file 审批预览 diff 生成。
|
||||
// 第五批从本文件抽离,行为零变更。
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//! - `ToolExecutionDto`:传给前端的精简审计视图
|
||||
//! - `list_tool_executions`:审批历史面板查询 IPC
|
||||
//!
|
||||
//! 依赖 audit/utils.rs 的 `truncate_chars` 做参数/结果截断,通过 `super::truncate_chars` 引用。
|
||||
//! 依赖 audit/utils.rs 的 `truncate_chars_ellipsis` 做参数/结果截断,通过 `super::truncate_chars_ellipsis` 引用。
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -233,8 +233,8 @@ pub async fn list_tool_executions(
|
||||
// ToolCallId → String(DTO 边界,前端按字符串消费)
|
||||
tool_call_id: r.tool_call_id.into(),
|
||||
tool_name: r.tool_name,
|
||||
arguments_brief: super::truncate_chars(&r.arguments, 120),
|
||||
result_brief: r.result.map(|s| super::truncate_chars(&s, 160)),
|
||||
arguments_brief: super::truncate_chars_ellipsis(&r.arguments, 120),
|
||||
result_brief: r.result.map(|s| super::truncate_chars_ellipsis(&s, 160)),
|
||||
status: r.status,
|
||||
risk_level: r.risk_level,
|
||||
requested_at: r.requested_at,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! - `risk_str` / `risk_from_str`:finalize / restore 通过 `super::` 引用(pub(crate))。
|
||||
//! - `truncate_chars`:mod.rs 的 process_tool_calls DTO 装配用 + record.rs 审计面板 IPC 用(pub(crate))。
|
||||
//!
|
||||
//! re-export 维持原路径透明:`super::risk_str` / `super::risk_from_str` / `super::truncate_chars`
|
||||
//! re-export 维持原路径透明:`super::risk_str` / `super::risk_from_str` / `super::truncate_chars_ellipsis`
|
||||
//! 在 audit/mod.rs 内通过 `pub(crate) use` 引入后裸名可用,外部子模块的 `super::risk_*` 引用不变。
|
||||
|
||||
use df_ai::ai_tools::RiskLevel;
|
||||
@@ -29,7 +29,7 @@ pub(crate) fn risk_from_str(s: &str) -> Option<RiskLevel> {
|
||||
}
|
||||
|
||||
/// 截断字符串到 max 字符(按 char_indices 边界切,避免切坏中文/emoji)
|
||||
pub(crate) fn truncate_chars(s: &str, max: usize) -> String {
|
||||
pub(crate) fn truncate_chars_ellipsis(s: &str, max: usize) -> String {
|
||||
if s.chars().count() <= max {
|
||||
return s.to_string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user