- ChatResponse 增加 display_hints 字段,Orchestrator 收集 Tool 产生的 DisplayHint - DisplayHint 实现 utoipa::ToSchema - Web ChatResponse 类型同步,DisplayHint 8 种联合类型 - RichMessage 组件:InsightCard/RiskAlert/LabReportCard/TrendChart/PatientProfile/VitalCard - AiSidebar 消息中渲染 display_hints 富消息 - 小程序 AiChatResponse 类型同步
70 lines
1.8 KiB
Rust
70 lines
1.8 KiB
Rust
use async_trait::async_trait;
|
|
use erp_core::health_provider::HealthDataProvider;
|
|
use sea_orm::DatabaseConnection;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::sync::Arc;
|
|
use uuid::Uuid;
|
|
|
|
/// Agent Tool trait — 所有 Agent 可调用的工具都实现此 trait
|
|
#[async_trait]
|
|
pub trait AgentTool: Send + Sync {
|
|
fn name(&self) -> &str;
|
|
fn description(&self) -> &str;
|
|
fn parameters_schema(&self) -> serde_json::Value;
|
|
async fn execute(&self, ctx: &ToolContext, params: serde_json::Value) -> ToolResult;
|
|
}
|
|
|
|
/// Tool 执行上下文 — 包含安全过滤后的租户/用户信息
|
|
pub struct ToolContext {
|
|
pub tenant_id: Uuid,
|
|
pub user_id: Uuid,
|
|
pub patient_id: Option<Uuid>,
|
|
pub db: DatabaseConnection,
|
|
pub health_provider: Arc<dyn HealthDataProvider>,
|
|
}
|
|
|
|
/// Tool 执行结果
|
|
pub struct ToolResult {
|
|
pub output: String,
|
|
pub display_hint: Option<DisplayHint>,
|
|
}
|
|
|
|
/// 前端渲染提示 — 告诉前端如何富化展示 Tool 返回的数据
|
|
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
|
|
#[serde(tag = "type", rename_all = "snake_case")]
|
|
pub enum DisplayHint {
|
|
VitalCard {
|
|
indicator_type: String,
|
|
values: Vec<(String, f64)>,
|
|
unit: String,
|
|
},
|
|
LabReportCard {
|
|
report_date: String,
|
|
abnormal_count: usize,
|
|
},
|
|
ActionConfirm {
|
|
action_type: String,
|
|
summary: String,
|
|
confirm_payload: serde_json::Value,
|
|
},
|
|
RiskAlert {
|
|
level: String,
|
|
message: String,
|
|
},
|
|
TrendChart {
|
|
metrics: Vec<String>,
|
|
period: String,
|
|
summary: String,
|
|
},
|
|
InsightCard {
|
|
title: String,
|
|
severity: String,
|
|
items: Vec<String>,
|
|
},
|
|
PatientProfile {
|
|
chronic_conditions: Vec<String>,
|
|
medication_count: usize,
|
|
},
|
|
Text,
|
|
}
|