diff --git a/daily/llm_client.py b/daily/llm_client.py index eb3e709..1be3fd5 100644 --- a/daily/llm_client.py +++ b/daily/llm_client.py @@ -74,7 +74,7 @@ def _cursor_chat(system: str, user: str) -> str: api_key = (env("CURSOR_API_KEY") or "").strip() if not api_key: return "" - from cursor_sdk import Agent, AgentOptions, CursorAgentError, LocalAgentOptions + from cursor_sdk import Agent, AgentOptions, Client, CursorAgentError, LocalAgentOptions from daily.bridge_manager import warm_cursor_bridge @@ -83,6 +83,17 @@ def _cursor_chat(system: str, user: str) -> str: warm_cursor_bridge() model = env("CURSOR_MODEL") or "composer-2.5" prompt = f"{system}\n\n{user}" + + # SDK 默认 unary_timeout 只有 60s,CURSOR_MODEL=auto 时后端首 token 常超时; + # 自建带大超时的 Client 绕开 _default_client(),unary/stream 都放大。 + unary_timeout = env_int("DAILY_CURSOR_UNARY_TIMEOUT", 300) + stream_timeout = env_int("DAILY_CURSOR_STREAM_TIMEOUT", 900) + client = Client( + base_url=os.environ["CURSOR_SDK_BRIDGE_URL"], + auth_token=os.environ["CURSOR_SDK_BRIDGE_TOKEN"], + unary_timeout=unary_timeout, + stream_timeout=stream_timeout, + ) try: result = Agent.prompt( prompt, @@ -91,9 +102,12 @@ def _cursor_chat(system: str, user: str) -> str: model=model, local=LocalAgentOptions(cwd=cwd), ), + client=client, ) except CursorAgentError as exc: raise RuntimeError(f"LLM 调用失败:{exc.message}") from exc + finally: + client.close() if result.status == "error": raise RuntimeError(f"LLM 调用失败:{result.result or '未知错误'}") return (result.result or "").strip()