Support Hermes 0.11.0 (AnthropicTransport) and improve site-packages detection
This commit is contained in:
parent
75a3f71200
commit
d834eb67aa
@ -497,7 +497,7 @@ def _lowercase_first(name: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _install_response_pascalcase_unhook(aa_module: Any, force: bool = False) -> bool:
|
def _install_response_pascalcase_unhook(aa_module: Any, force: bool = False) -> bool:
|
||||||
"""Post-process ``normalize_anthropic_response`` to restore lowercase tool names.
|
"""Post-process response normalization to restore lowercase tool names.
|
||||||
|
|
||||||
We rewrote outgoing tool names from ``mcp_bash`` to ``mcp_Bash`` to pass
|
We rewrote outgoing tool names from ``mcp_bash`` to ``mcp_Bash`` to pass
|
||||||
Anthropic's validator. The response comes back referencing ``mcp_Bash``
|
Anthropic's validator. The response comes back referencing ``mcp_Bash``
|
||||||
@ -513,6 +513,35 @@ def _install_response_pascalcase_unhook(aa_module: Any, force: bool = False) ->
|
|||||||
|
|
||||||
original = getattr(aa_module, "normalize_anthropic_response", None)
|
original = getattr(aa_module, "normalize_anthropic_response", None)
|
||||||
if not callable(original):
|
if not callable(original):
|
||||||
|
# Try to find AnthropicTransport in agent.transports.anthropic
|
||||||
|
try:
|
||||||
|
from agent.transports import anthropic as at
|
||||||
|
original_class = getattr(at, "AnthropicTransport", None)
|
||||||
|
if original_class:
|
||||||
|
original = getattr(original_class, "normalize_response", None)
|
||||||
|
if callable(original):
|
||||||
|
def patched_normalize_transport(self, response: Any, **kwargs: Any) -> Any:
|
||||||
|
result = original(self, response, **kwargs)
|
||||||
|
tool_calls = getattr(result, "tool_calls", None)
|
||||||
|
if not tool_calls:
|
||||||
|
return result
|
||||||
|
for tc in tool_calls:
|
||||||
|
name = getattr(tc, "name", None)
|
||||||
|
if isinstance(name, str) and name and name[0].isupper():
|
||||||
|
try:
|
||||||
|
tc.name = _lowercase_first(name)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
|
original_class.normalize_response = patched_normalize_transport
|
||||||
|
aa_module._CLAUDE_CODE_RESPONSE_UNHOOK_APPLIED = True
|
||||||
|
logger.info("Response PascalCase unhook installed on AnthropicTransport.normalize_response")
|
||||||
|
sys.stderr.write("[anthropic_billing_bypass] Response PascalCase unhook installed (Transport)\n")
|
||||||
|
return True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
logger.warning("normalize_anthropic_response not found; skipping response unhook")
|
logger.warning("normalize_anthropic_response not found; skipping response unhook")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@ -29,12 +29,13 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
VENV_PYTHON="$VENV_DIR/bin/python"
|
VENV_PYTHON="$VENV_DIR/bin/python"
|
||||||
|
if [ ! -x "$VENV_PYTHON" ]; then VENV_PYTHON="$VENV_DIR/bin/python3"; fi
|
||||||
if [ ! -x "$VENV_PYTHON" ]; then
|
if [ ! -x "$VENV_PYTHON" ]; then
|
||||||
printf "${RED}[✗] Python not found at %s${RESET}\n" "$VENV_PYTHON"
|
printf "${RED}[✗] Python not found at %s${RESET}\n" "$VENV_PYTHON"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SITE_PACKAGES="$("$VENV_PYTHON" -c "import site; print(site.getsitepackages()[0])")"
|
SITE_PACKAGES="$("$VENV_PYTHON" -c "import site; print(site.getsitepackages()[0] if site.getsitepackages() else site.getusersitepackages())")"
|
||||||
if [ ! -d "$SITE_PACKAGES" ]; then
|
if [ ! -d "$SITE_PACKAGES" ]; then
|
||||||
printf "${RED}[✗] site-packages directory does not exist: %s${RESET}\n" "$SITE_PACKAGES"
|
printf "${RED}[✗] site-packages directory does not exist: %s${RESET}\n" "$SITE_PACKAGES"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user