重构: 模型路由纯函数提取独立模块
巨石拆解首步,仅纯函数移动调用方零变更
This commit is contained in:
@@ -358,6 +358,8 @@ pub(crate) mod workflow_context;
|
||||
pub mod conv_state;
|
||||
pub mod command_lock;
|
||||
pub(crate) mod helpers;
|
||||
pub(crate) mod router_setup;
|
||||
pub(crate) use router_setup::resolve_model_with_override;
|
||||
pub(crate) use helpers::try_continue_agent_loop;
|
||||
pub(crate) use helpers::infer_goal_from_tool_calls;
|
||||
pub(crate) use helpers::{
|
||||
@@ -455,26 +457,6 @@ async fn stream_one_provider(
|
||||
).await
|
||||
}
|
||||
|
||||
// ── resolve_model_with_override: 在 candidate.model_configs 上重算 resolved_model,穿透 override ──
|
||||
// override 非空且在本 candidate 池中(enabled) → 用 override;否则用 select_model_id 结果。
|
||||
// 绝不因 override 致无模型(兜底用 default_model)。
|
||||
fn resolve_model_with_override(
|
||||
agentic_req: &TaskRequirements,
|
||||
candidate: &AiProviderRecord,
|
||||
model_override: &Option<String>,
|
||||
) -> String {
|
||||
let resolved = select_model_id(agentic_req, &candidate.model_configs)
|
||||
.unwrap_or_else(|| candidate.default_model.clone());
|
||||
match model_override.as_deref() {
|
||||
Some(id) if !id.is_empty()
|
||||
&& candidate.model_configs.iter().any(|m| m.model_id == id && m.enabled) =>
|
||||
{
|
||||
id.to_string()
|
||||
}
|
||||
_ => resolved,
|
||||
}
|
||||
}
|
||||
|
||||
// ── stream_with_retry: 流式 + 流前 InitFailed retryable 重试循环(扁平抽自原嵌套 5 层 match) ──
|
||||
// 返回 StreamOutcome。内部含 retry_attempt 循环 + match StreamResult 三分支:
|
||||
// Complete/Partial → Success;InitFailed Fatal → Fatal;InitFailed Retryable → 重试/耗尽。
|
||||
|
||||
Reference in New Issue
Block a user