优化: 工具调用标识类型安全加固
This commit is contained in:
@@ -98,7 +98,9 @@ fn ai_tool_execution_from_row(row: &Row<'_>) -> std::result::Result<AiToolExecut
|
||||
// message_id 列老库经 v21 迁移补建。unwrap_or(None) 兜底:
|
||||
// 新库空表直接有列;老库行 ALTER 后 NULL;极端情况(迁移未跑/手工删列)防御。
|
||||
message_id: row.get("message_id").unwrap_or(None),
|
||||
tool_call_id: row.get("tool_call_id")?,
|
||||
// row.get::<String> 后 From<String> → ToolCallId(newtype 不直接 impl rusqlite::FromSql,
|
||||
// 避免 df-types 反向依赖 rusqlite;Deref<Target=str> 不自动给 ToSql)
|
||||
tool_call_id: row.get::<_, String>("tool_call_id")?.into(),
|
||||
tool_name: row.get("tool_name")?,
|
||||
arguments: row.get("arguments")?,
|
||||
result: row.get("result")?,
|
||||
@@ -221,7 +223,7 @@ impl_repo!(
|
||||
"INSERT INTO ai_tool_executions (id, conversation_id, message_id, tool_call_id, tool_name, arguments, result, status, risk_level, requested_at, executed_at, decided_by)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)",
|
||||
params![
|
||||
rec.id, rec.conversation_id, rec.message_id, rec.tool_call_id, rec.tool_name,
|
||||
rec.id, rec.conversation_id, rec.message_id, &*rec.tool_call_id, rec.tool_name,
|
||||
rec.arguments, rec.result, rec.status, rec.risk_level,
|
||||
rec.requested_at, rec.executed_at, rec.decided_by
|
||||
],
|
||||
@@ -231,7 +233,7 @@ impl_repo!(
|
||||
conn.execute(
|
||||
"UPDATE ai_tool_executions SET conversation_id = ?1, message_id = ?2, tool_call_id = ?3, tool_name = ?4, arguments = ?5, result = ?6, status = ?7, risk_level = ?8, requested_at = ?9, executed_at = ?10, decided_by = ?11 WHERE id = ?12",
|
||||
params![
|
||||
rec.conversation_id, rec.message_id, rec.tool_call_id, rec.tool_name,
|
||||
rec.conversation_id, rec.message_id, &*rec.tool_call_id, rec.tool_name,
|
||||
rec.arguments, rec.result, rec.status, rec.risk_level,
|
||||
rec.requested_at, rec.executed_at, rec.decided_by, rec.id
|
||||
],
|
||||
@@ -269,7 +271,7 @@ impl AiToolExecutionRepo {
|
||||
)?;
|
||||
for rec in &records {
|
||||
stmt.execute(params![
|
||||
rec.id, rec.conversation_id, rec.message_id, rec.tool_call_id, rec.tool_name,
|
||||
rec.id, rec.conversation_id, rec.message_id, &*rec.tool_call_id, rec.tool_name,
|
||||
rec.arguments, rec.result, rec.status, rec.risk_level,
|
||||
rec.requested_at, rec.executed_at, rec.decided_by
|
||||
])?;
|
||||
|
||||
Reference in New Issue
Block a user