@truefoundry/ai-gateway-sdk 0.0.0-stage → 0.0.2
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 +192 -2
- package/dist/adapters/bedrock-converse/index.d.ts +9 -0
- package/dist/adapters/bedrock-converse/index.js +121 -0
- package/dist/adapters/bedrock-converse/index.js.map +1 -0
- package/dist/adapters/bedrock-converse/requestTransform.d.ts +111 -0
- package/dist/adapters/bedrock-converse/requestTransform.js +187 -0
- package/dist/adapters/bedrock-converse/requestTransform.js.map +1 -0
- package/dist/adapters/bedrock-converse/responseTransform.d.ts +7 -0
- package/dist/adapters/bedrock-converse/responseTransform.js +104 -0
- package/dist/adapters/bedrock-converse/responseTransform.js.map +1 -0
- package/dist/adapters/bedrock-converse/streamTransform.d.ts +34 -0
- package/dist/adapters/bedrock-converse/streamTransform.js +204 -0
- package/dist/adapters/bedrock-converse/streamTransform.js.map +1 -0
- package/dist/adapters/constants.d.ts +15 -0
- package/dist/adapters/constants.js +26 -0
- package/dist/adapters/constants.js.map +1 -0
- package/dist/adapters/gemini/index.d.ts +9 -0
- package/dist/adapters/gemini/index.js +146 -0
- package/dist/adapters/gemini/index.js.map +1 -0
- package/dist/adapters/gemini/requestTransform.d.ts +72 -0
- package/dist/adapters/gemini/requestTransform.js +227 -0
- package/dist/adapters/gemini/requestTransform.js.map +1 -0
- package/dist/adapters/gemini/responseTransform.d.ts +7 -0
- package/dist/adapters/gemini/responseTransform.js +113 -0
- package/dist/adapters/gemini/responseTransform.js.map +1 -0
- package/dist/adapters/gemini/streamTransform.d.ts +22 -0
- package/dist/adapters/gemini/streamTransform.js +174 -0
- package/dist/adapters/gemini/streamTransform.js.map +1 -0
- package/dist/adapters/guardrailHelpers.d.ts +49 -0
- package/dist/adapters/guardrailHelpers.js +23 -0
- package/dist/adapters/guardrailHelpers.js.map +1 -0
- package/dist/adapters/index.d.ts +28 -0
- package/dist/adapters/index.js +62 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/messages/index.d.ts +9 -0
- package/dist/adapters/messages/index.js +112 -0
- package/dist/adapters/messages/index.js.map +1 -0
- package/dist/adapters/messages/requestTransform.d.ts +8 -0
- package/dist/adapters/messages/requestTransform.js +206 -0
- package/dist/adapters/messages/requestTransform.js.map +1 -0
- package/dist/adapters/messages/responseTransform.d.ts +8 -0
- package/dist/adapters/messages/responseTransform.js +104 -0
- package/dist/adapters/messages/responseTransform.js.map +1 -0
- package/dist/adapters/messages/streamTransform.d.ts +26 -0
- package/dist/adapters/messages/streamTransform.js +174 -0
- package/dist/adapters/messages/streamTransform.js.map +1 -0
- package/dist/adapters/registry.d.ts +67 -0
- package/dist/adapters/registry.js +232 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/responses/encryptedContentAffinity.d.ts +12 -0
- package/dist/adapters/responses/encryptedContentAffinity.js +55 -0
- package/dist/adapters/responses/encryptedContentAffinity.js.map +1 -0
- package/dist/adapters/responses/index.d.ts +6 -0
- package/dist/adapters/responses/index.js +201 -0
- package/dist/adapters/responses/index.js.map +1 -0
- package/dist/adapters/responses/requestTransform.d.ts +7 -0
- package/dist/adapters/responses/requestTransform.js +190 -0
- package/dist/adapters/responses/requestTransform.js.map +1 -0
- package/dist/adapters/responses/responseTransform.d.ts +30 -0
- package/dist/adapters/responses/responseTransform.js +174 -0
- package/dist/adapters/responses/responseTransform.js.map +1 -0
- package/dist/adapters/responses/streamTransform.d.ts +40 -0
- package/dist/adapters/responses/streamTransform.js +301 -0
- package/dist/adapters/responses/streamTransform.js.map +1 -0
- package/dist/adapters/types.d.ts +79 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/autogen/decoders.d.ts +956 -0
- package/dist/autogen/decoders.js +10502 -0
- package/dist/autogen/decoders.js.map +1 -0
- package/dist/autogen/helpers.d.ts +5 -0
- package/dist/autogen/helpers.js +3 -0
- package/dist/autogen/helpers.js.map +1 -0
- package/dist/autogen/meta.d.ts +961 -0
- package/dist/autogen/meta.js +960 -0
- package/dist/autogen/meta.js.map +1 -0
- package/dist/autogen/models.d.ts +24388 -0
- package/dist/autogen/models.js +9 -0
- package/dist/autogen/models.js.map +1 -0
- package/dist/autogen/schema.json +30705 -0
- package/dist/autogen/validate.d.ts +6 -0
- package/dist/autogen/validate.js +15 -0
- package/dist/autogen/validate.js.map +1 -0
- package/dist/cache/port.d.ts +31 -0
- package/dist/cache/port.js +44 -0
- package/dist/cache/port.js.map +1 -0
- package/dist/catalog/snapshots.d.ts +19 -0
- package/dist/catalog/snapshots.js +14 -0
- package/dist/catalog/snapshots.js.map +1 -0
- package/dist/config.d.ts +89 -0
- package/dist/config.js +195 -0
- package/dist/config.js.map +1 -0
- package/dist/constants/jsonRpc.d.ts +30 -0
- package/dist/constants/jsonRpc.js +11 -0
- package/dist/constants/jsonRpc.js.map +1 -0
- package/dist/constants.d.ts +26 -0
- package/dist/constants.js +27 -0
- package/dist/constants.js.map +1 -0
- package/dist/entities/Authentication.d.ts +37 -0
- package/dist/entities/Authentication.js +11 -0
- package/dist/entities/Authentication.js.map +1 -0
- package/dist/entities/Model.d.ts +105 -0
- package/dist/entities/Model.js +55 -0
- package/dist/entities/Model.js.map +1 -0
- package/dist/entities/Provider.d.ts +46 -0
- package/dist/entities/Provider.js +48 -0
- package/dist/entities/Provider.js.map +1 -0
- package/dist/entities/ProviderAccount.d.ts +23 -0
- package/dist/entities/ProviderAccount.js +2 -0
- package/dist/entities/ProviderAccount.js.map +1 -0
- package/dist/errors.d.ts +190 -0
- package/dist/errors.js +300 -0
- package/dist/errors.js.map +1 -0
- package/dist/globals.d.ts +452 -0
- package/dist/globals.js +782 -0
- package/dist/globals.js.map +1 -0
- package/dist/handlers/handlerUtils.d.ts +2 -0
- package/dist/handlers/handlerUtils.js +240 -0
- package/dist/handlers/handlerUtils.js.map +1 -0
- package/dist/handlers/retryFromExecution.d.ts +12 -0
- package/dist/handlers/retryFromExecution.js +21 -0
- package/dist/handlers/retryFromExecution.js.map +1 -0
- package/dist/handlers/retryHandler.d.ts +20 -0
- package/dist/handlers/retryHandler.js +276 -0
- package/dist/handlers/retryHandler.js.map +1 -0
- package/dist/handlers/streamHandler.d.ts +6 -0
- package/dist/handlers/streamHandler.js +29 -0
- package/dist/handlers/streamHandler.js.map +1 -0
- package/dist/handlers/streamHandlerUtils.d.ts +21 -0
- package/dist/handlers/streamHandlerUtils.js +220 -0
- package/dist/handlers/streamHandlerUtils.js.map +1 -0
- package/dist/handlers/tfyUtils.d.ts +24 -0
- package/dist/handlers/tfyUtils.js +221 -0
- package/dist/handlers/tfyUtils.js.map +1 -0
- package/dist/http/createSafeDispatcher.d.ts +29 -0
- package/dist/http/createSafeDispatcher.js +49 -0
- package/dist/http/createSafeDispatcher.js.map +1 -0
- package/dist/http/errors.d.ts +23 -0
- package/dist/http/errors.js +128 -0
- package/dist/http/errors.js.map +1 -0
- package/dist/http/guardedLookup.d.ts +18 -0
- package/dist/http/guardedLookup.js +72 -0
- package/dist/http/guardedLookup.js.map +1 -0
- package/dist/http/index.d.ts +7 -0
- package/dist/http/index.js +7 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/isPublicIp.d.ts +1 -0
- package/dist/http/isPublicIp.js +63 -0
- package/dist/http/isPublicIp.js.map +1 -0
- package/dist/http/loopbackDispatcher.d.ts +32 -0
- package/dist/http/loopbackDispatcher.js +40 -0
- package/dist/http/loopbackDispatcher.js.map +1 -0
- package/dist/http/loopbackFetch.d.ts +18 -0
- package/dist/http/loopbackFetch.js +47 -0
- package/dist/http/loopbackFetch.js.map +1 -0
- package/dist/http/meshTls.d.ts +153 -0
- package/dist/http/meshTls.js +274 -0
- package/dist/http/meshTls.js.map +1 -0
- package/dist/http/safeFetch.d.ts +49 -0
- package/dist/http/safeFetch.js +226 -0
- package/dist/http/safeFetch.js.map +1 -0
- package/dist/http/types.d.ts +10 -0
- package/dist/http/types.js +2 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/urlverify/config.d.ts +20 -0
- package/dist/http/urlverify/config.js +66 -0
- package/dist/http/urlverify/config.js.map +1 -0
- package/dist/http/urlverify/hostname.d.ts +10 -0
- package/dist/http/urlverify/hostname.js +29 -0
- package/dist/http/urlverify/hostname.js.map +1 -0
- package/dist/http/urlverify/ip.d.ts +13 -0
- package/dist/http/urlverify/ip.js +115 -0
- package/dist/http/urlverify/ip.js.map +1 -0
- package/dist/http/urlverify/mode.d.ts +20 -0
- package/dist/http/urlverify/mode.js +22 -0
- package/dist/http/urlverify/mode.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/loadbalancer_utils.d.ts +6 -0
- package/dist/loadbalancer_utils.js +2 -0
- package/dist/loadbalancer_utils.js.map +1 -0
- package/dist/logger.d.ts +18 -0
- package/dist/logger.js +93 -0
- package/dist/logger.js.map +1 -0
- package/dist/parity/transformCapturedProviderResponse.d.ts +42 -0
- package/dist/parity/transformCapturedProviderResponse.js +52 -0
- package/dist/parity/transformCapturedProviderResponse.js.map +1 -0
- package/dist/providers/ai21/api.d.ts +3 -0
- package/dist/providers/ai21/api.js +21 -0
- package/dist/providers/ai21/api.js.map +1 -0
- package/dist/providers/ai21/chatComplete.d.ts +4 -0
- package/dist/providers/ai21/chatComplete.js +170 -0
- package/dist/providers/ai21/chatComplete.js.map +1 -0
- package/dist/providers/ai21/index.d.ts +8 -0
- package/dist/providers/ai21/index.js +11 -0
- package/dist/providers/ai21/index.js.map +1 -0
- package/dist/providers/anthropic/anthropicBetas.d.ts +51 -0
- package/dist/providers/anthropic/anthropicBetas.js +95 -0
- package/dist/providers/anthropic/anthropicBetas.js.map +1 -0
- package/dist/providers/anthropic/api.d.ts +22 -0
- package/dist/providers/anthropic/api.js +87 -0
- package/dist/providers/anthropic/api.js.map +1 -0
- package/dist/providers/anthropic/betaTracing.d.ts +10 -0
- package/dist/providers/anthropic/betaTracing.js +30 -0
- package/dist/providers/anthropic/betaTracing.js.map +1 -0
- package/dist/providers/anthropic/chatComplete.d.ts +137 -0
- package/dist/providers/anthropic/chatComplete.js +1395 -0
- package/dist/providers/anthropic/chatComplete.js.map +1 -0
- package/dist/providers/anthropic/complete.d.ts +32 -0
- package/dist/providers/anthropic/complete.js +110 -0
- package/dist/providers/anthropic/complete.js.map +1 -0
- package/dist/providers/anthropic/deleteFile.d.ts +7 -0
- package/dist/providers/anthropic/deleteFile.js +23 -0
- package/dist/providers/anthropic/deleteFile.js.map +1 -0
- package/dist/providers/anthropic/fileTypes.d.ts +64 -0
- package/dist/providers/anthropic/fileTypes.js +7 -0
- package/dist/providers/anthropic/fileTypes.js.map +1 -0
- package/dist/providers/anthropic/fileUtils.d.ts +14 -0
- package/dist/providers/anthropic/fileUtils.js +22 -0
- package/dist/providers/anthropic/fileUtils.js.map +1 -0
- package/dist/providers/anthropic/index.d.ts +8 -0
- package/dist/providers/anthropic/index.js +33 -0
- package/dist/providers/anthropic/index.js.map +1 -0
- package/dist/providers/anthropic/listFiles.d.ts +7 -0
- package/dist/providers/anthropic/listFiles.js +26 -0
- package/dist/providers/anthropic/listFiles.js.map +1 -0
- package/dist/providers/anthropic/messages.d.ts +5 -0
- package/dist/providers/anthropic/messages.js +19 -0
- package/dist/providers/anthropic/messages.js.map +1 -0
- package/dist/providers/anthropic/retrieveFile.d.ts +7 -0
- package/dist/providers/anthropic/retrieveFile.js +19 -0
- package/dist/providers/anthropic/retrieveFile.js.map +1 -0
- package/dist/providers/anthropic/retrieveFileContent.d.ts +4 -0
- package/dist/providers/anthropic/retrieveFileContent.js +17 -0
- package/dist/providers/anthropic/retrieveFileContent.js.map +1 -0
- package/dist/providers/anthropic/serverTools.d.ts +10 -0
- package/dist/providers/anthropic/serverTools.js +70 -0
- package/dist/providers/anthropic/serverTools.js.map +1 -0
- package/dist/providers/anthropic/types.d.ts +119 -0
- package/dist/providers/anthropic/types.js +11 -0
- package/dist/providers/anthropic/types.js.map +1 -0
- package/dist/providers/anthropic/uploadFile.d.ts +7 -0
- package/dist/providers/anthropic/uploadFile.js +47 -0
- package/dist/providers/anthropic/uploadFile.js.map +1 -0
- package/dist/providers/anthropic/uploadFileUtils.d.ts +20 -0
- package/dist/providers/anthropic/uploadFileUtils.js +60 -0
- package/dist/providers/anthropic/uploadFileUtils.js.map +1 -0
- package/dist/providers/anthropic/utils.d.ts +52 -0
- package/dist/providers/anthropic/utils.js +119 -0
- package/dist/providers/anthropic/utils.js.map +1 -0
- package/dist/providers/anthropic-base/constants.d.ts +12 -0
- package/dist/providers/anthropic-base/constants.js +53 -0
- package/dist/providers/anthropic-base/constants.js.map +1 -0
- package/dist/providers/anthropic-base/messages.d.ts +12 -0
- package/dist/providers/anthropic-base/messages.js +81 -0
- package/dist/providers/anthropic-base/messages.js.map +1 -0
- package/dist/providers/anthropic-base/types.d.ts +49 -0
- package/dist/providers/anthropic-base/types.js +2 -0
- package/dist/providers/anthropic-base/types.js.map +1 -0
- package/dist/providers/anthropic-base/utils/streamGenerator.d.ts +7 -0
- package/dist/providers/anthropic-base/utils/streamGenerator.js +135 -0
- package/dist/providers/anthropic-base/utils/streamGenerator.js.map +1 -0
- package/dist/providers/anyscale/api.d.ts +12 -0
- package/dist/providers/anyscale/api.js +26 -0
- package/dist/providers/anyscale/api.js.map +1 -0
- package/dist/providers/anyscale/chatComplete.d.ts +29 -0
- package/dist/providers/anyscale/chatComplete.js +163 -0
- package/dist/providers/anyscale/chatComplete.js.map +1 -0
- package/dist/providers/anyscale/complete.d.ts +8 -0
- package/dist/providers/anyscale/complete.js +111 -0
- package/dist/providers/anyscale/complete.js.map +1 -0
- package/dist/providers/anyscale/embed.d.ts +7 -0
- package/dist/providers/anyscale/embed.js +40 -0
- package/dist/providers/anyscale/embed.js.map +1 -0
- package/dist/providers/anyscale/index.d.ts +8 -0
- package/dist/providers/anyscale/index.js +19 -0
- package/dist/providers/anyscale/index.js.map +1 -0
- package/dist/providers/aws-bedrock-mantle/api.d.ts +14 -0
- package/dist/providers/aws-bedrock-mantle/api.js +200 -0
- package/dist/providers/aws-bedrock-mantle/api.js.map +1 -0
- package/dist/providers/aws-bedrock-mantle/index.d.ts +5 -0
- package/dist/providers/aws-bedrock-mantle/index.js +91 -0
- package/dist/providers/aws-bedrock-mantle/index.js.map +1 -0
- package/dist/providers/aws-bedrock-mantle/modelFamily.d.ts +5 -0
- package/dist/providers/aws-bedrock-mantle/modelFamily.js +11 -0
- package/dist/providers/aws-bedrock-mantle/modelFamily.js.map +1 -0
- package/dist/providers/aws-bedrock-mantle/responsesLite.d.ts +14 -0
- package/dist/providers/aws-bedrock-mantle/responsesLite.js +210 -0
- package/dist/providers/aws-bedrock-mantle/responsesLite.js.map +1 -0
- package/dist/providers/aws-claude-platform/api.d.ts +3 -0
- package/dist/providers/aws-claude-platform/api.js +105 -0
- package/dist/providers/aws-claude-platform/api.js.map +1 -0
- package/dist/providers/aws-claude-platform/index.d.ts +3 -0
- package/dist/providers/aws-claude-platform/index.js +21 -0
- package/dist/providers/aws-claude-platform/index.js.map +1 -0
- package/dist/providers/aws-claude-platform/uploadFile.d.ts +21 -0
- package/dist/providers/aws-claude-platform/uploadFile.js +58 -0
- package/dist/providers/aws-claude-platform/uploadFile.js.map +1 -0
- package/dist/providers/azure-ai-inference/api.d.ts +4 -0
- package/dist/providers/azure-ai-inference/api.js +209 -0
- package/dist/providers/azure-ai-inference/api.js.map +1 -0
- package/dist/providers/azure-ai-inference/chatComplete.d.ts +6 -0
- package/dist/providers/azure-ai-inference/chatComplete.js +78 -0
- package/dist/providers/azure-ai-inference/chatComplete.js.map +1 -0
- package/dist/providers/azure-ai-inference/complete.d.ts +6 -0
- package/dist/providers/azure-ai-inference/complete.js +63 -0
- package/dist/providers/azure-ai-inference/complete.js.map +1 -0
- package/dist/providers/azure-ai-inference/createSpeech.d.ts +5 -0
- package/dist/providers/azure-ai-inference/createSpeech.js +58 -0
- package/dist/providers/azure-ai-inference/createSpeech.js.map +1 -0
- package/dist/providers/azure-ai-inference/createTranscription.d.ts +4 -0
- package/dist/providers/azure-ai-inference/createTranscription.js +29 -0
- package/dist/providers/azure-ai-inference/createTranscription.js.map +1 -0
- package/dist/providers/azure-ai-inference/createTranslation.d.ts +4 -0
- package/dist/providers/azure-ai-inference/createTranslation.js +29 -0
- package/dist/providers/azure-ai-inference/createTranslation.js.map +1 -0
- package/dist/providers/azure-ai-inference/embed.d.ts +12 -0
- package/dist/providers/azure-ai-inference/embed.js +24 -0
- package/dist/providers/azure-ai-inference/embed.js.map +1 -0
- package/dist/providers/azure-ai-inference/index.d.ts +4 -0
- package/dist/providers/azure-ai-inference/index.js +69 -0
- package/dist/providers/azure-ai-inference/index.js.map +1 -0
- package/dist/providers/azure-ai-inference/messages.d.ts +5 -0
- package/dist/providers/azure-ai-inference/messages.js +21 -0
- package/dist/providers/azure-ai-inference/messages.js.map +1 -0
- package/dist/providers/azure-ai-inference/rerank.d.ts +30 -0
- package/dist/providers/azure-ai-inference/rerank.js +61 -0
- package/dist/providers/azure-ai-inference/rerank.js.map +1 -0
- package/dist/providers/azure-openai/api.d.ts +3 -0
- package/dist/providers/azure-openai/api.js +227 -0
- package/dist/providers/azure-openai/api.js.map +1 -0
- package/dist/providers/azure-openai/chatComplete.d.ts +6 -0
- package/dist/providers/azure-openai/chatComplete.js +168 -0
- package/dist/providers/azure-openai/chatComplete.js.map +1 -0
- package/dist/providers/azure-openai/complete.d.ts +6 -0
- package/dist/providers/azure-openai/complete.js +78 -0
- package/dist/providers/azure-openai/complete.js.map +1 -0
- package/dist/providers/azure-openai/createBatch.d.ts +3 -0
- package/dist/providers/azure-openai/createBatch.js +47 -0
- package/dist/providers/azure-openai/createBatch.js.map +1 -0
- package/dist/providers/azure-openai/createFinetune.d.ts +37 -0
- package/dist/providers/azure-openai/createFinetune.js +12 -0
- package/dist/providers/azure-openai/createFinetune.js.map +1 -0
- package/dist/providers/azure-openai/createSpeech.d.ts +3 -0
- package/dist/providers/azure-openai/createSpeech.js +40 -0
- package/dist/providers/azure-openai/createSpeech.js.map +1 -0
- package/dist/providers/azure-openai/createTranscription.d.ts +9 -0
- package/dist/providers/azure-openai/createTranscription.js +41 -0
- package/dist/providers/azure-openai/createTranscription.js.map +1 -0
- package/dist/providers/azure-openai/createTranslation.d.ts +9 -0
- package/dist/providers/azure-openai/createTranslation.js +41 -0
- package/dist/providers/azure-openai/createTranslation.js.map +1 -0
- package/dist/providers/azure-openai/embed.d.ts +7 -0
- package/dist/providers/azure-openai/embed.js +34 -0
- package/dist/providers/azure-openai/embed.js.map +1 -0
- package/dist/providers/azure-openai/getBatchOutput.d.ts +2 -0
- package/dist/providers/azure-openai/getBatchOutput.js +120 -0
- package/dist/providers/azure-openai/getBatchOutput.js.map +1 -0
- package/dist/providers/azure-openai/imageEdit.d.ts +4 -0
- package/dist/providers/azure-openai/imageEdit.js +40 -0
- package/dist/providers/azure-openai/imageEdit.js.map +1 -0
- package/dist/providers/azure-openai/imageGenerate.d.ts +12 -0
- package/dist/providers/azure-openai/imageGenerate.js +45 -0
- package/dist/providers/azure-openai/imageGenerate.js.map +1 -0
- package/dist/providers/azure-openai/index.d.ts +6 -0
- package/dist/providers/azure-openai/index.js +125 -0
- package/dist/providers/azure-openai/index.js.map +1 -0
- package/dist/providers/azure-openai/utils.d.ts +19 -0
- package/dist/providers/azure-openai/utils.js +99 -0
- package/dist/providers/azure-openai/utils.js.map +1 -0
- package/dist/providers/azure-openai/wifAuth.d.ts +1 -0
- package/dist/providers/azure-openai/wifAuth.js +19 -0
- package/dist/providers/azure-openai/wifAuth.js.map +1 -0
- package/dist/providers/baseten/api.d.ts +3 -0
- package/dist/providers/baseten/api.js +24 -0
- package/dist/providers/baseten/api.js.map +1 -0
- package/dist/providers/baseten/index.d.ts +3 -0
- package/dist/providers/baseten/index.js +19 -0
- package/dist/providers/baseten/index.js.map +1 -0
- package/dist/providers/bedrock/api.d.ts +25 -0
- package/dist/providers/bedrock/api.js +470 -0
- package/dist/providers/bedrock/api.js.map +1 -0
- package/dist/providers/bedrock/cancelBatch.d.ts +10 -0
- package/dist/providers/bedrock/cancelBatch.js +20 -0
- package/dist/providers/bedrock/cancelBatch.js.map +1 -0
- package/dist/providers/bedrock/chatComplete.d.ts +70 -0
- package/dist/providers/bedrock/chatComplete.js +1375 -0
- package/dist/providers/bedrock/chatComplete.js.map +1 -0
- package/dist/providers/bedrock/complete.d.ts +136 -0
- package/dist/providers/bedrock/complete.js +868 -0
- package/dist/providers/bedrock/complete.js.map +1 -0
- package/dist/providers/bedrock/constants.d.ts +72 -0
- package/dist/providers/bedrock/constants.js +99 -0
- package/dist/providers/bedrock/constants.js.map +1 -0
- package/dist/providers/bedrock/countTokens.d.ts +16 -0
- package/dist/providers/bedrock/countTokens.js +61 -0
- package/dist/providers/bedrock/countTokens.js.map +1 -0
- package/dist/providers/bedrock/createBatch.d.ts +4 -0
- package/dist/providers/bedrock/createBatch.js +75 -0
- package/dist/providers/bedrock/createBatch.js.map +1 -0
- package/dist/providers/bedrock/createFinetune.d.ts +11 -0
- package/dist/providers/bedrock/createFinetune.js +88 -0
- package/dist/providers/bedrock/createFinetune.js.map +1 -0
- package/dist/providers/bedrock/deleteFile.d.ts +2 -0
- package/dist/providers/bedrock/deleteFile.js +10 -0
- package/dist/providers/bedrock/deleteFile.js.map +1 -0
- package/dist/providers/bedrock/embed.d.ts +68 -0
- package/dist/providers/bedrock/embed.js +345 -0
- package/dist/providers/bedrock/embed.js.map +1 -0
- package/dist/providers/bedrock/getBatchOutput.d.ts +5 -0
- package/dist/providers/bedrock/getBatchOutput.js +112 -0
- package/dist/providers/bedrock/getBatchOutput.js.map +1 -0
- package/dist/providers/bedrock/imageEdit.d.ts +18 -0
- package/dist/providers/bedrock/imageEdit.js +493 -0
- package/dist/providers/bedrock/imageEdit.js.map +1 -0
- package/dist/providers/bedrock/imageGenerate.d.ts +36 -0
- package/dist/providers/bedrock/imageGenerate.js +151 -0
- package/dist/providers/bedrock/imageGenerate.js.map +1 -0
- package/dist/providers/bedrock/imageVariation.d.ts +9 -0
- package/dist/providers/bedrock/imageVariation.js +117 -0
- package/dist/providers/bedrock/imageVariation.js.map +1 -0
- package/dist/providers/bedrock/index.d.ts +6 -0
- package/dist/providers/bedrock/index.js +328 -0
- package/dist/providers/bedrock/index.js.map +1 -0
- package/dist/providers/bedrock/listBatches.d.ts +4 -0
- package/dist/providers/bedrock/listBatches.js +33 -0
- package/dist/providers/bedrock/listBatches.js.map +1 -0
- package/dist/providers/bedrock/listFiles.d.ts +2 -0
- package/dist/providers/bedrock/listFiles.js +10 -0
- package/dist/providers/bedrock/listFiles.js.map +1 -0
- package/dist/providers/bedrock/listFinetunes.d.ts +7 -0
- package/dist/providers/bedrock/listFinetunes.js +16 -0
- package/dist/providers/bedrock/listFinetunes.js.map +1 -0
- package/dist/providers/bedrock/messages.d.ts +21 -0
- package/dist/providers/bedrock/messages.js +436 -0
- package/dist/providers/bedrock/messages.js.map +1 -0
- package/dist/providers/bedrock/modelFamily.d.ts +9 -0
- package/dist/providers/bedrock/modelFamily.js +12 -0
- package/dist/providers/bedrock/modelFamily.js.map +1 -0
- package/dist/providers/bedrock/requestHandlerFetch.d.ts +9 -0
- package/dist/providers/bedrock/requestHandlerFetch.js +35 -0
- package/dist/providers/bedrock/requestHandlerFetch.js.map +1 -0
- package/dist/providers/bedrock/rerank.d.ts +18 -0
- package/dist/providers/bedrock/rerank.js +126 -0
- package/dist/providers/bedrock/rerank.js.map +1 -0
- package/dist/providers/bedrock/retrieveBatch.d.ts +4 -0
- package/dist/providers/bedrock/retrieveBatch.js +43 -0
- package/dist/providers/bedrock/retrieveBatch.js.map +1 -0
- package/dist/providers/bedrock/retrieveFile.d.ts +2 -0
- package/dist/providers/bedrock/retrieveFile.js +66 -0
- package/dist/providers/bedrock/retrieveFile.js.map +1 -0
- package/dist/providers/bedrock/retrieveFileContent.d.ts +3 -0
- package/dist/providers/bedrock/retrieveFileContent.js +61 -0
- package/dist/providers/bedrock/retrieveFileContent.js.map +1 -0
- package/dist/providers/bedrock/retrieveFinetune.d.ts +7 -0
- package/dist/providers/bedrock/retrieveFinetune.js +9 -0
- package/dist/providers/bedrock/retrieveFinetune.js.map +1 -0
- package/dist/providers/bedrock/types.d.ts +291 -0
- package/dist/providers/bedrock/types.js +28 -0
- package/dist/providers/bedrock/types.js.map +1 -0
- package/dist/providers/bedrock/uploadFile.d.ts +11 -0
- package/dist/providers/bedrock/uploadFile.js +471 -0
- package/dist/providers/bedrock/uploadFile.js.map +1 -0
- package/dist/providers/bedrock/uploadFileUtils.d.ts +68 -0
- package/dist/providers/bedrock/uploadFileUtils.js +952 -0
- package/dist/providers/bedrock/uploadFileUtils.js.map +1 -0
- package/dist/providers/bedrock/utils/messagesUtils.d.ts +35 -0
- package/dist/providers/bedrock/utils/messagesUtils.js +73 -0
- package/dist/providers/bedrock/utils/messagesUtils.js.map +1 -0
- package/dist/providers/bedrock/utils.d.ts +72 -0
- package/dist/providers/bedrock/utils.js +652 -0
- package/dist/providers/bedrock/utils.js.map +1 -0
- package/dist/providers/cartesia/api.d.ts +13 -0
- package/dist/providers/cartesia/api.js +27 -0
- package/dist/providers/cartesia/api.js.map +1 -0
- package/dist/providers/cartesia/index.d.ts +13 -0
- package/dist/providers/cartesia/index.js +16 -0
- package/dist/providers/cartesia/index.js.map +1 -0
- package/dist/providers/cerebras/api.d.ts +2 -0
- package/dist/providers/cerebras/api.js +19 -0
- package/dist/providers/cerebras/api.js.map +1 -0
- package/dist/providers/cerebras/index.d.ts +3 -0
- package/dist/providers/cerebras/index.js +19 -0
- package/dist/providers/cerebras/index.js.map +1 -0
- package/dist/providers/cloudera/api.d.ts +3 -0
- package/dist/providers/cloudera/api.js +34 -0
- package/dist/providers/cloudera/api.js.map +1 -0
- package/dist/providers/cloudera/chatComplete.d.ts +14 -0
- package/dist/providers/cloudera/chatComplete.js +63 -0
- package/dist/providers/cloudera/chatComplete.js.map +1 -0
- package/dist/providers/cloudera/embed.d.ts +5 -0
- package/dist/providers/cloudera/embed.js +29 -0
- package/dist/providers/cloudera/embed.js.map +1 -0
- package/dist/providers/cloudera/index.d.ts +8 -0
- package/dist/providers/cloudera/index.js +15 -0
- package/dist/providers/cloudera/index.js.map +1 -0
- package/dist/providers/cloudera/utils.d.ts +1 -0
- package/dist/providers/cloudera/utils.js +261 -0
- package/dist/providers/cloudera/utils.js.map +1 -0
- package/dist/providers/cohere/api.d.ts +3 -0
- package/dist/providers/cohere/api.js +52 -0
- package/dist/providers/cohere/api.js.map +1 -0
- package/dist/providers/cohere/cancelBatch.d.ts +8 -0
- package/dist/providers/cohere/cancelBatch.js +12 -0
- package/dist/providers/cohere/cancelBatch.js.map +1 -0
- package/dist/providers/cohere/chatComplete.d.ts +6 -0
- package/dist/providers/cohere/chatComplete.js +315 -0
- package/dist/providers/cohere/chatComplete.js.map +1 -0
- package/dist/providers/cohere/complete.d.ts +39 -0
- package/dist/providers/cohere/complete.js +116 -0
- package/dist/providers/cohere/complete.js.map +1 -0
- package/dist/providers/cohere/createBatch.d.ts +4 -0
- package/dist/providers/cohere/createBatch.js +51 -0
- package/dist/providers/cohere/createBatch.js.map +1 -0
- package/dist/providers/cohere/deleteFile.d.ts +8 -0
- package/dist/providers/cohere/deleteFile.js +13 -0
- package/dist/providers/cohere/deleteFile.js.map +1 -0
- package/dist/providers/cohere/embed.d.ts +94 -0
- package/dist/providers/cohere/embed.js +137 -0
- package/dist/providers/cohere/embed.js.map +1 -0
- package/dist/providers/cohere/getBatchOutput.d.ts +2 -0
- package/dist/providers/cohere/getBatchOutput.js +117 -0
- package/dist/providers/cohere/getBatchOutput.js.map +1 -0
- package/dist/providers/cohere/getFiles.d.ts +4 -0
- package/dist/providers/cohere/getFiles.js +51 -0
- package/dist/providers/cohere/getFiles.js.map +1 -0
- package/dist/providers/cohere/index.d.ts +10 -0
- package/dist/providers/cohere/index.js +46 -0
- package/dist/providers/cohere/index.js.map +1 -0
- package/dist/providers/cohere/listBatches.d.ts +3 -0
- package/dist/providers/cohere/listBatches.js +30 -0
- package/dist/providers/cohere/listBatches.js.map +1 -0
- package/dist/providers/cohere/rerank.d.ts +46 -0
- package/dist/providers/cohere/rerank.js +41 -0
- package/dist/providers/cohere/rerank.js.map +1 -0
- package/dist/providers/cohere/retrieveBatch.d.ts +3 -0
- package/dist/providers/cohere/retrieveBatch.js +33 -0
- package/dist/providers/cohere/retrieveBatch.js.map +1 -0
- package/dist/providers/cohere/types.d.ts +264 -0
- package/dist/providers/cohere/types.js +10 -0
- package/dist/providers/cohere/types.js.map +1 -0
- package/dist/providers/cohere/uploadFile.d.ts +13 -0
- package/dist/providers/cohere/uploadFile.js +40 -0
- package/dist/providers/cohere/uploadFile.js.map +1 -0
- package/dist/providers/cohere/utils.d.ts +2 -0
- package/dist/providers/cohere/utils.js +15 -0
- package/dist/providers/cohere/utils.js.map +1 -0
- package/dist/providers/cortex/api.d.ts +3 -0
- package/dist/providers/cortex/api.js +25 -0
- package/dist/providers/cortex/api.js.map +1 -0
- package/dist/providers/cortex/index.d.ts +3 -0
- package/dist/providers/cortex/index.js +37 -0
- package/dist/providers/cortex/index.js.map +1 -0
- package/dist/providers/databricks/api.d.ts +3 -0
- package/dist/providers/databricks/api.js +69 -0
- package/dist/providers/databricks/api.js.map +1 -0
- package/dist/providers/databricks/chatComplete.d.ts +17 -0
- package/dist/providers/databricks/chatComplete.js +174 -0
- package/dist/providers/databricks/chatComplete.js.map +1 -0
- package/dist/providers/databricks/createModelResponse.d.ts +12 -0
- package/dist/providers/databricks/createModelResponse.js +24 -0
- package/dist/providers/databricks/createModelResponse.js.map +1 -0
- package/dist/providers/databricks/embed.d.ts +6 -0
- package/dist/providers/databricks/embed.js +27 -0
- package/dist/providers/databricks/embed.js.map +1 -0
- package/dist/providers/databricks/index.d.ts +3 -0
- package/dist/providers/databricks/index.js +66 -0
- package/dist/providers/databricks/index.js.map +1 -0
- package/dist/providers/databricks/messages.d.ts +5 -0
- package/dist/providers/databricks/messages.js +23 -0
- package/dist/providers/databricks/messages.js.map +1 -0
- package/dist/providers/databricks/utils.d.ts +3 -0
- package/dist/providers/databricks/utils.js +46 -0
- package/dist/providers/databricks/utils.js.map +1 -0
- package/dist/providers/deepgram/api.d.ts +13 -0
- package/dist/providers/deepgram/api.js +26 -0
- package/dist/providers/deepgram/api.js.map +1 -0
- package/dist/providers/deepgram/index.d.ts +13 -0
- package/dist/providers/deepgram/index.js +16 -0
- package/dist/providers/deepgram/index.js.map +1 -0
- package/dist/providers/deepinfra/api.d.ts +3 -0
- package/dist/providers/deepinfra/api.js +21 -0
- package/dist/providers/deepinfra/api.js.map +1 -0
- package/dist/providers/deepinfra/chatComplete.d.ts +23 -0
- package/dist/providers/deepinfra/chatComplete.js +150 -0
- package/dist/providers/deepinfra/chatComplete.js.map +1 -0
- package/dist/providers/deepinfra/embed.d.ts +5 -0
- package/dist/providers/deepinfra/embed.js +28 -0
- package/dist/providers/deepinfra/embed.js.map +1 -0
- package/dist/providers/deepinfra/index.d.ts +8 -0
- package/dist/providers/deepinfra/index.js +15 -0
- package/dist/providers/deepinfra/index.js.map +1 -0
- package/dist/providers/deepinfra/utils.d.ts +3 -0
- package/dist/providers/deepinfra/utils.js +25 -0
- package/dist/providers/deepinfra/utils.js.map +1 -0
- package/dist/providers/elevenlabs/api.d.ts +8 -0
- package/dist/providers/elevenlabs/api.js +21 -0
- package/dist/providers/elevenlabs/api.js.map +1 -0
- package/dist/providers/elevenlabs/index.d.ts +8 -0
- package/dist/providers/elevenlabs/index.js +11 -0
- package/dist/providers/elevenlabs/index.js.map +1 -0
- package/dist/providers/google/api.d.ts +8 -0
- package/dist/providers/google/api.js +52 -0
- package/dist/providers/google/api.js.map +1 -0
- package/dist/providers/google/chatComplete.d.ts +131 -0
- package/dist/providers/google/chatComplete.js +935 -0
- package/dist/providers/google/chatComplete.js.map +1 -0
- package/dist/providers/google/createSpeech.d.ts +30 -0
- package/dist/providers/google/createSpeech.js +227 -0
- package/dist/providers/google/createSpeech.js.map +1 -0
- package/dist/providers/google/embed.d.ts +11 -0
- package/dist/providers/google/embed.js +77 -0
- package/dist/providers/google/embed.js.map +1 -0
- package/dist/providers/google/imageEdit.d.ts +5 -0
- package/dist/providers/google/imageEdit.js +165 -0
- package/dist/providers/google/imageEdit.js.map +1 -0
- package/dist/providers/google/imageGenerate.d.ts +16 -0
- package/dist/providers/google/imageGenerate.js +181 -0
- package/dist/providers/google/imageGenerate.js.map +1 -0
- package/dist/providers/google/index.d.ts +8 -0
- package/dist/providers/google/index.js +44 -0
- package/dist/providers/google/index.js.map +1 -0
- package/dist/providers/google/responseFormatHandlers.d.ts +13 -0
- package/dist/providers/google/responseFormatHandlers.js +30 -0
- package/dist/providers/google/responseFormatHandlers.js.map +1 -0
- package/dist/providers/google/types.d.ts +48 -0
- package/dist/providers/google/types.js +16 -0
- package/dist/providers/google/types.js.map +1 -0
- package/dist/providers/google-vertex-ai/api.d.ts +14 -0
- package/dist/providers/google-vertex-ai/api.js +330 -0
- package/dist/providers/google-vertex-ai/api.js.map +1 -0
- package/dist/providers/google-vertex-ai/cancelBatch.d.ts +6 -0
- package/dist/providers/google-vertex-ai/cancelBatch.js +9 -0
- package/dist/providers/google-vertex-ai/cancelBatch.js.map +1 -0
- package/dist/providers/google-vertex-ai/chatComplete.d.ts +50 -0
- package/dist/providers/google-vertex-ai/chatComplete.js +1512 -0
- package/dist/providers/google-vertex-ai/chatComplete.js.map +1 -0
- package/dist/providers/google-vertex-ai/createBatch.d.ts +186 -0
- package/dist/providers/google-vertex-ai/createBatch.js +101 -0
- package/dist/providers/google-vertex-ai/createBatch.js.map +1 -0
- package/dist/providers/google-vertex-ai/createFinetune.d.ts +44 -0
- package/dist/providers/google-vertex-ai/createFinetune.js +44 -0
- package/dist/providers/google-vertex-ai/createFinetune.js.map +1 -0
- package/dist/providers/google-vertex-ai/createSpeech.d.ts +16 -0
- package/dist/providers/google-vertex-ai/createSpeech.js +185 -0
- package/dist/providers/google-vertex-ai/createSpeech.js.map +1 -0
- package/dist/providers/google-vertex-ai/embed.d.ts +32 -0
- package/dist/providers/google-vertex-ai/embed.js +275 -0
- package/dist/providers/google-vertex-ai/embed.js.map +1 -0
- package/dist/providers/google-vertex-ai/getBatchOutput.d.ts +3 -0
- package/dist/providers/google-vertex-ai/getBatchOutput.js +160 -0
- package/dist/providers/google-vertex-ai/getBatchOutput.js.map +1 -0
- package/dist/providers/google-vertex-ai/imageEdit.d.ts +56 -0
- package/dist/providers/google-vertex-ai/imageEdit.js +559 -0
- package/dist/providers/google-vertex-ai/imageEdit.js.map +1 -0
- package/dist/providers/google-vertex-ai/imageGenerate.d.ts +75 -0
- package/dist/providers/google-vertex-ai/imageGenerate.js +384 -0
- package/dist/providers/google-vertex-ai/imageGenerate.js.map +1 -0
- package/dist/providers/google-vertex-ai/index.d.ts +20 -0
- package/dist/providers/google-vertex-ai/index.js +207 -0
- package/dist/providers/google-vertex-ai/index.js.map +1 -0
- package/dist/providers/google-vertex-ai/listBatches.d.ts +429 -0
- package/dist/providers/google-vertex-ai/listBatches.js +23 -0
- package/dist/providers/google-vertex-ai/listBatches.js.map +1 -0
- package/dist/providers/google-vertex-ai/listFiles.d.ts +2 -0
- package/dist/providers/google-vertex-ai/listFiles.js +16 -0
- package/dist/providers/google-vertex-ai/listFiles.js.map +1 -0
- package/dist/providers/google-vertex-ai/listFinetunes.d.ts +58 -0
- package/dist/providers/google-vertex-ai/listFinetunes.js +22 -0
- package/dist/providers/google-vertex-ai/listFinetunes.js.map +1 -0
- package/dist/providers/google-vertex-ai/messages.d.ts +5 -0
- package/dist/providers/google-vertex-ai/messages.js +39 -0
- package/dist/providers/google-vertex-ai/messages.js.map +1 -0
- package/dist/providers/google-vertex-ai/messagesCountTokens.d.ts +8 -0
- package/dist/providers/google-vertex-ai/messagesCountTokens.js +13 -0
- package/dist/providers/google-vertex-ai/messagesCountTokens.js.map +1 -0
- package/dist/providers/google-vertex-ai/retrieveBatch.d.ts +189 -0
- package/dist/providers/google-vertex-ai/retrieveBatch.js +14 -0
- package/dist/providers/google-vertex-ai/retrieveBatch.js.map +1 -0
- package/dist/providers/google-vertex-ai/retrieveFile.d.ts +3 -0
- package/dist/providers/google-vertex-ai/retrieveFile.js +52 -0
- package/dist/providers/google-vertex-ai/retrieveFile.js.map +1 -0
- package/dist/providers/google-vertex-ai/retrieveFileContent.d.ts +1 -0
- package/dist/providers/google-vertex-ai/retrieveFileContent.js +13 -0
- package/dist/providers/google-vertex-ai/retrieveFileContent.js.map +1 -0
- package/dist/providers/google-vertex-ai/retrieveFinetune.d.ts +19 -0
- package/dist/providers/google-vertex-ai/retrieveFinetune.js +8 -0
- package/dist/providers/google-vertex-ai/retrieveFinetune.js.map +1 -0
- package/dist/providers/google-vertex-ai/transformGenerationConfig.d.ts +14 -0
- package/dist/providers/google-vertex-ai/transformGenerationConfig.js +136 -0
- package/dist/providers/google-vertex-ai/transformGenerationConfig.js.map +1 -0
- package/dist/providers/google-vertex-ai/types.d.ts +364 -0
- package/dist/providers/google-vertex-ai/types.js +20 -0
- package/dist/providers/google-vertex-ai/types.js.map +1 -0
- package/dist/providers/google-vertex-ai/uploadFile.d.ts +7 -0
- package/dist/providers/google-vertex-ai/uploadFile.js +193 -0
- package/dist/providers/google-vertex-ai/uploadFile.js.map +1 -0
- package/dist/providers/google-vertex-ai/utils.d.ts +654 -0
- package/dist/providers/google-vertex-ai/utils.js +1151 -0
- package/dist/providers/google-vertex-ai/utils.js.map +1 -0
- package/dist/providers/google-vertex-ai/wifAuth.d.ts +2 -0
- package/dist/providers/google-vertex-ai/wifAuth.js +237 -0
- package/dist/providers/google-vertex-ai/wifAuth.js.map +1 -0
- package/dist/providers/groq/api.d.ts +3 -0
- package/dist/providers/groq/api.js +59 -0
- package/dist/providers/groq/api.js.map +1 -0
- package/dist/providers/groq/cancelBatch.d.ts +2 -0
- package/dist/providers/groq/cancelBatch.js +9 -0
- package/dist/providers/groq/cancelBatch.js.map +1 -0
- package/dist/providers/groq/chatComplete.d.ts +39 -0
- package/dist/providers/groq/chatComplete.js +142 -0
- package/dist/providers/groq/chatComplete.js.map +1 -0
- package/dist/providers/groq/complete.d.ts +13 -0
- package/dist/providers/groq/complete.js +213 -0
- package/dist/providers/groq/complete.js.map +1 -0
- package/dist/providers/groq/createBatch.d.ts +3 -0
- package/dist/providers/groq/createBatch.js +28 -0
- package/dist/providers/groq/createBatch.js.map +1 -0
- package/dist/providers/groq/createSpeech.d.ts +8 -0
- package/dist/providers/groq/createSpeech.js +37 -0
- package/dist/providers/groq/createSpeech.js.map +1 -0
- package/dist/providers/groq/createTranscription.d.ts +7 -0
- package/dist/providers/groq/createTranscription.js +31 -0
- package/dist/providers/groq/createTranscription.js.map +1 -0
- package/dist/providers/groq/createTranslation.d.ts +7 -0
- package/dist/providers/groq/createTranslation.js +31 -0
- package/dist/providers/groq/createTranslation.js.map +1 -0
- package/dist/providers/groq/deleteFile.d.ts +2 -0
- package/dist/providers/groq/deleteFile.js +9 -0
- package/dist/providers/groq/deleteFile.js.map +1 -0
- package/dist/providers/groq/index.d.ts +3 -0
- package/dist/providers/groq/index.js +70 -0
- package/dist/providers/groq/index.js.map +1 -0
- package/dist/providers/groq/listBatches.d.ts +2 -0
- package/dist/providers/groq/listBatches.js +9 -0
- package/dist/providers/groq/listBatches.js.map +1 -0
- package/dist/providers/groq/listFiles.d.ts +2 -0
- package/dist/providers/groq/listFiles.js +9 -0
- package/dist/providers/groq/listFiles.js.map +1 -0
- package/dist/providers/groq/retrieveBatch.d.ts +2 -0
- package/dist/providers/groq/retrieveBatch.js +9 -0
- package/dist/providers/groq/retrieveBatch.js.map +1 -0
- package/dist/providers/groq/retrieveFile.d.ts +2 -0
- package/dist/providers/groq/retrieveFile.js +9 -0
- package/dist/providers/groq/retrieveFile.js.map +1 -0
- package/dist/providers/groq/retrieveFileContent.d.ts +2 -0
- package/dist/providers/groq/retrieveFileContent.js +9 -0
- package/dist/providers/groq/retrieveFileContent.js.map +1 -0
- package/dist/providers/groq/uploadFile.d.ts +3 -0
- package/dist/providers/groq/uploadFile.js +12 -0
- package/dist/providers/groq/uploadFile.js.map +1 -0
- package/dist/providers/groq/utils.d.ts +2 -0
- package/dist/providers/groq/utils.js +7 -0
- package/dist/providers/groq/utils.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +88 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/microsoft-foundry/api.d.ts +11 -0
- package/dist/providers/microsoft-foundry/api.js +270 -0
- package/dist/providers/microsoft-foundry/api.js.map +1 -0
- package/dist/providers/microsoft-foundry/createBatch.d.ts +10 -0
- package/dist/providers/microsoft-foundry/createBatch.js +40 -0
- package/dist/providers/microsoft-foundry/createBatch.js.map +1 -0
- package/dist/providers/microsoft-foundry/createTranscription.d.ts +3 -0
- package/dist/providers/microsoft-foundry/createTranscription.js +23 -0
- package/dist/providers/microsoft-foundry/createTranscription.js.map +1 -0
- package/dist/providers/microsoft-foundry/createTranslation.d.ts +3 -0
- package/dist/providers/microsoft-foundry/createTranslation.js +23 -0
- package/dist/providers/microsoft-foundry/createTranslation.js.map +1 -0
- package/dist/providers/microsoft-foundry/getBatchOutput.d.ts +3 -0
- package/dist/providers/microsoft-foundry/getBatchOutput.js +106 -0
- package/dist/providers/microsoft-foundry/getBatchOutput.js.map +1 -0
- package/dist/providers/microsoft-foundry/imageEdit.d.ts +3 -0
- package/dist/providers/microsoft-foundry/imageEdit.js +28 -0
- package/dist/providers/microsoft-foundry/imageEdit.js.map +1 -0
- package/dist/providers/microsoft-foundry/index.d.ts +3 -0
- package/dist/providers/microsoft-foundry/index.js +142 -0
- package/dist/providers/microsoft-foundry/index.js.map +1 -0
- package/dist/providers/microsoft-foundry/messages.d.ts +5 -0
- package/dist/providers/microsoft-foundry/messages.js +16 -0
- package/dist/providers/microsoft-foundry/messages.js.map +1 -0
- package/dist/providers/microsoft-foundry/rerank.d.ts +30 -0
- package/dist/providers/microsoft-foundry/rerank.js +53 -0
- package/dist/providers/microsoft-foundry/rerank.js.map +1 -0
- package/dist/providers/microsoft-foundry/responseTransforms.d.ts +2 -0
- package/dist/providers/microsoft-foundry/responseTransforms.js +4 -0
- package/dist/providers/microsoft-foundry/responseTransforms.js.map +1 -0
- package/dist/providers/mistral-ai/api.d.ts +3 -0
- package/dist/providers/mistral-ai/api.js +23 -0
- package/dist/providers/mistral-ai/api.js.map +1 -0
- package/dist/providers/mistral-ai/chatComplete.d.ts +48 -0
- package/dist/providers/mistral-ai/chatComplete.js +257 -0
- package/dist/providers/mistral-ai/chatComplete.js.map +1 -0
- package/dist/providers/mistral-ai/embed.d.ts +8 -0
- package/dist/providers/mistral-ai/embed.js +52 -0
- package/dist/providers/mistral-ai/embed.js.map +1 -0
- package/dist/providers/mistral-ai/index.d.ts +8 -0
- package/dist/providers/mistral-ai/index.js +15 -0
- package/dist/providers/mistral-ai/index.js.map +1 -0
- package/dist/providers/mistral-ai/types.d.ts +7 -0
- package/dist/providers/mistral-ai/types.js +9 -0
- package/dist/providers/mistral-ai/types.js.map +1 -0
- package/dist/providers/nomic/api.d.ts +3 -0
- package/dist/providers/nomic/api.js +18 -0
- package/dist/providers/nomic/api.js.map +1 -0
- package/dist/providers/nomic/embed.d.ts +24 -0
- package/dist/providers/nomic/embed.js +70 -0
- package/dist/providers/nomic/embed.js.map +1 -0
- package/dist/providers/nomic/index.d.ts +8 -0
- package/dist/providers/nomic/index.js +11 -0
- package/dist/providers/nomic/index.js.map +1 -0
- package/dist/providers/ollama/api.d.ts +3 -0
- package/dist/providers/ollama/api.js +31 -0
- package/dist/providers/ollama/api.js.map +1 -0
- package/dist/providers/ollama/chatComplete.d.ts +22 -0
- package/dist/providers/ollama/chatComplete.js +110 -0
- package/dist/providers/ollama/chatComplete.js.map +1 -0
- package/dist/providers/ollama/embed.d.ts +11 -0
- package/dist/providers/ollama/embed.js +43 -0
- package/dist/providers/ollama/embed.js.map +1 -0
- package/dist/providers/ollama/index.d.ts +8 -0
- package/dist/providers/ollama/index.js +15 -0
- package/dist/providers/ollama/index.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/eligibility.d.ts +62 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/eligibility.js +171 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/eligibility.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/index.d.ts +10 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/index.js +10 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/index.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/requestTransform.d.ts +32 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/requestTransform.js +257 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/requestTransform.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/responseTransform.d.ts +13 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/responseTransform.js +116 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/responseTransform.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/streamTransform.d.ts +34 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/streamTransform.js +285 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/streamTransform.js.map +1 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/types.d.ts +19 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/types.js +2 -0
- package/dist/providers/open-ai-base/chatCompleteViaResponses/types.js.map +1 -0
- package/dist/providers/open-ai-base/constants.d.ts +38 -0
- package/dist/providers/open-ai-base/constants.js +347 -0
- package/dist/providers/open-ai-base/constants.js.map +1 -0
- package/dist/providers/open-ai-base/createModelResponse.d.ts +9 -0
- package/dist/providers/open-ai-base/createModelResponse.js +172 -0
- package/dist/providers/open-ai-base/createModelResponse.js.map +1 -0
- package/dist/providers/open-ai-base/cursor.utils.d.ts +42 -0
- package/dist/providers/open-ai-base/cursor.utils.js +131 -0
- package/dist/providers/open-ai-base/cursor.utils.js.map +1 -0
- package/dist/providers/open-ai-base/helpers.d.ts +41 -0
- package/dist/providers/open-ai-base/helpers.js +356 -0
- package/dist/providers/open-ai-base/helpers.js.map +1 -0
- package/dist/providers/open-ai-base/index.d.ts +67 -0
- package/dist/providers/open-ai-base/index.js +550 -0
- package/dist/providers/open-ai-base/index.js.map +1 -0
- package/dist/providers/openai/api.d.ts +3 -0
- package/dist/providers/openai/api.js +141 -0
- package/dist/providers/openai/api.js.map +1 -0
- package/dist/providers/openai/cancelBatch.d.ts +2 -0
- package/dist/providers/openai/cancelBatch.js +14 -0
- package/dist/providers/openai/cancelBatch.js.map +1 -0
- package/dist/providers/openai/chatComplete.d.ts +14 -0
- package/dist/providers/openai/chatComplete.js +402 -0
- package/dist/providers/openai/chatComplete.js.map +1 -0
- package/dist/providers/openai/complete.d.ts +14 -0
- package/dist/providers/openai/complete.js +144 -0
- package/dist/providers/openai/complete.js.map +1 -0
- package/dist/providers/openai/createBatch.d.ts +3 -0
- package/dist/providers/openai/createBatch.js +33 -0
- package/dist/providers/openai/createBatch.js.map +1 -0
- package/dist/providers/openai/createFinetune.d.ts +3 -0
- package/dist/providers/openai/createFinetune.js +48 -0
- package/dist/providers/openai/createFinetune.js.map +1 -0
- package/dist/providers/openai/createModelResponseCompact.d.ts +42 -0
- package/dist/providers/openai/createModelResponseCompact.js +25 -0
- package/dist/providers/openai/createModelResponseCompact.js.map +1 -0
- package/dist/providers/openai/createSpeech.d.ts +3 -0
- package/dist/providers/openai/createSpeech.js +40 -0
- package/dist/providers/openai/createSpeech.js.map +1 -0
- package/dist/providers/openai/createTranscription.d.ts +8 -0
- package/dist/providers/openai/createTranscription.js +44 -0
- package/dist/providers/openai/createTranscription.js.map +1 -0
- package/dist/providers/openai/createTranslation.d.ts +8 -0
- package/dist/providers/openai/createTranslation.js +41 -0
- package/dist/providers/openai/createTranslation.js.map +1 -0
- package/dist/providers/openai/deleteFile.d.ts +2 -0
- package/dist/providers/openai/deleteFile.js +14 -0
- package/dist/providers/openai/deleteFile.js.map +1 -0
- package/dist/providers/openai/embed.d.ts +7 -0
- package/dist/providers/openai/embed.js +35 -0
- package/dist/providers/openai/embed.js.map +1 -0
- package/dist/providers/openai/getBatchOutput.d.ts +3 -0
- package/dist/providers/openai/getBatchOutput.js +55 -0
- package/dist/providers/openai/getBatchOutput.js.map +1 -0
- package/dist/providers/openai/imageEdit.d.ts +3 -0
- package/dist/providers/openai/imageEdit.js +34 -0
- package/dist/providers/openai/imageEdit.js.map +1 -0
- package/dist/providers/openai/imageGenerate.d.ts +12 -0
- package/dist/providers/openai/imageGenerate.js +45 -0
- package/dist/providers/openai/imageGenerate.js.map +1 -0
- package/dist/providers/openai/imageVariation.d.ts +3 -0
- package/dist/providers/openai/imageVariation.js +29 -0
- package/dist/providers/openai/imageVariation.js.map +1 -0
- package/dist/providers/openai/index.d.ts +6 -0
- package/dist/providers/openai/index.js +146 -0
- package/dist/providers/openai/index.js.map +1 -0
- package/dist/providers/openai/listBatches.d.ts +2 -0
- package/dist/providers/openai/listBatches.js +14 -0
- package/dist/providers/openai/listBatches.js.map +1 -0
- package/dist/providers/openai/listFiles.d.ts +2 -0
- package/dist/providers/openai/listFiles.js +14 -0
- package/dist/providers/openai/listFiles.js.map +1 -0
- package/dist/providers/openai/moderation.d.ts +2 -0
- package/dist/providers/openai/moderation.js +14 -0
- package/dist/providers/openai/moderation.js.map +1 -0
- package/dist/providers/openai/retrieveBatch.d.ts +2 -0
- package/dist/providers/openai/retrieveBatch.js +9 -0
- package/dist/providers/openai/retrieveBatch.js.map +1 -0
- package/dist/providers/openai/retrieveFileContent.d.ts +2 -0
- package/dist/providers/openai/retrieveFileContent.js +9 -0
- package/dist/providers/openai/retrieveFileContent.js.map +1 -0
- package/dist/providers/openai/uploadFile.d.ts +3 -0
- package/dist/providers/openai/uploadFile.js +17 -0
- package/dist/providers/openai/uploadFile.js.map +1 -0
- package/dist/providers/openai/utils.d.ts +7 -0
- package/dist/providers/openai/utils.js +7 -0
- package/dist/providers/openai/utils.js.map +1 -0
- package/dist/providers/openai-like/api.d.ts +7 -0
- package/dist/providers/openai-like/api.js +40 -0
- package/dist/providers/openai-like/api.js.map +1 -0
- package/dist/providers/openai-like/chatComplete.d.ts +41 -0
- package/dist/providers/openai-like/chatComplete.js +91 -0
- package/dist/providers/openai-like/chatComplete.js.map +1 -0
- package/dist/providers/openai-like/embed.d.ts +9 -0
- package/dist/providers/openai-like/embed.js +23 -0
- package/dist/providers/openai-like/embed.js.map +1 -0
- package/dist/providers/openai-like/index.d.ts +16 -0
- package/dist/providers/openai-like/index.js +35 -0
- package/dist/providers/openai-like/index.js.map +1 -0
- package/dist/providers/openai-like/utils.d.ts +16 -0
- package/dist/providers/openai-like/utils.js +16 -0
- package/dist/providers/openai-like/utils.js.map +1 -0
- package/dist/providers/openrouter/api.d.ts +3 -0
- package/dist/providers/openrouter/api.js +30 -0
- package/dist/providers/openrouter/api.js.map +1 -0
- package/dist/providers/openrouter/chatComplete.d.ts +51 -0
- package/dist/providers/openrouter/chatComplete.js +251 -0
- package/dist/providers/openrouter/chatComplete.js.map +1 -0
- package/dist/providers/openrouter/index.d.ts +3 -0
- package/dist/providers/openrouter/index.js +20 -0
- package/dist/providers/openrouter/index.js.map +1 -0
- package/dist/providers/openrouter/utils.d.ts +20 -0
- package/dist/providers/openrouter/utils.js +15 -0
- package/dist/providers/openrouter/utils.js.map +1 -0
- package/dist/providers/palm/api.d.ts +3 -0
- package/dist/providers/palm/api.js +26 -0
- package/dist/providers/palm/api.js.map +1 -0
- package/dist/providers/palm/chatComplete.d.ts +5 -0
- package/dist/providers/palm/chatComplete.js +91 -0
- package/dist/providers/palm/chatComplete.js.map +1 -0
- package/dist/providers/palm/complete.d.ts +5 -0
- package/dist/providers/palm/complete.js +82 -0
- package/dist/providers/palm/complete.js.map +1 -0
- package/dist/providers/palm/embed.d.ts +12 -0
- package/dist/providers/palm/embed.js +46 -0
- package/dist/providers/palm/embed.js.map +1 -0
- package/dist/providers/palm/index.d.ts +8 -0
- package/dist/providers/palm/index.js +17 -0
- package/dist/providers/palm/index.js.map +1 -0
- package/dist/providers/perplexity-ai/api.d.ts +3 -0
- package/dist/providers/perplexity-ai/api.js +20 -0
- package/dist/providers/perplexity-ai/api.js.map +1 -0
- package/dist/providers/perplexity-ai/chatCompleteViaResponses.d.ts +8 -0
- package/dist/providers/perplexity-ai/chatCompleteViaResponses.js +152 -0
- package/dist/providers/perplexity-ai/chatCompleteViaResponses.js.map +1 -0
- package/dist/providers/perplexity-ai/createModelResponse.d.ts +6 -0
- package/dist/providers/perplexity-ai/createModelResponse.js +51 -0
- package/dist/providers/perplexity-ai/createModelResponse.js.map +1 -0
- package/dist/providers/perplexity-ai/decision.d.ts +29 -0
- package/dist/providers/perplexity-ai/decision.js +47 -0
- package/dist/providers/perplexity-ai/decision.js.map +1 -0
- package/dist/providers/perplexity-ai/index.d.ts +3 -0
- package/dist/providers/perplexity-ai/index.js +23 -0
- package/dist/providers/perplexity-ai/index.js.map +1 -0
- package/dist/providers/requestHandlerApiArgs.d.ts +12 -0
- package/dist/providers/requestHandlerApiArgs.js +19 -0
- package/dist/providers/requestHandlerApiArgs.js.map +1 -0
- package/dist/providers/sagemaker/api.d.ts +3 -0
- package/dist/providers/sagemaker/api.js +86 -0
- package/dist/providers/sagemaker/api.js.map +1 -0
- package/dist/providers/sagemaker/chatComplete.d.ts +10 -0
- package/dist/providers/sagemaker/chatComplete.js +160 -0
- package/dist/providers/sagemaker/chatComplete.js.map +1 -0
- package/dist/providers/sagemaker/embed.d.ts +10 -0
- package/dist/providers/sagemaker/embed.js +55 -0
- package/dist/providers/sagemaker/embed.js.map +1 -0
- package/dist/providers/sagemaker/index.d.ts +3 -0
- package/dist/providers/sagemaker/index.js +30 -0
- package/dist/providers/sagemaker/index.js.map +1 -0
- package/dist/providers/sagemaker/utils.d.ts +3 -0
- package/dist/providers/sagemaker/utils.js +11 -0
- package/dist/providers/sagemaker/utils.js.map +1 -0
- package/dist/providers/sambanova/api.d.ts +3 -0
- package/dist/providers/sambanova/api.js +18 -0
- package/dist/providers/sambanova/api.js.map +1 -0
- package/dist/providers/sambanova/chatComplete.d.ts +31 -0
- package/dist/providers/sambanova/chatComplete.js +54 -0
- package/dist/providers/sambanova/chatComplete.js.map +1 -0
- package/dist/providers/sambanova/index.d.ts +3 -0
- package/dist/providers/sambanova/index.js +72 -0
- package/dist/providers/sambanova/index.js.map +1 -0
- package/dist/providers/segmind/api.d.ts +7 -0
- package/dist/providers/segmind/api.js +18 -0
- package/dist/providers/segmind/api.js.map +1 -0
- package/dist/providers/segmind/imageGenerate.d.ts +13 -0
- package/dist/providers/segmind/imageGenerate.js +130 -0
- package/dist/providers/segmind/imageGenerate.js.map +1 -0
- package/dist/providers/segmind/index.d.ts +8 -0
- package/dist/providers/segmind/index.js +11 -0
- package/dist/providers/segmind/index.js.map +1 -0
- package/dist/providers/shared/responseFormatUtils.d.ts +100 -0
- package/dist/providers/shared/responseFormatUtils.js +495 -0
- package/dist/providers/shared/responseFormatUtils.js.map +1 -0
- package/dist/providers/smallest-ai/api.d.ts +10 -0
- package/dist/providers/smallest-ai/api.js +24 -0
- package/dist/providers/smallest-ai/api.js.map +1 -0
- package/dist/providers/smallest-ai/index.d.ts +3 -0
- package/dist/providers/smallest-ai/index.js +6 -0
- package/dist/providers/smallest-ai/index.js.map +1 -0
- package/dist/providers/stability-ai/api.d.ts +7 -0
- package/dist/providers/stability-ai/api.js +52 -0
- package/dist/providers/stability-ai/api.js.map +1 -0
- package/dist/providers/stability-ai/constants.d.ts +6 -0
- package/dist/providers/stability-ai/constants.js +7 -0
- package/dist/providers/stability-ai/constants.js.map +1 -0
- package/dist/providers/stability-ai/imageGenerate.d.ts +17 -0
- package/dist/providers/stability-ai/imageGenerate.js +77 -0
- package/dist/providers/stability-ai/imageGenerate.js.map +1 -0
- package/dist/providers/stability-ai/imageGenerateV2.d.ts +18 -0
- package/dist/providers/stability-ai/imageGenerateV2.js +127 -0
- package/dist/providers/stability-ai/imageGenerateV2.js.map +1 -0
- package/dist/providers/stability-ai/index.d.ts +8 -0
- package/dist/providers/stability-ai/index.js +26 -0
- package/dist/providers/stability-ai/index.js.map +1 -0
- package/dist/providers/stability-ai/utils.d.ts +1 -0
- package/dist/providers/stability-ai/utils.js +12 -0
- package/dist/providers/stability-ai/utils.js.map +1 -0
- package/dist/providers/together-ai/api.d.ts +3 -0
- package/dist/providers/together-ai/api.js +22 -0
- package/dist/providers/together-ai/api.js.map +1 -0
- package/dist/providers/together-ai/chatComplete.d.ts +41 -0
- package/dist/providers/together-ai/chatComplete.js +161 -0
- package/dist/providers/together-ai/chatComplete.js.map +1 -0
- package/dist/providers/together-ai/complete.d.ts +13 -0
- package/dist/providers/together-ai/complete.js +100 -0
- package/dist/providers/together-ai/complete.js.map +1 -0
- package/dist/providers/together-ai/embed.d.ts +8 -0
- package/dist/providers/together-ai/embed.js +50 -0
- package/dist/providers/together-ai/embed.js.map +1 -0
- package/dist/providers/together-ai/index.d.ts +8 -0
- package/dist/providers/together-ai/index.js +19 -0
- package/dist/providers/together-ai/index.js.map +1 -0
- package/dist/providers/together-ai/types.d.ts +7 -0
- package/dist/providers/together-ai/types.js +9 -0
- package/dist/providers/together-ai/types.js.map +1 -0
- package/dist/providers/truefoundry-models/api.d.ts +3 -0
- package/dist/providers/truefoundry-models/api.js +29 -0
- package/dist/providers/truefoundry-models/api.js.map +1 -0
- package/dist/providers/truefoundry-models/index.d.ts +3 -0
- package/dist/providers/truefoundry-models/index.js +27 -0
- package/dist/providers/truefoundry-models/index.js.map +1 -0
- package/dist/providers/types.d.ts +459 -0
- package/dist/providers/types.js +9 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/typesafe/api.d.ts +5 -0
- package/dist/providers/typesafe/api.js +55 -0
- package/dist/providers/typesafe/api.js.map +1 -0
- package/dist/providers/typesafe/decision.d.ts +44 -0
- package/dist/providers/typesafe/decision.js +105 -0
- package/dist/providers/typesafe/decision.js.map +1 -0
- package/dist/providers/typesafe/index.d.ts +3 -0
- package/dist/providers/typesafe/index.js +23 -0
- package/dist/providers/typesafe/index.js.map +1 -0
- package/dist/providers/utils/cacheControlUtils.d.ts +40 -0
- package/dist/providers/utils/cacheControlUtils.js +196 -0
- package/dist/providers/utils/cacheControlUtils.js.map +1 -0
- package/dist/providers/utils/fileUtils.d.ts +18 -0
- package/dist/providers/utils/fileUtils.js +46 -0
- package/dist/providers/utils/fileUtils.js.map +1 -0
- package/dist/providers/utils/finishReasonMap.d.ts +4 -0
- package/dist/providers/utils/finishReasonMap.js +83 -0
- package/dist/providers/utils/finishReasonMap.js.map +1 -0
- package/dist/providers/utils/toolUtils.d.ts +10 -0
- package/dist/providers/utils/toolUtils.js +35 -0
- package/dist/providers/utils/toolUtils.js.map +1 -0
- package/dist/providers/utils.d.ts +63 -0
- package/dist/providers/utils.js +210 -0
- package/dist/providers/utils.js.map +1 -0
- package/dist/providers/wafer/api.d.ts +2 -0
- package/dist/providers/wafer/api.js +26 -0
- package/dist/providers/wafer/api.js.map +1 -0
- package/dist/providers/wafer/index.d.ts +3 -0
- package/dist/providers/wafer/index.js +16 -0
- package/dist/providers/wafer/index.js.map +1 -0
- package/dist/providers/xai/index.d.ts +3 -0
- package/dist/providers/xai/index.js +21 -0
- package/dist/providers/xai/index.js.map +1 -0
- package/dist/requestContext.d.ts +5 -0
- package/dist/requestContext.js +19 -0
- package/dist/requestContext.js.map +1 -0
- package/dist/runtime/ambientCredentials.d.ts +14 -0
- package/dist/runtime/ambientCredentials.js +22 -0
- package/dist/runtime/ambientCredentials.js.map +1 -0
- package/dist/sdk.d.ts +66 -0
- package/dist/sdk.js +98 -0
- package/dist/sdk.js.map +1 -0
- package/dist/services/buildExecutionReport.d.ts +48 -0
- package/dist/services/buildExecutionReport.js +206 -0
- package/dist/services/buildExecutionReport.js.map +1 -0
- package/dist/services/buildFetchInit.d.ts +7 -0
- package/dist/services/buildFetchInit.js +70 -0
- package/dist/services/buildFetchInit.js.map +1 -0
- package/dist/services/createProviderRequest.d.ts +25 -0
- package/dist/services/createProviderRequest.js +276 -0
- package/dist/services/createProviderRequest.js.map +1 -0
- package/dist/services/execute.d.ts +11 -0
- package/dist/services/execute.js +204 -0
- package/dist/services/execute.js.map +1 -0
- package/dist/services/handleProviderResponse.d.ts +42 -0
- package/dist/services/handleProviderResponse.js +436 -0
- package/dist/services/handleProviderResponse.js.map +1 -0
- package/dist/services/transformToProviderRequest.d.ts +29 -0
- package/dist/services/transformToProviderRequest.js +268 -0
- package/dist/services/transformToProviderRequest.js.map +1 -0
- package/dist/stream/firstChunkGate.d.ts +31 -0
- package/dist/stream/firstChunkGate.js +86 -0
- package/dist/stream/firstChunkGate.js.map +1 -0
- package/dist/stream/firstChunkGateValidators.d.ts +23 -0
- package/dist/stream/firstChunkGateValidators.js +174 -0
- package/dist/stream/firstChunkGateValidators.js.map +1 -0
- package/dist/stream/index.d.ts +19 -0
- package/dist/stream/index.js +13 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/internalMetadataSse.d.ts +22 -0
- package/dist/stream/internalMetadataSse.js +60 -0
- package/dist/stream/internalMetadataSse.js.map +1 -0
- package/dist/stream/pumpProviderAwsEventStream.d.ts +32 -0
- package/dist/stream/pumpProviderAwsEventStream.js +103 -0
- package/dist/stream/pumpProviderAwsEventStream.js.map +1 -0
- package/dist/stream/pumpProviderSseStream.d.ts +11 -0
- package/dist/stream/pumpProviderSseStream.js +154 -0
- package/dist/stream/pumpProviderSseStream.js.map +1 -0
- package/dist/stream/readAwsEventFrames.d.ts +12 -0
- package/dist/stream/readAwsEventFrames.js +113 -0
- package/dist/stream/readAwsEventFrames.js.map +1 -0
- package/dist/stream/readSseFrames.d.ts +6 -0
- package/dist/stream/readSseFrames.js +80 -0
- package/dist/stream/readSseFrames.js.map +1 -0
- package/dist/stream/resolvePumpAbortSignal.d.ts +16 -0
- package/dist/stream/resolvePumpAbortSignal.js +30 -0
- package/dist/stream/resolvePumpAbortSignal.js.map +1 -0
- package/dist/stream/resolveStreamEndReason.d.ts +16 -0
- package/dist/stream/resolveStreamEndReason.js +89 -0
- package/dist/stream/resolveStreamEndReason.js.map +1 -0
- package/dist/stream/shouldReadAwsEventStream.d.ts +17 -0
- package/dist/stream/shouldReadAwsEventStream.js +29 -0
- package/dist/stream/shouldReadAwsEventStream.js.map +1 -0
- package/dist/stream/shouldRequireAzureStreamSleep.d.ts +8 -0
- package/dist/stream/shouldRequireAzureStreamSleep.js +12 -0
- package/dist/stream/shouldRequireAzureStreamSleep.js.map +1 -0
- package/dist/stream/splitPatterns.d.ts +20 -0
- package/dist/stream/splitPatterns.js +33 -0
- package/dist/stream/splitPatterns.js.map +1 -0
- package/dist/stream/types.d.ts +91 -0
- package/dist/stream/types.js +2 -0
- package/dist/stream/types.js.map +1 -0
- package/dist/tfy-providers/custom/api.d.ts +3 -0
- package/dist/tfy-providers/custom/api.js +125 -0
- package/dist/tfy-providers/custom/api.js.map +1 -0
- package/dist/tfy-providers/custom/cohere-rerank-v2/rerank.d.ts +30 -0
- package/dist/tfy-providers/custom/cohere-rerank-v2/rerank.js +30 -0
- package/dist/tfy-providers/custom/cohere-rerank-v2/rerank.js.map +1 -0
- package/dist/tfy-providers/custom/index.d.ts +14 -0
- package/dist/tfy-providers/custom/index.js +85 -0
- package/dist/tfy-providers/custom/index.js.map +1 -0
- package/dist/tfy-providers/custom/infinity/embed.d.ts +10 -0
- package/dist/tfy-providers/custom/infinity/embed.js +24 -0
- package/dist/tfy-providers/custom/infinity/embed.js.map +1 -0
- package/dist/tfy-providers/custom/infinity/rerank.d.ts +27 -0
- package/dist/tfy-providers/custom/infinity/rerank.js +28 -0
- package/dist/tfy-providers/custom/infinity/rerank.js.map +1 -0
- package/dist/tfy-providers/custom/nemo-retriever/embed.d.ts +10 -0
- package/dist/tfy-providers/custom/nemo-retriever/embed.js +28 -0
- package/dist/tfy-providers/custom/nemo-retriever/embed.js.map +1 -0
- package/dist/tfy-providers/custom/nemo-retriever/rerank.d.ts +45 -0
- package/dist/tfy-providers/custom/nemo-retriever/rerank.js +53 -0
- package/dist/tfy-providers/custom/nemo-retriever/rerank.js.map +1 -0
- package/dist/tfy-providers/custom/openai-compatible/chatComplete.d.ts +12 -0
- package/dist/tfy-providers/custom/openai-compatible/chatComplete.js +109 -0
- package/dist/tfy-providers/custom/openai-compatible/chatComplete.js.map +1 -0
- package/dist/tfy-providers/custom/openai-compatible/complete.d.ts +12 -0
- package/dist/tfy-providers/custom/openai-compatible/complete.js +82 -0
- package/dist/tfy-providers/custom/openai-compatible/complete.js.map +1 -0
- package/dist/tfy-providers/custom/openai-compatible/embed.d.ts +10 -0
- package/dist/tfy-providers/custom/openai-compatible/embed.js +28 -0
- package/dist/tfy-providers/custom/openai-compatible/embed.js.map +1 -0
- package/dist/tfy-providers/custom/tei/embed.d.ts +10 -0
- package/dist/tfy-providers/custom/tei/embed.js +24 -0
- package/dist/tfy-providers/custom/tei/embed.js.map +1 -0
- package/dist/tfy-providers/custom/vllm-openai/chatComplete.d.ts +27 -0
- package/dist/tfy-providers/custom/vllm-openai/chatComplete.js +158 -0
- package/dist/tfy-providers/custom/vllm-openai/chatComplete.js.map +1 -0
- package/dist/tfy-providers/custom/vllm-openai/complete.d.ts +12 -0
- package/dist/tfy-providers/custom/vllm-openai/complete.js +82 -0
- package/dist/tfy-providers/custom/vllm-openai/complete.js.map +1 -0
- package/dist/tracing/constants.d.ts +0 -0
- package/dist/tracing/constants.js +2 -0
- package/dist/tracing/constants.js.map +1 -0
- package/dist/types/MessagesRequest.d.ts +459 -0
- package/dist/types/MessagesRequest.js +2 -0
- package/dist/types/MessagesRequest.js.map +1 -0
- package/dist/types/MessagesStreamResponse.d.ts +64 -0
- package/dist/types/MessagesStreamResponse.js +2 -0
- package/dist/types/MessagesStreamResponse.js.map +1 -0
- package/dist/types/cache.d.ts +12 -0
- package/dist/types/cache.js +2 -0
- package/dist/types/cache.js.map +1 -0
- package/dist/types/contracts.d.ts +161 -0
- package/dist/types/contracts.js +2 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/embedRequestBody.d.ts +59 -0
- package/dist/types/embedRequestBody.js +2 -0
- package/dist/types/embedRequestBody.js.map +1 -0
- package/dist/types/executionReport.d.ts +223 -0
- package/dist/types/executionReport.js +2 -0
- package/dist/types/executionReport.js.map +1 -0
- package/dist/types/headers.d.ts +42 -0
- package/dist/types/headers.js +8 -0
- package/dist/types/headers.js.map +1 -0
- package/dist/types/inputList.d.ts +145 -0
- package/dist/types/inputList.js +8 -0
- package/dist/types/inputList.js.map +1 -0
- package/dist/types/messagesResponse.d.ts +204 -0
- package/dist/types/messagesResponse.js +10 -0
- package/dist/types/messagesResponse.js.map +1 -0
- package/dist/types/modelConfig.d.ts +41 -0
- package/dist/types/modelConfig.js +2 -0
- package/dist/types/modelConfig.js.map +1 -0
- package/dist/types/modelResponses.d.ts +2174 -0
- package/dist/types/modelResponses.js +8 -0
- package/dist/types/modelResponses.js.map +1 -0
- package/dist/types/options.d.ts +122 -0
- package/dist/types/options.js +2 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/requestBody.d.ts +586 -0
- package/dist/types/requestBody.js +25 -0
- package/dist/types/requestBody.js.map +1 -0
- package/dist/types/responseBody.d.ts +51 -0
- package/dist/types/responseBody.js +2 -0
- package/dist/types/responseBody.js.map +1 -0
- package/dist/types/shared.d.ts +116 -0
- package/dist/types/shared.js +2 -0
- package/dist/types/shared.js.map +1 -0
- package/dist/utils/abortSignals.d.ts +4 -0
- package/dist/utils/abortSignals.js +7 -0
- package/dist/utils/abortSignals.js.map +1 -0
- package/dist/utils/abortUtils.d.ts +5 -0
- package/dist/utils/abortUtils.js +20 -0
- package/dist/utils/abortUtils.js.map +1 -0
- package/dist/utils/audioUtils.d.ts +5 -0
- package/dist/utils/audioUtils.js +50 -0
- package/dist/utils/audioUtils.js.map +1 -0
- package/dist/utils/awsEventStreamEncoder.d.ts +12 -0
- package/dist/utils/awsEventStreamEncoder.js +49 -0
- package/dist/utils/awsEventStreamEncoder.js.map +1 -0
- package/dist/utils/awsSigV4.d.ts +2 -0
- package/dist/utils/awsSigV4.js +49 -0
- package/dist/utils/awsSigV4.js.map +1 -0
- package/dist/utils/azureEntraAuth.d.ts +10 -0
- package/dist/utils/azureEntraAuth.js +80 -0
- package/dist/utils/azureEntraAuth.js.map +1 -0
- package/dist/utils/billedUsage.d.ts +18 -0
- package/dist/utils/billedUsage.js +89 -0
- package/dist/utils/billedUsage.js.map +1 -0
- package/dist/utils/deriveProviderHeaderOptions.d.ts +9 -0
- package/dist/utils/deriveProviderHeaderOptions.js +141 -0
- package/dist/utils/deriveProviderHeaderOptions.js.map +1 -0
- package/dist/utils/errorHandlingUtils.d.ts +93 -0
- package/dist/utils/errorHandlingUtils.js +134 -0
- package/dist/utils/errorHandlingUtils.js.map +1 -0
- package/dist/utils/ignoreWithLog.d.ts +3 -0
- package/dist/utils/ignoreWithLog.js +12 -0
- package/dist/utils/ignoreWithLog.js.map +1 -0
- package/dist/utils/isStreamingEnabled.d.ts +14 -0
- package/dist/utils/isStreamingEnabled.js +14 -0
- package/dist/utils/isStreamingEnabled.js.map +1 -0
- package/dist/utils/jsonValue.d.ts +5 -0
- package/dist/utils/jsonValue.js +15 -0
- package/dist/utils/jsonValue.js.map +1 -0
- package/dist/utils/jwtUtils.d.ts +30 -0
- package/dist/utils/jwtUtils.js +102 -0
- package/dist/utils/jwtUtils.js.map +1 -0
- package/dist/utils/k8sTokenRequest.d.ts +1 -0
- package/dist/utils/k8sTokenRequest.js +45 -0
- package/dist/utils/k8sTokenRequest.js.map +1 -0
- package/dist/utils/memoryOptimizationUtils.d.ts +19 -0
- package/dist/utils/memoryOptimizationUtils.js +38 -0
- package/dist/utils/memoryOptimizationUtils.js.map +1 -0
- package/dist/utils/misc.d.ts +3 -0
- package/dist/utils/misc.js +24 -0
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/modelParamUtils.d.ts +91 -0
- package/dist/utils/modelParamUtils.js +387 -0
- package/dist/utils/modelParamUtils.js.map +1 -0
- package/dist/utils/providerConfigTransform.d.ts +24 -0
- package/dist/utils/providerConfigTransform.js +111 -0
- package/dist/utils/providerConfigTransform.js.map +1 -0
- package/dist/utils/providerReportedCost.d.ts +2 -0
- package/dist/utils/providerReportedCost.js +15 -0
- package/dist/utils/providerReportedCost.js.map +1 -0
- package/dist/utils/reasoningUtils.d.ts +28 -0
- package/dist/utils/reasoningUtils.js +148 -0
- package/dist/utils/reasoningUtils.js.map +1 -0
- package/dist/utils/sdkRequestUrl.d.ts +7 -0
- package/dist/utils/sdkRequestUrl.js +9 -0
- package/dist/utils/sdkRequestUrl.js.map +1 -0
- package/dist/utils/sseUtils.d.ts +48 -0
- package/dist/utils/sseUtils.js +152 -0
- package/dist/utils/sseUtils.js.map +1 -0
- package/dist/utils/systemMessageUtils.d.ts +7 -0
- package/dist/utils/systemMessageUtils.js +67 -0
- package/dist/utils/systemMessageUtils.js.map +1 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/package.json +59 -4
|
@@ -0,0 +1,1512 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ================================
|
|
3
|
+
* Inherited upstream file
|
|
4
|
+
* But needs some custom changes for TFY
|
|
5
|
+
* 1. Use tfy- prefix for ids instead of the legacy prefix
|
|
6
|
+
* 2. Use const instead of let for variables that are not reassigned (for linting)
|
|
7
|
+
* 3. Remove unused vars for linting
|
|
8
|
+
* 4. Add passedMimeType to the inlineData if present, otherwise default to image/jpeg
|
|
9
|
+
* 5. Remove stream_options from the request body
|
|
10
|
+
* 6. Add Qwen Chat Complete Config
|
|
11
|
+
* 7. Add Qwen Chat Complete Stream and Non-Stream Transform
|
|
12
|
+
* 8. Apply transformGeminiToolParameters on tools (inline $defs/$ref for Vertex)
|
|
13
|
+
* ================================
|
|
14
|
+
*/
|
|
15
|
+
// Docs for REST API
|
|
16
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-multimodal-prompts#gemini-send-multimodal-samples-drest
|
|
17
|
+
import { ValidationError } from '../../errors.js';
|
|
18
|
+
import { GOOGLE_VERTEX_AI } from '../../globals.js';
|
|
19
|
+
import { MESSAGE_ROLES, SYSTEM_MESSAGE_ROLES, } from '../../types/requestBody.js';
|
|
20
|
+
import { resolveAnthropicBetas, VERTEX_BETA_KEY } from '../anthropic/anthropicBetas.js';
|
|
21
|
+
import { AnthropicChatCompleteConfig, } from '../anthropic/chatComplete.js';
|
|
22
|
+
import { mergeAnthropicBetasWithOverride } from '../anthropic/utils.js';
|
|
23
|
+
import { encodeToolCallIdWithSignature, getThoughtSignatureFromToolCall, SYSTEM_INSTRUCTION_DISABLED_MODELS, transformOpenAIRoleToGoogleRole, transformToolChoiceForGemini, } from '../google/chatComplete.js';
|
|
24
|
+
import { generateErrorResponse, generateInvalidProviderResponseError, transformFinishReason } from '../utils.js';
|
|
25
|
+
import { decodeUrlIfEncoded, parseFileData } from '../utils/fileUtils.js';
|
|
26
|
+
import { parseToolArgumentsByContext } from '../utils/toolUtils.js';
|
|
27
|
+
import { transformGenerationConfig } from './transformGenerationConfig.js';
|
|
28
|
+
import { VERTEX_MODALITY, } from './types.js';
|
|
29
|
+
import { getMimeType, googleTools, mapOpenAIDetailToMediaResolution, recursivelyDeleteUnsupportedParameters, transformComputerUseToolFromOpenAI, transformGeminiToolParameters, transformGoogleTools, transformInputAudioPart, transformVertexLogprobs, } from './utils.js';
|
|
30
|
+
export const buildGoogleSearchRetrievalTool = (tool) => {
|
|
31
|
+
const googleSearchRetrievalTool = {
|
|
32
|
+
googleSearchRetrieval: {},
|
|
33
|
+
};
|
|
34
|
+
if (tool.function.parameters?.dynamicRetrievalConfig) {
|
|
35
|
+
googleSearchRetrievalTool.googleSearchRetrieval.dynamicRetrievalConfig =
|
|
36
|
+
tool.function.parameters.dynamicRetrievalConfig;
|
|
37
|
+
}
|
|
38
|
+
return googleSearchRetrievalTool;
|
|
39
|
+
};
|
|
40
|
+
export const VertexGoogleChatCompleteConfig = {
|
|
41
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versioning#gemini-model-versions
|
|
42
|
+
model: {
|
|
43
|
+
param: 'model',
|
|
44
|
+
required: true,
|
|
45
|
+
default: 'gemini-1.0-pro',
|
|
46
|
+
},
|
|
47
|
+
messages: [
|
|
48
|
+
{
|
|
49
|
+
param: 'contents',
|
|
50
|
+
default: '',
|
|
51
|
+
transform: (params) => {
|
|
52
|
+
let lastRole;
|
|
53
|
+
const messages = [];
|
|
54
|
+
params.messages?.forEach((message) => {
|
|
55
|
+
// From gemini-1.5 onwards, systemInstruction is supported
|
|
56
|
+
// Skipping system message and sending it in systemInstruction for gemini 1.5 models
|
|
57
|
+
if (SYSTEM_MESSAGE_ROLES.includes(message.role) &&
|
|
58
|
+
!SYSTEM_INSTRUCTION_DISABLED_MODELS.includes(params.model))
|
|
59
|
+
return;
|
|
60
|
+
const role = transformOpenAIRoleToGoogleRole(message.role);
|
|
61
|
+
const parts = [];
|
|
62
|
+
if (message.role === 'assistant') {
|
|
63
|
+
const msg = message;
|
|
64
|
+
// 1. Emit thinking parts first (for multi-turn signature reconstruction).
|
|
65
|
+
const thinkingBlocks = msg.thinking_blocks;
|
|
66
|
+
if (thinkingBlocks?.length) {
|
|
67
|
+
for (const block of thinkingBlocks) {
|
|
68
|
+
if (block.type === 'thinking' && block.thinking !== undefined && block.signature) {
|
|
69
|
+
parts.push({
|
|
70
|
+
thought: true,
|
|
71
|
+
text: block.thinking,
|
|
72
|
+
thoughtSignature: block.signature,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 2. Emit text content part.
|
|
78
|
+
// Do NOT attach thoughtSignature here: `thought_signatures[0]` is the first
|
|
79
|
+
// thinking-block signature (already on the thought part above), not a text-part
|
|
80
|
+
// signature. Gemini only validates thoughtSignature on `thought: true` and
|
|
81
|
+
// `functionCall` parts — plain text parts do not require it.
|
|
82
|
+
if (typeof message.content === 'string' && message.content) {
|
|
83
|
+
parts.push({ text: message.content });
|
|
84
|
+
}
|
|
85
|
+
else if (message.content && Array.isArray(message.content)) {
|
|
86
|
+
message.content.forEach((c) => {
|
|
87
|
+
if (c.type === 'text' && c.text) {
|
|
88
|
+
parts.push({ text: c.text });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// 3. Emit function call parts with thoughtSignature.
|
|
93
|
+
if (message.tool_calls) {
|
|
94
|
+
message.tool_calls.forEach((tool_call) => {
|
|
95
|
+
const thoughtSig = getThoughtSignatureFromToolCall(tool_call, params.model);
|
|
96
|
+
parts.push({
|
|
97
|
+
functionCall: {
|
|
98
|
+
name: tool_call.function.name,
|
|
99
|
+
args: parseToolArgumentsByContext(tool_call.function.arguments, { model: params.model }),
|
|
100
|
+
},
|
|
101
|
+
...(thoughtSig && { thoughtSignature: thoughtSig }),
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Guard: Gemini rejects turns with zero parts. If somehow all branches above
|
|
106
|
+
// produced nothing (e.g. content="" with no tool_calls), emit a minimal empty-text
|
|
107
|
+
// part rather than silently sending an invalid message that the API will reject.
|
|
108
|
+
if (parts.length === 0) {
|
|
109
|
+
parts.push({ text: '' });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (message.role === 'tool') {
|
|
113
|
+
let toolContent = '';
|
|
114
|
+
if (typeof message.content === 'string') {
|
|
115
|
+
toolContent = message.content;
|
|
116
|
+
}
|
|
117
|
+
else if (Array.isArray(message.content)) {
|
|
118
|
+
// concatenate all text parts from the content array
|
|
119
|
+
toolContent = message.content
|
|
120
|
+
.filter((c) => c.type === 'text')
|
|
121
|
+
.map((c) => c.text)
|
|
122
|
+
.join('\n');
|
|
123
|
+
}
|
|
124
|
+
parts.push({
|
|
125
|
+
functionResponse: {
|
|
126
|
+
name: message.name ?? 'gateway-tool-filler-name',
|
|
127
|
+
response: {
|
|
128
|
+
content: toolContent,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else if (message.content && Array.isArray(message.content)) {
|
|
134
|
+
message.content.forEach((c) => {
|
|
135
|
+
if (c.type === 'text') {
|
|
136
|
+
parts.push({
|
|
137
|
+
text: c.text ?? '',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else if (c.type === 'input_audio') {
|
|
141
|
+
parts.push(transformInputAudioPart(c));
|
|
142
|
+
}
|
|
143
|
+
else if (c.type === 'file') {
|
|
144
|
+
// Handle file content type - translate to Gemini PartType format
|
|
145
|
+
if (!c.file) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const fileId = c.file.file_id || c.file.file_url;
|
|
149
|
+
const fileData = c.file.file_data;
|
|
150
|
+
const mimeType = c.file.mime_type;
|
|
151
|
+
// Determine file source
|
|
152
|
+
const fileSource = fileId || fileData;
|
|
153
|
+
if (!fileSource) {
|
|
154
|
+
throw new ValidationError('Unknown file type. Please pass in a file_id or file_data');
|
|
155
|
+
}
|
|
156
|
+
// Case A: Google Cloud Storage (GCS) URI
|
|
157
|
+
if (typeof fileSource === 'string') {
|
|
158
|
+
const decodedFileSource = decodeUrlIfEncoded(fileSource);
|
|
159
|
+
if (decodedFileSource.includes('gs://')) {
|
|
160
|
+
const detectedMimeType = mimeType || getMimeType(decodedFileSource) || 'application/octet-stream';
|
|
161
|
+
parts.push({
|
|
162
|
+
fileData: {
|
|
163
|
+
mimeType: detectedMimeType,
|
|
164
|
+
fileUri: decodedFileSource,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Case B: HTTP/HTTPS URL
|
|
171
|
+
if (typeof fileSource === 'string') {
|
|
172
|
+
const decodedFileSource = decodeUrlIfEncoded(fileSource);
|
|
173
|
+
if (decodedFileSource.includes('https://') || decodedFileSource.includes('http://')) {
|
|
174
|
+
const detectedMimeType = mimeType || getMimeType(decodedFileSource);
|
|
175
|
+
if (!detectedMimeType) {
|
|
176
|
+
throw new ValidationError(`Unable to determine mime type for file_id: ${decodedFileSource}, set this explicitly using file.mime_type`);
|
|
177
|
+
}
|
|
178
|
+
parts.push({
|
|
179
|
+
fileData: {
|
|
180
|
+
fileUri: decodedFileSource,
|
|
181
|
+
mimeType: detectedMimeType,
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Case C: Base64 Data URI
|
|
188
|
+
if (fileData) {
|
|
189
|
+
const { base64String, mimeType: parsedMimeType } = parseFileData(fileData);
|
|
190
|
+
const detectedMimeType = mimeType || parsedMimeType || 'application/octet-stream';
|
|
191
|
+
parts.push({
|
|
192
|
+
inlineData: {
|
|
193
|
+
mimeType: detectedMimeType,
|
|
194
|
+
data: base64String,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (c.type === 'image_url') {
|
|
201
|
+
const { url, mime_type: passedMimeType, detail } = c.image_url || {};
|
|
202
|
+
if (!url) {
|
|
203
|
+
// Shouldn't throw error?
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const mediaResolution = mapOpenAIDetailToMediaResolution(detail);
|
|
207
|
+
// Example: data:image/png;base64,abcdefg...
|
|
208
|
+
if (url.startsWith('data:')) {
|
|
209
|
+
const [mimeTypeWithPrefix, base64Image] = url.split(';base64,');
|
|
210
|
+
const mimeType = mimeTypeWithPrefix.split(':')[1];
|
|
211
|
+
const part = {
|
|
212
|
+
inlineData: {
|
|
213
|
+
mimeType: mimeType,
|
|
214
|
+
data: base64Image,
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
// only add mediaResolution for base64 images if it's not null
|
|
218
|
+
if (mediaResolution !== null) {
|
|
219
|
+
part.mediaResolution = mediaResolution;
|
|
220
|
+
}
|
|
221
|
+
parts.push(part);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const decodedUrl = decodeUrlIfEncoded(url);
|
|
226
|
+
if (decodedUrl.startsWith('gs://') ||
|
|
227
|
+
decodedUrl.startsWith('https://') ||
|
|
228
|
+
decodedUrl.startsWith('http://')) {
|
|
229
|
+
const part = {
|
|
230
|
+
fileData: {
|
|
231
|
+
mimeType: passedMimeType || getMimeType(decodedUrl) || 'image/jpeg',
|
|
232
|
+
fileUri: decodedUrl,
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
// only add mediaResolution for URL images if it's not null
|
|
236
|
+
if (mediaResolution !== null) {
|
|
237
|
+
part.mediaResolution = mediaResolution;
|
|
238
|
+
}
|
|
239
|
+
parts.push(part);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// NOTE: This block is kept to maintain backward compatibility
|
|
243
|
+
// Earlier we were assuming that all images will be base64 with image/jpeg mimeType
|
|
244
|
+
/**
|
|
245
|
+
* ================================
|
|
246
|
+
* NOTE: Mimetype should be passedMimeType if provided, otherwise default to image/jpeg
|
|
247
|
+
* ================================
|
|
248
|
+
*/
|
|
249
|
+
const part = {
|
|
250
|
+
inlineData: {
|
|
251
|
+
mimeType: passedMimeType || 'image/jpeg',
|
|
252
|
+
data: c.image_url?.url || undefined,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
// only add mediaResolution for base64 images if it's not null
|
|
256
|
+
if (mediaResolution !== null) {
|
|
257
|
+
part.mediaResolution = mediaResolution;
|
|
258
|
+
}
|
|
259
|
+
parts.push(part);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
else if (typeof message.content === 'string') {
|
|
266
|
+
parts.push({
|
|
267
|
+
text: message.content,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
// @NOTE: This takes care of the "Please ensure that multiturn requests alternate between user and model."
|
|
271
|
+
// error that occurs when we have multiple user messages in a row.
|
|
272
|
+
const shouldCombineMessages = lastRole === role && !params.model?.includes('vision');
|
|
273
|
+
if (shouldCombineMessages) {
|
|
274
|
+
messages[messages.length - 1].parts.push(...parts);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
messages.push({ role, parts });
|
|
278
|
+
}
|
|
279
|
+
lastRole = role;
|
|
280
|
+
});
|
|
281
|
+
return messages;
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
param: 'systemInstruction',
|
|
286
|
+
default: '',
|
|
287
|
+
transform: (params) => {
|
|
288
|
+
// systemInstruction is only supported from gemini 1.5 models
|
|
289
|
+
if (SYSTEM_INSTRUCTION_DISABLED_MODELS.includes(params.model))
|
|
290
|
+
return;
|
|
291
|
+
const firstMessage = params.messages?.[0] || null;
|
|
292
|
+
if (!firstMessage)
|
|
293
|
+
return;
|
|
294
|
+
if (SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) && typeof firstMessage.content === 'string') {
|
|
295
|
+
return {
|
|
296
|
+
parts: [
|
|
297
|
+
{
|
|
298
|
+
text: firstMessage.content,
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
role: 'system',
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if (SYSTEM_MESSAGE_ROLES.includes(firstMessage.role) &&
|
|
305
|
+
typeof firstMessage.content === 'object' &&
|
|
306
|
+
firstMessage.content?.[0]?.text) {
|
|
307
|
+
return {
|
|
308
|
+
parts: [
|
|
309
|
+
{
|
|
310
|
+
text: firstMessage.content?.[0].text,
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
role: 'system',
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
temperature: {
|
|
321
|
+
param: 'generationConfig',
|
|
322
|
+
transform: (params) => transformGenerationConfig(params),
|
|
323
|
+
},
|
|
324
|
+
top_p: {
|
|
325
|
+
param: 'generationConfig',
|
|
326
|
+
transform: (params) => transformGenerationConfig(params),
|
|
327
|
+
},
|
|
328
|
+
top_k: {
|
|
329
|
+
param: 'generationConfig',
|
|
330
|
+
transform: (params) => transformGenerationConfig(params),
|
|
331
|
+
},
|
|
332
|
+
max_tokens: {
|
|
333
|
+
param: 'generationConfig',
|
|
334
|
+
transform: (params) => transformGenerationConfig(params),
|
|
335
|
+
},
|
|
336
|
+
max_completion_tokens: {
|
|
337
|
+
param: 'generationConfig',
|
|
338
|
+
transform: (params) => transformGenerationConfig(params),
|
|
339
|
+
},
|
|
340
|
+
stop: {
|
|
341
|
+
param: 'generationConfig',
|
|
342
|
+
transform: (params) => transformGenerationConfig(params),
|
|
343
|
+
},
|
|
344
|
+
response_format: {
|
|
345
|
+
param: 'generationConfig',
|
|
346
|
+
transform: (params) => transformGenerationConfig(params),
|
|
347
|
+
},
|
|
348
|
+
logprobs: {
|
|
349
|
+
param: 'generationConfig',
|
|
350
|
+
transform: (params) => transformGenerationConfig(params),
|
|
351
|
+
},
|
|
352
|
+
top_logprobs: {
|
|
353
|
+
param: 'generationConfig',
|
|
354
|
+
transform: (params) => transformGenerationConfig(params),
|
|
355
|
+
},
|
|
356
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-attributes
|
|
357
|
+
// Example payload to be included in the request that sets the safety settings:
|
|
358
|
+
// "safety_settings": [
|
|
359
|
+
// {
|
|
360
|
+
// "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
361
|
+
// "threshold": "BLOCK_NONE"
|
|
362
|
+
// },
|
|
363
|
+
// {
|
|
364
|
+
// "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
365
|
+
// "threshold": "BLOCK_ONLY_HIGH"
|
|
366
|
+
// }
|
|
367
|
+
// ]
|
|
368
|
+
safety_settings: {
|
|
369
|
+
param: 'safety_settings',
|
|
370
|
+
},
|
|
371
|
+
tools: {
|
|
372
|
+
param: 'tools',
|
|
373
|
+
default: '',
|
|
374
|
+
transform: (params) => {
|
|
375
|
+
const functionDeclarations = [];
|
|
376
|
+
const tools = [];
|
|
377
|
+
params.tools?.forEach(tool => {
|
|
378
|
+
if (tool.type === 'computer_use') {
|
|
379
|
+
tools.push(transformComputerUseToolFromOpenAI(tool));
|
|
380
|
+
}
|
|
381
|
+
else if (tool.type === 'function') {
|
|
382
|
+
// these are not supported by google
|
|
383
|
+
recursivelyDeleteUnsupportedParameters(tool.function?.parameters);
|
|
384
|
+
delete tool.function?.strict;
|
|
385
|
+
if (googleTools.includes(tool.function.name)) {
|
|
386
|
+
tools.push(...transformGoogleTools(tool));
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
if (tool.function?.parameters) {
|
|
390
|
+
tool.function.parameters = transformGeminiToolParameters(tool.function.parameters);
|
|
391
|
+
}
|
|
392
|
+
functionDeclarations.push(tool.function);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
if (functionDeclarations.length) {
|
|
397
|
+
tools.push({ functionDeclarations });
|
|
398
|
+
}
|
|
399
|
+
return tools;
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
tool_choice: {
|
|
403
|
+
param: 'tool_config',
|
|
404
|
+
default: '',
|
|
405
|
+
transform: (params) => {
|
|
406
|
+
if (params.tool_choice) {
|
|
407
|
+
const allowedFunctionNames = [];
|
|
408
|
+
if (typeof params.tool_choice === 'object' && params.tool_choice.type === 'function') {
|
|
409
|
+
allowedFunctionNames.push(params.tool_choice.function.name);
|
|
410
|
+
}
|
|
411
|
+
const toolConfig = {
|
|
412
|
+
function_calling_config: {
|
|
413
|
+
mode: transformToolChoiceForGemini(params.tool_choice),
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
if (allowedFunctionNames.length > 0) {
|
|
417
|
+
toolConfig.function_calling_config.allowed_function_names = allowedFunctionNames;
|
|
418
|
+
}
|
|
419
|
+
return toolConfig;
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
labels: {
|
|
424
|
+
param: 'labels',
|
|
425
|
+
},
|
|
426
|
+
thinking: {
|
|
427
|
+
param: 'generationConfig',
|
|
428
|
+
transform: (params) => transformGenerationConfig(params),
|
|
429
|
+
},
|
|
430
|
+
reasoning_effort: {
|
|
431
|
+
param: 'generationConfig',
|
|
432
|
+
transform: (params) => transformGenerationConfig(params),
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* ================================
|
|
436
|
+
* NOTE: Remove stream_options from the request body
|
|
437
|
+
* ================================
|
|
438
|
+
*/
|
|
439
|
+
stream_options: {
|
|
440
|
+
param: 'stream_options',
|
|
441
|
+
removeFromParams: true,
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
444
|
+
* ================================
|
|
445
|
+
* NOTE: Remove parallel_tool_calls from the request body
|
|
446
|
+
* ================================
|
|
447
|
+
*/
|
|
448
|
+
parallel_tool_calls: {
|
|
449
|
+
param: 'parallel_tool_calls',
|
|
450
|
+
removeFromParams: true,
|
|
451
|
+
},
|
|
452
|
+
// Vertex has no end-user identifier field and rejects unknown fields.
|
|
453
|
+
user: {
|
|
454
|
+
param: 'user',
|
|
455
|
+
removeFromParams: true,
|
|
456
|
+
},
|
|
457
|
+
modalities: {
|
|
458
|
+
param: 'generationConfig',
|
|
459
|
+
transform: (params) => transformGenerationConfig(params),
|
|
460
|
+
},
|
|
461
|
+
seed: {
|
|
462
|
+
param: 'generationConfig',
|
|
463
|
+
transform: (params) => transformGenerationConfig(params),
|
|
464
|
+
},
|
|
465
|
+
};
|
|
466
|
+
const buildVertexAnthropicBeta = (params, providerOptions) => resolveAnthropicBetas(mergeAnthropicBetasWithOverride(providerOptions, params?.anthropic_beta), VERTEX_BETA_KEY);
|
|
467
|
+
export const VertexAnthropicChatCompleteConfig = {
|
|
468
|
+
...AnthropicChatCompleteConfig,
|
|
469
|
+
anthropic_version: {
|
|
470
|
+
param: 'anthropic_version',
|
|
471
|
+
required: true,
|
|
472
|
+
default: 'vertex-2023-10-16',
|
|
473
|
+
},
|
|
474
|
+
// `required: true` so the header-only path still fires the default branch.
|
|
475
|
+
// Outgoing anthropic-beta header is set in api.ts; this covers the body field.
|
|
476
|
+
anthropic_beta: {
|
|
477
|
+
param: 'anthropic_beta',
|
|
478
|
+
required: true,
|
|
479
|
+
default: buildVertexAnthropicBeta,
|
|
480
|
+
transform: buildVertexAnthropicBeta,
|
|
481
|
+
},
|
|
482
|
+
model: {
|
|
483
|
+
param: 'model',
|
|
484
|
+
required: false,
|
|
485
|
+
transform: () => {
|
|
486
|
+
return undefined;
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
/** Sum IMAGE modality tokens from Gemini usageMetadata (native generateContent shape). */
|
|
491
|
+
function getImageTokenCountsFromUsageMetadata(usageMetadata) {
|
|
492
|
+
if (!usageMetadata)
|
|
493
|
+
return { inputImageTokens: 0, outputImageTokens: 0 };
|
|
494
|
+
const inputImageTokens = usageMetadata.promptTokensDetails?.reduce((acc, curr) => {
|
|
495
|
+
if (curr.modality === VERTEX_MODALITY.IMAGE)
|
|
496
|
+
return acc + curr.tokenCount;
|
|
497
|
+
return acc;
|
|
498
|
+
}, 0) ?? 0;
|
|
499
|
+
const outputImageTokens = usageMetadata.candidatesTokensDetails?.reduce((acc, curr) => {
|
|
500
|
+
if (curr.modality === VERTEX_MODALITY.IMAGE)
|
|
501
|
+
return acc + curr.tokenCount;
|
|
502
|
+
return acc;
|
|
503
|
+
}, 0) ?? 0;
|
|
504
|
+
return { inputImageTokens, outputImageTokens };
|
|
505
|
+
}
|
|
506
|
+
function readGeminiUsageMetadataFromOpenAICompatPayload(payload) {
|
|
507
|
+
const raw = payload.usageMetadata ?? payload.usage_metadata;
|
|
508
|
+
if (raw !== undefined && raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
509
|
+
return raw;
|
|
510
|
+
}
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
function asObject(value) {
|
|
514
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
515
|
+
return value;
|
|
516
|
+
}
|
|
517
|
+
return {};
|
|
518
|
+
}
|
|
519
|
+
// Merge Gemini IMAGE modality counts into OpenAI-shaped usage.
|
|
520
|
+
// Preserves existing detail fields (reasoning_tokens, cached_tokens, audio_tokens, etc.).
|
|
521
|
+
function enrichOpenAIShapedUsageWithGeminiImageTokens(usage, usageMetadata) {
|
|
522
|
+
if (!usageMetadata)
|
|
523
|
+
return usage;
|
|
524
|
+
const { inputImageTokens, outputImageTokens } = getImageTokenCountsFromUsageMetadata(usageMetadata);
|
|
525
|
+
const merged = { ...asObject(usage) };
|
|
526
|
+
merged.prompt_tokens_details = {
|
|
527
|
+
...asObject(merged.prompt_tokens_details),
|
|
528
|
+
image_tokens: inputImageTokens,
|
|
529
|
+
};
|
|
530
|
+
merged.completion_tokens_details = {
|
|
531
|
+
...asObject(merged.completion_tokens_details),
|
|
532
|
+
image_tokens: outputImageTokens,
|
|
533
|
+
};
|
|
534
|
+
return merged;
|
|
535
|
+
}
|
|
536
|
+
export const GoogleChatCompleteResponseTransform = (response, responseStatus, _responseHeaders, strictOpenAiCompliance) => {
|
|
537
|
+
// when error occurs on streaming request, the response is an array of errors.
|
|
538
|
+
if (responseStatus !== 200 && Array.isArray(response) && response.length > 0 && 'error' in response[0]) {
|
|
539
|
+
const { error } = response[0];
|
|
540
|
+
return generateErrorResponse({
|
|
541
|
+
message: error.message,
|
|
542
|
+
type: error.status,
|
|
543
|
+
code: String(error.code),
|
|
544
|
+
}, GOOGLE_VERTEX_AI);
|
|
545
|
+
}
|
|
546
|
+
if (responseStatus !== 200 && 'error' in response) {
|
|
547
|
+
const { error } = response;
|
|
548
|
+
return generateErrorResponse({
|
|
549
|
+
message: error.message,
|
|
550
|
+
type: error.status,
|
|
551
|
+
code: String(error.code),
|
|
552
|
+
}, GOOGLE_VERTEX_AI);
|
|
553
|
+
}
|
|
554
|
+
// sometimes vertex gemini returns usageMetadata without candidates
|
|
555
|
+
const isValidResponse = 'candidates' in response || 'usageMetadata' in response;
|
|
556
|
+
if (isValidResponse) {
|
|
557
|
+
const { promptTokenCount = 0, candidatesTokenCount = 0, totalTokenCount = 0, thoughtsTokenCount = 0, cachedContentTokenCount = 0, promptTokensDetails = [], candidatesTokensDetails = [], } = response.usageMetadata;
|
|
558
|
+
const inputAudioTokens = promptTokensDetails.reduce((acc, curr) => {
|
|
559
|
+
if (curr.modality === VERTEX_MODALITY.AUDIO)
|
|
560
|
+
return acc + curr.tokenCount;
|
|
561
|
+
return acc;
|
|
562
|
+
}, 0);
|
|
563
|
+
const outputAudioTokens = candidatesTokensDetails.reduce((acc, curr) => {
|
|
564
|
+
if (curr.modality === VERTEX_MODALITY.AUDIO)
|
|
565
|
+
return acc + curr.tokenCount;
|
|
566
|
+
return acc;
|
|
567
|
+
}, 0);
|
|
568
|
+
const { inputImageTokens, outputImageTokens } = getImageTokenCountsFromUsageMetadata({
|
|
569
|
+
promptTokensDetails,
|
|
570
|
+
candidatesTokensDetails,
|
|
571
|
+
});
|
|
572
|
+
return {
|
|
573
|
+
/**
|
|
574
|
+
* ================================
|
|
575
|
+
* NOTE: Use tfy- prefix for ids instead of the legacy prefix
|
|
576
|
+
* ================================
|
|
577
|
+
*/
|
|
578
|
+
id: 'tfy-' + crypto.randomUUID(),
|
|
579
|
+
object: 'chat.completion',
|
|
580
|
+
created: Math.floor(Date.now() / 1000),
|
|
581
|
+
model: response.modelVersion,
|
|
582
|
+
provider: GOOGLE_VERTEX_AI,
|
|
583
|
+
choices: response.candidates?.map((generation, index) => {
|
|
584
|
+
// transform tool calls and content by iterating over the content parts
|
|
585
|
+
const toolCalls = [];
|
|
586
|
+
let content;
|
|
587
|
+
const thinkingBlocks = [];
|
|
588
|
+
const thoughtSignaturesAll = [];
|
|
589
|
+
const inlineDataParts = [];
|
|
590
|
+
for (const part of generation.content?.parts ?? []) {
|
|
591
|
+
if (part.functionCall) {
|
|
592
|
+
const baseId = 'tfy-' + crypto.randomUUID();
|
|
593
|
+
const thoughtSig = part.thoughtSignature;
|
|
594
|
+
const toolCallId = thoughtSig ? encodeToolCallIdWithSignature(baseId, thoughtSig) : baseId;
|
|
595
|
+
toolCalls.push({
|
|
596
|
+
id: toolCallId,
|
|
597
|
+
type: 'function',
|
|
598
|
+
function: {
|
|
599
|
+
name: part.functionCall.name,
|
|
600
|
+
arguments: JSON.stringify(part.functionCall.args),
|
|
601
|
+
},
|
|
602
|
+
...(thoughtSig && { provider_specific_fields: { thought_signature: thoughtSig } }),
|
|
603
|
+
});
|
|
604
|
+
if (thoughtSig)
|
|
605
|
+
thoughtSignaturesAll.push(thoughtSig);
|
|
606
|
+
}
|
|
607
|
+
else if (part.text) {
|
|
608
|
+
if (part.thought) {
|
|
609
|
+
const block = {
|
|
610
|
+
type: 'thinking',
|
|
611
|
+
thinking: part.text,
|
|
612
|
+
};
|
|
613
|
+
if (part.thoughtSignature) {
|
|
614
|
+
block.signature = part.thoughtSignature;
|
|
615
|
+
thoughtSignaturesAll.push(part.thoughtSignature);
|
|
616
|
+
}
|
|
617
|
+
thinkingBlocks.push(block);
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
// Concatenate — Gemini can return multiple text parts in one candidate.
|
|
621
|
+
content = (content ?? '') + part.text;
|
|
622
|
+
if (part.thoughtSignature)
|
|
623
|
+
thoughtSignaturesAll.push(part.thoughtSignature);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
else if (part.inlineData) {
|
|
627
|
+
// Inline data (images, audio from Imagen/TTS models).
|
|
628
|
+
// Convert to a data URI and collect; exposed via provider_specific_fields.inline_data
|
|
629
|
+
// so clients can consume the binary payload without breaking the string content field.
|
|
630
|
+
inlineDataParts.push({
|
|
631
|
+
mimeType: part.inlineData.mimeType,
|
|
632
|
+
data: part.inlineData.data,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
const reasoning_content = thinkingBlocks.map(b => b.thinking).join('') || undefined;
|
|
637
|
+
const providerSpecificFields = {
|
|
638
|
+
...(thoughtSignaturesAll.length > 0 && { thought_signatures: thoughtSignaturesAll }),
|
|
639
|
+
...(inlineDataParts.length > 0 && { inline_data: inlineDataParts }),
|
|
640
|
+
};
|
|
641
|
+
const message = {
|
|
642
|
+
role: MESSAGE_ROLES.ASSISTANT,
|
|
643
|
+
...(toolCalls.length && { tool_calls: toolCalls }),
|
|
644
|
+
...(content && { content }),
|
|
645
|
+
...(thinkingBlocks.length > 0 && { thinking_blocks: thinkingBlocks }),
|
|
646
|
+
...(reasoning_content && { reasoning_content }),
|
|
647
|
+
...(Object.keys(providerSpecificFields).length > 0 && { provider_specific_fields: providerSpecificFields }),
|
|
648
|
+
};
|
|
649
|
+
const logprobsContent = transformVertexLogprobs(generation);
|
|
650
|
+
let logprobs;
|
|
651
|
+
if (logprobsContent) {
|
|
652
|
+
logprobs = {
|
|
653
|
+
content: logprobsContent,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
message: message,
|
|
658
|
+
index: index,
|
|
659
|
+
finish_reason: transformFinishReason(generation.finishReason, strictOpenAiCompliance),
|
|
660
|
+
logprobs,
|
|
661
|
+
...(!strictOpenAiCompliance && {
|
|
662
|
+
safetyRatings: generation.safetyRatings,
|
|
663
|
+
}),
|
|
664
|
+
...(!strictOpenAiCompliance && generation.groundingMetadata
|
|
665
|
+
? { groundingMetadata: generation.groundingMetadata }
|
|
666
|
+
: {}),
|
|
667
|
+
};
|
|
668
|
+
}) ?? [],
|
|
669
|
+
usage: {
|
|
670
|
+
prompt_tokens: promptTokenCount,
|
|
671
|
+
completion_tokens: candidatesTokenCount + thoughtsTokenCount,
|
|
672
|
+
total_tokens: totalTokenCount,
|
|
673
|
+
completion_tokens_details: {
|
|
674
|
+
reasoning_tokens: thoughtsTokenCount,
|
|
675
|
+
audio_tokens: outputAudioTokens,
|
|
676
|
+
image_tokens: outputImageTokens,
|
|
677
|
+
},
|
|
678
|
+
prompt_tokens_details: {
|
|
679
|
+
cached_tokens: cachedContentTokenCount,
|
|
680
|
+
audio_tokens: inputAudioTokens,
|
|
681
|
+
image_tokens: inputImageTokens,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return generateInvalidProviderResponseError(response, GOOGLE_VERTEX_AI);
|
|
687
|
+
};
|
|
688
|
+
export const VertexLlamaChatCompleteConfig = {
|
|
689
|
+
model: {
|
|
690
|
+
param: 'model',
|
|
691
|
+
required: true,
|
|
692
|
+
default: 'meta/llama-3.1-405b-instruct-maas',
|
|
693
|
+
transform: (params) => {
|
|
694
|
+
return params.model?.replace('meta.', 'meta/') || 'meta/llama-3.1-405b-instruct-maas';
|
|
695
|
+
},
|
|
696
|
+
},
|
|
697
|
+
messages: {
|
|
698
|
+
param: 'messages',
|
|
699
|
+
required: true,
|
|
700
|
+
default: [],
|
|
701
|
+
},
|
|
702
|
+
max_tokens: {
|
|
703
|
+
param: 'max_tokens',
|
|
704
|
+
default: 512,
|
|
705
|
+
min: 1,
|
|
706
|
+
max: 2048,
|
|
707
|
+
},
|
|
708
|
+
max_completion_tokens: {
|
|
709
|
+
param: 'max_tokens',
|
|
710
|
+
default: 512,
|
|
711
|
+
min: 1,
|
|
712
|
+
max: 2048,
|
|
713
|
+
},
|
|
714
|
+
temperature: {
|
|
715
|
+
param: 'temperature',
|
|
716
|
+
default: 0.5,
|
|
717
|
+
min: 0,
|
|
718
|
+
max: 1,
|
|
719
|
+
},
|
|
720
|
+
top_p: {
|
|
721
|
+
param: 'top_p',
|
|
722
|
+
default: 0.9,
|
|
723
|
+
min: 0,
|
|
724
|
+
max: 1,
|
|
725
|
+
},
|
|
726
|
+
top_k: {
|
|
727
|
+
param: 'top_k',
|
|
728
|
+
default: 0,
|
|
729
|
+
min: 0,
|
|
730
|
+
max: 2048,
|
|
731
|
+
},
|
|
732
|
+
stream: {
|
|
733
|
+
param: 'stream',
|
|
734
|
+
default: false,
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* ================================
|
|
738
|
+
* NOTE: Remove stream_options from the request body
|
|
739
|
+
* ================================
|
|
740
|
+
*/
|
|
741
|
+
stream_options: {
|
|
742
|
+
param: 'stream_options',
|
|
743
|
+
removeFromParams: true,
|
|
744
|
+
},
|
|
745
|
+
parallel_tool_calls: {
|
|
746
|
+
param: 'parallel_tool_calls',
|
|
747
|
+
removeFromParams: true,
|
|
748
|
+
},
|
|
749
|
+
};
|
|
750
|
+
/**
|
|
751
|
+
* ================================
|
|
752
|
+
* NOTE: OpenAI-compatible config for default (non-Google/Anthropic/Mistral/endpoints) providers
|
|
753
|
+
* ================================
|
|
754
|
+
*/
|
|
755
|
+
export const VertexOpenAICompatibleChatCompleteConfig = {
|
|
756
|
+
model: {
|
|
757
|
+
param: 'model',
|
|
758
|
+
required: true,
|
|
759
|
+
default: 'openai/gpt-oss-120b-maas',
|
|
760
|
+
},
|
|
761
|
+
messages: {
|
|
762
|
+
param: 'messages',
|
|
763
|
+
required: true,
|
|
764
|
+
default: [],
|
|
765
|
+
},
|
|
766
|
+
max_tokens: {
|
|
767
|
+
param: 'max_tokens',
|
|
768
|
+
default: 2500,
|
|
769
|
+
min: 1,
|
|
770
|
+
max: 8192,
|
|
771
|
+
},
|
|
772
|
+
max_completion_tokens: {
|
|
773
|
+
param: 'max_tokens',
|
|
774
|
+
default: 2500,
|
|
775
|
+
min: 1,
|
|
776
|
+
max: 8192,
|
|
777
|
+
},
|
|
778
|
+
temperature: {
|
|
779
|
+
param: 'temperature',
|
|
780
|
+
default: 0.7,
|
|
781
|
+
min: 0,
|
|
782
|
+
max: 2,
|
|
783
|
+
},
|
|
784
|
+
top_p: {
|
|
785
|
+
param: 'top_p',
|
|
786
|
+
default: 1,
|
|
787
|
+
min: 0,
|
|
788
|
+
max: 1,
|
|
789
|
+
},
|
|
790
|
+
stop: {
|
|
791
|
+
param: 'stop',
|
|
792
|
+
},
|
|
793
|
+
stream: {
|
|
794
|
+
param: 'stream',
|
|
795
|
+
default: false,
|
|
796
|
+
},
|
|
797
|
+
/**
|
|
798
|
+
* ================================
|
|
799
|
+
* NOTE: Remove stream_options from the request body
|
|
800
|
+
* ================================
|
|
801
|
+
*/
|
|
802
|
+
stream_options: {
|
|
803
|
+
param: 'stream_options',
|
|
804
|
+
removeFromParams: true,
|
|
805
|
+
},
|
|
806
|
+
parallel_tool_calls: {
|
|
807
|
+
param: 'parallel_tool_calls',
|
|
808
|
+
removeFromParams: true,
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
/**
|
|
812
|
+
* ================================
|
|
813
|
+
* NOTE: Add Qwen Chat Complete Config
|
|
814
|
+
* ================================
|
|
815
|
+
*/
|
|
816
|
+
export const VertexQwenChatCompleteConfig = {
|
|
817
|
+
model: {
|
|
818
|
+
param: 'model',
|
|
819
|
+
required: true,
|
|
820
|
+
default: 'qwen/qwen3-235b-a22b-instruct-2507-maas',
|
|
821
|
+
},
|
|
822
|
+
messages: {
|
|
823
|
+
param: 'messages',
|
|
824
|
+
required: true,
|
|
825
|
+
default: [],
|
|
826
|
+
},
|
|
827
|
+
max_tokens: {
|
|
828
|
+
param: 'max_tokens',
|
|
829
|
+
default: 512,
|
|
830
|
+
min: 1,
|
|
831
|
+
max: 2048,
|
|
832
|
+
},
|
|
833
|
+
max_completion_tokens: {
|
|
834
|
+
param: 'max_tokens',
|
|
835
|
+
default: 512,
|
|
836
|
+
min: 1,
|
|
837
|
+
max: 2048,
|
|
838
|
+
},
|
|
839
|
+
temperature: {
|
|
840
|
+
param: 'temperature',
|
|
841
|
+
default: 0.5,
|
|
842
|
+
min: 0,
|
|
843
|
+
max: 1,
|
|
844
|
+
},
|
|
845
|
+
top_p: {
|
|
846
|
+
param: 'top_p',
|
|
847
|
+
default: 0.9,
|
|
848
|
+
min: 0,
|
|
849
|
+
max: 1,
|
|
850
|
+
},
|
|
851
|
+
top_k: {
|
|
852
|
+
param: 'top_k',
|
|
853
|
+
default: 0,
|
|
854
|
+
min: 0,
|
|
855
|
+
max: 2048,
|
|
856
|
+
},
|
|
857
|
+
stream: {
|
|
858
|
+
param: 'stream',
|
|
859
|
+
default: false,
|
|
860
|
+
},
|
|
861
|
+
/**
|
|
862
|
+
* ================================
|
|
863
|
+
* NOTE: Remove stream_options from the request body
|
|
864
|
+
* ================================
|
|
865
|
+
*/
|
|
866
|
+
stream_options: {
|
|
867
|
+
param: 'stream_options',
|
|
868
|
+
removeFromParams: true,
|
|
869
|
+
},
|
|
870
|
+
};
|
|
871
|
+
export const GoogleChatCompleteStreamChunkTransform = (responseChunk, fallbackId, streamState, strictOpenAiCompliance) => {
|
|
872
|
+
streamState.containsChainOfThoughtMessage = streamState?.containsChainOfThoughtMessage ?? false;
|
|
873
|
+
streamState.cumulativeToolCallIndex = streamState?.cumulativeToolCallIndex ?? 0;
|
|
874
|
+
const chunk = responseChunk
|
|
875
|
+
.trim()
|
|
876
|
+
.replace(/^data: /, '')
|
|
877
|
+
.trim();
|
|
878
|
+
if (chunk === '[DONE]') {
|
|
879
|
+
return `data: ${chunk}\n\n`;
|
|
880
|
+
}
|
|
881
|
+
const parsedChunk = JSON.parse(chunk);
|
|
882
|
+
let usageMetadata;
|
|
883
|
+
if (parsedChunk.usageMetadata) {
|
|
884
|
+
const thoughtsTokenCount = parsedChunk.usageMetadata.thoughtsTokenCount ?? 0;
|
|
885
|
+
const streamInputImageTokens = parsedChunk.usageMetadata.promptTokensDetails?.reduce((acc, curr) => {
|
|
886
|
+
if (curr.modality === VERTEX_MODALITY.IMAGE)
|
|
887
|
+
return acc + curr.tokenCount;
|
|
888
|
+
return acc;
|
|
889
|
+
}, 0) ?? 0;
|
|
890
|
+
const streamOutputImageTokens = parsedChunk.usageMetadata.candidatesTokensDetails?.reduce((acc, curr) => {
|
|
891
|
+
if (curr.modality === VERTEX_MODALITY.IMAGE)
|
|
892
|
+
return acc + curr.tokenCount;
|
|
893
|
+
return acc;
|
|
894
|
+
}, 0) ?? 0;
|
|
895
|
+
usageMetadata = {
|
|
896
|
+
prompt_tokens: parsedChunk.usageMetadata.promptTokenCount,
|
|
897
|
+
completion_tokens: (parsedChunk.usageMetadata.candidatesTokenCount ?? 0) + thoughtsTokenCount,
|
|
898
|
+
total_tokens: parsedChunk.usageMetadata.totalTokenCount,
|
|
899
|
+
completion_tokens_details: {
|
|
900
|
+
reasoning_tokens: thoughtsTokenCount,
|
|
901
|
+
audio_tokens: parsedChunk.usageMetadata?.candidatesTokensDetails?.reduce((acc, curr) => {
|
|
902
|
+
if (curr.modality === VERTEX_MODALITY.AUDIO)
|
|
903
|
+
return acc + curr.tokenCount;
|
|
904
|
+
return acc;
|
|
905
|
+
}, 0),
|
|
906
|
+
image_tokens: streamOutputImageTokens,
|
|
907
|
+
},
|
|
908
|
+
prompt_tokens_details: {
|
|
909
|
+
cached_tokens: parsedChunk.usageMetadata.cachedContentTokenCount,
|
|
910
|
+
audio_tokens: parsedChunk.usageMetadata?.promptTokensDetails?.reduce((acc, curr) => {
|
|
911
|
+
if (curr.modality === VERTEX_MODALITY.AUDIO)
|
|
912
|
+
return acc + curr.tokenCount;
|
|
913
|
+
return acc;
|
|
914
|
+
}, 0),
|
|
915
|
+
image_tokens: streamInputImageTokens,
|
|
916
|
+
},
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
const dataChunk = {
|
|
920
|
+
id: fallbackId,
|
|
921
|
+
object: 'chat.completion.chunk',
|
|
922
|
+
created: Math.floor(Date.now() / 1000),
|
|
923
|
+
model: parsedChunk.modelVersion,
|
|
924
|
+
provider: GOOGLE_VERTEX_AI,
|
|
925
|
+
choices: parsedChunk.candidates?.map((generation, index) => {
|
|
926
|
+
const finishReason = generation.finishReason
|
|
927
|
+
? transformFinishReason(generation.finishReason, strictOpenAiCompliance)
|
|
928
|
+
: null;
|
|
929
|
+
let message = { role: 'assistant', content: '' };
|
|
930
|
+
if (generation.content?.parts?.[0]?.text) {
|
|
931
|
+
const streamThinkingBlocks = [];
|
|
932
|
+
let content = '';
|
|
933
|
+
// Gemini 3+ can emit thought parts AND functionCall parts in the same streaming chunk.
|
|
934
|
+
// Collect function calls here so they aren't dropped when parts[0] is a thought/text part.
|
|
935
|
+
const mixedToolCalls = [];
|
|
936
|
+
let localToolIdx = 0;
|
|
937
|
+
for (const part of generation.content.parts) {
|
|
938
|
+
if (part.thought) {
|
|
939
|
+
const block = {
|
|
940
|
+
type: 'thinking',
|
|
941
|
+
thinking: part.text ?? '',
|
|
942
|
+
};
|
|
943
|
+
if (part.thoughtSignature)
|
|
944
|
+
block.signature = part.thoughtSignature;
|
|
945
|
+
streamThinkingBlocks.push(block);
|
|
946
|
+
streamState.containsChainOfThoughtMessage = true;
|
|
947
|
+
}
|
|
948
|
+
else if (part.functionCall) {
|
|
949
|
+
const baseId = 'tfy-' + crypto.randomUUID();
|
|
950
|
+
const thoughtSig = part.thoughtSignature;
|
|
951
|
+
const toolCallId = thoughtSig ? encodeToolCallIdWithSignature(baseId, thoughtSig) : baseId;
|
|
952
|
+
mixedToolCalls.push({
|
|
953
|
+
index: (streamState.cumulativeToolCallIndex ?? 0) + localToolIdx++,
|
|
954
|
+
id: toolCallId,
|
|
955
|
+
type: 'function',
|
|
956
|
+
function: {
|
|
957
|
+
name: part.functionCall.name,
|
|
958
|
+
arguments: JSON.stringify(part.functionCall.args),
|
|
959
|
+
},
|
|
960
|
+
...(thoughtSig && { provider_specific_fields: { thought_signature: thoughtSig } }),
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
// Concatenate — a chunk may contain multiple plain-text parts.
|
|
965
|
+
content = (content ?? '') + (part.text ?? '');
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
streamState.cumulativeToolCallIndex = (streamState.cumulativeToolCallIndex ?? 0) + localToolIdx;
|
|
969
|
+
const reasoning_content = streamThinkingBlocks.map(b => b.thinking).join('') || undefined;
|
|
970
|
+
message = {
|
|
971
|
+
role: 'assistant',
|
|
972
|
+
content,
|
|
973
|
+
...(reasoning_content && { reasoning_content }),
|
|
974
|
+
...(streamThinkingBlocks.length > 0 && { thinking_blocks: streamThinkingBlocks }),
|
|
975
|
+
...(mixedToolCalls.length > 0 && { tool_calls: mixedToolCalls }),
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
else if (generation.content?.parts?.[0]?.functionCall) {
|
|
979
|
+
let localIdx = 0;
|
|
980
|
+
const toolCalls = generation.content.parts
|
|
981
|
+
.map(part => {
|
|
982
|
+
if (part.functionCall) {
|
|
983
|
+
const baseId = 'tfy-' + crypto.randomUUID();
|
|
984
|
+
const thoughtSig = part.thoughtSignature;
|
|
985
|
+
const toolCallId = thoughtSig ? encodeToolCallIdWithSignature(baseId, thoughtSig) : baseId;
|
|
986
|
+
return {
|
|
987
|
+
index: (streamState.cumulativeToolCallIndex ?? 0) + localIdx++,
|
|
988
|
+
id: toolCallId,
|
|
989
|
+
type: 'function',
|
|
990
|
+
function: {
|
|
991
|
+
name: part.functionCall.name,
|
|
992
|
+
arguments: JSON.stringify(part.functionCall.args),
|
|
993
|
+
},
|
|
994
|
+
...(thoughtSig && { provider_specific_fields: { thought_signature: thoughtSig } }),
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
return undefined;
|
|
998
|
+
})
|
|
999
|
+
.filter((tc) => tc !== undefined);
|
|
1000
|
+
streamState.cumulativeToolCallIndex = (streamState.cumulativeToolCallIndex ?? 0) + localIdx;
|
|
1001
|
+
message = {
|
|
1002
|
+
role: 'assistant',
|
|
1003
|
+
tool_calls: toolCalls,
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
else if (generation.content?.parts?.[0]?.inlineData) {
|
|
1007
|
+
const part = generation.content.parts[0];
|
|
1008
|
+
const contentBlocks = [
|
|
1009
|
+
{
|
|
1010
|
+
index: streamState.containsChainOfThoughtMessage ? 1 : 0,
|
|
1011
|
+
delta: {
|
|
1012
|
+
type: 'image_url',
|
|
1013
|
+
image_url: {
|
|
1014
|
+
url: `data:${part.inlineData?.mimeType};base64,${part.inlineData?.data}`,
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
},
|
|
1018
|
+
];
|
|
1019
|
+
message = {
|
|
1020
|
+
role: 'assistant',
|
|
1021
|
+
content_blocks: contentBlocks,
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
return {
|
|
1025
|
+
delta: message,
|
|
1026
|
+
index: index,
|
|
1027
|
+
finish_reason: finishReason,
|
|
1028
|
+
...(!strictOpenAiCompliance && {
|
|
1029
|
+
safetyRatings: generation.safetyRatings,
|
|
1030
|
+
}),
|
|
1031
|
+
...(!strictOpenAiCompliance && generation.groundingMetadata
|
|
1032
|
+
? { groundingMetadata: generation.groundingMetadata }
|
|
1033
|
+
: {}),
|
|
1034
|
+
};
|
|
1035
|
+
}) ?? [],
|
|
1036
|
+
...(parsedChunk.usageMetadata != null && {
|
|
1037
|
+
usage: usageMetadata,
|
|
1038
|
+
}),
|
|
1039
|
+
};
|
|
1040
|
+
return `data: ${JSON.stringify(dataChunk)}\n\n`;
|
|
1041
|
+
};
|
|
1042
|
+
export const AnthropicErrorResponseTransform = response => {
|
|
1043
|
+
// Vertex :streamRawPredict returns errors as an array `[{ error: {...} }]`,
|
|
1044
|
+
// while :rawPredict returns a plain object `{ error: {...} }`. Normalise both
|
|
1045
|
+
// to the object shape so streaming errors don't collapse to `undefined`.
|
|
1046
|
+
const body = Array.isArray(response) ? response[0] : response;
|
|
1047
|
+
if (body && 'error' in body) {
|
|
1048
|
+
return generateErrorResponse({
|
|
1049
|
+
message: body.error?.message,
|
|
1050
|
+
type: body.error?.type,
|
|
1051
|
+
code: null,
|
|
1052
|
+
}, GOOGLE_VERTEX_AI);
|
|
1053
|
+
}
|
|
1054
|
+
return undefined;
|
|
1055
|
+
};
|
|
1056
|
+
export const VertexAnthropicChatCompleteResponseTransform = (response, responseStatus, _responseHeaders, strictOpenAiCompliance) => {
|
|
1057
|
+
if (responseStatus !== 200) {
|
|
1058
|
+
const errorResponse = AnthropicErrorResponseTransform(response);
|
|
1059
|
+
if (errorResponse)
|
|
1060
|
+
return errorResponse;
|
|
1061
|
+
}
|
|
1062
|
+
if ('content' in response) {
|
|
1063
|
+
const { input_tokens = 0, output_tokens = 0, cache_creation_input_tokens = 0, cache_read_input_tokens = 0, } = response?.usage ?? {};
|
|
1064
|
+
const shouldSendCacheUsage = cache_creation_input_tokens || cache_read_input_tokens;
|
|
1065
|
+
// Extract plain text content (always a string for the top-level content field)
|
|
1066
|
+
const content = response.content
|
|
1067
|
+
.filter(item => item.type === 'text')
|
|
1068
|
+
.map(item => item.text)
|
|
1069
|
+
.join('');
|
|
1070
|
+
// Include both regular tool calls and server-side tool calls (e.g. web_search via
|
|
1071
|
+
// srvtoolu_ IDs). Direct Anthropic does the same — both need to appear in tool_calls
|
|
1072
|
+
// so that transformAssistantMessage can reconstruct the interleaved content on the
|
|
1073
|
+
// next turn.
|
|
1074
|
+
const toolCalls = [];
|
|
1075
|
+
response.content.forEach(item => {
|
|
1076
|
+
if (item.type === 'tool_use' || item.type === 'server_tool_use') {
|
|
1077
|
+
toolCalls.push({
|
|
1078
|
+
id: item.id,
|
|
1079
|
+
type: 'function',
|
|
1080
|
+
function: {
|
|
1081
|
+
name: item.name,
|
|
1082
|
+
arguments: JSON.stringify(item.input),
|
|
1083
|
+
},
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
// Extract thinking blocks — unified format shared with the direct Anthropic provider
|
|
1088
|
+
const thinking_blocks = response.content.reduce((acc, item) => {
|
|
1089
|
+
if (item.type === 'thinking') {
|
|
1090
|
+
acc.push({
|
|
1091
|
+
type: 'thinking',
|
|
1092
|
+
thinking: item.thinking ?? '',
|
|
1093
|
+
...(item.signature && { signature: item.signature }),
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
else if (item.type === 'redacted_thinking') {
|
|
1097
|
+
acc.push({ type: 'redacted_thinking', data: item.data ?? '' });
|
|
1098
|
+
}
|
|
1099
|
+
return acc;
|
|
1100
|
+
}, []);
|
|
1101
|
+
const reasoning_content = thinking_blocks
|
|
1102
|
+
.filter((b) => b.type === 'thinking')
|
|
1103
|
+
.map(b => b.thinking)
|
|
1104
|
+
.join('');
|
|
1105
|
+
// Server-side tool results — extracted the same way as the direct Anthropic provider.
|
|
1106
|
+
const web_search_results = [];
|
|
1107
|
+
const tool_results = [];
|
|
1108
|
+
response.content.forEach(item => {
|
|
1109
|
+
if (item.type === 'web_search_tool_result' || item.type === 'web_fetch_tool_result') {
|
|
1110
|
+
web_search_results.push(item);
|
|
1111
|
+
}
|
|
1112
|
+
else if (item.type === 'bash_code_execution_tool_result' ||
|
|
1113
|
+
item.type === 'text_editor_code_execution_tool_result') {
|
|
1114
|
+
tool_results.push(item);
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
// content_blocks preserves the full response structure for non-strict mode.
|
|
1118
|
+
// Matches direct Anthropic: keep everything except regular tool_use (already in tool_calls).
|
|
1119
|
+
// server_tool_use and *_tool_result blocks are kept so clients that echo back content_blocks
|
|
1120
|
+
// get the correct interleaved ordering on the next turn.
|
|
1121
|
+
const content_blocks = !strictOpenAiCompliance
|
|
1122
|
+
? response.content.filter(item => item.type !== 'tool_use')
|
|
1123
|
+
: undefined;
|
|
1124
|
+
return {
|
|
1125
|
+
id: response.id,
|
|
1126
|
+
object: 'chat.completion',
|
|
1127
|
+
created: Math.floor(Date.now() / 1000),
|
|
1128
|
+
model: response.model,
|
|
1129
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1130
|
+
choices: [
|
|
1131
|
+
{
|
|
1132
|
+
message: {
|
|
1133
|
+
role: 'assistant',
|
|
1134
|
+
content,
|
|
1135
|
+
tool_calls: toolCalls.length ? toolCalls : undefined,
|
|
1136
|
+
...(thinking_blocks.length > 0 && { thinking_blocks }),
|
|
1137
|
+
...(reasoning_content && { reasoning_content }),
|
|
1138
|
+
...(content_blocks?.length && { content_blocks }),
|
|
1139
|
+
...(web_search_results.length > 0 && { web_search_results }),
|
|
1140
|
+
...(tool_results.length > 0 && { tool_results }),
|
|
1141
|
+
},
|
|
1142
|
+
index: 0,
|
|
1143
|
+
logprobs: null,
|
|
1144
|
+
finish_reason: transformFinishReason(response.stop_reason, strictOpenAiCompliance),
|
|
1145
|
+
},
|
|
1146
|
+
],
|
|
1147
|
+
usage: {
|
|
1148
|
+
prompt_tokens: input_tokens + (cache_read_input_tokens ?? 0) + (cache_creation_input_tokens ?? 0),
|
|
1149
|
+
completion_tokens: output_tokens,
|
|
1150
|
+
total_tokens: input_tokens + output_tokens,
|
|
1151
|
+
...(shouldSendCacheUsage && {
|
|
1152
|
+
cache_read_input_tokens: cache_read_input_tokens,
|
|
1153
|
+
cache_creation_input_tokens: cache_creation_input_tokens,
|
|
1154
|
+
}),
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
return generateInvalidProviderResponseError(response, GOOGLE_VERTEX_AI);
|
|
1159
|
+
};
|
|
1160
|
+
export const VertexAnthropicChatCompleteStreamChunkTransform = (responseChunk, fallbackId, streamState, strictOpenAiCompliance) => {
|
|
1161
|
+
let chunk = responseChunk.trim();
|
|
1162
|
+
if (chunk.startsWith('event: ping') || chunk.startsWith('event: vertex_event')) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
if (chunk.startsWith('event: message_stop')) {
|
|
1166
|
+
return 'data: [DONE]\n\n';
|
|
1167
|
+
}
|
|
1168
|
+
// Strip the event: line (including content_block_stop — its data line must be parsed
|
|
1169
|
+
// so the zero-arg tool call handler and state resets fire correctly).
|
|
1170
|
+
chunk = chunk.replace(/^event: content_block_stop[\r\n]*/, '');
|
|
1171
|
+
chunk = chunk.replace(/^event: content_block_delta[\r\n]*/, '');
|
|
1172
|
+
chunk = chunk.replace(/^event: content_block_start[\r\n]*/, '');
|
|
1173
|
+
chunk = chunk.replace(/^event: message_delta[\r\n]*/, '');
|
|
1174
|
+
chunk = chunk.replace(/^event: message_start[\r\n]*/, '');
|
|
1175
|
+
chunk = chunk.replace(/^event: error[\r\n]*/, '');
|
|
1176
|
+
chunk = chunk.replace(/^data: /, '');
|
|
1177
|
+
chunk = chunk.trim();
|
|
1178
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1179
|
+
if (parsedChunk.type === 'error' && parsedChunk.error) {
|
|
1180
|
+
return (`data: ${JSON.stringify({
|
|
1181
|
+
id: fallbackId,
|
|
1182
|
+
object: 'chat.completion.chunk',
|
|
1183
|
+
created: Math.floor(Date.now() / 1000),
|
|
1184
|
+
model: '',
|
|
1185
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1186
|
+
choices: [
|
|
1187
|
+
{
|
|
1188
|
+
finish_reason: parsedChunk.error.type,
|
|
1189
|
+
delta: {
|
|
1190
|
+
content: '',
|
|
1191
|
+
},
|
|
1192
|
+
},
|
|
1193
|
+
],
|
|
1194
|
+
})}` +
|
|
1195
|
+
'\n\n' +
|
|
1196
|
+
'data: [DONE]\n\n');
|
|
1197
|
+
}
|
|
1198
|
+
const shouldSendCacheUsage = parsedChunk.message?.usage?.cache_read_input_tokens || parsedChunk.message?.usage?.cache_creation_input_tokens;
|
|
1199
|
+
if (parsedChunk.type === 'message_start' && parsedChunk.message?.usage) {
|
|
1200
|
+
streamState.model = parsedChunk?.message?.model ?? '';
|
|
1201
|
+
const cacheReadTokens = parsedChunk.message?.usage?.cache_read_input_tokens ?? 0;
|
|
1202
|
+
const cacheCreationTokens = parsedChunk.message?.usage?.cache_creation_input_tokens ?? 0;
|
|
1203
|
+
const promptTokens = (parsedChunk.message.usage?.input_tokens ?? 0) + cacheReadTokens + cacheCreationTokens;
|
|
1204
|
+
streamState.usage = {
|
|
1205
|
+
prompt_tokens: promptTokens,
|
|
1206
|
+
...(shouldSendCacheUsage && {
|
|
1207
|
+
cache_read_input_tokens: cacheReadTokens,
|
|
1208
|
+
cache_creation_input_tokens: cacheCreationTokens,
|
|
1209
|
+
}),
|
|
1210
|
+
};
|
|
1211
|
+
// Read by billing after the stream ends; already cache-inclusive on this path.
|
|
1212
|
+
streamState.promptTokensWithCache = promptTokens;
|
|
1213
|
+
return (`data: ${JSON.stringify({
|
|
1214
|
+
id: fallbackId,
|
|
1215
|
+
object: 'chat.completion.chunk',
|
|
1216
|
+
created: Math.floor(Date.now() / 1000),
|
|
1217
|
+
model: streamState.model,
|
|
1218
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1219
|
+
choices: [
|
|
1220
|
+
{
|
|
1221
|
+
delta: {
|
|
1222
|
+
/*
|
|
1223
|
+
================================
|
|
1224
|
+
NOTE: Keep the message role from the response
|
|
1225
|
+
================================
|
|
1226
|
+
*/
|
|
1227
|
+
role: parsedChunk.message?.role,
|
|
1228
|
+
content: '',
|
|
1229
|
+
},
|
|
1230
|
+
index: 0,
|
|
1231
|
+
logprobs: null,
|
|
1232
|
+
finish_reason: null,
|
|
1233
|
+
},
|
|
1234
|
+
],
|
|
1235
|
+
// Input side only: message_start's output_tokens is a placeholder (1-2), and sending it would
|
|
1236
|
+
// look like complete usage and suppress estimation on a cancelled stream.
|
|
1237
|
+
usage: {
|
|
1238
|
+
prompt_tokens: promptTokens,
|
|
1239
|
+
...(shouldSendCacheUsage && {
|
|
1240
|
+
cache_read_input_tokens: cacheReadTokens,
|
|
1241
|
+
cache_creation_input_tokens: cacheCreationTokens,
|
|
1242
|
+
}),
|
|
1243
|
+
},
|
|
1244
|
+
})}` + '\n\n');
|
|
1245
|
+
}
|
|
1246
|
+
if (parsedChunk.type === 'message_delta' && parsedChunk.usage) {
|
|
1247
|
+
const totalTokens = (streamState?.usage?.prompt_tokens ?? 0) + (parsedChunk.usage.output_tokens ?? 0);
|
|
1248
|
+
return (`data: ${JSON.stringify({
|
|
1249
|
+
id: fallbackId,
|
|
1250
|
+
object: 'chat.completion.chunk',
|
|
1251
|
+
created: Math.floor(Date.now() / 1000),
|
|
1252
|
+
model: streamState.model,
|
|
1253
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1254
|
+
choices: [
|
|
1255
|
+
{
|
|
1256
|
+
index: 0,
|
|
1257
|
+
delta: {
|
|
1258
|
+
// Emit fully assembled thinking_blocks (text + signature) once the stream completes.
|
|
1259
|
+
// Clients can echo these back for multi-turn without reconstructing from partial deltas.
|
|
1260
|
+
...(streamState.thinkingBlocks?.length && { thinking_blocks: streamState.thinkingBlocks }),
|
|
1261
|
+
},
|
|
1262
|
+
finish_reason: transformFinishReason(parsedChunk.delta?.stop_reason, strictOpenAiCompliance),
|
|
1263
|
+
},
|
|
1264
|
+
],
|
|
1265
|
+
usage: {
|
|
1266
|
+
...streamState.usage,
|
|
1267
|
+
completion_tokens: parsedChunk.usage?.output_tokens ?? 0,
|
|
1268
|
+
total_tokens: totalTokens,
|
|
1269
|
+
prompt_tokens_details: {
|
|
1270
|
+
cached_tokens: streamState.usage?.cache_read_input_tokens ?? 0,
|
|
1271
|
+
},
|
|
1272
|
+
},
|
|
1273
|
+
})}` + '\n\n');
|
|
1274
|
+
}
|
|
1275
|
+
const toolCalls = [];
|
|
1276
|
+
// Single unified content_block_start handler — mirrors the direct Anthropic provider exactly.
|
|
1277
|
+
// State must be updated before any early returns so subsequent delta/stop events are consistent.
|
|
1278
|
+
if (parsedChunk.type === 'content_block_start') {
|
|
1279
|
+
streamState.currentContentBlockType = parsedChunk.content_block?.type;
|
|
1280
|
+
streamState.currentToolBlockHasArgs = false;
|
|
1281
|
+
if (parsedChunk.content_block?.type === 'thinking') {
|
|
1282
|
+
streamState.currentThinkingText = '';
|
|
1283
|
+
return undefined;
|
|
1284
|
+
}
|
|
1285
|
+
if (parsedChunk.content_block?.type === 'text') {
|
|
1286
|
+
return undefined;
|
|
1287
|
+
}
|
|
1288
|
+
// Redacted thinking: Anthropic delivers the full data in the content_block_start event
|
|
1289
|
+
// (not in a subsequent delta), same as the direct Anthropic provider.
|
|
1290
|
+
if (parsedChunk.content_block?.type === 'redacted_thinking' && parsedChunk.content_block.data) {
|
|
1291
|
+
const redactedBlock = {
|
|
1292
|
+
type: 'redacted_thinking',
|
|
1293
|
+
data: parsedChunk.content_block.data,
|
|
1294
|
+
};
|
|
1295
|
+
if (!streamState.thinkingBlocks)
|
|
1296
|
+
streamState.thinkingBlocks = [];
|
|
1297
|
+
streamState.thinkingBlocks.push(redactedBlock);
|
|
1298
|
+
return undefined;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
else if (parsedChunk.type === 'content_block_stop') {
|
|
1302
|
+
// Tool block completed with no argument deltas — emit `{}` so the client
|
|
1303
|
+
// receives valid JSON instead of an empty string.
|
|
1304
|
+
if ((streamState.currentContentBlockType === 'tool_use' ||
|
|
1305
|
+
streamState.currentContentBlockType === 'server_tool_use') &&
|
|
1306
|
+
!streamState.currentToolBlockHasArgs) {
|
|
1307
|
+
toolCalls.push({
|
|
1308
|
+
index: streamState.toolIndex,
|
|
1309
|
+
function: { arguments: '{}' },
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
streamState.currentContentBlockType = undefined;
|
|
1313
|
+
streamState.currentToolBlockHasArgs = false;
|
|
1314
|
+
// Only emit a chunk when there is a zero-arg tool call to send; all other block stops
|
|
1315
|
+
// (text, thinking, redacted_thinking, web_search_tool_result, etc.) are silent.
|
|
1316
|
+
// Without this guard a spurious empty SSE chunk is emitted for every non-tool block stop.
|
|
1317
|
+
if (!toolCalls.length)
|
|
1318
|
+
return undefined;
|
|
1319
|
+
}
|
|
1320
|
+
// server_tool_use blocks are treated the same as tool_use for streaming tool call creation.
|
|
1321
|
+
const isToolBlockStart = parsedChunk.type === 'content_block_start' &&
|
|
1322
|
+
(parsedChunk.content_block?.type === 'tool_use' || parsedChunk.content_block?.type === 'server_tool_use');
|
|
1323
|
+
if (isToolBlockStart) {
|
|
1324
|
+
// Increment tool call index for parallel tool calls. The streamState persists across chunks,
|
|
1325
|
+
// so toolIndex tracks the sequential index: undefined → 0 → 1 → 2 → ...
|
|
1326
|
+
// First tool: (undefined ?? -1) + 1 = 0
|
|
1327
|
+
// Second tool: (0 ?? -1) + 1 = 1
|
|
1328
|
+
// Third tool: (1 ?? -1) + 1 = 2
|
|
1329
|
+
// Use nullish coalescing (??) instead of ternary (? : ) because 0 is a valid tool index.
|
|
1330
|
+
// A ternary would treat 0 as falsy and reset to 0, causing all tool calls after the first
|
|
1331
|
+
// to incorrectly get index 0. Nullish coalescing only treats null/undefined as missing.
|
|
1332
|
+
streamState.toolIndex = (streamState.toolIndex ?? -1) + 1;
|
|
1333
|
+
}
|
|
1334
|
+
// Only emit tool_calls for partial_json deltas when inside a tool_use or server_tool_use block.
|
|
1335
|
+
// web_search_tool_result blocks also emit input_json_delta and must not become tool_calls.
|
|
1336
|
+
const isToolBlockDelta = parsedChunk.type === 'content_block_delta' &&
|
|
1337
|
+
parsedChunk.delta?.partial_json != undefined &&
|
|
1338
|
+
(streamState.currentContentBlockType === 'tool_use' || streamState.currentContentBlockType === 'server_tool_use');
|
|
1339
|
+
if (isToolBlockStart && parsedChunk.content_block) {
|
|
1340
|
+
toolCalls.push({
|
|
1341
|
+
index: streamState.toolIndex,
|
|
1342
|
+
id: parsedChunk.content_block.id,
|
|
1343
|
+
type: 'function',
|
|
1344
|
+
function: {
|
|
1345
|
+
name: parsedChunk.content_block.name,
|
|
1346
|
+
arguments: '',
|
|
1347
|
+
},
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
else if (isToolBlockDelta) {
|
|
1351
|
+
streamState.currentToolBlockHasArgs = true;
|
|
1352
|
+
toolCalls.push({
|
|
1353
|
+
index: streamState.toolIndex,
|
|
1354
|
+
function: {
|
|
1355
|
+
arguments: parsedChunk.delta.partial_json ?? '',
|
|
1356
|
+
},
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
// Server-side tool results emitted immediately on the chunk where the block starts,
|
|
1360
|
+
// same as the direct Anthropic provider.
|
|
1361
|
+
let immediateWebSearchResults;
|
|
1362
|
+
let immediateToolResults;
|
|
1363
|
+
if (parsedChunk.type === 'content_block_start' && parsedChunk.content_block) {
|
|
1364
|
+
const cbType = parsedChunk.content_block.type ?? '';
|
|
1365
|
+
if (cbType === 'web_search_tool_result' || cbType === 'web_fetch_tool_result') {
|
|
1366
|
+
if (!streamState.webSearchResults)
|
|
1367
|
+
streamState.webSearchResults = [];
|
|
1368
|
+
const newWebResult = parsedChunk.content_block;
|
|
1369
|
+
streamState.webSearchResults.push(newWebResult);
|
|
1370
|
+
immediateWebSearchResults = [newWebResult];
|
|
1371
|
+
}
|
|
1372
|
+
else if (cbType.endsWith('_tool_result') && cbType !== 'tool_search_tool_result') {
|
|
1373
|
+
if (!streamState.toolResults)
|
|
1374
|
+
streamState.toolResults = [];
|
|
1375
|
+
const newToolResult = parsedChunk.content_block;
|
|
1376
|
+
streamState.toolResults.push(newToolResult);
|
|
1377
|
+
immediateToolResults = [newToolResult];
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const content = parsedChunk.delta?.text;
|
|
1381
|
+
// Handle thinking deltas: accumulate text and capture signature for multi-turn.
|
|
1382
|
+
let thinkingTextDelta;
|
|
1383
|
+
let incomingSignature;
|
|
1384
|
+
if (parsedChunk.type === 'content_block_delta') {
|
|
1385
|
+
if (parsedChunk.delta?.thinking) {
|
|
1386
|
+
thinkingTextDelta = parsedChunk.delta.thinking;
|
|
1387
|
+
streamState.currentThinkingText = (streamState.currentThinkingText ?? '') + thinkingTextDelta;
|
|
1388
|
+
}
|
|
1389
|
+
else if (parsedChunk.delta?.signature) {
|
|
1390
|
+
// Signature delta marks the end of a thinking block. Assemble and store it so it can
|
|
1391
|
+
// be emitted as a complete block in the message_delta chunk.
|
|
1392
|
+
incomingSignature = parsedChunk.delta.signature;
|
|
1393
|
+
const finalThinkingBlock = {
|
|
1394
|
+
type: 'thinking',
|
|
1395
|
+
thinking: streamState.currentThinkingText ?? '',
|
|
1396
|
+
signature: incomingSignature,
|
|
1397
|
+
};
|
|
1398
|
+
if (!streamState.thinkingBlocks)
|
|
1399
|
+
streamState.thinkingBlocks = [];
|
|
1400
|
+
streamState.thinkingBlocks.push(finalThinkingBlock);
|
|
1401
|
+
streamState.currentThinkingText = undefined;
|
|
1402
|
+
}
|
|
1403
|
+
// Note: redacted_thinking data is captured from content_block_start, not from a delta.
|
|
1404
|
+
}
|
|
1405
|
+
return (`data: ${JSON.stringify({
|
|
1406
|
+
id: fallbackId,
|
|
1407
|
+
object: 'chat.completion.chunk',
|
|
1408
|
+
created: Math.floor(Date.now() / 1000),
|
|
1409
|
+
model: streamState.model,
|
|
1410
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1411
|
+
choices: [
|
|
1412
|
+
{
|
|
1413
|
+
delta: {
|
|
1414
|
+
content,
|
|
1415
|
+
// Emit incremental reasoning text for consumers that want a simple string delta
|
|
1416
|
+
...(thinkingTextDelta && { reasoning_content: thinkingTextDelta }),
|
|
1417
|
+
// Emit the signature when it arrives (same as direct Anthropic provider)
|
|
1418
|
+
...(incomingSignature && { reasoning_signature: incomingSignature }),
|
|
1419
|
+
tool_calls: toolCalls.length ? toolCalls : undefined,
|
|
1420
|
+
// Server-side tool results emitted immediately on the chunk where the block starts
|
|
1421
|
+
...(immediateWebSearchResults?.length && { web_search_results: immediateWebSearchResults }),
|
|
1422
|
+
...(immediateToolResults?.length && { tool_results: immediateToolResults }),
|
|
1423
|
+
},
|
|
1424
|
+
index: 0,
|
|
1425
|
+
logprobs: null,
|
|
1426
|
+
finish_reason: parsedChunk.delta?.stop_reason ?? null,
|
|
1427
|
+
},
|
|
1428
|
+
],
|
|
1429
|
+
})}` + '\n\n');
|
|
1430
|
+
};
|
|
1431
|
+
export const VertexLlamaChatCompleteResponseTransform = (response, responseStatus) => {
|
|
1432
|
+
if (responseStatus !== 200 && Array.isArray(response) && response.length > 0 && 'error' in response[0]) {
|
|
1433
|
+
const { error } = response[0];
|
|
1434
|
+
return generateErrorResponse({
|
|
1435
|
+
message: error.message,
|
|
1436
|
+
type: error.status,
|
|
1437
|
+
code: String(error.code),
|
|
1438
|
+
}, GOOGLE_VERTEX_AI);
|
|
1439
|
+
}
|
|
1440
|
+
if ('choices' in response) {
|
|
1441
|
+
return {
|
|
1442
|
+
id: crypto.randomUUID(),
|
|
1443
|
+
created: Math.floor(Date.now() / 1000),
|
|
1444
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1445
|
+
...response,
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
return generateInvalidProviderResponseError(response, GOOGLE_VERTEX_AI);
|
|
1449
|
+
};
|
|
1450
|
+
export const VertexLlamaChatCompleteStreamChunkTransform = (responseChunk, fallbackId) => {
|
|
1451
|
+
let chunk = responseChunk.trim();
|
|
1452
|
+
chunk = chunk.replace(/^data: /, '');
|
|
1453
|
+
chunk = chunk.trim();
|
|
1454
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1455
|
+
parsedChunk.id = fallbackId;
|
|
1456
|
+
parsedChunk.created = Math.floor(Date.now() / 1000);
|
|
1457
|
+
parsedChunk.provider = GOOGLE_VERTEX_AI;
|
|
1458
|
+
return `data: ${JSON.stringify(parsedChunk)}` + '\n\n';
|
|
1459
|
+
};
|
|
1460
|
+
/**
|
|
1461
|
+
* ================================
|
|
1462
|
+
* NOTE: Add OpenAI OSS response transform functions
|
|
1463
|
+
* ================================
|
|
1464
|
+
*/
|
|
1465
|
+
export const VertexOpenAICompatibleChatCompleteResponseTransform = (response, responseStatus) => {
|
|
1466
|
+
if (responseStatus !== 200 && Array.isArray(response) && response.length > 0 && 'error' in response[0]) {
|
|
1467
|
+
const { error } = response[0];
|
|
1468
|
+
return generateErrorResponse({
|
|
1469
|
+
message: error.message,
|
|
1470
|
+
type: error.status,
|
|
1471
|
+
code: String(error.code),
|
|
1472
|
+
}, GOOGLE_VERTEX_AI);
|
|
1473
|
+
}
|
|
1474
|
+
if (!Array.isArray(response) && 'choices' in response) {
|
|
1475
|
+
const resRecord = response;
|
|
1476
|
+
const geminiUm = readGeminiUsageMetadataFromOpenAICompatPayload(resRecord);
|
|
1477
|
+
const mergedUsage = geminiUm
|
|
1478
|
+
? enrichOpenAIShapedUsageWithGeminiImageTokens(resRecord.usage, geminiUm)
|
|
1479
|
+
: resRecord.usage;
|
|
1480
|
+
return {
|
|
1481
|
+
...resRecord,
|
|
1482
|
+
id: response.id || crypto.randomUUID(),
|
|
1483
|
+
object: response.object || 'chat.completion',
|
|
1484
|
+
created: response.created || Math.floor(Date.now() / 1000),
|
|
1485
|
+
model: response.model || '',
|
|
1486
|
+
provider: GOOGLE_VERTEX_AI,
|
|
1487
|
+
usage: mergedUsage,
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
return generateInvalidProviderResponseError(response, GOOGLE_VERTEX_AI);
|
|
1491
|
+
};
|
|
1492
|
+
export const VertexOpenAICompatibleChatCompleteStreamChunkTransform = (responseChunk, fallbackId) => {
|
|
1493
|
+
let chunk = responseChunk.trim();
|
|
1494
|
+
if (chunk === 'data: [DONE]') {
|
|
1495
|
+
return chunk + '\n\n';
|
|
1496
|
+
}
|
|
1497
|
+
chunk = chunk.replace(/^data: /, '');
|
|
1498
|
+
chunk = chunk.trim();
|
|
1499
|
+
if (!chunk) {
|
|
1500
|
+
return '';
|
|
1501
|
+
}
|
|
1502
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1503
|
+
const geminiUm = readGeminiUsageMetadataFromOpenAICompatPayload(parsedChunk);
|
|
1504
|
+
if (geminiUm !== undefined && parsedChunk.usage !== undefined) {
|
|
1505
|
+
parsedChunk.usage = enrichOpenAIShapedUsageWithGeminiImageTokens(parsedChunk.usage, geminiUm);
|
|
1506
|
+
}
|
|
1507
|
+
parsedChunk.id = parsedChunk.id || fallbackId;
|
|
1508
|
+
parsedChunk.created = parsedChunk.created || Math.floor(Date.now() / 1000);
|
|
1509
|
+
parsedChunk.provider = GOOGLE_VERTEX_AI;
|
|
1510
|
+
return `data: ${JSON.stringify(parsedChunk)}` + '\n\n';
|
|
1511
|
+
};
|
|
1512
|
+
//# sourceMappingURL=chatComplete.js.map
|