fix(anthropic): avoid sanitized tool id collisions
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user