fix(anthropic): avoid sanitized tool id collisions

This commit is contained in:
Xubin Ren
2026-06-18 00:03:08 +08:00
parent 4d7c2074e6
commit bdf21c932b
2 changed files with 42 additions and 1 deletions
+4 -1
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import hashlib
import re
import secrets
import string
@@ -37,7 +38,9 @@ def _sanitize_tool_id(tid: str) -> str:
"""
if not tid or _VALID_TOOL_ID.match(tid):
return tid
return re.sub(r"[^a-zA-Z0-9_-]", "_", tid)
safe_prefix = re.sub(r"[^a-zA-Z0-9_-]", "_", tid)[:48].strip("_") or "toolu"
digest = hashlib.sha1(tid.encode()).hexdigest()[:8]
return f"{safe_prefix}_{digest}"
class AnthropicProvider(LLMProvider):