mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
refactor: 大规模模块拆分与代码精简,新增 ai-pipeline/data-contracts 独立 crate
- 新增 aether-ai-pipeline 和 aether-data-contracts crate,将 pipeline 逻辑与数据契约从 gateway 中解耦 - 重构 admin handlers:拆分单体模块为 auth/billing/endpoint/features/model/observability/provider/system 等独立子模块 - 合并 chat/cli 重复代码路径:精简 conversion、finalize、planner 中的 sync/chat/cli 分支 - 重构 scheduler/executor/data 层,引入 facade 模式降低模块间耦合 - 移除冗余的 intent 模块,将 plan_fallback/policy/stream_path/sync_path 迁移至 executor - 前端适配:调整 admin API 调用和 provider 模型测试对话框
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
pub(crate) fn short_request_id(value: &str) -> String {
|
||||
let trimmed = value.trim();
|
||||
if trimmed.is_empty() {
|
||||
return "-".to_string();
|
||||
}
|
||||
|
||||
if trimmed.chars().count() <= 12 {
|
||||
return trimmed.to_string();
|
||||
}
|
||||
|
||||
if looks_like_uuid(trimmed) {
|
||||
return trimmed.chars().take(8).collect();
|
||||
}
|
||||
|
||||
let prefix: String = trimmed.chars().take(6).collect();
|
||||
let suffix: String = trimmed
|
||||
.chars()
|
||||
.rev()
|
||||
.take(4)
|
||||
.collect::<String>()
|
||||
.chars()
|
||||
.rev()
|
||||
.collect();
|
||||
format!("{prefix}...{suffix}")
|
||||
}
|
||||
|
||||
fn looks_like_uuid(value: &str) -> bool {
|
||||
let bytes = value.as_bytes();
|
||||
if bytes.len() != 36 {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (index, byte) in bytes.iter().enumerate() {
|
||||
let is_hyphen = matches!(index, 8 | 13 | 18 | 23);
|
||||
if is_hyphen {
|
||||
if *byte != b'-' {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if !byte.is_ascii_hexdigit() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::short_request_id;
|
||||
|
||||
#[test]
|
||||
fn shortens_uuid_like_request_ids_to_prefix() {
|
||||
assert_eq!(
|
||||
short_request_id("d07e1e94-41b8-409f-a18a-27993ae7ecb1"),
|
||||
"d07e1e94"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shortens_long_named_request_ids_to_prefix_and_suffix() {
|
||||
assert_eq!(
|
||||
short_request_id("trace-openai-cli-stream-sync-direct-123"),
|
||||
"trace-...-123"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_short_request_ids() {
|
||||
assert_eq!(short_request_id("req-123"), "req-123");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user