feat: Batch 5-9 — GrowthIntegration桥接、验证补全、死代码清理、Pipeline模板、Speech/Twitter真实实现
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Batch 5 (P0): GrowthIntegration 接入 Tauri - Kernel 新增 set_viking()/set_extraction_driver() 桥接 SqliteStorage - 中间件链共享存储,MemoryExtractor 接入 LLM 驱动 Batch 6 (P1): 输入验证 + Heartbeat - Relay 验证补全(stream 兼容检查、API key 格式校验) - UUID 类型校验、SessionId 错误返回 - Heartbeat 默认开启 + 首次聊天自动初始化 Batch 7 (P2): 死代码清理 - zclaw-channels 整体移除(317 行) - multi-agent 特性门控、admin 方法标注 Batch 8 (P2): Pipeline 模板 - PipelineMetadata 新增 annotations 字段 - pipeline_templates 命令 + 2 个示例模板 - fallback driver base_url 修复(doubao/qwen/deepseek 端点) Batch 9 (P1): SpeechHand/TwitterHand 真实实现 - SpeechHand: tts_method 字段 + Browser TTS 前端集成 (Web Speech API) - TwitterHand: 12 个 action 全部替换为 Twitter API v2 真实 HTTP 调用 - chatStore/useAutomationEvents 双路径 TTS 触发
This commit is contained in:
@@ -66,10 +66,14 @@ async fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
async fn health_handler(State(state): State<AppState>) -> axum::Json<serde_json::Value> {
|
||||
let db_healthy = sqlx::query_scalar::<_, i32>("SELECT 1")
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.is_ok();
|
||||
// health 必须独立快速返回,用 3s 超时避免连接池满时阻塞
|
||||
let db_healthy = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(3),
|
||||
sqlx::query_scalar::<_, i32>("SELECT 1").fetch_one(&state.db),
|
||||
)
|
||||
.await
|
||||
.map(|r| r.is_ok())
|
||||
.unwrap_or(false);
|
||||
|
||||
let status = if db_healthy { "healthy" } else { "degraded" };
|
||||
let _code = if db_healthy { 200 } else { 503 };
|
||||
|
||||
@@ -441,9 +441,9 @@ pub async fn get_usage_stats(
|
||||
.and_hms_opt(0, 0, 0).unwrap()
|
||||
.and_utc()
|
||||
.to_rfc3339();
|
||||
let daily_sql = "SELECT SUBSTRING(created_at, 1, 10) as day, COUNT(*)::bigint AS request_count, COALESCE(SUM(input_tokens), 0) AS input_tokens, COALESCE(SUM(output_tokens), 0) AS output_tokens
|
||||
let daily_sql = "SELECT created_at::date::text as day, COUNT(*)::bigint AS request_count, COALESCE(SUM(input_tokens), 0) AS input_tokens, COALESCE(SUM(output_tokens), 0) AS output_tokens
|
||||
FROM usage_records WHERE account_id = $1 AND created_at >= $2
|
||||
GROUP BY SUBSTRING(created_at, 1, 10) ORDER BY day DESC LIMIT $3";
|
||||
GROUP BY created_at::date ORDER BY day DESC LIMIT $3";
|
||||
let daily_rows: Vec<UsageByDayRow> = sqlx::query_as(daily_sql)
|
||||
.bind(account_id).bind(&from_days).bind(days as i32)
|
||||
.fetch_all(db).await?;
|
||||
|
||||
@@ -142,6 +142,13 @@ pub async fn chat_completions(
|
||||
let target_model = target_model
|
||||
.ok_or_else(|| SaasError::NotFound(format!("模型 {} 不存在或未启用", model_name)))?;
|
||||
|
||||
// Stream compatibility check: reject stream requests for non-streaming models
|
||||
if stream && !target_model.supports_streaming {
|
||||
return Err(SaasError::InvalidInput(
|
||||
format!("模型 {} 不支持流式响应,请使用 stream: false", model_name)
|
||||
));
|
||||
}
|
||||
|
||||
// 获取 provider 信息
|
||||
let provider = model_service::get_provider(&state.db, &target_model.provider_id).await?;
|
||||
if !provider.enabled {
|
||||
@@ -385,6 +392,12 @@ pub async fn add_provider_key(
|
||||
if req.key_value.trim().is_empty() {
|
||||
return Err(SaasError::InvalidInput("key_value 不能为空".into()));
|
||||
}
|
||||
if req.key_value.len() < 20 {
|
||||
return Err(SaasError::InvalidInput("key_value 长度不足(至少 20 字符)".into()));
|
||||
}
|
||||
if req.key_value.contains(char::is_whitespace) {
|
||||
return Err(SaasError::InvalidInput("key_value 不能包含空白字符".into()));
|
||||
}
|
||||
|
||||
let key_id = super::key_pool::add_provider_key(
|
||||
&state.db, &provider_id, &req.key_label, &req.key_value,
|
||||
|
||||
@@ -240,7 +240,7 @@ pub async fn get_daily_stats(
|
||||
.to_rfc3339();
|
||||
|
||||
let sql = "SELECT
|
||||
SUBSTRING(reported_at, 1, 10) as day,
|
||||
reported_at::date::text as day,
|
||||
COUNT(*)::bigint as request_count,
|
||||
COALESCE(SUM(input_tokens), 0)::bigint as input_tokens,
|
||||
COALESCE(SUM(output_tokens), 0)::bigint as output_tokens,
|
||||
@@ -248,7 +248,7 @@ pub async fn get_daily_stats(
|
||||
FROM telemetry_reports
|
||||
WHERE account_id = $1
|
||||
AND reported_at >= $2
|
||||
GROUP BY SUBSTRING(reported_at, 1, 10)
|
||||
GROUP BY reported_at::date
|
||||
ORDER BY day DESC";
|
||||
|
||||
let rows: Vec<TelemetryDailyStatsRow> =
|
||||
|
||||
Reference in New Issue
Block a user