fix: preflight Anthropic auth and prefer Claude store

This commit is contained in:
teknium1
2026-03-14 19:38:55 -07:00
parent e052c74727
commit 70ea13eb40
6 changed files with 135 additions and 8 deletions

View File

@@ -2645,6 +2645,11 @@ class AIAgent:
self._anthropic_api_key = new_token
return True
def _anthropic_messages_create(self, api_kwargs: dict):
if self.api_mode == "anthropic_messages":
self._try_refresh_anthropic_client_credentials()
return self._anthropic_client.messages.create(**api_kwargs)
def _interruptible_api_call(self, api_kwargs: dict):
"""
Run the API call in a background thread so the main conversation loop
@@ -2661,7 +2666,7 @@ class AIAgent:
if self.api_mode == "codex_responses":
result["response"] = self._run_codex_stream(api_kwargs)
elif self.api_mode == "anthropic_messages":
result["response"] = self._anthropic_client.messages.create(**api_kwargs)
result["response"] = self._anthropic_messages_create(api_kwargs)
else:
result["response"] = self.client.chat.completions.create(**api_kwargs)
except Exception as e:
@@ -3299,7 +3304,7 @@ class AIAgent:
tools=[memory_tool_def], max_tokens=5120,
reasoning_config=None,
)
response = self._anthropic_client.messages.create(**ant_kwargs)
response = self._anthropic_messages_create(ant_kwargs)
elif not _aux_available:
api_kwargs = {
"model": self.model,
@@ -4050,7 +4055,7 @@ class AIAgent:
from agent.anthropic_adapter import build_anthropic_kwargs as _bak, normalize_anthropic_response as _nar
_ant_kw = _bak(model=self.model, messages=api_messages, tools=None,
max_tokens=self.max_tokens, reasoning_config=self.reasoning_config)
summary_response = self._anthropic_client.messages.create(**_ant_kw)
summary_response = self._anthropic_messages_create(_ant_kw)
_msg, _ = _nar(summary_response)
final_response = (_msg.content or "").strip()
else:
@@ -4080,7 +4085,7 @@ class AIAgent:
from agent.anthropic_adapter import build_anthropic_kwargs as _bak2, normalize_anthropic_response as _nar2
_ant_kw2 = _bak2(model=self.model, messages=api_messages, tools=None,
max_tokens=self.max_tokens, reasoning_config=self.reasoning_config)
retry_response = self._anthropic_client.messages.create(**_ant_kw2)
retry_response = self._anthropic_messages_create(_ant_kw2)
_retry_msg, _ = _nar2(retry_response)
final_response = (_retry_msg.content or "").strip()
else: