"""Cursor SDK 调用(daily 包专用)。""" from __future__ import annotations from cursor_sdk import Agent, AgentOptions, CursorAgentError, LocalAgentOptions from daily.config import env from daily.cursor_bridge import cursor_cwd, warm_cursor_bridge def cursor_chat(system: str, user: str) -> str: api_key = (env("CURSOR_API_KEY") or "").strip() if not api_key: return "" warm_cursor_bridge() cwd = cursor_cwd() model = env("CURSOR_MODEL") or "composer-2.5" prompt = f"{system}\n\n{user}" try: result = Agent.prompt( prompt, AgentOptions( api_key=api_key, model=model, local=LocalAgentOptions(cwd=cwd), ), ) except CursorAgentError as exc: raise RuntimeError(f"LLM 调用失败:{exc.message}") from exc if result.status == "error": raise RuntimeError(f"LLM 调用失败:{result.result or '未知错误'}") return (result.result or "").strip()