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,590 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translator: OpenAI Chat Completions → OpenAI Responses API (response)
|
|
3
|
+
* Converts streaming chunks from Chat Completions to Responses API events
|
|
4
|
+
*/
|
|
5
|
+
import { register } from "../index.js";
|
|
6
|
+
import { FORMATS } from "../formats.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Translate OpenAI chunk to Responses API events
|
|
10
|
+
* @returns {Array} Array of events with { event, data } structure
|
|
11
|
+
*/
|
|
12
|
+
export function openaiToOpenAIResponsesResponse(chunk, state) {
|
|
13
|
+
if (!chunk) {
|
|
14
|
+
return flushEvents(state);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!chunk.choices?.length) return [];
|
|
18
|
+
|
|
19
|
+
const events = [];
|
|
20
|
+
const nextSeq = () => ++state.seq;
|
|
21
|
+
|
|
22
|
+
const emit = (eventType, data) => {
|
|
23
|
+
data.sequence_number = nextSeq();
|
|
24
|
+
events.push({ event: eventType, data });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const choice = chunk.choices[0];
|
|
28
|
+
const idx = choice.index || 0;
|
|
29
|
+
const delta = choice.delta || {};
|
|
30
|
+
|
|
31
|
+
// Emit initial events
|
|
32
|
+
if (!state.started) {
|
|
33
|
+
state.started = true;
|
|
34
|
+
state.responseId = chunk.id ? `resp_${chunk.id}` : state.responseId;
|
|
35
|
+
|
|
36
|
+
emit("response.created", {
|
|
37
|
+
type: "response.created",
|
|
38
|
+
response: {
|
|
39
|
+
id: state.responseId,
|
|
40
|
+
object: "response",
|
|
41
|
+
created_at: state.created,
|
|
42
|
+
status: "in_progress",
|
|
43
|
+
background: false,
|
|
44
|
+
error: null,
|
|
45
|
+
output: []
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
emit("response.in_progress", {
|
|
50
|
+
type: "response.in_progress",
|
|
51
|
+
response: {
|
|
52
|
+
id: state.responseId,
|
|
53
|
+
object: "response",
|
|
54
|
+
created_at: state.created,
|
|
55
|
+
status: "in_progress"
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Handle reasoning_content
|
|
61
|
+
if (delta.reasoning_content) {
|
|
62
|
+
startReasoning(state, emit, idx);
|
|
63
|
+
emitReasoningDelta(state, emit, delta.reasoning_content);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Handle text content
|
|
67
|
+
if (delta.content) {
|
|
68
|
+
let content = delta.content;
|
|
69
|
+
|
|
70
|
+
if (content.includes("<think>")) {
|
|
71
|
+
state.inThinking = true;
|
|
72
|
+
content = content.replace("<think>", "");
|
|
73
|
+
startReasoning(state, emit, idx);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (content.includes("</think>")) {
|
|
77
|
+
const parts = content.split("</think>");
|
|
78
|
+
const thinkPart = parts[0];
|
|
79
|
+
const textPart = parts.slice(1).join("</think>");
|
|
80
|
+
if (thinkPart) emitReasoningDelta(state, emit, thinkPart);
|
|
81
|
+
closeReasoning(state, emit);
|
|
82
|
+
state.inThinking = false;
|
|
83
|
+
content = textPart;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (state.inThinking && content) {
|
|
87
|
+
emitReasoningDelta(state, emit, content);
|
|
88
|
+
return events;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (content) {
|
|
92
|
+
emitTextContent(state, emit, idx, content);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Handle tool_calls
|
|
97
|
+
if (delta.tool_calls) {
|
|
98
|
+
closeMessage(state, emit, idx);
|
|
99
|
+
for (const tc of delta.tool_calls) {
|
|
100
|
+
emitToolCall(state, emit, tc);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Handle finish_reason
|
|
105
|
+
if (choice.finish_reason) {
|
|
106
|
+
for (const i in state.msgItemAdded) closeMessage(state, emit, i);
|
|
107
|
+
closeReasoning(state, emit);
|
|
108
|
+
for (const i in state.funcCallIds) closeToolCall(state, emit, i);
|
|
109
|
+
sendCompleted(state, emit);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return events;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Helper functions
|
|
116
|
+
function startReasoning(state, emit, idx) {
|
|
117
|
+
if (!state.reasoningId) {
|
|
118
|
+
state.reasoningId = `rs_${state.responseId}_${idx}`;
|
|
119
|
+
state.reasoningIndex = idx;
|
|
120
|
+
|
|
121
|
+
emit("response.output_item.added", {
|
|
122
|
+
type: "response.output_item.added",
|
|
123
|
+
output_index: idx,
|
|
124
|
+
item: { id: state.reasoningId, type: "reasoning", summary: [] }
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
emit("response.reasoning_summary_part.added", {
|
|
128
|
+
type: "response.reasoning_summary_part.added",
|
|
129
|
+
item_id: state.reasoningId,
|
|
130
|
+
output_index: idx,
|
|
131
|
+
summary_index: 0,
|
|
132
|
+
part: { type: "summary_text", text: "" }
|
|
133
|
+
});
|
|
134
|
+
state.reasoningPartAdded = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function emitReasoningDelta(state, emit, text) {
|
|
139
|
+
if (!text) return;
|
|
140
|
+
state.reasoningBuf += text;
|
|
141
|
+
emit("response.reasoning_summary_text.delta", {
|
|
142
|
+
type: "response.reasoning_summary_text.delta",
|
|
143
|
+
item_id: state.reasoningId,
|
|
144
|
+
output_index: state.reasoningIndex,
|
|
145
|
+
summary_index: 0,
|
|
146
|
+
delta: text
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function closeReasoning(state, emit) {
|
|
151
|
+
if (state.reasoningId && !state.reasoningDone) {
|
|
152
|
+
state.reasoningDone = true;
|
|
153
|
+
|
|
154
|
+
emit("response.reasoning_summary_text.done", {
|
|
155
|
+
type: "response.reasoning_summary_text.done",
|
|
156
|
+
item_id: state.reasoningId,
|
|
157
|
+
output_index: state.reasoningIndex,
|
|
158
|
+
summary_index: 0,
|
|
159
|
+
text: state.reasoningBuf
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
emit("response.reasoning_summary_part.done", {
|
|
163
|
+
type: "response.reasoning_summary_part.done",
|
|
164
|
+
item_id: state.reasoningId,
|
|
165
|
+
output_index: state.reasoningIndex,
|
|
166
|
+
summary_index: 0,
|
|
167
|
+
part: { type: "summary_text", text: state.reasoningBuf }
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
emit("response.output_item.done", {
|
|
171
|
+
type: "response.output_item.done",
|
|
172
|
+
output_index: state.reasoningIndex,
|
|
173
|
+
item: {
|
|
174
|
+
id: state.reasoningId,
|
|
175
|
+
type: "reasoning",
|
|
176
|
+
summary: [{ type: "summary_text", text: state.reasoningBuf }]
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function emitTextContent(state, emit, idx, content) {
|
|
183
|
+
if (!state.msgItemAdded[idx]) {
|
|
184
|
+
state.msgItemAdded[idx] = true;
|
|
185
|
+
const msgId = `msg_${state.responseId}_${idx}`;
|
|
186
|
+
|
|
187
|
+
emit("response.output_item.added", {
|
|
188
|
+
type: "response.output_item.added",
|
|
189
|
+
output_index: idx,
|
|
190
|
+
item: { id: msgId, type: "message", content: [], role: "assistant" }
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!state.msgContentAdded[idx]) {
|
|
195
|
+
state.msgContentAdded[idx] = true;
|
|
196
|
+
|
|
197
|
+
emit("response.content_part.added", {
|
|
198
|
+
type: "response.content_part.added",
|
|
199
|
+
item_id: `msg_${state.responseId}_${idx}`,
|
|
200
|
+
output_index: idx,
|
|
201
|
+
content_index: 0,
|
|
202
|
+
part: { type: "output_text", annotations: [], logprobs: [], text: "" }
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
emit("response.output_text.delta", {
|
|
207
|
+
type: "response.output_text.delta",
|
|
208
|
+
item_id: `msg_${state.responseId}_${idx}`,
|
|
209
|
+
output_index: idx,
|
|
210
|
+
content_index: 0,
|
|
211
|
+
delta: content,
|
|
212
|
+
logprobs: []
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (!state.msgTextBuf[idx]) state.msgTextBuf[idx] = "";
|
|
216
|
+
state.msgTextBuf[idx] += content;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function closeMessage(state, emit, idx) {
|
|
220
|
+
if (state.msgItemAdded[idx] && !state.msgItemDone[idx]) {
|
|
221
|
+
state.msgItemDone[idx] = true;
|
|
222
|
+
const fullText = state.msgTextBuf[idx] || "";
|
|
223
|
+
const msgId = `msg_${state.responseId}_${idx}`;
|
|
224
|
+
|
|
225
|
+
emit("response.output_text.done", {
|
|
226
|
+
type: "response.output_text.done",
|
|
227
|
+
item_id: msgId,
|
|
228
|
+
output_index: parseInt(idx),
|
|
229
|
+
content_index: 0,
|
|
230
|
+
text: fullText,
|
|
231
|
+
logprobs: []
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
emit("response.content_part.done", {
|
|
235
|
+
type: "response.content_part.done",
|
|
236
|
+
item_id: msgId,
|
|
237
|
+
output_index: parseInt(idx),
|
|
238
|
+
content_index: 0,
|
|
239
|
+
part: { type: "output_text", annotations: [], logprobs: [], text: fullText }
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
emit("response.output_item.done", {
|
|
243
|
+
type: "response.output_item.done",
|
|
244
|
+
output_index: parseInt(idx),
|
|
245
|
+
item: {
|
|
246
|
+
id: msgId,
|
|
247
|
+
type: "message",
|
|
248
|
+
content: [{ type: "output_text", annotations: [], logprobs: [], text: fullText }],
|
|
249
|
+
role: "assistant"
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function emitToolCall(state, emit, tc) {
|
|
256
|
+
const tcIdx = tc.index ?? 0;
|
|
257
|
+
const newCallId = tc.id;
|
|
258
|
+
const funcName = tc.function?.name;
|
|
259
|
+
|
|
260
|
+
if (funcName) state.funcNames[tcIdx] = funcName;
|
|
261
|
+
|
|
262
|
+
if (!state.funcCallIds[tcIdx] && newCallId) {
|
|
263
|
+
state.funcCallIds[tcIdx] = newCallId;
|
|
264
|
+
|
|
265
|
+
emit("response.output_item.added", {
|
|
266
|
+
type: "response.output_item.added",
|
|
267
|
+
output_index: tcIdx,
|
|
268
|
+
item: {
|
|
269
|
+
id: `fc_${newCallId}`,
|
|
270
|
+
type: "function_call",
|
|
271
|
+
arguments: "",
|
|
272
|
+
call_id: newCallId,
|
|
273
|
+
name: state.funcNames[tcIdx] || ""
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (!state.funcArgsBuf[tcIdx]) state.funcArgsBuf[tcIdx] = "";
|
|
279
|
+
|
|
280
|
+
if (tc.function?.arguments) {
|
|
281
|
+
const refCallId = state.funcCallIds[tcIdx] || newCallId;
|
|
282
|
+
if (refCallId) {
|
|
283
|
+
emit("response.function_call_arguments.delta", {
|
|
284
|
+
type: "response.function_call_arguments.delta",
|
|
285
|
+
item_id: `fc_${refCallId}`,
|
|
286
|
+
output_index: tcIdx,
|
|
287
|
+
delta: tc.function.arguments
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
state.funcArgsBuf[tcIdx] += tc.function.arguments;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function closeToolCall(state, emit, idx) {
|
|
295
|
+
const callId = state.funcCallIds[idx];
|
|
296
|
+
if (callId && !state.funcItemDone[idx]) {
|
|
297
|
+
const args = state.funcArgsBuf[idx] || "{}";
|
|
298
|
+
|
|
299
|
+
emit("response.function_call_arguments.done", {
|
|
300
|
+
type: "response.function_call_arguments.done",
|
|
301
|
+
item_id: `fc_${callId}`,
|
|
302
|
+
output_index: parseInt(idx),
|
|
303
|
+
arguments: args
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
emit("response.output_item.done", {
|
|
307
|
+
type: "response.output_item.done",
|
|
308
|
+
output_index: parseInt(idx),
|
|
309
|
+
item: {
|
|
310
|
+
id: `fc_${callId}`,
|
|
311
|
+
type: "function_call",
|
|
312
|
+
arguments: args,
|
|
313
|
+
call_id: callId,
|
|
314
|
+
name: state.funcNames[idx] || ""
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
state.funcItemDone[idx] = true;
|
|
319
|
+
state.funcArgsDone[idx] = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function sendCompleted(state, emit) {
|
|
324
|
+
if (!state.completedSent) {
|
|
325
|
+
state.completedSent = true;
|
|
326
|
+
emit("response.completed", {
|
|
327
|
+
type: "response.completed",
|
|
328
|
+
response: {
|
|
329
|
+
id: state.responseId,
|
|
330
|
+
object: "response",
|
|
331
|
+
created_at: state.created,
|
|
332
|
+
status: "completed",
|
|
333
|
+
background: false,
|
|
334
|
+
error: null
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function flushEvents(state) {
|
|
341
|
+
if (state.completedSent) return [];
|
|
342
|
+
|
|
343
|
+
const events = [];
|
|
344
|
+
const nextSeq = () => ++state.seq;
|
|
345
|
+
const emit = (eventType, data) => {
|
|
346
|
+
data.sequence_number = nextSeq();
|
|
347
|
+
events.push({ event: eventType, data });
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
for (const i in state.msgItemAdded) closeMessage(state, emit, i);
|
|
351
|
+
closeReasoning(state, emit);
|
|
352
|
+
for (const i in state.funcCallIds) closeToolCall(state, emit, i);
|
|
353
|
+
sendCompleted(state, emit);
|
|
354
|
+
|
|
355
|
+
return events;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// currentToolCallId is intentionally sticky for the current turn so flush/completion
|
|
359
|
+
// can still finalize as tool_calls even if the tool call was emitted before stream end.
|
|
360
|
+
function computeFinishReason(state) {
|
|
361
|
+
return state.toolCallIndex > 0 || state.currentToolCallId
|
|
362
|
+
? "tool_calls"
|
|
363
|
+
: "stop";
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Translate OpenAI Responses API chunk to OpenAI Chat Completions format
|
|
368
|
+
* This is for when Codex returns data and we need to send it to an OpenAI-compatible client
|
|
369
|
+
*/
|
|
370
|
+
export function openaiResponsesToOpenAIResponse(chunk, state) {
|
|
371
|
+
if (!chunk) {
|
|
372
|
+
// Flush: send final chunk with finish_reason
|
|
373
|
+
if (state.finishReasonSent || !state.started) return null;
|
|
374
|
+
|
|
375
|
+
const finishReason = computeFinishReason(state);
|
|
376
|
+
|
|
377
|
+
state.finishReasonSent = true;
|
|
378
|
+
state.finishReason = finishReason;
|
|
379
|
+
|
|
380
|
+
const finalChunk = {
|
|
381
|
+
id: state.chatId || `chatcmpl-${Date.now()}`,
|
|
382
|
+
object: "chat.completion.chunk",
|
|
383
|
+
created: state.created || Math.floor(Date.now() / 1000),
|
|
384
|
+
model: state.model || "unknown",
|
|
385
|
+
choices: [{
|
|
386
|
+
index: 0,
|
|
387
|
+
delta: {},
|
|
388
|
+
finish_reason: finishReason
|
|
389
|
+
}]
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
if (state.usage && typeof state.usage === "object") {
|
|
393
|
+
finalChunk.usage = state.usage;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return finalChunk;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Handle different event types from Responses API
|
|
400
|
+
const eventType = chunk.type || chunk.event;
|
|
401
|
+
const data = chunk.data || chunk;
|
|
402
|
+
|
|
403
|
+
// Initialize state
|
|
404
|
+
if (!state.started) {
|
|
405
|
+
state.started = true;
|
|
406
|
+
state.chatId = `chatcmpl-${Date.now()}`;
|
|
407
|
+
state.created = Math.floor(Date.now() / 1000);
|
|
408
|
+
state.toolCallIndex = 0;
|
|
409
|
+
state.currentToolCallId = null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Text content delta
|
|
413
|
+
if (eventType === "response.output_text.delta") {
|
|
414
|
+
const delta = data.delta || "";
|
|
415
|
+
if (!delta) return null;
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
id: state.chatId,
|
|
419
|
+
object: "chat.completion.chunk",
|
|
420
|
+
created: state.created,
|
|
421
|
+
model: state.model || "unknown",
|
|
422
|
+
choices: [{
|
|
423
|
+
index: 0,
|
|
424
|
+
delta: { content: delta },
|
|
425
|
+
finish_reason: null
|
|
426
|
+
}]
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Text content done (ignore, we handle via delta)
|
|
431
|
+
if (eventType === "response.output_text.done") {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Function call started (standard function_call or custom_tool_call)
|
|
436
|
+
if (eventType === "response.output_item.added" && (data.item?.type === "function_call" || data.item?.type === "custom_tool_call")) {
|
|
437
|
+
const item = data.item;
|
|
438
|
+
state.currentToolCallId = item.call_id || `call_${Date.now()}`;
|
|
439
|
+
|
|
440
|
+
return {
|
|
441
|
+
id: state.chatId,
|
|
442
|
+
object: "chat.completion.chunk",
|
|
443
|
+
created: state.created,
|
|
444
|
+
model: state.model || "unknown",
|
|
445
|
+
choices: [{
|
|
446
|
+
index: 0,
|
|
447
|
+
delta: {
|
|
448
|
+
tool_calls: [{
|
|
449
|
+
index: state.toolCallIndex,
|
|
450
|
+
id: state.currentToolCallId,
|
|
451
|
+
type: "function",
|
|
452
|
+
function: {
|
|
453
|
+
name: item.name || "",
|
|
454
|
+
arguments: ""
|
|
455
|
+
}
|
|
456
|
+
}]
|
|
457
|
+
},
|
|
458
|
+
finish_reason: null
|
|
459
|
+
}]
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Function call arguments delta (standard or custom_tool_call variant)
|
|
464
|
+
if (eventType === "response.function_call_arguments.delta" || eventType === "response.custom_tool_call_input.delta") {
|
|
465
|
+
const argsDelta = data.delta || "";
|
|
466
|
+
if (!argsDelta) return null;
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
id: state.chatId,
|
|
470
|
+
object: "chat.completion.chunk",
|
|
471
|
+
created: state.created,
|
|
472
|
+
model: state.model || "unknown",
|
|
473
|
+
choices: [{
|
|
474
|
+
index: 0,
|
|
475
|
+
delta: {
|
|
476
|
+
tool_calls: [{
|
|
477
|
+
index: state.toolCallIndex,
|
|
478
|
+
function: { arguments: argsDelta }
|
|
479
|
+
}]
|
|
480
|
+
},
|
|
481
|
+
finish_reason: null
|
|
482
|
+
}]
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Function call done (standard or custom_tool_call variant)
|
|
487
|
+
if (eventType === "response.output_item.done" && (data.item?.type === "function_call" || data.item?.type === "custom_tool_call")) {
|
|
488
|
+
state.toolCallIndex++;
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Response completed
|
|
493
|
+
if (eventType === "response.completed" || eventType === "response.done") {
|
|
494
|
+
// Extract usage from response.completed event
|
|
495
|
+
const responseUsage = data.response?.usage;
|
|
496
|
+
if (responseUsage && typeof responseUsage === "object") {
|
|
497
|
+
const inputTokens = responseUsage.input_tokens || responseUsage.prompt_tokens || 0;
|
|
498
|
+
const outputTokens = responseUsage.output_tokens || responseUsage.completion_tokens || 0;
|
|
499
|
+
// OpenAI Responses API: input_tokens already includes cached_tokens
|
|
500
|
+
// Cache info is in input_tokens_details.cached_tokens
|
|
501
|
+
const cacheReadTokens = responseUsage.input_tokens_details?.cached_tokens || responseUsage.cache_read_input_tokens || 0;
|
|
502
|
+
|
|
503
|
+
state.usage = {
|
|
504
|
+
prompt_tokens: inputTokens,
|
|
505
|
+
completion_tokens: outputTokens,
|
|
506
|
+
total_tokens: inputTokens + outputTokens
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// Add prompt_tokens_details if cache tokens exist
|
|
510
|
+
if (cacheReadTokens > 0) {
|
|
511
|
+
state.usage.prompt_tokens_details = {
|
|
512
|
+
cached_tokens: cacheReadTokens
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (!state.finishReasonSent) {
|
|
518
|
+
const finishReason = computeFinishReason(state);
|
|
519
|
+
|
|
520
|
+
state.finishReasonSent = true;
|
|
521
|
+
state.finishReason = finishReason; // Mark for usage injection in stream.js
|
|
522
|
+
|
|
523
|
+
const finalChunk = {
|
|
524
|
+
id: state.chatId,
|
|
525
|
+
object: "chat.completion.chunk",
|
|
526
|
+
created: state.created,
|
|
527
|
+
model: state.model || "unknown",
|
|
528
|
+
choices: [{
|
|
529
|
+
index: 0,
|
|
530
|
+
delta: {},
|
|
531
|
+
finish_reason: finishReason
|
|
532
|
+
}]
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// Include usage in final chunk if available
|
|
536
|
+
if (state.usage && typeof state.usage === "object") {
|
|
537
|
+
finalChunk.usage = state.usage;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return finalChunk;
|
|
541
|
+
}
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Error events from Responses API (e.g. model_not_found)
|
|
546
|
+
if (eventType === "error" || eventType === "response.failed") {
|
|
547
|
+
// Avoid emitting duplicate errors (error + response.failed arrive back-to-back)
|
|
548
|
+
if (state.finishReasonSent) return null;
|
|
549
|
+
|
|
550
|
+
const error = data.error || data.response?.error;
|
|
551
|
+
if (error) {
|
|
552
|
+
state.error = error;
|
|
553
|
+
state.finishReasonSent = true;
|
|
554
|
+
|
|
555
|
+
// Surface the error as an OpenAI-compatible error chunk
|
|
556
|
+
return {
|
|
557
|
+
id: state.chatId || `chatcmpl-${Date.now()}`,
|
|
558
|
+
object: "chat.completion.chunk",
|
|
559
|
+
created: state.created || Math.floor(Date.now() / 1000),
|
|
560
|
+
model: state.model || "unknown",
|
|
561
|
+
choices: [{
|
|
562
|
+
index: 0,
|
|
563
|
+
delta: { content: `[Error] ${error.message || JSON.stringify(error)}` },
|
|
564
|
+
finish_reason: "stop"
|
|
565
|
+
}]
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Reasoning summary delta → emit as reasoning_content for client thinking display
|
|
572
|
+
if (eventType === "response.reasoning_summary_text.delta") {
|
|
573
|
+
const delta = data.delta || "";
|
|
574
|
+
if (!delta) return null;
|
|
575
|
+
return {
|
|
576
|
+
id: state.chatId,
|
|
577
|
+
object: "chat.completion.chunk",
|
|
578
|
+
created: state.created,
|
|
579
|
+
model: state.model || "unknown",
|
|
580
|
+
choices: [{ index: 0, delta: { reasoning_content: delta }, finish_reason: null }]
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Ignore other events
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Register both directions
|
|
589
|
+
register(FORMATS.OPENAI, FORMATS.OPENAI_RESPONSES, null, openaiToOpenAIResponsesResponse);
|
|
590
|
+
register(FORMATS.OPENAI_RESPONSES, FORMATS.OPENAI, null, openaiResponsesToOpenAIResponse);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { register } from "../index.js";
|
|
2
|
+
import { FORMATS } from "../formats.js";
|
|
3
|
+
|
|
4
|
+
// Convert OpenAI SSE chunk to Antigravity SSE format
|
|
5
|
+
// Real Antigravity format:
|
|
6
|
+
// data: {"response":{"candidates":[{"content":{"role":"model","parts":[...]}, "finishReason":"STOP"}], "usageMetadata":{...}, "modelVersion":"...", "responseId":"..."}}
|
|
7
|
+
// Tool calls: OpenAI sends incremental args across chunks → accumulate and emit ONCE at finish
|
|
8
|
+
export function openaiToAntigravityResponse(chunk, state) {
|
|
9
|
+
if (!chunk) return null;
|
|
10
|
+
|
|
11
|
+
const choice = chunk.choices?.[0];
|
|
12
|
+
if (!choice) {
|
|
13
|
+
if (chunk.usage) {
|
|
14
|
+
state._usage = chunk.usage;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const delta = choice.delta || {};
|
|
20
|
+
const finishReason = choice.finish_reason;
|
|
21
|
+
|
|
22
|
+
// Init state
|
|
23
|
+
if (!state._toolCallAccum) state._toolCallAccum = {};
|
|
24
|
+
if (!state._responseId) state._responseId = chunk.id || `resp_${Date.now()}`;
|
|
25
|
+
if (!state._modelVersion) state._modelVersion = chunk.model || "";
|
|
26
|
+
|
|
27
|
+
const parts = [];
|
|
28
|
+
|
|
29
|
+
// Thinking/reasoning → thought part
|
|
30
|
+
if (delta.reasoning_content) {
|
|
31
|
+
parts.push({ thought: true, text: delta.reasoning_content });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Text content
|
|
35
|
+
if (delta.content) {
|
|
36
|
+
parts.push({ text: delta.content });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Accumulate tool calls silently (no emit until finish)
|
|
40
|
+
if (delta.tool_calls) {
|
|
41
|
+
for (const tc of delta.tool_calls) {
|
|
42
|
+
const idx = tc.index ?? 0;
|
|
43
|
+
if (!state._toolCallAccum[idx]) {
|
|
44
|
+
state._toolCallAccum[idx] = { id: "", name: "", arguments: "" };
|
|
45
|
+
}
|
|
46
|
+
const accum = state._toolCallAccum[idx];
|
|
47
|
+
if (tc.id) accum.id = tc.id;
|
|
48
|
+
if (tc.function?.name) accum.name += tc.function.name;
|
|
49
|
+
if (tc.function?.arguments) accum.arguments += tc.function.arguments;
|
|
50
|
+
}
|
|
51
|
+
// Skip emit — wait for finish_reason
|
|
52
|
+
if (parts.length === 0 && !finishReason) return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// On finish, emit accumulated tool calls as complete functionCall parts
|
|
56
|
+
if (finishReason) {
|
|
57
|
+
const indices = Object.keys(state._toolCallAccum);
|
|
58
|
+
for (const idx of indices) {
|
|
59
|
+
const accum = state._toolCallAccum[idx];
|
|
60
|
+
let args = {};
|
|
61
|
+
try { args = JSON.parse(accum.arguments); } catch { /* empty */ }
|
|
62
|
+
// Restore original tool name if it was prefixed during cloaking
|
|
63
|
+
const originalName = state.toolNameMap?.get(accum.name) || accum.name;
|
|
64
|
+
parts.push({
|
|
65
|
+
functionCall: {
|
|
66
|
+
name: originalName,
|
|
67
|
+
args
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Skip empty non-finish chunks
|
|
74
|
+
if (parts.length === 0 && !finishReason) return null;
|
|
75
|
+
|
|
76
|
+
// Ensure at least empty text part on finish with no content
|
|
77
|
+
if (parts.length === 0 && finishReason) {
|
|
78
|
+
parts.push({ text: "" });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Build candidate
|
|
82
|
+
const candidate = { content: { role: "model", parts } };
|
|
83
|
+
|
|
84
|
+
// Finish reason mapping
|
|
85
|
+
if (finishReason) {
|
|
86
|
+
const reasonMap = {
|
|
87
|
+
"stop": "STOP",
|
|
88
|
+
"length": "MAX_TOKENS",
|
|
89
|
+
"tool_calls": "STOP",
|
|
90
|
+
"content_filter": "SAFETY"
|
|
91
|
+
};
|
|
92
|
+
candidate.finishReason = reasonMap[finishReason] || "STOP";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Build response
|
|
96
|
+
const response = {
|
|
97
|
+
candidates: [candidate],
|
|
98
|
+
modelVersion: state._modelVersion,
|
|
99
|
+
responseId: state._responseId
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Usage metadata
|
|
103
|
+
const usage = chunk.usage || state._usage;
|
|
104
|
+
if (usage) {
|
|
105
|
+
response.usageMetadata = {
|
|
106
|
+
promptTokenCount: usage.prompt_tokens || 0,
|
|
107
|
+
candidatesTokenCount: usage.completion_tokens || 0,
|
|
108
|
+
totalTokenCount: usage.total_tokens || 0
|
|
109
|
+
};
|
|
110
|
+
if (usage.completion_tokens_details?.reasoning_tokens) {
|
|
111
|
+
response.usageMetadata.thoughtsTokenCount = usage.completion_tokens_details.reasoning_tokens;
|
|
112
|
+
}
|
|
113
|
+
if (usage.prompt_tokens_details?.cached_tokens) {
|
|
114
|
+
response.usageMetadata.cachedContentTokenCount = usage.prompt_tokens_details.cached_tokens;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { response };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Register
|
|
122
|
+
register(FORMATS.OPENAI, FORMATS.ANTIGRAVITY, null, openaiToAntigravityResponse);
|