promptfoo 0.125.0 → 0.125.1
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/README.md +3 -3
- package/dist/src/accounts-BOxNYxVN.js +229 -0
- package/dist/src/accounts-BezXLdAW.cjs +276 -0
- package/dist/src/accounts-CPISMNlh.js +227 -0
- package/dist/src/accounts-vJBPs89d.js +222 -0
- package/dist/src/agentWorkspace-Bom7SpF2.js +592 -0
- package/dist/src/agentWorkspace-CEomAcws.cjs +619 -0
- package/dist/src/agentWorkspace-DPtMLrlI.js +593 -0
- package/dist/src/agentWorkspace-DkAeEYLz.js +592 -0
- package/dist/src/agentic-utils-121v7mJo.js +197 -0
- package/dist/src/agentic-utils-CBWD_rcd.cjs +237 -0
- package/dist/src/agentic-utils-D8wyQwPG.js +198 -0
- package/dist/src/agentic-utils-EP1QkQCs.js +197 -0
- package/dist/src/agents-Br3ah8iA.js +778 -0
- package/dist/src/agents-C5wj_UTv.js +777 -0
- package/dist/src/agents-C9Efp4mC.js +266 -0
- package/dist/src/agents-CQYwaVCO.js +267 -0
- package/dist/src/agents-CjCd4Vo8.js +777 -0
- package/dist/src/agents-DRWiCHYz.js +266 -0
- package/dist/src/agents-F2rhx0iL.cjs +266 -0
- package/dist/src/agents-RTYyy69h.cjs +777 -0
- package/dist/src/agents-api-CY72O86e.js +711 -0
- package/dist/src/agents-api-CsSsC21b.js +710 -0
- package/dist/src/agents-api-DN-ibDc8.js +710 -0
- package/dist/src/agents-api-cNDsCCv1.cjs +710 -0
- package/dist/src/ai.studio-Bj6Dyi6o.js +2 -0
- package/dist/src/ai.studio-C-e0LzyW.js +369 -0
- package/dist/src/ai.studio-CR8M6Aqf.cjs +391 -0
- package/dist/src/ai.studio-YKk7F0tv.js +374 -0
- package/dist/src/aimlapi-BGunsuTu.js +30 -0
- package/dist/src/aimlapi-BkzcfBsL.js +29 -0
- package/dist/src/aimlapi-DXFcEdP8.js +28 -0
- package/dist/src/aimlapi-r-8iCcAw.cjs +29 -0
- package/dist/src/anthropicMessages-7-YNRgQR.js +114 -0
- package/dist/src/anthropicMessages-C8m9Whrd.cjs +114 -0
- package/dist/src/anthropicMessages-DS1vXD0f.js +115 -0
- package/dist/src/anthropicMessages-DmvGkz-0.js +114 -0
- package/dist/src/app/assets/index-CrdXWTXm.js +392 -0
- package/dist/src/app/browser-inventory.json +4 -4
- package/dist/src/app/index.html +1 -1
- package/dist/src/audio-BLgFgyw-.cjs +104 -0
- package/dist/src/audio-C2sibT7Q.js +104 -0
- package/dist/src/audio-DXEXb03H.js +104 -0
- package/dist/src/audio-TkvojpwO.js +105 -0
- package/dist/src/authoritativeMarkupInjection-BAT9B-Wj.js +79 -0
- package/dist/src/authoritativeMarkupInjection-B_yHETKT.js +78 -0
- package/dist/src/authoritativeMarkupInjection-BfjecQ3Q.cjs +78 -0
- package/dist/src/authoritativeMarkupInjection-D-hDKrhD.js +78 -0
- package/dist/src/aws-B_9unI_-.js +1149 -0
- package/dist/src/aws-D0FY3qkc.js +2433 -0
- package/dist/src/aws-Dh1-a90n.js +2433 -0
- package/dist/src/aws-qskKGczY.cjs +2454 -0
- package/dist/src/base-CaWlBkVz.js +462 -0
- package/dist/src/base-CcViNwVs.js +255 -0
- package/dist/src/base-CsVbPJkU.cjs +467 -0
- package/dist/src/base-DNK9py25.js +255 -0
- package/dist/src/base-DlH5tjEZ.js +463 -0
- package/dist/src/base-DyLOZ_iX.js +256 -0
- package/dist/src/base-RRYXfG7l.cjs +305 -0
- package/dist/src/base-oXVgvtVn.js +462 -0
- package/dist/src/bedrock-BP17ZXbR.cjs +2 -0
- package/dist/src/bedrock-CsjM1dOt.js +1300 -0
- package/dist/src/bedrock-CzPwj8GO.js +1 -0
- package/dist/src/bedrock-eGXZw8oh.js +1 -0
- package/dist/src/bedrock-tSWjmXdj.js +2 -0
- package/dist/src/bestOfN-BQ93nUKV.js +160 -0
- package/dist/src/bestOfN-ByGGwlcb.cjs +161 -0
- package/dist/src/bestOfN-CbP7csHr.js +159 -0
- package/dist/src/bestOfN-xn6i2Xs2.js +159 -0
- package/dist/src/cache-CHq9hPz9.js +2 -0
- package/dist/src/cache-D-9eZN3I.js +754 -0
- package/dist/src/cache-DSm6t1MZ.js +741 -0
- package/dist/src/cache-DeF5zIEN.js +782 -0
- package/dist/src/cache-iG87oYan.cjs +856 -0
- package/dist/src/cerebras-CTtM4yMH.js +98 -0
- package/dist/src/cerebras-CogcJ3ce.cjs +97 -0
- package/dist/src/cerebras-DmkRypTh.js +97 -0
- package/dist/src/cerebras-GUp0B8JY.js +97 -0
- package/dist/src/chat-B4ihd3fw.js +226 -0
- package/dist/src/chat-B9cAQ_rS.js +227 -0
- package/dist/src/chat-BU7EB4R-.cjs +76 -0
- package/dist/src/chat-C8yxJ2-s.cjs +226 -0
- package/dist/src/chat-ClTFM3qq.js +934 -0
- package/dist/src/chat-Cnq0Is68.js +123 -0
- package/dist/src/chat-CwrurR57.cjs +987 -0
- package/dist/src/chat-D0lsojPv.js +124 -0
- package/dist/src/chat-D7_8yFIx.js +76 -0
- package/dist/src/chat-DCoETlLG.js +226 -0
- package/dist/src/chat-DHE7xaTR.js +76 -0
- package/dist/src/chat-DmhT6rz2.cjs +123 -0
- package/dist/src/chat-DvfMe8KI.js +123 -0
- package/dist/src/chat-DwP5kVnl.js +935 -0
- package/dist/src/chat-MB7U-QE2.js +77 -0
- package/dist/src/chat-zCWuBKAj.js +934 -0
- package/dist/src/claude-agent-sdk-23bIVI75.js +999 -0
- package/dist/src/claude-agent-sdk-BACpnIJi.cjs +1005 -0
- package/dist/src/claude-agent-sdk-BlYlmcEr.js +999 -0
- package/dist/src/claude-agent-sdk-Cr-jqJZl.js +1000 -0
- package/dist/src/client-BktbiPx9.cjs +357 -0
- package/dist/src/client-CjztEBmW.js +351 -0
- package/dist/src/client-mRs2UvH9.js +351 -0
- package/dist/src/client-uCz0ydjC.js +352 -0
- package/dist/src/cloud-BtYF555L.js +2 -0
- package/dist/src/cloud-CVSUEmAy.js +287 -0
- package/dist/src/cloud-D7Ifb-Fl.js +599 -0
- package/dist/src/cloud-DB5oK5NX.cjs +666 -0
- package/dist/src/cloud-ecu989Em.js +657 -0
- package/dist/src/cloud-ramjGURF.js +599 -0
- package/dist/src/cloudflare-ai-BfDkIjO8.js +133 -0
- package/dist/src/cloudflare-ai-D9HaXz1M.js +134 -0
- package/dist/src/cloudflare-ai-HrD5WUK8.js +132 -0
- package/dist/src/cloudflare-ai-Qdj8aKP2.cjs +133 -0
- package/dist/src/cloudflare-gateway-C81uKETQ.js +276 -0
- package/dist/src/cloudflare-gateway-CX5Z9X0k.js +276 -0
- package/dist/src/cloudflare-gateway-DW-og8gb.js +277 -0
- package/dist/src/cloudflare-gateway-iRyXo9n2.cjs +276 -0
- package/dist/src/codex-app-server-BFIrSgdy.js +2155 -0
- package/dist/src/codex-app-server-By1eDVD4.js +2 -0
- package/dist/src/codex-app-server-DKsF4qmY.js +2156 -0
- package/dist/src/codex-app-server-n7n4uZzC.cjs +2162 -0
- package/dist/src/codex-app-server-xAoELVxu.js +2155 -0
- package/dist/src/codex-sdk-C2ZLxa6r.js +1552 -0
- package/dist/src/codex-sdk-CzG02tQt.cjs +1588 -0
- package/dist/src/codex-sdk-DNxAOhiV.js +2 -0
- package/dist/src/codex-sdk-DT3aQezK.js +1557 -0
- package/dist/src/codex-sdk-pw9DpcJP.js +1557 -0
- package/dist/src/codex-security-B0bLmXJF.js +406 -0
- package/dist/src/codex-security-BhYs-3iY.js +406 -0
- package/dist/src/codex-security-DQcOfxYW.js +407 -0
- package/dist/src/codex-security-DsCWr6GZ.cjs +411 -0
- package/dist/src/cometapi-B16asPLX.cjs +55 -0
- package/dist/src/cometapi-MgTbZA_H.js +53 -0
- package/dist/src/cometapi-i33vKzPV.js +55 -0
- package/dist/src/cometapi-wK2UWK0X.js +56 -0
- package/dist/src/compatible-COj8ZCy9.js +24 -0
- package/dist/src/compatible-CRSsIUGb.cjs +24 -0
- package/dist/src/compatible-Dy1vCcNF.js +25 -0
- package/dist/src/compatible-aUItQrpk.js +24 -0
- package/dist/src/completion-Bn7COFMk.js +119 -0
- package/dist/src/completion-Bub2N48b.js +118 -0
- package/dist/src/completion-Cf2G9OlM.cjs +123 -0
- package/dist/src/conversationScoring-BiTYJ9MD.js +374 -0
- package/dist/src/conversationScoring-CKL47uIu.js +373 -0
- package/dist/src/conversationScoring-DCvQKp6k.cjs +398 -0
- package/dist/src/conversationScoring-DLNJtDZI.js +373 -0
- package/dist/src/crescendo-5iLk9WiJ.cjs +734 -0
- package/dist/src/crescendo-B5ylG7kW.js +733 -0
- package/dist/src/crescendo-BD7k6TIx.js +730 -0
- package/dist/src/crescendo-DqO2Ch0P.js +732 -0
- package/dist/src/custom-8rv_aG2K.js +617 -0
- package/dist/src/custom-BOtrIHFN.js +619 -0
- package/dist/src/custom-BvN8seCs.cjs +620 -0
- package/dist/src/custom-Cld9v_Y4.js +618 -0
- package/dist/src/dataUrl-BdHUey2l.cjs +3187 -0
- package/dist/src/dataUrl-DBMifX6C.js +3133 -0
- package/dist/src/dataUrl-DUSr-ZvI.js +2868 -0
- package/dist/src/decisions-CLazADTw.js +516 -0
- package/dist/src/decisions-D5X93awq.js +515 -0
- package/dist/src/decisions-DmaeArEn.js +515 -0
- package/dist/src/decisions-DyQJyHJz.cjs +514 -0
- package/dist/src/docker-C9NYQFeu.js +94 -0
- package/dist/src/docker-CGq3mMol.cjs +94 -0
- package/dist/src/docker-DOm7nmpl.js +95 -0
- package/dist/src/docker-skFN-Kfo.js +93 -0
- package/dist/src/embedding-0UbzkTk9.js +82 -0
- package/dist/src/embedding-DTrSDt7k.cjs +86 -0
- package/dist/src/embedding-j2ORNl5H.js +81 -0
- package/dist/src/envoy-BvS8XTQO.js +60 -0
- package/dist/src/envoy-Cn6Hzw0e.js +60 -0
- package/dist/src/envoy-DC3KWcUY.cjs +60 -0
- package/dist/src/envoy-DetHjo5B.js +61 -0
- package/dist/src/eval-Cer9dPe9.js +1920 -0
- package/dist/src/eval-CytYmI2Z.js +2 -0
- package/dist/src/evalResult-DzOq5wt9.js +1300 -0
- package/dist/src/evaluator-BxCmvGtv.js +10578 -0
- package/dist/src/evaluator-Ct7YDELm.js +2 -0
- package/dist/src/evaluatorHelpers-B_AwIrsl.js +600 -0
- package/dist/src/evaluatorHelpers-D1Tpc7gd.js +601 -0
- package/dist/src/evaluatorHelpers-DRR3rLq0.cjs +622 -0
- package/dist/src/fetch-B5KxZuKu.js +1559 -0
- package/dist/src/fetch-BG_Jl7ty.js +1556 -0
- package/dist/src/fetch-BKlgUg08.cjs +1853 -0
- package/dist/src/fetch-C9Fsja0R.js +2 -0
- package/dist/src/fetch-CM7P8KWA.cjs +14 -0
- package/dist/src/fetch-D0FkIB3G.js +9 -0
- package/dist/src/fetch-RXHsZF-J.js +1280 -0
- package/dist/src/fetch-rSECy8jR.js +10 -0
- package/dist/src/functionCallbackUtils-BB9tmf6a.cjs +262 -0
- package/dist/src/functionCallbackUtils-BXk2iY01.js +246 -0
- package/dist/src/functionCallbackUtils-B_cYp7P5.js +245 -0
- package/dist/src/functionCallbackUtils-BfXnPo0o.js +245 -0
- package/dist/src/gemini-image-BXLMADDz.js +471 -0
- package/dist/src/gemini-image-BYUZyEUx.js +472 -0
- package/dist/src/gemini-image-DSt1QubZ.cjs +471 -0
- package/dist/src/gemini-image-DdNDMiZ_.js +471 -0
- package/dist/src/goat-9b-uU_k6.js +514 -0
- package/dist/src/goat-BCJuiDd0.js +515 -0
- package/dist/src/goat-CmAHbemm.js +512 -0
- package/dist/src/goat-DdOTdyoS.cjs +515 -0
- package/dist/src/goblin-Bp5C5lyb.js +22 -0
- package/dist/src/goblin-Dmr7GItI.js +23 -0
- package/dist/src/goblin-DpM8wxlf.cjs +22 -0
- package/dist/src/goblin-cJyH6Pq-.js +22 -0
- package/dist/src/google-B6eaPAbE.js +142 -0
- package/dist/src/google-D-FStdN6.cjs +142 -0
- package/dist/src/google-DAC7BsCW.js +142 -0
- package/dist/src/google-Id18H0Va.js +143 -0
- package/dist/src/graders-BjNQWkaB.js +2 -0
- package/dist/src/graders-CqdIp_vl.js +15470 -0
- package/dist/src/hydra-6Ouh74DE.js +610 -0
- package/dist/src/hydra-BHjhZnLB.cjs +612 -0
- package/dist/src/hydra-BL6k2REV.js +2 -0
- package/dist/src/hydra-BWUc0o67.js +613 -0
- package/dist/src/hydra-CUkEOLKw.js +612 -0
- package/dist/src/image-B6hG_xhb.js +481 -0
- package/dist/src/image-BFaq7Krd.cjs +209 -0
- package/dist/src/image-Bql5C0N9.cjs +504 -0
- package/dist/src/image-BtZfI2pT.js +163 -0
- package/dist/src/image-CIM4oN7Z.cjs +163 -0
- package/dist/src/image-CbAl7Jpu.js +209 -0
- package/dist/src/image-CiYm_yFw.js +209 -0
- package/dist/src/image-DCMNvBiV.js +163 -0
- package/dist/src/image-DL7pIuUZ.js +210 -0
- package/dist/src/image-ey0kxF8o.js +164 -0
- package/dist/src/image-smgIk3rE.js +482 -0
- package/dist/src/index.cjs +27 -27
- package/dist/src/index.d.cts +8 -8
- package/dist/src/index.js +27 -27
- package/dist/src/indirectWebPwn-B_-UpWY5.js +285 -0
- package/dist/src/indirectWebPwn-Cz3SLiEq.js +434 -0
- package/dist/src/indirectWebPwn-D2s8zGiM.cjs +463 -0
- package/dist/src/indirectWebPwn-DXbj2wGu.cjs +285 -0
- package/dist/src/indirectWebPwn-D_4H44E6.js +285 -0
- package/dist/src/indirectWebPwn-L044SrpV.js +434 -0
- package/dist/src/indirectWebPwn-cnmvdavH.js +435 -0
- package/dist/src/indirectWebPwn-zUBzsqTt.js +286 -0
- package/dist/src/interactions-Bu3oVQ-j.js +850 -0
- package/dist/src/interactions-CND010Lh.cjs +850 -0
- package/dist/src/interactions-DAx7tqUz.js +851 -0
- package/dist/src/interactions-DPkIumeh.js +850 -0
- package/dist/src/iterative-BO4JRnpG.js +545 -0
- package/dist/src/iterative-CAK-k9rz.js +548 -0
- package/dist/src/iterative-CDgHc0xO.cjs +549 -0
- package/dist/src/iterative-CXJlHLl9.js +547 -0
- package/dist/src/iterativeImage-BEdGKSmh.cjs +419 -0
- package/dist/src/iterativeImage-BfL0QZw5.js +417 -0
- package/dist/src/iterativeImage-C9KhnibC.js +417 -0
- package/dist/src/iterativeImage-btjkOfWG.js +418 -0
- package/dist/src/iterativeMeta-B5Bdw6QA.js +437 -0
- package/dist/src/iterativeMeta-C3mI4gpT.js +440 -0
- package/dist/src/iterativeMeta-Co2BKyqS.cjs +439 -0
- package/dist/src/iterativeMeta-DD8ihRWD.js +439 -0
- package/dist/src/iterativeTree-AMi4GV2O.js +878 -0
- package/dist/src/iterativeTree-C8FJOEje.cjs +879 -0
- package/dist/src/iterativeTree-CvrY1f2Z.js +877 -0
- package/dist/src/iterativeTree-bPtESmaD.js +876 -0
- package/dist/src/knowledgeBase-Cf5871e3.js +163 -0
- package/dist/src/knowledgeBase-D2PQhqLH.js +164 -0
- package/dist/src/knowledgeBase-DpoMw1IH.cjs +163 -0
- package/dist/src/knowledgeBase-npGFl763.js +163 -0
- package/dist/src/litellm-BBB5DQdt.cjs +146 -0
- package/dist/src/litellm-Bo43ow7r.js +145 -0
- package/dist/src/litellm-CaU8CMLS.js +146 -0
- package/dist/src/litellm-wY7Unh8o.js +147 -0
- package/dist/src/live-5g2w-M-E.js +891 -0
- package/dist/src/live-BfaXsDyD.cjs +891 -0
- package/dist/src/live-C1xewnGD.js +2 -0
- package/dist/src/live-DaF7nYy5.js +892 -0
- package/dist/src/live-lp3urLUw.js +891 -0
- package/dist/src/luma-ray-B7zvKGVG.js +309 -0
- package/dist/src/luma-ray-DCf5fnrz.cjs +309 -0
- package/dist/src/luma-ray-DepBcn6z.js +309 -0
- package/dist/src/luma-ray-XQC4M1pt.js +310 -0
- package/dist/src/main.js +26 -26
- package/dist/src/mantleChat-7xm95vSV.js +154 -0
- package/dist/src/mantleChat-CXhAs5RD.js +155 -0
- package/dist/src/mantleChat-CcE-zjfj.cjs +154 -0
- package/dist/src/mantleChat-Cpefl7Zm.js +154 -0
- package/dist/src/mcp-B0V0ikdM.js +84 -0
- package/dist/src/mcp-CV2k2gwj.js +85 -0
- package/dist/src/memoryPoisoning-BC5FQQWZ.js +111 -0
- package/dist/src/memoryPoisoning-BDwrtZKX.js +111 -0
- package/dist/src/memoryPoisoning-BFemS_FF.js +112 -0
- package/dist/src/memoryPoisoning-DRs2rbVV.cjs +111 -0
- package/dist/src/messages-Bc5oZoAJ.js +1128 -0
- package/dist/src/messages-BkaH8fRW.js +1127 -0
- package/dist/src/messages-CoHlziS5.js +1127 -0
- package/dist/src/messages-Cv_m6kYs.cjs +1161 -0
- package/dist/src/mischievousUser-BcyFxrqJ.js +51 -0
- package/dist/src/mischievousUser-BlhOQSd2.js +52 -0
- package/dist/src/mischievousUser-BuQiKE8D.js +51 -0
- package/dist/src/mischievousUser-ChIOk6cT.cjs +51 -0
- package/dist/src/modelslab-BXIWBTgX.js +171 -0
- package/dist/src/modelslab-ChVsUiaJ.js +170 -0
- package/dist/src/modelslab-DZ6BFlDv.js +170 -0
- package/dist/src/modelslab-DhRr-vyo.cjs +170 -0
- package/dist/src/nova-reel-BL8DrN4_.js +272 -0
- package/dist/src/nova-reel-BiOMUm5q.cjs +272 -0
- package/dist/src/nova-reel-CTsya1hV.js +273 -0
- package/dist/src/nova-reel-kgBY4Svd.js +272 -0
- package/dist/src/nova-sonic-CaSSA3Jq.cjs +374 -0
- package/dist/src/nova-sonic-DLpmoGsR.js +375 -0
- package/dist/src/nova-sonic-DwWc4SoN.js +374 -0
- package/dist/src/nova-sonic-qnReTaXm.js +374 -0
- package/dist/src/novita-B5mAt3Ui.js +114 -0
- package/dist/src/novita-D57vCjDD.js +116 -0
- package/dist/src/novita-ITRtG8IJ.js +115 -0
- package/dist/src/novita-Rh3T13YO.cjs +115 -0
- package/dist/src/nscale-8V7iZ_pI.js +210 -0
- package/dist/src/nscale-BQnMv4pH.cjs +209 -0
- package/dist/src/nscale-BWZXHZVF.js +209 -0
- package/dist/src/nscale-BqrHiUqU.js +207 -0
- package/dist/src/openaiResponses-BMtGTu8R.js +317 -0
- package/dist/src/openaiResponses-CvcI_viE.js +318 -0
- package/dist/src/openaiResponses-DYPZEMX1.cjs +318 -0
- package/dist/src/openaiResponses-DZTg1-kb.js +319 -0
- package/dist/src/openclaw-BeKuig4g.js +1338 -0
- package/dist/src/openclaw-COkdQ83y.js +1337 -0
- package/dist/src/openclaw-CSoX_HQ5.cjs +1344 -0
- package/dist/src/openclaw-DJlhPGCb.js +1336 -0
- package/dist/src/opencode-sdk-BEJftEs6.cjs +1018 -0
- package/dist/src/opencode-sdk-DMvBB3V7.js +1013 -0
- package/dist/src/opencode-sdk-Df7hMjLO.js +1012 -0
- package/dist/src/opencode-sdk-bQp5Xf3W.js +1012 -0
- package/dist/src/openinterpreter-B3GgVZjK.js +431 -0
- package/dist/src/openinterpreter-BiGcU-HN.cjs +435 -0
- package/dist/src/openinterpreter-Buj2l3Eh.js +432 -0
- package/dist/src/openinterpreter-C3_Cg5b_.js +431 -0
- package/dist/src/pricing-0Pampf0q.cjs +999 -0
- package/dist/src/pricing-B8VdhEhY.js +976 -0
- package/dist/src/pricing-CtLA-rKA.js +976 -0
- package/dist/src/promptfoo-4OkHtH9P.cjs +341 -0
- package/dist/src/promptfoo-Bhpm7sH6.js +286 -0
- package/dist/src/promptfoo-BqV8ogVA.js +285 -0
- package/dist/src/promptfoo-S1Q9OHk_.js +286 -0
- package/dist/src/providers-B5zs1ZRv.js +24437 -0
- package/dist/src/providers-Cd6CJh6m.js +2 -0
- package/dist/src/providers-CpJlgHET.js +24039 -0
- package/dist/src/providers-CzvLvK6G.cjs +24180 -0
- package/dist/src/quiverai-1E_IvLHn.js +325 -0
- package/dist/src/quiverai-BXH004Vv.js +325 -0
- package/dist/src/quiverai-Ccya2z8Y.cjs +325 -0
- package/dist/src/quiverai-Cez57oe-.js +326 -0
- package/dist/src/registry-3zX_M9Ik.js +131 -0
- package/dist/src/registry-AuCrKTvS.js +132 -0
- package/dist/src/registry-CxXWKtQG.js +131 -0
- package/dist/src/registry-DG3o66JQ.cjs +131 -0
- package/dist/src/remoteGeneration-CAtvamG6.js +370 -0
- package/dist/src/remoteGeneration-CF225pDl.cjs +482 -0
- package/dist/src/remoteGeneration-DtnqocnL.js +370 -0
- package/dist/src/remoteGeneration-g3KvW-sP.js +371 -0
- package/dist/src/responses-BMbaUXQI.js +1098 -0
- package/dist/src/responses-B_TOSof-.js +1099 -0
- package/dist/src/responses-v-yANwTA.cjs +1109 -0
- package/dist/src/runtimeTransform-BBZv-oUZ.js +156 -0
- package/dist/src/runtimeTransform-DT2v5ovW.js +156 -0
- package/dist/src/runtimeTransform-GXXEIXdS.cjs +161 -0
- package/dist/src/runtimeTransform-JTwBQc-P.js +157 -0
- package/dist/src/sagemaker-B8D0L4rj.cjs +716 -0
- package/dist/src/sagemaker-CR2_AGdB.js +713 -0
- package/dist/src/sagemaker-Cd9qSQUV.js +714 -0
- package/dist/src/sagemaker-mKlltN4p.js +713 -0
- package/dist/src/scanner-PG_8lh8r.js +1971 -0
- package/dist/src/server/index.js +55 -55
- package/dist/src/server-Bmh7sd9F.js +155 -0
- package/dist/src/server-C7b8z6aC.js +63 -0
- package/dist/src/server-CAcovgtL.js +2 -0
- package/dist/src/server-CuuMfKlh.cjs +74 -0
- package/dist/src/server-DMPCj9jy.js +189 -0
- package/dist/src/session-BksXvRH_.cjs +69 -0
- package/dist/src/session-DOxUjqGQ.js +63 -0
- package/dist/src/session-Dujsc-b9.js +62 -0
- package/dist/src/session-VjtIxREd.js +62 -0
- package/dist/src/shared-Bkyz_7e5.cjs +2185 -0
- package/dist/src/shared-DDJg8ycC.js +1929 -0
- package/dist/src/shared-Dh3yfRBd.js +1927 -0
- package/dist/src/shared-tfPT8Tna.js +1928 -0
- package/dist/src/simulatedUser-6JdkyL3k.cjs +252 -0
- package/dist/src/simulatedUser-CFr2mr3M.js +248 -0
- package/dist/src/simulatedUser-DjwwUqx-.js +247 -0
- package/dist/src/slack-C_gIYiUs.js +144 -0
- package/dist/src/slack-DhNbz9CM.cjs +144 -0
- package/dist/src/slack-Dm2iI1zu.js +145 -0
- package/dist/src/strategies-BIY-bNul.js +2248 -0
- package/dist/src/strategies-C1KQQj9G.cjs +2420 -0
- package/dist/src/strategies-DM_3mReG.js +2385 -0
- package/dist/src/telemetry-BhMTibZO.js +2 -0
- package/dist/src/telemetry-C04d25BM.cjs +216 -0
- package/dist/src/telemetry-CIqy4fSC.js +201 -0
- package/dist/src/telemetry-CXozp_6C.js +205 -0
- package/dist/src/telemetry-g7PkBxmY.js +205 -0
- package/dist/src/togetherai-BvCim68-.js +50 -0
- package/dist/src/togetherai-CWyDCA9m.cjs +49 -0
- package/dist/src/togetherai-CeSE31vK.js +49 -0
- package/dist/src/togetherai-_2W0URf8.js +48 -0
- package/dist/src/traceContext-Brw3Oe41.js +1016 -0
- package/dist/src/traceContext-DpAYv27G.js +1015 -0
- package/dist/src/traceContext-KSqhzZI2.cjs +1032 -0
- package/dist/src/transcription-BySopazW.js +175 -0
- package/dist/src/transcription-DO4UPkRI.cjs +178 -0
- package/dist/src/transcription-RJGBa-pC.js +176 -0
- package/dist/src/transcription-fZenF3G5.js +175 -0
- package/dist/src/transform-BzhRc5z2.js +125 -0
- package/dist/src/transform-CPQu05u6.cjs +154 -0
- package/dist/src/transform-DAED8imp.js +126 -0
- package/dist/src/transform-DIOIQDmM.js +125 -0
- package/dist/src/typesafe-ByE0Kxfg.js +253 -0
- package/dist/src/typesafe-CFqGFY34.js +253 -0
- package/dist/src/typesafe-DCWIw-CP.cjs +253 -0
- package/dist/src/typesafe-DyHFV5Qk.js +254 -0
- package/dist/src/util-BHkj9joz.js +2049 -0
- package/dist/src/util-CICwIpmu.cjs +934 -0
- package/dist/src/util-CePiY2xZ.js +286 -0
- package/dist/src/util-CgT3uf4p.js +743 -0
- package/dist/src/util-Cj9drvOY.js +1770 -0
- package/dist/src/util-ClJRjlQA.cjs +357 -0
- package/dist/src/util-Cxf8VF2M.js +395 -0
- package/dist/src/util-D7RdV7rS.js +395 -0
- package/dist/src/util-DMNFhk47.js +351 -0
- package/dist/src/util-DNzh3M0z.js +396 -0
- package/dist/src/util-Df7rfMGb.cjs +2305 -0
- package/dist/src/util-Kf0KnG_6.js +2051 -0
- package/dist/src/util-LEbeiYw_.js +743 -0
- package/dist/src/util-WH8CgVs4.js +352 -0
- package/dist/src/util-cx6Xw8Lw.cjs +478 -0
- package/dist/src/util-qzBqirBH.js +2050 -0
- package/dist/src/vertex-CBAMfRz3.js +854 -0
- package/dist/src/vertex-CMP2IpN9.js +2 -0
- package/dist/src/vertex-CZ5YOotT.js +848 -0
- package/dist/src/vertex-DNsh1F1M.cjs +871 -0
- package/dist/src/vertexLive-BTXYj3-F.js +55 -0
- package/dist/src/vertexLive-Ba_LAqEF.cjs +55 -0
- package/dist/src/vertexLive-DM4sFaaj.js +56 -0
- package/dist/src/vertexLive-JqZOw7HC.js +55 -0
- package/dist/src/video-BY7Q2Gii.cjs +706 -0
- package/dist/src/video-CYElP-CK.js +703 -0
- package/dist/src/video-C_AdEDH0.js +702 -0
- package/dist/src/video-DGvjQ_4j.js +702 -0
- package/package.json +1 -1
- package/dist/src/accounts-Dpb43yde.cjs +0 -276
- package/dist/src/accounts-GKrO1olH.js +0 -229
- package/dist/src/accounts-e4FGOsji.js +0 -227
- package/dist/src/accounts-sUiEJfkB.js +0 -222
- package/dist/src/agentWorkspace-B8A_wuMR.cjs +0 -619
- package/dist/src/agentWorkspace-DSPIscXR.js +0 -593
- package/dist/src/agentWorkspace-DxUqd-XK.js +0 -592
- package/dist/src/agentWorkspace-n0uOJXhD.js +0 -592
- package/dist/src/agentic-utils-9bCj4twQ.js +0 -197
- package/dist/src/agentic-utils-CyCLuLoj.js +0 -197
- package/dist/src/agentic-utils-D23qtOlx.cjs +0 -237
- package/dist/src/agentic-utils-DuBMMNCw.js +0 -198
- package/dist/src/agents-6hDRNoYD.js +0 -777
- package/dist/src/agents-B8w2o7Sc.cjs +0 -777
- package/dist/src/agents-Ck0NXl7v.js +0 -777
- package/dist/src/agents-CwT3B1qB.js +0 -778
- package/dist/src/agents-DOLjfOEq.js +0 -266
- package/dist/src/agents-OcF9hq--.js +0 -267
- package/dist/src/agents-api-CnZZt8bn.cjs +0 -710
- package/dist/src/agents-api-D04u3bmL.js +0 -711
- package/dist/src/agents-api-DWw0_Vio.js +0 -710
- package/dist/src/agents-api-IWHEwp8i.js +0 -710
- package/dist/src/agents-mHt2Mh9O.cjs +0 -266
- package/dist/src/agents-sICccZCA.js +0 -266
- package/dist/src/ai.studio-Ci4rypDT.js +0 -2
- package/dist/src/ai.studio-KkQ6KaHa.js +0 -369
- package/dist/src/ai.studio-gSXK2cGI.js +0 -374
- package/dist/src/ai.studio-nQF_B4DH.cjs +0 -391
- package/dist/src/aimlapi-BeSk5BDV.js +0 -30
- package/dist/src/aimlapi-CzNUhdKu.cjs +0 -29
- package/dist/src/aimlapi-DCkazDPI.js +0 -29
- package/dist/src/aimlapi-WeH5B6K1.js +0 -28
- package/dist/src/anthropicMessages-AcNWTpYO.js +0 -115
- package/dist/src/anthropicMessages-BUtvzbpL.js +0 -114
- package/dist/src/anthropicMessages-DTWhZDCd.js +0 -114
- package/dist/src/anthropicMessages-lGVnSgyx.cjs +0 -114
- package/dist/src/app/assets/index-CyEI5aDN.js +0 -392
- package/dist/src/audio-BE_Duiu1.js +0 -104
- package/dist/src/audio-CiUd00k2.cjs +0 -104
- package/dist/src/audio-Dop6omna.js +0 -105
- package/dist/src/audio-EZNTInr_.js +0 -104
- package/dist/src/authoritativeMarkupInjection-BUqH6hNk.js +0 -78
- package/dist/src/authoritativeMarkupInjection-BmbJdJO0.cjs +0 -78
- package/dist/src/authoritativeMarkupInjection-Cpz12Y3w.js +0 -78
- package/dist/src/authoritativeMarkupInjection-W4XfcH91.js +0 -79
- package/dist/src/aws-B2Jqbnet.js +0 -2433
- package/dist/src/aws-DHtuUIzQ.js +0 -1149
- package/dist/src/aws-DLqXP6wY.js +0 -2433
- package/dist/src/aws-DfduhmwL.cjs +0 -2454
- package/dist/src/base-B9L2Xvpc.js +0 -255
- package/dist/src/base-BTZnIsuH.cjs +0 -305
- package/dist/src/base-BhaWNQPJ.js +0 -462
- package/dist/src/base-Br-G_Xou.js +0 -256
- package/dist/src/base-Bzo8hiUS.cjs +0 -467
- package/dist/src/base-C82fd2jq.js +0 -463
- package/dist/src/base-CRdQwC1W.js +0 -462
- package/dist/src/base-CjGwZNOQ.js +0 -255
- package/dist/src/bedrock-BdMru_ro.js +0 -1300
- package/dist/src/bedrock-CBUmfLX1.cjs +0 -2
- package/dist/src/bedrock-DBDxBaF9.js +0 -2
- package/dist/src/bedrock-DDrECM21.js +0 -1
- package/dist/src/bedrock-DVwkgvRS.js +0 -1
- package/dist/src/bestOfN-AKF5beq4.js +0 -159
- package/dist/src/bestOfN-C1UIVGJV.js +0 -160
- package/dist/src/bestOfN-DlkETbXy.cjs +0 -161
- package/dist/src/bestOfN-XIfEgU-g.js +0 -159
- package/dist/src/cache-BZaVoKaA.js +0 -2
- package/dist/src/cache-CEYhFUsH.js +0 -741
- package/dist/src/cache-Cbw1zH6q.js +0 -782
- package/dist/src/cache-CdaZNb75.js +0 -754
- package/dist/src/cache-DpuIzPxh.cjs +0 -856
- package/dist/src/cerebras-Bpn6FPkJ.js +0 -97
- package/dist/src/cerebras-CqJ0BRCJ.cjs +0 -97
- package/dist/src/cerebras-D4ILa_TY.js +0 -97
- package/dist/src/cerebras-DR8uc7ee.js +0 -98
- package/dist/src/chat-B7PZfaYp.cjs +0 -987
- package/dist/src/chat-BVuSjdEb.js +0 -227
- package/dist/src/chat-BsaZRjXN.js +0 -76
- package/dist/src/chat-C5liqe3Y.js +0 -226
- package/dist/src/chat-C9hyHf5B.js +0 -124
- package/dist/src/chat-CFLalAck.js +0 -226
- package/dist/src/chat-CN8JGrHu.js +0 -76
- package/dist/src/chat-CaHBBpCb.js +0 -123
- package/dist/src/chat-CcbLSghx.js +0 -123
- package/dist/src/chat-CoSN6sr2.js +0 -934
- package/dist/src/chat-CsJRFX8a.cjs +0 -226
- package/dist/src/chat-DFoZLvO_.js +0 -934
- package/dist/src/chat-DiLQvL7r.js +0 -77
- package/dist/src/chat-F6qVSDk3.cjs +0 -123
- package/dist/src/chat-Oq4FaJgI.cjs +0 -76
- package/dist/src/chat-knMfQUKz.js +0 -935
- package/dist/src/claude-agent-sdk-CJkOLpnI.js +0 -999
- package/dist/src/claude-agent-sdk-Ckn76PRD.js +0 -999
- package/dist/src/claude-agent-sdk-DX0gTr11.cjs +0 -1005
- package/dist/src/claude-agent-sdk-LMeikxoR.js +0 -1000
- package/dist/src/client-BFf1r6Z8.js +0 -352
- package/dist/src/client-CdXyDdDi.js +0 -351
- package/dist/src/client-DV8XMu7i.js +0 -351
- package/dist/src/client-iEXtOBKW.cjs +0 -357
- package/dist/src/cloud-B02qcpjf.js +0 -2
- package/dist/src/cloud-BlHP-g1v.cjs +0 -666
- package/dist/src/cloud-C9BI4isF.js +0 -287
- package/dist/src/cloud-CTTLNdvj.js +0 -657
- package/dist/src/cloud-D5X5yQ_d.js +0 -599
- package/dist/src/cloud-QxPkpsHA.js +0 -599
- package/dist/src/cloudflare-ai-DRTRT1fc.js +0 -132
- package/dist/src/cloudflare-ai-DgaXapAV.cjs +0 -133
- package/dist/src/cloudflare-ai-DkuJXijS.js +0 -134
- package/dist/src/cloudflare-ai-wy9QCHku.js +0 -133
- package/dist/src/cloudflare-gateway-9cAN8g29.cjs +0 -276
- package/dist/src/cloudflare-gateway-BVFMD292.js +0 -277
- package/dist/src/cloudflare-gateway-BuUI4p6I.js +0 -276
- package/dist/src/cloudflare-gateway-TlYHizbW.js +0 -276
- package/dist/src/codex-app-server-BPz_feug.cjs +0 -2162
- package/dist/src/codex-app-server-C9noXM9C.js +0 -2155
- package/dist/src/codex-app-server-CEmD-Y5U.js +0 -2
- package/dist/src/codex-app-server-DZolc18r.js +0 -2156
- package/dist/src/codex-app-server-Dd0A37nO.js +0 -2155
- package/dist/src/codex-sdk-BbxjBvBk.cjs +0 -1588
- package/dist/src/codex-sdk-BpXeIs-_.js +0 -1557
- package/dist/src/codex-sdk-BtQp5X0f.js +0 -1552
- package/dist/src/codex-sdk-CH0v9Bk1.js +0 -2
- package/dist/src/codex-sdk-CgrN7JB8.js +0 -1557
- package/dist/src/codex-security-B5fENNUr.js +0 -406
- package/dist/src/codex-security-C6uuJx-y.cjs +0 -411
- package/dist/src/codex-security-CifWtZR_.js +0 -407
- package/dist/src/codex-security-Kg2bOEKy.js +0 -406
- package/dist/src/cometapi-BFpIDLIx.js +0 -55
- package/dist/src/cometapi-C6O2PIrN.js +0 -56
- package/dist/src/cometapi-D5Yupc6F.js +0 -53
- package/dist/src/cometapi-DzgIwJzJ.cjs +0 -55
- package/dist/src/compatible-0jhmVfOp.js +0 -25
- package/dist/src/compatible-DdtwWdJi.cjs +0 -24
- package/dist/src/compatible-Di4nR3sU.js +0 -24
- package/dist/src/compatible-iJKLWdnf.js +0 -24
- package/dist/src/completion-B0_hVUDG.js +0 -119
- package/dist/src/completion-BdI6v0-Q.cjs +0 -123
- package/dist/src/completion-CWcJscwv.js +0 -118
- package/dist/src/conversationScoring-99EOPJRa.js +0 -373
- package/dist/src/conversationScoring-BIq4J0Cq.js +0 -374
- package/dist/src/conversationScoring-DARyeATr.cjs +0 -398
- package/dist/src/conversationScoring-DS48t4Hb.js +0 -373
- package/dist/src/crescendo-CebvXIu4.js +0 -730
- package/dist/src/crescendo-CxrLS0oo.js +0 -732
- package/dist/src/crescendo-DZQXBSkj.js +0 -733
- package/dist/src/crescendo-wjEx68uD.cjs +0 -734
- package/dist/src/custom-BiQ-aUNw.cjs +0 -620
- package/dist/src/custom-ByyB5Z93.js +0 -619
- package/dist/src/custom-C5jOevNb.js +0 -617
- package/dist/src/custom-CCrsCz8o.js +0 -618
- package/dist/src/dataUrl-C9J7wz9H.js +0 -3133
- package/dist/src/dataUrl-CGsBT7UZ.cjs +0 -3187
- package/dist/src/dataUrl-CzKvvWNO.js +0 -2868
- package/dist/src/decisions-BTusXCUx.cjs +0 -514
- package/dist/src/decisions-BYtL9edD.js +0 -515
- package/dist/src/decisions-jYix_gCF.js +0 -515
- package/dist/src/decisions-nxxfHRAN.js +0 -516
- package/dist/src/docker-DDIv4zkg.js +0 -93
- package/dist/src/docker-DVLp_5OG.js +0 -94
- package/dist/src/docker-INm9w0SY.cjs +0 -94
- package/dist/src/docker-sGuoCul_.js +0 -95
- package/dist/src/embedding-CAhqLLrR.js +0 -82
- package/dist/src/embedding-D94GAsti.cjs +0 -86
- package/dist/src/embedding-zb4MAzQy.js +0 -81
- package/dist/src/envoy-BMPszwEa.cjs +0 -60
- package/dist/src/envoy-Bp-s39_8.js +0 -60
- package/dist/src/envoy-BswDt-Ou.js +0 -61
- package/dist/src/envoy-rVbYcV80.js +0 -60
- package/dist/src/eval-B1-XfrC7.js +0 -2
- package/dist/src/eval-pC4qCvLw.js +0 -1920
- package/dist/src/evalResult-CzjCb5bd.js +0 -1300
- package/dist/src/evaluator-CNq2K7J_.js +0 -10578
- package/dist/src/evaluator-LtfxdxEu.js +0 -2
- package/dist/src/evaluatorHelpers-C5J0NYpQ.js +0 -601
- package/dist/src/evaluatorHelpers-DcdCglCs.cjs +0 -622
- package/dist/src/evaluatorHelpers-Rvb88W6B.js +0 -600
- package/dist/src/fetch-5HtnNhHg.js +0 -1556
- package/dist/src/fetch-BCwjoIFd.js +0 -1559
- package/dist/src/fetch-BhfUnKen.js +0 -1280
- package/dist/src/fetch-C08w4vVl.js +0 -9
- package/dist/src/fetch-DBxy8Tlb.cjs +0 -14
- package/dist/src/fetch-DYte6oQX.cjs +0 -1853
- package/dist/src/fetch-ElpfcAVG.js +0 -10
- package/dist/src/fetch-lM1OIaSt.js +0 -2
- package/dist/src/functionCallbackUtils-BCAdWfHO.js +0 -246
- package/dist/src/functionCallbackUtils-BYq9qOhG.js +0 -245
- package/dist/src/functionCallbackUtils-ByWkmVud.cjs +0 -262
- package/dist/src/functionCallbackUtils-D_C_JaFd.js +0 -245
- package/dist/src/gemini-image-CAlwaJhZ.js +0 -471
- package/dist/src/gemini-image-DJoVoOnZ.cjs +0 -471
- package/dist/src/gemini-image-Waio-9Xx.js +0 -472
- package/dist/src/gemini-image-vbY6Ftbf.js +0 -471
- package/dist/src/goat-BWbtyY9c.js +0 -512
- package/dist/src/goat-CXzzeCOQ.cjs +0 -515
- package/dist/src/goat-CfgvzSgZ.js +0 -514
- package/dist/src/goat-DLeoIHBp.js +0 -515
- package/dist/src/goblin-CmfCfwqk.cjs +0 -22
- package/dist/src/goblin-CtcaORRH.js +0 -22
- package/dist/src/goblin-DF6DDhM-.js +0 -22
- package/dist/src/goblin-Nai0xxBV.js +0 -23
- package/dist/src/google-ClpkLtKL.cjs +0 -142
- package/dist/src/google-CrFgKu9k.js +0 -143
- package/dist/src/google-Dj_EIBqS.js +0 -142
- package/dist/src/google-e4-vARv6.js +0 -142
- package/dist/src/graders-BN1IIa71.js +0 -15470
- package/dist/src/graders-C5sCfSP5.js +0 -2
- package/dist/src/hydra-B7RfXVBK.js +0 -2
- package/dist/src/hydra-C1cFN-Jg.js +0 -613
- package/dist/src/hydra-CK6Uc1ia.js +0 -612
- package/dist/src/hydra-Dg65rAP_.js +0 -610
- package/dist/src/hydra-Fqx8l_Xu.cjs +0 -612
- package/dist/src/image-BdlUDAtp.js +0 -163
- package/dist/src/image-C-KwEhwt.cjs +0 -163
- package/dist/src/image-C76fp6NK.cjs +0 -209
- package/dist/src/image-D75ehv3D.js +0 -482
- package/dist/src/image-DKtc5v5W.js +0 -209
- package/dist/src/image-DT_xOkJY.js +0 -163
- package/dist/src/image-DVpdllEE.js +0 -209
- package/dist/src/image-DXZ8AzMf.js +0 -481
- package/dist/src/image-DZl_1mvy.js +0 -164
- package/dist/src/image-DcTD7Ak0.cjs +0 -504
- package/dist/src/image-ndxEvBKB.js +0 -210
- package/dist/src/indirectWebPwn-70WA5x_q.js +0 -435
- package/dist/src/indirectWebPwn-BRVyd3qV.cjs +0 -463
- package/dist/src/indirectWebPwn-BsJVsu0q.js +0 -285
- package/dist/src/indirectWebPwn-Cw6yJu0i.js +0 -285
- package/dist/src/indirectWebPwn-D-PhJzo4.js +0 -286
- package/dist/src/indirectWebPwn-DRPHt2I8.js +0 -434
- package/dist/src/indirectWebPwn-DXtfFhd9.cjs +0 -285
- package/dist/src/indirectWebPwn-DvpNouzc.js +0 -434
- package/dist/src/interactions-5ixfW7Cl.js +0 -850
- package/dist/src/interactions-BOUzfmg1.cjs +0 -850
- package/dist/src/interactions-CSSXcGNc.js +0 -851
- package/dist/src/interactions-WB_sgkN0.js +0 -850
- package/dist/src/iterative-BShRNqjC.cjs +0 -549
- package/dist/src/iterative-BcW_ELtB.js +0 -548
- package/dist/src/iterative-BpHbHz8B.js +0 -547
- package/dist/src/iterative-YcchP12d.js +0 -545
- package/dist/src/iterativeImage-BMFE5Hl7.cjs +0 -419
- package/dist/src/iterativeImage-CkSaYLMY.js +0 -417
- package/dist/src/iterativeImage-DAEUlQX_.js +0 -418
- package/dist/src/iterativeImage-DeUSkEnj.js +0 -417
- package/dist/src/iterativeMeta-DbdaKdEO.cjs +0 -439
- package/dist/src/iterativeMeta-DcF9JWEK.js +0 -437
- package/dist/src/iterativeMeta-DkfPqWIC.js +0 -439
- package/dist/src/iterativeMeta-DkrpnVSs.js +0 -440
- package/dist/src/iterativeTree-CEMY1FhE.cjs +0 -879
- package/dist/src/iterativeTree-Cv5W4tX9.js +0 -877
- package/dist/src/iterativeTree-DGvomd3M.js +0 -876
- package/dist/src/iterativeTree-KbtC2Mkz.js +0 -878
- package/dist/src/knowledgeBase-AYRXn4wO.js +0 -163
- package/dist/src/knowledgeBase-BNqQfx01.js +0 -163
- package/dist/src/knowledgeBase-C0IaCCVs.js +0 -164
- package/dist/src/knowledgeBase-C2uj6wK4.cjs +0 -163
- package/dist/src/litellm-CN1ScAwZ.js +0 -147
- package/dist/src/litellm-CTjwiKSa.js +0 -146
- package/dist/src/litellm-Cd4Nj5ue.js +0 -145
- package/dist/src/litellm-DMqLpEBg.cjs +0 -146
- package/dist/src/live-Bt50-InO.cjs +0 -891
- package/dist/src/live-Bu2ujadG.js +0 -2
- package/dist/src/live-C3M52i3p.js +0 -891
- package/dist/src/live-CRfHMO3B.js +0 -892
- package/dist/src/live-iCIpO14m.js +0 -891
- package/dist/src/luma-ray-B8eHC4c8.cjs +0 -309
- package/dist/src/luma-ray-BIvkPw0s.js +0 -309
- package/dist/src/luma-ray-ChsiBxMA.js +0 -309
- package/dist/src/luma-ray-DAvKrInz.js +0 -310
- package/dist/src/mantleChat-5YeEXAZI.js +0 -154
- package/dist/src/mantleChat-D--mW3hl.js +0 -154
- package/dist/src/mantleChat-DHP3siNg.cjs +0 -154
- package/dist/src/mantleChat-wBfAX46o.js +0 -155
- package/dist/src/mcp-49jlEcTQ.js +0 -85
- package/dist/src/mcp-__PIz81I.js +0 -84
- package/dist/src/memoryPoisoning-Chxge74M.js +0 -111
- package/dist/src/memoryPoisoning-QH6NCUVE.js +0 -112
- package/dist/src/memoryPoisoning-tCxZt8Nz.js +0 -111
- package/dist/src/memoryPoisoning-ymrRItRR.cjs +0 -111
- package/dist/src/messages-BE_eZ7NA.js +0 -1127
- package/dist/src/messages-Bo638ShI.js +0 -1127
- package/dist/src/messages-BzR0-NQ1.js +0 -1128
- package/dist/src/messages-Cbg5Pfd0.cjs +0 -1161
- package/dist/src/mischievousUser-BtED2Z5Z.cjs +0 -51
- package/dist/src/mischievousUser-KqSOjrDJ.js +0 -51
- package/dist/src/mischievousUser-YMD41YNZ.js +0 -51
- package/dist/src/mischievousUser-zBxlNdCu.js +0 -52
- package/dist/src/modelslab-B8gZxtfE.js +0 -171
- package/dist/src/modelslab-C7bmVpTB.js +0 -170
- package/dist/src/modelslab-CCeQCTZg.js +0 -170
- package/dist/src/modelslab-CvBJGv7y.cjs +0 -170
- package/dist/src/nova-reel-BOEWsEKA.cjs +0 -272
- package/dist/src/nova-reel-BtyBXq5M.js +0 -273
- package/dist/src/nova-reel-C1eF3-EE.js +0 -272
- package/dist/src/nova-reel-YhgrxEKT.js +0 -272
- package/dist/src/nova-sonic-BaERP20w.js +0 -374
- package/dist/src/nova-sonic-CxgM3O-P.cjs +0 -374
- package/dist/src/nova-sonic-DJS22fC3.js +0 -375
- package/dist/src/nova-sonic-DwvwHyRX.js +0 -374
- package/dist/src/novita-D1l2tG0O.js +0 -116
- package/dist/src/novita-D84VM3v0.cjs +0 -115
- package/dist/src/novita-DGInvwfR.js +0 -115
- package/dist/src/novita-vXHkXhTg.js +0 -114
- package/dist/src/nscale-CU0Ldr00.js +0 -209
- package/dist/src/nscale-ClfKlQeM.cjs +0 -209
- package/dist/src/nscale-DxaVnF0x.js +0 -210
- package/dist/src/nscale-_poVxIrO.js +0 -207
- package/dist/src/openaiResponses-CJGsneNj.js +0 -317
- package/dist/src/openaiResponses-CKSl5Sdg.js +0 -319
- package/dist/src/openaiResponses-DC8rzFUc.js +0 -318
- package/dist/src/openaiResponses-rMHIA3dV.cjs +0 -318
- package/dist/src/openclaw-CCbvsNFW.cjs +0 -1344
- package/dist/src/openclaw-CZw1lCDZ.js +0 -1336
- package/dist/src/openclaw-ChFLgC-a.js +0 -1338
- package/dist/src/openclaw-DrPMoRrH.js +0 -1337
- package/dist/src/opencode-sdk-2EfIDhFp.cjs +0 -1018
- package/dist/src/opencode-sdk-CHw3F845.js +0 -1013
- package/dist/src/opencode-sdk-D0EGGxvy.js +0 -1012
- package/dist/src/opencode-sdk-jSS7NI2Q.js +0 -1012
- package/dist/src/openinterpreter-CY622xHC.js +0 -431
- package/dist/src/openinterpreter-DATyhuhP.js +0 -432
- package/dist/src/openinterpreter-DDUMyIf1.js +0 -431
- package/dist/src/openinterpreter-s5Tz6Lid.cjs +0 -435
- package/dist/src/pricing-C498twd2.js +0 -976
- package/dist/src/pricing-DBd_bMIh.cjs +0 -999
- package/dist/src/pricing-ISrMCskv.js +0 -976
- package/dist/src/promptfoo-6p0WG2ih.js +0 -286
- package/dist/src/promptfoo-BQRfgNs_.js +0 -285
- package/dist/src/promptfoo-Bqo88z20.cjs +0 -341
- package/dist/src/promptfoo-Cq5AVI3I.js +0 -286
- package/dist/src/providers-ATbeMX5E.cjs +0 -24180
- package/dist/src/providers-B7F1FiNI.js +0 -2
- package/dist/src/providers-DazIw8mI.js +0 -24039
- package/dist/src/providers-QvGlNAD0.js +0 -24437
- package/dist/src/quiverai-BPlNcLkV.cjs +0 -325
- package/dist/src/quiverai-By99-YmJ.js +0 -325
- package/dist/src/quiverai-CmmByDqo.js +0 -325
- package/dist/src/quiverai-HZkoJJqw.js +0 -326
- package/dist/src/registry-BLTnTfjT.cjs +0 -131
- package/dist/src/registry-BMC-COHT.js +0 -132
- package/dist/src/registry-C8UZtmBp.js +0 -131
- package/dist/src/registry-CfwEUYXG.js +0 -131
- package/dist/src/remoteGeneration-Bgg6kC5V.js +0 -370
- package/dist/src/remoteGeneration-CKJFE960.cjs +0 -482
- package/dist/src/remoteGeneration-DaxwJDKv.js +0 -370
- package/dist/src/remoteGeneration-vHMGVKr1.js +0 -371
- package/dist/src/responses-BvnyIHrq.js +0 -1099
- package/dist/src/responses-CERAgvf-.js +0 -1098
- package/dist/src/responses-CwgjeuOg.cjs +0 -1109
- package/dist/src/runtimeTransform-3RF9Avyg.cjs +0 -161
- package/dist/src/runtimeTransform-C51Z5j4H.js +0 -156
- package/dist/src/runtimeTransform-CKE_Iyv8.js +0 -157
- package/dist/src/runtimeTransform-Cs11xJpj.js +0 -156
- package/dist/src/sagemaker-BJ4dOCxE.js +0 -713
- package/dist/src/sagemaker-Bt3JUAWq.js +0 -714
- package/dist/src/sagemaker-QVKyLgLF.cjs +0 -716
- package/dist/src/sagemaker-l3IB8iTs.js +0 -713
- package/dist/src/scanner-DGjIiTZ1.js +0 -1971
- package/dist/src/server-BNaLZH6u.js +0 -63
- package/dist/src/server-CBMuQul3.js +0 -189
- package/dist/src/server-CMKKIzKv.cjs +0 -74
- package/dist/src/server-CN2IS9Cs.js +0 -155
- package/dist/src/server-ua4cqbjC.js +0 -2
- package/dist/src/session-CQIjq_HZ.cjs +0 -69
- package/dist/src/session-FTlg8sEu.js +0 -62
- package/dist/src/session-GBQXtPWp.js +0 -63
- package/dist/src/session-_0-rTdwY.js +0 -62
- package/dist/src/shared-BtuO-OAM.js +0 -1927
- package/dist/src/shared-Ci78wTZX.js +0 -1928
- package/dist/src/shared-Dd3rimdM.js +0 -1929
- package/dist/src/shared-KAjFxRre.cjs +0 -2185
- package/dist/src/simulatedUser--OjW6xCx.js +0 -247
- package/dist/src/simulatedUser-D0-slRye.cjs +0 -252
- package/dist/src/simulatedUser-D1Kh_cwA.js +0 -248
- package/dist/src/slack-BX0FUevO.js +0 -144
- package/dist/src/slack-CcwXFiJE.cjs +0 -144
- package/dist/src/slack-CnfqKfXp.js +0 -145
- package/dist/src/strategies-2ntcK4tN.js +0 -2248
- package/dist/src/strategies-DZIW7Zcs.js +0 -2385
- package/dist/src/strategies-YRDF2j-N.cjs +0 -2420
- package/dist/src/telemetry-CL8CVA4p.js +0 -205
- package/dist/src/telemetry-Cix90qqz.js +0 -201
- package/dist/src/telemetry-CkmlqTjV.js +0 -205
- package/dist/src/telemetry-DQH7l5bb.js +0 -2
- package/dist/src/telemetry-DUCXc1-r.cjs +0 -216
- package/dist/src/togetherai-3yUt5Ck7.js +0 -49
- package/dist/src/togetherai-BJUByLwt.cjs +0 -49
- package/dist/src/togetherai-Bh6KZkmd.js +0 -50
- package/dist/src/togetherai-DDl9yk3b.js +0 -48
- package/dist/src/traceContext-BiJVppjT.cjs +0 -1032
- package/dist/src/traceContext-CKKluULP.js +0 -1016
- package/dist/src/traceContext-D3Sk8fO-.js +0 -1015
- package/dist/src/transcription-BoVQKIVz.js +0 -175
- package/dist/src/transcription-Bs5u8780.js +0 -175
- package/dist/src/transcription-Dl654d1p.cjs +0 -178
- package/dist/src/transcription-VEvhM1Fu.js +0 -176
- package/dist/src/transform-BAbkGpvl.js +0 -125
- package/dist/src/transform-C_j4hUH8.js +0 -126
- package/dist/src/transform-Da86hs4M.cjs +0 -154
- package/dist/src/transform-_i1raQNo.js +0 -125
- package/dist/src/typesafe-CKXBeh82.cjs +0 -253
- package/dist/src/typesafe-D3VaGeNm.js +0 -253
- package/dist/src/typesafe-DYM-SFNH.js +0 -253
- package/dist/src/typesafe-LXmSbw8F.js +0 -254
- package/dist/src/util-41rb0XHX.js +0 -743
- package/dist/src/util-B0WlHYFM.js +0 -2049
- package/dist/src/util-BD1R_PsR.js +0 -1770
- package/dist/src/util-BLbM_ItC.js +0 -395
- package/dist/src/util-C72P0iIa.js +0 -352
- package/dist/src/util-C7MpGlJ6.cjs +0 -2305
- package/dist/src/util-CCtqagKc.js +0 -286
- package/dist/src/util-CM2Ec_uY.js +0 -2051
- package/dist/src/util-CSSAWO8v.js +0 -351
- package/dist/src/util-CkQc-fx3.cjs +0 -934
- package/dist/src/util-DcOlFTFa.cjs +0 -478
- package/dist/src/util-DluGTGVB.js +0 -395
- package/dist/src/util-PfQ60chz.js +0 -743
- package/dist/src/util-f14-CPij.js +0 -396
- package/dist/src/util-l9pXX3Eu.cjs +0 -357
- package/dist/src/util-o_BnlYqS.js +0 -2050
- package/dist/src/vertex-B_-gQgzc.js +0 -2
- package/dist/src/vertex-CU4gqoYa.js +0 -854
- package/dist/src/vertex-DZ42UHb3.js +0 -848
- package/dist/src/vertex-DsYQJA0T.cjs +0 -871
- package/dist/src/vertexLive-BvIaHKGB.js +0 -55
- package/dist/src/vertexLive-CTULqNx7.js +0 -56
- package/dist/src/vertexLive-DjJ_YQBe.cjs +0 -55
- package/dist/src/vertexLive-STUGcteB.js +0 -55
- package/dist/src/video-CAQGmtEV.js +0 -703
- package/dist/src/video-_FSTWlwX.js +0 -702
- package/dist/src/video-aBPJPWdt.js +0 -702
- package/dist/src/video-gDjkWv5m.cjs +0 -706
|
@@ -0,0 +1,2050 @@
|
|
|
1
|
+
import { o as InvalidToolCallError } from "./shared-DS0YmCOx.js";
|
|
2
|
+
import { F as getAjv, K as getEnvOverrides, Z as getProviderEnvString, it as getExplicitProviderEnv, o as logger, q as getEnvString } from "./logger-CNHLbG5Y.js";
|
|
3
|
+
import { n as isDataUrl, r as parseDataUrl, t as extractBase64FromDataUrl } from "./dataUrl-DUSr-ZvI.js";
|
|
4
|
+
import { i as isJavascriptFile } from "./fileExtensions-D1LbB4Aa.js";
|
|
5
|
+
import { _ as transformToolChoice, f as parseChatPrompt, n as calculateCost, r as clampCachedTokens, v as transformTools } from "./shared-BnN4RWgk.js";
|
|
6
|
+
import { _ as parseFileUrl, a as maybeLoadFromExternalFile, c as maybeLoadToolsFromExternalFile, t as getLoadedFileMimeType } from "./file-BPc_9IQ5.js";
|
|
7
|
+
import { n as renderVarsInObject, o as getNunjucksEngine } from "./render-DrCSgzhR.js";
|
|
8
|
+
import { t as resolveProviderEnv } from "./env-DG25rpzi.js";
|
|
9
|
+
import { t as InvalidToolSchemaError } from "./toolSchemaError-CmpqIHQW.js";
|
|
10
|
+
import { z as z$1 } from "zod";
|
|
11
|
+
import path from "path";
|
|
12
|
+
import crypto from "crypto";
|
|
13
|
+
import Clone from "rfdc";
|
|
14
|
+
//#region src/providers/google/auth.ts
|
|
15
|
+
/**
|
|
16
|
+
* Centralized authentication manager for Google AI providers.
|
|
17
|
+
*
|
|
18
|
+
* This module handles authentication for both Google AI Studio and Vertex AI,
|
|
19
|
+
* with support for API keys, OAuth/ADC, and service account credentials.
|
|
20
|
+
*
|
|
21
|
+
* Environment variable priority is aligned with the Python SDK:
|
|
22
|
+
* 1. config.apiKey (explicit)
|
|
23
|
+
* 2. VERTEX_API_KEY (Vertex mode only)
|
|
24
|
+
* 3. GOOGLE_API_KEY (primary - Python SDK alignment)
|
|
25
|
+
* 4. GEMINI_API_KEY (secondary)
|
|
26
|
+
*/
|
|
27
|
+
const EXPECTED_GCP_METADATA_LOOKUP_WARNING_PREFIX = "received unexpected error = ";
|
|
28
|
+
let activeGcpMetadataLookupWarningSuppressions = 0;
|
|
29
|
+
let restoreEmitWarning;
|
|
30
|
+
async function suppressExpectedGcpMetadataLookupWarning(action) {
|
|
31
|
+
if (activeGcpMetadataLookupWarningSuppressions === 0) {
|
|
32
|
+
const originalEmitWarning = process.emitWarning;
|
|
33
|
+
const wrappedEmitWarning = ((warning, ...args) => {
|
|
34
|
+
const message = warning instanceof Error ? warning.message : warning;
|
|
35
|
+
if ((warning instanceof Error ? warning.name : args[0]) === "MetadataLookupWarning" && typeof message === "string" && message.startsWith(EXPECTED_GCP_METADATA_LOOKUP_WARNING_PREFIX)) return;
|
|
36
|
+
Reflect.apply(originalEmitWarning, process, [warning, ...args]);
|
|
37
|
+
});
|
|
38
|
+
process.emitWarning = wrappedEmitWarning;
|
|
39
|
+
restoreEmitWarning = () => {
|
|
40
|
+
if (process.emitWarning === wrappedEmitWarning) process.emitWarning = originalEmitWarning;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
activeGcpMetadataLookupWarningSuppressions += 1;
|
|
44
|
+
try {
|
|
45
|
+
return await action();
|
|
46
|
+
} finally {
|
|
47
|
+
activeGcpMetadataLookupWarningSuppressions -= 1;
|
|
48
|
+
if (activeGcpMetadataLookupWarningSuppressions === 0) {
|
|
49
|
+
restoreEmitWarning?.();
|
|
50
|
+
restoreEmitWarning = void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Centralized authentication manager for Google AI providers.
|
|
56
|
+
*
|
|
57
|
+
* Handles:
|
|
58
|
+
* - API key resolution with proper priority
|
|
59
|
+
* - OAuth client creation for Vertex AI
|
|
60
|
+
* - Service account credential loading
|
|
61
|
+
* - Conflict detection and warnings
|
|
62
|
+
*/
|
|
63
|
+
var GoogleAuthManager = class {
|
|
64
|
+
static cachedHasDefaultCredentials;
|
|
65
|
+
static pendingHasDefaultCredentials;
|
|
66
|
+
/**
|
|
67
|
+
* Get API key with proper priority order.
|
|
68
|
+
*
|
|
69
|
+
* Environment scope takes priority; aliases are checked in this order within each scope.
|
|
70
|
+
* Priority (aligned with Python SDK):
|
|
71
|
+
* 1. config.apiKey (explicit)
|
|
72
|
+
* 2. VERTEX_API_KEY (Vertex mode only)
|
|
73
|
+
* 3. GOOGLE_API_KEY (primary - Python SDK alignment)
|
|
74
|
+
* 4. GEMINI_API_KEY (secondary)
|
|
75
|
+
* 5. PALM_API_KEY (legacy)
|
|
76
|
+
*
|
|
77
|
+
* @param config - Provider configuration
|
|
78
|
+
* @param env - Environment overrides
|
|
79
|
+
* @param isVertexMode - Whether in Vertex AI mode
|
|
80
|
+
* @returns The resolved API key and its source
|
|
81
|
+
*/
|
|
82
|
+
static getApiKey(config, env, isVertexMode = false) {
|
|
83
|
+
if (config.apiKey) return {
|
|
84
|
+
apiKey: config.apiKey,
|
|
85
|
+
source: "config"
|
|
86
|
+
};
|
|
87
|
+
const keys = isVertexMode ? ["VERTEX_API_KEY", "GOOGLE_API_KEY"] : [
|
|
88
|
+
"GOOGLE_API_KEY",
|
|
89
|
+
"GEMINI_API_KEY",
|
|
90
|
+
"PALM_API_KEY"
|
|
91
|
+
];
|
|
92
|
+
const masked = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const layer of [
|
|
94
|
+
getExplicitProviderEnv(env),
|
|
95
|
+
getEnvOverrides("provider"),
|
|
96
|
+
env,
|
|
97
|
+
getEnvOverrides(),
|
|
98
|
+
getEnvOverrides("file"),
|
|
99
|
+
Object.fromEntries(keys.map((key) => [key, getEnvString(key)]))
|
|
100
|
+
]) for (const source of keys) {
|
|
101
|
+
const apiKey = layer?.[source];
|
|
102
|
+
if (masked.has(source) || apiKey === void 0) continue;
|
|
103
|
+
masked.add(source);
|
|
104
|
+
if (!apiKey) continue;
|
|
105
|
+
if (source === "VERTEX_API_KEY") logger.warn("[Google] VERTEX_API_KEY is not a standard SDK env var. Use GOOGLE_API_KEY instead.");
|
|
106
|
+
else if (source === "PALM_API_KEY") logger.warn("[Google] PALM_API_KEY is deprecated. Use GOOGLE_API_KEY instead.");
|
|
107
|
+
else if (source === "GEMINI_API_KEY") logger.debug("[Google] GEMINI_API_KEY is not a standard SDK env var. Consider using GOOGLE_API_KEY.");
|
|
108
|
+
else if (!isVertexMode && layer?.GEMINI_API_KEY) logger.debug("[Google] Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.");
|
|
109
|
+
return {
|
|
110
|
+
apiKey,
|
|
111
|
+
source
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
apiKey: void 0,
|
|
116
|
+
source: "none"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Validate authentication configuration and emit warnings or throw errors for issues.
|
|
121
|
+
*
|
|
122
|
+
* @param config - Authentication configuration
|
|
123
|
+
* @param env - Environment overrides
|
|
124
|
+
* @throws Error if strictMutualExclusivity is true and mutual exclusivity violation detected
|
|
125
|
+
*/
|
|
126
|
+
static validateAndWarn(config, env) {
|
|
127
|
+
const { apiKey, credentials, projectId, region, vertexai, strictMutualExclusivity } = config;
|
|
128
|
+
const isStrict = strictMutualExclusivity === true;
|
|
129
|
+
const useVertexEnv = getProviderEnvString(env, "GOOGLE_GENAI_USE_VERTEXAI") ?? getEnvString("GOOGLE_GENAI_USE_VERTEXAI");
|
|
130
|
+
const cloudProject = env?.GOOGLE_CLOUD_PROJECT ?? getEnvString("GOOGLE_CLOUD_PROJECT");
|
|
131
|
+
const hasProjectEnvironment = Boolean(resolveProviderEnv(env, [
|
|
132
|
+
"VERTEX_PROJECT_ID",
|
|
133
|
+
"GOOGLE_PROJECT_ID",
|
|
134
|
+
"GOOGLE_CLOUD_PROJECT"
|
|
135
|
+
])?.value);
|
|
136
|
+
if ((projectId || region) && apiKey) {
|
|
137
|
+
const message = "[Google] Project/location and API key are mutually exclusive in the client initializer. Use either apiKey for express mode OR projectId/region for OAuth mode, not both.";
|
|
138
|
+
if (isStrict) throw new Error(message);
|
|
139
|
+
else logger.warn(message);
|
|
140
|
+
}
|
|
141
|
+
if (useVertexEnv && vertexai === false) logger.warn("[Google] GOOGLE_GENAI_USE_VERTEXAI is set but vertexai: false was specified in config. Config takes precedence.");
|
|
142
|
+
if (cloudProject && projectId && cloudProject !== projectId) logger.warn("[Google] Both GOOGLE_CLOUD_PROJECT and config.projectId are set with different values. Using config.projectId.");
|
|
143
|
+
if (apiKey && credentials) logger.debug("[Google] Both apiKey and credentials are set. Using API key (express mode). Set expressMode: false to use OAuth/ADC instead.");
|
|
144
|
+
if (vertexai && !apiKey && !projectId && !hasProjectEnvironment && !credentials) {
|
|
145
|
+
if (!Boolean(env?.GOOGLE_APPLICATION_CREDENTIALS ?? getEnvString("GOOGLE_APPLICATION_CREDENTIALS"))) logger.debug("[Google] Vertex AI mode enabled but no projectId, credentials, or ADC detected. Authentication may fail.");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Determine if Vertex AI mode should be used.
|
|
150
|
+
*
|
|
151
|
+
* Priority:
|
|
152
|
+
* 1. Explicit vertexai config flag
|
|
153
|
+
* 2. GOOGLE_GENAI_USE_VERTEXAI env var (Python SDK compatibility)
|
|
154
|
+
* 3. Auto-detect from projectId/credentials presence
|
|
155
|
+
* 4. Default: false (Google AI Studio)
|
|
156
|
+
*
|
|
157
|
+
* @param config - Provider configuration
|
|
158
|
+
* @param env - Environment overrides
|
|
159
|
+
* @returns Whether to use Vertex AI mode
|
|
160
|
+
*/
|
|
161
|
+
static determineVertexMode(config, env) {
|
|
162
|
+
if (config.vertexai !== void 0) return config.vertexai;
|
|
163
|
+
const useVertexEnv = getProviderEnvString(env, "GOOGLE_GENAI_USE_VERTEXAI") ?? getEnvString("GOOGLE_GENAI_USE_VERTEXAI");
|
|
164
|
+
if (useVertexEnv === "true" || useVertexEnv === "1") {
|
|
165
|
+
logger.debug("[Google] Vertex AI mode enabled via GOOGLE_GENAI_USE_VERTEXAI");
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (useVertexEnv === "false" || useVertexEnv === "0") return false;
|
|
169
|
+
const hasProjectId = Boolean(config.projectId || resolveProviderEnv(env, [
|
|
170
|
+
"VERTEX_PROJECT_ID",
|
|
171
|
+
"GOOGLE_PROJECT_ID",
|
|
172
|
+
"GOOGLE_CLOUD_PROJECT"
|
|
173
|
+
])?.value);
|
|
174
|
+
const hasCredentials = Boolean(config.credentials);
|
|
175
|
+
if (hasProjectId || hasCredentials) {
|
|
176
|
+
logger.debug("[Google] Auto-detected Vertex AI mode from projectId/credentials. Set vertexai: true/false explicitly to suppress this message.");
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load credentials from file or return as-is.
|
|
183
|
+
*
|
|
184
|
+
* Supports:
|
|
185
|
+
* - file:// prefix to load from external file
|
|
186
|
+
* - Raw JSON string
|
|
187
|
+
* - Pre-parsed object (from config loading pipeline)
|
|
188
|
+
*
|
|
189
|
+
* @param credentials - Credentials string, file path, or pre-parsed object
|
|
190
|
+
* @returns Processed credentials JSON string
|
|
191
|
+
*/
|
|
192
|
+
static loadCredentials(credentials) {
|
|
193
|
+
if (!credentials) return;
|
|
194
|
+
if (typeof credentials === "object") return JSON.stringify(credentials);
|
|
195
|
+
if (credentials.startsWith("file://")) try {
|
|
196
|
+
const loaded = maybeLoadFromExternalFile(credentials);
|
|
197
|
+
if (typeof loaded === "object") return JSON.stringify(loaded);
|
|
198
|
+
return loaded;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
throw new Error(`Failed to load credentials from file: ${error}`);
|
|
201
|
+
}
|
|
202
|
+
return credentials;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get or create a Google OAuth client.
|
|
206
|
+
*
|
|
207
|
+
* Supports googleAuthOptions passthrough for advanced configuration
|
|
208
|
+
* like custom scopes, keyFilename, universeDomain, etc.
|
|
209
|
+
*
|
|
210
|
+
* @param options - OAuth client options (can also pass string for backward compatibility)
|
|
211
|
+
* @returns OAuth client and detected project ID
|
|
212
|
+
*/
|
|
213
|
+
static async getOAuthClient(options = {}) {
|
|
214
|
+
const { credentials, googleAuthOptions, scopes, keyFilename } = typeof options === "string" ? { credentials: options } : options;
|
|
215
|
+
const resolvedScopes = scopes ?? googleAuthOptions?.scopes ?? "https://www.googleapis.com/auth/cloud-platform";
|
|
216
|
+
const authOptions = {
|
|
217
|
+
...googleAuthOptions,
|
|
218
|
+
scopes: resolvedScopes
|
|
219
|
+
};
|
|
220
|
+
if (keyFilename && !authOptions.keyFilename) authOptions.keyFilename = keyFilename;
|
|
221
|
+
let GoogleAuthClass;
|
|
222
|
+
try {
|
|
223
|
+
GoogleAuthClass = (await import("google-auth-library")).GoogleAuth;
|
|
224
|
+
} catch {
|
|
225
|
+
throw new Error("The google-auth-library package is required for Vertex AI. Please install it: npm install google-auth-library");
|
|
226
|
+
}
|
|
227
|
+
const auth = new GoogleAuthClass(authOptions);
|
|
228
|
+
const processedCredentials = this.loadCredentials(credentials);
|
|
229
|
+
let client;
|
|
230
|
+
if (processedCredentials) {
|
|
231
|
+
let parsedCredentials;
|
|
232
|
+
try {
|
|
233
|
+
parsedCredentials = JSON.parse(processedCredentials);
|
|
234
|
+
} catch (parseError) {
|
|
235
|
+
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
|
|
236
|
+
throw new Error(`[Google] Invalid credentials JSON format: ${errorMsg}`);
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
client = await auth.fromJSON(parsedCredentials);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
242
|
+
logger.error(`[Google] Could not load credentials: ${errorMsg}`);
|
|
243
|
+
throw new Error(`[Google] Could not load credentials: ${errorMsg}`);
|
|
244
|
+
}
|
|
245
|
+
} else client = await auth.getClient();
|
|
246
|
+
let projectId;
|
|
247
|
+
try {
|
|
248
|
+
projectId = await auth.getProjectId();
|
|
249
|
+
} catch {
|
|
250
|
+
projectId = void 0;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
client,
|
|
254
|
+
projectId
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Resolve project ID from multiple sources.
|
|
259
|
+
*
|
|
260
|
+
* Priority:
|
|
261
|
+
* 1. config.projectId
|
|
262
|
+
* 2. Provider-scoped VERTEX_PROJECT_ID / GOOGLE_PROJECT_ID / GOOGLE_CLOUD_PROJECT
|
|
263
|
+
* 3. Process-wide VERTEX_PROJECT_ID / GOOGLE_PROJECT_ID / GOOGLE_CLOUD_PROJECT
|
|
264
|
+
* 4. Auto-detected from OAuth credentials
|
|
265
|
+
*
|
|
266
|
+
* @param config - Provider configuration
|
|
267
|
+
* @param env - Environment overrides
|
|
268
|
+
* @returns Resolved project ID
|
|
269
|
+
*/
|
|
270
|
+
static async resolveProjectId(config, env) {
|
|
271
|
+
const project = resolveProviderEnv(env, [
|
|
272
|
+
"VERTEX_PROJECT_ID",
|
|
273
|
+
"GOOGLE_PROJECT_ID",
|
|
274
|
+
"GOOGLE_CLOUD_PROJECT"
|
|
275
|
+
]);
|
|
276
|
+
if (project && project.name !== "GOOGLE_CLOUD_PROJECT" && !config.projectId) logger.debug(`[Google] ${project.name} is not a standard SDK env var. Consider using GOOGLE_CLOUD_PROJECT.`);
|
|
277
|
+
const configuredProjectId = config.projectId || project?.value;
|
|
278
|
+
if (configuredProjectId) return configuredProjectId;
|
|
279
|
+
const { projectId: authProjectId } = await this.getOAuthClient({
|
|
280
|
+
credentials: config.credentials,
|
|
281
|
+
googleAuthOptions: config.googleAuthOptions,
|
|
282
|
+
keyFilename: config.keyFilename,
|
|
283
|
+
scopes: config.scopes
|
|
284
|
+
});
|
|
285
|
+
return authProjectId || "";
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Resolve region from multiple sources.
|
|
289
|
+
*
|
|
290
|
+
* Priority:
|
|
291
|
+
* 1. config.region
|
|
292
|
+
* 2. Provider-scoped VERTEX_REGION / GOOGLE_CLOUD_LOCATION overrides
|
|
293
|
+
* 3. Process-wide VERTEX_REGION / GOOGLE_CLOUD_LOCATION env vars
|
|
294
|
+
* 4. Model-specific fallback region
|
|
295
|
+
* 5. Default: 'global' for Vertex AI without API key (SDK aligned), 'us-central1' otherwise
|
|
296
|
+
*
|
|
297
|
+
* @param config - Provider configuration
|
|
298
|
+
* @param env - Environment overrides
|
|
299
|
+
* @param hasApiKey - Whether an API key is configured (affects default region)
|
|
300
|
+
* @param modelDefaultRegion - Model-specific fallback region
|
|
301
|
+
* @returns Resolved region
|
|
302
|
+
*/
|
|
303
|
+
static resolveRegion(config, env, hasApiKey, modelDefaultRegion) {
|
|
304
|
+
const region = resolveProviderEnv(env, ["VERTEX_REGION", "GOOGLE_CLOUD_LOCATION"]);
|
|
305
|
+
if (region?.name === "VERTEX_REGION" && !config.region) logger.debug("[Google] VERTEX_REGION is not a standard SDK env var. Consider using GOOGLE_CLOUD_LOCATION.");
|
|
306
|
+
const configuredRegion = config.region || region?.value;
|
|
307
|
+
if (configuredRegion) return configuredRegion;
|
|
308
|
+
if (modelDefaultRegion) return modelDefaultRegion;
|
|
309
|
+
if (hasApiKey === false) return "global";
|
|
310
|
+
return "us-central1";
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Check if Application Default Credentials are available.
|
|
314
|
+
*
|
|
315
|
+
* @returns True if ADC is available
|
|
316
|
+
*/
|
|
317
|
+
static async hasDefaultCredentials() {
|
|
318
|
+
if (this.cachedHasDefaultCredentials !== void 0) return this.cachedHasDefaultCredentials;
|
|
319
|
+
if (!this.pendingHasDefaultCredentials) {
|
|
320
|
+
const probe = (async () => {
|
|
321
|
+
try {
|
|
322
|
+
await suppressExpectedGcpMetadataLookupWarning(() => this.getOAuthClient());
|
|
323
|
+
return true;
|
|
324
|
+
} catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
})();
|
|
328
|
+
this.pendingHasDefaultCredentials = probe;
|
|
329
|
+
probe.then((result) => {
|
|
330
|
+
if (this.pendingHasDefaultCredentials === probe) this.cachedHasDefaultCredentials = result;
|
|
331
|
+
return result;
|
|
332
|
+
}).finally(() => {
|
|
333
|
+
if (this.pendingHasDefaultCredentials === probe) this.pendingHasDefaultCredentials = void 0;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return this.pendingHasDefaultCredentials;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Clear internal auth detection caches (useful for testing).
|
|
340
|
+
*/
|
|
341
|
+
static clearCache() {
|
|
342
|
+
this.cachedHasDefaultCredentials = void 0;
|
|
343
|
+
this.pendingHasDefaultCredentials = void 0;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
const loadCredentials = GoogleAuthManager.loadCredentials.bind(GoogleAuthManager);
|
|
347
|
+
const getGoogleClient = GoogleAuthManager.getOAuthClient.bind(GoogleAuthManager);
|
|
348
|
+
const resolveProjectId = GoogleAuthManager.resolveProjectId.bind(GoogleAuthManager);
|
|
349
|
+
const getGoogleApiKey = GoogleAuthManager.getApiKey.bind(GoogleAuthManager);
|
|
350
|
+
const determineGoogleVertexMode = GoogleAuthManager.determineVertexMode.bind(GoogleAuthManager);
|
|
351
|
+
const hasGoogleDefaultCredentials = GoogleAuthManager.hasDefaultCredentials.bind(GoogleAuthManager);
|
|
352
|
+
GoogleAuthManager.clearCache.bind(GoogleAuthManager);
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/providers/google/shared.ts
|
|
355
|
+
const VERTEX_GLOBAL_DEFAULT_MODELS = /* @__PURE__ */ new Set([
|
|
356
|
+
"gemini-3.8-flash-tts",
|
|
357
|
+
"gemini-3.8-flash-lite-tts",
|
|
358
|
+
"gemini-3.8-flash",
|
|
359
|
+
"gemini-3.8-flash-cyber",
|
|
360
|
+
"gemini-3.7-flash",
|
|
361
|
+
"gemini-3.6-flash",
|
|
362
|
+
"gemini-3.5-flash",
|
|
363
|
+
"gemini-flash-latest",
|
|
364
|
+
"gemini-3.5-flash-lite",
|
|
365
|
+
"gemini-3.1-pro-preview",
|
|
366
|
+
"gemini-3.1-pro-preview-customtools",
|
|
367
|
+
"gemini-3.1-flash-lite",
|
|
368
|
+
"gemini-flash-lite-latest",
|
|
369
|
+
"gemini-3-flash-preview"
|
|
370
|
+
]);
|
|
371
|
+
const VERTEX_US_EAST5_DEFAULT_MODELS = /* @__PURE__ */ new Set(["llama-4-maverick-17b-128e-instruct-maas", "llama-4-scout-17b-16e-instruct-maas"]);
|
|
372
|
+
function getVertexModelDefaultRegion(modelName) {
|
|
373
|
+
if (VERTEX_GLOBAL_DEFAULT_MODELS.has(modelName)) return "global";
|
|
374
|
+
if (VERTEX_US_EAST5_DEFAULT_MODELS.has(modelName)) return "us-east5";
|
|
375
|
+
}
|
|
376
|
+
const GEMINI_FLASH_MODELS = [
|
|
377
|
+
{
|
|
378
|
+
id: "gemini-3.8-flash",
|
|
379
|
+
name: "Gemini 3.8 Flash"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
id: "gemini-3.7-flash",
|
|
383
|
+
name: "Gemini 3.7 Flash"
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
id: "gemini-3.6-flash",
|
|
387
|
+
name: "Gemini 3.6 Flash"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
id: "gemini-3.5-flash-lite",
|
|
391
|
+
name: "Gemini 3.5 Flash-Lite"
|
|
392
|
+
}
|
|
393
|
+
];
|
|
394
|
+
function getVertexApiHostForRegion(region) {
|
|
395
|
+
if (region === "global") return "aiplatform.googleapis.com";
|
|
396
|
+
if (region === "us" || region === "eu") return `aiplatform.${region}.rep.googleapis.com`;
|
|
397
|
+
return `${region}-aiplatform.googleapis.com`;
|
|
398
|
+
}
|
|
399
|
+
const GEMINI_3_PRO_COST = {
|
|
400
|
+
input: 2 / 1e6,
|
|
401
|
+
output: 12 / 1e6,
|
|
402
|
+
cacheRead: .2 / 1e6
|
|
403
|
+
};
|
|
404
|
+
const GEMINI_3_PRO_TIERED_COST = {
|
|
405
|
+
threshold: 2e5,
|
|
406
|
+
above: {
|
|
407
|
+
input: 4 / 1e6,
|
|
408
|
+
output: 18 / 1e6,
|
|
409
|
+
cacheRead: .4 / 1e6
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const GEMINI_2_5_PRO_COST = {
|
|
413
|
+
input: 1.25 / 1e6,
|
|
414
|
+
output: 10 / 1e6,
|
|
415
|
+
cacheRead: .125 / 1e6
|
|
416
|
+
};
|
|
417
|
+
const GEMINI_2_5_PRO_TIERED_COST = {
|
|
418
|
+
threshold: 2e5,
|
|
419
|
+
above: {
|
|
420
|
+
input: 2.5 / 1e6,
|
|
421
|
+
output: 15 / 1e6,
|
|
422
|
+
cacheRead: .25 / 1e6
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const GEMINI_FLASH_INTRODUCTORY_PRICING = {
|
|
426
|
+
expiresAt: Date.UTC(2027, 0, 1),
|
|
427
|
+
multiplier: .5
|
|
428
|
+
};
|
|
429
|
+
const GEMINI_3_5_FLASH_LITE_COST = {
|
|
430
|
+
input: .3 / 1e6,
|
|
431
|
+
output: 2.5 / 1e6,
|
|
432
|
+
cacheRead: .03 / 1e6,
|
|
433
|
+
priorityMultiplier: 1.8,
|
|
434
|
+
flexMultiplier: .5
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Google AI Studio model pricing used for current requests and saved-evaluation cost scoring.
|
|
438
|
+
* Prices are per token (from Google AI pricing page, converted from per-million).
|
|
439
|
+
*
|
|
440
|
+
* Selected retired IDs remain here so historical results can still be scored. Membership in this
|
|
441
|
+
* table does not imply that Google still serves the endpoint.
|
|
442
|
+
*
|
|
443
|
+
* Note: Vertex AI may have different pricing for some models.
|
|
444
|
+
* @see https://ai.google.dev/gemini-api/docs/pricing
|
|
445
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/pricing
|
|
446
|
+
*/
|
|
447
|
+
const GOOGLE_MODELS = [
|
|
448
|
+
{
|
|
449
|
+
id: "gemini-3.8-flash-cyber",
|
|
450
|
+
vertexCost: {
|
|
451
|
+
input: 1.5 / 1e6,
|
|
452
|
+
output: 7.5 / 1e6,
|
|
453
|
+
cacheRead: .15 / 1e6,
|
|
454
|
+
priorityMultiplier: 1.8,
|
|
455
|
+
flexMultiplier: .5
|
|
456
|
+
},
|
|
457
|
+
vertexRegionalPremium: 1.1
|
|
458
|
+
},
|
|
459
|
+
...[
|
|
460
|
+
"gemini-3.8-flash",
|
|
461
|
+
"gemini-3.7-flash",
|
|
462
|
+
"gemini-3.6-flash",
|
|
463
|
+
"gemini-flash-latest"
|
|
464
|
+
].map((id) => ({
|
|
465
|
+
id,
|
|
466
|
+
cost: {
|
|
467
|
+
input: 1.5 / 1e6,
|
|
468
|
+
output: 7.5 / 1e6,
|
|
469
|
+
cacheRead: .15 / 1e6,
|
|
470
|
+
priorityMultiplier: 1.8,
|
|
471
|
+
flexMultiplier: .5
|
|
472
|
+
},
|
|
473
|
+
introductoryPricing: GEMINI_FLASH_INTRODUCTORY_PRICING,
|
|
474
|
+
vertexRegionalPremium: 1.1
|
|
475
|
+
})),
|
|
476
|
+
...[{
|
|
477
|
+
id: "gemini-3.8-flash-tts",
|
|
478
|
+
audioOutput: 18 / 1e6
|
|
479
|
+
}, {
|
|
480
|
+
id: "gemini-3.8-flash-lite-tts",
|
|
481
|
+
audioOutput: 12 / 1e6
|
|
482
|
+
}].map(({ id, audioOutput }) => ({
|
|
483
|
+
id,
|
|
484
|
+
cost: {
|
|
485
|
+
input: 1 / 1e6,
|
|
486
|
+
output: audioOutput,
|
|
487
|
+
audioOutput,
|
|
488
|
+
priorityMultiplier: 1.8,
|
|
489
|
+
flexMultiplier: .5
|
|
490
|
+
},
|
|
491
|
+
vertexCost: {
|
|
492
|
+
input: 1 / 1e6,
|
|
493
|
+
output: audioOutput,
|
|
494
|
+
audioOutput
|
|
495
|
+
},
|
|
496
|
+
introductoryPricing: GEMINI_FLASH_INTRODUCTORY_PRICING
|
|
497
|
+
})),
|
|
498
|
+
{
|
|
499
|
+
id: "gemini-3.5-flash",
|
|
500
|
+
cost: {
|
|
501
|
+
input: 1.5 / 1e6,
|
|
502
|
+
output: 9 / 1e6,
|
|
503
|
+
cacheRead: .15 / 1e6,
|
|
504
|
+
audioInput: 1.5 / 1e6,
|
|
505
|
+
priorityMultiplier: 1.8,
|
|
506
|
+
flexMultiplier: .5,
|
|
507
|
+
flexCacheRead: .08 / 1e6
|
|
508
|
+
},
|
|
509
|
+
vertexCost: {
|
|
510
|
+
input: 1.5 / 1e6,
|
|
511
|
+
output: 9 / 1e6,
|
|
512
|
+
cacheRead: .15 / 1e6,
|
|
513
|
+
audioInput: 1.5 / 1e6,
|
|
514
|
+
priorityMultiplier: 1.8,
|
|
515
|
+
flexMultiplier: .5,
|
|
516
|
+
flexCacheRead: .075 / 1e6
|
|
517
|
+
},
|
|
518
|
+
vertexRegionalCost: {
|
|
519
|
+
input: 1.65 / 1e6,
|
|
520
|
+
output: 9.9 / 1e6,
|
|
521
|
+
cacheRead: .165 / 1e6,
|
|
522
|
+
audioInput: 1.65 / 1e6,
|
|
523
|
+
priorityMultiplier: 1.8,
|
|
524
|
+
flexMultiplier: .5,
|
|
525
|
+
flexCacheRead: .0825 / 1e6
|
|
526
|
+
},
|
|
527
|
+
vertexRegionalPremium: 1.1
|
|
528
|
+
},
|
|
529
|
+
...["gemini-3.5-flash-lite", "gemini-flash-lite-latest"].map((id) => ({
|
|
530
|
+
id,
|
|
531
|
+
cost: {
|
|
532
|
+
...GEMINI_3_5_FLASH_LITE_COST,
|
|
533
|
+
priorityCacheRead: .05 / 1e6,
|
|
534
|
+
flexCacheRead: .02 / 1e6
|
|
535
|
+
},
|
|
536
|
+
vertexCost: GEMINI_3_5_FLASH_LITE_COST,
|
|
537
|
+
vertexRegionalPremium: 1.1
|
|
538
|
+
})),
|
|
539
|
+
...modelsWithCost([
|
|
540
|
+
"gemini-omni-flash-preview",
|
|
541
|
+
"gemini-omni-1.1-flash",
|
|
542
|
+
"gemini-omni-1.1-flash-preview"
|
|
543
|
+
], {
|
|
544
|
+
input: 1.5 / 1e6,
|
|
545
|
+
output: 9 / 1e6,
|
|
546
|
+
audioInput: 1.5 / 1e6,
|
|
547
|
+
videoOutput: 17.5 / 1e6
|
|
548
|
+
}),
|
|
549
|
+
...modelsWithCost(["gemini-3.5-live-translate-preview"], {
|
|
550
|
+
input: 3.5 / 1e6,
|
|
551
|
+
output: 21 / 1e6,
|
|
552
|
+
audioInput: 3.5 / 1e6,
|
|
553
|
+
audioOutput: 21 / 1e6
|
|
554
|
+
}),
|
|
555
|
+
...[
|
|
556
|
+
"gemini-3.1-pro-preview",
|
|
557
|
+
"gemini-3.1-pro-preview-customtools",
|
|
558
|
+
"gemini-pro-latest"
|
|
559
|
+
].map((id) => ({
|
|
560
|
+
id,
|
|
561
|
+
cost: {
|
|
562
|
+
...GEMINI_3_PRO_COST,
|
|
563
|
+
priorityMultiplier: 1.8,
|
|
564
|
+
flexMultiplier: .5,
|
|
565
|
+
flexCacheRead: GEMINI_3_PRO_COST.cacheRead
|
|
566
|
+
},
|
|
567
|
+
tieredCost: {
|
|
568
|
+
...GEMINI_3_PRO_TIERED_COST,
|
|
569
|
+
above: {
|
|
570
|
+
...GEMINI_3_PRO_TIERED_COST.above,
|
|
571
|
+
priorityMultiplier: 1.8,
|
|
572
|
+
flexMultiplier: .5,
|
|
573
|
+
flexCacheRead: GEMINI_3_PRO_TIERED_COST.above.cacheRead
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
})),
|
|
577
|
+
...["gemini-3.1-flash-lite", "gemini-3.1-flash-lite-preview"].map((id) => ({
|
|
578
|
+
id,
|
|
579
|
+
cost: {
|
|
580
|
+
input: .25 / 1e6,
|
|
581
|
+
output: 1.5 / 1e6,
|
|
582
|
+
cacheRead: .025 / 1e6,
|
|
583
|
+
cacheReadAudio: .05 / 1e6,
|
|
584
|
+
audioInput: .5 / 1e6,
|
|
585
|
+
...id === "gemini-3.1-flash-lite-preview" ? {} : {
|
|
586
|
+
priorityMultiplier: 1.8,
|
|
587
|
+
priorityAudioInput: .9 / 1e6,
|
|
588
|
+
flexMultiplier: .5,
|
|
589
|
+
flexAudioInput: .25 / 1e6
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
...id === "gemini-3.1-flash-lite-preview" ? {} : { vertexRegionalPremium: 1.1 }
|
|
593
|
+
})),
|
|
594
|
+
...modelsWithCost([
|
|
595
|
+
"gemini-3.8-live",
|
|
596
|
+
"gemini-3.8-live-extended-thinking",
|
|
597
|
+
"gemini-3.1-flash-live-preview"
|
|
598
|
+
], {
|
|
599
|
+
input: .75 / 1e6,
|
|
600
|
+
output: 4.5 / 1e6,
|
|
601
|
+
audioInput: 3 / 1e6,
|
|
602
|
+
audioOutput: 12 / 1e6,
|
|
603
|
+
imageInput: 1 / 1e6,
|
|
604
|
+
videoInputPerSecond: 33333333333333335e-21
|
|
605
|
+
}),
|
|
606
|
+
...modelsWithCost(["gemini-live-2.5-flash-native-audio"], {
|
|
607
|
+
input: .5 / 1e6,
|
|
608
|
+
output: 2 / 1e6,
|
|
609
|
+
audioInput: 3 / 1e6,
|
|
610
|
+
audioOutput: 12 / 1e6,
|
|
611
|
+
imageInput: 3 / 1e6
|
|
612
|
+
}),
|
|
613
|
+
...modelsWithCost(["gemini-3.1-flash-tts-preview"], {
|
|
614
|
+
input: 1 / 1e6,
|
|
615
|
+
output: 20 / 1e6,
|
|
616
|
+
audioOutput: 20 / 1e6
|
|
617
|
+
}),
|
|
618
|
+
...modelsWithCost(["gemini-live-2.5-flash-preview-native-audio-09-2025"], {
|
|
619
|
+
input: .3 / 1e6,
|
|
620
|
+
output: 2 / 1e6,
|
|
621
|
+
cacheRead: .075 / 1e6,
|
|
622
|
+
audioInput: 3 / 1e6,
|
|
623
|
+
audioOutput: 12 / 1e6
|
|
624
|
+
}),
|
|
625
|
+
...modelsWithCost(["gemini-2.5-flash-native-audio-latest", "gemini-2.5-flash-native-audio-preview-12-2025"], {
|
|
626
|
+
input: .5 / 1e6,
|
|
627
|
+
output: 2 / 1e6,
|
|
628
|
+
audioInput: 3 / 1e6,
|
|
629
|
+
audioOutput: 12 / 1e6
|
|
630
|
+
}),
|
|
631
|
+
...modelsWithCost(["gemini-2.5-flash-native-audio-preview-09-2025"], {
|
|
632
|
+
input: .3 / 1e6,
|
|
633
|
+
output: 2.5 / 1e6,
|
|
634
|
+
audioInput: 1 / 1e6
|
|
635
|
+
}),
|
|
636
|
+
...modelsWithCost(["gemini-3-flash-preview"], {
|
|
637
|
+
input: .5 / 1e6,
|
|
638
|
+
output: 3 / 1e6,
|
|
639
|
+
cacheRead: .05 / 1e6,
|
|
640
|
+
cacheReadAudio: .1 / 1e6,
|
|
641
|
+
audioInput: 1 / 1e6,
|
|
642
|
+
priorityMultiplier: 1.8,
|
|
643
|
+
flexMultiplier: .5,
|
|
644
|
+
flexCacheRead: .05 / 1e6,
|
|
645
|
+
flexCacheReadAudio: .1 / 1e6
|
|
646
|
+
}),
|
|
647
|
+
{
|
|
648
|
+
id: "gemini-3-pro-preview",
|
|
649
|
+
cost: {
|
|
650
|
+
...GEMINI_3_PRO_COST,
|
|
651
|
+
priorityMultiplier: 1.8
|
|
652
|
+
},
|
|
653
|
+
tieredCost: {
|
|
654
|
+
...GEMINI_3_PRO_TIERED_COST,
|
|
655
|
+
above: {
|
|
656
|
+
...GEMINI_3_PRO_TIERED_COST.above,
|
|
657
|
+
priorityMultiplier: 1.8
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
...["gemini-2.5-pro", "gemini-2.5-computer-use-preview-10-2025"].map((id) => ({
|
|
662
|
+
id,
|
|
663
|
+
cost: id === "gemini-2.5-computer-use-preview-10-2025" ? {
|
|
664
|
+
input: 1.25 / 1e6,
|
|
665
|
+
output: 10 / 1e6
|
|
666
|
+
} : GEMINI_2_5_PRO_COST,
|
|
667
|
+
tieredCost: id === "gemini-2.5-computer-use-preview-10-2025" ? {
|
|
668
|
+
threshold: 2e5,
|
|
669
|
+
above: {
|
|
670
|
+
input: 2.5 / 1e6,
|
|
671
|
+
output: 15 / 1e6
|
|
672
|
+
}
|
|
673
|
+
} : GEMINI_2_5_PRO_TIERED_COST
|
|
674
|
+
})),
|
|
675
|
+
...modelsWithCost(["gemini-2.5-pro-preview-tts"], {
|
|
676
|
+
input: 1 / 1e6,
|
|
677
|
+
output: 20 / 1e6,
|
|
678
|
+
audioOutput: 20 / 1e6
|
|
679
|
+
}),
|
|
680
|
+
...modelsWithCost(["gemini-2.5-flash-preview-tts"], {
|
|
681
|
+
input: .5 / 1e6,
|
|
682
|
+
output: 10 / 1e6,
|
|
683
|
+
audioOutput: 10 / 1e6
|
|
684
|
+
}),
|
|
685
|
+
...modelsWithCost(["gemini-2.5-flash", "gemini-2.5-flash-preview-04-17"], {
|
|
686
|
+
input: .3 / 1e6,
|
|
687
|
+
output: 2.5 / 1e6,
|
|
688
|
+
cacheRead: .03 / 1e6,
|
|
689
|
+
cacheReadAudio: .1 / 1e6,
|
|
690
|
+
audioInput: 1 / 1e6
|
|
691
|
+
}),
|
|
692
|
+
...modelsWithCost(["gemini-2.5-flash-lite"], {
|
|
693
|
+
input: .1 / 1e6,
|
|
694
|
+
output: .4 / 1e6,
|
|
695
|
+
cacheRead: .01 / 1e6,
|
|
696
|
+
cacheReadAudio: .03 / 1e6,
|
|
697
|
+
audioInput: .3 / 1e6
|
|
698
|
+
}),
|
|
699
|
+
...["gemini-2.0-flash", "gemini-2.0-flash-001"].map((id) => ({
|
|
700
|
+
id,
|
|
701
|
+
cost: {
|
|
702
|
+
input: .1 / 1e6,
|
|
703
|
+
output: .4 / 1e6,
|
|
704
|
+
cacheRead: .025 / 1e6,
|
|
705
|
+
cacheReadAudio: .175 / 1e6,
|
|
706
|
+
audioInput: .7 / 1e6
|
|
707
|
+
},
|
|
708
|
+
vertexCost: {
|
|
709
|
+
input: .15 / 1e6,
|
|
710
|
+
output: .6 / 1e6,
|
|
711
|
+
cacheRead: .0375 / 1e6,
|
|
712
|
+
audioInput: 1 / 1e6
|
|
713
|
+
}
|
|
714
|
+
})),
|
|
715
|
+
...modelsWithCost(["gemini-2.0-flash-lite", "gemini-2.0-flash-lite-001"], {
|
|
716
|
+
input: .075 / 1e6,
|
|
717
|
+
output: .3 / 1e6,
|
|
718
|
+
cacheRead: .01875 / 1e6,
|
|
719
|
+
audioInput: .075 / 1e6
|
|
720
|
+
}),
|
|
721
|
+
{
|
|
722
|
+
id: "gemini-1.5-pro",
|
|
723
|
+
cost: {
|
|
724
|
+
input: 1.25 / 1e6,
|
|
725
|
+
output: 5 / 1e6
|
|
726
|
+
},
|
|
727
|
+
tieredCost: {
|
|
728
|
+
threshold: 128e3,
|
|
729
|
+
above: {
|
|
730
|
+
input: 2.5 / 1e6,
|
|
731
|
+
output: 10 / 1e6
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
...[
|
|
736
|
+
"gemini-1.5-pro-001",
|
|
737
|
+
"gemini-1.5-pro-002",
|
|
738
|
+
"gemini-1.5-pro-latest"
|
|
739
|
+
].map((id) => ({
|
|
740
|
+
id,
|
|
741
|
+
cost: {
|
|
742
|
+
input: 1.25 / 1e6,
|
|
743
|
+
output: 5 / 1e6
|
|
744
|
+
},
|
|
745
|
+
tieredCost: {
|
|
746
|
+
threshold: 128e3,
|
|
747
|
+
above: {
|
|
748
|
+
input: 2.5 / 1e6,
|
|
749
|
+
output: 10 / 1e6
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
})),
|
|
753
|
+
...["gemini-1.5-pro-preview-0409", "gemini-1.5-pro-preview-0514"].map((id) => ({
|
|
754
|
+
id,
|
|
755
|
+
cost: {
|
|
756
|
+
input: 1.25 / 1e6,
|
|
757
|
+
output: 5 / 1e6
|
|
758
|
+
},
|
|
759
|
+
tieredCost: {
|
|
760
|
+
threshold: 128e3,
|
|
761
|
+
above: {
|
|
762
|
+
input: 2.5 / 1e6,
|
|
763
|
+
output: 10 / 1e6
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
})),
|
|
767
|
+
...[
|
|
768
|
+
"gemini-1.5-flash",
|
|
769
|
+
"gemini-1.5-flash-001",
|
|
770
|
+
"gemini-1.5-flash-002",
|
|
771
|
+
"gemini-1.5-flash-latest",
|
|
772
|
+
"gemini-1.5-flash-preview-0514"
|
|
773
|
+
].map((id) => ({
|
|
774
|
+
id,
|
|
775
|
+
cost: {
|
|
776
|
+
input: .075 / 1e6,
|
|
777
|
+
output: .3 / 1e6
|
|
778
|
+
},
|
|
779
|
+
tieredCost: {
|
|
780
|
+
threshold: 128e3,
|
|
781
|
+
above: {
|
|
782
|
+
input: .15 / 1e6,
|
|
783
|
+
output: .6 / 1e6
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
})),
|
|
787
|
+
...[
|
|
788
|
+
"gemini-1.5-flash-8b",
|
|
789
|
+
"gemini-1.5-flash-8b-001",
|
|
790
|
+
"gemini-1.5-flash-8b-latest"
|
|
791
|
+
].map((id) => ({
|
|
792
|
+
id,
|
|
793
|
+
cost: {
|
|
794
|
+
input: .0375 / 1e6,
|
|
795
|
+
output: .15 / 1e6
|
|
796
|
+
},
|
|
797
|
+
tieredCost: {
|
|
798
|
+
threshold: 128e3,
|
|
799
|
+
above: {
|
|
800
|
+
input: .075 / 1e6,
|
|
801
|
+
output: .3 / 1e6
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
})),
|
|
805
|
+
...modelsWithCost([
|
|
806
|
+
"gemini-1.0-pro",
|
|
807
|
+
"gemini-1.0-pro-001",
|
|
808
|
+
"gemini-1.0-pro-002",
|
|
809
|
+
"gemini-1.0-pro-vision",
|
|
810
|
+
"gemini-1.0-pro-vision-001"
|
|
811
|
+
], {
|
|
812
|
+
input: .5 / 1e6,
|
|
813
|
+
output: 1.5 / 1e6
|
|
814
|
+
}),
|
|
815
|
+
...modelsWithCost(["gemini-pro"], {
|
|
816
|
+
input: .5 / 1e6,
|
|
817
|
+
output: 1.5 / 1e6
|
|
818
|
+
}),
|
|
819
|
+
...modelsWithCost(["gemini-pro-vision"], {
|
|
820
|
+
input: .5 / 1e6,
|
|
821
|
+
output: 1.5 / 1e6
|
|
822
|
+
}),
|
|
823
|
+
...modelsWithCost(["gemini-robotics-er-1.6-preview"], {
|
|
824
|
+
input: 1 / 1e6,
|
|
825
|
+
output: 5 / 1e6,
|
|
826
|
+
audioInput: 2 / 1e6
|
|
827
|
+
}),
|
|
828
|
+
...modelsWithCost(["gemini-robotics-er-2-preview"], {
|
|
829
|
+
input: 2 / 1e6,
|
|
830
|
+
output: 10 / 1e6,
|
|
831
|
+
cacheRead: .2 / 1e6
|
|
832
|
+
}),
|
|
833
|
+
...modelsWithCost(["gemini-robotics-er-2-streaming-preview"], {
|
|
834
|
+
input: 2 / 1e6,
|
|
835
|
+
output: 10 / 1e6
|
|
836
|
+
}),
|
|
837
|
+
...modelsWithCost([
|
|
838
|
+
"gemini-embedding-2",
|
|
839
|
+
"embedding-2-preview",
|
|
840
|
+
"gemini-embedding-2-preview"
|
|
841
|
+
], {
|
|
842
|
+
input: .2 / 1e6,
|
|
843
|
+
output: 0
|
|
844
|
+
}),
|
|
845
|
+
...modelsWithCost(["gemini-embedding-001"], {
|
|
846
|
+
input: .15 / 1e6,
|
|
847
|
+
output: 0
|
|
848
|
+
}),
|
|
849
|
+
{ id: "aqa" },
|
|
850
|
+
{ id: "chat-bison" },
|
|
851
|
+
{ id: "chat-bison-32k" },
|
|
852
|
+
{ id: "chat-bison-32k@001" },
|
|
853
|
+
{ id: "chat-bison-32k@002" },
|
|
854
|
+
{ id: "chat-bison@001" },
|
|
855
|
+
{ id: "chat-bison@002" },
|
|
856
|
+
{ id: "codechat-bison" },
|
|
857
|
+
{ id: "codechat-bison-32k" },
|
|
858
|
+
{ id: "codechat-bison-32k@001" },
|
|
859
|
+
{ id: "codechat-bison-32k@002" },
|
|
860
|
+
{ id: "codechat-bison@001" },
|
|
861
|
+
{ id: "codechat-bison@002" },
|
|
862
|
+
{ id: "gemini-ultra" },
|
|
863
|
+
{ id: "gemma" },
|
|
864
|
+
{ id: "gemma-4-31b-it" },
|
|
865
|
+
{ id: "gemma-4-26b-a4b-it" },
|
|
866
|
+
{ id: "codegemma" },
|
|
867
|
+
{ id: "paligemma" },
|
|
868
|
+
{ id: "medlm-medium" },
|
|
869
|
+
{ id: "medlm-large" }
|
|
870
|
+
];
|
|
871
|
+
/**
|
|
872
|
+
* List of chat model IDs for backwards compatibility.
|
|
873
|
+
* Used for model validation in ai.studio.ts.
|
|
874
|
+
*/
|
|
875
|
+
const CHAT_MODELS = GOOGLE_MODELS.map((m) => m.id);
|
|
876
|
+
function modelsWithCost(ids, cost) {
|
|
877
|
+
return ids.map((id) => ({
|
|
878
|
+
id,
|
|
879
|
+
cost: { ...cost }
|
|
880
|
+
}));
|
|
881
|
+
}
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/providers/google/types.ts
|
|
884
|
+
const VALID_SCHEMA_TYPES = [
|
|
885
|
+
"TYPE_UNSPECIFIED",
|
|
886
|
+
"STRING",
|
|
887
|
+
"NUMBER",
|
|
888
|
+
"INTEGER",
|
|
889
|
+
"BOOLEAN",
|
|
890
|
+
"ARRAY",
|
|
891
|
+
"OBJECT"
|
|
892
|
+
];
|
|
893
|
+
//#endregion
|
|
894
|
+
//#region src/providers/google/util.ts
|
|
895
|
+
/**
|
|
896
|
+
* Normalizes safety settings to use the correct Google API field name `threshold`.
|
|
897
|
+
* Accepts the legacy `probability` field for backwards compatibility and maps it to `threshold`.
|
|
898
|
+
*/
|
|
899
|
+
function normalizeSafetySettings(safetySettings) {
|
|
900
|
+
if (!safetySettings) return;
|
|
901
|
+
return safetySettings.map(({ category, threshold, probability }) => ({
|
|
902
|
+
category,
|
|
903
|
+
threshold: threshold || probability || ""
|
|
904
|
+
}));
|
|
905
|
+
}
|
|
906
|
+
/** Normalize supported tier names, including legacy prefixed configuration values. */
|
|
907
|
+
function normalizeGoogleServiceTier(serviceTier) {
|
|
908
|
+
if (typeof serviceTier !== "string") return;
|
|
909
|
+
const normalized = serviceTier.toLowerCase().replace(/^service_tier_/, "");
|
|
910
|
+
if (normalized !== "standard" && normalized !== "priority" && normalized !== "flex") return serviceTier;
|
|
911
|
+
return normalized;
|
|
912
|
+
}
|
|
913
|
+
/** Add the documented Vertex PayGo tier without overriding an explicit custom header. */
|
|
914
|
+
function getVertexServiceTierHeaders(serviceTier, headers = {}) {
|
|
915
|
+
const headerName = "X-Vertex-AI-LLM-Shared-Request-Type";
|
|
916
|
+
if (Object.keys(headers).some((name) => name.toLowerCase() === headerName.toLowerCase())) return headers;
|
|
917
|
+
const normalized = normalizeGoogleServiceTier(serviceTier);
|
|
918
|
+
return normalized === "priority" || normalized === "flex" ? {
|
|
919
|
+
[headerName]: normalized,
|
|
920
|
+
...headers
|
|
921
|
+
} : headers;
|
|
922
|
+
}
|
|
923
|
+
/** Read the actual processing tier before estimating costs for a downgraded request. */
|
|
924
|
+
function getGoogleResponseServiceTier(headers, usageMetadata, vertexai = false) {
|
|
925
|
+
let headerValue;
|
|
926
|
+
if (headers && typeof headers === "object") {
|
|
927
|
+
const headerCollection = headers;
|
|
928
|
+
headerValue = typeof headerCollection.get === "function" ? headerCollection.get("x-gemini-service-tier") : Object.entries(headerCollection).find(([name]) => name.toLowerCase() === "x-gemini-service-tier")?.[1];
|
|
929
|
+
}
|
|
930
|
+
const metadata = usageMetadata;
|
|
931
|
+
if (headerValue == null && vertexai && metadata?.trafficType !== void 0) switch (metadata.trafficType) {
|
|
932
|
+
case "ON_DEMAND": return "standard";
|
|
933
|
+
case "ON_DEMAND_PRIORITY": return "priority";
|
|
934
|
+
case "ON_DEMAND_FLEX": return "flex";
|
|
935
|
+
default: return;
|
|
936
|
+
}
|
|
937
|
+
const normalized = normalizeGoogleServiceTier(headerValue ?? metadata?.serviceTier ?? metadata?.service_tier);
|
|
938
|
+
return normalized === "standard" || normalized === "priority" || normalized === "flex" ? normalized : void 0;
|
|
939
|
+
}
|
|
940
|
+
function normalizeGoogleToolMode(mode) {
|
|
941
|
+
if (typeof mode !== "string") return;
|
|
942
|
+
switch (mode.toUpperCase()) {
|
|
943
|
+
case "MODE_UNSPECIFIED":
|
|
944
|
+
case "AUTO":
|
|
945
|
+
case "VALIDATED":
|
|
946
|
+
case "ANY":
|
|
947
|
+
case "NONE": return mode.toUpperCase();
|
|
948
|
+
default: return;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
function normalizeCamelCaseGoogleToolConfig(config) {
|
|
952
|
+
const { functionCallingConfig: rawFunctionCallingConfig, ...restToolConfig } = config;
|
|
953
|
+
const normalizedToolConfig = { ...restToolConfig };
|
|
954
|
+
if (rawFunctionCallingConfig) {
|
|
955
|
+
const { mode: rawMode, allowedFunctionNames, ...restFunctionCallingConfig } = rawFunctionCallingConfig;
|
|
956
|
+
const mode = normalizeGoogleToolMode(rawMode);
|
|
957
|
+
const functionCallingConfig = {
|
|
958
|
+
...restFunctionCallingConfig,
|
|
959
|
+
...mode ? { mode } : {},
|
|
960
|
+
...allowedFunctionNames?.length ? { allowedFunctionNames } : {}
|
|
961
|
+
};
|
|
962
|
+
if (Object.keys(functionCallingConfig).length > 0) normalizedToolConfig.functionCallingConfig = functionCallingConfig;
|
|
963
|
+
}
|
|
964
|
+
return Object.keys(normalizedToolConfig).length > 0 ? normalizedToolConfig : void 0;
|
|
965
|
+
}
|
|
966
|
+
function normalizeSnakeCaseGoogleToolConfig(config) {
|
|
967
|
+
const { function_calling_config: rawFunctionCallingConfig, retrieval_config: retrievalConfig, include_server_side_tool_invocations: includeServerSideToolInvocations } = config;
|
|
968
|
+
const normalizedToolConfig = {
|
|
969
|
+
...retrievalConfig ? { retrievalConfig: {
|
|
970
|
+
...retrievalConfig.lat_lng ? { latLng: retrievalConfig.lat_lng } : {},
|
|
971
|
+
...retrievalConfig.language_code ? { languageCode: retrievalConfig.language_code } : {}
|
|
972
|
+
} } : {},
|
|
973
|
+
...includeServerSideToolInvocations === void 0 ? {} : { includeServerSideToolInvocations }
|
|
974
|
+
};
|
|
975
|
+
if (rawFunctionCallingConfig) {
|
|
976
|
+
const { mode: rawMode, allowed_function_names: allowedFunctionNames, stream_function_call_arguments: streamFunctionCallArguments } = rawFunctionCallingConfig;
|
|
977
|
+
const mode = normalizeGoogleToolMode(rawMode);
|
|
978
|
+
const functionCallingConfig = {
|
|
979
|
+
...mode ? { mode } : {},
|
|
980
|
+
...allowedFunctionNames?.length ? { allowedFunctionNames } : {},
|
|
981
|
+
...streamFunctionCallArguments === void 0 ? {} : { streamFunctionCallArguments }
|
|
982
|
+
};
|
|
983
|
+
if (Object.keys(functionCallingConfig).length > 0) normalizedToolConfig.functionCallingConfig = functionCallingConfig;
|
|
984
|
+
}
|
|
985
|
+
return Object.keys(normalizedToolConfig).length > 0 ? normalizedToolConfig : void 0;
|
|
986
|
+
}
|
|
987
|
+
function normalizeGoogleToolConfig(config) {
|
|
988
|
+
if (config.toolConfig) return normalizeCamelCaseGoogleToolConfig(config.toolConfig);
|
|
989
|
+
return config.tool_config ? normalizeSnakeCaseGoogleToolConfig(config.tool_config) : void 0;
|
|
990
|
+
}
|
|
991
|
+
function resolveGoogleToolConfig(config) {
|
|
992
|
+
const explicitConfig = normalizeGoogleToolConfig(config);
|
|
993
|
+
const passthrough = config.passthrough;
|
|
994
|
+
const passthroughConfig = passthrough ? normalizeGoogleToolConfig(passthrough) : void 0;
|
|
995
|
+
const transformedToolChoice = transformToolChoice(config.tool_choice, "google");
|
|
996
|
+
const toolChoiceConfig = transformedToolChoice && typeof transformedToolChoice === "object" ? transformedToolChoice : void 0;
|
|
997
|
+
const toolConfig = {
|
|
998
|
+
...toolChoiceConfig,
|
|
999
|
+
...explicitConfig,
|
|
1000
|
+
...passthroughConfig
|
|
1001
|
+
};
|
|
1002
|
+
const functionCallingConfig = {
|
|
1003
|
+
...toolChoiceConfig?.functionCallingConfig,
|
|
1004
|
+
...explicitConfig?.functionCallingConfig,
|
|
1005
|
+
...passthroughConfig?.functionCallingConfig
|
|
1006
|
+
};
|
|
1007
|
+
if (Object.keys(functionCallingConfig).length > 0) toolConfig.functionCallingConfig = functionCallingConfig;
|
|
1008
|
+
return {
|
|
1009
|
+
...Object.keys(toolConfig).length > 0 ? { toolConfig } : {},
|
|
1010
|
+
toolsDisabled: functionCallingConfig.mode === "NONE"
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
/** Merge configured tools with single-object or array passthrough tools. */
|
|
1014
|
+
function mergeGoogleRequestTools(configuredTools, passthroughTools) {
|
|
1015
|
+
if (passthroughTools === void 0) return configuredTools.length > 0 ? configuredTools : void 0;
|
|
1016
|
+
return [...configuredTools, ...Array.isArray(passthroughTools) ? passthroughTools : [passthroughTools]];
|
|
1017
|
+
}
|
|
1018
|
+
/** Resolve native Gemini endpoints consistently across text and image adapters. */
|
|
1019
|
+
function getGoogleApiBaseUrl(config, env) {
|
|
1020
|
+
if (config.apiHost) return `https://${getNunjucksEngine().renderString(config.apiHost, {})}`;
|
|
1021
|
+
if (config.apiBaseUrl) return config.apiBaseUrl;
|
|
1022
|
+
const endpoint = resolveProviderEnv(env, [
|
|
1023
|
+
"GOOGLE_API_HOST",
|
|
1024
|
+
"PALM_API_HOST",
|
|
1025
|
+
"GOOGLE_API_BASE_URL"
|
|
1026
|
+
]);
|
|
1027
|
+
if (endpoint?.name === "GOOGLE_API_BASE_URL") return endpoint.value;
|
|
1028
|
+
return `https://${getNunjucksEngine().renderString(endpoint?.value || "generativelanguage.googleapis.com", {})}`;
|
|
1029
|
+
}
|
|
1030
|
+
function mergeGoogleCompletionOptions(baseConfig, promptConfig) {
|
|
1031
|
+
const mergedConfig = {
|
|
1032
|
+
...baseConfig,
|
|
1033
|
+
...promptConfig
|
|
1034
|
+
};
|
|
1035
|
+
const promptHasToolChoice = promptConfig?.tool_choice !== void 0;
|
|
1036
|
+
const promptHasToolConfig = promptConfig?.toolConfig !== void 0;
|
|
1037
|
+
const promptHasSnakeToolConfig = promptConfig?.tool_config !== void 0;
|
|
1038
|
+
if (promptHasToolChoice || promptHasToolConfig || promptHasSnakeToolConfig) {
|
|
1039
|
+
delete mergedConfig.tool_choice;
|
|
1040
|
+
delete mergedConfig.toolConfig;
|
|
1041
|
+
delete mergedConfig.tool_config;
|
|
1042
|
+
if (promptHasToolChoice) mergedConfig.tool_choice = promptConfig.tool_choice;
|
|
1043
|
+
if (promptHasToolConfig) mergedConfig.toolConfig = promptConfig.toolConfig;
|
|
1044
|
+
if (promptHasSnakeToolConfig) mergedConfig.tool_config = promptConfig.tool_config;
|
|
1045
|
+
if (promptHasToolChoice && !promptHasToolConfig && !promptHasSnakeToolConfig) {
|
|
1046
|
+
const baseToolConfig = normalizeGoogleToolConfig(baseConfig);
|
|
1047
|
+
if (baseToolConfig) {
|
|
1048
|
+
const { functionCallingConfig: _functionCallingConfig, ...nonFunctionToolConfig } = baseToolConfig;
|
|
1049
|
+
if (Object.keys(nonFunctionToolConfig).length > 0) mergedConfig.toolConfig = nonFunctionToolConfig;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
if (promptConfig?.passthrough === void 0 && baseConfig.passthrough) {
|
|
1053
|
+
const passthrough = { ...baseConfig.passthrough };
|
|
1054
|
+
const inheritedToolConfig = normalizeGoogleToolConfig(passthrough);
|
|
1055
|
+
delete passthrough.toolConfig;
|
|
1056
|
+
delete passthrough.tool_config;
|
|
1057
|
+
if (inheritedToolConfig) {
|
|
1058
|
+
const { functionCallingConfig: _functionCallingConfig, ...nonFunctionToolConfig } = inheritedToolConfig;
|
|
1059
|
+
if (Object.keys(nonFunctionToolConfig).length > 0) passthrough.toolConfig = nonFunctionToolConfig;
|
|
1060
|
+
}
|
|
1061
|
+
mergedConfig.passthrough = passthrough;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return mergedConfig;
|
|
1065
|
+
}
|
|
1066
|
+
function removeGoogleFunctionDeclarations(tools) {
|
|
1067
|
+
return (Array.isArray(tools) ? tools : [tools]).flatMap((rawTool) => {
|
|
1068
|
+
if (!rawTool || typeof rawTool !== "object" || Array.isArray(rawTool)) return [];
|
|
1069
|
+
const { functionDeclarations, function_declarations, ...tool } = rawTool;
|
|
1070
|
+
return (functionDeclarations || function_declarations) && Object.keys(tool).length === 0 ? [] : [tool];
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Current Gemini Flash models ignore sampling parameters and reject penalties
|
|
1075
|
+
* and candidate counts. Remove typed and passthrough spellings.
|
|
1076
|
+
*/
|
|
1077
|
+
function removeDeprecatedGeminiGenerationParams(modelName, generationConfig) {
|
|
1078
|
+
if (!GEMINI_FLASH_MODELS.some(({ id }) => modelName.startsWith(id)) && modelName !== "gemini-flash-latest" && modelName !== "gemini-flash-lite-latest") return generationConfig;
|
|
1079
|
+
if (!generationConfig || typeof generationConfig !== "object" || Array.isArray(generationConfig)) return generationConfig;
|
|
1080
|
+
const sanitized = { ...generationConfig };
|
|
1081
|
+
for (const field of [
|
|
1082
|
+
"temperature",
|
|
1083
|
+
"topP",
|
|
1084
|
+
"top_p",
|
|
1085
|
+
"topK",
|
|
1086
|
+
"top_k",
|
|
1087
|
+
"candidateCount",
|
|
1088
|
+
"candidate_count",
|
|
1089
|
+
"presencePenalty",
|
|
1090
|
+
"presence_penalty",
|
|
1091
|
+
"frequencyPenalty",
|
|
1092
|
+
"frequency_penalty"
|
|
1093
|
+
]) delete sanitized[field];
|
|
1094
|
+
if (modelName.startsWith("gemini-3.8-flash") || modelName.startsWith("gemini-3.7-flash") || modelName === "gemini-flash-latest") for (const config of [sanitized.thinkingConfig, sanitized.thinking_config]) {
|
|
1095
|
+
const thinkingConfig = config;
|
|
1096
|
+
if (thinkingConfig?.thinkingBudget !== void 0 || thinkingConfig?.thinking_budget !== void 0) throw new Error(`${modelName} does not support thinkingBudget. Use thinkingLevel (LOW, MEDIUM, or HIGH).`);
|
|
1097
|
+
const thinkingLevel = thinkingConfig?.thinkingLevel ?? thinkingConfig?.thinking_level;
|
|
1098
|
+
if (typeof thinkingLevel === "string" && thinkingLevel.toUpperCase() === "MINIMAL") throw new Error(`${modelName} does not support MINIMAL thinking. Use LOW, MEDIUM, or HIGH.`);
|
|
1099
|
+
}
|
|
1100
|
+
return sanitized;
|
|
1101
|
+
}
|
|
1102
|
+
function stripExecutableToolFileReferencesFromValue(tools) {
|
|
1103
|
+
if (typeof tools === "string" && tools.startsWith("file://")) {
|
|
1104
|
+
const { filePath } = parseFileUrl(tools);
|
|
1105
|
+
if (filePath.endsWith(".py") || isJavascriptFile(filePath)) return;
|
|
1106
|
+
}
|
|
1107
|
+
if (Array.isArray(tools)) return tools.flatMap((tool) => {
|
|
1108
|
+
const strippedTool = stripExecutableToolFileReferencesFromValue(tool);
|
|
1109
|
+
return strippedTool === void 0 ? [] : [strippedTool];
|
|
1110
|
+
});
|
|
1111
|
+
return tools;
|
|
1112
|
+
}
|
|
1113
|
+
function stripExecutableToolFileReferences(tools, vars) {
|
|
1114
|
+
return stripExecutableToolFileReferencesFromValue(renderVarsInObject(tools, vars));
|
|
1115
|
+
}
|
|
1116
|
+
/** Load and normalize configured tools using the shared file and variable handling. */
|
|
1117
|
+
async function loadGoogleTools(tools, vars, options = {}) {
|
|
1118
|
+
const requestTools = options.skipExecutableToolFiles ? stripExecutableToolFileReferences(tools, vars) : tools;
|
|
1119
|
+
const loadedTools = requestTools ? await maybeLoadToolsFromExternalFile(requestTools, options.skipExecutableToolFiles ? void 0 : vars, options.abortSignal) : [];
|
|
1120
|
+
return normalizeTools(Array.isArray(loadedTools) ? transformTools(loadedTools, "google") : loadedTools ? [loadedTools] : []);
|
|
1121
|
+
}
|
|
1122
|
+
function getServiceTierCacheRead(modelCost, serviceTier, modality = "default") {
|
|
1123
|
+
if (serviceTier === "priority") return modality === "audio" ? modelCost.priorityCacheReadAudio ?? modelCost.priorityCacheRead : modelCost.priorityCacheRead;
|
|
1124
|
+
if (serviceTier === "flex") return modality === "audio" ? modelCost.flexCacheReadAudio ?? modelCost.flexCacheRead : modelCost.flexCacheRead;
|
|
1125
|
+
}
|
|
1126
|
+
function resolveServiceTierCacheCost(defaultCost, exactTierCost, serviceTierMultiplier) {
|
|
1127
|
+
return exactTierCost === void 0 ? defaultCost : exactTierCost / serviceTierMultiplier;
|
|
1128
|
+
}
|
|
1129
|
+
function resolveGoogleServiceTierCosts(modelCost, serviceTier, cachedInputCost, cachedAudioInputCost, cachedImageInputCost, audioInputCost) {
|
|
1130
|
+
let serviceTierMultiplier = 1;
|
|
1131
|
+
if (serviceTier === "priority") serviceTierMultiplier = modelCost.priorityMultiplier ?? 1;
|
|
1132
|
+
else if (serviceTier === "flex") serviceTierMultiplier = modelCost.flexMultiplier ?? 1;
|
|
1133
|
+
const tierCacheRead = getServiceTierCacheRead(modelCost, serviceTier);
|
|
1134
|
+
const tierAudioCacheRead = getServiceTierCacheRead(modelCost, serviceTier, "audio");
|
|
1135
|
+
const serviceTierCachedInputCost = resolveServiceTierCacheCost(cachedInputCost, tierCacheRead, serviceTierMultiplier);
|
|
1136
|
+
const serviceTierCachedAudioInputCost = resolveServiceTierCacheCost(cachedAudioInputCost, tierAudioCacheRead, serviceTierMultiplier);
|
|
1137
|
+
const serviceTierCachedImageInputCost = resolveServiceTierCacheCost(cachedImageInputCost, tierCacheRead, serviceTierMultiplier);
|
|
1138
|
+
let serviceTierAudioInputCost = audioInputCost;
|
|
1139
|
+
if (serviceTier === "priority" && modelCost.priorityAudioInput !== void 0) serviceTierAudioInputCost = modelCost.priorityAudioInput / serviceTierMultiplier;
|
|
1140
|
+
else if (serviceTier === "flex" && modelCost.flexAudioInput !== void 0) serviceTierAudioInputCost = modelCost.flexAudioInput / serviceTierMultiplier;
|
|
1141
|
+
return {
|
|
1142
|
+
serviceTierMultiplier,
|
|
1143
|
+
serviceTierCachedInputCost,
|
|
1144
|
+
serviceTierCachedAudioInputCost,
|
|
1145
|
+
serviceTierCachedImageInputCost,
|
|
1146
|
+
serviceTierAudioInputCost
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
function applyGoogleRegionalPremium(modelCost, multiplier) {
|
|
1150
|
+
const scale = (value) => value === void 0 ? void 0 : value * multiplier;
|
|
1151
|
+
return {
|
|
1152
|
+
...modelCost,
|
|
1153
|
+
input: modelCost.input * multiplier,
|
|
1154
|
+
output: modelCost.output * multiplier,
|
|
1155
|
+
cacheRead: scale(modelCost.cacheRead),
|
|
1156
|
+
cacheReadAudio: scale(modelCost.cacheReadAudio),
|
|
1157
|
+
audioInput: scale(modelCost.audioInput),
|
|
1158
|
+
audioOutput: scale(modelCost.audioOutput),
|
|
1159
|
+
imageInput: scale(modelCost.imageInput),
|
|
1160
|
+
videoInputPerSecond: scale(modelCost.videoInputPerSecond),
|
|
1161
|
+
videoOutput: scale(modelCost.videoOutput),
|
|
1162
|
+
priorityCacheRead: scale(modelCost.priorityCacheRead),
|
|
1163
|
+
priorityCacheReadAudio: scale(modelCost.priorityCacheReadAudio),
|
|
1164
|
+
priorityAudioInput: scale(modelCost.priorityAudioInput),
|
|
1165
|
+
flexCacheRead: scale(modelCost.flexCacheRead),
|
|
1166
|
+
flexCacheReadAudio: scale(modelCost.flexCacheReadAudio),
|
|
1167
|
+
flexAudioInput: scale(modelCost.flexAudioInput)
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function getGoogleCatalogCost(model, promptTokens, isVertexMode, usesNonGlobalVertexEndpoint) {
|
|
1171
|
+
if (model?.tieredCost && promptTokens > model.tieredCost.threshold) return model.tieredCost.above;
|
|
1172
|
+
if (usesNonGlobalVertexEndpoint && model?.vertexRegionalCost) return model.vertexRegionalCost;
|
|
1173
|
+
if (isVertexMode && model?.vertexCost) return model.vertexCost;
|
|
1174
|
+
return model?.cost;
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Calculates the cost for a Google API call.
|
|
1178
|
+
*
|
|
1179
|
+
* Handles tiered pricing for models where cost varies by prompt size.
|
|
1180
|
+
* For example, Gemini Pro models have higher rates for prompts >200k tokens.
|
|
1181
|
+
* Some models (e.g. Gemini 2.0 Flash) have different pricing on Vertex AI.
|
|
1182
|
+
*
|
|
1183
|
+
* @param modelName - The name of the model used
|
|
1184
|
+
* @param config - Provider configuration (may contain custom cost override)
|
|
1185
|
+
* @param promptTokens - Number of tokens in the prompt
|
|
1186
|
+
* @param completionTokens - Number of tokens in the completion
|
|
1187
|
+
* @param isVertexMode - Whether the call was made via Vertex AI (uses Vertex pricing when available)
|
|
1188
|
+
* @param audioPromptTokens - Number of audio tokens included in the prompt token count
|
|
1189
|
+
* @param audioCompletionTokens - Number of audio tokens included in the completion token count
|
|
1190
|
+
* @param videoCompletionTokens - Number of video tokens included in the completion token count
|
|
1191
|
+
* @param imagePromptTokens - Number of image tokens included in the prompt token count
|
|
1192
|
+
* @param cachedPromptTokens - Number of cached tokens included in the prompt token count
|
|
1193
|
+
* @param cachedAudioPromptTokens - Number of cached audio tokens included in the prompt token count
|
|
1194
|
+
* @param cachedImagePromptTokens - Number of cached image tokens included in the prompt token count
|
|
1195
|
+
* @returns The calculated cost in dollars, or undefined if it cannot be calculated
|
|
1196
|
+
*/
|
|
1197
|
+
function calculateGoogleCost(modelName, config, promptTokens, completionTokens, isVertexMode, audioPromptTokens, audioCompletionTokens, videoCompletionTokens, imagePromptTokens, cachedPromptTokens, cachedAudioPromptTokens, cachedImagePromptTokens, actualServiceTier, vertexRegion, requestedServiceTier, pricingTime = Date.now()) {
|
|
1198
|
+
const timestamp = Number.isFinite(pricingTime) ? pricingTime : Date.now();
|
|
1199
|
+
const pricingModelName = !isVertexMode && modelName === "gemini-3.5-flash" && timestamp >= Date.UTC(2026, 9, 8) ? "gemini-3.6-flash" : modelName;
|
|
1200
|
+
const model = GOOGLE_MODELS.find((m) => m.id === pricingModelName);
|
|
1201
|
+
if (typeof promptTokens !== "number" || typeof completionTokens !== "number" || !Number.isFinite(promptTokens) || !Number.isFinite(completionTokens)) return calculateCost(modelName, config, promptTokens, completionTokens, GOOGLE_MODELS);
|
|
1202
|
+
const effectiveVertexRegion = vertexRegion ?? config.region;
|
|
1203
|
+
const usesNonGlobalVertexEndpoint = isVertexMode && effectiveVertexRegion !== void 0 && effectiveVertexRegion !== "global";
|
|
1204
|
+
const baseModelCost = getGoogleCatalogCost(model, promptTokens, isVertexMode, usesNonGlobalVertexEndpoint);
|
|
1205
|
+
if (!baseModelCost) return;
|
|
1206
|
+
const vertexRegionalMultiplier = usesNonGlobalVertexEndpoint && model?.vertexRegionalCost === void 0 && model?.vertexRegionalPremium !== void 0 ? model.vertexRegionalPremium : 1;
|
|
1207
|
+
const catalogMultiplier = model?.introductoryPricing && timestamp < model.introductoryPricing.expiresAt ? model.introductoryPricing.multiplier : 1;
|
|
1208
|
+
const applyCatalogMultiplier = (rate) => rate === void 0 ? void 0 : rate * catalogMultiplier;
|
|
1209
|
+
const modelCost = vertexRegionalMultiplier === 1 ? baseModelCost : applyGoogleRegionalPremium(baseModelCost, vertexRegionalMultiplier);
|
|
1210
|
+
const serviceTier = normalizeGoogleServiceTier(actualServiceTier ?? (isVertexMode ? requestedServiceTier : void 0) ?? config.passthrough?.service_tier ?? config.passthrough?.serviceTier ?? config.service_tier);
|
|
1211
|
+
const catalogInputCost = modelCost.input * catalogMultiplier;
|
|
1212
|
+
const catalogOutputCost = modelCost.output * catalogMultiplier;
|
|
1213
|
+
const catalogAudioInputCost = applyCatalogMultiplier(modelCost.audioInput) ?? catalogInputCost;
|
|
1214
|
+
const catalogImageInputCost = applyCatalogMultiplier(modelCost.imageInput) ?? catalogInputCost;
|
|
1215
|
+
const catalogCacheRead = applyCatalogMultiplier(modelCost.cacheRead);
|
|
1216
|
+
const tierCosts = resolveGoogleServiceTierCosts(applyGoogleRegionalPremium(modelCost, catalogMultiplier), serviceTier, catalogCacheRead ?? catalogInputCost, applyCatalogMultiplier(modelCost.cacheReadAudio) ?? catalogCacheRead ?? catalogAudioInputCost, catalogCacheRead ?? catalogImageInputCost, catalogAudioInputCost);
|
|
1217
|
+
const multiplier = tierCosts.serviceTierMultiplier;
|
|
1218
|
+
const inputCost = config.inputCost ?? config.cost ?? catalogInputCost * multiplier;
|
|
1219
|
+
const outputCost = config.outputCost ?? config.cost ?? catalogOutputCost * multiplier;
|
|
1220
|
+
const audioInputTokens = clampCachedTokens(audioPromptTokens, promptTokens);
|
|
1221
|
+
const imageInputTokens = clampCachedTokens(imagePromptTokens, Math.max(promptTokens - audioInputTokens, 0));
|
|
1222
|
+
const textInputTokens = Math.max(promptTokens - audioInputTokens - imageInputTokens, 0);
|
|
1223
|
+
const cachedTokens = clampCachedTokens(cachedPromptTokens, promptTokens);
|
|
1224
|
+
let cachedAudioTokens = clampCachedTokens(cachedAudioPromptTokens, Math.min(cachedTokens, audioInputTokens));
|
|
1225
|
+
let cachedImageTokens = clampCachedTokens(cachedImagePromptTokens, Math.min(Math.max(cachedTokens - cachedAudioTokens, 0), imageInputTokens));
|
|
1226
|
+
if (cachedAudioTokens === 0 && cachedImageTokens === 0) {
|
|
1227
|
+
const cachedNonTextTokens = Math.max(cachedTokens - textInputTokens, 0);
|
|
1228
|
+
if (imageInputTokens === 0) cachedAudioTokens = Math.min(cachedNonTextTokens, audioInputTokens);
|
|
1229
|
+
else if (audioInputTokens === 0) cachedImageTokens = Math.min(cachedNonTextTokens, imageInputTokens);
|
|
1230
|
+
}
|
|
1231
|
+
const cachedTextTokens = Math.min(Math.max(cachedTokens - cachedAudioTokens - cachedImageTokens, 0), textInputTokens);
|
|
1232
|
+
const audioOutputTokens = clampCachedTokens(audioCompletionTokens, completionTokens);
|
|
1233
|
+
const videoOutputTokens = clampCachedTokens(videoCompletionTokens, Math.max(completionTokens - audioOutputTokens, 0));
|
|
1234
|
+
const audioInputCost = config.audioInputCost ?? config.audioCost ?? config.inputCost ?? config.cost ?? tierCosts.serviceTierAudioInputCost * multiplier;
|
|
1235
|
+
const audioOutputCost = config.audioOutputCost ?? config.audioCost ?? config.outputCost ?? config.cost ?? (applyCatalogMultiplier(modelCost.audioOutput) ?? catalogOutputCost) * multiplier;
|
|
1236
|
+
const videoOutputCost = config.videoOutputCost ?? config.outputCost ?? config.cost ?? (applyCatalogMultiplier(modelCost.videoOutput) ?? catalogOutputCost) * multiplier;
|
|
1237
|
+
const imageInputCost = config.imageInputCost ?? config.inputCost ?? config.cost ?? catalogImageInputCost * multiplier;
|
|
1238
|
+
const cachedInputCost = config.inputCost ?? config.cost ?? tierCosts.serviceTierCachedInputCost * multiplier;
|
|
1239
|
+
const cachedAudioInputCost = config.audioInputCost ?? config.audioCost ?? config.inputCost ?? config.cost ?? tierCosts.serviceTierCachedAudioInputCost * multiplier;
|
|
1240
|
+
const cachedImageInputCost = config.imageInputCost ?? config.inputCost ?? config.cost ?? tierCosts.serviceTierCachedImageInputCost * multiplier;
|
|
1241
|
+
return (textInputTokens - cachedTextTokens) * inputCost + cachedTextTokens * cachedInputCost + (audioInputTokens - cachedAudioTokens) * audioInputCost + cachedAudioTokens * cachedAudioInputCost + (imageInputTokens - cachedImageTokens) * imageInputCost + cachedImageTokens * cachedImageInputCost + (completionTokens - audioOutputTokens - videoOutputTokens) * outputCost + audioOutputTokens * audioOutputCost + videoOutputTokens * videoOutputCost;
|
|
1242
|
+
}
|
|
1243
|
+
const getGoogleModalityTokenCount = (details, modalities) => {
|
|
1244
|
+
if (!Array.isArray(details)) return 0;
|
|
1245
|
+
return details.reduce((total, detail) => {
|
|
1246
|
+
const tokenCount = detail?.tokenCount ?? detail?.token_count;
|
|
1247
|
+
return modalities.includes(detail?.modality) && typeof tokenCount === "number" && Number.isFinite(tokenCount) ? total + Math.max(tokenCount, 0) : total;
|
|
1248
|
+
}, 0);
|
|
1249
|
+
};
|
|
1250
|
+
function calculateGoogleCostFromUsage(modelName, config, promptTokens, completionTokens, isVertexMode, usageMetadata, responseServiceTier, vertexRegion, requestedServiceTier, pricingTime) {
|
|
1251
|
+
const promptDetails = usageMetadata?.promptTokensDetails ?? usageMetadata?.prompt_tokens_details;
|
|
1252
|
+
const toolPromptDetails = usageMetadata?.toolUsePromptTokensDetails ?? usageMetadata?.tool_use_prompt_tokens_details;
|
|
1253
|
+
const responseDetails = usageMetadata?.candidatesTokensDetails ?? usageMetadata?.responseTokensDetails ?? usageMetadata?.candidates_tokens_details ?? usageMetadata?.response_tokens_details;
|
|
1254
|
+
const cacheDetails = usageMetadata?.cacheTokensDetails ?? usageMetadata?.cache_tokens_details;
|
|
1255
|
+
const toolPromptTokens = usageMetadata?.toolUsePromptTokenCount ?? usageMetadata?.tool_use_prompt_token_count ?? 0;
|
|
1256
|
+
const promptTokensForCost = typeof promptTokens === "number" && typeof toolPromptTokens === "number" && Number.isFinite(toolPromptTokens) ? promptTokens + Math.max(toolPromptTokens, 0) : promptTokens;
|
|
1257
|
+
const audioPromptTokens = getGoogleModalityTokenCount(promptDetails, ["AUDIO"]) + getGoogleModalityTokenCount(toolPromptDetails, ["AUDIO"]);
|
|
1258
|
+
const imagePromptTokens = getGoogleModalityTokenCount(promptDetails, [
|
|
1259
|
+
"IMAGE",
|
|
1260
|
+
"VIDEO",
|
|
1261
|
+
"DOCUMENT"
|
|
1262
|
+
]) + getGoogleModalityTokenCount(toolPromptDetails, [
|
|
1263
|
+
"IMAGE",
|
|
1264
|
+
"VIDEO",
|
|
1265
|
+
"DOCUMENT"
|
|
1266
|
+
]);
|
|
1267
|
+
return calculateGoogleCost(modelName, config, promptTokensForCost, completionTokens, isVertexMode, audioPromptTokens, getGoogleModalityTokenCount(responseDetails, ["AUDIO"]), getGoogleModalityTokenCount(responseDetails, ["VIDEO"]), imagePromptTokens, usageMetadata?.cachedContentTokenCount ?? usageMetadata?.cached_content_token_count, getGoogleModalityTokenCount(cacheDetails, ["AUDIO"]), getGoogleModalityTokenCount(cacheDetails, [
|
|
1268
|
+
"IMAGE",
|
|
1269
|
+
"VIDEO",
|
|
1270
|
+
"DOCUMENT"
|
|
1271
|
+
]), getGoogleResponseServiceTier(responseServiceTier ? { "x-gemini-service-tier": responseServiceTier } : void 0, usageMetadata, isVertexMode), vertexRegion, requestedServiceTier, pricingTime);
|
|
1272
|
+
}
|
|
1273
|
+
const clone = Clone();
|
|
1274
|
+
const PartSchema = z$1.object({
|
|
1275
|
+
text: z$1.string().optional(),
|
|
1276
|
+
inline_data: z$1.object({
|
|
1277
|
+
mime_type: z$1.string(),
|
|
1278
|
+
data: z$1.string()
|
|
1279
|
+
}).optional()
|
|
1280
|
+
}).passthrough();
|
|
1281
|
+
const ContentSchema = z$1.object({
|
|
1282
|
+
role: z$1.enum(["user", "model"]).optional(),
|
|
1283
|
+
parts: z$1.array(PartSchema)
|
|
1284
|
+
});
|
|
1285
|
+
const GeminiFormatSchema = z$1.array(ContentSchema);
|
|
1286
|
+
function maybeCoerceToGeminiFormat(contents, options) {
|
|
1287
|
+
let coerced = false;
|
|
1288
|
+
const parseResult = GeminiFormatSchema.safeParse(contents);
|
|
1289
|
+
if (parseResult.success) {
|
|
1290
|
+
let systemInst = void 0;
|
|
1291
|
+
if (typeof contents === "object" && "system_instruction" in contents) {
|
|
1292
|
+
systemInst = contents.system_instruction;
|
|
1293
|
+
coerced = true;
|
|
1294
|
+
}
|
|
1295
|
+
return {
|
|
1296
|
+
contents: parseResult.data,
|
|
1297
|
+
coerced,
|
|
1298
|
+
systemInstruction: systemInst
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
let coercedContents;
|
|
1302
|
+
if (typeof contents === "object" && contents !== null && !Array.isArray(contents) && "system_instruction" in contents) {
|
|
1303
|
+
const systemInst = contents.system_instruction;
|
|
1304
|
+
if ("contents" in contents) coercedContents = contents.contents;
|
|
1305
|
+
else coercedContents = [];
|
|
1306
|
+
return {
|
|
1307
|
+
contents: coercedContents,
|
|
1308
|
+
coerced: true,
|
|
1309
|
+
systemInstruction: systemInst
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
if (typeof contents === "string") {
|
|
1313
|
+
coercedContents = [{ parts: [{ text: contents }] }];
|
|
1314
|
+
coerced = true;
|
|
1315
|
+
} else if (Array.isArray(contents) && contents.every((item) => typeof item.content === "string")) {
|
|
1316
|
+
const targetRole = options?.useAssistantRole ? "assistant" : "model";
|
|
1317
|
+
coercedContents = contents.map((item) => ({
|
|
1318
|
+
role: item.role === "assistant" ? targetRole : item.role,
|
|
1319
|
+
parts: [{ text: item.content }]
|
|
1320
|
+
}));
|
|
1321
|
+
coerced = true;
|
|
1322
|
+
} else if (Array.isArray(contents) && contents.every((item) => item.role && item.content)) {
|
|
1323
|
+
const targetRole = options?.useAssistantRole ? "assistant" : "model";
|
|
1324
|
+
coercedContents = contents.map((item) => {
|
|
1325
|
+
const mappedRole = item.role === "assistant" ? targetRole : item.role;
|
|
1326
|
+
if (Array.isArray(item.content)) return {
|
|
1327
|
+
role: mappedRole,
|
|
1328
|
+
parts: item.content.map((contentItem) => {
|
|
1329
|
+
if (typeof contentItem === "string") return { text: contentItem };
|
|
1330
|
+
else if (contentItem.type === "text") return { text: contentItem.text };
|
|
1331
|
+
else return contentItem;
|
|
1332
|
+
})
|
|
1333
|
+
};
|
|
1334
|
+
else if (typeof item.content === "object") return {
|
|
1335
|
+
role: mappedRole,
|
|
1336
|
+
parts: [item.content]
|
|
1337
|
+
};
|
|
1338
|
+
else return {
|
|
1339
|
+
role: mappedRole,
|
|
1340
|
+
parts: [{ text: item.content }]
|
|
1341
|
+
};
|
|
1342
|
+
});
|
|
1343
|
+
coerced = true;
|
|
1344
|
+
} else if (typeof contents === "object" && contents !== null && "parts" in contents) {
|
|
1345
|
+
coercedContents = [contents];
|
|
1346
|
+
coerced = true;
|
|
1347
|
+
} else {
|
|
1348
|
+
logger.warn(`Unknown format for Gemini: ${JSON.stringify(contents)}`);
|
|
1349
|
+
return {
|
|
1350
|
+
contents: Array.isArray(contents) ? contents : [],
|
|
1351
|
+
coerced: false,
|
|
1352
|
+
systemInstruction: void 0
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
let systemPromptParts = [];
|
|
1356
|
+
coercedContents = coercedContents.filter((message) => {
|
|
1357
|
+
if (message.role === "system" && message.parts.length > 0) {
|
|
1358
|
+
systemPromptParts.push(...message.parts.filter((part) => "text" in part && typeof part.text === "string"));
|
|
1359
|
+
return false;
|
|
1360
|
+
}
|
|
1361
|
+
return true;
|
|
1362
|
+
});
|
|
1363
|
+
if (coercedContents.length === 0 && systemPromptParts.length > 0) {
|
|
1364
|
+
coercedContents = [{
|
|
1365
|
+
role: "user",
|
|
1366
|
+
parts: systemPromptParts
|
|
1367
|
+
}];
|
|
1368
|
+
coerced = true;
|
|
1369
|
+
systemPromptParts = [];
|
|
1370
|
+
}
|
|
1371
|
+
return {
|
|
1372
|
+
contents: coercedContents,
|
|
1373
|
+
coerced,
|
|
1374
|
+
systemInstruction: systemPromptParts.length > 0 ? { parts: systemPromptParts } : void 0
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
let cachedGenerativeLanguageAuth = null;
|
|
1378
|
+
/**
|
|
1379
|
+
* Gets an OAuth2 access token for Google APIs.
|
|
1380
|
+
* Used by providers that need to authenticate via OAuth2 instead of API keys.
|
|
1381
|
+
* @param credentials - Optional credentials JSON string or file:// path
|
|
1382
|
+
* @param scopes - Optional scopes to use. Defaults to cloud-platform + generative-language scopes
|
|
1383
|
+
* @returns The access token string, or undefined if authentication fails
|
|
1384
|
+
*/
|
|
1385
|
+
async function getGoogleAccessToken(credentials) {
|
|
1386
|
+
try {
|
|
1387
|
+
if (!cachedGenerativeLanguageAuth) {
|
|
1388
|
+
let GoogleAuth;
|
|
1389
|
+
try {
|
|
1390
|
+
GoogleAuth = (await import("google-auth-library")).GoogleAuth;
|
|
1391
|
+
cachedGenerativeLanguageAuth = new GoogleAuth({ scopes: [
|
|
1392
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
1393
|
+
"https://www.googleapis.com/auth/generative-language.retriever",
|
|
1394
|
+
"https://www.googleapis.com/auth/generative-language.tuning"
|
|
1395
|
+
] });
|
|
1396
|
+
} catch {
|
|
1397
|
+
throw new Error("The google-auth-library package is required as a peer dependency. Please install it in your project or globally.");
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const processedCredentials = loadCredentials(credentials);
|
|
1401
|
+
let client;
|
|
1402
|
+
if (processedCredentials) client = await cachedGenerativeLanguageAuth.fromJSON(JSON.parse(processedCredentials));
|
|
1403
|
+
else client = await cachedGenerativeLanguageAuth.getClient();
|
|
1404
|
+
return (await client.getAccessToken()).token || void 0;
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
logger.debug("[GoogleAuth] Could not get access token", { error: error instanceof Error ? error.message : String(error) });
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
function getCandidate(data) {
|
|
1411
|
+
if (!data || !data.candidates || data.candidates.length < 1) {
|
|
1412
|
+
let errorDetails = "No candidates returned in API response.";
|
|
1413
|
+
if (data?.promptFeedback?.blockReason) {
|
|
1414
|
+
errorDetails = `Response blocked: ${data.promptFeedback.blockReason}`;
|
|
1415
|
+
if (data.promptFeedback.safetyRatings) {
|
|
1416
|
+
const flaggedCategories = data.promptFeedback.safetyRatings.filter((rating) => rating.probability !== "NEGLIGIBLE").map((rating) => `${rating.category}: ${rating.probability}`);
|
|
1417
|
+
if (flaggedCategories.length > 0) errorDetails += ` (Safety ratings: ${flaggedCategories.join(", ")})`;
|
|
1418
|
+
}
|
|
1419
|
+
} else if (data?.promptFeedback?.safetyRatings) {
|
|
1420
|
+
const flaggedCategories = data.promptFeedback.safetyRatings.filter((rating) => rating.probability !== "NEGLIGIBLE").map((rating) => `${rating.category}: ${rating.probability}`);
|
|
1421
|
+
if (flaggedCategories.length > 0) errorDetails = `Response may have been blocked due to safety filters: ${flaggedCategories.join(", ")}`;
|
|
1422
|
+
}
|
|
1423
|
+
errorDetails += `\n\nGot response: ${JSON.stringify(data)}`;
|
|
1424
|
+
throw new Error(errorDetails);
|
|
1425
|
+
}
|
|
1426
|
+
if (data.candidates.length > 1) logger.debug(`Expected one candidate in AI Studio API response, but got ${data.candidates.length}: ${JSON.stringify(data)}`);
|
|
1427
|
+
const candidate = data.candidates[0];
|
|
1428
|
+
if (!candidate) throw new Error(`No candidates returned in API response.\n\nGot response: ${JSON.stringify(data)}`);
|
|
1429
|
+
return candidate;
|
|
1430
|
+
}
|
|
1431
|
+
function isNonCandidateStreamChunk(datum) {
|
|
1432
|
+
return !datum.candidates?.length && (Boolean(datum.usageMetadata) && !datum.promptFeedback || Boolean(datum.promptFeedback?.safetyRatings) && !datum.promptFeedback?.blockReason);
|
|
1433
|
+
}
|
|
1434
|
+
function getLastPromptSafetyRatings(data) {
|
|
1435
|
+
let safetyRatings;
|
|
1436
|
+
for (const datum of data) if (datum.promptFeedback?.safetyRatings) safetyRatings = datum.promptFeedback.safetyRatings;
|
|
1437
|
+
return safetyRatings;
|
|
1438
|
+
}
|
|
1439
|
+
/** Normalize Google's prompt and candidate ratings for guardrails assertions. */
|
|
1440
|
+
function getGoogleGuardrails(promptSafetyRatings, candidateSafetyRatings) {
|
|
1441
|
+
if (!promptSafetyRatings && !candidateSafetyRatings) return;
|
|
1442
|
+
const flaggedInput = promptSafetyRatings?.some((rating) => rating.probability !== "NEGLIGIBLE");
|
|
1443
|
+
const flaggedOutput = candidateSafetyRatings?.some((rating) => rating.probability !== "NEGLIGIBLE");
|
|
1444
|
+
return {
|
|
1445
|
+
flaggedInput,
|
|
1446
|
+
flaggedOutput,
|
|
1447
|
+
flagged: flaggedInput || flaggedOutput
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
function collectThoughtSignatures(data) {
|
|
1451
|
+
return data.flatMap((datum) => (datum.candidates ?? []).flatMap((candidate) => (candidate.content?.parts ?? []).flatMap((part) => typeof part.thoughtSignature === "string" ? [part.thoughtSignature] : [])));
|
|
1452
|
+
}
|
|
1453
|
+
function collectGroundingMetadata(data) {
|
|
1454
|
+
const candidates = data.filter((d) => d.candidates?.length).map((d) => getCandidate(d));
|
|
1455
|
+
const flatChunks = candidates.flatMap((c) => c.groundingChunks ?? []);
|
|
1456
|
+
const flatSupports = candidates.flatMap((c) => c.groundingSupports ?? []);
|
|
1457
|
+
const flatQueries = candidates.flatMap((c) => c.webSearchQueries ?? []);
|
|
1458
|
+
const metas = candidates.map((c) => c.groundingMetadata).filter((m) => Boolean(m));
|
|
1459
|
+
let groundingMetadata;
|
|
1460
|
+
if (metas.length === 1) groundingMetadata = metas[0];
|
|
1461
|
+
else if (metas.length > 1) {
|
|
1462
|
+
const merged = {};
|
|
1463
|
+
for (const m of metas) for (const [key, value] of Object.entries(m)) {
|
|
1464
|
+
if (key === "groundingChunks" || key === "groundingSupports" || key === "webSearchQueries") continue;
|
|
1465
|
+
if (value !== void 0) merged[key] = value;
|
|
1466
|
+
}
|
|
1467
|
+
const innerChunks = metas.flatMap((m) => m.groundingChunks ?? []);
|
|
1468
|
+
const innerSupports = metas.flatMap((m) => m.groundingSupports ?? []);
|
|
1469
|
+
const innerQueries = metas.flatMap((m) => m.webSearchQueries ?? []);
|
|
1470
|
+
if (innerChunks.length) merged.groundingChunks = innerChunks;
|
|
1471
|
+
if (innerSupports.length) merged.groundingSupports = innerSupports;
|
|
1472
|
+
if (innerQueries.length) merged.webSearchQueries = innerQueries;
|
|
1473
|
+
groundingMetadata = merged;
|
|
1474
|
+
}
|
|
1475
|
+
return {
|
|
1476
|
+
...groundingMetadata && { groundingMetadata },
|
|
1477
|
+
...flatChunks.length > 0 && { groundingChunks: flatChunks },
|
|
1478
|
+
...flatSupports.length > 0 && { groundingSupports: flatSupports },
|
|
1479
|
+
...flatQueries.length > 0 && { webSearchQueries: flatQueries }
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
function formatCandidateContents(candidate) {
|
|
1483
|
+
if (candidate.finishReason && [
|
|
1484
|
+
"SAFETY",
|
|
1485
|
+
"RECITATION",
|
|
1486
|
+
"PROHIBITED_CONTENT",
|
|
1487
|
+
"BLOCKLIST",
|
|
1488
|
+
"SPII"
|
|
1489
|
+
].includes(candidate.finishReason)) {
|
|
1490
|
+
let errorMessage = `Response was blocked with finish reason: ${candidate.finishReason}`;
|
|
1491
|
+
if (candidate.safetyRatings) {
|
|
1492
|
+
const flaggedCategories = candidate.safetyRatings.filter((rating) => rating.probability !== "NEGLIGIBLE" || rating.blocked).map((rating) => `${rating.category}: ${rating.probability}${rating.blocked ? " (BLOCKED)" : ""}`);
|
|
1493
|
+
if (flaggedCategories.length > 0) errorMessage += `\nSafety ratings: ${flaggedCategories.join(", ")}`;
|
|
1494
|
+
}
|
|
1495
|
+
if (candidate.finishReason === "RECITATION") errorMessage += "\n\nThis typically occurs when the response is too similar to content from the model's training data.";
|
|
1496
|
+
else if (candidate.finishReason === "SAFETY") errorMessage += "\n\nThe response was blocked due to safety filters. Consider adjusting safety settings or modifying your prompt.";
|
|
1497
|
+
throw new Error(errorMessage);
|
|
1498
|
+
}
|
|
1499
|
+
if (candidate.content?.parts) {
|
|
1500
|
+
let output = "";
|
|
1501
|
+
let is_text = true;
|
|
1502
|
+
for (const part of candidate.content.parts) if ("text" in part) output += part.text;
|
|
1503
|
+
else is_text = false;
|
|
1504
|
+
if (is_text) return output;
|
|
1505
|
+
else return candidate.content.parts;
|
|
1506
|
+
} else throw new Error(`No output found in response: ${JSON.stringify(candidate)}`);
|
|
1507
|
+
}
|
|
1508
|
+
function mergeParts(parts1, parts2) {
|
|
1509
|
+
if (parts1 === void 0) return typeof parts2 === "string" ? parts2 : [...parts2];
|
|
1510
|
+
if (typeof parts1 === "string" && typeof parts2 === "string") return parts1 + parts2;
|
|
1511
|
+
const array1 = typeof parts1 === "string" ? [{ text: parts1 }] : parts1;
|
|
1512
|
+
const array2 = typeof parts2 === "string" ? [{ text: parts2 }] : parts2;
|
|
1513
|
+
array1.push(...array2);
|
|
1514
|
+
return array1;
|
|
1515
|
+
}
|
|
1516
|
+
function normalizeGeminiAudio(output) {
|
|
1517
|
+
if (!Array.isArray(output)) return;
|
|
1518
|
+
const audioParts = output.filter((part) => part.inlineData?.mimeType?.startsWith("audio/"));
|
|
1519
|
+
if (audioParts.length === 0) return;
|
|
1520
|
+
const mimeType = audioParts[0].inlineData.mimeType;
|
|
1521
|
+
const audioData = Buffer.concat(audioParts.map((part) => Buffer.from(part.inlineData.data, "base64")));
|
|
1522
|
+
if (!/^audio\/(?:L16|pcm)(?:;|$)/i.test(mimeType)) return {
|
|
1523
|
+
data: audioData.toString("base64"),
|
|
1524
|
+
format: mimeType.split(/[;/]/)[1]
|
|
1525
|
+
};
|
|
1526
|
+
const sampleRate = Number(mimeType.match(/(?:^|;)\s*rate=(\d+)/i)?.[1] ?? 24e3);
|
|
1527
|
+
const header = Buffer.alloc(44);
|
|
1528
|
+
header.write("RIFF", 0);
|
|
1529
|
+
header.writeUInt32LE(36 + audioData.length, 4);
|
|
1530
|
+
header.write("WAVE", 8);
|
|
1531
|
+
header.write("fmt ", 12);
|
|
1532
|
+
header.writeUInt32LE(16, 16);
|
|
1533
|
+
header.writeUInt16LE(1, 20);
|
|
1534
|
+
header.writeUInt16LE(1, 22);
|
|
1535
|
+
header.writeUInt32LE(sampleRate, 24);
|
|
1536
|
+
header.writeUInt32LE(sampleRate * 2, 28);
|
|
1537
|
+
header.writeUInt16LE(2, 32);
|
|
1538
|
+
header.writeUInt16LE(16, 34);
|
|
1539
|
+
header.write("data", 36);
|
|
1540
|
+
header.writeUInt32LE(audioData.length, 40);
|
|
1541
|
+
return {
|
|
1542
|
+
data: Buffer.concat([header, audioData]).toString("base64"),
|
|
1543
|
+
format: "wav",
|
|
1544
|
+
sampleRate,
|
|
1545
|
+
channels: 1
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Normalizes and sanitizes tools configuration for Gemini API compatibility.
|
|
1550
|
+
* - Canonicalizes snake_case aliases to camelCase for backwards compatibility
|
|
1551
|
+
* - Sanitizes function declaration schemas to remove unsupported JSON Schema properties
|
|
1552
|
+
* (e.g., additionalProperties, $schema, default) that Gemini doesn't support
|
|
1553
|
+
*/
|
|
1554
|
+
function normalizeTools(tools) {
|
|
1555
|
+
const canonicalNames = new Set(tools.flatMap((tool) => tool.functionDeclarations?.map(({ name }) => name) ?? []));
|
|
1556
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
1557
|
+
return tools.flatMap((tool) => {
|
|
1558
|
+
const { code_execution, google_search, google_search_retrieval, ...canonicalTool } = tool;
|
|
1559
|
+
const normalizedTool = { ...canonicalTool };
|
|
1560
|
+
if (normalizedTool.codeExecution === void 0 && code_execution !== void 0) normalizedTool.codeExecution = code_execution;
|
|
1561
|
+
if (normalizedTool.googleSearch === void 0 && google_search !== void 0) normalizedTool.googleSearch = google_search;
|
|
1562
|
+
if (normalizedTool.googleSearchRetrieval === void 0 && google_search_retrieval !== void 0) normalizedTool.googleSearchRetrieval = google_search_retrieval;
|
|
1563
|
+
if (tool.functionDeclarations || tool.function_declarations) {
|
|
1564
|
+
normalizedTool.functionDeclarations = [...tool.functionDeclarations ?? [], ...(tool.function_declarations ?? []).filter(({ name }) => !canonicalNames.has(name))].filter(({ name }) => {
|
|
1565
|
+
if (seenNames.has(name)) return false;
|
|
1566
|
+
seenNames.add(name);
|
|
1567
|
+
return true;
|
|
1568
|
+
});
|
|
1569
|
+
delete normalizedTool.function_declarations;
|
|
1570
|
+
if (normalizedTool.functionDeclarations.length === 0 && (tool.functionDeclarations?.length || tool.function_declarations?.length)) {
|
|
1571
|
+
delete normalizedTool.functionDeclarations;
|
|
1572
|
+
if (Object.keys(normalizedTool).length === 0) return [];
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
if (normalizedTool.functionDeclarations) normalizedTool.functionDeclarations = normalizedTool.functionDeclarations.map((fd) => ({
|
|
1576
|
+
...fd,
|
|
1577
|
+
parameters: fd.parameters ? sanitizeSchemaForGemini(fd.parameters) : void 0
|
|
1578
|
+
}));
|
|
1579
|
+
return [normalizedTool];
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
function loadFile(config_var, context_vars) {
|
|
1583
|
+
const fileContents = maybeLoadFromExternalFile(renderVarsInObject(config_var, context_vars));
|
|
1584
|
+
if (typeof fileContents === "string") try {
|
|
1585
|
+
const parsedContents = JSON.parse(fileContents);
|
|
1586
|
+
return Array.isArray(parsedContents) ? normalizeTools(parsedContents) : parsedContents;
|
|
1587
|
+
} catch (err) {
|
|
1588
|
+
logger.debug(`ERROR: failed to convert file contents to JSON:\n${JSON.stringify(err)}`);
|
|
1589
|
+
return fileContents;
|
|
1590
|
+
}
|
|
1591
|
+
if (Array.isArray(fileContents)) return normalizeTools(fileContents);
|
|
1592
|
+
return fileContents;
|
|
1593
|
+
}
|
|
1594
|
+
function getMimeTypeFromFtypBrand(brand) {
|
|
1595
|
+
if ([
|
|
1596
|
+
"avif",
|
|
1597
|
+
"avis",
|
|
1598
|
+
"crx "
|
|
1599
|
+
].includes(brand)) return;
|
|
1600
|
+
if ([
|
|
1601
|
+
"M4A ",
|
|
1602
|
+
"M4B ",
|
|
1603
|
+
"M4P ",
|
|
1604
|
+
"F4A ",
|
|
1605
|
+
"F4B "
|
|
1606
|
+
].includes(brand)) return "audio/mp4";
|
|
1607
|
+
else if ([
|
|
1608
|
+
"heic",
|
|
1609
|
+
"heix",
|
|
1610
|
+
"hevc",
|
|
1611
|
+
"hevx"
|
|
1612
|
+
].includes(brand)) return "image/heic";
|
|
1613
|
+
else if (["mif1", "msf1"].includes(brand)) return "image/heif";
|
|
1614
|
+
else if (brand === "qt ") return "video/quicktime";
|
|
1615
|
+
else if (brand.startsWith("3g")) return "video/3gpp";
|
|
1616
|
+
return "video/mp4";
|
|
1617
|
+
}
|
|
1618
|
+
const ASF_HEADER_GUID = Buffer.from("3026b2758e66cf11a6d900aa0062ce6c", "hex");
|
|
1619
|
+
const ASF_STREAM_PROPERTIES_GUID = Buffer.from("9107dcb7b7a9cf118ee600c00c205365", "hex");
|
|
1620
|
+
const ASF_AUDIO_STREAM_GUID = Buffer.from("409e69f84d5bcf11a8fd00805f5c442b", "hex");
|
|
1621
|
+
const ASF_VIDEO_STREAM_GUID = Buffer.from("c0ef19bc4d5bcf11a8fd00805f5c442b", "hex");
|
|
1622
|
+
const EBML_DOCTYPE_ID = Buffer.from([66, 130]);
|
|
1623
|
+
const MAX_MEDIA_SNIFF_BYTES = 65536;
|
|
1624
|
+
const SUPPORTED_INLINE_MEDIA_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
1625
|
+
"application/pdf",
|
|
1626
|
+
"image/jpeg",
|
|
1627
|
+
"image/png",
|
|
1628
|
+
"image/webp",
|
|
1629
|
+
"image/heic",
|
|
1630
|
+
"image/heif",
|
|
1631
|
+
"audio/wav",
|
|
1632
|
+
"audio/mpeg",
|
|
1633
|
+
"audio/aiff",
|
|
1634
|
+
"audio/aac",
|
|
1635
|
+
"audio/ogg",
|
|
1636
|
+
"audio/flac",
|
|
1637
|
+
"audio/mp4",
|
|
1638
|
+
"video/mp4",
|
|
1639
|
+
"video/mpeg",
|
|
1640
|
+
"video/quicktime",
|
|
1641
|
+
"video/avi",
|
|
1642
|
+
"video/x-flv",
|
|
1643
|
+
"video/webm",
|
|
1644
|
+
"video/wmv",
|
|
1645
|
+
"video/3gpp"
|
|
1646
|
+
]);
|
|
1647
|
+
function getAsfMimeType(bytes) {
|
|
1648
|
+
let streamOffset = bytes.indexOf(ASF_STREAM_PROPERTIES_GUID, ASF_HEADER_GUID.length);
|
|
1649
|
+
let hasAudio = false;
|
|
1650
|
+
while (streamOffset !== -1) {
|
|
1651
|
+
const streamTypeOffset = streamOffset + ASF_STREAM_PROPERTIES_GUID.length + 8;
|
|
1652
|
+
const streamType = bytes.subarray(streamTypeOffset, streamTypeOffset + 16);
|
|
1653
|
+
if (streamType.equals(ASF_VIDEO_STREAM_GUID)) return "video/wmv";
|
|
1654
|
+
if (streamType.equals(ASF_AUDIO_STREAM_GUID)) hasAudio = true;
|
|
1655
|
+
streamOffset = bytes.indexOf(ASF_STREAM_PROPERTIES_GUID, streamTypeOffset);
|
|
1656
|
+
}
|
|
1657
|
+
return hasAudio ? "audio/x-ms-wma" : void 0;
|
|
1658
|
+
}
|
|
1659
|
+
function getEbmlMimeType(bytes) {
|
|
1660
|
+
const doctypeOffset = bytes.indexOf(EBML_DOCTYPE_ID, 4);
|
|
1661
|
+
if (doctypeOffset < 0) return;
|
|
1662
|
+
const sizeOffset = doctypeOffset + EBML_DOCTYPE_ID.length;
|
|
1663
|
+
const encodedLength = bytes[sizeOffset];
|
|
1664
|
+
if (encodedLength === void 0 || encodedLength === 0) return;
|
|
1665
|
+
let width = 1;
|
|
1666
|
+
let marker = 128;
|
|
1667
|
+
while ((encodedLength & marker) === 0) {
|
|
1668
|
+
marker >>= 1;
|
|
1669
|
+
width++;
|
|
1670
|
+
}
|
|
1671
|
+
if (sizeOffset + width > bytes.length) return;
|
|
1672
|
+
let doctypeLength = encodedLength & marker - 1;
|
|
1673
|
+
for (let index = 1; index < width; index++) {
|
|
1674
|
+
doctypeLength = doctypeLength * 256 + bytes[sizeOffset + index];
|
|
1675
|
+
if (doctypeLength > 4) return;
|
|
1676
|
+
}
|
|
1677
|
+
const doctypeOffsetStart = sizeOffset + width;
|
|
1678
|
+
if (doctypeLength !== 4 || doctypeOffsetStart + doctypeLength > bytes.length) return;
|
|
1679
|
+
return bytes.subarray(doctypeOffsetStart, doctypeOffsetStart + doctypeLength).equals(Buffer.from("webm")) ? "video/webm" : void 0;
|
|
1680
|
+
}
|
|
1681
|
+
function getOggMimeType(bytes) {
|
|
1682
|
+
let offset = 0;
|
|
1683
|
+
let hasAudio = false;
|
|
1684
|
+
while (offset + 27 <= bytes.length) {
|
|
1685
|
+
if (bytes.toString("utf8", offset, offset + 4) !== "OggS" || bytes[offset + 4] !== 0) return;
|
|
1686
|
+
const flags = bytes[offset + 5];
|
|
1687
|
+
if ((flags & 2) === 0) return hasAudio ? "audio/ogg" : void 0;
|
|
1688
|
+
const segmentCount = bytes[offset + 26];
|
|
1689
|
+
const payloadOffset = offset + 27 + segmentCount;
|
|
1690
|
+
if ((flags & 1) !== 0 || segmentCount === 0 || payloadOffset > bytes.length) return;
|
|
1691
|
+
const segments = bytes.subarray(offset + 27, payloadOffset);
|
|
1692
|
+
const packetEnd = segments.findIndex((length) => length < 255);
|
|
1693
|
+
if (packetEnd < 0) return;
|
|
1694
|
+
const packetLength = segments.subarray(0, packetEnd + 1).reduce((sum, length) => sum + length, 0);
|
|
1695
|
+
const pageEnd = payloadOffset + segments.reduce((sum, length) => sum + length, 0);
|
|
1696
|
+
if (pageEnd > bytes.length) return;
|
|
1697
|
+
const packet = bytes.subarray(payloadOffset, payloadOffset + packetLength);
|
|
1698
|
+
if (packet.length >= 64 && packet.subarray(0, 8).equals(Buffer.from("fishead\0"))) {
|
|
1699
|
+
offset = pageEnd;
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
if (packet.subarray(0, 7).equals(Buffer.from("theora", "latin1"))) return "video/ogg";
|
|
1703
|
+
if (![
|
|
1704
|
+
"OpusHead",
|
|
1705
|
+
"vorbis",
|
|
1706
|
+
"Speex ",
|
|
1707
|
+
"FLAC"
|
|
1708
|
+
].some((header) => packet.subarray(0, header.length).equals(Buffer.from(header)))) return;
|
|
1709
|
+
hasAudio = true;
|
|
1710
|
+
offset = pageEnd;
|
|
1711
|
+
}
|
|
1712
|
+
return offset === bytes.length && hasAudio ? "audio/ogg" : void 0;
|
|
1713
|
+
}
|
|
1714
|
+
function getMimeTypeFromMediaBytes(bytes) {
|
|
1715
|
+
const riffType = bytes.subarray(8, 12).toString("ascii");
|
|
1716
|
+
if (bytes.subarray(0, 4).toString("ascii") === "RIFF") {
|
|
1717
|
+
if (riffType === "WEBP") return "image/webp";
|
|
1718
|
+
else if (riffType === "WAVE") return "audio/wav";
|
|
1719
|
+
else if (riffType === "AVI ") return "video/avi";
|
|
1720
|
+
} else if (bytes.subarray(0, 4).toString("ascii") === "FORM" && ["AIFF", "AIFC"].includes(riffType)) return "audio/aiff";
|
|
1721
|
+
else if (bytes.subarray(4, 8).toString("ascii") === "ftyp") return getMimeTypeFromFtypBrand(bytes.subarray(8, 12).toString("ascii"));
|
|
1722
|
+
else if ([
|
|
1723
|
+
"moov",
|
|
1724
|
+
"mdat",
|
|
1725
|
+
"wide"
|
|
1726
|
+
].includes(bytes.subarray(4, 8).toString("ascii"))) return "video/quicktime";
|
|
1727
|
+
else if (bytes.subarray(0, 4).toString("hex") === "1a45dfa3") return getEbmlMimeType(bytes);
|
|
1728
|
+
else if (["000001ba", "000001b3"].includes(bytes.subarray(0, 4).toString("hex"))) return "video/mpeg";
|
|
1729
|
+
else if (bytes.subarray(0, 3).toString("ascii") === "FLV") return "video/x-flv";
|
|
1730
|
+
else if (bytes.subarray(0, ASF_HEADER_GUID.length).equals(ASF_HEADER_GUID)) return getAsfMimeType(bytes);
|
|
1731
|
+
else if (bytes[0] === 255 && (bytes[1] & 246) === 240) return "audio/aac";
|
|
1732
|
+
else if (bytes.subarray(0, 3).toString("ascii") === "ID3" || bytes[0] === 255 && (bytes[1] & 224) === 224) return "audio/mpeg";
|
|
1733
|
+
else if (bytes.subarray(0, 4).toString("ascii") === "fLaC") return "audio/flac";
|
|
1734
|
+
else if (bytes.subarray(0, 4).toString("ascii") === "OggS") return getOggMimeType(bytes);
|
|
1735
|
+
}
|
|
1736
|
+
function getMimeTypeFromBase64(data) {
|
|
1737
|
+
const parsed = parseDataUrl(data);
|
|
1738
|
+
const base64Data = parsed ? parsed.base64Data : data;
|
|
1739
|
+
if (!base64Data || base64Data.length < 20 || !/^[A-Za-z0-9+/]+={0,2}$/.test(base64Data)) return;
|
|
1740
|
+
if (parsed) {
|
|
1741
|
+
const normalizedMimeType = parsed.mimeType.toLowerCase();
|
|
1742
|
+
const mimeType = {
|
|
1743
|
+
"audio/mp3": "audio/mpeg",
|
|
1744
|
+
"audio/m4a": "audio/mp4",
|
|
1745
|
+
"video/mpg": "video/mpeg",
|
|
1746
|
+
"video/mov": "video/quicktime"
|
|
1747
|
+
}[normalizedMimeType] ?? normalizedMimeType;
|
|
1748
|
+
return SUPPORTED_INLINE_MEDIA_MIME_TYPES.has(mimeType) ? mimeType : void 0;
|
|
1749
|
+
}
|
|
1750
|
+
if (base64Data.startsWith("/9j/")) return "image/jpeg";
|
|
1751
|
+
else if (base64Data.startsWith("iVBORw0KGgo")) return "image/png";
|
|
1752
|
+
else if (base64Data.startsWith("JVBER")) return "application/pdf";
|
|
1753
|
+
const sniffBase64Length = Math.ceil(MAX_MEDIA_SNIFF_BYTES / 3) * 4;
|
|
1754
|
+
const inferredMimeType = getMimeTypeFromMediaBytes(Buffer.from(base64Data.slice(0, sniffBase64Length), "base64"));
|
|
1755
|
+
return inferredMimeType && SUPPORTED_INLINE_MEDIA_MIME_TYPES.has(inferredMimeType) ? inferredMimeType : void 0;
|
|
1756
|
+
}
|
|
1757
|
+
function processImagesInContents(contents, contextVars) {
|
|
1758
|
+
if (!contextVars) return contents;
|
|
1759
|
+
if (!Array.isArray(contents)) {
|
|
1760
|
+
logger.warn("[Google] contents is not an array in processImagesInContents", {
|
|
1761
|
+
contentsType: typeof contents,
|
|
1762
|
+
contentsValue: contents
|
|
1763
|
+
});
|
|
1764
|
+
return [];
|
|
1765
|
+
}
|
|
1766
|
+
const base64ToMimeType = /* @__PURE__ */ new Map();
|
|
1767
|
+
for (const value of Object.values(contextVars)) if (typeof value === "string") {
|
|
1768
|
+
let mimeType = getMimeTypeFromBase64(value);
|
|
1769
|
+
if (mimeType === "video/mp4" && !isDataUrl(value) && getLoadedFileMimeType(contextVars, value) === "audio/mp4") mimeType = "audio/mp4";
|
|
1770
|
+
if (mimeType && (mimeType !== "video/mp4" || base64ToMimeType.get(value) !== "audio/mp4")) base64ToMimeType.set(value, mimeType);
|
|
1771
|
+
}
|
|
1772
|
+
return contents.map((content) => {
|
|
1773
|
+
if (content.parts) {
|
|
1774
|
+
const newParts = [];
|
|
1775
|
+
for (const part of content.parts) if (part.text) {
|
|
1776
|
+
const lines = part.text.split("\n");
|
|
1777
|
+
let foundValidMedia = false;
|
|
1778
|
+
let currentTextBlock = "";
|
|
1779
|
+
const processedParts = [];
|
|
1780
|
+
for (const line of lines) {
|
|
1781
|
+
const trimmedLine = line.trim();
|
|
1782
|
+
const mimeType = base64ToMimeType.get(trimmedLine);
|
|
1783
|
+
if (mimeType) {
|
|
1784
|
+
foundValidMedia = true;
|
|
1785
|
+
if (currentTextBlock.length > 0) {
|
|
1786
|
+
processedParts.push({ text: currentTextBlock });
|
|
1787
|
+
currentTextBlock = "";
|
|
1788
|
+
}
|
|
1789
|
+
const base64Data = isDataUrl(trimmedLine) ? extractBase64FromDataUrl(trimmedLine) : trimmedLine;
|
|
1790
|
+
processedParts.push({ inlineData: {
|
|
1791
|
+
mimeType,
|
|
1792
|
+
data: base64Data
|
|
1793
|
+
} });
|
|
1794
|
+
} else {
|
|
1795
|
+
if (currentTextBlock.length > 0) currentTextBlock += "\n";
|
|
1796
|
+
currentTextBlock += line;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
if (currentTextBlock.length > 0) processedParts.push({ text: currentTextBlock });
|
|
1800
|
+
if (foundValidMedia) newParts.push(...processedParts);
|
|
1801
|
+
else newParts.push(part);
|
|
1802
|
+
} else newParts.push(part);
|
|
1803
|
+
return {
|
|
1804
|
+
...content,
|
|
1805
|
+
parts: newParts
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
return content;
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Parses and processes config-level systemInstruction.
|
|
1813
|
+
* Handles file loading, string-to-Content conversion, and Nunjucks template rendering.
|
|
1814
|
+
*
|
|
1815
|
+
* @param configSystemInstruction - The systemInstruction from config (can be string, Content, or undefined)
|
|
1816
|
+
* @param contextVars - Variables for Nunjucks template rendering
|
|
1817
|
+
* @param basePath - Optional base directory for resolving relative instruction file references
|
|
1818
|
+
* @returns Processed Content object or undefined
|
|
1819
|
+
*/
|
|
1820
|
+
function parseConfigSystemInstruction(configSystemInstruction, contextVars, basePath) {
|
|
1821
|
+
if (!configSystemInstruction) return;
|
|
1822
|
+
let configInstruction = clone(configSystemInstruction);
|
|
1823
|
+
let renderInstructionParts = true;
|
|
1824
|
+
if (typeof configSystemInstruction === "string") {
|
|
1825
|
+
const instructionReference = resolveGoogleConfigFileReference(renderVarsInObject(configSystemInstruction, contextVars), basePath);
|
|
1826
|
+
configInstruction = loadFile(instructionReference, void 0);
|
|
1827
|
+
renderInstructionParts = instructionReference.startsWith("file://");
|
|
1828
|
+
}
|
|
1829
|
+
if (typeof configInstruction === "string") configInstruction = { parts: [{ text: configInstruction }] };
|
|
1830
|
+
if (renderInstructionParts && contextVars && configInstruction) {
|
|
1831
|
+
const nunjucks = getNunjucksEngine();
|
|
1832
|
+
for (const part of configInstruction.parts) if (part.text) try {
|
|
1833
|
+
part.text = nunjucks.renderString(part.text, contextVars);
|
|
1834
|
+
} catch (err) {
|
|
1835
|
+
throw new Error(`Unable to render nunjucks in systemInstruction: ${err}`);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
return configInstruction;
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Loads, parses, and renders a config-level response schema.
|
|
1842
|
+
*
|
|
1843
|
+
* @param configResponseSchema - Inline JSON or a reference to an external schema file
|
|
1844
|
+
* @param contextVars - Variables for template rendering
|
|
1845
|
+
* @param basePath - Optional base directory for resolving relative schema file references
|
|
1846
|
+
* @returns The parsed and rendered response schema
|
|
1847
|
+
*/
|
|
1848
|
+
function parseConfigResponseSchema(configResponseSchema, contextVars, basePath) {
|
|
1849
|
+
const renderedSchema = renderVarsInObject(configResponseSchema, contextVars);
|
|
1850
|
+
const schemaReference = typeof renderedSchema === "string" ? resolveGoogleConfigFileReference(renderedSchema, basePath) : renderedSchema;
|
|
1851
|
+
let responseSchema = maybeLoadFromExternalFile(schemaReference);
|
|
1852
|
+
if (typeof responseSchema === "string") try {
|
|
1853
|
+
responseSchema = JSON.parse(responseSchema);
|
|
1854
|
+
} catch (error) {
|
|
1855
|
+
throw new Error(`Invalid JSON in responseSchema: ${error}`);
|
|
1856
|
+
}
|
|
1857
|
+
return typeof schemaReference === "string" && schemaReference.startsWith("file://") ? renderVarsInObject(responseSchema, contextVars) : responseSchema;
|
|
1858
|
+
}
|
|
1859
|
+
/** Resolve only relative Google config file references against their owning base path. */
|
|
1860
|
+
function resolveGoogleConfigFileReference(reference, basePath) {
|
|
1861
|
+
if (!basePath || !reference.startsWith("file://")) return reference;
|
|
1862
|
+
const { filePath } = parseFileUrl(reference);
|
|
1863
|
+
return `file://${path.isAbsolute(filePath) || path.win32.isAbsolute(filePath) ? filePath : path.resolve(basePath, filePath)}`;
|
|
1864
|
+
}
|
|
1865
|
+
function geminiFormatAndSystemInstructions(prompt, contextVars, configSystemInstruction, options) {
|
|
1866
|
+
let contents = parseChatPrompt(prompt, [{
|
|
1867
|
+
parts: [{ text: prompt }],
|
|
1868
|
+
role: "user"
|
|
1869
|
+
}]);
|
|
1870
|
+
const { contents: updatedContents, coerced, systemInstruction: parsedSystemInstruction } = maybeCoerceToGeminiFormat(contents, options);
|
|
1871
|
+
if (coerced) {
|
|
1872
|
+
logger.debug(`Coerced JSON prompt to Gemini format: ${JSON.stringify(contents)}`);
|
|
1873
|
+
contents = updatedContents;
|
|
1874
|
+
}
|
|
1875
|
+
let systemInstruction = parsedSystemInstruction;
|
|
1876
|
+
const parsedConfigInstruction = parseConfigSystemInstruction(configSystemInstruction, contextVars, options?.basePath);
|
|
1877
|
+
if (parsedConfigInstruction) systemInstruction = systemInstruction ? { parts: [...parsedConfigInstruction.parts, ...systemInstruction.parts] } : parsedConfigInstruction;
|
|
1878
|
+
contents = processImagesInContents(contents, contextVars);
|
|
1879
|
+
return {
|
|
1880
|
+
contents,
|
|
1881
|
+
systemInstruction
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Recursively traverses a JSON schema object and converts
|
|
1886
|
+
* uppercase type keywords (string values) to lowercase.
|
|
1887
|
+
* Handles nested objects and arrays within the schema.
|
|
1888
|
+
* Creates a deep copy to avoid modifying the original schema.
|
|
1889
|
+
*
|
|
1890
|
+
* @param {object | any} schemaNode - The current node (object or value) being processed.
|
|
1891
|
+
* @returns {object | any} - The processed node with type keywords lowercased.
|
|
1892
|
+
*/
|
|
1893
|
+
function normalizeSchemaTypes(schemaNode) {
|
|
1894
|
+
if (typeof schemaNode !== "object" || schemaNode === null) return schemaNode;
|
|
1895
|
+
if (Array.isArray(schemaNode)) return schemaNode.map(normalizeSchemaTypes);
|
|
1896
|
+
const newNode = {};
|
|
1897
|
+
for (const key in schemaNode) if (Object.prototype.hasOwnProperty.call(schemaNode, key)) {
|
|
1898
|
+
const value = schemaNode[key];
|
|
1899
|
+
if (key === "type") {
|
|
1900
|
+
if (typeof value === "string" && VALID_SCHEMA_TYPES.includes(value)) newNode[key] = value.toLowerCase();
|
|
1901
|
+
else if (Array.isArray(value)) newNode[key] = value.map((t) => typeof t === "string" && VALID_SCHEMA_TYPES.includes(t) ? t.toLowerCase() : t);
|
|
1902
|
+
else newNode[key] = normalizeSchemaTypes(value);
|
|
1903
|
+
} else newNode[key] = normalizeSchemaTypes(value);
|
|
1904
|
+
}
|
|
1905
|
+
return newNode;
|
|
1906
|
+
}
|
|
1907
|
+
function parseStringObject(input) {
|
|
1908
|
+
if (typeof input === "string") return JSON.parse(input);
|
|
1909
|
+
return input;
|
|
1910
|
+
}
|
|
1911
|
+
function validateFunctionCall(output, functions, vars) {
|
|
1912
|
+
let functionCalls;
|
|
1913
|
+
try {
|
|
1914
|
+
let parsedOutput = parseStringObject(output);
|
|
1915
|
+
if ("toolCall" in parsedOutput) {
|
|
1916
|
+
parsedOutput = parsedOutput.toolCall;
|
|
1917
|
+
functionCalls = parsedOutput.functionCalls;
|
|
1918
|
+
} else if (Array.isArray(parsedOutput)) functionCalls = parsedOutput.filter((obj) => Object.prototype.hasOwnProperty.call(obj, "functionCall")).map((obj) => obj.functionCall);
|
|
1919
|
+
else throw new Error("Unrecognized function call format");
|
|
1920
|
+
if (!Array.isArray(functionCalls) || functionCalls.length === 0 || functionCalls.some((call) => !call || typeof call.name !== "string")) throw new Error("Expected at least one function call");
|
|
1921
|
+
} catch {
|
|
1922
|
+
throw new InvalidToolCallError(`Google did not return a valid-looking function call: ${JSON.stringify(output)}`);
|
|
1923
|
+
}
|
|
1924
|
+
let interpolatedFunctions;
|
|
1925
|
+
try {
|
|
1926
|
+
interpolatedFunctions = loadFile(functions, vars);
|
|
1927
|
+
} catch (err) {
|
|
1928
|
+
throw new InvalidToolSchemaError(err.message);
|
|
1929
|
+
}
|
|
1930
|
+
if (interpolatedFunctions !== void 0 && !Array.isArray(interpolatedFunctions)) throw new InvalidToolSchemaError("Expected the loaded functions to be an array");
|
|
1931
|
+
if (interpolatedFunctions?.some((tool) => !tool || typeof tool !== "object" || tool.functionDeclarations !== void 0 && (!Array.isArray(tool.functionDeclarations) || tool.functionDeclarations.some((declaration) => !declaration || typeof declaration.name !== "string" || !declaration.name.trim())))) throw new InvalidToolSchemaError("Expected valid function declarations in each tool");
|
|
1932
|
+
const declarations = interpolatedFunctions?.flatMap((tool) => tool.functionDeclarations ?? []);
|
|
1933
|
+
if (!declarations?.length) throw new InvalidToolSchemaError(`Called "${functionCalls[0].name}", but there is no function with that name`);
|
|
1934
|
+
const ajv = getAjv();
|
|
1935
|
+
for (const functionCall of functionCalls) {
|
|
1936
|
+
const functionName = functionCall.name;
|
|
1937
|
+
let functionArgs;
|
|
1938
|
+
try {
|
|
1939
|
+
functionArgs = functionCall.args === void 0 ? {} : parseStringObject(functionCall.args);
|
|
1940
|
+
} catch (err) {
|
|
1941
|
+
throw new InvalidToolCallError(err.message);
|
|
1942
|
+
}
|
|
1943
|
+
const functionSchema = declarations.find((declaration) => declaration.name === functionName);
|
|
1944
|
+
if (!functionSchema) throw new InvalidToolCallError(`Called "${functionName}", but there is no function with that name`);
|
|
1945
|
+
if (functionSchema.parameters) {
|
|
1946
|
+
const parameterSchema = normalizeSchemaTypes(functionSchema.parameters);
|
|
1947
|
+
let validate;
|
|
1948
|
+
try {
|
|
1949
|
+
validate = ajv.compile(parameterSchema);
|
|
1950
|
+
} catch (err) {
|
|
1951
|
+
throw new InvalidToolSchemaError(`Tool schema doesn't compile with ajv: ${err}. If this is a valid tool schema you may need to reformulate your assertion without is-valid-function-call.`);
|
|
1952
|
+
}
|
|
1953
|
+
if (!validate(functionArgs)) throw new InvalidToolCallError(`Call to "${functionName}":\n${JSON.stringify(functionCall)}\ndoes not match schema:\n${JSON.stringify(validate.errors)}`);
|
|
1954
|
+
} else if (!(JSON.stringify(functionArgs) === "{}" && !functionSchema?.parameters)) throw new InvalidToolCallError(`Call to "${functionName}":\n${JSON.stringify(functionCall)}\ndoes not match schema:\n${JSON.stringify(functionSchema)}`);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Properties supported by Gemini's function calling API.
|
|
1959
|
+
* Based on Google's Schema type definition and API documentation.
|
|
1960
|
+
* @see https://ai.google.dev/api/caching#Schema
|
|
1961
|
+
*/
|
|
1962
|
+
const GEMINI_SUPPORTED_SCHEMA_PROPERTIES = /* @__PURE__ */ new Set([
|
|
1963
|
+
"type",
|
|
1964
|
+
"format",
|
|
1965
|
+
"description",
|
|
1966
|
+
"nullable",
|
|
1967
|
+
"enum",
|
|
1968
|
+
"maxItems",
|
|
1969
|
+
"minItems",
|
|
1970
|
+
"properties",
|
|
1971
|
+
"required",
|
|
1972
|
+
"propertyOrdering",
|
|
1973
|
+
"items"
|
|
1974
|
+
]);
|
|
1975
|
+
/**
|
|
1976
|
+
* Valid JSON Schema types mapped to Gemini's expected format (uppercase).
|
|
1977
|
+
*/
|
|
1978
|
+
const JSON_SCHEMA_TYPE_MAP = {
|
|
1979
|
+
string: "STRING",
|
|
1980
|
+
number: "NUMBER",
|
|
1981
|
+
integer: "INTEGER",
|
|
1982
|
+
boolean: "BOOLEAN",
|
|
1983
|
+
array: "ARRAY",
|
|
1984
|
+
object: "OBJECT",
|
|
1985
|
+
null: "STRING"
|
|
1986
|
+
};
|
|
1987
|
+
/**
|
|
1988
|
+
* Recursively sanitizes a JSON Schema for Gemini API compatibility.
|
|
1989
|
+
*
|
|
1990
|
+
* - Removes unsupported properties (additionalProperties, $schema, default, title, etc.)
|
|
1991
|
+
* - Converts type values to uppercase (string → STRING, object → OBJECT)
|
|
1992
|
+
* - Recursively processes nested schemas in 'properties' and 'items'
|
|
1993
|
+
*
|
|
1994
|
+
* @param schema - The JSON Schema object to sanitize
|
|
1995
|
+
* @returns A sanitized schema compatible with Gemini's function calling API
|
|
1996
|
+
*/
|
|
1997
|
+
function sanitizeSchemaForGemini(schema) {
|
|
1998
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
1999
|
+
const result = {};
|
|
2000
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
2001
|
+
if (!GEMINI_SUPPORTED_SCHEMA_PROPERTIES.has(key)) continue;
|
|
2002
|
+
if (key === "type") {
|
|
2003
|
+
if (typeof value === "string") {
|
|
2004
|
+
const lowerType = value.toLowerCase();
|
|
2005
|
+
result[key] = JSON_SCHEMA_TYPE_MAP[lowerType] || value.toUpperCase();
|
|
2006
|
+
} else result[key] = value;
|
|
2007
|
+
} else if (key === "properties" && typeof value === "object" && value !== null) {
|
|
2008
|
+
result[key] = {};
|
|
2009
|
+
for (const [propName, propSchema] of Object.entries(value)) if (typeof propSchema === "object" && propSchema !== null) result[key][propName] = sanitizeSchemaForGemini(propSchema);
|
|
2010
|
+
else result[key][propName] = propSchema;
|
|
2011
|
+
} else if (key === "items" && typeof value === "object" && value !== null) result[key] = sanitizeSchemaForGemini(value);
|
|
2012
|
+
else result[key] = value;
|
|
2013
|
+
}
|
|
2014
|
+
return result;
|
|
2015
|
+
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Create a cache discriminator from auth headers.
|
|
2018
|
+
*
|
|
2019
|
+
* This is used to ensure different API keys/credentials don't share cached responses.
|
|
2020
|
+
* The discriminator is included as a custom property in fetchWithCache options,
|
|
2021
|
+
* which gets included in the cache key automatically.
|
|
2022
|
+
*
|
|
2023
|
+
* Security note: We hash auth headers rather than using them directly to avoid
|
|
2024
|
+
* exposing sensitive credentials in cache keys or logs. The hash is truncated
|
|
2025
|
+
* to 16 hex characters (64 bits) for brevity - collision probability is acceptably
|
|
2026
|
+
* low for cache key differentiation (birthday problem: ~4 billion entries needed
|
|
2027
|
+
* for 50% collision probability).
|
|
2028
|
+
*
|
|
2029
|
+
* @param headers - Request headers containing auth info
|
|
2030
|
+
* @returns A short hash string for cache key differentiation
|
|
2031
|
+
*/
|
|
2032
|
+
function createAuthCacheDiscriminator(headers) {
|
|
2033
|
+
const authValues = [];
|
|
2034
|
+
for (const name of [
|
|
2035
|
+
"authorization",
|
|
2036
|
+
"x-goog-api-key",
|
|
2037
|
+
"x-api-key",
|
|
2038
|
+
"api-key",
|
|
2039
|
+
"x-goog-user-project"
|
|
2040
|
+
]) {
|
|
2041
|
+
const value = headers[name] || headers[name.toLowerCase()];
|
|
2042
|
+
if (value) authValues.push(`${name}:${value}`);
|
|
2043
|
+
}
|
|
2044
|
+
if (authValues.length === 0) return "";
|
|
2045
|
+
return crypto.createHash("sha256").update(authValues.join("|")).digest("hex").substring(0, 16);
|
|
2046
|
+
}
|
|
2047
|
+
//#endregion
|
|
2048
|
+
export { stripExecutableToolFileReferences as A, hasGoogleDefaultCredentials as B, normalizeTools as C, removeGoogleFunctionDeclarations as D, removeDeprecatedGeminiGenerationParams as E, getVertexModelDefaultRegion as F, resolveProjectId as H, GoogleAuthManager as I, determineGoogleVertexMode as L, CHAT_MODELS as M, GOOGLE_MODELS as N, resolveGoogleToolConfig as O, getVertexApiHostForRegion as P, getGoogleApiKey as R, normalizeSafetySettings as S, parseConfigSystemInstruction as T, loadCredentials as V, mergeGoogleCompletionOptions as _, createAuthCacheDiscriminator as a, normalizeGeminiAudio as b, getCandidate as c, getGoogleGuardrails as d, getGoogleResponseServiceTier as f, loadGoogleTools as g, isNonCandidateStreamChunk as h, collectThoughtSignatures as i, validateFunctionCall as j, sanitizeSchemaForGemini as k, getGoogleAccessToken as l, getVertexServiceTierHeaders as m, calculateGoogleCostFromUsage as n, formatCandidateContents as o, getLastPromptSafetyRatings as p, collectGroundingMetadata as r, geminiFormatAndSystemInstructions as s, calculateGoogleCost as t, getGoogleApiBaseUrl as u, mergeGoogleRequestTools as v, parseConfigResponseSchema as w, normalizeGoogleServiceTier as x, mergeParts as y, getGoogleClient as z };
|
|
2049
|
+
|
|
2050
|
+
//# sourceMappingURL=util-qzBqirBH.js.map
|