mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 09:50:21 +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:
@@ -199,6 +199,46 @@ pub fn body_rules_are_locally_supported(rules: Option<&Value>) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn body_rules_handle_path(rules: Option<&Value>, path: &str) -> bool {
|
||||
let Some(target_path) = parse_body_path(path) else {
|
||||
return false;
|
||||
};
|
||||
let Some(rules) = rules.and_then(Value::as_array) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
rules.iter().any(|rule| {
|
||||
let Some(rule) = rule.as_object() else {
|
||||
return false;
|
||||
};
|
||||
match rule
|
||||
.get("action")
|
||||
.and_then(Value::as_str)
|
||||
.map(str::trim)
|
||||
.map(str::to_ascii_lowercase)
|
||||
.as_deref()
|
||||
{
|
||||
Some("set") | Some("drop") => rule
|
||||
.get("path")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(parse_body_path)
|
||||
.is_some_and(|candidate| candidate == target_path),
|
||||
Some("rename") => {
|
||||
rule.get("from")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(parse_body_path)
|
||||
.is_some_and(|candidate| candidate == target_path)
|
||||
|| rule
|
||||
.get("to")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(parse_body_path)
|
||||
.is_some_and(|candidate| candidate == target_path)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn apply_local_body_rules(
|
||||
body: &mut Value,
|
||||
rules: Option<&Value>,
|
||||
@@ -705,7 +745,7 @@ fn rename_nested_value(
|
||||
mod tests {
|
||||
use super::{
|
||||
apply_local_body_rules, apply_local_header_rules, body_rules_are_locally_supported,
|
||||
header_rules_are_locally_supported,
|
||||
body_rules_handle_path, header_rules_are_locally_supported,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -817,4 +857,19 @@ mod tests {
|
||||
let wildcard_rules = serde_json::json!([{"action":"drop","path":"items[*].value"}]);
|
||||
assert!(!body_rules_are_locally_supported(Some(&wildcard_rules)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn body_rules_handle_exact_paths_for_set_drop_and_rename() {
|
||||
let rules = serde_json::json!([
|
||||
{"action":"set","path":"store","value":false},
|
||||
{"action":"drop","path":"metadata"},
|
||||
{"action":"rename","from":"max_output_tokens","to":"limit"}
|
||||
]);
|
||||
|
||||
assert!(body_rules_handle_path(Some(&rules), "store"));
|
||||
assert!(body_rules_handle_path(Some(&rules), "metadata"));
|
||||
assert!(body_rules_handle_path(Some(&rules), "max_output_tokens"));
|
||||
assert!(body_rules_handle_path(Some(&rules), "limit"));
|
||||
assert!(!body_rules_handle_path(Some(&rules), "instructions"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user