wyxrouter 0.4.71
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/CHANGELOG.md +222 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/README.zh-CN.md +1311 -0
- package/assets/pixel-router-2d.png +0 -0
- package/cli/LICENSE +42 -0
- package/cli/README.md +125 -0
- package/cli/app/package.json +58 -0
- package/cli/cli.js +806 -0
- package/cli/package.json +48 -0
- package/i18n/README.ja-JP.md +1209 -0
- package/i18n/README.ru.md +1311 -0
- package/i18n/README.vi.md +1310 -0
- package/i18n/README.zh-CN.md +1306 -0
- package/images/9router.png +0 -0
- package/jsconfig.json +12 -0
- package/next.config.mjs +71 -0
- package/open-sse/config/appConstants.js +203 -0
- package/open-sse/config/codexInstructions.js +119 -0
- package/open-sse/config/constants.js +4 -0
- package/open-sse/config/defaultThinkingSignature.js +12 -0
- package/open-sse/config/errorConfig.js +85 -0
- package/open-sse/config/googleTtsLanguages.js +62 -0
- package/open-sse/config/kiroConstants.js +322 -0
- package/open-sse/config/models.js +13 -0
- package/open-sse/config/ollamaModels.js +19 -0
- package/open-sse/config/providerModels.js +944 -0
- package/open-sse/config/providers.js +458 -0
- package/open-sse/config/runtimeConfig.js +72 -0
- package/open-sse/config/ttsModels.js +129 -0
- package/open-sse/executors/antigravity.js +504 -0
- package/open-sse/executors/azure.js +57 -0
- package/open-sse/executors/base.js +185 -0
- package/open-sse/executors/codex.js +469 -0
- package/open-sse/executors/commandcode.js +88 -0
- package/open-sse/executors/cursor.js +795 -0
- package/open-sse/executors/default.js +497 -0
- package/open-sse/executors/gemini-cli.js +89 -0
- package/open-sse/executors/github.js +379 -0
- package/open-sse/executors/grok-web.js +345 -0
- package/open-sse/executors/iflow.js +108 -0
- package/open-sse/executors/index.js +75 -0
- package/open-sse/executors/kiro.js +508 -0
- package/open-sse/executors/ollama-local.js +14 -0
- package/open-sse/executors/opencode-go.js +41 -0
- package/open-sse/executors/opencode.js +32 -0
- package/open-sse/executors/perplexity-web.js +507 -0
- package/open-sse/executors/qoder.js +450 -0
- package/open-sse/executors/qwen.js +129 -0
- package/open-sse/executors/vertex.js +131 -0
- package/open-sse/executors/xiaomi-tokenplan.js +19 -0
- package/open-sse/handlers/chatCore/nonStreamingHandler.js +230 -0
- package/open-sse/handlers/chatCore/requestDetail.js +102 -0
- package/open-sse/handlers/chatCore/sseToJsonHandler.js +231 -0
- package/open-sse/handlers/chatCore/streamingHandler.js +103 -0
- package/open-sse/handlers/chatCore.js +287 -0
- package/open-sse/handlers/embeddingProviders/_base.js +4 -0
- package/open-sse/handlers/embeddingProviders/gemini.js +54 -0
- package/open-sse/handlers/embeddingProviders/index.js +23 -0
- package/open-sse/handlers/embeddingProviders/openai.js +39 -0
- package/open-sse/handlers/embeddingProviders/openaiCompatNode.js +13 -0
- package/open-sse/handlers/embeddingsCore.js +126 -0
- package/open-sse/handlers/fetch/index.js +237 -0
- package/open-sse/handlers/imageGenerationCore.js +189 -0
- package/open-sse/handlers/imageProviders/_base.js +31 -0
- package/open-sse/handlers/imageProviders/blackForestLabs.js +43 -0
- package/open-sse/handlers/imageProviders/cloudflareAi.js +178 -0
- package/open-sse/handlers/imageProviders/codex.js +198 -0
- package/open-sse/handlers/imageProviders/comfyui.js +8 -0
- package/open-sse/handlers/imageProviders/falAi.js +41 -0
- package/open-sse/handlers/imageProviders/gemini.js +25 -0
- package/open-sse/handlers/imageProviders/huggingface.js +22 -0
- package/open-sse/handlers/imageProviders/index.js +40 -0
- package/open-sse/handlers/imageProviders/nanobanana.js +58 -0
- package/open-sse/handlers/imageProviders/openai.js +40 -0
- package/open-sse/handlers/imageProviders/runwayml.js +47 -0
- package/open-sse/handlers/imageProviders/sdwebui.js +17 -0
- package/open-sse/handlers/imageProviders/stabilityAi.js +34 -0
- package/open-sse/handlers/responsesHandler.js +103 -0
- package/open-sse/handlers/search/callers.js +371 -0
- package/open-sse/handlers/search/chatSearch.js +409 -0
- package/open-sse/handlers/search/index.js +201 -0
- package/open-sse/handlers/search/normalizers.js +223 -0
- package/open-sse/handlers/sttCore.js +194 -0
- package/open-sse/handlers/ttsCore.js +74 -0
- package/open-sse/handlers/ttsProviders/_base.js +39 -0
- package/open-sse/handlers/ttsProviders/edgeTts.js +89 -0
- package/open-sse/handlers/ttsProviders/elevenlabs.js +48 -0
- package/open-sse/handlers/ttsProviders/gemini.js +117 -0
- package/open-sse/handlers/ttsProviders/genericFormats.js +169 -0
- package/open-sse/handlers/ttsProviders/googleTts.js +54 -0
- package/open-sse/handlers/ttsProviders/index.js +50 -0
- package/open-sse/handlers/ttsProviders/localDevice.js +87 -0
- package/open-sse/handlers/ttsProviders/minimax.js +59 -0
- package/open-sse/handlers/ttsProviders/openai.js +30 -0
- package/open-sse/handlers/ttsProviders/openrouter.js +70 -0
- package/open-sse/index.js +82 -0
- package/open-sse/rtk/applyFilter.js +15 -0
- package/open-sse/rtk/autodetect.js +111 -0
- package/open-sse/rtk/caveman.js +100 -0
- package/open-sse/rtk/cavemanPrompts.js +78 -0
- package/open-sse/rtk/constants.js +55 -0
- package/open-sse/rtk/filters/buildOutput.js +127 -0
- package/open-sse/rtk/filters/dedupLog.js +44 -0
- package/open-sse/rtk/filters/find.js +49 -0
- package/open-sse/rtk/filters/gitDiff.js +92 -0
- package/open-sse/rtk/filters/gitStatus.js +117 -0
- package/open-sse/rtk/filters/grep.js +48 -0
- package/open-sse/rtk/filters/ls.js +79 -0
- package/open-sse/rtk/filters/readNumbered.js +27 -0
- package/open-sse/rtk/filters/searchList.js +52 -0
- package/open-sse/rtk/filters/smartTruncate.js +15 -0
- package/open-sse/rtk/filters/tree.js +32 -0
- package/open-sse/rtk/index.js +155 -0
- package/open-sse/rtk/registry.js +38 -0
- package/open-sse/services/accountFallback.js +238 -0
- package/open-sse/services/combo.js +198 -0
- package/open-sse/services/compact.js +71 -0
- package/open-sse/services/kiroModels.js +332 -0
- package/open-sse/services/model.js +261 -0
- package/open-sse/services/oauthCredentialManager.js +151 -0
- package/open-sse/services/projectId.js +306 -0
- package/open-sse/services/provider.js +356 -0
- package/open-sse/services/qoderModels.js +214 -0
- package/open-sse/services/tokenRefresh.js +939 -0
- package/open-sse/services/usage.js +1496 -0
- package/open-sse/transformer/responsesTransformer.js +439 -0
- package/open-sse/transformer/streamToJsonConverter.js +103 -0
- package/open-sse/translator/formats.js +36 -0
- package/open-sse/translator/helpers/claudeHelper.js +216 -0
- package/open-sse/translator/helpers/geminiHelper.js +372 -0
- package/open-sse/translator/helpers/imageHelper.js +34 -0
- package/open-sse/translator/helpers/maxTokensHelper.js +27 -0
- package/open-sse/translator/helpers/openaiHelper.js +130 -0
- package/open-sse/translator/helpers/responsesApiHelper.js +139 -0
- package/open-sse/translator/helpers/toolCallHelper.js +148 -0
- package/open-sse/translator/index.js +251 -0
- package/open-sse/translator/request/antigravity-to-openai.js +229 -0
- package/open-sse/translator/request/claude-to-openai.js +232 -0
- package/open-sse/translator/request/gemini-to-openai.js +147 -0
- package/open-sse/translator/request/openai-responses.js +318 -0
- package/open-sse/translator/request/openai-to-claude.js +401 -0
- package/open-sse/translator/request/openai-to-commandcode.js +170 -0
- package/open-sse/translator/request/openai-to-cursor.js +183 -0
- package/open-sse/translator/request/openai-to-gemini.js +470 -0
- package/open-sse/translator/request/openai-to-kiro.js +629 -0
- package/open-sse/translator/request/openai-to-kiro.old.js +278 -0
- package/open-sse/translator/request/openai-to-ollama.js +192 -0
- package/open-sse/translator/request/openai-to-vertex.js +42 -0
- package/open-sse/translator/response/claude-to-openai.js +206 -0
- package/open-sse/translator/response/commandcode-to-openai.js +197 -0
- package/open-sse/translator/response/cursor-to-openai.js +30 -0
- package/open-sse/translator/response/gemini-to-openai.js +245 -0
- package/open-sse/translator/response/kiro-to-openai.js +195 -0
- package/open-sse/translator/response/ollama-to-openai.js +152 -0
- package/open-sse/translator/response/openai-responses.js +590 -0
- package/open-sse/translator/response/openai-to-antigravity.js +122 -0
- package/open-sse/translator/response/openai-to-claude.js +266 -0
- package/open-sse/utils/bypassHandler.js +298 -0
- package/open-sse/utils/claudeCloaking.js +155 -0
- package/open-sse/utils/claudeHeaderCache.js +70 -0
- package/open-sse/utils/clientDetector.js +63 -0
- package/open-sse/utils/cursorChecksum.js +149 -0
- package/open-sse/utils/cursorProtobuf.js +904 -0
- package/open-sse/utils/debugLog.js +14 -0
- package/open-sse/utils/error.js +147 -0
- package/open-sse/utils/ollamaTransform.js +85 -0
- package/open-sse/utils/proxyFetch.js +368 -0
- package/open-sse/utils/reasoningContentInjector.js +79 -0
- package/open-sse/utils/requestLogger.js +260 -0
- package/open-sse/utils/responsesStreamHelpers.js +49 -0
- package/open-sse/utils/sessionManager.js +82 -0
- package/open-sse/utils/stream.js +462 -0
- package/open-sse/utils/streamHandler.js +250 -0
- package/open-sse/utils/streamHelpers.js +122 -0
- package/open-sse/utils/toolDeduper.js +49 -0
- package/open-sse/utils/usageTracking.js +347 -0
- package/package.json +100 -0
- package/postcss.config.mjs +12 -0
- package/public/favicon.svg +11 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/i18n/literals/ar.json +195 -0
- package/public/i18n/literals/bn.json +195 -0
- package/public/i18n/literals/cs.json +195 -0
- package/public/i18n/literals/da.json +195 -0
- package/public/i18n/literals/de.json +195 -0
- package/public/i18n/literals/el.json +195 -0
- package/public/i18n/literals/es.json +195 -0
- package/public/i18n/literals/fi.json +195 -0
- package/public/i18n/literals/fr.json +195 -0
- package/public/i18n/literals/he.json +195 -0
- package/public/i18n/literals/hi.json +195 -0
- package/public/i18n/literals/hu.json +195 -0
- package/public/i18n/literals/id.json +195 -0
- package/public/i18n/literals/it.json +195 -0
- package/public/i18n/literals/ja.json +195 -0
- package/public/i18n/literals/ko.json +195 -0
- package/public/i18n/literals/nl.json +195 -0
- package/public/i18n/literals/no.json +195 -0
- package/public/i18n/literals/pl.json +195 -0
- package/public/i18n/literals/pt-BR.json +195 -0
- package/public/i18n/literals/pt-PT.json +195 -0
- package/public/i18n/literals/ro.json +195 -0
- package/public/i18n/literals/ru.json +195 -0
- package/public/i18n/literals/sv.json +195 -0
- package/public/i18n/literals/th.json +195 -0
- package/public/i18n/literals/tl.json +195 -0
- package/public/i18n/literals/tr.json +195 -0
- package/public/i18n/literals/uk.json +195 -0
- package/public/i18n/literals/ur.json +195 -0
- package/public/i18n/literals/vi.json +195 -0
- package/public/i18n/literals/zh-CN.json +772 -0
- package/public/i18n/literals/zh-TW.json +195 -0
- package/public/icons/discord.svg +4 -0
- package/public/icons/icon-192.svg +4 -0
- package/public/icons/icon-512.svg +4 -0
- package/public/next.svg +1 -0
- package/public/providers/alicode-intl.png +0 -0
- package/public/providers/alicode.png +0 -0
- package/public/providers/amp.png +0 -0
- package/public/providers/anthropic-m.png +0 -0
- package/public/providers/anthropic.png +0 -0
- package/public/providers/antigravity.png +0 -0
- package/public/providers/assemblyai.png +0 -0
- package/public/providers/aws-polly.png +0 -0
- package/public/providers/azure.png +0 -0
- package/public/providers/black-forest-labs.png +0 -0
- package/public/providers/blackbox.png +0 -0
- package/public/providers/brave-search.png +0 -0
- package/public/providers/byteplus.png +0 -0
- package/public/providers/cartesia.png +0 -0
- package/public/providers/cerebras.png +0 -0
- package/public/providers/chutes.png +0 -0
- package/public/providers/claude.png +0 -0
- package/public/providers/cline.png +0 -0
- package/public/providers/cloudflare-ai.png +0 -0
- package/public/providers/codebuddy.svg +37 -0
- package/public/providers/codex.png +0 -0
- package/public/providers/cohere.png +0 -0
- package/public/providers/comfyui.png +0 -0
- package/public/providers/commandcode.png +0 -0
- package/public/providers/continue.png +0 -0
- package/public/providers/copilot.png +0 -0
- package/public/providers/coqui.png +0 -0
- package/public/providers/cursor.png +0 -0
- package/public/providers/deepgram.png +0 -0
- package/public/providers/deepseek-tui.png +0 -0
- package/public/providers/deepseek.png +0 -0
- package/public/providers/droid.png +0 -0
- package/public/providers/edge-tts.png +0 -0
- package/public/providers/elevenlabs.png +0 -0
- package/public/providers/exa.png +0 -0
- package/public/providers/fal-ai.png +0 -0
- package/public/providers/firecrawl.png +0 -0
- package/public/providers/fireworks.png +0 -0
- package/public/providers/gemini-cli.png +0 -0
- package/public/providers/gemini.png +0 -0
- package/public/providers/github.png +0 -0
- package/public/providers/glm-cn.png +0 -0
- package/public/providers/glm.png +0 -0
- package/public/providers/google-pse.png +0 -0
- package/public/providers/google-tts.png +0 -0
- package/public/providers/grok-web.png +0 -0
- package/public/providers/groq.png +0 -0
- package/public/providers/hermes.png +0 -0
- package/public/providers/huggingface.png +0 -0
- package/public/providers/hyperbolic.png +0 -0
- package/public/providers/iflow.png +0 -0
- package/public/providers/inworld.png +0 -0
- package/public/providers/jcode.png +0 -0
- package/public/providers/jina-ai.png +0 -0
- package/public/providers/jina-reader.png +0 -0
- package/public/providers/kilocode.png +0 -0
- package/public/providers/kimi-coding.png +0 -0
- package/public/providers/kimi.png +0 -0
- package/public/providers/kiro.png +0 -0
- package/public/providers/linkup.png +0 -0
- package/public/providers/local-device.png +0 -0
- package/public/providers/minimax-cn.png +0 -0
- package/public/providers/minimax.png +0 -0
- package/public/providers/mistral.png +0 -0
- package/public/providers/nanobanana.png +0 -0
- package/public/providers/nebius.png +0 -0
- package/public/providers/nvidia.png +0 -0
- package/public/providers/oai-cc.png +0 -0
- package/public/providers/oai-r.png +0 -0
- package/public/providers/ollama-local.png +0 -0
- package/public/providers/ollama.png +0 -0
- package/public/providers/openai.png +0 -0
- package/public/providers/openclaw.png +0 -0
- package/public/providers/opencode-go.png +0 -0
- package/public/providers/opencode.png +0 -0
- package/public/providers/openrouter.png +0 -0
- package/public/providers/perplexity-web.png +0 -0
- package/public/providers/perplexity.png +0 -0
- package/public/providers/playht.png +0 -0
- package/public/providers/qoder.png +0 -0
- package/public/providers/qwen.png +0 -0
- package/public/providers/recraft.png +0 -0
- package/public/providers/roo.png +0 -0
- package/public/providers/runwayml.png +0 -0
- package/public/providers/sdwebui.png +0 -0
- package/public/providers/searchapi.png +0 -0
- package/public/providers/searxng.png +0 -0
- package/public/providers/serper.png +0 -0
- package/public/providers/siliconflow.png +0 -0
- package/public/providers/stability-ai.png +0 -0
- package/public/providers/tavily.png +0 -0
- package/public/providers/together.png +0 -0
- package/public/providers/topaz.png +0 -0
- package/public/providers/tortoise.png +0 -0
- package/public/providers/vertex-partner.png +0 -0
- package/public/providers/vertex.png +0 -0
- package/public/providers/volcengine-ark.png +0 -0
- package/public/providers/voyage-ai.png +0 -0
- package/public/providers/xai.png +0 -0
- package/public/providers/xiaomi-mimo.png +0 -0
- package/public/providers/xiaomi-tokenplan.png +0 -0
- package/public/providers/youcom.png +0 -0
- package/public/sw.js +22 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/scripts/compact-request-details.mjs +71 -0
- package/scripts/import-codex-gptjson.mjs +342 -0
- package/scripts/start-standalone.mjs +25 -0
- package/scripts/translate-readme.js +201 -0
- package/src/app/(dashboard)/dashboard/automation/page.js +294 -0
- package/src/app/(dashboard)/dashboard/basic-chat/BasicChatPageClient.js +967 -0
- package/src/app/(dashboard)/dashboard/basic-chat/page.js +5 -0
- package/src/app/(dashboard)/dashboard/cli-tools/CLIToolsPageClient.js +66 -0
- package/src/app/(dashboard)/dashboard/cli-tools/[toolId]/ToolDetailClient.js +173 -0
- package/src/app/(dashboard)/dashboard/cli-tools/[toolId]/page.js +11 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/AntigravityToolCard.js +481 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ApiKeySelect.js +66 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/BaseUrlSelect.js +174 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ClaudeToolCard.js +390 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ClineToolCard.js +301 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CodexToolCard.js +458 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CopilotToolCard.js +323 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/CoworkToolCard.js +640 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DeepSeekTuiToolCard.js +338 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DefaultToolCard.js +271 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/DroidToolCard.js +410 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/EndpointPresetControl.js +128 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/HermesToolCard.js +317 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/JcodeToolCard.js +380 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/KiloToolCard.js +275 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmLinkCard.js +40 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmServerCard.js +329 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/MitmToolCard.js +318 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/OpenClawToolCard.js +388 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/OpenCodeToolCard.js +500 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/ToolSummaryCard.js +39 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/cliEndpointMatch.js +13 -0
- package/src/app/(dashboard)/dashboard/cli-tools/components/index.js +19 -0
- package/src/app/(dashboard)/dashboard/cli-tools/page.js +7 -0
- package/src/app/(dashboard)/dashboard/combos/page.js +612 -0
- package/src/app/(dashboard)/dashboard/console-log/ConsoleLogClient.js +91 -0
- package/src/app/(dashboard)/dashboard/console-log/page.js +8 -0
- package/src/app/(dashboard)/dashboard/endpoint/EndpointPageClient.js +1555 -0
- package/src/app/(dashboard)/dashboard/endpoint/page.js +7 -0
- package/src/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page.js +1903 -0
- package/src/app/(dashboard)/dashboard/media-providers/[kind]/page.js +289 -0
- package/src/app/(dashboard)/dashboard/media-providers/combo/[id]/page.js +410 -0
- package/src/app/(dashboard)/dashboard/media-providers/web/page.js +209 -0
- package/src/app/(dashboard)/dashboard/mitm/MitmPageClient.js +117 -0
- package/src/app/(dashboard)/dashboard/mitm/page.js +5 -0
- package/src/app/(dashboard)/dashboard/page.js +7 -0
- package/src/app/(dashboard)/dashboard/profile/page.js +1140 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/AddApiKeyModal.js +389 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/AddCustomModelModal.js +125 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/CompatibleModelsSection.js +250 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/ConnectionRow.js +299 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/CooldownTimer.js +42 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/EditCompatibleNodeModal.js +161 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/ModelRow.js +95 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/PassthroughModelsSection.js +183 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/page.js +2053 -0
- package/src/app/(dashboard)/dashboard/providers/[id]/page.new.js +1724 -0
- package/src/app/(dashboard)/dashboard/providers/components/ConnectionsCard.js +497 -0
- package/src/app/(dashboard)/dashboard/providers/components/ModelAvailabilityBadge.js +185 -0
- package/src/app/(dashboard)/dashboard/providers/components/ModelsCard.js +294 -0
- package/src/app/(dashboard)/dashboard/providers/new/page.js +220 -0
- package/src/app/(dashboard)/dashboard/providers/page.js +1365 -0
- package/src/app/(dashboard)/dashboard/proxy-pools/page.js +1092 -0
- package/src/app/(dashboard)/dashboard/quota/page.js +11 -0
- package/src/app/(dashboard)/dashboard/skills/page.js +112 -0
- package/src/app/(dashboard)/dashboard/translator/page.js +303 -0
- package/src/app/(dashboard)/dashboard/usage/components/OverviewCards.js +35 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/ProviderLimitCard.js +185 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/QuotaProgressBar.js +127 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/QuotaTable.js +259 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js +1394 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.js +244 -0
- package/src/app/(dashboard)/dashboard/usage/components/ProviderTopology.js +327 -0
- package/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js +433 -0
- package/src/app/(dashboard)/dashboard/usage/components/UsageChart.js +141 -0
- package/src/app/(dashboard)/dashboard/usage/components/UsageTable.js +247 -0
- package/src/app/(dashboard)/dashboard/usage/page.js +75 -0
- package/src/app/(dashboard)/layout.js +6 -0
- package/src/app/api/auth/login/route.js +76 -0
- package/src/app/api/auth/logout/route.js +12 -0
- package/src/app/api/auth/oidc/callback/route.js +87 -0
- package/src/app/api/auth/oidc/start/route.js +52 -0
- package/src/app/api/auth/oidc/test/route.js +84 -0
- package/src/app/api/auth/status/route.js +45 -0
- package/src/app/api/cli-tools/all-statuses/route.js +46 -0
- package/src/app/api/cli-tools/antigravity-mitm/alias/route.js +53 -0
- package/src/app/api/cli-tools/antigravity-mitm/route.js +202 -0
- package/src/app/api/cli-tools/claude-settings/route.js +203 -0
- package/src/app/api/cli-tools/cline-settings/route.js +133 -0
- package/src/app/api/cli-tools/codex-gateway/accounts/route.js +16 -0
- package/src/app/api/cli-tools/codex-settings/route.js +239 -0
- package/src/app/api/cli-tools/copilot-settings/route.js +148 -0
- package/src/app/api/cli-tools/cowork-mcp-registry/route.js +77 -0
- package/src/app/api/cli-tools/cowork-mcp-tools/route.js +95 -0
- package/src/app/api/cli-tools/cowork-settings/route.js +412 -0
- package/src/app/api/cli-tools/deepseek-tui-settings/route.js +164 -0
- package/src/app/api/cli-tools/droid-settings/route.js +213 -0
- package/src/app/api/cli-tools/hermes-settings/route.js +175 -0
- package/src/app/api/cli-tools/jcode-settings/route.js +216 -0
- package/src/app/api/cli-tools/kilo-settings/route.js +131 -0
- package/src/app/api/cli-tools/openclaw-settings/route.js +292 -0
- package/src/app/api/cli-tools/opencode-settings/route.js +259 -0
- package/src/app/api/combos/[id]/route.js +81 -0
- package/src/app/api/combos/route.js +48 -0
- package/src/app/api/health/route.js +15 -0
- package/src/app/api/init/route.js +4 -0
- package/src/app/api/keys/[id]/route.js +58 -0
- package/src/app/api/keys/route.js +42 -0
- package/src/app/api/locale/route.js +30 -0
- package/src/app/api/mcp/[plugin]/message/route.js +21 -0
- package/src/app/api/mcp/[plugin]/sse/route.js +37 -0
- package/src/app/api/media-providers/tts/deepgram/voices/route.js +65 -0
- package/src/app/api/media-providers/tts/elevenlabs/voices/route.js +71 -0
- package/src/app/api/media-providers/tts/inworld/voices/route.js +61 -0
- package/src/app/api/media-providers/tts/minimax/voices/route.js +113 -0
- package/src/app/api/media-providers/tts/voices/route.js +99 -0
- package/src/app/api/models/alias/route.js +53 -0
- package/src/app/api/models/availability/route.js +103 -0
- package/src/app/api/models/custom/route.js +48 -0
- package/src/app/api/models/disabled/route.js +50 -0
- package/src/app/api/models/route.js +64 -0
- package/src/app/api/models/test/ping.js +191 -0
- package/src/app/api/models/test/route.js +14 -0
- package/src/app/api/oauth/[provider]/[action]/route.js +343 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/cancel/route.js +19 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/manual/[workerId]/route.js +30 -0
- package/src/app/api/oauth/codebuddy/bulk-import/[jobId]/route.js +23 -0
- package/src/app/api/oauth/codebuddy/bulk-import/latest/route.js +25 -0
- package/src/app/api/oauth/codebuddy/bulk-import/route.js +49 -0
- package/src/app/api/oauth/codebuddy/quota-cookie/route.js +133 -0
- package/src/app/api/oauth/codex/import-token/route.js +96 -0
- package/src/app/api/oauth/cursor/auto-import/route.js +258 -0
- package/src/app/api/oauth/cursor/import/route.js +100 -0
- package/src/app/api/oauth/gitlab/pat/route.js +62 -0
- package/src/app/api/oauth/iflow/cookie/route.js +137 -0
- package/src/app/api/oauth/kiro/auto-import/route.js +85 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/cancel/route.js +18 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/manual/[workerId]/route.js +29 -0
- package/src/app/api/oauth/kiro/bulk-import/[jobId]/route.js +22 -0
- package/src/app/api/oauth/kiro/bulk-import/latest/route.js +25 -0
- package/src/app/api/oauth/kiro/bulk-import/route.js +49 -0
- package/src/app/api/oauth/kiro/import/route.js +110 -0
- package/src/app/api/oauth/kiro/social-authorize/route.js +27 -0
- package/src/app/api/oauth/kiro/social-exchange/route.js +41 -0
- package/src/app/api/pricing/route.js +134 -0
- package/src/app/api/provider-nodes/[id]/route.js +101 -0
- package/src/app/api/provider-nodes/route.js +104 -0
- package/src/app/api/provider-nodes/validate/route.js +201 -0
- package/src/app/api/providers/[id]/models/route.js +526 -0
- package/src/app/api/providers/[id]/route.js +189 -0
- package/src/app/api/providers/[id]/test/route.js +23 -0
- package/src/app/api/providers/[id]/test/testUtils.js +714 -0
- package/src/app/api/providers/[id]/test-models/route.js +66 -0
- package/src/app/api/providers/client/route.js +126 -0
- package/src/app/api/providers/kilo/free-models/route.js +55 -0
- package/src/app/api/providers/route.js +206 -0
- package/src/app/api/providers/suggested-models/filters.js +20 -0
- package/src/app/api/providers/suggested-models/route.js +32 -0
- package/src/app/api/providers/test-batch/route.js +131 -0
- package/src/app/api/providers/validate/route.js +637 -0
- package/src/app/api/proxy-pools/[id]/route.js +123 -0
- package/src/app/api/proxy-pools/[id]/test/route.js +70 -0
- package/src/app/api/proxy-pools/cloudflare-deploy/route.js +145 -0
- package/src/app/api/proxy-pools/deno-deploy/route.js +175 -0
- package/src/app/api/proxy-pools/route.js +93 -0
- package/src/app/api/proxy-pools/vercel-deploy/route.js +142 -0
- package/src/app/api/settings/database/route.js +36 -0
- package/src/app/api/settings/proxy-test/route.js +23 -0
- package/src/app/api/settings/require-login/route.js +15 -0
- package/src/app/api/settings/route.js +100 -0
- package/src/app/api/shutdown/route.js +24 -0
- package/src/app/api/tags/route.js +18 -0
- package/src/app/api/translator/console-logs/route.js +24 -0
- package/src/app/api/translator/console-logs/stream/route.js +79 -0
- package/src/app/api/translator/load/route.js +45 -0
- package/src/app/api/translator/save/route.js +44 -0
- package/src/app/api/translator/send/route.js +94 -0
- package/src/app/api/translator/translate/route.js +90 -0
- package/src/app/api/tunnel/disable/route.js +12 -0
- package/src/app/api/tunnel/enable/route.js +16 -0
- package/src/app/api/tunnel/status/route.js +13 -0
- package/src/app/api/tunnel/tailscale-check/route.js +50 -0
- package/src/app/api/tunnel/tailscale-disable/route.js +12 -0
- package/src/app/api/tunnel/tailscale-enable/route.js +12 -0
- package/src/app/api/tunnel/tailscale-install/route.js +72 -0
- package/src/app/api/usage/[connectionId]/route.js +188 -0
- package/src/app/api/usage/chart/route.js +21 -0
- package/src/app/api/usage/history/route.js +12 -0
- package/src/app/api/usage/logs/route.js +12 -0
- package/src/app/api/usage/providers/route.js +42 -0
- package/src/app/api/usage/request-details/route.js +57 -0
- package/src/app/api/usage/request-logs/route.js +13 -0
- package/src/app/api/usage/stats/route.js +23 -0
- package/src/app/api/usage/stream/route.js +79 -0
- package/src/app/api/v1/api/chat/route.js +37 -0
- package/src/app/api/v1/audio/speech/route.js +16 -0
- package/src/app/api/v1/audio/transcriptions/route.js +19 -0
- package/src/app/api/v1/audio/voices/route.js +68 -0
- package/src/app/api/v1/chat/completions/route.js +35 -0
- package/src/app/api/v1/embeddings/route.js +21 -0
- package/src/app/api/v1/images/generations/route.js +16 -0
- package/src/app/api/v1/messages/count_tokens/route.js +52 -0
- package/src/app/api/v1/messages/route.js +36 -0
- package/src/app/api/v1/models/[kind]/route.js +55 -0
- package/src/app/api/v1/models/info/route.js +110 -0
- package/src/app/api/v1/models/route.js +451 -0
- package/src/app/api/v1/responses/compact/route.js +37 -0
- package/src/app/api/v1/responses/route.js +30 -0
- package/src/app/api/v1/route.js +1 -0
- package/src/app/api/v1/search/route.js +21 -0
- package/src/app/api/v1/web/fetch/route.js +21 -0
- package/src/app/api/v1beta/models/[...path]/route.js +328 -0
- package/src/app/api/v1beta/models/route.js +44 -0
- package/src/app/api/version/route.js +45 -0
- package/src/app/api/version/shutdown/route.js +15 -0
- package/src/app/api/version/update/route.js +21 -0
- package/src/app/callback/page.js +148 -0
- package/src/app/dashboard/settings/pricing/page.js +173 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +496 -0
- package/src/app/landing/components/AnimatedBackground.js +57 -0
- package/src/app/landing/components/Features.js +133 -0
- package/src/app/landing/components/FlowAnimation.js +175 -0
- package/src/app/landing/components/Footer.js +61 -0
- package/src/app/landing/components/GetStarted.js +97 -0
- package/src/app/landing/components/HeroSection.js +47 -0
- package/src/app/landing/components/HowItWorks.js +66 -0
- package/src/app/landing/components/Navigation.js +72 -0
- package/src/app/landing/page.js +106 -0
- package/src/app/layout.js +49 -0
- package/src/app/login/page.js +197 -0
- package/src/app/manifest.js +30 -0
- package/src/app/page.js +5 -0
- package/src/dashboardGuard.js +242 -0
- package/src/i18n/RuntimeI18nProvider.js +27 -0
- package/src/i18n/config.js +146 -0
- package/src/i18n/runtime.js +162 -0
- package/src/lib/appUpdater.js +200 -0
- package/src/lib/auth/dashboardSession.js +68 -0
- package/src/lib/auth/loginLimiter.js +52 -0
- package/src/lib/auth/oidc.js +234 -0
- package/src/lib/consoleLogBuffer.js +79 -0
- package/src/lib/dataDir.js +29 -0
- package/src/lib/db/adapters/betterSqliteAdapter.js +55 -0
- package/src/lib/db/adapters/bunSqliteAdapter.js +63 -0
- package/src/lib/db/adapters/nodeSqliteAdapter.js +84 -0
- package/src/lib/db/adapters/sqljsAdapter.js +115 -0
- package/src/lib/db/backup.js +35 -0
- package/src/lib/db/driver.js +85 -0
- package/src/lib/db/helpers/jsonCol.js +9 -0
- package/src/lib/db/helpers/kvStore.js +39 -0
- package/src/lib/db/helpers/metaStore.js +22 -0
- package/src/lib/db/index.js +171 -0
- package/src/lib/db/migrate.js +286 -0
- package/src/lib/db/migrations/001-initial.js +14 -0
- package/src/lib/db/migrations/index.js +10 -0
- package/src/lib/db/paths.js +18 -0
- package/src/lib/db/repos/aliasRepo.js +62 -0
- package/src/lib/db/repos/apiKeysRepo.js +75 -0
- package/src/lib/db/repos/combosRepo.js +73 -0
- package/src/lib/db/repos/connectionsRepo.js +226 -0
- package/src/lib/db/repos/disabledModelsRepo.js +56 -0
- package/src/lib/db/repos/nodesRepo.js +95 -0
- package/src/lib/db/repos/pricingRepo.js +108 -0
- package/src/lib/db/repos/proxyPoolsRepo.js +103 -0
- package/src/lib/db/repos/requestDetailsRepo.js +259 -0
- package/src/lib/db/repos/settingsRepo.js +104 -0
- package/src/lib/db/repos/usageRepo.js +731 -0
- package/src/lib/db/schema.js +157 -0
- package/src/lib/db/version.js +21 -0
- package/src/lib/disabledModelsDb.js +4 -0
- package/src/lib/localDb.js +21 -0
- package/src/lib/mcp/stdioSseBridge.js +198 -0
- package/src/lib/mitmAliasCache.js +46 -0
- package/src/lib/network/connectionProxy.js +160 -0
- package/src/lib/network/initOutboundProxy.js +25 -0
- package/src/lib/network/outboundProxy.js +68 -0
- package/src/lib/network/proxyTest.js +91 -0
- package/src/lib/oauth/constants/oauth.js +284 -0
- package/src/lib/oauth/constants/xai.js +61 -0
- package/src/lib/oauth/providers.js +1506 -0
- package/src/lib/oauth/services/antigravity.js +321 -0
- package/src/lib/oauth/services/claude.js +136 -0
- package/src/lib/oauth/services/codebuddyBulkImportManager.js +454 -0
- package/src/lib/oauth/services/codex.js +144 -0
- package/src/lib/oauth/services/cursor.js +179 -0
- package/src/lib/oauth/services/gemini.js +240 -0
- package/src/lib/oauth/services/github.js +225 -0
- package/src/lib/oauth/services/iflow.js +202 -0
- package/src/lib/oauth/services/index.js +17 -0
- package/src/lib/oauth/services/kiro.js +334 -0
- package/src/lib/oauth/services/kiroBulkImportManager.js +778 -0
- package/src/lib/oauth/services/kiroConnections.js +93 -0
- package/src/lib/oauth/services/kiroGoogleAutomation.js +1136 -0
- package/src/lib/oauth/services/oauth.js +157 -0
- package/src/lib/oauth/services/openai.js +123 -0
- package/src/lib/oauth/services/qoder.js +216 -0
- package/src/lib/oauth/services/qwen.js +170 -0
- package/src/lib/oauth/services/xai.js +238 -0
- package/src/lib/oauth/utils/banner.js +63 -0
- package/src/lib/oauth/utils/pkce.js +39 -0
- package/src/lib/oauth/utils/server.js +415 -0
- package/src/lib/oauth/utils/ui.js +48 -0
- package/src/lib/providerNormalization.js +45 -0
- package/src/lib/qoder/constants.js +64 -0
- package/src/lib/qoder/cosy.js +175 -0
- package/src/lib/qoder/encoding.js +55 -0
- package/src/lib/requestDetailsDb.js +4 -0
- package/src/lib/tunnel/cloudflare/cloudflared.js +449 -0
- package/src/lib/tunnel/cloudflare/config.js +9 -0
- package/src/lib/tunnel/cloudflare/healthCheck.js +29 -0
- package/src/lib/tunnel/cloudflare/manager.js +151 -0
- package/src/lib/tunnel/cloudflare/pid.js +23 -0
- package/src/lib/tunnel/index.js +48 -0
- package/src/lib/tunnel/shared/dnsResolver.js +17 -0
- package/src/lib/tunnel/shared/internetCheck.js +26 -0
- package/src/lib/tunnel/shared/state.js +41 -0
- package/src/lib/tunnel/shared/watchdogConfig.js +8 -0
- package/src/lib/tunnel/tailscale/config.js +7 -0
- package/src/lib/tunnel/tailscale/healthCheck.js +29 -0
- package/src/lib/tunnel/tailscale/manager.js +129 -0
- package/src/lib/tunnel/tailscale/tailscale.js +790 -0
- package/src/lib/updater/updater.js +235 -0
- package/src/lib/usage/fetcher.js +208 -0
- package/src/lib/usageDb.js +7 -0
- package/src/mitm/antigravityIdeVersion.js +50 -0
- package/src/mitm/cert/generate.js +32 -0
- package/src/mitm/cert/install.js +269 -0
- package/src/mitm/cert/rootCA.js +173 -0
- package/src/mitm/config.js +87 -0
- package/src/mitm/dbReader.js +22 -0
- package/src/mitm/dns/dnsConfig.js +266 -0
- package/src/mitm/handlers/antigravity.js +33 -0
- package/src/mitm/handlers/base.js +226 -0
- package/src/mitm/handlers/copilot.js +35 -0
- package/src/mitm/handlers/cursor.js +15 -0
- package/src/mitm/handlers/kiro.js +526 -0
- package/src/mitm/logger.js +106 -0
- package/src/mitm/manager.js +851 -0
- package/src/mitm/paths.js +32 -0
- package/src/mitm/server.js +435 -0
- package/src/mitm/winElevated.js +81 -0
- package/src/models/index.js +38 -0
- package/src/proxy.js +5 -0
- package/src/shared/components/AddCustomEmbeddingModal.js +183 -0
- package/src/shared/components/Avatar.js +88 -0
- package/src/shared/components/Badge.js +54 -0
- package/src/shared/components/BulkAccountAutomationModal.js +508 -0
- package/src/shared/components/Button.js +56 -0
- package/src/shared/components/Card.js +116 -0
- package/src/shared/components/ChangelogModal.js +97 -0
- package/src/shared/components/CodeBuddyQuotaCookieModal.js +109 -0
- package/src/shared/components/ComboFormModal.js +176 -0
- package/src/shared/components/CursorAuthModal.js +212 -0
- package/src/shared/components/DonateModal.js +136 -0
- package/src/shared/components/Drawer.js +82 -0
- package/src/shared/components/EditConnectionModal.js +286 -0
- package/src/shared/components/Footer.js +132 -0
- package/src/shared/components/GitLabAuthModal.js +194 -0
- package/src/shared/components/Header.js +380 -0
- package/src/shared/components/HeaderLanguage.js +46 -0
- package/src/shared/components/HeaderMenu.js +126 -0
- package/src/shared/components/IFlowCookieModal.js +132 -0
- package/src/shared/components/Input.js +65 -0
- package/src/shared/components/KiroAuthModal.js +1171 -0
- package/src/shared/components/KiroOAuthWrapper.js +149 -0
- package/src/shared/components/KiroSocialOAuthModal.js +205 -0
- package/src/shared/components/LanguageSwitcher.js +190 -0
- package/src/shared/components/Loading.js +75 -0
- package/src/shared/components/ManualConfigModal.js +44 -0
- package/src/shared/components/McpMarketplaceModal.js +255 -0
- package/src/shared/components/Modal.js +146 -0
- package/src/shared/components/ModelSelectModal.js +537 -0
- package/src/shared/components/NineRemoteButton.js +23 -0
- package/src/shared/components/NineRemotePromoModal.js +99 -0
- package/src/shared/components/NoAuthProxyCard.js +86 -0
- package/src/shared/components/OAuthModal.js +682 -0
- package/src/shared/components/Pagination.js +150 -0
- package/src/shared/components/PricingModal.js +208 -0
- package/src/shared/components/ProviderIcon.js +63 -0
- package/src/shared/components/ProviderInfoCard.js +82 -0
- package/src/shared/components/RequestLogger.js +121 -0
- package/src/shared/components/SegmentedControl.js +48 -0
- package/src/shared/components/Select.js +67 -0
- package/src/shared/components/Sidebar.js +441 -0
- package/src/shared/components/ThemeProvider.js +15 -0
- package/src/shared/components/ThemeToggle.js +42 -0
- package/src/shared/components/Toggle.js +69 -0
- package/src/shared/components/Tooltip.js +25 -0
- package/src/shared/components/UsageStats.js +505 -0
- package/src/shared/components/index.js +46 -0
- package/src/shared/components/layouts/AuthLayout.js +29 -0
- package/src/shared/components/layouts/DashboardLayout.js +104 -0
- package/src/shared/components/layouts/index.js +4 -0
- package/src/shared/constants/cliTools.js +397 -0
- package/src/shared/constants/colors.js +77 -0
- package/src/shared/constants/config.js +99 -0
- package/src/shared/constants/coworkPlugins.js +75 -0
- package/src/shared/constants/index.js +4 -0
- package/src/shared/constants/locales.js +36 -0
- package/src/shared/constants/mitmToolHosts.js +12 -0
- package/src/shared/constants/models.js +38 -0
- package/src/shared/constants/pricing.js +303 -0
- package/src/shared/constants/providers.js +289 -0
- package/src/shared/constants/skills.js +78 -0
- package/src/shared/constants/ttsProviders.js +138 -0
- package/src/shared/hooks/index.js +2 -0
- package/src/shared/hooks/useCopyToClipboard.js +43 -0
- package/src/shared/hooks/useTheme.js +60 -0
- package/src/shared/services/bootstrap.js +12 -0
- package/src/shared/services/initializeApp.js +268 -0
- package/src/shared/utils/api.js +93 -0
- package/src/shared/utils/apiKey.js +98 -0
- package/src/shared/utils/clineAuth.js +37 -0
- package/src/shared/utils/cn.js +11 -0
- package/src/shared/utils/connectionStatus.js +162 -0
- package/src/shared/utils/index.js +40 -0
- package/src/shared/utils/machine.js +6 -0
- package/src/shared/utils/machineId.js +66 -0
- package/src/shared/utils/providerModelsFetcher.js +30 -0
- package/src/sse/handlers/chat.js +261 -0
- package/src/sse/handlers/embeddings.js +141 -0
- package/src/sse/handlers/fetch.js +213 -0
- package/src/sse/handlers/imageGeneration.js +142 -0
- package/src/sse/handlers/search.js +206 -0
- package/src/sse/handlers/stt.js +88 -0
- package/src/sse/handlers/tts.js +114 -0
- package/src/sse/services/auth.js +346 -0
- package/src/sse/services/codexGateway.js +215 -0
- package/src/sse/services/model.js +99 -0
- package/src/sse/services/tokenRefresh.js +319 -0
- package/src/sse/utils/logger.js +75 -0
- package/src/store/headerSearchStore.js +19 -0
- package/src/store/index.js +6 -0
- package/src/store/notificationStore.js +45 -0
- package/src/store/providerStore.js +55 -0
- package/src/store/settingsStore.js +51 -0
- package/src/store/themeStore.js +54 -0
- package/src/store/userStore.js +20 -0
- package/start.sh +4 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Port of Rust git::compact_diff (src/cmds/git/git.rs L325-413)
|
|
2
|
+
// Compacts unified diff: file headers, hunk-level truncation at 100 lines, +/-/context counting
|
|
3
|
+
import { GIT_DIFF_HUNK_MAX_LINES } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
export function gitDiff(diff, maxLines = 500) {
|
|
6
|
+
const result = [];
|
|
7
|
+
let currentFile = "";
|
|
8
|
+
let added = 0;
|
|
9
|
+
let removed = 0;
|
|
10
|
+
let inHunk = false;
|
|
11
|
+
let hunkShown = 0;
|
|
12
|
+
let hunkSkipped = 0;
|
|
13
|
+
let wasTruncated = false;
|
|
14
|
+
const maxHunkLines = GIT_DIFF_HUNK_MAX_LINES;
|
|
15
|
+
|
|
16
|
+
const lines = diff.split("\n");
|
|
17
|
+
|
|
18
|
+
outer: for (const line of lines) {
|
|
19
|
+
if (line.startsWith("diff --git")) {
|
|
20
|
+
if (hunkSkipped > 0) {
|
|
21
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
22
|
+
wasTruncated = true;
|
|
23
|
+
hunkSkipped = 0;
|
|
24
|
+
}
|
|
25
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
26
|
+
result.push(` +${added} -${removed}`);
|
|
27
|
+
}
|
|
28
|
+
const parts = line.split(" b/");
|
|
29
|
+
currentFile = parts.length > 1 ? parts.slice(1).join(" b/") : "unknown";
|
|
30
|
+
result.push(`\n${currentFile}`);
|
|
31
|
+
added = 0;
|
|
32
|
+
removed = 0;
|
|
33
|
+
inHunk = false;
|
|
34
|
+
hunkShown = 0;
|
|
35
|
+
} else if (line.startsWith("@@")) {
|
|
36
|
+
if (hunkSkipped > 0) {
|
|
37
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
38
|
+
wasTruncated = true;
|
|
39
|
+
hunkSkipped = 0;
|
|
40
|
+
}
|
|
41
|
+
inHunk = true;
|
|
42
|
+
hunkShown = 0;
|
|
43
|
+
result.push(` ${line}`);
|
|
44
|
+
} else if (inHunk) {
|
|
45
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
46
|
+
added += 1;
|
|
47
|
+
if (hunkShown < maxHunkLines) {
|
|
48
|
+
result.push(` ${line}`);
|
|
49
|
+
hunkShown += 1;
|
|
50
|
+
} else {
|
|
51
|
+
hunkSkipped += 1;
|
|
52
|
+
}
|
|
53
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
54
|
+
removed += 1;
|
|
55
|
+
if (hunkShown < maxHunkLines) {
|
|
56
|
+
result.push(` ${line}`);
|
|
57
|
+
hunkShown += 1;
|
|
58
|
+
} else {
|
|
59
|
+
hunkSkipped += 1;
|
|
60
|
+
}
|
|
61
|
+
} else if (hunkShown < maxHunkLines && !line.startsWith("\\")) {
|
|
62
|
+
if (hunkShown > 0) {
|
|
63
|
+
result.push(` ${line}`);
|
|
64
|
+
hunkShown += 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (result.length >= maxLines) {
|
|
70
|
+
result.push("\n... (more changes truncated)");
|
|
71
|
+
wasTruncated = true;
|
|
72
|
+
break outer;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (hunkSkipped > 0) {
|
|
77
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
78
|
+
wasTruncated = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
82
|
+
result.push(` +${added} -${removed}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (wasTruncated) {
|
|
86
|
+
result.push("[full diff: rtk git diff --no-compact]");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result.join("\n");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
gitDiff.filterName = "git-diff";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Port of git::format_status_output (rtk/src/cmds/git/git.rs:619-730)
|
|
2
|
+
// Output format:
|
|
3
|
+
// * <branch>
|
|
4
|
+
// + Staged: N files
|
|
5
|
+
// path1
|
|
6
|
+
// ... +K more
|
|
7
|
+
// ~ Modified: N files
|
|
8
|
+
// ? Untracked: N files
|
|
9
|
+
// conflicts: N files
|
|
10
|
+
// clean — nothing to commit
|
|
11
|
+
import { STATUS_MAX_FILES, STATUS_MAX_UNTRACKED } from "../constants.js";
|
|
12
|
+
|
|
13
|
+
export function gitStatus(input) {
|
|
14
|
+
const lines = input.split("\n");
|
|
15
|
+
if (lines.length === 0 || (lines.length === 1 && !lines[0].trim())) {
|
|
16
|
+
return "Clean working tree";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let branch = "";
|
|
20
|
+
const stagedFiles = [];
|
|
21
|
+
const modifiedFiles = [];
|
|
22
|
+
const untrackedFiles = [];
|
|
23
|
+
let staged = 0;
|
|
24
|
+
let modified = 0;
|
|
25
|
+
let untracked = 0;
|
|
26
|
+
let conflicts = 0;
|
|
27
|
+
|
|
28
|
+
for (const raw of lines) {
|
|
29
|
+
if (!raw.trim()) continue;
|
|
30
|
+
|
|
31
|
+
// Long-form branch detection (LLM usually sends this, not porcelain)
|
|
32
|
+
const longBranch = raw.match(/^On branch (\S+)/);
|
|
33
|
+
if (longBranch) { branch = longBranch[1]; continue; }
|
|
34
|
+
|
|
35
|
+
// Porcelain branch header: "## main...origin/main"
|
|
36
|
+
if (raw.startsWith("##")) { branch = raw.replace(/^##\s*/, ""); continue; }
|
|
37
|
+
|
|
38
|
+
// Porcelain status (2 chars + space + path)
|
|
39
|
+
if (raw.length >= 3 && /^[ MADRCU?!][ MADRCU?!] /.test(raw)) {
|
|
40
|
+
const x = raw[0];
|
|
41
|
+
const y = raw[1];
|
|
42
|
+
const file = raw.slice(3);
|
|
43
|
+
|
|
44
|
+
if (raw.slice(0, 2) === "??") {
|
|
45
|
+
untracked++;
|
|
46
|
+
untrackedFiles.push(file);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ("MADRC".includes(x)) {
|
|
51
|
+
staged++;
|
|
52
|
+
stagedFiles.push(file);
|
|
53
|
+
} else if (x === "U") {
|
|
54
|
+
conflicts++;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (y === "M" || y === "D") {
|
|
58
|
+
modified++;
|
|
59
|
+
modifiedFiles.push(file);
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Long form fallback ("modified: path", "new file: path", ...)
|
|
65
|
+
const longMatch = raw.match(/^\s*(modified|new file|deleted|renamed|both modified):\s+(.+)$/);
|
|
66
|
+
if (longMatch) {
|
|
67
|
+
const kind = longMatch[1];
|
|
68
|
+
const path = longMatch[2].trim();
|
|
69
|
+
if (kind === "both modified") { conflicts++; }
|
|
70
|
+
else if (kind === "modified" || kind === "deleted") { modified++; modifiedFiles.push(path); }
|
|
71
|
+
else if (kind === "new file" || kind === "renamed") { staged++; stagedFiles.push(path); }
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// "Untracked files:" section — gather bare paths after this marker
|
|
76
|
+
// Handled implicitly: plain paths without markers are skipped (safer).
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let out = "";
|
|
80
|
+
if (branch) out += `* ${branch}\n`;
|
|
81
|
+
|
|
82
|
+
if (staged > 0) {
|
|
83
|
+
out += `+ Staged: ${staged} files\n`;
|
|
84
|
+
for (const f of stagedFiles.slice(0, STATUS_MAX_FILES)) out += ` ${f}\n`;
|
|
85
|
+
if (stagedFiles.length > STATUS_MAX_FILES) {
|
|
86
|
+
out += ` ... +${stagedFiles.length - STATUS_MAX_FILES} more\n`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (modified > 0) {
|
|
91
|
+
out += `~ Modified: ${modified} files\n`;
|
|
92
|
+
for (const f of modifiedFiles.slice(0, STATUS_MAX_FILES)) out += ` ${f}\n`;
|
|
93
|
+
if (modifiedFiles.length > STATUS_MAX_FILES) {
|
|
94
|
+
out += ` ... +${modifiedFiles.length - STATUS_MAX_FILES} more\n`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (untracked > 0) {
|
|
99
|
+
out += `? Untracked: ${untracked} files\n`;
|
|
100
|
+
for (const f of untrackedFiles.slice(0, STATUS_MAX_UNTRACKED)) out += ` ${f}\n`;
|
|
101
|
+
if (untrackedFiles.length > STATUS_MAX_UNTRACKED) {
|
|
102
|
+
out += ` ... +${untrackedFiles.length - STATUS_MAX_UNTRACKED} more\n`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (conflicts > 0) {
|
|
107
|
+
out += `conflicts: ${conflicts} files\n`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (staged === 0 && modified === 0 && untracked === 0 && conflicts === 0) {
|
|
111
|
+
out += "clean — nothing to commit\n";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return out.replace(/\n+$/, "");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
gitStatus.filterName = "git-status";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Port of grep_wrapper (rtk/src/cmds/system/pipe_cmd.rs:50-86)
|
|
2
|
+
// Input format: "file:lineno:content" — splitn(3, ':') in Rust
|
|
3
|
+
import { GREP_PER_FILE_MAX } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
export function grep(input) {
|
|
6
|
+
const byFile = new Map();
|
|
7
|
+
let total = 0;
|
|
8
|
+
|
|
9
|
+
for (const line of input.split("\n")) {
|
|
10
|
+
// splitn(3, ':') — only split on first 2 colons
|
|
11
|
+
const first = line.indexOf(":");
|
|
12
|
+
if (first === -1) continue;
|
|
13
|
+
const second = line.indexOf(":", first + 1);
|
|
14
|
+
if (second === -1) continue;
|
|
15
|
+
const file = line.slice(0, first);
|
|
16
|
+
const lineNumStr = line.slice(first + 1, second);
|
|
17
|
+
const content = line.slice(second + 1);
|
|
18
|
+
// Rust: parts[1].parse::<usize>().is_ok()
|
|
19
|
+
if (!/^\d+$/.test(lineNumStr)) continue;
|
|
20
|
+
total++;
|
|
21
|
+
if (!byFile.has(file)) byFile.set(file, []);
|
|
22
|
+
byFile.get(file).push([lineNumStr, content]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (total === 0) return input;
|
|
26
|
+
|
|
27
|
+
// Rust: files.sort_by_key(|(f, _)| *f)
|
|
28
|
+
const files = Array.from(byFile.keys()).sort();
|
|
29
|
+
let out = `${total} matches in ${files.length}F:\n\n`;
|
|
30
|
+
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
const matches = byFile.get(file);
|
|
33
|
+
out += `[file] ${file} (${matches.length}):\n`;
|
|
34
|
+
const show = matches.slice(0, GREP_PER_FILE_MAX);
|
|
35
|
+
for (const [lineNum, content] of show) {
|
|
36
|
+
// Rust: format!(" {:>4}: {}", line_num, content.trim())
|
|
37
|
+
out += ` ${lineNum.padStart(4)}: ${content.trim()}\n`;
|
|
38
|
+
}
|
|
39
|
+
if (matches.length > GREP_PER_FILE_MAX) {
|
|
40
|
+
out += ` +${matches.length - GREP_PER_FILE_MAX}\n`;
|
|
41
|
+
}
|
|
42
|
+
out += "\n";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
grep.filterName = "grep";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Port of compact_ls (rtk/src/cmds/system/ls.rs:154-232)
|
|
2
|
+
// Input: `ls -la` style output. Output: compact "name/ (dirs)\nname size"
|
|
3
|
+
import { LS_EXT_SUMMARY_TOP, LS_NOISE_DIRS } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
// Rust LS_DATE_RE: month + day + (year|HH:MM)
|
|
6
|
+
const LS_DATE_RE = /\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d{1,2}\s+(\d{4}|\d{2}:\d{2})\s+/;
|
|
7
|
+
|
|
8
|
+
function humanSize(bytes) {
|
|
9
|
+
if (bytes >= 1_048_576) return `${(bytes / 1_048_576).toFixed(1)}M`;
|
|
10
|
+
if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)}K`;
|
|
11
|
+
return `${bytes}B`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function parseLsLine(line) {
|
|
15
|
+
const m = LS_DATE_RE.exec(line);
|
|
16
|
+
if (!m) return null;
|
|
17
|
+
const name = line.slice(m.index + m[0].length);
|
|
18
|
+
const beforeDate = line.slice(0, m.index);
|
|
19
|
+
const beforeParts = beforeDate.split(/\s+/).filter(Boolean);
|
|
20
|
+
if (beforeParts.length < 4) return null;
|
|
21
|
+
|
|
22
|
+
const perms = beforeParts[0];
|
|
23
|
+
const fileType = perms.charAt(0);
|
|
24
|
+
|
|
25
|
+
// size = rightmost parseable number before the date
|
|
26
|
+
let size = 0;
|
|
27
|
+
for (let i = beforeParts.length - 1; i >= 0; i--) {
|
|
28
|
+
const n = Number(beforeParts[i]);
|
|
29
|
+
if (Number.isInteger(n) && String(n) === beforeParts[i]) { size = n; break; }
|
|
30
|
+
}
|
|
31
|
+
return { fileType, size, name };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function ls(input) {
|
|
35
|
+
const dirs = [];
|
|
36
|
+
const files = []; // [name, sizeStr]
|
|
37
|
+
const byExt = new Map();
|
|
38
|
+
|
|
39
|
+
for (const line of input.split("\n")) {
|
|
40
|
+
if (line.startsWith("total ") || line.length === 0) continue;
|
|
41
|
+
const parsed = parseLsLine(line);
|
|
42
|
+
if (!parsed) continue;
|
|
43
|
+
if (parsed.name === "." || parsed.name === "..") continue;
|
|
44
|
+
|
|
45
|
+
// Rust ls.rs: show_all flag respected — for LLM context always skip noise
|
|
46
|
+
if (LS_NOISE_DIRS.includes(parsed.name)) continue;
|
|
47
|
+
|
|
48
|
+
if (parsed.fileType === "d") {
|
|
49
|
+
dirs.push(parsed.name);
|
|
50
|
+
} else if (parsed.fileType === "-" || parsed.fileType === "l") {
|
|
51
|
+
const dot = parsed.name.lastIndexOf(".");
|
|
52
|
+
const ext = dot > 0 ? parsed.name.slice(dot) : "no ext";
|
|
53
|
+
byExt.set(ext, (byExt.get(ext) || 0) + 1);
|
|
54
|
+
files.push([parsed.name, humanSize(parsed.size)]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (dirs.length === 0 && files.length === 0) return input;
|
|
59
|
+
|
|
60
|
+
let out = "";
|
|
61
|
+
for (const d of dirs) out += `${d}/\n`;
|
|
62
|
+
for (const [name, size] of files) out += `${name} ${size}\n`;
|
|
63
|
+
|
|
64
|
+
// Summary line (Rust port)
|
|
65
|
+
let summary = `\nSummary: ${files.length} files, ${dirs.length} dirs`;
|
|
66
|
+
if (byExt.size > 0) {
|
|
67
|
+
const ext = Array.from(byExt.entries()).sort((a, b) => b[1] - a[1]);
|
|
68
|
+
const parts = ext.slice(0, LS_EXT_SUMMARY_TOP).map(([e, c]) => `${c} ${e}`);
|
|
69
|
+
summary += ` (${parts.join(", ")}`;
|
|
70
|
+
if (ext.length > LS_EXT_SUMMARY_TOP) {
|
|
71
|
+
summary += `, +${ext.length - LS_EXT_SUMMARY_TOP} more`;
|
|
72
|
+
}
|
|
73
|
+
summary += ")";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return out + summary;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ls.filterName = "ls";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Handles Cursor/Codex read_file output: " 1|content\n 2|content".
|
|
2
|
+
// Strategy mirrors Rust filter::smart_truncate (filter.rs): keep head+tail, drop middle.
|
|
3
|
+
import { SMART_TRUNCATE_HEAD, SMART_TRUNCATE_TAIL, SMART_TRUNCATE_MIN_LINES } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
const LINE_RE = /^\s*\d+\|/;
|
|
6
|
+
|
|
7
|
+
export function readNumbered(input) {
|
|
8
|
+
const lines = input.split("\n");
|
|
9
|
+
if (lines.length < SMART_TRUNCATE_MIN_LINES) return input;
|
|
10
|
+
|
|
11
|
+
// Count how many lines match "N|content" to verify shape (hit ratio check
|
|
12
|
+
// already done by autodetect; here we just truncate).
|
|
13
|
+
const head = lines.slice(0, SMART_TRUNCATE_HEAD);
|
|
14
|
+
const tail = lines.slice(lines.length - SMART_TRUNCATE_TAIL);
|
|
15
|
+
const cut = lines.length - head.length - tail.length;
|
|
16
|
+
|
|
17
|
+
return [
|
|
18
|
+
...head,
|
|
19
|
+
`... +${cut} lines truncated (file continues)`,
|
|
20
|
+
...tail
|
|
21
|
+
].join("\n");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
readNumbered.filterName = "read-numbered";
|
|
25
|
+
|
|
26
|
+
// Exposed for autodetect
|
|
27
|
+
export const READ_NUMBERED_LINE_RE = LINE_RE;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Compact "Result of search in '...' (total N files):\n- path\n- path" output
|
|
2
|
+
// (Cursor Glob tool). Groups by parent dir like find, shows basenames.
|
|
3
|
+
import { SEARCH_LIST_PER_DIR_MAX, SEARCH_LIST_TOTAL_DIR_MAX } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
const HEADER_RE = /^Result of search in '[^']*' \(total (\d+) files?\):/;
|
|
6
|
+
|
|
7
|
+
export function searchList(input) {
|
|
8
|
+
const lines = input.split("\n");
|
|
9
|
+
if (lines.length === 0) return input;
|
|
10
|
+
|
|
11
|
+
// First line must be the header (validated by autodetect too)
|
|
12
|
+
const header = lines[0] || "";
|
|
13
|
+
const rest = lines.slice(1);
|
|
14
|
+
|
|
15
|
+
const paths = [];
|
|
16
|
+
for (const raw of rest) {
|
|
17
|
+
const t = raw.trim();
|
|
18
|
+
if (!t.startsWith("- ")) continue;
|
|
19
|
+
paths.push(t.slice(2));
|
|
20
|
+
}
|
|
21
|
+
if (paths.length === 0) return input;
|
|
22
|
+
|
|
23
|
+
const byDir = new Map();
|
|
24
|
+
for (const p of paths) {
|
|
25
|
+
const slash = p.lastIndexOf("/");
|
|
26
|
+
const dir = slash === -1 ? "." : (p.slice(0, slash) || "/");
|
|
27
|
+
const name = slash === -1 ? p : p.slice(slash + 1);
|
|
28
|
+
if (!byDir.has(dir)) byDir.set(dir, []);
|
|
29
|
+
byDir.get(dir).push(name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const dirs = Array.from(byDir.keys()).sort();
|
|
33
|
+
let out = `${header}\n${paths.length} files in ${dirs.length} dirs:\n\n`;
|
|
34
|
+
|
|
35
|
+
for (const dir of dirs.slice(0, SEARCH_LIST_TOTAL_DIR_MAX)) {
|
|
36
|
+
const names = byDir.get(dir);
|
|
37
|
+
out += `${dir}/ (${names.length}):\n`;
|
|
38
|
+
for (const n of names.slice(0, SEARCH_LIST_PER_DIR_MAX)) out += ` ${n}\n`;
|
|
39
|
+
if (names.length > SEARCH_LIST_PER_DIR_MAX) {
|
|
40
|
+
out += ` +${names.length - SEARCH_LIST_PER_DIR_MAX}\n`;
|
|
41
|
+
}
|
|
42
|
+
out += "\n";
|
|
43
|
+
}
|
|
44
|
+
if (dirs.length > SEARCH_LIST_TOTAL_DIR_MAX) {
|
|
45
|
+
out += `+${dirs.length - SEARCH_LIST_TOTAL_DIR_MAX} more dirs\n`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return out.replace(/\n+$/, "");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
searchList.filterName = "search-list";
|
|
52
|
+
export const SEARCH_LIST_HEADER_RE = HEADER_RE;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Port concept of filter::smart_truncate (rtk/src/core/filter.rs).
|
|
2
|
+
// Keep HEAD + TAIL lines, replace middle with "... +N lines truncated".
|
|
3
|
+
import { SMART_TRUNCATE_HEAD, SMART_TRUNCATE_TAIL, SMART_TRUNCATE_MIN_LINES } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
export function smartTruncate(input) {
|
|
6
|
+
const lines = input.split("\n");
|
|
7
|
+
if (lines.length < SMART_TRUNCATE_MIN_LINES) return input;
|
|
8
|
+
|
|
9
|
+
const head = lines.slice(0, SMART_TRUNCATE_HEAD);
|
|
10
|
+
const tail = lines.slice(lines.length - SMART_TRUNCATE_TAIL);
|
|
11
|
+
const cut = lines.length - head.length - tail.length;
|
|
12
|
+
return [...head, `... +${cut} lines truncated`, ...tail].join("\n");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
smartTruncate.filterName = "smart-truncate";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Port of filter_tree_output (rtk/src/cmds/system/tree.rs:65-94)
|
|
2
|
+
// Removes summary line (e.g. "5 directories, 23 files") and trailing blanks.
|
|
3
|
+
import { TREE_MAX_LINES } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
export function tree(input) {
|
|
6
|
+
const lines = input.split("\n");
|
|
7
|
+
if (lines.length === 0) return input;
|
|
8
|
+
|
|
9
|
+
const filtered = [];
|
|
10
|
+
for (const line of lines) {
|
|
11
|
+
// Drop "X directories, Y files" summary
|
|
12
|
+
if (line.includes("director") && line.includes("file")) continue;
|
|
13
|
+
// Drop leading blanks
|
|
14
|
+
if (line.trim() === "" && filtered.length === 0) continue;
|
|
15
|
+
filtered.push(line);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Drop trailing blanks
|
|
19
|
+
while (filtered.length > 0 && filtered[filtered.length - 1].trim() === "") {
|
|
20
|
+
filtered.pop();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Cap overly long trees (JS-only safeguard; Rust has no cap)
|
|
24
|
+
if (filtered.length > TREE_MAX_LINES) {
|
|
25
|
+
const cut = filtered.length - TREE_MAX_LINES;
|
|
26
|
+
return filtered.slice(0, TREE_MAX_LINES).join("\n") + `\n... +${cut} more lines`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return filtered.join("\n");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
tree.filterName = "tree";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// RTK port: compress tool_result content in LLM request bodies
|
|
2
|
+
// Injected at the top of translateRequest (before any format translation)
|
|
3
|
+
import { RAW_CAP, MIN_COMPRESS_SIZE } from "./constants.js";
|
|
4
|
+
import { autoDetectFilter } from "./autodetect.js";
|
|
5
|
+
import { safeApply } from "./applyFilter.js";
|
|
6
|
+
|
|
7
|
+
// Compress tool_result content in-place. Returns stats or null if disabled/failed.
|
|
8
|
+
export function compressMessages(body, enabled) {
|
|
9
|
+
if (!enabled) return null;
|
|
10
|
+
if (!body) return null;
|
|
11
|
+
|
|
12
|
+
// Kiro format: conversationState.history + conversationState.currentMessage
|
|
13
|
+
if (body.conversationState) {
|
|
14
|
+
return compressKiroFormat(body, enabled);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Support both OpenAI/Claude "messages" and OpenAI Responses "input"
|
|
18
|
+
const items = Array.isArray(body.messages) ? body.messages
|
|
19
|
+
: Array.isArray(body.input) ? body.input
|
|
20
|
+
: null;
|
|
21
|
+
if (!items) return null;
|
|
22
|
+
|
|
23
|
+
const stats = { bytesBefore: 0, bytesAfter: 0, hits: [] };
|
|
24
|
+
try {
|
|
25
|
+
for (let i = 0; i < items.length; i++) {
|
|
26
|
+
const msg = items[i];
|
|
27
|
+
if (!msg) continue;
|
|
28
|
+
|
|
29
|
+
// Shape 4: OpenAI Responses — top-level { type:"function_call_output", output: string | [{type:"input_text", text}] }
|
|
30
|
+
if (msg.type === "function_call_output") {
|
|
31
|
+
if (typeof msg.output === "string") {
|
|
32
|
+
msg.output = compressText(msg.output, stats, "openai-responses-string");
|
|
33
|
+
} else if (Array.isArray(msg.output)) {
|
|
34
|
+
for (let k = 0; k < msg.output.length; k++) {
|
|
35
|
+
const part = msg.output[k];
|
|
36
|
+
if (part && part.type === "input_text" && typeof part.text === "string") {
|
|
37
|
+
part.text = compressText(part.text, stats, "openai-responses-array");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Shape 1: OpenAI tool message — { role:"tool", content: "string" }
|
|
45
|
+
if (msg.role === "tool" && typeof msg.content === "string") {
|
|
46
|
+
msg.content = compressText(msg.content, stats, "openai-tool");
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!Array.isArray(msg.content)) continue;
|
|
51
|
+
|
|
52
|
+
// Shape 1b: OpenAI tool message — { role:"tool", content:[{type:"text", text:"..."}] }
|
|
53
|
+
if (msg.role === "tool") {
|
|
54
|
+
for (let k = 0; k < msg.content.length; k++) {
|
|
55
|
+
const part = msg.content[k];
|
|
56
|
+
if (part && part.type === "text" && typeof part.text === "string") {
|
|
57
|
+
part.text = compressText(part.text, stats, "openai-tool-array");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Shape 2/3: blocks array with tool_result entries
|
|
64
|
+
for (let j = 0; j < msg.content.length; j++) {
|
|
65
|
+
const block = msg.content[j];
|
|
66
|
+
if (!block || block.type !== "tool_result") continue;
|
|
67
|
+
if (block.is_error === true) continue; // preserve error traces
|
|
68
|
+
|
|
69
|
+
if (typeof block.content === "string") {
|
|
70
|
+
// Shape 2: claude string form
|
|
71
|
+
block.content = compressText(block.content, stats, "claude-string");
|
|
72
|
+
} else if (Array.isArray(block.content)) {
|
|
73
|
+
// Shape 3: claude array form — compress each text part
|
|
74
|
+
for (let k = 0; k < block.content.length; k++) {
|
|
75
|
+
const part = block.content[k];
|
|
76
|
+
if (part && part.type === "text" && typeof part.text === "string") {
|
|
77
|
+
part.text = compressText(part.text, stats, "claude-array");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.warn("[RTK] compressMessages error:", e.message);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return stats;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Compress Kiro format: conversationState.history[].userInputMessage.userInputMessageContext.toolResults[].content[].text
|
|
91
|
+
function compressKiroFormat(body, enabled) {
|
|
92
|
+
const stats = { bytesBefore: 0, bytesAfter: 0, hits: [] };
|
|
93
|
+
try {
|
|
94
|
+
const state = body.conversationState;
|
|
95
|
+
const allMessages = [...(Array.isArray(state?.history) ? state.history : [])];
|
|
96
|
+
if (state?.currentMessage) allMessages.push(state.currentMessage);
|
|
97
|
+
|
|
98
|
+
for (const msg of allMessages) {
|
|
99
|
+
const toolResults = msg?.userInputMessage?.userInputMessageContext?.toolResults;
|
|
100
|
+
if (!Array.isArray(toolResults)) continue;
|
|
101
|
+
|
|
102
|
+
for (const tr of toolResults) {
|
|
103
|
+
if (tr.status === "error") continue; // preserve error traces
|
|
104
|
+
if (!Array.isArray(tr.content)) continue;
|
|
105
|
+
|
|
106
|
+
for (const part of tr.content) {
|
|
107
|
+
if (part && typeof part.text === "string") {
|
|
108
|
+
part.text = compressText(part.text, stats, "kiro-tool-result");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.warn("[RTK] compressKiroFormat error:", e.message);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return stats;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function compressText(text, stats, shape) {
|
|
121
|
+
const bytesIn = text.length;
|
|
122
|
+
stats.bytesBefore += bytesIn;
|
|
123
|
+
|
|
124
|
+
if (bytesIn < MIN_COMPRESS_SIZE || bytesIn > RAW_CAP) {
|
|
125
|
+
stats.bytesAfter += bytesIn;
|
|
126
|
+
return text;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const fn = autoDetectFilter(text);
|
|
130
|
+
if (!fn) {
|
|
131
|
+
stats.bytesAfter += bytesIn;
|
|
132
|
+
return text;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const out = safeApply(fn, text);
|
|
136
|
+
|
|
137
|
+
// Safety: never return empty, never grow the input
|
|
138
|
+
if (!out || out.length === 0 || out.length >= bytesIn) {
|
|
139
|
+
stats.bytesAfter += bytesIn;
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
stats.bytesAfter += out.length;
|
|
144
|
+
stats.hits.push({ shape, filter: fn.filterName || fn.name, saved: bytesIn - out.length });
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Convenience: format a log line from stats
|
|
149
|
+
export function formatRtkLog(stats) {
|
|
150
|
+
if (!stats || !stats.hits || stats.hits.length === 0) return null;
|
|
151
|
+
const saved = stats.bytesBefore - stats.bytesAfter;
|
|
152
|
+
const pct = stats.bytesBefore > 0 ? ((saved / stats.bytesBefore) * 100).toFixed(1) : "0";
|
|
153
|
+
const filters = Array.from(new Set(stats.hits.map(h => h.filter))).join(",");
|
|
154
|
+
return `[RTK] saved ${saved}B / ${stats.bytesBefore}B (${pct}%) via [${filters}] hits=${stats.hits.length}`;
|
|
155
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FILTERS } from "./constants.js";
|
|
2
|
+
import { gitDiff } from "./filters/gitDiff.js";
|
|
3
|
+
import { gitStatus } from "./filters/gitStatus.js";
|
|
4
|
+
import { grep } from "./filters/grep.js";
|
|
5
|
+
import { find } from "./filters/find.js";
|
|
6
|
+
import { dedupLog } from "./filters/dedupLog.js";
|
|
7
|
+
import { ls } from "./filters/ls.js";
|
|
8
|
+
import { tree } from "./filters/tree.js";
|
|
9
|
+
import { smartTruncate } from "./filters/smartTruncate.js";
|
|
10
|
+
import { readNumbered } from "./filters/readNumbered.js";
|
|
11
|
+
import { searchList } from "./filters/searchList.js";
|
|
12
|
+
|
|
13
|
+
const REGISTRY = {
|
|
14
|
+
[FILTERS.GIT_DIFF]: gitDiff,
|
|
15
|
+
[FILTERS.GIT_STATUS]: gitStatus,
|
|
16
|
+
[FILTERS.GREP]: grep,
|
|
17
|
+
[FILTERS.FIND]: find,
|
|
18
|
+
[FILTERS.DEDUP_LOG]: dedupLog,
|
|
19
|
+
[FILTERS.LS]: ls,
|
|
20
|
+
[FILTERS.TREE]: tree,
|
|
21
|
+
[FILTERS.SMART_TRUNCATE]: smartTruncate,
|
|
22
|
+
[FILTERS.READ_NUMBERED]: readNumbered,
|
|
23
|
+
[FILTERS.SEARCH_LIST]: searchList
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Rust resolve_filter aliases (pipe_cmd.rs): grep|rg, find|fd
|
|
27
|
+
const ALIASES = {
|
|
28
|
+
rg: grep,
|
|
29
|
+
fd: find
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function resolveFilter(name) {
|
|
33
|
+
return REGISTRY[name] || ALIASES[name] || null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function allFilters() {
|
|
37
|
+
return REGISTRY;
|
|
38
|
+
}
|