优化: 工具调用标识类型安全加固
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -75,9 +75,11 @@ pub async fn restore_pending_approvals(state: &AppState) {
|
||||
}
|
||||
}
|
||||
session.pending_approvals.insert(
|
||||
rec.tool_call_id.clone(),
|
||||
// ToolCallId → String(AiSession pending_approvals 是 String HashMap,
|
||||
// 与 LLM provider draft.id 同形直接比较;DB 边界已 newtype 防误传)
|
||||
rec.tool_call_id.to_string(),
|
||||
PendingApproval {
|
||||
tool_call_id: rec.tool_call_id,
|
||||
tool_call_id: rec.tool_call_id.to_string(),
|
||||
tool_name: rec.tool_name,
|
||||
arguments: args,
|
||||
conversation_id: rec.conversation_id,
|
||||
|
||||
Reference in New Issue
Block a user