fix(cursor): HTTP/2 AgentService support + version bump to 3.12.17

Real Cursor IDE now uses AgentService at agent.api5.cursor.sh (HTTP/2-only)
while 9router still spoke the retired ChatService at api2.cursor.sh with
outdated headers, producing HTTP 429 "Update Required". Add an executeAgent
path that builds an agent.v1.RunRequest Connect RPC over a raw http2 stream
and fetches the account-specific usable model catalog via GetUsableModels.

Also implement MCP tool calling over AgentService: encode OpenAI tools as
AgentRunRequest.mcp_tools (McpToolDefinition with google.protobuf.Value
input_schema), decode McpArgs tool calls, and forward them to the client as
OpenAI tool_calls so the client runs the tool and resumes in the next turn.
Reply to request_context_args with a non-empty RequestContext, to server
heartbeats with client_heartbeat, and to KV blob get/set with empty results,
so action queries no longer stall the stream. Fold the client system prompt
into the user message (custom_system_prompt makes the server return an empty
turn). Bump clientVersion to 3.12.17 and add the x-cursor-client-commit
header so the gateway identifies as a current Cursor IDE release.
This commit is contained in:
long2ice
2026-07-20 15:39:17 +07:00
committed by decolua
parent 4f48ab8c7f
commit 6994cd1f70
12 changed files with 1106 additions and 13 deletions

View File

@@ -48,6 +48,48 @@ export default function ModelSelectModal({
const [providerNodes, setProviderNodes] = useState([]);
const [customModels, setCustomModels] = useState([]);
const [disabledModels, setDisabledModels] = useState({});
const [cursorModels, setCursorModels] = useState([]);
// Cursor exposes the usable catalog per account. Keep the static catalog only
// as a fallback, since it quickly becomes stale and different accounts can
// have different model entitlements.
const cursorConnectionIds = useMemo(
() => activeProviders
.filter((provider) => provider.provider === "cursor" && provider.id)
.map((provider) => provider.id),
[activeProviders],
);
useEffect(() => {
if (!isOpen || cursorConnectionIds.length === 0) {
setCursorModels([]);
return undefined;
}
let cancelled = false;
Promise.all(cursorConnectionIds.map(async (connectionId) => {
const response = await fetch(`/api/providers/${connectionId}/models`, { cache: "no-store" });
if (!response.ok) return [];
const data = await response.json();
return Array.isArray(data.models) ? data.models : [];
}))
.then((modelLists) => {
if (cancelled) return;
const seen = new Set();
setCursorModels(modelLists.flat().filter((model) => {
if (!model?.id || seen.has(model.id)) return false;
seen.add(model.id);
return true;
}));
})
.catch((error) => {
// Do not hide the static fallback when the account catalog is unavailable.
console.warn("Unable to load Cursor models for selector:", error);
if (!cancelled) setCursorModels([]);
});
return () => { cancelled = true; };
}, [isOpen, cursorConnectionIds]);
const fetchCombos = async () => {
try {
@@ -280,7 +322,9 @@ export default function ModelSelectModal({
hasModels: mergedModels.length > 0,
};
} else {
const hardcodedModels = getModelsByProviderId(providerId);
const hardcodedModels = providerId === "cursor" && cursorModels.length > 0
? cursorModels
: getModelsByProviderId(providerId);
const hardcodedIds = new Set(hardcodedModels.map((m) => m.id));
// Custom models: if no hardcoded models (e.g. openrouter), show all aliases for this provider
@@ -349,7 +393,7 @@ export default function ModelSelectModal({
});
return groups;
}, [filteredActiveProviders, modelAliases, allProviders, providerNodes, customModels, disabledModels, kindFilter, activeProviders]);
}, [filteredActiveProviders, modelAliases, allProviders, providerNodes, customModels, disabledModels, kindFilter, activeProviders, cursorModels]);
// Filter combos by search query (and hide combos when kindFilter is set — combos are LLM-only by design)
const filteredCombos = useMemo(() => {