@fudrouter/fsrouter 0.6.72 → 0.6.74
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/dist/lib/headroom/detect.js +97 -7
- package/dist/lib/headroom/process.js +136 -4
- package/dist/open-sse/config/appConstants.js +23 -79
- package/dist/open-sse/config/cliFingerprints.js +1 -1
- package/dist/open-sse/config/errorConfig.js +0 -11
- package/dist/open-sse/config/grokCli.js +10 -0
- package/dist/open-sse/config/kiroConstants.js +99 -46
- package/dist/open-sse/config/runtimeConfig.js +2 -0
- package/dist/open-sse/config/ttsModels.js +2 -0
- package/dist/open-sse/executors/antigravity.js +250 -164
- package/dist/open-sse/executors/base.js +16 -11
- package/dist/open-sse/executors/codex.js +269 -1108
- package/dist/open-sse/executors/commandCode.js +1 -1
- package/dist/open-sse/executors/commandcode.js +10 -4
- package/dist/open-sse/executors/cursor.js +96 -203
- package/dist/open-sse/executors/default.js +146 -244
- package/dist/open-sse/executors/github.js +128 -73
- package/dist/open-sse/executors/grok-cli.js +527 -94
- package/dist/open-sse/executors/grok-web.js +5 -7
- package/dist/open-sse/executors/index.js +12 -0
- package/dist/open-sse/executors/kiro.js +150 -61
- package/dist/open-sse/executors/opencode-go.js +12 -4
- package/dist/open-sse/executors/opencode.js +1 -1
- package/dist/open-sse/executors/perplexity-web.js +20 -96
- package/dist/open-sse/executors/qoder.js +28 -18
- package/dist/open-sse/executors/vertex.js +53 -7
- package/dist/open-sse/executors/xiaomi-tokenplan.js +6 -5
- package/dist/open-sse/handlers/chatCore/nonStreamingHandler.js +97 -85
- package/dist/open-sse/handlers/chatCore/requestDetail.js +32 -8
- package/dist/open-sse/handlers/chatCore/sseToJsonHandler.js +13 -7
- package/dist/open-sse/handlers/chatCore/streamingHandler.js +74 -25
- package/dist/open-sse/handlers/chatCore.js +35 -41
- package/dist/open-sse/handlers/embeddingProviders/index.js +1 -0
- package/dist/open-sse/handlers/embeddingProviders/openai.js +8 -16
- package/dist/open-sse/handlers/imageProviders/blackForestLabs.js +2 -21
- package/dist/open-sse/handlers/imageProviders/cloudflareAi.js +2 -30
- package/dist/open-sse/handlers/imageProviders/codex.js +2 -20
- package/dist/open-sse/handlers/imageProviders/comfyui.js +5 -18
- package/dist/open-sse/handlers/imageProviders/falAi.js +2 -22
- package/dist/open-sse/handlers/imageProviders/gemini.js +2 -16
- package/dist/open-sse/handlers/imageProviders/huggingface.js +2 -17
- package/dist/open-sse/handlers/imageProviders/index.js +3 -4
- package/dist/open-sse/handlers/imageProviders/leonardo.js +1 -1
- package/dist/open-sse/handlers/imageProviders/nanobanana.js +4 -23
- package/dist/open-sse/handlers/imageProviders/openai.js +15 -43
- package/dist/open-sse/handlers/imageProviders/runwayml.js +2 -26
- package/dist/open-sse/handlers/imageProviders/sdwebui.js +4 -20
- package/dist/open-sse/handlers/imageProviders/stabilityAi.js +2 -26
- package/dist/open-sse/handlers/imageProviders/weavy.js +1 -1
- package/dist/open-sse/handlers/search/chatSearch.js +60 -14
- package/dist/open-sse/handlers/ttsProviders/gemini.js +14 -3
- package/dist/open-sse/handlers/ttsProviders/index.js +4 -2
- package/dist/open-sse/handlers/ttsProviders/openai.js +4 -1
- package/dist/open-sse/handlers/ttsProviders/openrouter.js +7 -4
- package/dist/open-sse/handlers/videoCore.js +166 -0
- package/dist/open-sse/handlers/videoProviders/weavy.js +1 -1
- package/dist/open-sse/mcp-server/catalog.js +1 -1
- package/dist/open-sse/mcp-server/server.js +2 -2
- package/dist/open-sse/mcp-server/tools/advancedTools.js +2 -2
- package/dist/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
- package/dist/open-sse/mcp-server/tools/compressionTools.js +4 -4
- package/dist/open-sse/mcp-server/tools/gamificationTools.js +10 -10
- package/dist/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
- package/dist/open-sse/mcp-server/tools/memoryTools.js +3 -3
- package/dist/open-sse/mcp-server/tools/notionTools.js +2 -2
- package/dist/open-sse/mcp-server/tools/obsidianTools.js +2 -2
- package/dist/open-sse/mcp-server/tools/pickFastestModel.js +1 -1
- package/dist/open-sse/mcp-server/tools/pluginTools.js +4 -4
- package/dist/open-sse/mcp-server/tools/skillTools.js +2 -2
- package/dist/open-sse/providers/capabilities.js +24 -4
- package/dist/open-sse/providers/registry/alicode-intl.js +1 -1
- package/dist/open-sse/providers/registry/anthropic.js +1 -8
- package/dist/open-sse/providers/registry/codex.js +0 -9
- package/dist/open-sse/providers/registry/cohere.js +0 -2
- package/dist/open-sse/providers/registry/gemini.js +0 -2
- package/dist/open-sse/providers/registry/github.js +9 -6
- package/dist/open-sse/providers/registry/grok-cli.js +28 -18
- package/dist/open-sse/providers/registry/index.js +74 -80
- package/dist/open-sse/providers/registry/kiro.js +12 -0
- package/dist/open-sse/providers/registry/mistral.js +0 -3
- package/dist/open-sse/providers/registry/openai.js +0 -3
- package/dist/open-sse/providers/registry/perplexity.js +0 -2
- package/dist/open-sse/providers/registry/xai.js +5 -3
- package/dist/open-sse/rtk/autodetect.js +10 -2
- package/dist/open-sse/rtk/caveman.js +2 -93
- package/dist/open-sse/rtk/cavemanPrompts.js +34 -2
- package/dist/open-sse/rtk/constants.js +7 -2
- package/dist/open-sse/rtk/headroom.js +133 -0
- package/dist/open-sse/rtk/ponytail.js +1 -1
- package/dist/open-sse/rtk/registry.js +2 -0
- package/dist/open-sse/services/accountFallback.js +0 -108
- package/dist/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
- package/dist/open-sse/services/combo/quotaShareStrategy.js +1 -1
- package/dist/open-sse/services/combo/resolveAutoStrategy.js +1 -1
- package/dist/open-sse/services/combo/sessionStickiness.js +1 -1
- package/dist/open-sse/services/combo/targetSorters.js +2 -2
- package/dist/open-sse/services/combo/validateQuality.js +1 -1
- package/dist/open-sse/services/comboConfig.js +1 -1
- package/dist/open-sse/services/emergencyFallback.js +1 -1
- package/dist/open-sse/services/grokCliModels.js +127 -0
- package/dist/open-sse/services/model.js +7 -1
- package/dist/open-sse/services/provider.js +1 -1
- package/dist/open-sse/services/proxyAutoSelector.js +1 -1
- package/dist/open-sse/services/tokenRefresh/providers.js +3 -3
- package/dist/open-sse/services/usage/codex.js +148 -214
- package/dist/open-sse/services/usage/grok-cli.js +61 -7
- package/dist/open-sse/services/usage/misc.js +0 -19
- package/dist/open-sse/services/usage.js +0 -2
- package/dist/open-sse/translator/concerns/paramSupport.js +2 -2
- package/dist/open-sse/translator/concerns/thinkingUnified.js +6 -0
- package/dist/open-sse/translator/index.js +97 -59
- package/dist/open-sse/translator/request/claude-to-kiro.js +67 -40
- package/dist/open-sse/translator/request/openai-responses.js +1 -0
- package/dist/open-sse/translator/request/openai-to-commandcode.js +0 -4
- package/dist/open-sse/translator/request/openai-to-kiro.js +49 -20
- package/dist/open-sse/translator/response/commandcode-to-openai.js +0 -4
- package/dist/open-sse/utils/bypassHandler.js +18 -3
- package/dist/open-sse/utils/claudeCloaking.js +15 -5
- package/dist/open-sse/utils/cursorImages.js +1 -1
- package/dist/open-sse/utils/error.js +0 -17
- package/dist/open-sse/utils/keepaliveThreshold.js +4 -4
- package/dist/open-sse/utils/kiroSessionReplay.js +125 -0
- package/dist/open-sse/utils/noThinkingAlias.js +1 -1
- package/dist/open-sse/utils/proxyFetch.js +0 -1
- package/dist/open-sse/utils/reasoningContentInjector.js +4 -7
- package/dist/open-sse/utils/responsesStatePolicy.js +1 -1
- package/dist/open-sse/utils/responsesStreamHelpers.js +1 -0
- package/dist/open-sse/utils/sessionManager.js +49 -22
- package/dist/open-sse/utils/stream.js +54 -77
- package/dist/open-sse/utils/streamHandler.js +19 -15
- package/dist/open-sse/utils/streamHelpers.js +2 -17
- package/dist/open-sse/utils/usageTracking.js +103 -12
- package/dist/routes/headroom/extras/route.js +58 -0
- package/dist/routes/headroom/restart/route.js +33 -0
- package/open-sse/config/appConstants.js +23 -79
- package/open-sse/config/errorConfig.js +0 -11
- package/open-sse/config/grokCli.js +10 -0
- package/open-sse/config/kiroConstants.js +99 -46
- package/open-sse/config/runtimeConfig.js +2 -0
- package/open-sse/config/ttsModels.js +2 -0
- package/open-sse/executors/antigravity.js +250 -164
- package/open-sse/executors/base.js +16 -11
- package/open-sse/executors/codex.js +269 -1108
- package/open-sse/executors/commandcode.js +10 -4
- package/open-sse/executors/cursor.js +96 -203
- package/open-sse/executors/default.js +146 -244
- package/open-sse/executors/github.js +128 -73
- package/open-sse/executors/grok-cli.js +527 -94
- package/open-sse/executors/grok-web.js +5 -7
- package/open-sse/executors/index.js +12 -0
- package/open-sse/executors/kiro.js +150 -61
- package/open-sse/executors/opencode-go.js +12 -4
- package/open-sse/executors/opencode.js +1 -1
- package/open-sse/executors/perplexity-web.js +20 -96
- package/open-sse/executors/qoder.js +28 -18
- package/open-sse/executors/vertex.js +53 -7
- package/open-sse/executors/xiaomi-tokenplan.js +6 -5
- package/open-sse/handlers/chatCore/nonStreamingHandler.js +97 -85
- package/open-sse/handlers/chatCore/requestDetail.js +32 -8
- package/open-sse/handlers/chatCore/sseToJsonHandler.js +13 -7
- package/open-sse/handlers/chatCore/streamingHandler.js +74 -25
- package/open-sse/handlers/chatCore.js +35 -41
- package/open-sse/handlers/embeddingProviders/index.js +1 -0
- package/open-sse/handlers/embeddingProviders/openai.js +8 -16
- package/open-sse/handlers/imageProviders/blackForestLabs.js +2 -21
- package/open-sse/handlers/imageProviders/cloudflareAi.js +2 -30
- package/open-sse/handlers/imageProviders/codex.js +2 -20
- package/open-sse/handlers/imageProviders/comfyui.js +5 -18
- package/open-sse/handlers/imageProviders/falAi.js +2 -22
- package/open-sse/handlers/imageProviders/gemini.js +2 -16
- package/open-sse/handlers/imageProviders/huggingface.js +2 -17
- package/open-sse/handlers/imageProviders/index.js +3 -4
- package/open-sse/handlers/imageProviders/leonardo.js +1 -1
- package/open-sse/handlers/imageProviders/nanobanana.js +4 -23
- package/open-sse/handlers/imageProviders/openai.js +15 -43
- package/open-sse/handlers/imageProviders/runwayml.js +2 -26
- package/open-sse/handlers/imageProviders/sdwebui.js +4 -20
- package/open-sse/handlers/imageProviders/stabilityAi.js +2 -26
- package/open-sse/handlers/imageProviders/weavy.js +1 -1
- package/open-sse/handlers/search/chatSearch.js +60 -14
- package/open-sse/handlers/ttsProviders/gemini.js +14 -3
- package/open-sse/handlers/ttsProviders/index.js +4 -2
- package/open-sse/handlers/ttsProviders/openai.js +4 -1
- package/open-sse/handlers/ttsProviders/openrouter.js +7 -4
- package/open-sse/handlers/videoCore.js +166 -0
- package/open-sse/handlers/videoProviders/weavy.js +1 -1
- package/open-sse/mcp-server/audit.js +1 -1
- package/open-sse/mcp-server/catalog.js +2 -2
- package/open-sse/mcp-server/descriptionCompressor.js +1 -1
- package/open-sse/mcp-server/mcpCallerIdentity.js +1 -1
- package/open-sse/mcp-server/schemas/tools.js +1 -1
- package/open-sse/mcp-server/server.js +4 -4
- package/open-sse/mcp-server/tools/advancedTools.js +5 -5
- package/open-sse/mcp-server/tools/agentSkillTools.js +1 -1
- package/open-sse/mcp-server/tools/compressionTools.js +4 -4
- package/open-sse/mcp-server/tools/gamificationTools.js +10 -10
- package/open-sse/mcp-server/tools/githubSkillTools.js +1 -1
- package/open-sse/mcp-server/tools/memoryTools.js +3 -3
- package/open-sse/mcp-server/tools/notionTools.js +2 -2
- package/open-sse/mcp-server/tools/obsidianTools.js +2 -2
- package/open-sse/mcp-server/tools/pickFastestModel.js +3 -3
- package/open-sse/mcp-server/tools/pluginTools.js +4 -4
- package/open-sse/mcp-server/tools/skillTools.js +2 -2
- package/open-sse/providers/capabilities.js +24 -4
- package/open-sse/providers/registry/alicode-intl.js +1 -1
- package/open-sse/providers/registry/anthropic.js +1 -8
- package/open-sse/providers/registry/codex.js +0 -9
- package/open-sse/providers/registry/cohere.js +0 -2
- package/open-sse/providers/registry/gemini.js +0 -2
- package/open-sse/providers/registry/github.js +9 -6
- package/open-sse/providers/registry/grok-cli.js +28 -18
- package/open-sse/providers/registry/index.js +74 -80
- package/open-sse/providers/registry/kiro.js +12 -0
- package/open-sse/providers/registry/mistral.js +0 -3
- package/open-sse/providers/registry/openai.js +0 -3
- package/open-sse/providers/registry/perplexity.js +0 -2
- package/open-sse/providers/registry/xai.js +5 -3
- package/open-sse/rtk/autodetect.js +10 -2
- package/open-sse/rtk/caveman.js +2 -93
- package/open-sse/rtk/cavemanPrompts.js +34 -2
- package/open-sse/rtk/constants.js +7 -2
- package/open-sse/rtk/headroom.js +133 -0
- package/open-sse/rtk/ponytail.js +1 -1
- package/open-sse/rtk/registry.js +2 -0
- package/open-sse/services/accountFallback.js +0 -108
- package/open-sse/services/combo/quotaExhaustionCutoff.js +2 -2
- package/open-sse/services/combo/quotaShareStrategy.js +1 -1
- package/open-sse/services/combo/resolveAutoStrategy.js +1 -1
- package/open-sse/services/combo/sessionStickiness.js +1 -1
- package/open-sse/services/combo/shadowRouting.js +1 -1
- package/open-sse/services/combo/targetSorters.js +4 -4
- package/open-sse/services/combo/validateQuality.js +1 -1
- package/open-sse/services/evalRouting.js +1 -1
- package/open-sse/services/grokCliModels.js +127 -0
- package/open-sse/services/model.js +7 -1
- package/open-sse/services/modelCapabilities.js +1 -1
- package/open-sse/services/modelFamilyFallback.js +1 -1
- package/open-sse/services/provider.js +1 -1
- package/open-sse/services/providerCooldownTracker.js +1 -1
- package/open-sse/services/rateLimitManager.js +1 -1
- package/open-sse/services/tokenRefresh/providers.js +3 -3
- package/open-sse/services/usage/codex.js +148 -214
- package/open-sse/services/usage/grok-cli.js +61 -7
- package/open-sse/services/usage/misc.js +0 -19
- package/open-sse/services/usage.js +0 -2
- package/open-sse/translator/concerns/paramSupport.js +2 -2
- package/open-sse/translator/concerns/thinkingUnified.js +6 -0
- package/open-sse/translator/index.js +97 -59
- package/open-sse/translator/request/claude-to-kiro.js +67 -40
- package/open-sse/translator/request/openai-responses.js +1 -0
- package/open-sse/translator/request/openai-to-commandcode.js +0 -4
- package/open-sse/translator/request/openai-to-kiro.js +49 -20
- package/open-sse/translator/response/commandcode-to-openai.js +0 -4
- package/open-sse/utils/bypassHandler.js +18 -3
- package/open-sse/utils/claudeCloaking.js +15 -5
- package/open-sse/utils/error.js +0 -17
- package/open-sse/utils/kiroSessionReplay.js +125 -0
- package/open-sse/utils/logger.js +1 -1
- package/open-sse/utils/proxyFetch.js +0 -1
- package/open-sse/utils/reasoningContentInjector.js +4 -7
- package/open-sse/utils/responsesStreamHelpers.js +1 -0
- package/open-sse/utils/sessionManager.js +49 -22
- package/open-sse/utils/stream.js +54 -77
- package/open-sse/utils/streamHandler.js +19 -15
- package/open-sse/utils/streamHelpers.js +2 -17
- package/open-sse/utils/usageTracking.js +103 -12
- package/package.json +4 -7
- package/public/assets/EndpointPageClient.C2WMTYy0.js +6 -0
- package/public/assets/{Loading.Bj-WGl4k.js → Loading.BHPtQ9vj.js} +1 -1
- package/public/assets/{NoAuthProxyCard.qAv57b-0.js → NoAuthProxyCard.BDcXaWvM.js} +1 -1
- package/public/assets/index.Be3gbrBl.js +89 -0
- package/public/assets/index.COMgQZYj.css +1 -0
- package/public/assets/{page.CbkENBd5.js → page.-lpNgYAw.js} +1 -1
- package/public/assets/{page.CssmrzTT.js → page.11hpNKmq.js} +1 -1
- package/public/assets/{page.C72FTTJr.js → page.B-LxsnqU.js} +1 -1
- package/public/assets/{page.sOFOrxqq.js → page.B-dzeIUC.js} +1 -1
- package/public/assets/{page.CsxWmPoI.js → page.B-nBR75u.js} +1 -1
- package/public/assets/{page.Dx_GRRdT.js → page.B3QqvLep.js} +1 -1
- package/public/assets/{page.DPyOkPVo.js → page.B8xdkCWA.js} +1 -1
- package/public/assets/{page.DUI8kqOY.js → page.BFb7yUd8.js} +1 -1
- package/public/assets/page.BbPPdoas.js +1 -0
- package/public/assets/page.BdS20a1O.js +1 -0
- package/public/assets/{page.DibhF7f-.js → page.BfmI9KYe.js} +1 -1
- package/public/assets/{page.DX4Nno6M.js → page.BgGJovOg.js} +1 -1
- package/public/assets/{page.BnmTC5jG.js → page.C0gBvR4O.js} +1 -1
- package/public/assets/{page.D5gj98Oe.js → page.C6bYizL7.js} +1 -1
- package/public/assets/{page.vla5Mzki.js → page.C8sLEMa6.js} +1 -1
- package/public/assets/{page.CXd_R9yU.js → page.CCNsZBXp.js} +1 -1
- package/public/assets/{page.CQlVGoXg.js → page.CF_YSLwP.js} +1 -1
- package/public/assets/{page.BbO1pspY.js → page.CPTtRDxw.js} +1 -1
- package/public/assets/{page.D1oKew1j.js → page.CdMmlUEm.js} +1 -1
- package/public/assets/{page.DxMDTbSx.js → page.Cged1bOZ.js} +1 -1
- package/public/assets/{page.Cj5h09Zo.js → page.Ch647dVk.js} +1 -1
- package/public/assets/{page.DVIHRbxB.js → page.CpvXDkQF.js} +1 -1
- package/public/assets/{page.i4KDuWcM.js → page.CrBl7f8N.js} +1 -1
- package/public/assets/{page.BSLJ4tx5.js → page.CrP7niA2.js} +1 -1
- package/public/assets/{page.CnTop8Zt.js → page.CvUFZzXr.js} +1 -1
- package/public/assets/{page.O2ddJYoT.js → page.CyUqJPmx.js} +1 -1
- package/public/assets/{page.DBhu4Arl.js → page.D8Rp8fFR.js} +1 -1
- package/public/assets/{page.CPZav1_c.js → page.Df9qtrdG.js} +1 -1
- package/public/assets/{page.Qkkv8roc.js → page.DiL4Gwqe.js} +1 -1
- package/public/assets/{page.BdmJ3yY3.js → page.Dl1apZE2.js} +1 -1
- package/public/assets/{page.1qjqvrwX.js → page.HV0w1d5C.js} +1 -1
- package/public/assets/{page.ChX1NqmC.js → page.N1x4YL8_.js} +1 -1
- package/public/assets/{page.Dh5f0XJC.js → page.P2Ny5veR.js} +1 -1
- package/public/assets/{page.CSs3-gdt.js → page.fOOCr18J.js} +1 -1
- package/public/assets/{page.Ir7KvKcF.js → page.sUIPWIiF.js} +1 -1
- package/public/assets/{page.CzlQTyAL.js → page.tE7PpWYW.js} +1 -1
- package/public/assets/{page.DzZLqI5Q.js → page.uziaGZsT.js} +1 -1
- package/public/index.html +2 -2
- package/public/assets/EndpointPageClient.LyNNvZ4z.js +0 -6
- package/public/assets/index.BuPfZebu.css +0 -1
- package/public/assets/index.CShjRV_B.js +0 -89
- package/public/assets/page.DD_czjjP.js +0 -1
|
@@ -1,100 +1,9 @@
|
|
|
1
1
|
// Caveman injector: appends a caveman-style instruction into the system message
|
|
2
2
|
// of the final request body, just before it is dispatched to the provider executor.
|
|
3
|
-
// Dispatches by format so it works for both translated and native-passthrough flows.
|
|
4
3
|
|
|
5
|
-
import {
|
|
4
|
+
import { injectSystemPrompt } from "./systemInject.js";
|
|
6
5
|
import { CAVEMAN_PROMPTS } from "./cavemanPrompts.js";
|
|
7
6
|
|
|
8
|
-
const SEP = "\n\n";
|
|
9
|
-
|
|
10
7
|
export function injectCaveman(body, format, level) {
|
|
11
|
-
|
|
12
|
-
if (!body || !prompt) return;
|
|
13
|
-
|
|
14
|
-
switch (format) {
|
|
15
|
-
case FORMATS.CLAUDE:
|
|
16
|
-
injectClaudeSystem(body, prompt);
|
|
17
|
-
return;
|
|
18
|
-
case FORMATS.GEMINI:
|
|
19
|
-
case FORMATS.GEMINI_CLI:
|
|
20
|
-
case FORMATS.VERTEX:
|
|
21
|
-
case FORMATS.ANTIGRAVITY:
|
|
22
|
-
// Antigravity wraps Gemini shape in body.request → injectGeminiSystem handles it
|
|
23
|
-
injectGeminiSystem(body, prompt);
|
|
24
|
-
return;
|
|
25
|
-
default:
|
|
26
|
-
// OpenAI and OpenAI-shaped formats (responses/codex/cursor/kiro/ollama)
|
|
27
|
-
injectMessagesSystem(body, prompt);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// OpenAI-shaped: messages[] (chat) or input[] (responses) or instructions (responses string)
|
|
32
|
-
function injectMessagesSystem(body, prompt) {
|
|
33
|
-
// OpenAI Responses API: top-level string field
|
|
34
|
-
if (typeof body.instructions === "string") {
|
|
35
|
-
body.instructions = body.instructions
|
|
36
|
-
? `${body.instructions}${SEP}${prompt}`
|
|
37
|
-
: prompt;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const arr = Array.isArray(body.messages) ? body.messages
|
|
42
|
-
: Array.isArray(body.input) ? body.input
|
|
43
|
-
: null;
|
|
44
|
-
if (!arr) return;
|
|
45
|
-
|
|
46
|
-
const idx = arr.findIndex(m => m && (m.role === "system" || m.role === "developer"));
|
|
47
|
-
if (idx >= 0) {
|
|
48
|
-
appendToOpenAIMessage(arr[idx], prompt);
|
|
49
|
-
} else {
|
|
50
|
-
arr.unshift({ role: "system", content: prompt });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function appendToOpenAIMessage(msg, prompt) {
|
|
55
|
-
if (typeof msg.content === "string") {
|
|
56
|
-
msg.content = `${msg.content}${SEP}${prompt}`;
|
|
57
|
-
} else if (Array.isArray(msg.content)) {
|
|
58
|
-
// Responses-style array of parts {type:"input_text"|"text", text}
|
|
59
|
-
msg.content.push({ type: "input_text", text: prompt });
|
|
60
|
-
} else {
|
|
61
|
-
msg.content = prompt;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Claude shape: body.system as string | array of {type:"text", text}
|
|
66
|
-
// Insert before the last cache_control block to keep caveman inside the cached prefix.
|
|
67
|
-
function injectClaudeSystem(body, prompt) {
|
|
68
|
-
if (typeof body.system === "string" && body.system.length > 0) {
|
|
69
|
-
body.system = `${body.system}${SEP}${prompt}`;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (Array.isArray(body.system)) {
|
|
73
|
-
const block = { type: "text", text: prompt };
|
|
74
|
-
let lastCacheIdx = -1;
|
|
75
|
-
for (let i = body.system.length - 1; i >= 0; i--) {
|
|
76
|
-
if (body.system[i]?.cache_control) { lastCacheIdx = i; break; }
|
|
77
|
-
}
|
|
78
|
-
if (lastCacheIdx >= 0) {
|
|
79
|
-
body.system.splice(lastCacheIdx, 0, block);
|
|
80
|
-
} else {
|
|
81
|
-
body.system.push(block);
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
body.system = prompt;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Gemini shape: body.system_instruction | body.systemInstruction | body.request.systemInstruction
|
|
89
|
-
// Each shape: { parts: [{ text }] }
|
|
90
|
-
function injectGeminiSystem(body, prompt) {
|
|
91
|
-
const target = body.request && typeof body.request === "object" ? body.request : body;
|
|
92
|
-
const useSnake = Object.prototype.hasOwnProperty.call(target, "system_instruction");
|
|
93
|
-
const key = useSnake ? "system_instruction" : "systemInstruction";
|
|
94
|
-
const sys = target[key];
|
|
95
|
-
if (sys && Array.isArray(sys.parts)) {
|
|
96
|
-
sys.parts.push({ text: prompt });
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
target[key] = { parts: [{ text: prompt }] };
|
|
8
|
+
injectSystemPrompt(body, format, CAVEMAN_PROMPTS[level]);
|
|
100
9
|
}
|
|
@@ -18,6 +18,14 @@ const SHARED_AUTO_CLARITY = "Auto-Clarity: drop caveman for security warnings, i
|
|
|
18
18
|
|
|
19
19
|
const SHARED_PERSISTENCE = "ACTIVE EVERY RESPONSE. No revert after many turns. No filler drift. Still active if unsure.";
|
|
20
20
|
|
|
21
|
+
const SHARED_NO_INVENTED_ABBREV = "No invented abbreviations. Standard well-known tech acronyms (DB, API, HTTP, URL, JSON, ID, OS, CPU) OK. Names of code symbols, function names, API names, error strings: keep verbatim.";
|
|
22
|
+
|
|
23
|
+
const SHARED_PRESERVE_LANGUAGE = "Preserve the user's dominant language. User wrote Vietnamese, reply Vietnamese. User wrote English, reply English. Wenyan/classical-Chinese levels override this language-preservation rule. Code identifiers, error strings, file paths, commands: keep in their original form regardless of language.";
|
|
24
|
+
|
|
25
|
+
const SHARED_NO_SELF_REFERENCE = 'No self-reference. Do not name or announce the style (no "caveman mode", no "me caveman think", no "compressed mode active"). Just respond.';
|
|
26
|
+
|
|
27
|
+
const SHARED_NO_DECORATION = 'No decorative emoji. No narrating tool calls ("I will now search", "I used X to find Y"). No status phrases ("Sure!", "Of course!", "I\'d be happy to"). No causal arrow shorthand ("A -> B -> fails"). State the thing, the action, the reason. Then next step.';
|
|
28
|
+
|
|
21
29
|
export const CAVEMAN_PROMPTS = {
|
|
22
30
|
[CAVEMAN_LEVELS.LITE]: [
|
|
23
31
|
"Respond tersely. Keep grammar and full sentences but drop filler, hedging and pleasantries (just/really/basically/sure/of course/I'd be happy to).",
|
|
@@ -26,6 +34,10 @@ export const CAVEMAN_PROMPTS = {
|
|
|
26
34
|
SHARED_BOUNDARIES,
|
|
27
35
|
SHARED_AUTO_CLARITY,
|
|
28
36
|
SHARED_PERSISTENCE,
|
|
37
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
38
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
39
|
+
SHARED_NO_SELF_REFERENCE,
|
|
40
|
+
SHARED_NO_DECORATION,
|
|
29
41
|
].join(" "),
|
|
30
42
|
|
|
31
43
|
[CAVEMAN_LEVELS.FULL]: [
|
|
@@ -36,16 +48,24 @@ export const CAVEMAN_PROMPTS = {
|
|
|
36
48
|
SHARED_BOUNDARIES,
|
|
37
49
|
SHARED_AUTO_CLARITY,
|
|
38
50
|
SHARED_PERSISTENCE,
|
|
51
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
52
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
53
|
+
SHARED_NO_SELF_REFERENCE,
|
|
54
|
+
SHARED_NO_DECORATION,
|
|
39
55
|
].join(" "),
|
|
40
56
|
|
|
41
57
|
[CAVEMAN_LEVELS.ULTRA]: [
|
|
42
58
|
"Respond ultra-terse. Maximum compression. Telegraphic.",
|
|
43
|
-
"
|
|
44
|
-
"Pattern: [thing]
|
|
59
|
+
"Strip conjunctions. One word when one word enough.",
|
|
60
|
+
"Pattern: [thing] [action] [reason]. [next step].",
|
|
45
61
|
SHARED_EXAMPLES,
|
|
46
62
|
SHARED_BOUNDARIES,
|
|
47
63
|
SHARED_AUTO_CLARITY,
|
|
48
64
|
SHARED_PERSISTENCE,
|
|
65
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
66
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
67
|
+
SHARED_NO_SELF_REFERENCE,
|
|
68
|
+
SHARED_NO_DECORATION,
|
|
49
69
|
].join(" "),
|
|
50
70
|
|
|
51
71
|
[CAVEMAN_LEVELS.WENYAN_LITE]: [
|
|
@@ -55,6 +75,10 @@ export const CAVEMAN_PROMPTS = {
|
|
|
55
75
|
SHARED_BOUNDARIES,
|
|
56
76
|
SHARED_AUTO_CLARITY,
|
|
57
77
|
SHARED_PERSISTENCE,
|
|
78
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
79
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
80
|
+
SHARED_NO_SELF_REFERENCE,
|
|
81
|
+
SHARED_NO_DECORATION,
|
|
58
82
|
].join(" "),
|
|
59
83
|
|
|
60
84
|
[CAVEMAN_LEVELS.WENYAN]: [
|
|
@@ -65,6 +89,10 @@ export const CAVEMAN_PROMPTS = {
|
|
|
65
89
|
SHARED_BOUNDARIES,
|
|
66
90
|
SHARED_AUTO_CLARITY,
|
|
67
91
|
SHARED_PERSISTENCE,
|
|
92
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
93
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
94
|
+
SHARED_NO_SELF_REFERENCE,
|
|
95
|
+
SHARED_NO_DECORATION,
|
|
68
96
|
].join(" "),
|
|
69
97
|
|
|
70
98
|
[CAVEMAN_LEVELS.WENYAN_ULTRA]: [
|
|
@@ -74,5 +102,9 @@ export const CAVEMAN_PROMPTS = {
|
|
|
74
102
|
SHARED_BOUNDARIES,
|
|
75
103
|
SHARED_AUTO_CLARITY,
|
|
76
104
|
SHARED_PERSISTENCE,
|
|
105
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
106
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
107
|
+
SHARED_NO_SELF_REFERENCE,
|
|
108
|
+
SHARED_NO_DECORATION,
|
|
77
109
|
].join(" "),
|
|
78
110
|
};
|
|
@@ -4,6 +4,7 @@ export const MIN_COMPRESS_SIZE = 500; // bytes; skip tiny blobs
|
|
|
4
4
|
export const DETECT_WINDOW = 1024; // autodetect peeks first N chars
|
|
5
5
|
export const GIT_DIFF_HUNK_MAX_LINES = 100; // per-hunk line cap
|
|
6
6
|
export const GIT_DIFF_CONTEXT_KEEP = 3; // context lines around changes
|
|
7
|
+
export const GIT_LOG_MAX_LINES = 200; // gitLog line cap
|
|
7
8
|
export const DEDUP_LINE_MAX = 2000; // dedupLog truncation cap
|
|
8
9
|
|
|
9
10
|
// Rust pipe_cmd.rs parity caps
|
|
@@ -19,8 +20,12 @@ export const STATUS_MAX_UNTRACKED = 10; // config::limits().status_max_un
|
|
|
19
20
|
export const LS_EXT_SUMMARY_TOP = 5; // top-N extensions in summary
|
|
20
21
|
export const LS_NOISE_DIRS = [
|
|
21
22
|
"node_modules", ".git", "target", "__pycache__",
|
|
22
|
-
".next", "dist", "build", ".
|
|
23
|
-
".
|
|
23
|
+
".next", "dist", "build", ".cache", ".turbo",
|
|
24
|
+
".vercel", ".pytest_cache", ".mypy_cache", ".tox",
|
|
25
|
+
".venv", "venv",
|
|
26
|
+
"env", // Python legacy virtualenv; .env (dotenv) intentionally excluded
|
|
27
|
+
"coverage", ".nyc_output", ".DS_Store", "Thumbs.db",
|
|
28
|
+
".idea", ".vscode", ".vs", "*.egg-info", ".eggs"
|
|
24
29
|
];
|
|
25
30
|
|
|
26
31
|
// tree filter_tree_output cap (no rust cap, we add one to be safe)
|
|
@@ -18,6 +18,8 @@ function jsonBytes(value) {
|
|
|
18
18
|
function messagePayload(body) {
|
|
19
19
|
if (Array.isArray(body?.messages)) return body.messages;
|
|
20
20
|
if (Array.isArray(body?.input)) return body.input;
|
|
21
|
+
const kiro = collectKiroHeadroomMessages(body);
|
|
22
|
+
if (kiro) return kiro.messages;
|
|
21
23
|
return null;
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -81,6 +83,121 @@ function hasUnsafeResponsesInputForCompression(body) {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
function collectKiroHeadroomMessages(body) {
|
|
87
|
+
const state = body?.conversationState;
|
|
88
|
+
if (!state || typeof state !== "object") return null;
|
|
89
|
+
|
|
90
|
+
const messages = [];
|
|
91
|
+
const targets = [];
|
|
92
|
+
|
|
93
|
+
const addTextTarget = (role, text, target, extra = {}) => {
|
|
94
|
+
if (typeof text !== "string") return;
|
|
95
|
+
messages.push({ role, content: text, ...extra });
|
|
96
|
+
targets.push(target);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const toToolCalls = (toolUses) => {
|
|
100
|
+
if (!Array.isArray(toolUses) || toolUses.length === 0) return undefined;
|
|
101
|
+
const calls = toolUses.map((toolUse) => ({
|
|
102
|
+
id: toolUse?.toolUseId,
|
|
103
|
+
type: "function",
|
|
104
|
+
function: {
|
|
105
|
+
name: toolUse?.name || "",
|
|
106
|
+
arguments: JSON.stringify(toolUse?.input || {}),
|
|
107
|
+
},
|
|
108
|
+
})).filter((call) => call.id || call.function.name);
|
|
109
|
+
return calls.length > 0 ? calls : undefined;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const visit = (item) => {
|
|
113
|
+
const user = item?.userInputMessage;
|
|
114
|
+
if (user) {
|
|
115
|
+
addTextTarget("system", user.systemInstruction, { object: user, key: "systemInstruction" });
|
|
116
|
+
addTextTarget("user", user.content, { object: user, key: "content" });
|
|
117
|
+
|
|
118
|
+
const toolResults = user.userInputMessageContext?.toolResults;
|
|
119
|
+
if (Array.isArray(toolResults)) {
|
|
120
|
+
for (const toolResult of toolResults) {
|
|
121
|
+
const content = toolResult?.content;
|
|
122
|
+
if (!Array.isArray(content)) continue;
|
|
123
|
+
for (const part of content) {
|
|
124
|
+
addTextTarget(
|
|
125
|
+
"tool",
|
|
126
|
+
part?.text,
|
|
127
|
+
{ object: part, key: "text" },
|
|
128
|
+
toolResult?.toolUseId ? { tool_call_id: toolResult.toolUseId } : {}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const assistant = item?.assistantResponseMessage;
|
|
137
|
+
if (assistant) {
|
|
138
|
+
const toolCalls = toToolCalls(assistant.toolUses);
|
|
139
|
+
addTextTarget(
|
|
140
|
+
"assistant",
|
|
141
|
+
assistant.content,
|
|
142
|
+
{ object: assistant, key: "content" },
|
|
143
|
+
toolCalls ? { tool_calls: toolCalls } : {}
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (Array.isArray(state.history)) {
|
|
149
|
+
for (const item of state.history) visit(item);
|
|
150
|
+
}
|
|
151
|
+
if (state.currentMessage) visit(state.currentMessage);
|
|
152
|
+
|
|
153
|
+
return messages.length > 0 ? { messages, targets } : null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function textFromHeadroomMessage(message) {
|
|
157
|
+
const content = message?.content;
|
|
158
|
+
if (typeof content === "string") return content;
|
|
159
|
+
if (!Array.isArray(content)) return null;
|
|
160
|
+
|
|
161
|
+
const parts = [];
|
|
162
|
+
for (const part of content) {
|
|
163
|
+
if (typeof part === "string") {
|
|
164
|
+
parts.push(part);
|
|
165
|
+
} else if (typeof part?.text === "string") {
|
|
166
|
+
parts.push(part.text);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return parts.length > 0 ? parts.join("\n") : null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function applyKiroHeadroomMessages(projection, compressedMessages, diagnostics) {
|
|
173
|
+
if (!Array.isArray(compressedMessages) || compressedMessages.length !== projection.messages.length) {
|
|
174
|
+
setDiagnostic(diagnostics, "proxy response did not match Kiro message count");
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const updates = [];
|
|
179
|
+
for (let i = 0; i < projection.messages.length; i++) {
|
|
180
|
+
const expected = projection.messages[i];
|
|
181
|
+
const actual = compressedMessages[i];
|
|
182
|
+
if (!actual || actual.role !== expected.role) {
|
|
183
|
+
setDiagnostic(diagnostics, "proxy response did not preserve Kiro message order");
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const text = textFromHeadroomMessage(actual);
|
|
188
|
+
if (text === null) {
|
|
189
|
+
setDiagnostic(diagnostics, "proxy response missing Kiro text content");
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
updates.push({ target: projection.targets[i], text });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (const update of updates) {
|
|
196
|
+
update.target.object[update.target.key] = update.text;
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
84
201
|
// POST messages to Headroom /v1/compress; returns compressed messages + stats or null.
|
|
85
202
|
async function callCompress(url, messages, model, timeoutMs, compressUserMessages, diagnostics) {
|
|
86
203
|
const endpoint = buildCompressEndpoint(url);
|
|
@@ -171,6 +288,22 @@ export async function compressWithHeadroom(body, { enabled, url, model, format,
|
|
|
171
288
|
return data;
|
|
172
289
|
}
|
|
173
290
|
|
|
291
|
+
// Kiro shape: conversationState.history/currentMessage are projected to
|
|
292
|
+
// OpenAI messages for the proxy, then copied back into the original Kiro
|
|
293
|
+
// fields. Keep the provider payload shape intact for Kiro's executor.
|
|
294
|
+
if (format === "kiro") {
|
|
295
|
+
const projection = collectKiroHeadroomMessages(body);
|
|
296
|
+
if (!projection) {
|
|
297
|
+
setDiagnostic(diagnostics, "Kiro request did not project to messages[]");
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
const data = await callCompress(url, projection.messages, model, timeoutMs, compressUserMessages, diagnostics || {});
|
|
301
|
+
if (!data) return null;
|
|
302
|
+
if (!applyKiroHeadroomMessages(projection, data.messages, diagnostics)) return null;
|
|
303
|
+
if (diagnostics) diagnostics.after = captureSizeSnapshot(body);
|
|
304
|
+
return data;
|
|
305
|
+
}
|
|
306
|
+
|
|
174
307
|
// OpenAI shape: messages/input go straight to the proxy.
|
|
175
308
|
const key = Array.isArray(body.messages) ? "messages"
|
|
176
309
|
: Array.isArray(body.input) ? "input"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// message of the final request body, just before dispatch to the provider executor.
|
|
3
3
|
|
|
4
4
|
import { injectSystemPrompt } from "./systemInject.js";
|
|
5
|
-
import { PONYTAIL_PROMPTS } from "./
|
|
5
|
+
import { PONYTAIL_PROMPTS } from "./ponytailPrompt.js";
|
|
6
6
|
|
|
7
7
|
export function injectPonytail(body, format, level) {
|
|
8
8
|
injectSystemPrompt(body, format, PONYTAIL_PROMPTS[level]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FILTERS } from "./constants.js";
|
|
2
2
|
import { gitDiff } from "./filters/gitDiff.js";
|
|
3
3
|
import { gitStatus } from "./filters/gitStatus.js";
|
|
4
|
+
import { gitLog } from "./filters/gitLog.js";
|
|
4
5
|
import { grep } from "./filters/grep.js";
|
|
5
6
|
import { find } from "./filters/find.js";
|
|
6
7
|
import { dedupLog } from "./filters/dedupLog.js";
|
|
@@ -13,6 +14,7 @@ import { searchList } from "./filters/searchList.js";
|
|
|
13
14
|
const REGISTRY = {
|
|
14
15
|
[FILTERS.GIT_DIFF]: gitDiff,
|
|
15
16
|
[FILTERS.GIT_STATUS]: gitStatus,
|
|
17
|
+
[FILTERS.GIT_LOG]: gitLog,
|
|
16
18
|
[FILTERS.GREP]: grep,
|
|
17
19
|
[FILTERS.FIND]: find,
|
|
18
20
|
[FILTERS.DEDUP_LOG]: dedupLog,
|
|
@@ -213,111 +213,3 @@ export function applyErrorState(account, status, errorText) {
|
|
|
213
213
|
status: "error"
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
// ── Error classification stubs (used by errorClassifier.js) ─────────────────
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Check if error text indicates the account has been deactivated/disabled.
|
|
221
|
-
*/
|
|
222
|
-
export function isAccountDeactivated(text) {
|
|
223
|
-
if (!text || typeof text !== 'string') return false;
|
|
224
|
-
const lower = text.toLowerCase();
|
|
225
|
-
return (
|
|
226
|
-
lower.includes('account disabled') ||
|
|
227
|
-
lower.includes('account_deactivated') ||
|
|
228
|
-
lower.includes('account has been deactivated') ||
|
|
229
|
-
lower.includes('account is no longer active') ||
|
|
230
|
-
lower.includes('organization has been disabled')
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Check if error text indicates credits/billing exhaustion.
|
|
236
|
-
*/
|
|
237
|
-
export function isCreditsExhausted(text) {
|
|
238
|
-
if (!text || typeof text !== 'string') return false;
|
|
239
|
-
const lower = text.toLowerCase();
|
|
240
|
-
return (
|
|
241
|
-
lower.includes('insufficient funds') ||
|
|
242
|
-
lower.includes('insufficient_funds') ||
|
|
243
|
-
lower.includes('credits exhausted') ||
|
|
244
|
-
lower.includes('out of credits') ||
|
|
245
|
-
lower.includes('no credits') ||
|
|
246
|
-
lower.includes('credit limit') ||
|
|
247
|
-
lower.includes('payment required') ||
|
|
248
|
-
lower.includes('spending limit') ||
|
|
249
|
-
lower.includes('quota exceeded') ||
|
|
250
|
-
lower.includes('quota_exceeded') ||
|
|
251
|
-
lower.includes('budget exceeded') ||
|
|
252
|
-
lower.includes('budget_exceeded')
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Check if error text indicates daily quota exhaustion (for 429 responses).
|
|
258
|
-
*/
|
|
259
|
-
export function isDailyQuotaExhausted(text) {
|
|
260
|
-
if (!text || typeof text !== 'string') return false;
|
|
261
|
-
const lower = text.toLowerCase();
|
|
262
|
-
return (
|
|
263
|
-
lower.includes('daily') ||
|
|
264
|
-
lower.includes('per day') ||
|
|
265
|
-
lower.includes('daily limit') ||
|
|
266
|
-
lower.includes('rate limit reached') ||
|
|
267
|
-
lower.includes('daily quota')
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Check if error text indicates an invalid/expired OAuth token.
|
|
273
|
-
*/
|
|
274
|
-
export function isOAuthInvalidToken(text) {
|
|
275
|
-
if (!text || typeof text !== 'string') return false;
|
|
276
|
-
const lower = text.toLowerCase();
|
|
277
|
-
return (
|
|
278
|
-
lower.includes('invalid_token') ||
|
|
279
|
-
lower.includes('invalid token') ||
|
|
280
|
-
lower.includes('token expired') ||
|
|
281
|
-
lower.includes('token has expired') ||
|
|
282
|
-
lower.includes('access token is invalid')
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Parse retry-after from a response body (JSON or string).
|
|
288
|
-
* Returns { retryAfterMs, reason }.
|
|
289
|
-
*/
|
|
290
|
-
export function parseRetryAfterFromBody(responseBody) {
|
|
291
|
-
if (!responseBody) return { retryAfterMs: 0, reason: null };
|
|
292
|
-
const text = typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody);
|
|
293
|
-
|
|
294
|
-
let retryAfterMs = 0;
|
|
295
|
-
let reason = null;
|
|
296
|
-
|
|
297
|
-
if (typeof responseBody === 'object' && responseBody !== null) {
|
|
298
|
-
const raw = responseBody.retry_after ?? responseBody.retryAfter ?? responseBody.retry_after_seconds;
|
|
299
|
-
if (typeof raw === 'number' && raw > 0) {
|
|
300
|
-
retryAfterMs = raw < 1e12 ? raw * 1000 : raw - Date.now();
|
|
301
|
-
reason = 'retry_after header';
|
|
302
|
-
} else if (typeof raw === 'string') {
|
|
303
|
-
const parsed = Number(raw);
|
|
304
|
-
if (Number.isFinite(parsed) && parsed > 0) {
|
|
305
|
-
retryAfterMs = parsed < 1e12 ? parsed * 1000 : parsed - Date.now();
|
|
306
|
-
reason = 'retry_after header';
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (retryAfterMs === 0) {
|
|
312
|
-
const match = text.match(/retry.*?(\d+)\s*(?:second|minute|hour)/i);
|
|
313
|
-
if (match) {
|
|
314
|
-
const val = Number(match[1]);
|
|
315
|
-
if (text.includes('minute')) retryAfterMs = val * 60 * 1000;
|
|
316
|
-
else if (text.includes('hour')) retryAfterMs = val * 3600 * 1000;
|
|
317
|
-
else retryAfterMs = val * 1000;
|
|
318
|
-
reason = 'body text pattern';
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return { retryAfterMs, reason };
|
|
323
|
-
}
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
evaluateQuotaCutoff,
|
|
3
3
|
getQuotaFetcher
|
|
4
4
|
} from "../quotaPreflight.ts";
|
|
5
|
-
import { getProviderConnectionById } from '
|
|
5
|
+
import { getProviderConnectionById } from '../../../dist/lib/db/providers.js';
|
|
6
6
|
import {
|
|
7
7
|
resolveResilienceSettings
|
|
8
|
-
} from '
|
|
8
|
+
} from '../../../dist/lib/resilience/settings.js';
|
|
9
9
|
import { fetchResetAwareQuotaWithCache } from "./quotaStrategies.ts";
|
|
10
10
|
function asThresholdMap(value) {
|
|
11
11
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBucketSaturated } from '
|
|
1
|
+
import { isBucketSaturated } from '../../../dist/lib/quota/accountBuckets.ts.js';
|
|
2
2
|
import { incrementInflight, decrementInflight, getInflight } from "./quotaShareInflight.ts";
|
|
3
3
|
const MAX_DRR_COMBOS = 200;
|
|
4
4
|
const _drrState = /* @__PURE__ */ new Map();
|
|
@@ -100,7 +100,7 @@ async function resolveAutoStrategyOrder(deps) {
|
|
|
100
100
|
}
|
|
101
101
|
let lastKnownGoodProvider;
|
|
102
102
|
try {
|
|
103
|
-
const { getLKGP } = await import('
|
|
103
|
+
const { getLKGP } = await import('../../../dist/lib/localDb.js');
|
|
104
104
|
const lkgp = await getLKGP(combo.name, combo.id || combo.name);
|
|
105
105
|
if (lkgp) lastKnownGoodProvider = lkgp.provider;
|
|
106
106
|
} catch (err) {
|
|
@@ -10,7 +10,7 @@ function __setStickinessHeadroomFetcherForTests(fetcher) {
|
|
|
10
10
|
async function resolveSaturation(connectionId, provider) {
|
|
11
11
|
if (_fetcherOverride) return _fetcherOverride(connectionId);
|
|
12
12
|
try {
|
|
13
|
-
const mod = await import('
|
|
13
|
+
const mod = await import('../../../dist/lib/quota/saturationSignals.js');
|
|
14
14
|
const getSaturation = mod.getSaturation;
|
|
15
15
|
const [util5h, util7d] = await Promise.all([
|
|
16
16
|
getSaturation(connectionId, provider, { unit: "percent", window: "5h" }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getCircuitBreaker } from "../../../shared/utils/circuitBreaker";
|
|
2
2
|
import { secureRandomFloat, secureRandomInt } from "../../../shared/utils/secureRandom";
|
|
3
|
-
import { getComboStepTarget, getComboStepWeight } from '
|
|
3
|
+
import { getComboStepTarget, getComboStepWeight } from '../../../dist/lib/combos/steps.ts.js';
|
|
4
4
|
import { getComboMetrics } from "../comboMetrics.ts";
|
|
5
5
|
import { parseModel } from "../model.ts";
|
|
6
6
|
function normalizeModelEntry(entry) {
|
|
@@ -32,7 +32,7 @@ function orderTargetsForWeightedFallback(targets, selectedExecutionKey, preserve
|
|
|
32
32
|
}
|
|
33
33
|
async function sortModelsByCost(models) {
|
|
34
34
|
try {
|
|
35
|
-
const { getPricingForModel } = await import('
|
|
35
|
+
const { getPricingForModel } = await import('../../../dist/lib/localDb.js');
|
|
36
36
|
const withCost = await Promise.all(
|
|
37
37
|
models.map(async (modelStr) => {
|
|
38
38
|
const parsed = parseModel(modelStr);
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
isKnownNonClaudeStreamPayload
|
|
4
4
|
} from "../../utils/streamHelpers.ts";
|
|
5
5
|
import { evaluateResponseValidation } from "./responseValidation.ts";
|
|
6
|
-
import { getReasoningTokens } from '
|
|
6
|
+
import { getReasoningTokens } from '../../../dist/lib/usage/tokenAccounting.ts.js';
|
|
7
7
|
function toRetryAfterDisplayValue(value) {
|
|
8
8
|
if (typeof value !== "number") return value;
|
|
9
9
|
if (value > 0 && value < 1e9) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_TIMER_TIMEOUT_MS } from '
|
|
1
|
+
import { MAX_TIMER_TIMEOUT_MS } from '../../dist/shared/utils/runtimeTimeouts.ts.js';
|
|
2
2
|
const PRE_SCREEN_CONCURRENCY = 5;
|
|
3
3
|
const DEFAULT_COMBO_TARGET_TIMEOUT_MS = 12e4;
|
|
4
4
|
const DEFAULT_COMBO_QUEUE_DEPTH = 20;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFeatureFlagEnabled } from '
|
|
1
|
+
import { isFeatureFlagEnabled } from '../../dist/shared/utils/featureFlags.js';
|
|
2
2
|
const EMERGENCY_FALLBACK_FLAG_KEY = "OMNIROUTE_EMERGENCY_FALLBACK";
|
|
3
3
|
const EMERGENCY_FALLBACK_FLAG_CACHE_MS = 500;
|
|
4
4
|
let emergencyFallbackFlagCache = null;
|