优化: 工具调用标识类型安全加固

This commit is contained in:
lxy
2026-08-10 08:04:30 +08:00
parent 5a1b7a871a
commit 256af4e736
5 changed files with 86 additions and 11 deletions
+5 -3
View File
@@ -48,7 +48,8 @@ pub(crate) fn build_audit_record(
// assistant 消息已 push 到 per_conv.messages,入口取末条 assistant id)。
// None 表示无 assistant 消息(异常路径/老数据无 id),展示侧兼容。
message_id: message_id.map(|s| s.to_string()),
tool_call_id: tool_call_id.to_string(),
// &str → ToolCallId(From<&str>),branded newtype 防外部 String 误传
tool_call_id: tool_call_id.into(),
tool_name: tool_name.to_string(),
arguments: arguments.to_string(),
result,
@@ -228,7 +229,8 @@ pub async fn list_tool_executions(
.map(|r| ToolExecutionDto {
id: r.id,
conversation_id: r.conversation_id,
tool_call_id: r.tool_call_id,
// ToolCallId → String(DTO 边界,前端按字符串消费)
tool_call_id: r.tool_call_id.into(),
tool_name: r.tool_name,
arguments_brief: super::truncate_chars(&r.arguments, 120),
result_brief: r.result.map(|s| super::truncate_chars(&s, 160)),
@@ -362,7 +364,7 @@ mod tests {
id: new_id(),
conversation_id: None,
message_id: None,
tool_call_id: new_id(),
tool_call_id: new_id().into(),
tool_name: tool.to_string(),
arguments: "{}".to_string(),
result: None,