@fudrouter/fsrouter 0.6.63 → 0.6.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rewriteSseImports.js +5 -1
- package/dist/open-sse/executors/cliproxyapi.js +2 -2
- package/dist/open-sse/services/rateLimitManager.js +4 -4
- package/package.json +1 -1
- package/open-sse/AGENTS.md +0 -39
- package/open-sse/config/anthropicHeaders.js +0 -87
- package/open-sse/config/appConstants.js +0 -238
- package/open-sse/config/audioRegistry.js +0 -506
- package/open-sse/config/cliFingerprints.js +0 -304
- package/open-sse/config/codexInstructions.js +0 -119
- package/open-sse/config/codexQuotaScopes.js +0 -42
- package/open-sse/config/constants.js +0 -4
- package/open-sse/config/contextEditing.js +0 -68
- package/open-sse/config/credentialLoader.js +0 -83
- package/open-sse/config/defaultThinkingSignature.js +0 -12
- package/open-sse/config/embeddingRegistry.js +0 -264
- package/open-sse/config/errorConfig.js +0 -96
- package/open-sse/config/freeModelCatalog.data.js +0 -121
- package/open-sse/config/freeModelCatalog.js +0 -90
- package/open-sse/config/freeTierCatalog.js +0 -81
- package/open-sse/config/googleTtsLanguages.js +0 -62
- package/open-sse/config/imageParamDefs.js +0 -360
- package/open-sse/config/imageRegistry.js +0 -493
- package/open-sse/config/kiroConstants.js +0 -268
- package/open-sse/config/mediaConfig.js +0 -27
- package/open-sse/config/mediaServiceKinds.js +0 -71
- package/open-sse/config/models.js +0 -13
- package/open-sse/config/moderationRegistry.js +0 -71
- package/open-sse/config/musicRegistry.js +0 -99
- package/open-sse/config/ocrRegistry.js +0 -61
- package/open-sse/config/ollamaModels.js +0 -19
- package/open-sse/config/providerErrorRules.js +0 -114
- package/open-sse/config/providerFieldStrips.js +0 -35
- package/open-sse/config/providerHeaderProfiles.js +0 -191
- package/open-sse/config/providerModels.js +0 -106
- package/open-sse/config/providerRegistry.js +0 -16
- package/open-sse/config/providers.js +0 -19
- package/open-sse/config/registryUtils.js +0 -106
- package/open-sse/config/rerankRegistry.js +0 -177
- package/open-sse/config/runtimeConfig.js +0 -96
- package/open-sse/config/runway.js +0 -39
- package/open-sse/config/searchRegistry.js +0 -153
- package/open-sse/config/toolCloaking.js +0 -199
- package/open-sse/config/ttsModels.js +0 -129
- package/open-sse/config/videoRegistry.js +0 -207
- package/open-sse/executors/adapta-web.js +0 -435
- package/open-sse/executors/antigravity.js +0 -534
- package/open-sse/executors/antigravityUpstreamError.js +0 -13
- package/open-sse/executors/auggie.js +0 -437
- package/open-sse/executors/azure-openai.js +0 -32
- package/open-sse/executors/azure.js +0 -57
- package/open-sse/executors/base.js +0 -181
- package/open-sse/executors/bedrock.js +0 -633
- package/open-sse/executors/blackbox-web.js +0 -578
- package/open-sse/executors/chatgpt-web.js +0 -2042
- package/open-sse/executors/chipotle.js +0 -357
- package/open-sse/executors/claude-web-with-auto-refresh.js +0 -73
- package/open-sse/executors/claude-web.js +0 -586
- package/open-sse/executors/cliproxyapi.js +0 -296
- package/open-sse/executors/cloudflare-ai.js +0 -46
- package/open-sse/executors/codebuddy-cn.js +0 -40
- package/open-sse/executors/codex.js +0 -1324
- package/open-sse/executors/commandCode.js +0 -558
- package/open-sse/executors/commandcode.js +0 -88
- package/open-sse/executors/copilot-m365-connection.js +0 -176
- package/open-sse/executors/copilot-m365-frames.js +0 -192
- package/open-sse/executors/copilot-m365-web.js +0 -299
- package/open-sse/executors/copilot-web.js +0 -580
- package/open-sse/executors/cursor.js +0 -795
- package/open-sse/executors/deepseek-web-with-auto-refresh.js +0 -150
- package/open-sse/executors/deepseek-web.js +0 -875
- package/open-sse/executors/default.js +0 -430
- package/open-sse/executors/devin-cli.js +0 -351
- package/open-sse/executors/doubao-web.js +0 -550
- package/open-sse/executors/duckduckgo-web.js +0 -629
- package/open-sse/executors/forceResponsesUpstream.js +0 -33
- package/open-sse/executors/gemini-business.js +0 -320
- package/open-sse/executors/gemini-cli.js +0 -89
- package/open-sse/executors/gemini-web.js +0 -297
- package/open-sse/executors/github.js +0 -379
- package/open-sse/executors/gitlab.js +0 -569
- package/open-sse/executors/glm.js +0 -361
- package/open-sse/executors/grok-cli.js +0 -119
- package/open-sse/executors/grok-web.js +0 -345
- package/open-sse/executors/huggingchat.js +0 -467
- package/open-sse/executors/iflow.js +0 -108
- package/open-sse/executors/index.js +0 -78
- package/open-sse/executors/inner-ai.js +0 -527
- package/open-sse/executors/kimchi.js +0 -123
- package/open-sse/executors/kimi-web.js +0 -325
- package/open-sse/executors/kimi.js +0 -97
- package/open-sse/executors/kiro.js +0 -503
- package/open-sse/executors/kiroThinking.js +0 -44
- package/open-sse/executors/lmarena.js +0 -395
- package/open-sse/executors/mimo-free.js +0 -167
- package/open-sse/executors/mimocode.js +0 -392
- package/open-sse/executors/ninerouter.js +0 -155
- package/open-sse/executors/nlpcloud.js +0 -438
- package/open-sse/executors/ollama-local.js +0 -14
- package/open-sse/executors/opencode-go.js +0 -41
- package/open-sse/executors/opencode.js +0 -32
- package/open-sse/executors/perplexity-web.js +0 -581
- package/open-sse/executors/poe-web.js +0 -133
- package/open-sse/executors/pollinations.js +0 -95
- package/open-sse/executors/puter.js +0 -31
- package/open-sse/executors/qoder.js +0 -448
- package/open-sse/executors/qwen-web.js +0 -372
- package/open-sse/executors/qwen.js +0 -129
- package/open-sse/executors/t3-chat-web.js +0 -417
- package/open-sse/executors/theoldllm.js +0 -290
- package/open-sse/executors/trae.js +0 -418
- package/open-sse/executors/v0-vercel-web.js +0 -141
- package/open-sse/executors/venice-web.js +0 -142
- package/open-sse/executors/vertex.js +0 -131
- package/open-sse/executors/vertexMedia.js +0 -236
- package/open-sse/executors/windsurf.js +0 -560
- package/open-sse/executors/xai.js +0 -46
- package/open-sse/executors/xiaomi-tokenplan.js +0 -19
- package/open-sse/executors/yuanbao-web.js +0 -385
- package/open-sse/executors/zed-hosted.js +0 -281
- package/open-sse/executors/zenmux-free.js +0 -247
- package/open-sse/handlers/audioSpeech.js +0 -759
- package/open-sse/handlers/audioTranscription.js +0 -395
- package/open-sse/handlers/audioTranslation.js +0 -181
- package/open-sse/handlers/chatCore/nonStreamingHandler.js +0 -300
- package/open-sse/handlers/chatCore/requestDetail.js +0 -102
- package/open-sse/handlers/chatCore/sseToJsonHandler.js +0 -231
- package/open-sse/handlers/chatCore/streamingHandler.js +0 -95
- package/open-sse/handlers/chatCore.js +0 -404
- package/open-sse/handlers/embeddingProviders/_base.js +0 -4
- package/open-sse/handlers/embeddingProviders/gemini.js +0 -54
- package/open-sse/handlers/embeddingProviders/index.js +0 -23
- package/open-sse/handlers/embeddingProviders/openai.js +0 -39
- package/open-sse/handlers/embeddingProviders/openaiCompatNode.js +0 -13
- package/open-sse/handlers/embeddingsCore.js +0 -126
- package/open-sse/handlers/fetch/index.js +0 -237
- package/open-sse/handlers/imageGenerationCore.js +0 -230
- package/open-sse/handlers/imageProviders/_base.js +0 -31
- package/open-sse/handlers/imageProviders/antigravity.js +0 -73
- package/open-sse/handlers/imageProviders/blackForestLabs.js +0 -63
- package/open-sse/handlers/imageProviders/cloudflareAi.js +0 -207
- package/open-sse/handlers/imageProviders/codex.js +0 -217
- package/open-sse/handlers/imageProviders/comfyui.js +0 -25
- package/open-sse/handlers/imageProviders/falAi.js +0 -62
- package/open-sse/handlers/imageProviders/gemini.js +0 -40
- package/open-sse/handlers/imageProviders/huggingface.js +0 -38
- package/open-sse/handlers/imageProviders/index.js +0 -44
- package/open-sse/handlers/imageProviders/leonardo.js +0 -435
- package/open-sse/handlers/imageProviders/nanobanana.js +0 -79
- package/open-sse/handlers/imageProviders/openai.js +0 -61
- package/open-sse/handlers/imageProviders/runwayml.js +0 -72
- package/open-sse/handlers/imageProviders/sdwebui.js +0 -36
- package/open-sse/handlers/imageProviders/stabilityAi.js +0 -59
- package/open-sse/handlers/imageProviders/weavy.js +0 -222
- package/open-sse/handlers/moderations.js +0 -92
- package/open-sse/handlers/ocr.js +0 -89
- package/open-sse/handlers/rerank.js +0 -223
- package/open-sse/handlers/responseSanitizer/reasoning.js +0 -144
- package/open-sse/handlers/responsesHandler.js +0 -99
- package/open-sse/handlers/search/callers.js +0 -371
- package/open-sse/handlers/search/chatSearch.js +0 -409
- package/open-sse/handlers/search/index.js +0 -201
- package/open-sse/handlers/search/normalizers.js +0 -223
- package/open-sse/handlers/search.js +0 -1056
- package/open-sse/handlers/sseParser.js +0 -469
- package/open-sse/handlers/sttCore.js +0 -193
- package/open-sse/handlers/ttsCore.js +0 -74
- package/open-sse/handlers/ttsProviders/_base.js +0 -39
- package/open-sse/handlers/ttsProviders/edgeTts.js +0 -89
- package/open-sse/handlers/ttsProviders/elevenlabs.js +0 -48
- package/open-sse/handlers/ttsProviders/gemini.js +0 -117
- package/open-sse/handlers/ttsProviders/genericFormats.js +0 -169
- package/open-sse/handlers/ttsProviders/googleTts.js +0 -54
- package/open-sse/handlers/ttsProviders/index.js +0 -50
- package/open-sse/handlers/ttsProviders/localDevice.js +0 -87
- package/open-sse/handlers/ttsProviders/minimax.js +0 -59
- package/open-sse/handlers/ttsProviders/openai.js +0 -30
- package/open-sse/handlers/ttsProviders/openrouter.js +0 -70
- package/open-sse/handlers/usageExtractor.js +0 -93
- package/open-sse/handlers/videoGenerationCore.js +0 -119
- package/open-sse/handlers/videoProviders/index.js +0 -22
- package/open-sse/handlers/videoProviders/leonardo.js +0 -511
- package/open-sse/handlers/videoProviders/weavy.js +0 -198
- package/open-sse/handlers/webFetch.js +0 -200
- package/open-sse/index.js +0 -79
- package/open-sse/mcp-server/audit.js +0 -283
- package/open-sse/mcp-server/catalog.js +0 -184
- package/open-sse/mcp-server/descriptionCompressor.js +0 -175
- package/open-sse/mcp-server/httpAuthContext.js +0 -32
- package/open-sse/mcp-server/httpTransport.js +0 -229
- package/open-sse/mcp-server/index.js +0 -33
- package/open-sse/mcp-server/mcpCallerIdentity.js +0 -21
- package/open-sse/mcp-server/runtimeHeartbeat.js +0 -110
- package/open-sse/mcp-server/schemas/a2a.js +0 -153
- package/open-sse/mcp-server/schemas/audit.js +0 -17
- package/open-sse/mcp-server/schemas/index.js +0 -166
- package/open-sse/mcp-server/schemas/pickFastestModel.js +0 -90
- package/open-sse/mcp-server/schemas/toolDefinition.js +0 -0
- package/open-sse/mcp-server/schemas/toolSearch.js +0 -32
- package/open-sse/mcp-server/schemas/tools.js +0 -1219
- package/open-sse/mcp-server/scopeEnforcement.js +0 -80
- package/open-sse/mcp-server/server.js +0 -1168
- package/open-sse/mcp-server/toolCardinality.js +0 -78
- package/open-sse/mcp-server/toolSearch/catalog.js +0 -66
- package/open-sse/mcp-server/toolSearch/handler.js +0 -20
- package/open-sse/mcp-server/toolSearch/index.js +0 -10
- package/open-sse/mcp-server/toolSearch/register.js +0 -21
- package/open-sse/mcp-server/toolSearch/search.js +0 -55
- package/open-sse/mcp-server/toolSearch/signature.js +0 -67
- package/open-sse/mcp-server/tools/advancedTools.js +0 -893
- package/open-sse/mcp-server/tools/agentSkillTools.js +0 -69
- package/open-sse/mcp-server/tools/compressionTools.js +0 -309
- package/open-sse/mcp-server/tools/gamificationTools.js +0 -134
- package/open-sse/mcp-server/tools/githubSkillTools.js +0 -102
- package/open-sse/mcp-server/tools/memoryTools.js +0 -118
- package/open-sse/mcp-server/tools/notionTools.js +0 -101
- package/open-sse/mcp-server/tools/obsidianTools.js +0 -307
- package/open-sse/mcp-server/tools/pickFastestModel.js +0 -223
- package/open-sse/mcp-server/tools/pluginTools.js +0 -181
- package/open-sse/mcp-server/tools/poolTools.js +0 -139
- package/open-sse/mcp-server/tools/skillTools.js +0 -113
- package/open-sse/package.json +0 -10
- package/open-sse/providers/REGISTRY_TEMPLATE.js +0 -98
- package/open-sse/providers/capabilities.js +0 -293
- package/open-sse/providers/index.js +0 -51
- package/open-sse/providers/models/helpers.js +0 -20
- package/open-sse/providers/models/namePatterns.js +0 -33
- package/open-sse/providers/models/schema.js +0 -40
- package/open-sse/providers/pricing.js +0 -308
- package/open-sse/providers/registry/alicode-intl.js +0 -30
- package/open-sse/providers/registry/alicode.js +0 -31
- package/open-sse/providers/registry/anthropic.js +0 -37
- package/open-sse/providers/registry/antigravity.js +0 -81
- package/open-sse/providers/registry/assemblyai.js +0 -38
- package/open-sse/providers/registry/aws-polly.js +0 -45
- package/open-sse/providers/registry/azure.js +0 -21
- package/open-sse/providers/registry/black-forest-labs.js +0 -32
- package/open-sse/providers/registry/blackbox.js +0 -41
- package/open-sse/providers/registry/brave-search.js +0 -35
- package/open-sse/providers/registry/byteplus.js +0 -35
- package/open-sse/providers/registry/cartesia.js +0 -36
- package/open-sse/providers/registry/cerebras.js +0 -31
- package/open-sse/providers/registry/chutes.js +0 -24
- package/open-sse/providers/registry/claude.js +0 -87
- package/open-sse/providers/registry/cline.js +0 -51
- package/open-sse/providers/registry/clinepass.js +0 -57
- package/open-sse/providers/registry/cloudflare-ai.js +0 -55
- package/open-sse/providers/registry/codebuddy-cn.js +0 -77
- package/open-sse/providers/registry/codex.js +0 -100
- package/open-sse/providers/registry/cohere.js +0 -27
- package/open-sse/providers/registry/comfyui.js +0 -20
- package/open-sse/providers/registry/commandcode.js +0 -43
- package/open-sse/providers/registry/coqui.js +0 -30
- package/open-sse/providers/registry/cursor.js +0 -58
- package/open-sse/providers/registry/deepgram.js +0 -33
- package/open-sse/providers/registry/deepseek.js +0 -51
- package/open-sse/providers/registry/digitalocean.js +0 -92
- package/open-sse/providers/registry/edge-tts.js +0 -24
- package/open-sse/providers/registry/elevenlabs.js +0 -35
- package/open-sse/providers/registry/exa.js +0 -50
- package/open-sse/providers/registry/fal-ai.js +0 -34
- package/open-sse/providers/registry/featherless.js +0 -34
- package/open-sse/providers/registry/firecrawl.js +0 -34
- package/open-sse/providers/registry/fireworks.js +0 -29
- package/open-sse/providers/registry/gemini-cli.js +0 -58
- package/open-sse/providers/registry/gemini.js +0 -83
- package/open-sse/providers/registry/github.js +0 -88
- package/open-sse/providers/registry/gitlab.js +0 -32
- package/open-sse/providers/registry/glm-cn.js +0 -35
- package/open-sse/providers/registry/glm.js +0 -58
- package/open-sse/providers/registry/google-pse.js +0 -35
- package/open-sse/providers/registry/google-tts.js +0 -24
- package/open-sse/providers/registry/grok-cli.js +0 -86
- package/open-sse/providers/registry/grok-web.js +0 -39
- package/open-sse/providers/registry/groq.js +0 -37
- package/open-sse/providers/registry/huggingface.js +0 -34
- package/open-sse/providers/registry/hyperbolic.js +0 -35
- package/open-sse/providers/registry/ibm-bob.js +0 -27
- package/open-sse/providers/registry/iflow.js +0 -52
- package/open-sse/providers/registry/index.js +0 -210
- package/open-sse/providers/registry/inworld.js +0 -36
- package/open-sse/providers/registry/jina-ai.js +0 -42
- package/open-sse/providers/registry/jina-reader.js +0 -34
- package/open-sse/providers/registry/kilocode.js +0 -51
- package/open-sse/providers/registry/kimchi.js +0 -49
- package/open-sse/providers/registry/kimi-coding.js +0 -65
- package/open-sse/providers/registry/kimi.js +0 -56
- package/open-sse/providers/registry/kiro.js +0 -115
- package/open-sse/providers/registry/linkup.js +0 -34
- package/open-sse/providers/registry/local-device.js +0 -24
- package/open-sse/providers/registry/mimo-free.js +0 -24
- package/open-sse/providers/registry/minimax-cn.js +0 -76
- package/open-sse/providers/registry/minimax.js +0 -83
- package/open-sse/providers/registry/mistral.js +0 -34
- package/open-sse/providers/registry/mmf.js +0 -19
- package/open-sse/providers/registry/nanobanana.js +0 -35
- package/open-sse/providers/registry/nebius.js +0 -27
- package/open-sse/providers/registry/nvidia.js +0 -43
- package/open-sse/providers/registry/ollama-local.js +0 -19
- package/open-sse/providers/registry/ollama.js +0 -36
- package/open-sse/providers/registry/openai.js +0 -84
- package/open-sse/providers/registry/opencode-go.js +0 -41
- package/open-sse/providers/registry/opencode.js +0 -25
- package/open-sse/providers/registry/openrouter.js +0 -60
- package/open-sse/providers/registry/perplexity-agent.js +0 -49
- package/open-sse/providers/registry/perplexity-web.js +0 -33
- package/open-sse/providers/registry/perplexity.js +0 -37
- package/open-sse/providers/registry/playht.js +0 -36
- package/open-sse/providers/registry/qoder.js +0 -54
- package/open-sse/providers/registry/qwen.js +0 -33
- package/open-sse/providers/registry/recraft.js +0 -24
- package/open-sse/providers/registry/runwayml.js +0 -30
- package/open-sse/providers/registry/sdwebui.js +0 -20
- package/open-sse/providers/registry/searchapi.js +0 -35
- package/open-sse/providers/registry/searxng.js +0 -35
- package/open-sse/providers/registry/serper.js +0 -35
- package/open-sse/providers/registry/siliconflow.js +0 -39
- package/open-sse/providers/registry/stability-ai.js +0 -31
- package/open-sse/providers/registry/tavily.js +0 -50
- package/open-sse/providers/registry/together.js +0 -31
- package/open-sse/providers/registry/topaz.js +0 -19
- package/open-sse/providers/registry/tortoise.js +0 -30
- package/open-sse/providers/registry/venice.js +0 -56
- package/open-sse/providers/registry/vercel-ai-gateway.js +0 -41
- package/open-sse/providers/registry/vertex-partner.js +0 -29
- package/open-sse/providers/registry/vertex.js +0 -32
- package/open-sse/providers/registry/volcengine-ark.js +0 -35
- package/open-sse/providers/registry/voyage-ai.js +0 -30
- package/open-sse/providers/registry/xai.js +0 -45
- package/open-sse/providers/registry/xiaomi-mimo.js +0 -46
- package/open-sse/providers/registry/xiaomi-tokenplan.js +0 -63
- package/open-sse/providers/registry/youcom.js +0 -35
- package/open-sse/providers/schema.js +0 -76
- package/open-sse/providers/shared.js +0 -74
- package/open-sse/providers/thinkingLevels.js +0 -48
- package/open-sse/rtk/applyFilter.js +0 -15
- package/open-sse/rtk/autodetect.js +0 -111
- package/open-sse/rtk/caveman.js +0 -100
- package/open-sse/rtk/cavemanPrompts.js +0 -78
- package/open-sse/rtk/constants.js +0 -55
- package/open-sse/rtk/filters/buildOutput.js +0 -127
- package/open-sse/rtk/filters/dedupLog.js +0 -44
- package/open-sse/rtk/filters/find.js +0 -50
- package/open-sse/rtk/filters/gitDiff.js +0 -92
- package/open-sse/rtk/filters/gitLog.js +0 -99
- package/open-sse/rtk/filters/gitStatus.js +0 -117
- package/open-sse/rtk/filters/grep.js +0 -48
- package/open-sse/rtk/filters/ls.js +0 -79
- package/open-sse/rtk/filters/readNumbered.js +0 -27
- package/open-sse/rtk/filters/searchList.js +0 -52
- package/open-sse/rtk/filters/smartTruncate.js +0 -15
- package/open-sse/rtk/filters/tree.js +0 -32
- package/open-sse/rtk/headroom.js +0 -215
- package/open-sse/rtk/index.js +0 -155
- package/open-sse/rtk/paleo.js +0 -47
- package/open-sse/rtk/ponytail.js +0 -9
- package/open-sse/rtk/ponytailPrompt.js +0 -52
- package/open-sse/rtk/ponytailPrompts.js +0 -76
- package/open-sse/rtk/pxpipe.js +0 -104
- package/open-sse/rtk/registry.js +0 -38
- package/open-sse/rtk/systemInject.js +0 -98
- package/open-sse/services/accountFallback.js +0 -323
- package/open-sse/services/antigravityHeaders.js +0 -91
- package/open-sse/services/antigravityVersion.js +0 -154
- package/open-sse/services/clinepassModels.js +0 -63
- package/open-sse/services/codexQuotaFetcher.js +0 -312
- package/open-sse/services/codexVerbosity.js +0 -30
- package/open-sse/services/combo/context.js +0 -12
- package/open-sse/services/combo/fingerprintExpansion.js +0 -51
- package/open-sse/services/combo/headroomRanking.js +0 -28
- package/open-sse/services/combo/quotaExhaustionCutoff.js +0 -87
- package/open-sse/services/combo/quotaScoring.js +0 -226
- package/open-sse/services/combo/quotaShareConcurrency.js +0 -25
- package/open-sse/services/combo/quotaShareInflight.js +0 -50
- package/open-sse/services/combo/quotaShareStrategy.js +0 -130
- package/open-sse/services/combo/resolveAutoStrategy.js +0 -231
- package/open-sse/services/combo/responseValidation.js +0 -140
- package/open-sse/services/combo/runtimeUnits.js +0 -195
- package/open-sse/services/combo/sessionStickiness.js +0 -128
- package/open-sse/services/combo/shadowRouting.js +0 -131
- package/open-sse/services/combo/targetExhaustion.js +0 -75
- package/open-sse/services/combo/targetSorters.js +0 -126
- package/open-sse/services/combo/targetTimeoutRunner.js +0 -65
- package/open-sse/services/combo/validateQuality.js +0 -271
- package/open-sse/services/combo.js +0 -571
- package/open-sse/services/comboAgentMiddleware.js +0 -91
- package/open-sse/services/comboConfig.js +0 -153
- package/open-sse/services/comboManifestMetrics.js +0 -10
- package/open-sse/services/comboMetrics.js +0 -278
- package/open-sse/services/compact.js +0 -71
- package/open-sse/services/copilotModels.js +0 -155
- package/open-sse/services/emergencyFallback.js +0 -109
- package/open-sse/services/errorClassifier.js +0 -190
- package/open-sse/services/evalRouting.js +0 -201
- package/open-sse/services/freeWebSearch.js +0 -4
- package/open-sse/services/fusion.js +0 -223
- package/open-sse/services/intentClassifier.js +0 -631
- package/open-sse/services/kimchiModels.js +0 -176
- package/open-sse/services/kiroModels.js +0 -332
- package/open-sse/services/model.js +0 -136
- package/open-sse/services/modelCapabilities.js +0 -5
- package/open-sse/services/modelDeprecation.js +0 -101
- package/open-sse/services/modelFamilyFallback.js +0 -166
- package/open-sse/services/oauthCredentialManager.js +0 -156
- package/open-sse/services/pipeline.js +0 -107
- package/open-sse/services/projectId.js +0 -306
- package/open-sse/services/provider.js +0 -169
- package/open-sse/services/providerCooldownTracker.js +0 -94
- package/open-sse/services/providerDefaultRateLimit.js +0 -11
- package/open-sse/services/proxyAutoSelector.js +0 -24
- package/open-sse/services/qoderModels.js +0 -214
- package/open-sse/services/quotaFetchThrottle.js +0 -103
- package/open-sse/services/quotaMonitor.js +0 -310
- package/open-sse/services/quotaPreflight.js +0 -266
- package/open-sse/services/rateLimitManager/headers.js +0 -56
- package/open-sse/services/rateLimitManager.js +0 -616
- package/open-sse/services/rateLimitSemaphore.js +0 -112
- package/open-sse/services/responsesInputSanitizer.js +0 -99
- package/open-sse/services/slidingWindowLimiter.js +0 -44
- package/open-sse/services/streamRecovery.js +0 -355
- package/open-sse/services/taskAwareRouter.js +0 -227
- package/open-sse/services/taskAwareRouting.js +0 -332
- package/open-sse/services/thinkingBudget.js +0 -247
- package/open-sse/services/tokenRefresh/dedup.js +0 -31
- package/open-sse/services/tokenRefresh/providers.js +0 -624
- package/open-sse/services/tokenRefresh.js +0 -254
- package/open-sse/services/usage/claude.js +0 -147
- package/open-sse/services/usage/codebuddy-cn.js +0 -138
- package/open-sse/services/usage/codex.js +0 -267
- package/open-sse/services/usage/github.js +0 -100
- package/open-sse/services/usage/google.js +0 -241
- package/open-sse/services/usage/grok-cli.js +0 -274
- package/open-sse/services/usage/kiro.js +0 -188
- package/open-sse/services/usage/minimax.js +0 -234
- package/open-sse/services/usage/misc.js +0 -288
- package/open-sse/services/usage/shared.js +0 -70
- package/open-sse/services/usage.js +0 -62
- package/open-sse/services/usageDb.js +0 -2
- package/open-sse/services/webSearchRouting.js +0 -25
- package/open-sse/services/wildcardRouter.js +0 -59
- package/open-sse/shared/clineAuth.js +0 -37
- package/open-sse/shared/machineId.js +0 -19
- package/open-sse/shared/qoder/constants.js +0 -64
- package/open-sse/shared/qoder/cosy.js +0 -175
- package/open-sse/shared/qoder/encoding.js +0 -55
- package/open-sse/transformer/responsesTransformer.js +0 -439
- package/open-sse/transformer/streamToJsonConverter.js +0 -103
- package/open-sse/translator/concerns/chunk.js +0 -11
- package/open-sse/translator/concerns/finishReason.js +0 -63
- package/open-sse/translator/concerns/image.js +0 -124
- package/open-sse/translator/concerns/json.js +0 -5
- package/open-sse/translator/concerns/message.js +0 -7
- package/open-sse/translator/concerns/modality.js +0 -155
- package/open-sse/translator/concerns/paramSupport.js +0 -75
- package/open-sse/translator/concerns/prefetch.js +0 -96
- package/open-sse/translator/concerns/reasoning.js +0 -24
- package/open-sse/translator/concerns/thinking.js +0 -53
- package/open-sse/translator/concerns/thinkingUnified.js +0 -329
- package/open-sse/translator/concerns/toolCall.js +0 -153
- package/open-sse/translator/concerns/usage.js +0 -69
- package/open-sse/translator/formats/claude.js +0 -368
- package/open-sse/translator/formats/gemini.js +0 -380
- package/open-sse/translator/formats/maxTokens.js +0 -34
- package/open-sse/translator/formats/openai.js +0 -134
- package/open-sse/translator/formats/responsesApi.js +0 -141
- package/open-sse/translator/formats.js +0 -36
- package/open-sse/translator/helpers/claudeHelper.js +0 -216
- package/open-sse/translator/helpers/geminiHelper.js +0 -372
- package/open-sse/translator/helpers/imageHelper.js +0 -34
- package/open-sse/translator/helpers/maxTokensHelper.js +0 -27
- package/open-sse/translator/helpers/openaiHelper.js +0 -130
- package/open-sse/translator/helpers/responsesApiHelper.js +0 -139
- package/open-sse/translator/helpers/toolCallHelper.js +0 -148
- package/open-sse/translator/index.js +0 -252
- package/open-sse/translator/request/antigravity-to-openai.js +0 -242
- package/open-sse/translator/request/claude-to-kiro.js +0 -478
- package/open-sse/translator/request/claude-to-openai.js +0 -263
- package/open-sse/translator/request/gemini-to-openai.js +0 -152
- package/open-sse/translator/request/openai-responses.js +0 -385
- package/open-sse/translator/request/openai-to-claude.js +0 -383
- package/open-sse/translator/request/openai-to-commandcode.js +0 -176
- package/open-sse/translator/request/openai-to-cursor.js +0 -185
- package/open-sse/translator/request/openai-to-gemini.js +0 -442
- package/open-sse/translator/request/openai-to-kiro.js +0 -607
- package/open-sse/translator/request/openai-to-kiro.old.js +0 -278
- package/open-sse/translator/request/openai-to-ollama.js +0 -195
- package/open-sse/translator/request/openai-to-vertex.js +0 -42
- package/open-sse/translator/response/claude-to-openai.js +0 -195
- package/open-sse/translator/response/commandcode-to-openai.js +0 -188
- package/open-sse/translator/response/cursor-to-openai.js +0 -30
- package/open-sse/translator/response/gemini-to-openai.js +0 -147
- package/open-sse/translator/response/kiro-to-claude.js +0 -261
- package/open-sse/translator/response/kiro-to-openai.js +0 -160
- package/open-sse/translator/response/ollama-to-openai.js +0 -134
- package/open-sse/translator/response/openai-responses.js +0 -535
- package/open-sse/translator/response/openai-to-antigravity.js +0 -123
- package/open-sse/translator/response/openai-to-claude.js +0 -265
- package/open-sse/translator/schema/blocks.js +0 -43
- package/open-sse/translator/schema/defaults.js +0 -7
- package/open-sse/translator/schema/finishReasons.js +0 -27
- package/open-sse/translator/schema/index.js +0 -8
- package/open-sse/translator/schema/roles.js +0 -16
- package/open-sse/utils/agentGoalPolicy.js +0 -85
- package/open-sse/utils/aiSdkCompat.js +0 -75
- package/open-sse/utils/bypassHandler.js +0 -298
- package/open-sse/utils/cacheControlPolicy.js +0 -189
- package/open-sse/utils/claudeCloaking.js +0 -155
- package/open-sse/utils/claudeHeaderCache.js +0 -70
- package/open-sse/utils/claudeSignature.js +0 -41
- package/open-sse/utils/clientDetector.js +0 -63
- package/open-sse/utils/codebuddySanitizer.js +0 -96
- package/open-sse/utils/composerToolCalls.js +0 -158
- package/open-sse/utils/cors.js +0 -13
- package/open-sse/utils/cursorChecksum.js +0 -149
- package/open-sse/utils/cursorImages.js +0 -224
- package/open-sse/utils/cursorProtobuf.js +0 -904
- package/open-sse/utils/cursorVersionDetector.js +0 -55
- package/open-sse/utils/debugLog.js +0 -14
- package/open-sse/utils/diagnostics.js +0 -143
- package/open-sse/utils/error.js +0 -164
- package/open-sse/utils/estimateSize.js +0 -33
- package/open-sse/utils/finishReason.js +0 -32
- package/open-sse/utils/flattenToolHistory.js +0 -68
- package/open-sse/utils/headers.js +0 -36
- package/open-sse/utils/heapPressure.js +0 -35
- package/open-sse/utils/jsonToSse.js +0 -125
- package/open-sse/utils/keepaliveThreshold.js +0 -40
- package/open-sse/utils/logger.js +0 -104
- package/open-sse/utils/noThinkingAlias.js +0 -74
- package/open-sse/utils/number.js +0 -7
- package/open-sse/utils/ollamaTransform.js +0 -85
- package/open-sse/utils/opencodeHeaders.js +0 -47
- package/open-sse/utils/progressTracker.js +0 -81
- package/open-sse/utils/providerRequestLogging.js +0 -219
- package/open-sse/utils/proxyFetch.js +0 -369
- package/open-sse/utils/reasoningContentInjector.js +0 -79
- package/open-sse/utils/reasoningFields.js +0 -70
- package/open-sse/utils/requestLogger.js +0 -260
- package/open-sse/utils/responsesInputNormalization.js +0 -92
- package/open-sse/utils/responsesStatePolicy.js +0 -52
- package/open-sse/utils/responsesStreamHelpers.js +0 -49
- package/open-sse/utils/sessionManager.js +0 -240
- package/open-sse/utils/sleep.js +0 -6
- package/open-sse/utils/sse.js +0 -14
- package/open-sse/utils/sseConstants.js +0 -23
- package/open-sse/utils/sseHeartbeat.js +0 -104
- package/open-sse/utils/stream.js +0 -517
- package/open-sse/utils/streamFailureFinalization.js +0 -134
- package/open-sse/utils/streamHandler.js +0 -250
- package/open-sse/utils/streamHelpers.js +0 -137
- package/open-sse/utils/textualToolCall.js +0 -104
- package/open-sse/utils/thinkCloseMarker.js +0 -72
- package/open-sse/utils/thinkTagParser.js +0 -146
- package/open-sse/utils/toolCallArguments.js +0 -12
- package/open-sse/utils/toolDeduper.js +0 -49
- package/open-sse/utils/toolSources.js +0 -31
- package/open-sse/utils/upstreamResponseHeaders.js +0 -25
- package/open-sse/utils/urlSanitize.js +0 -15
- package/open-sse/utils/usageTracking.js +0 -347
|
@@ -1,904 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cursor Protobuf Encoder/Decoder
|
|
3
|
-
* Implements ConnectRPC protobuf wire format for Cursor API
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { v4 as uuidv4 } from "uuid";
|
|
7
|
-
import zlib from "zlib";
|
|
8
|
-
|
|
9
|
-
const DEBUG = process.env.CURSOR_PROTOBUF_DEBUG === "1";
|
|
10
|
-
const log = (tag, ...args) => DEBUG && console.log(`[PROTOBUF:${tag}]`, ...args);
|
|
11
|
-
const textDecoder = new TextDecoder();
|
|
12
|
-
|
|
13
|
-
const PROTOBUF_SCHEMA_VERSION = "1.1.3";
|
|
14
|
-
|
|
15
|
-
// ==================== SCHEMAS ====================
|
|
16
|
-
|
|
17
|
-
const WIRE_TYPE = { VARINT: 0, FIXED64: 1, LEN: 2, FIXED32: 5 };
|
|
18
|
-
|
|
19
|
-
const ROLE = { USER: 1, ASSISTANT: 2 };
|
|
20
|
-
|
|
21
|
-
const UNIFIED_MODE = { CHAT: 1, AGENT: 2 };
|
|
22
|
-
|
|
23
|
-
const THINKING_LEVEL = { UNSPECIFIED: 0, MEDIUM: 1, HIGH: 2 };
|
|
24
|
-
const CLIENT_SIDE_TOOL_V2 = { MCP: 19 };
|
|
25
|
-
const CLIENT_SIDE_TOOL_V2_MCP = 19;
|
|
26
|
-
|
|
27
|
-
const FIELD = {
|
|
28
|
-
// StreamUnifiedChatRequestWithTools (top level)
|
|
29
|
-
REQUEST: 1,
|
|
30
|
-
|
|
31
|
-
// StreamUnifiedChatRequest
|
|
32
|
-
MESSAGES: 1,
|
|
33
|
-
UNKNOWN_2: 2,
|
|
34
|
-
INSTRUCTION: 3,
|
|
35
|
-
UNKNOWN_4: 4,
|
|
36
|
-
MODEL: 5,
|
|
37
|
-
WEB_TOOL: 8,
|
|
38
|
-
UNKNOWN_13: 13,
|
|
39
|
-
CURSOR_SETTING: 15,
|
|
40
|
-
UNKNOWN_19: 19,
|
|
41
|
-
CONVERSATION_ID: 23,
|
|
42
|
-
METADATA: 26,
|
|
43
|
-
IS_AGENTIC: 27,
|
|
44
|
-
SUPPORTED_TOOLS: 29,
|
|
45
|
-
MESSAGE_IDS: 30,
|
|
46
|
-
MCP_TOOLS: 34,
|
|
47
|
-
LARGE_CONTEXT: 35,
|
|
48
|
-
UNKNOWN_38: 38,
|
|
49
|
-
UNIFIED_MODE: 46,
|
|
50
|
-
UNKNOWN_47: 47,
|
|
51
|
-
SHOULD_DISABLE_TOOLS: 48,
|
|
52
|
-
THINKING_LEVEL: 49,
|
|
53
|
-
UNKNOWN_51: 51,
|
|
54
|
-
UNKNOWN_53: 53,
|
|
55
|
-
UNIFIED_MODE_NAME: 54,
|
|
56
|
-
|
|
57
|
-
// ConversationMessage
|
|
58
|
-
MSG_CONTENT: 1,
|
|
59
|
-
MSG_ROLE: 2,
|
|
60
|
-
MSG_ID: 13,
|
|
61
|
-
MSG_TOOL_RESULTS: 18,
|
|
62
|
-
MSG_IS_AGENTIC: 29,
|
|
63
|
-
MSG_SERVER_BUBBLE_ID: 32,
|
|
64
|
-
MSG_UNIFIED_MODE: 47,
|
|
65
|
-
MSG_SUPPORTED_TOOLS: 51,
|
|
66
|
-
|
|
67
|
-
// ConversationMessage.ToolResult
|
|
68
|
-
TOOL_RESULT_CALL_ID: 1,
|
|
69
|
-
TOOL_RESULT_NAME: 2,
|
|
70
|
-
TOOL_RESULT_INDEX: 3,
|
|
71
|
-
TOOL_RESULT_RAW_ARGS: 5,
|
|
72
|
-
TOOL_RESULT_RESULT: 8,
|
|
73
|
-
TOOL_RESULT_TOOL_CALL: 11,
|
|
74
|
-
TOOL_RESULT_MODEL_CALL_ID: 12,
|
|
75
|
-
|
|
76
|
-
// ClientSideToolV2Result (nested inside ToolResult.result)
|
|
77
|
-
CLIENT_RESULT_TOOL: 1,
|
|
78
|
-
CLIENT_RESULT_MCP_RESULT: 28,
|
|
79
|
-
CLIENT_RESULT_TOOL_CALL_ID: 35,
|
|
80
|
-
CLIENT_RESULT_MODEL_CALL_ID: 48,
|
|
81
|
-
CLIENT_RESULT_TOOL_INDEX: 49,
|
|
82
|
-
// Aliases used by encodeClientSideToolV2Result
|
|
83
|
-
CV2R_TOOL: 1,
|
|
84
|
-
CV2R_MCP_RESULT: 28,
|
|
85
|
-
CV2R_CALL_ID: 35,
|
|
86
|
-
CV2R_MODEL_CALL_ID: 48,
|
|
87
|
-
CV2R_TOOL_INDEX: 49,
|
|
88
|
-
|
|
89
|
-
// MCPResult (nested inside ClientSideToolV2Result.mcp_result)
|
|
90
|
-
MCP_RESULT_SELECTED_TOOL: 1,
|
|
91
|
-
MCP_RESULT_RESULT: 2,
|
|
92
|
-
// Aliases used by encodeMcpResult
|
|
93
|
-
MCPR_SELECTED_TOOL: 1,
|
|
94
|
-
MCPR_RESULT: 2,
|
|
95
|
-
|
|
96
|
-
// ClientSideToolV2Call (nested inside ToolResult.tool_call)
|
|
97
|
-
CLIENT_CALL_TOOL: 1,
|
|
98
|
-
CLIENT_CALL_MCP_PARAMS: 27,
|
|
99
|
-
CLIENT_CALL_TOOL_CALL_ID: 3,
|
|
100
|
-
CLIENT_CALL_NAME: 9,
|
|
101
|
-
CLIENT_CALL_RAW_ARGS: 10,
|
|
102
|
-
CLIENT_CALL_TOOL_INDEX: 48,
|
|
103
|
-
CLIENT_CALL_MODEL_CALL_ID: 49,
|
|
104
|
-
// Aliases used by encodeClientSideToolV2Call
|
|
105
|
-
CV2C_TOOL: 1,
|
|
106
|
-
CV2C_MCP_PARAMS: 27,
|
|
107
|
-
CV2C_CALL_ID: 3,
|
|
108
|
-
CV2C_NAME: 9,
|
|
109
|
-
CV2C_RAW_ARGS: 10,
|
|
110
|
-
CV2C_TOOL_INDEX: 48,
|
|
111
|
-
CV2C_MODEL_CALL_ID: 49,
|
|
112
|
-
|
|
113
|
-
// Model
|
|
114
|
-
MODEL_NAME: 1,
|
|
115
|
-
MODEL_EMPTY: 4,
|
|
116
|
-
|
|
117
|
-
// Instruction
|
|
118
|
-
INSTRUCTION_TEXT: 1,
|
|
119
|
-
|
|
120
|
-
// CursorSetting
|
|
121
|
-
SETTING_PATH: 1,
|
|
122
|
-
SETTING_UNKNOWN_3: 3,
|
|
123
|
-
SETTING_UNKNOWN_6: 6,
|
|
124
|
-
SETTING_UNKNOWN_8: 8,
|
|
125
|
-
SETTING_UNKNOWN_9: 9,
|
|
126
|
-
|
|
127
|
-
// CursorSetting.Unknown6
|
|
128
|
-
SETTING6_FIELD_1: 1,
|
|
129
|
-
SETTING6_FIELD_2: 2,
|
|
130
|
-
|
|
131
|
-
// Metadata
|
|
132
|
-
META_PLATFORM: 1,
|
|
133
|
-
META_ARCH: 2,
|
|
134
|
-
META_VERSION: 3,
|
|
135
|
-
META_CWD: 4,
|
|
136
|
-
META_TIMESTAMP: 5,
|
|
137
|
-
|
|
138
|
-
// MessageId
|
|
139
|
-
MSGID_ID: 1,
|
|
140
|
-
MSGID_SUMMARY: 2,
|
|
141
|
-
MSGID_ROLE: 3,
|
|
142
|
-
|
|
143
|
-
// MCPTool
|
|
144
|
-
MCP_TOOL_NAME: 1,
|
|
145
|
-
MCP_TOOL_DESC: 2,
|
|
146
|
-
MCP_TOOL_PARAMS: 3,
|
|
147
|
-
MCP_TOOL_SERVER: 4,
|
|
148
|
-
|
|
149
|
-
// StreamUnifiedChatResponseWithTools (response)
|
|
150
|
-
TOOL_CALL: 1,
|
|
151
|
-
RESPONSE: 2,
|
|
152
|
-
|
|
153
|
-
// ClientSideToolV2Call
|
|
154
|
-
TOOL_ID: 3,
|
|
155
|
-
TOOL_NAME: 9,
|
|
156
|
-
TOOL_RAW_ARGS: 10,
|
|
157
|
-
TOOL_IS_LAST: 11,
|
|
158
|
-
TOOL_IS_LAST_ALT: 15,
|
|
159
|
-
TOOL_MCP_PARAMS: 27,
|
|
160
|
-
|
|
161
|
-
// MCPParams
|
|
162
|
-
MCP_TOOLS_LIST: 1,
|
|
163
|
-
|
|
164
|
-
// MCPParams.Tool (nested)
|
|
165
|
-
MCP_NESTED_NAME: 1,
|
|
166
|
-
MCP_NESTED_PARAMS: 3,
|
|
167
|
-
|
|
168
|
-
// StreamUnifiedChatResponse
|
|
169
|
-
RESPONSE_TEXT: 1,
|
|
170
|
-
THINKING: 25,
|
|
171
|
-
|
|
172
|
-
// Thinking
|
|
173
|
-
THINKING_TEXT: 1
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// Known response field numbers — used to detect unknown fields from protocol updates
|
|
177
|
-
const KNOWN_RESPONSE_FIELDS = new Set([
|
|
178
|
-
FIELD.TOOL_CALL,
|
|
179
|
-
FIELD.RESPONSE,
|
|
180
|
-
FIELD.TOOL_ID,
|
|
181
|
-
FIELD.TOOL_NAME,
|
|
182
|
-
FIELD.TOOL_RAW_ARGS,
|
|
183
|
-
FIELD.TOOL_IS_LAST,
|
|
184
|
-
FIELD.TOOL_MCP_PARAMS,
|
|
185
|
-
FIELD.RESPONSE_TEXT,
|
|
186
|
-
FIELD.THINKING
|
|
187
|
-
]);
|
|
188
|
-
|
|
189
|
-
// ==================== PRIMITIVE ENCODING ====================
|
|
190
|
-
|
|
191
|
-
export function encodeVarint(value) {
|
|
192
|
-
const bytes = [];
|
|
193
|
-
while (value >= 0x80) {
|
|
194
|
-
bytes.push((value & 0x7F) | 0x80);
|
|
195
|
-
value >>>= 7;
|
|
196
|
-
}
|
|
197
|
-
bytes.push(value & 0x7F);
|
|
198
|
-
return new Uint8Array(bytes);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function encodeField(fieldNum, wireType, value) {
|
|
202
|
-
const tag = (fieldNum << 3) | wireType;
|
|
203
|
-
const tagBytes = encodeVarint(tag);
|
|
204
|
-
|
|
205
|
-
if (wireType === WIRE_TYPE.VARINT) {
|
|
206
|
-
const valueBytes = encodeVarint(value);
|
|
207
|
-
return concatArrays(tagBytes, valueBytes);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (wireType === WIRE_TYPE.LEN) {
|
|
211
|
-
const dataBytes = typeof value === "string"
|
|
212
|
-
? new TextEncoder().encode(value)
|
|
213
|
-
: value instanceof Uint8Array ? value
|
|
214
|
-
: Buffer.isBuffer(value) ? new Uint8Array(value)
|
|
215
|
-
: new Uint8Array(0);
|
|
216
|
-
|
|
217
|
-
const lengthBytes = encodeVarint(dataBytes.length);
|
|
218
|
-
return concatArrays(tagBytes, lengthBytes, dataBytes);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return new Uint8Array(0);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function concatArrays(...arrays) {
|
|
225
|
-
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
226
|
-
const result = new Uint8Array(totalLength);
|
|
227
|
-
let offset = 0;
|
|
228
|
-
for (const arr of arrays) {
|
|
229
|
-
result.set(arr, offset);
|
|
230
|
-
offset += arr.length;
|
|
231
|
-
}
|
|
232
|
-
return result;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// ==================== MESSAGE ENCODING ====================
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Format tool name: "toolName" → "mcp_custom_toolName"
|
|
239
|
-
* Also handles: "mcp__server__tool" → "mcp_server_tool"
|
|
240
|
-
*/
|
|
241
|
-
function formatToolName(name) {
|
|
242
|
-
const base = typeof name === "string" && name.length > 0 ? name : "tool";
|
|
243
|
-
|
|
244
|
-
if (base.startsWith("mcp__")) {
|
|
245
|
-
const rest = base.slice("mcp__".length);
|
|
246
|
-
const splitIdx = rest.indexOf("__");
|
|
247
|
-
if (splitIdx >= 0) {
|
|
248
|
-
const server = rest.slice(0, splitIdx) || "custom";
|
|
249
|
-
const toolName = rest.slice(splitIdx + 2) || "tool";
|
|
250
|
-
return `mcp_${server}_${toolName}`;
|
|
251
|
-
}
|
|
252
|
-
return `mcp_custom_${rest || "tool"}`;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (base.startsWith("mcp_")) return base;
|
|
256
|
-
return `mcp_custom_${base}`;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Parse formatted tool name: "mcp_server_tool" → { serverName, selectedTool }
|
|
261
|
-
*/
|
|
262
|
-
function parseToolName(formattedName) {
|
|
263
|
-
if (typeof formattedName !== "string" || !formattedName.startsWith("mcp_")) {
|
|
264
|
-
return { serverName: "custom", selectedTool: formattedName || "tool" };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const tail = formattedName.slice("mcp_".length);
|
|
268
|
-
const splitIdx = tail.indexOf("_");
|
|
269
|
-
if (splitIdx < 0) {
|
|
270
|
-
return { serverName: "custom", selectedTool: tail || "tool" };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
serverName: tail.slice(0, splitIdx) || "custom",
|
|
275
|
-
selectedTool: tail.slice(splitIdx + 1) || "tool"
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Parse tool_call_id into { toolCallId, modelCallId }
|
|
281
|
-
* Cursor uses "\nmc_" delimiter for model_call_id
|
|
282
|
-
*/
|
|
283
|
-
function parseToolId(id) {
|
|
284
|
-
const delimiter = "\nmc_";
|
|
285
|
-
const idx = id.indexOf(delimiter);
|
|
286
|
-
if (idx >= 0) {
|
|
287
|
-
return { toolCallId: id.slice(0, idx), modelCallId: id.slice(idx + delimiter.length) };
|
|
288
|
-
}
|
|
289
|
-
return { toolCallId: id, modelCallId: null };
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Encode MCPResult proto: { selected_tool, result }
|
|
294
|
-
*/
|
|
295
|
-
function encodeMcpResult(selectedTool, resultContent) {
|
|
296
|
-
return concatArrays(
|
|
297
|
-
encodeField(FIELD.MCPR_SELECTED_TOOL, WIRE_TYPE.LEN, selectedTool),
|
|
298
|
-
encodeField(FIELD.MCPR_RESULT, WIRE_TYPE.LEN, resultContent)
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Encode ClientSideToolV2Result proto: { tool, mcp_result, call_id, model_call_id, tool_index }
|
|
304
|
-
* Represents the result of executing a tool
|
|
305
|
-
*/
|
|
306
|
-
function encodeClientSideToolV2Result(toolCallId, modelCallId, selectedTool, resultContent, toolIndex = 1) {
|
|
307
|
-
return concatArrays(
|
|
308
|
-
encodeField(FIELD.CV2R_TOOL, WIRE_TYPE.VARINT, CLIENT_SIDE_TOOL_V2_MCP),
|
|
309
|
-
encodeField(FIELD.CV2R_MCP_RESULT, WIRE_TYPE.LEN, encodeMcpResult(selectedTool, resultContent)),
|
|
310
|
-
encodeField(FIELD.CV2R_CALL_ID, WIRE_TYPE.LEN, toolCallId),
|
|
311
|
-
...(modelCallId ? [encodeField(FIELD.CV2R_MODEL_CALL_ID, WIRE_TYPE.LEN, modelCallId)] : []),
|
|
312
|
-
encodeField(FIELD.CV2R_TOOL_INDEX, WIRE_TYPE.VARINT, toolIndex > 0 ? toolIndex : 1)
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Encode MCPParams.Tool nested inside ClientSideToolV2Call
|
|
318
|
-
*/
|
|
319
|
-
function encodeMcpParamsForCall(toolName, rawArgs, serverName) {
|
|
320
|
-
const tool = concatArrays(
|
|
321
|
-
encodeField(FIELD.MCP_TOOL_NAME, WIRE_TYPE.LEN, toolName),
|
|
322
|
-
encodeField(FIELD.MCP_TOOL_PARAMS, WIRE_TYPE.LEN, rawArgs),
|
|
323
|
-
encodeField(FIELD.MCP_TOOL_SERVER, WIRE_TYPE.LEN, serverName)
|
|
324
|
-
);
|
|
325
|
-
return encodeField(FIELD.MCP_TOOLS_LIST, WIRE_TYPE.LEN, tool);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Encode ClientSideToolV2Call proto: { tool, mcp_params, call_id, name, raw_args, tool_index, model_call_id }
|
|
330
|
-
* Represents a tool call definition
|
|
331
|
-
*/
|
|
332
|
-
function encodeClientSideToolV2Call(toolCallId, toolName, selectedTool, serverName, rawArgs, modelCallId, toolIndex = 1) {
|
|
333
|
-
return concatArrays(
|
|
334
|
-
encodeField(FIELD.CV2C_TOOL, WIRE_TYPE.VARINT, CLIENT_SIDE_TOOL_V2_MCP),
|
|
335
|
-
encodeField(FIELD.CV2C_MCP_PARAMS, WIRE_TYPE.LEN, encodeMcpParamsForCall(selectedTool, rawArgs, serverName)),
|
|
336
|
-
encodeField(FIELD.CV2C_CALL_ID, WIRE_TYPE.LEN, toolCallId),
|
|
337
|
-
encodeField(FIELD.CV2C_NAME, WIRE_TYPE.LEN, toolName),
|
|
338
|
-
encodeField(FIELD.CV2C_RAW_ARGS, WIRE_TYPE.LEN, rawArgs),
|
|
339
|
-
encodeField(FIELD.CV2C_TOOL_INDEX, WIRE_TYPE.VARINT, toolIndex > 0 ? toolIndex : 1),
|
|
340
|
-
...(modelCallId ? [encodeField(FIELD.CV2C_MODEL_CALL_ID, WIRE_TYPE.LEN, modelCallId)] : [])
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Encode ConversationMessage.ToolResult with full structure
|
|
346
|
-
* Matches Cursor proto: tool_call_id, tool_name, tool_index, raw_args, result, tool_call
|
|
347
|
-
*/
|
|
348
|
-
export function encodeToolResult(toolResult) {
|
|
349
|
-
const originalName = toolResult.tool_name || toolResult.name || "";
|
|
350
|
-
const toolName = formatToolName(originalName);
|
|
351
|
-
const rawArgs = toolResult.raw_args || "{}";
|
|
352
|
-
const resultContent = toolResult.result_content || toolResult.result || "";
|
|
353
|
-
const { toolCallId, modelCallId } = parseToolId(toolResult.tool_call_id || "");
|
|
354
|
-
const toolIndex = toolResult.tool_index || toolResult.index || 1;
|
|
355
|
-
|
|
356
|
-
// Parse tool name to extract server and selected tool
|
|
357
|
-
const { serverName, selectedTool } = parseToolName(toolName);
|
|
358
|
-
|
|
359
|
-
return concatArrays(
|
|
360
|
-
encodeField(FIELD.TOOL_RESULT_CALL_ID, WIRE_TYPE.LEN, toolCallId),
|
|
361
|
-
encodeField(FIELD.TOOL_RESULT_NAME, WIRE_TYPE.LEN, toolName),
|
|
362
|
-
encodeField(FIELD.TOOL_RESULT_INDEX, WIRE_TYPE.VARINT, toolIndex > 0 ? toolIndex : 1),
|
|
363
|
-
...(modelCallId ? [encodeField(FIELD.TOOL_RESULT_MODEL_CALL_ID, WIRE_TYPE.LEN, modelCallId)] : []),
|
|
364
|
-
encodeField(FIELD.TOOL_RESULT_RAW_ARGS, WIRE_TYPE.LEN, rawArgs),
|
|
365
|
-
encodeField(FIELD.TOOL_RESULT_RESULT, WIRE_TYPE.LEN,
|
|
366
|
-
encodeClientSideToolV2Result(toolCallId, modelCallId, selectedTool, resultContent, toolIndex)
|
|
367
|
-
),
|
|
368
|
-
encodeField(FIELD.TOOL_RESULT_TOOL_CALL, WIRE_TYPE.LEN,
|
|
369
|
-
encodeClientSideToolV2Call(toolCallId, toolName, selectedTool, serverName, rawArgs, modelCallId, toolIndex)
|
|
370
|
-
)
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export function encodeMessage(content, role, messageId, chatModeEnum = null, isLast = false, hasTools = false, toolResults = [], serverBubbleId = null) {
|
|
375
|
-
const hasToolResults = toolResults.length > 0;
|
|
376
|
-
return concatArrays(
|
|
377
|
-
encodeField(FIELD.MSG_CONTENT, WIRE_TYPE.LEN, content),
|
|
378
|
-
encodeField(FIELD.MSG_ROLE, WIRE_TYPE.VARINT, role),
|
|
379
|
-
encodeField(FIELD.MSG_ID, WIRE_TYPE.LEN, messageId),
|
|
380
|
-
// Only include server_bubble_id if explicitly provided (last assistant message only)
|
|
381
|
-
...(serverBubbleId ? [encodeField(FIELD.MSG_SERVER_BUBBLE_ID, WIRE_TYPE.LEN, serverBubbleId)] : []),
|
|
382
|
-
...(hasToolResults ? toolResults.map(tr =>
|
|
383
|
-
encodeField(FIELD.MSG_TOOL_RESULTS, WIRE_TYPE.LEN, encodeToolResult(tr))
|
|
384
|
-
) : []),
|
|
385
|
-
encodeField(FIELD.MSG_IS_AGENTIC, WIRE_TYPE.VARINT, hasTools ? 1 : 0),
|
|
386
|
-
encodeField(FIELD.MSG_UNIFIED_MODE, WIRE_TYPE.VARINT, hasTools ? UNIFIED_MODE.AGENT : UNIFIED_MODE.CHAT),
|
|
387
|
-
...(isLast && hasTools ? [encodeField(FIELD.MSG_SUPPORTED_TOOLS, WIRE_TYPE.LEN, encodeVarint(1))] : [])
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
export function encodeInstruction(text) {
|
|
392
|
-
return text ? encodeField(FIELD.INSTRUCTION_TEXT, WIRE_TYPE.LEN, text) : new Uint8Array(0);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
export function encodeModel(modelName) {
|
|
396
|
-
return concatArrays(
|
|
397
|
-
encodeField(FIELD.MODEL_NAME, WIRE_TYPE.LEN, modelName),
|
|
398
|
-
encodeField(FIELD.MODEL_EMPTY, WIRE_TYPE.LEN, new Uint8Array(0))
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export function encodeCursorSetting() {
|
|
403
|
-
const unknown6 = concatArrays(
|
|
404
|
-
encodeField(FIELD.SETTING6_FIELD_1, WIRE_TYPE.LEN, new Uint8Array(0)),
|
|
405
|
-
encodeField(FIELD.SETTING6_FIELD_2, WIRE_TYPE.LEN, new Uint8Array(0))
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
return concatArrays(
|
|
409
|
-
encodeField(FIELD.SETTING_PATH, WIRE_TYPE.LEN, "cursor\\aisettings"),
|
|
410
|
-
encodeField(FIELD.SETTING_UNKNOWN_3, WIRE_TYPE.LEN, new Uint8Array(0)),
|
|
411
|
-
encodeField(FIELD.SETTING_UNKNOWN_6, WIRE_TYPE.LEN, unknown6),
|
|
412
|
-
encodeField(FIELD.SETTING_UNKNOWN_8, WIRE_TYPE.VARINT, 1),
|
|
413
|
-
encodeField(FIELD.SETTING_UNKNOWN_9, WIRE_TYPE.VARINT, 1)
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function encodeMetadata() {
|
|
418
|
-
return concatArrays(
|
|
419
|
-
encodeField(FIELD.META_PLATFORM, WIRE_TYPE.LEN, process.platform || "linux"),
|
|
420
|
-
encodeField(FIELD.META_ARCH, WIRE_TYPE.LEN, process.arch || "x64"),
|
|
421
|
-
encodeField(FIELD.META_VERSION, WIRE_TYPE.LEN, process.version || "v20.0.0"),
|
|
422
|
-
encodeField(FIELD.META_CWD, WIRE_TYPE.LEN, process.cwd?.() || "/"),
|
|
423
|
-
encodeField(FIELD.META_TIMESTAMP, WIRE_TYPE.LEN, new Date().toISOString())
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export function encodeMessageId(messageId, role, summaryId = null) {
|
|
428
|
-
return concatArrays(
|
|
429
|
-
encodeField(FIELD.MSGID_ID, WIRE_TYPE.LEN, messageId),
|
|
430
|
-
...(summaryId ? [encodeField(FIELD.MSGID_SUMMARY, WIRE_TYPE.LEN, summaryId)] : []),
|
|
431
|
-
encodeField(FIELD.MSGID_ROLE, WIRE_TYPE.VARINT, role)
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
export function encodeMcpTool(tool) {
|
|
436
|
-
const toolName = tool.function?.name || tool.name || "";
|
|
437
|
-
const toolDesc = tool.function?.description || tool.description || "";
|
|
438
|
-
const inputSchema = tool.function?.parameters || tool.input_schema || {};
|
|
439
|
-
|
|
440
|
-
return concatArrays(
|
|
441
|
-
...(toolName ? [encodeField(FIELD.MCP_TOOL_NAME, WIRE_TYPE.LEN, toolName)] : []),
|
|
442
|
-
...(toolDesc ? [encodeField(FIELD.MCP_TOOL_DESC, WIRE_TYPE.LEN, toolDesc)] : []),
|
|
443
|
-
...(Object.keys(inputSchema).length > 0 ? [encodeField(FIELD.MCP_TOOL_PARAMS, WIRE_TYPE.LEN, JSON.stringify(inputSchema))] : []),
|
|
444
|
-
encodeField(FIELD.MCP_TOOL_SERVER, WIRE_TYPE.LEN, "custom")
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// ==================== REQUEST BUILDING ====================
|
|
449
|
-
|
|
450
|
-
export function encodeRequest(messages, modelName, tools = [], reasoningEffort = null, forceAgentMode = false) {
|
|
451
|
-
const hasTools = tools?.length > 0;
|
|
452
|
-
const isAgentic = hasTools || forceAgentMode;
|
|
453
|
-
const formattedMessages = [];
|
|
454
|
-
const messageIds = [];
|
|
455
|
-
const normalizedMessages = [];
|
|
456
|
-
|
|
457
|
-
// Guardrail: split mixed assistant payload into separate assistant messages
|
|
458
|
-
// This prevents protobuf encoding errors when tool calls and results are in same message
|
|
459
|
-
for (let i = 0; i < messages.length; i++) {
|
|
460
|
-
const msg = messages[i];
|
|
461
|
-
const hasToolCalls = Array.isArray(msg?.tool_calls) && msg.tool_calls.length > 0;
|
|
462
|
-
const hasToolResults = Array.isArray(msg?.tool_results) && msg.tool_results.length > 0;
|
|
463
|
-
|
|
464
|
-
if (msg?.role === "assistant" && hasToolCalls && hasToolResults) {
|
|
465
|
-
log(
|
|
466
|
-
"ENCODE",
|
|
467
|
-
`normalizing mixed assistant tool payload at msg[${i}] (calls=${msg.tool_calls.length}, results=${msg.tool_results.length})`
|
|
468
|
-
);
|
|
469
|
-
|
|
470
|
-
// Keep assistant tool call message without embedded results
|
|
471
|
-
normalizedMessages.push({
|
|
472
|
-
...msg,
|
|
473
|
-
tool_results: []
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
// Avoid inserting duplicate assistant tool-result message if next one already matches
|
|
477
|
-
const nextMsg = messages[i + 1];
|
|
478
|
-
const nextHasToolResults =
|
|
479
|
-
nextMsg?.role === "assistant" &&
|
|
480
|
-
Array.isArray(nextMsg?.tool_results) &&
|
|
481
|
-
nextMsg.tool_results.length > 0;
|
|
482
|
-
const currentIds = new Set(
|
|
483
|
-
msg.tool_results.map(tr => tr?.tool_call_id).filter(id => typeof id === "string")
|
|
484
|
-
);
|
|
485
|
-
const nextIds = new Set(
|
|
486
|
-
(nextMsg?.tool_results || [])
|
|
487
|
-
.map(tr => tr?.tool_call_id)
|
|
488
|
-
.filter(id => typeof id === "string")
|
|
489
|
-
);
|
|
490
|
-
let sameIds = currentIds.size > 0 && currentIds.size === nextIds.size;
|
|
491
|
-
if (sameIds) {
|
|
492
|
-
for (const id of currentIds) {
|
|
493
|
-
if (!nextIds.has(id)) {
|
|
494
|
-
sameIds = false;
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (!(nextHasToolResults && sameIds)) {
|
|
501
|
-
normalizedMessages.push({
|
|
502
|
-
role: "assistant",
|
|
503
|
-
content: "",
|
|
504
|
-
tool_results: msg.tool_results
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
continue;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
normalizedMessages.push(msg);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// Prepare messages
|
|
515
|
-
for (let i = 0; i < normalizedMessages.length; i++) {
|
|
516
|
-
const msg = normalizedMessages[i];
|
|
517
|
-
const role = msg.role === "user" ? ROLE.USER : ROLE.ASSISTANT;
|
|
518
|
-
const msgId = uuidv4();
|
|
519
|
-
const isLast = i === normalizedMessages.length - 1;
|
|
520
|
-
|
|
521
|
-
formattedMessages.push({
|
|
522
|
-
content: msg.content,
|
|
523
|
-
role,
|
|
524
|
-
messageId: msgId,
|
|
525
|
-
isLast,
|
|
526
|
-
hasTools,
|
|
527
|
-
toolResults: msg.tool_results || []
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
messageIds.push({ messageId: msgId, role });
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// Map reasoning effort to thinking level
|
|
534
|
-
let thinkingLevel = THINKING_LEVEL.UNSPECIFIED;
|
|
535
|
-
if (reasoningEffort === "medium") thinkingLevel = THINKING_LEVEL.MEDIUM;
|
|
536
|
-
else if (reasoningEffort === "high") thinkingLevel = THINKING_LEVEL.HIGH;
|
|
537
|
-
|
|
538
|
-
// Build request
|
|
539
|
-
return concatArrays(
|
|
540
|
-
// Messages
|
|
541
|
-
...formattedMessages.map(fm =>
|
|
542
|
-
encodeField(FIELD.MESSAGES, WIRE_TYPE.LEN,
|
|
543
|
-
encodeMessage(fm.content, fm.role, fm.messageId, null, fm.isLast, fm.hasTools, fm.toolResults)
|
|
544
|
-
)
|
|
545
|
-
),
|
|
546
|
-
|
|
547
|
-
// Static fields
|
|
548
|
-
encodeField(FIELD.UNKNOWN_2, WIRE_TYPE.VARINT, 1),
|
|
549
|
-
encodeField(FIELD.INSTRUCTION, WIRE_TYPE.LEN, encodeInstruction("")),
|
|
550
|
-
encodeField(FIELD.UNKNOWN_4, WIRE_TYPE.VARINT, 1),
|
|
551
|
-
encodeField(FIELD.MODEL, WIRE_TYPE.LEN, encodeModel(modelName)),
|
|
552
|
-
encodeField(FIELD.WEB_TOOL, WIRE_TYPE.LEN, ""),
|
|
553
|
-
encodeField(FIELD.UNKNOWN_13, WIRE_TYPE.VARINT, 1),
|
|
554
|
-
encodeField(FIELD.CURSOR_SETTING, WIRE_TYPE.LEN, encodeCursorSetting()),
|
|
555
|
-
encodeField(FIELD.UNKNOWN_19, WIRE_TYPE.VARINT, 1),
|
|
556
|
-
encodeField(FIELD.CONVERSATION_ID, WIRE_TYPE.LEN, uuidv4()),
|
|
557
|
-
encodeField(FIELD.METADATA, WIRE_TYPE.LEN, encodeMetadata()),
|
|
558
|
-
|
|
559
|
-
// Tool-related fields
|
|
560
|
-
encodeField(FIELD.IS_AGENTIC, WIRE_TYPE.VARINT, isAgentic ? 1 : 0),
|
|
561
|
-
...(isAgentic ? [encodeField(FIELD.SUPPORTED_TOOLS, WIRE_TYPE.LEN, encodeVarint(1))] : []),
|
|
562
|
-
|
|
563
|
-
// Message IDs
|
|
564
|
-
...messageIds.map(mid =>
|
|
565
|
-
encodeField(FIELD.MESSAGE_IDS, WIRE_TYPE.LEN, encodeMessageId(mid.messageId, mid.role))
|
|
566
|
-
),
|
|
567
|
-
|
|
568
|
-
// MCP Tools
|
|
569
|
-
...(tools?.length > 0 ? tools.map(tool =>
|
|
570
|
-
encodeField(FIELD.MCP_TOOLS, WIRE_TYPE.LEN, encodeMcpTool(tool))
|
|
571
|
-
) : []),
|
|
572
|
-
|
|
573
|
-
// Mode fields
|
|
574
|
-
encodeField(FIELD.LARGE_CONTEXT, WIRE_TYPE.VARINT, 0),
|
|
575
|
-
encodeField(FIELD.UNKNOWN_38, WIRE_TYPE.VARINT, 0),
|
|
576
|
-
encodeField(FIELD.UNIFIED_MODE, WIRE_TYPE.VARINT, isAgentic ? UNIFIED_MODE.AGENT : UNIFIED_MODE.CHAT),
|
|
577
|
-
encodeField(FIELD.UNKNOWN_47, WIRE_TYPE.LEN, ""),
|
|
578
|
-
encodeField(FIELD.SHOULD_DISABLE_TOOLS, WIRE_TYPE.VARINT, isAgentic ? 0 : 1),
|
|
579
|
-
encodeField(FIELD.THINKING_LEVEL, WIRE_TYPE.VARINT, thinkingLevel),
|
|
580
|
-
encodeField(FIELD.UNKNOWN_51, WIRE_TYPE.VARINT, 0),
|
|
581
|
-
encodeField(FIELD.UNKNOWN_53, WIRE_TYPE.VARINT, 1),
|
|
582
|
-
encodeField(FIELD.UNIFIED_MODE_NAME, WIRE_TYPE.LEN, isAgentic ? "Agent" : "Ask")
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
export function buildChatRequest(messages, modelName, tools = [], reasoningEffort = null, forceAgentMode = false) {
|
|
587
|
-
return encodeField(FIELD.REQUEST, WIRE_TYPE.LEN, encodeRequest(messages, modelName, tools, reasoningEffort, forceAgentMode));
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Encode a tool result as ClientSideToolV2Result (field 2 of StreamUnifiedChatRequestWithTools)
|
|
592
|
-
* This is sent as a SEPARATE request frame, not inside conversation messages.
|
|
593
|
-
* Proto: StreamUnifiedChatRequestWithTools.client_side_tool_v2_result = 2
|
|
594
|
-
*/
|
|
595
|
-
export function buildToolResultRequest(toolResult) {
|
|
596
|
-
const { toolCallId, modelCallId } = parseToolId(toolResult.tool_call_id || "");
|
|
597
|
-
const rawName = toolResult.tool_name || "";
|
|
598
|
-
const resultContent = toolResult.result_content || "";
|
|
599
|
-
|
|
600
|
-
// selected_tool = raw tool name (e.g. "Write", "Read") per cursor-api Rust source:
|
|
601
|
-
// McpResult { selected_tool: tool_name, result } where tool_name is the mcpParams.tools[0].name
|
|
602
|
-
// which is the name AFTER server prefix stripping (e.g. "custom_Write" -> name = "Write")
|
|
603
|
-
// Actually cursor-api uses: name = tool_name.slice_unchecked(d+1..) → raw name without "custom_"
|
|
604
|
-
// So selected_tool = raw tool name without any prefix
|
|
605
|
-
const selectedTool = rawName.startsWith("mcp_custom_")
|
|
606
|
-
? rawName.slice("mcp_custom_".length)
|
|
607
|
-
: rawName.startsWith("mcp_")
|
|
608
|
-
? rawName.slice(4)
|
|
609
|
-
: rawName;
|
|
610
|
-
|
|
611
|
-
// ClientSideToolV2Result per proto:
|
|
612
|
-
// field 1 (tool): varint = 19 (MCP)
|
|
613
|
-
// field 28 (mcp_result): LEN { field 1: selected_tool, field 2: result }
|
|
614
|
-
// field 35 (tool_call_id): string
|
|
615
|
-
// field 48 (model_call_id): string (optional)
|
|
616
|
-
// NO tool_index (None in Rust source: encode_tool_result sets tool_index: None)
|
|
617
|
-
const cv2Result = concatArrays(
|
|
618
|
-
encodeField(FIELD.CV2R_TOOL, WIRE_TYPE.VARINT, CLIENT_SIDE_TOOL_V2_MCP),
|
|
619
|
-
encodeField(FIELD.CV2R_MCP_RESULT, WIRE_TYPE.LEN, encodeMcpResult(selectedTool, resultContent)),
|
|
620
|
-
encodeField(FIELD.CV2R_CALL_ID, WIRE_TYPE.LEN, toolCallId),
|
|
621
|
-
...(modelCallId ? [encodeField(FIELD.CV2R_MODEL_CALL_ID, WIRE_TYPE.LEN, modelCallId)] : [])
|
|
622
|
-
// tool_index intentionally omitted (None per Rust source)
|
|
623
|
-
);
|
|
624
|
-
|
|
625
|
-
// StreamUnifiedChatRequestWithTools: field 2 = client_side_tool_v2_result
|
|
626
|
-
return encodeField(2, WIRE_TYPE.LEN, cv2Result);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
export function wrapConnectRPCFrame(payload, compress = false) {
|
|
630
|
-
let finalPayload = payload;
|
|
631
|
-
let flags = 0x00;
|
|
632
|
-
|
|
633
|
-
if (compress) {
|
|
634
|
-
finalPayload = new Uint8Array(zlib.gzipSync(Buffer.from(payload)));
|
|
635
|
-
flags = 0x01;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const frame = new Uint8Array(5 + finalPayload.length);
|
|
639
|
-
frame[0] = flags;
|
|
640
|
-
frame[1] = (finalPayload.length >> 24) & 0xFF;
|
|
641
|
-
frame[2] = (finalPayload.length >> 16) & 0xFF;
|
|
642
|
-
frame[3] = (finalPayload.length >> 8) & 0xFF;
|
|
643
|
-
frame[4] = finalPayload.length & 0xFF;
|
|
644
|
-
frame.set(finalPayload, 5);
|
|
645
|
-
|
|
646
|
-
return frame;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
export function generateCursorBody(messages, modelName, tools = [], reasoningEffort = null, forceAgentMode = false) {
|
|
650
|
-
log("BODY", `Generating: ${messages.length} msgs, model=${modelName}, tools=${tools.length}, reasoning=${reasoningEffort || "none"}, forceAgentMode=${forceAgentMode}`);
|
|
651
|
-
|
|
652
|
-
const protobuf = buildChatRequest(messages, modelName, tools, reasoningEffort, forceAgentMode);
|
|
653
|
-
const framed = wrapConnectRPCFrame(protobuf, false); // Cursor doesn't support compressed requests
|
|
654
|
-
|
|
655
|
-
log("BODY", `Protobuf=${protobuf.length}B, Framed=${framed.length}B`);
|
|
656
|
-
return framed;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Generate a framed tool result body to send as a separate request frame.
|
|
661
|
-
* Uses field 2 (client_side_tool_v2_result) of StreamUnifiedChatRequestWithTools.
|
|
662
|
-
*/
|
|
663
|
-
export function generateToolResultBody(toolResult) {
|
|
664
|
-
const protobuf = buildToolResultRequest(toolResult);
|
|
665
|
-
return wrapConnectRPCFrame(protobuf, false);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// ==================== PRIMITIVE DECODING ====================
|
|
669
|
-
|
|
670
|
-
export function decodeVarint(buffer, offset) {
|
|
671
|
-
let result = 0;
|
|
672
|
-
let shift = 0;
|
|
673
|
-
let pos = offset;
|
|
674
|
-
|
|
675
|
-
while (pos < buffer.length) {
|
|
676
|
-
const b = buffer[pos];
|
|
677
|
-
result |= (b & 0x7F) << shift;
|
|
678
|
-
pos++;
|
|
679
|
-
if (!(b & 0x80)) break;
|
|
680
|
-
shift += 7;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
return [result, pos];
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
export function decodeField(buffer, offset) {
|
|
687
|
-
if (offset >= buffer.length) return [null, null, null, offset];
|
|
688
|
-
|
|
689
|
-
const [tag, pos1] = decodeVarint(buffer, offset);
|
|
690
|
-
const fieldNum = tag >> 3;
|
|
691
|
-
const wireType = tag & 0x07;
|
|
692
|
-
|
|
693
|
-
let value;
|
|
694
|
-
let pos = pos1;
|
|
695
|
-
|
|
696
|
-
if (wireType === WIRE_TYPE.VARINT) {
|
|
697
|
-
[value, pos] = decodeVarint(buffer, pos);
|
|
698
|
-
} else if (wireType === WIRE_TYPE.LEN) {
|
|
699
|
-
const [length, pos2] = decodeVarint(buffer, pos);
|
|
700
|
-
value = buffer.slice(pos2, pos2 + length);
|
|
701
|
-
pos = pos2 + length;
|
|
702
|
-
} else if (wireType === WIRE_TYPE.FIXED64) {
|
|
703
|
-
value = buffer.slice(pos, pos + 8);
|
|
704
|
-
pos += 8;
|
|
705
|
-
} else if (wireType === WIRE_TYPE.FIXED32) {
|
|
706
|
-
value = buffer.slice(pos, pos + 4);
|
|
707
|
-
pos += 4;
|
|
708
|
-
} else {
|
|
709
|
-
value = null;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return [fieldNum, wireType, value, pos];
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
export function decodeMessage(data) {
|
|
716
|
-
const fields = new Map();
|
|
717
|
-
let pos = 0;
|
|
718
|
-
|
|
719
|
-
while (pos < data.length) {
|
|
720
|
-
const [fieldNum, wireType, value, newPos] = decodeField(data, pos);
|
|
721
|
-
if (fieldNum === null) break;
|
|
722
|
-
|
|
723
|
-
if (!fields.has(fieldNum)) fields.set(fieldNum, []);
|
|
724
|
-
fields.get(fieldNum).push({ wireType, value });
|
|
725
|
-
pos = newPos;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
return fields;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// ==================== RESPONSE PARSING ====================
|
|
732
|
-
|
|
733
|
-
export function parseConnectRPCFrame(buffer) {
|
|
734
|
-
if (buffer.length < 5) return null;
|
|
735
|
-
|
|
736
|
-
const flags = buffer[0];
|
|
737
|
-
const length = (buffer[1] << 24) | (buffer[2] << 16) | (buffer[3] << 8) | buffer[4];
|
|
738
|
-
|
|
739
|
-
if (buffer.length < 5 + length) return null;
|
|
740
|
-
|
|
741
|
-
let payload = buffer.slice(5, 5 + length);
|
|
742
|
-
|
|
743
|
-
// Decompress if gzip
|
|
744
|
-
if (flags === 0x01) {
|
|
745
|
-
try {
|
|
746
|
-
payload = new Uint8Array(zlib.gunzipSync(Buffer.from(payload)));
|
|
747
|
-
} catch (err) {
|
|
748
|
-
log("PARSE", `Decompression failed: ${err.message}`);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
return { flags, length, payload, consumed: 5 + length };
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
function extractToolCall(toolCallData) {
|
|
756
|
-
const toolCall = decodeMessage(toolCallData);
|
|
757
|
-
let toolCallId = "";
|
|
758
|
-
let toolName = "";
|
|
759
|
-
let rawArgs = "";
|
|
760
|
-
let isLast = false;
|
|
761
|
-
|
|
762
|
-
// Extract tool call ID
|
|
763
|
-
if (toolCall.has(FIELD.TOOL_ID)) {
|
|
764
|
-
const fullId = new TextDecoder().decode(toolCall.get(FIELD.TOOL_ID)[0].value);
|
|
765
|
-
toolCallId = fullId.split("\n")[0]; // Cursor returns multi-line ID, take first line
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// Extract tool name
|
|
769
|
-
if (toolCall.has(FIELD.TOOL_NAME)) {
|
|
770
|
-
toolName = new TextDecoder().decode(toolCall.get(FIELD.TOOL_NAME)[0].value);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
// Extract is_last flag
|
|
774
|
-
if (toolCall.has(FIELD.TOOL_IS_LAST)) {
|
|
775
|
-
isLast = toolCall.get(FIELD.TOOL_IS_LAST)[0].value !== 0;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// Extract MCP params - nested real tool info
|
|
779
|
-
if (toolCall.has(FIELD.TOOL_MCP_PARAMS)) {
|
|
780
|
-
try {
|
|
781
|
-
const mcpParams = decodeMessage(toolCall.get(FIELD.TOOL_MCP_PARAMS)[0].value);
|
|
782
|
-
|
|
783
|
-
if (mcpParams.has(FIELD.MCP_TOOLS_LIST)) {
|
|
784
|
-
const tool = decodeMessage(mcpParams.get(FIELD.MCP_TOOLS_LIST)[0].value);
|
|
785
|
-
|
|
786
|
-
if (tool.has(FIELD.MCP_NESTED_NAME)) {
|
|
787
|
-
toolName = new TextDecoder().decode(tool.get(FIELD.MCP_NESTED_NAME)[0].value);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
if (tool.has(FIELD.MCP_NESTED_PARAMS)) {
|
|
791
|
-
rawArgs = new TextDecoder().decode(tool.get(FIELD.MCP_NESTED_PARAMS)[0].value);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
} catch (err) {
|
|
795
|
-
log("EXTRACT", `MCP parse error: ${err.message}`);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// Fallback to raw_args
|
|
800
|
-
if (!rawArgs && toolCall.has(FIELD.TOOL_RAW_ARGS)) {
|
|
801
|
-
rawArgs = new TextDecoder().decode(toolCall.get(FIELD.TOOL_RAW_ARGS)[0].value);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
if (toolCallId && toolName) {
|
|
805
|
-
return {
|
|
806
|
-
id: toolCallId,
|
|
807
|
-
type: "function",
|
|
808
|
-
function: {
|
|
809
|
-
name: toolName,
|
|
810
|
-
arguments: rawArgs || "{}"
|
|
811
|
-
},
|
|
812
|
-
isLast
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
return null;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
function extractTextAndThinking(responseData) {
|
|
820
|
-
const nested = decodeMessage(responseData);
|
|
821
|
-
let text = null;
|
|
822
|
-
let thinking = null;
|
|
823
|
-
|
|
824
|
-
// Extract text
|
|
825
|
-
if (nested.has(FIELD.RESPONSE_TEXT)) {
|
|
826
|
-
text = new TextDecoder().decode(nested.get(FIELD.RESPONSE_TEXT)[0].value);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// Extract thinking
|
|
830
|
-
if (nested.has(FIELD.THINKING)) {
|
|
831
|
-
try {
|
|
832
|
-
const thinkingMsg = decodeMessage(nested.get(FIELD.THINKING)[0].value);
|
|
833
|
-
if (thinkingMsg.has(FIELD.THINKING_TEXT)) {
|
|
834
|
-
thinking = new TextDecoder().decode(thinkingMsg.get(FIELD.THINKING_TEXT)[0].value);
|
|
835
|
-
}
|
|
836
|
-
} catch (err) {
|
|
837
|
-
log("EXTRACT", `Thinking parse error: ${err.message}`);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
return { text, thinking };
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
export function extractTextFromResponse(payload) {
|
|
845
|
-
try {
|
|
846
|
-
const fields = decodeMessage(payload);
|
|
847
|
-
|
|
848
|
-
// Warn about unknown field numbers — may indicate a Cursor protocol update
|
|
849
|
-
for (const fieldNum of fields.keys()) {
|
|
850
|
-
if (!KNOWN_RESPONSE_FIELDS.has(fieldNum)) {
|
|
851
|
-
log(
|
|
852
|
-
"SCHEMA",
|
|
853
|
-
`Unknown response field #${fieldNum} detected. Schema v${PROTOBUF_SCHEMA_VERSION} may be outdated.`
|
|
854
|
-
);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// Field 1: ClientSideToolV2Call
|
|
859
|
-
if (fields.has(FIELD.TOOL_CALL)) {
|
|
860
|
-
const toolCall = extractToolCall(fields.get(FIELD.TOOL_CALL)[0].value);
|
|
861
|
-
if (toolCall) {
|
|
862
|
-
log("EXTRACT", `Tool call: ${toolCall.function.name}`);
|
|
863
|
-
return { text: null, error: null, toolCall, thinking: null };
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
// Field 2: StreamUnifiedChatResponse
|
|
868
|
-
if (fields.has(FIELD.RESPONSE)) {
|
|
869
|
-
const { text, thinking } = extractTextAndThinking(fields.get(FIELD.RESPONSE)[0].value);
|
|
870
|
-
|
|
871
|
-
if (text || thinking) {
|
|
872
|
-
return { text, error: null, toolCall: null, thinking };
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
return { text: null, error: null, toolCall: null, thinking: null };
|
|
877
|
-
} catch (err) {
|
|
878
|
-
log("EXTRACT", `Decode failed (schema v${PROTOBUF_SCHEMA_VERSION}): ${err.message}`);
|
|
879
|
-
return {
|
|
880
|
-
text: null,
|
|
881
|
-
error: null,
|
|
882
|
-
toolCall: null,
|
|
883
|
-
thinking: null,
|
|
884
|
-
raw: Buffer.from(payload).toString("base64"),
|
|
885
|
-
decodeError: err.message
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
// ==================== EXPORTS ====================
|
|
891
|
-
|
|
892
|
-
export default {
|
|
893
|
-
encodeVarint,
|
|
894
|
-
encodeField,
|
|
895
|
-
encodeMessage,
|
|
896
|
-
buildChatRequest,
|
|
897
|
-
wrapConnectRPCFrame,
|
|
898
|
-
generateCursorBody,
|
|
899
|
-
decodeVarint,
|
|
900
|
-
decodeField,
|
|
901
|
-
decodeMessage,
|
|
902
|
-
parseConnectRPCFrame,
|
|
903
|
-
extractTextFromResponse
|
|
904
|
-
};
|