@llumiverse/drivers 1.3.0 → 1.4.0-dev.20260629.090753Z
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/lib/{types/adobe → adobe}/firefly.d.ts +2 -1
- package/lib/adobe/firefly.d.ts.map +1 -0
- package/lib/adobe/firefly.js +120 -0
- package/lib/adobe/firefly.js.map +1 -0
- package/lib/{types/anthropic → anthropic}/index.d.ts +4 -2
- package/lib/anthropic/index.d.ts.map +1 -0
- package/lib/{esm/anthropic → anthropic}/index.js +19 -8
- package/lib/anthropic/index.js.map +1 -0
- package/lib/{types/azure → azure}/azure_foundry.d.ts +9 -7
- package/lib/azure/azure_foundry.d.ts.map +1 -0
- package/lib/{esm/azure → azure}/azure_foundry.js +138 -124
- package/lib/azure/azure_foundry.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/converse.d.ts +2 -2
- package/lib/bedrock/converse.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/converse.js +86 -79
- package/lib/bedrock/converse.js.map +1 -0
- package/lib/bedrock/embeddings.d.ts +4 -0
- package/lib/bedrock/embeddings.d.ts.map +1 -0
- package/lib/bedrock/embeddings.js +359 -0
- package/lib/bedrock/embeddings.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/index.d.ts +33 -9
- package/lib/bedrock/index.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/index.js +599 -324
- package/lib/bedrock/index.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/nova-image-payload.d.ts +5 -5
- package/lib/bedrock/nova-image-payload.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/nova-image-payload.js +31 -36
- package/lib/bedrock/nova-image-payload.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/payloads.d.ts +1 -1
- package/lib/bedrock/payloads.d.ts.map +1 -0
- package/lib/{cjs/bedrock → bedrock}/payloads.js.map +1 -1
- package/lib/{types/bedrock → bedrock}/s3.d.ts +3 -2
- package/lib/bedrock/s3.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/s3.js +27 -23
- package/lib/bedrock/s3.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/twelvelabs.d.ts +8 -9
- package/lib/bedrock/twelvelabs.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/twelvelabs.js +17 -21
- package/lib/bedrock/twelvelabs.js.map +1 -0
- package/lib/{types/groq → groq}/index.d.ts +6 -4
- package/lib/groq/index.d.ts.map +1 -0
- package/lib/{esm/groq → groq}/index.js +72 -39
- package/lib/groq/index.js.map +1 -0
- package/lib/{types/huggingface_ie.d.ts → huggingface_ie.d.ts} +4 -3
- package/lib/huggingface_ie.d.ts.map +1 -0
- package/lib/{esm/huggingface_ie.js → huggingface_ie.js} +32 -31
- package/lib/huggingface_ie.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/{types/mistral → mistral}/index.d.ts +6 -5
- package/lib/mistral/index.d.ts.map +1 -0
- package/lib/{esm/mistral → mistral}/index.js +66 -38
- package/lib/mistral/index.js.map +1 -0
- package/lib/{types/mistral → mistral}/types.d.ts +1 -0
- package/lib/mistral/types.d.ts.map +1 -0
- package/lib/mistral/types.js.map +1 -0
- package/lib/{types/openai → openai}/azure_openai.d.ts +5 -4
- package/lib/openai/azure_openai.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/azure_openai.js +17 -14
- package/lib/openai/azure_openai.js.map +1 -0
- package/lib/openai/drivers.d.ts +4 -0
- package/lib/openai/drivers.d.ts.map +1 -0
- package/lib/openai/drivers.js +9 -0
- package/lib/openai/drivers.js.map +1 -0
- package/lib/{types/openai → openai}/index.d.ts +16 -5
- package/lib/openai/index.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/index.js +242 -141
- package/lib/openai/index.js.map +1 -0
- package/lib/{types/openai → openai}/openai.d.ts +3 -3
- package/lib/openai/openai.d.ts.map +1 -0
- package/lib/openai/openai.js +15 -0
- package/lib/openai/openai.js.map +1 -0
- package/lib/{types/openai → openai}/openai_compatible.d.ts +3 -3
- package/lib/openai/openai_compatible.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/openai_compatible.js +14 -11
- package/lib/openai/openai_compatible.js.map +1 -0
- package/lib/{types/openai → openai}/openai_format.d.ts +3 -2
- package/lib/openai/openai_format.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/openai_format.js +66 -24
- package/lib/openai/openai_format.js.map +1 -0
- package/lib/{types/replicate.d.ts → replicate.d.ts} +3 -2
- package/lib/replicate.d.ts.map +1 -0
- package/lib/{esm/replicate.js → replicate.js} +59 -49
- package/lib/replicate.js.map +1 -0
- package/lib/{types/shared → shared}/claude-messages.d.ts +25 -1
- package/lib/shared/claude-messages.d.ts.map +1 -0
- package/lib/{esm/shared → shared}/claude-messages.js +212 -59
- package/lib/shared/claude-messages.js.map +1 -0
- package/lib/{types/shared → shared}/claude-thinking.d.ts +1 -1
- package/lib/shared/claude-thinking.d.ts.map +1 -0
- package/lib/{esm/shared → shared}/claude-thinking.js +5 -7
- package/lib/shared/claude-thinking.js.map +1 -0
- package/lib/shared/debug-prompt.d.ts +5 -0
- package/lib/shared/debug-prompt.d.ts.map +1 -0
- package/lib/shared/debug-prompt.js +25 -0
- package/lib/shared/debug-prompt.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/TestErrorCompletionStream.d.ts +1 -1
- package/lib/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
- package/lib/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/TestValidationErrorCompletionStream.d.ts +1 -1
- package/lib/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/TestValidationErrorCompletionStream.js +4 -4
- package/lib/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/index.d.ts +3 -3
- package/lib/test-driver/index.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/index.js +20 -20
- package/lib/test-driver/index.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/utils.d.ts +1 -1
- package/lib/test-driver/utils.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/utils.js +4 -4
- package/lib/test-driver/utils.js.map +1 -0
- package/lib/togetherai/index.d.ts +15 -0
- package/lib/togetherai/index.d.ts.map +1 -0
- package/lib/togetherai/index.js +54 -0
- package/lib/togetherai/index.js.map +1 -0
- package/lib/{types/togetherai → togetherai}/interfaces.d.ts +1 -1
- package/lib/togetherai/interfaces.d.ts.map +1 -0
- package/lib/{cjs/watsonx → togetherai}/interfaces.js.map +1 -1
- package/lib/vertexai/debug.d.ts +2 -0
- package/lib/vertexai/debug.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/debug.js +1 -1
- package/lib/vertexai/debug.js.map +1 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts +9 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts.map +1 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.js +141 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.js.map +1 -0
- package/lib/vertexai/embeddings/embed.d.ts +13 -0
- package/lib/vertexai/embeddings/embed.d.ts.map +1 -0
- package/lib/vertexai/embeddings/embed.js +162 -0
- package/lib/vertexai/embeddings/embed.js.map +1 -0
- package/lib/vertexai/embeddings/source-utils.d.ts +9 -0
- package/lib/vertexai/embeddings/source-utils.d.ts.map +1 -0
- package/lib/vertexai/embeddings/source-utils.js +18 -0
- package/lib/vertexai/embeddings/source-utils.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/index.d.ts +31 -19
- package/lib/vertexai/index.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/index.js +221 -159
- package/lib/vertexai/index.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/claude.d.ts +4 -4
- package/lib/vertexai/models/claude.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/claude.js +17 -20
- package/lib/vertexai/models/claude.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/gemini.d.ts +28 -4
- package/lib/vertexai/models/gemini.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/gemini.js +238 -116
- package/lib/vertexai/models/gemini.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/imagen.d.ts +12 -11
- package/lib/vertexai/models/imagen.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/imagen.js +74 -47
- package/lib/vertexai/models/imagen.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/llama.d.ts +4 -4
- package/lib/vertexai/models/llama.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/llama.js +37 -33
- package/lib/vertexai/models/llama.js.map +1 -0
- package/lib/vertexai/models.d.ts +21 -0
- package/lib/vertexai/models.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models.js +12 -9
- package/lib/vertexai/models.js.map +1 -0
- package/lib/{types/watsonx → watsonx}/index.d.ts +4 -3
- package/lib/watsonx/index.d.ts.map +1 -0
- package/lib/{esm/watsonx → watsonx}/index.js +69 -41
- package/lib/watsonx/index.js.map +1 -0
- package/lib/watsonx/interfaces.d.ts.map +1 -0
- package/lib/{esm/watsonx → watsonx}/interfaces.js.map +1 -1
- package/lib/{types/xai → xai}/index.d.ts +4 -4
- package/lib/xai/index.d.ts.map +1 -0
- package/lib/{esm/xai → xai}/index.js +22 -18
- package/lib/xai/index.js.map +1 -0
- package/package.json +87 -36
- package/src/adobe/firefly.ts +60 -43
- package/src/anthropic/index.ts +37 -20
- package/src/azure/azure_foundry.ts +210 -165
- package/src/bedrock/converse.ts +124 -101
- package/src/bedrock/embeddings.test.ts +508 -0
- package/src/bedrock/embeddings.ts +517 -0
- package/src/bedrock/error-handling.test.ts +62 -14
- package/src/bedrock/index.ts +832 -466
- package/src/bedrock/nova-image-payload.ts +98 -91
- package/src/bedrock/payloads.ts +9 -9
- package/src/bedrock/s3.test.ts +39 -0
- package/src/bedrock/s3.ts +57 -38
- package/src/bedrock/streaming-tool-use.test.ts +86 -69
- package/src/bedrock/twelvelabs.ts +35 -32
- package/src/groq/index.ts +143 -60
- package/src/http-timeout-wiring.test.ts +263 -0
- package/src/huggingface_ie.ts +45 -61
- package/src/index.ts +15 -16
- package/src/mistral/index.ts +97 -48
- package/src/mistral/types.ts +13 -12
- package/src/openai/azure_openai.ts +35 -27
- package/src/openai/drivers.ts +9 -0
- package/src/openai/error-handling.test.ts +308 -113
- package/src/openai/index.ts +378 -248
- package/src/openai/openai.ts +6 -13
- package/src/openai/openai_compatible.ts +35 -25
- package/src/openai/openai_format.ts +90 -40
- package/src/replicate.ts +108 -86
- package/src/shared/claude-messages.test.ts +37 -0
- package/src/shared/claude-messages.ts +303 -97
- package/src/shared/claude-thinking.ts +6 -12
- package/src/shared/debug-prompt.ts +28 -0
- package/src/test-driver/TestErrorCompletionStream.ts +9 -10
- package/src/test-driver/TestValidationErrorCompletionStream.ts +9 -10
- package/src/test-driver/index.ts +43 -27
- package/src/test-driver/utils.ts +8 -8
- package/src/togetherai/index.test.ts +32 -0
- package/src/togetherai/index.ts +64 -128
- package/src/togetherai/interfaces.ts +5 -5
- package/src/vertexai/debug.ts +3 -3
- package/src/vertexai/embeddings/embed-legacy-multimodal.ts +211 -0
- package/src/vertexai/embeddings/embed.ts +206 -0
- package/src/vertexai/embeddings/embeddings.test.ts +497 -0
- package/src/vertexai/embeddings/source-utils.test.ts +54 -0
- package/src/vertexai/embeddings/source-utils.ts +29 -0
- package/src/vertexai/index.ts +331 -244
- package/src/vertexai/models/claude-error-handling.test.ts +83 -36
- package/src/vertexai/models/claude-streaming-spacing.test.ts +82 -75
- package/src/vertexai/models/claude.ts +55 -40
- package/src/vertexai/models/gemini-conversation-mutation.test.ts +65 -23
- package/src/vertexai/models/gemini-error-handling.test.ts +126 -10
- package/src/vertexai/models/gemini-orphaned-tool-result.test.ts +118 -0
- package/src/vertexai/models/gemini.ts +349 -172
- package/src/vertexai/models/imagen.ts +164 -100
- package/src/vertexai/models/llama.ts +70 -48
- package/src/vertexai/models.ts +36 -16
- package/src/watsonx/index.ts +101 -65
- package/src/watsonx/interfaces.ts +10 -15
- package/src/xai/index.ts +30 -30
- package/lib/cjs/adobe/firefly.js +0 -120
- package/lib/cjs/adobe/firefly.js.map +0 -1
- package/lib/cjs/anthropic/index.js +0 -64
- package/lib/cjs/anthropic/index.js.map +0 -1
- package/lib/cjs/azure/azure_foundry.js +0 -432
- package/lib/cjs/azure/azure_foundry.js.map +0 -1
- package/lib/cjs/bedrock/converse.js +0 -359
- package/lib/cjs/bedrock/converse.js.map +0 -1
- package/lib/cjs/bedrock/index.js +0 -1508
- package/lib/cjs/bedrock/index.js.map +0 -1
- package/lib/cjs/bedrock/nova-image-payload.js +0 -207
- package/lib/cjs/bedrock/nova-image-payload.js.map +0 -1
- package/lib/cjs/bedrock/payloads.js +0 -3
- package/lib/cjs/bedrock/s3.js +0 -107
- package/lib/cjs/bedrock/s3.js.map +0 -1
- package/lib/cjs/bedrock/twelvelabs.js +0 -87
- package/lib/cjs/bedrock/twelvelabs.js.map +0 -1
- package/lib/cjs/groq/index.js +0 -328
- package/lib/cjs/groq/index.js.map +0 -1
- package/lib/cjs/huggingface_ie.js +0 -201
- package/lib/cjs/huggingface_ie.js.map +0 -1
- package/lib/cjs/index.js +0 -32
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/mistral/index.js +0 -176
- package/lib/cjs/mistral/index.js.map +0 -1
- package/lib/cjs/mistral/types.js +0 -83
- package/lib/cjs/mistral/types.js.map +0 -1
- package/lib/cjs/openai/azure_openai.js +0 -72
- package/lib/cjs/openai/azure_openai.js.map +0 -1
- package/lib/cjs/openai/index.js +0 -1135
- package/lib/cjs/openai/index.js.map +0 -1
- package/lib/cjs/openai/openai.js +0 -21
- package/lib/cjs/openai/openai.js.map +0 -1
- package/lib/cjs/openai/openai_compatible.js +0 -63
- package/lib/cjs/openai/openai_compatible.js.map +0 -1
- package/lib/cjs/openai/openai_format.js +0 -131
- package/lib/cjs/openai/openai_format.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/replicate.js +0 -275
- package/lib/cjs/replicate.js.map +0 -1
- package/lib/cjs/shared/claude-messages.js +0 -737
- package/lib/cjs/shared/claude-messages.js.map +0 -1
- package/lib/cjs/shared/claude-thinking.js +0 -60
- package/lib/cjs/shared/claude-thinking.js.map +0 -1
- package/lib/cjs/test-driver/TestErrorCompletionStream.js +0 -20
- package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +0 -1
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +0 -24
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
- package/lib/cjs/test-driver/index.js +0 -109
- package/lib/cjs/test-driver/index.js.map +0 -1
- package/lib/cjs/test-driver/utils.js +0 -30
- package/lib/cjs/test-driver/utils.js.map +0 -1
- package/lib/cjs/togetherai/index.js +0 -126
- package/lib/cjs/togetherai/index.js.map +0 -1
- package/lib/cjs/togetherai/interfaces.js +0 -3
- package/lib/cjs/togetherai/interfaces.js.map +0 -1
- package/lib/cjs/vertexai/debug.js +0 -12
- package/lib/cjs/vertexai/debug.js.map +0 -1
- package/lib/cjs/vertexai/embeddings/embeddings-image.js +0 -27
- package/lib/cjs/vertexai/embeddings/embeddings-image.js.map +0 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js +0 -23
- package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +0 -1
- package/lib/cjs/vertexai/index.js +0 -644
- package/lib/cjs/vertexai/index.js.map +0 -1
- package/lib/cjs/vertexai/models/claude.js +0 -72
- package/lib/cjs/vertexai/models/claude.js.map +0 -1
- package/lib/cjs/vertexai/models/gemini.js +0 -864
- package/lib/cjs/vertexai/models/gemini.js.map +0 -1
- package/lib/cjs/vertexai/models/imagen.js +0 -303
- package/lib/cjs/vertexai/models/imagen.js.map +0 -1
- package/lib/cjs/vertexai/models/llama.js +0 -183
- package/lib/cjs/vertexai/models/llama.js.map +0 -1
- package/lib/cjs/vertexai/models.js +0 -35
- package/lib/cjs/vertexai/models.js.map +0 -1
- package/lib/cjs/watsonx/index.js +0 -161
- package/lib/cjs/watsonx/index.js.map +0 -1
- package/lib/cjs/watsonx/interfaces.js +0 -3
- package/lib/cjs/xai/index.js +0 -65
- package/lib/cjs/xai/index.js.map +0 -1
- package/lib/esm/adobe/firefly.js +0 -116
- package/lib/esm/adobe/firefly.js.map +0 -1
- package/lib/esm/anthropic/index.js.map +0 -1
- package/lib/esm/azure/azure_foundry.js.map +0 -1
- package/lib/esm/bedrock/converse.js.map +0 -1
- package/lib/esm/bedrock/index.js.map +0 -1
- package/lib/esm/bedrock/nova-image-payload.js.map +0 -1
- package/lib/esm/bedrock/payloads.js.map +0 -1
- package/lib/esm/bedrock/s3.js.map +0 -1
- package/lib/esm/bedrock/twelvelabs.js.map +0 -1
- package/lib/esm/groq/index.js.map +0 -1
- package/lib/esm/huggingface_ie.js.map +0 -1
- package/lib/esm/index.js +0 -16
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/mistral/index.js.map +0 -1
- package/lib/esm/mistral/types.js.map +0 -1
- package/lib/esm/openai/azure_openai.js.map +0 -1
- package/lib/esm/openai/index.js.map +0 -1
- package/lib/esm/openai/openai.js +0 -14
- package/lib/esm/openai/openai.js.map +0 -1
- package/lib/esm/openai/openai_compatible.js.map +0 -1
- package/lib/esm/openai/openai_format.js.map +0 -1
- package/lib/esm/replicate.js.map +0 -1
- package/lib/esm/shared/claude-messages.js.map +0 -1
- package/lib/esm/shared/claude-thinking.js.map +0 -1
- package/lib/esm/test-driver/TestErrorCompletionStream.js +0 -16
- package/lib/esm/test-driver/TestErrorCompletionStream.js.map +0 -1
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
- package/lib/esm/test-driver/index.js.map +0 -1
- package/lib/esm/test-driver/utils.js.map +0 -1
- package/lib/esm/togetherai/index.js +0 -122
- package/lib/esm/togetherai/index.js.map +0 -1
- package/lib/esm/togetherai/interfaces.js.map +0 -1
- package/lib/esm/vertexai/debug.js.map +0 -1
- package/lib/esm/vertexai/embeddings/embeddings-image.js +0 -24
- package/lib/esm/vertexai/embeddings/embeddings-image.js.map +0 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js +0 -20
- package/lib/esm/vertexai/embeddings/embeddings-text.js.map +0 -1
- package/lib/esm/vertexai/index.js.map +0 -1
- package/lib/esm/vertexai/models/claude.js.map +0 -1
- package/lib/esm/vertexai/models/gemini.js.map +0 -1
- package/lib/esm/vertexai/models/imagen.js.map +0 -1
- package/lib/esm/vertexai/models/llama.js.map +0 -1
- package/lib/esm/vertexai/models.js.map +0 -1
- package/lib/esm/watsonx/index.js.map +0 -1
- package/lib/esm/xai/index.js.map +0 -1
- package/lib/types/adobe/firefly.d.ts.map +0 -1
- package/lib/types/anthropic/index.d.ts.map +0 -1
- package/lib/types/azure/azure_foundry.d.ts.map +0 -1
- package/lib/types/bedrock/converse.d.ts.map +0 -1
- package/lib/types/bedrock/index.d.ts.map +0 -1
- package/lib/types/bedrock/nova-image-payload.d.ts.map +0 -1
- package/lib/types/bedrock/payloads.d.ts.map +0 -1
- package/lib/types/bedrock/s3.d.ts.map +0 -1
- package/lib/types/bedrock/twelvelabs.d.ts.map +0 -1
- package/lib/types/groq/index.d.ts.map +0 -1
- package/lib/types/huggingface_ie.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -16
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/mistral/index.d.ts.map +0 -1
- package/lib/types/mistral/types.d.ts.map +0 -1
- package/lib/types/openai/azure_openai.d.ts.map +0 -1
- package/lib/types/openai/index.d.ts.map +0 -1
- package/lib/types/openai/openai.d.ts.map +0 -1
- package/lib/types/openai/openai_compatible.d.ts.map +0 -1
- package/lib/types/openai/openai_format.d.ts.map +0 -1
- package/lib/types/replicate.d.ts.map +0 -1
- package/lib/types/shared/claude-messages.d.ts.map +0 -1
- package/lib/types/shared/claude-thinking.d.ts.map +0 -1
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +0 -1
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +0 -1
- package/lib/types/test-driver/index.d.ts.map +0 -1
- package/lib/types/test-driver/utils.d.ts.map +0 -1
- package/lib/types/togetherai/index.d.ts +0 -23
- package/lib/types/togetherai/index.d.ts.map +0 -1
- package/lib/types/togetherai/interfaces.d.ts.map +0 -1
- package/lib/types/vertexai/debug.d.ts +0 -2
- package/lib/types/vertexai/debug.d.ts.map +0 -1
- package/lib/types/vertexai/embeddings/embeddings-image.d.ts +0 -11
- package/lib/types/vertexai/embeddings/embeddings-image.d.ts.map +0 -1
- package/lib/types/vertexai/embeddings/embeddings-text.d.ts +0 -10
- package/lib/types/vertexai/embeddings/embeddings-text.d.ts.map +0 -1
- package/lib/types/vertexai/index.d.ts.map +0 -1
- package/lib/types/vertexai/models/claude.d.ts.map +0 -1
- package/lib/types/vertexai/models/gemini.d.ts.map +0 -1
- package/lib/types/vertexai/models/imagen.d.ts.map +0 -1
- package/lib/types/vertexai/models/llama.d.ts.map +0 -1
- package/lib/types/vertexai/models.d.ts +0 -20
- package/lib/types/vertexai/models.d.ts.map +0 -1
- package/lib/types/watsonx/index.d.ts.map +0 -1
- package/lib/types/watsonx/interfaces.d.ts.map +0 -1
- package/lib/types/xai/index.d.ts.map +0 -1
- package/src/vertexai/embeddings/embeddings-image.ts +0 -52
- package/src/vertexai/embeddings/embeddings-text.ts +0 -54
- /package/lib/{esm/bedrock → bedrock}/payloads.js +0 -0
- /package/lib/{esm/mistral → mistral}/types.js +0 -0
- /package/lib/{esm/togetherai → togetherai}/interfaces.js +0 -0
- /package/lib/{types/watsonx → watsonx}/interfaces.d.ts +0 -0
- /package/lib/{esm/watsonx → watsonx}/interfaces.js +0 -0
|
@@ -34,10 +34,7 @@ import type {
|
|
|
34
34
|
ToolResultBlockParam,
|
|
35
35
|
} from '@anthropic-ai/sdk/resources/index.js';
|
|
36
36
|
import type { MessageStreamParams } from '@anthropic-ai/sdk/resources/index.mjs';
|
|
37
|
-
import type {
|
|
38
|
-
MessageCreateParamsBase,
|
|
39
|
-
RawMessageStreamEvent,
|
|
40
|
-
} from '@anthropic-ai/sdk/resources/messages.js';
|
|
37
|
+
import type { MessageCreateParamsBase, RawMessageStreamEvent } from '@anthropic-ai/sdk/resources/messages.js';
|
|
41
38
|
import type AnthropicVertex from '@anthropic-ai/vertex-sdk';
|
|
42
39
|
import { getClaudeMaxTokensLimit } from '@llumiverse/common';
|
|
43
40
|
import {
|
|
@@ -63,16 +60,62 @@ import {
|
|
|
63
60
|
} from '@llumiverse/core';
|
|
64
61
|
import { asyncMap } from '@llumiverse/core/async';
|
|
65
62
|
import { resolveClaudeThinking } from './claude-thinking.js';
|
|
63
|
+
import { truncateBinaryForDebug } from './debug-prompt.js';
|
|
66
64
|
|
|
67
65
|
// ============================================================================
|
|
68
66
|
// Types
|
|
69
67
|
// ============================================================================
|
|
70
68
|
|
|
69
|
+
// Conversation text-trim policy (applied only when the caller requests text
|
|
70
|
+
// trimming via stripTextMaxTokens). Keep the last N messages fully intact (the
|
|
71
|
+
// active working set) and cap large text in older messages at the token ceiling
|
|
72
|
+
// below — so long agent conversations don't balloon context.
|
|
73
|
+
const KEEP_RECENT_MESSAGES = 12;
|
|
74
|
+
const OLD_MESSAGE_TEXT_MAX_TOKENS = 2000;
|
|
75
|
+
|
|
76
|
+
interface WarnLogger {
|
|
77
|
+
warn: (data: Record<string, unknown>, message: string) => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
71
80
|
export interface ClaudePrompt {
|
|
72
81
|
messages: MessageParam[];
|
|
73
82
|
system?: TextBlockParam[];
|
|
74
83
|
}
|
|
75
84
|
|
|
85
|
+
function formatClaudeContentBlockForDebug(block: ContentBlockParam): ContentBlockParam {
|
|
86
|
+
if (block.type === 'image' && block.source.type === 'base64') {
|
|
87
|
+
return {
|
|
88
|
+
...block,
|
|
89
|
+
source: {
|
|
90
|
+
...block.source,
|
|
91
|
+
data: truncateBinaryForDebug(block.source.data),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (block.type === 'document' && block.source.type === 'base64') {
|
|
96
|
+
return {
|
|
97
|
+
...block,
|
|
98
|
+
source: {
|
|
99
|
+
...block.source,
|
|
100
|
+
data: truncateBinaryForDebug(block.source.data),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return block;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function formatClaudeDebugPrompt(prompt: ClaudePrompt): ClaudePrompt {
|
|
108
|
+
return {
|
|
109
|
+
...prompt,
|
|
110
|
+
messages: prompt.messages.map((message) => ({
|
|
111
|
+
...message,
|
|
112
|
+
content: Array.isArray(message.content)
|
|
113
|
+
? message.content.map(formatClaudeContentBlockForDebug)
|
|
114
|
+
: message.content,
|
|
115
|
+
})),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
76
119
|
export interface AnthropicUsageLike {
|
|
77
120
|
input_tokens: number;
|
|
78
121
|
output_tokens: number;
|
|
@@ -103,6 +146,25 @@ interface RequestOptions {
|
|
|
103
146
|
}
|
|
104
147
|
|
|
105
148
|
type ClaudeTool = NonNullable<MessageCreateParamsBase['tools']>[number];
|
|
149
|
+
type ClaudeMessageStream = AsyncIterable<RawMessageStreamEvent> & {
|
|
150
|
+
finalMessage(): Promise<Message>;
|
|
151
|
+
};
|
|
152
|
+
type ClaudeMessagesStreamClient = {
|
|
153
|
+
messages: {
|
|
154
|
+
stream(body: MessageStreamParams, options?: RequestOptions): ClaudeMessageStream;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
function streamClaudeMessages(
|
|
159
|
+
client: Anthropic | AnthropicVertex,
|
|
160
|
+
payload: MessageStreamParams,
|
|
161
|
+
requestOptions: RequestOptions | undefined,
|
|
162
|
+
): Promise<ClaudeMessageStream> {
|
|
163
|
+
// AnthropicVertex intentionally wraps the Anthropic Messages API, but it depends on its
|
|
164
|
+
// own @anthropic-ai/sdk copy. Cast at the boundary so the implementation can call the
|
|
165
|
+
// shared runtime-compatible stream API without TS trying to call a union of SDK versions.
|
|
166
|
+
return Promise.resolve((client as unknown as ClaudeMessagesStreamClient).messages.stream(payload, requestOptions));
|
|
167
|
+
}
|
|
106
168
|
|
|
107
169
|
// ============================================================================
|
|
108
170
|
// Token usage
|
|
@@ -128,9 +190,12 @@ export function anthropicUsageToTokenUsage(usage: AnthropicUsageLike): Execution
|
|
|
128
190
|
export function claudeFinishReason(reason: string | undefined): string | undefined {
|
|
129
191
|
if (!reason) return undefined;
|
|
130
192
|
switch (reason) {
|
|
131
|
-
case 'end_turn':
|
|
132
|
-
|
|
133
|
-
|
|
193
|
+
case 'end_turn':
|
|
194
|
+
return 'stop';
|
|
195
|
+
case 'max_tokens':
|
|
196
|
+
return 'length';
|
|
197
|
+
default:
|
|
198
|
+
return reason; // stop_sequence, tool_use
|
|
134
199
|
}
|
|
135
200
|
}
|
|
136
201
|
|
|
@@ -198,10 +263,11 @@ export function claudeMaxTokens(option: StatelessExecutionOptions): number {
|
|
|
198
263
|
// File / multimodal block helpers
|
|
199
264
|
// ============================================================================
|
|
200
265
|
|
|
201
|
-
async function collectFileBlocks(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
266
|
+
async function collectFileBlocks(
|
|
267
|
+
segment: PromptSegment,
|
|
268
|
+
logger?: WarnLogger,
|
|
269
|
+
): Promise<Array<TextBlockParam | ImageBlockParam | DocumentBlockParam>> {
|
|
270
|
+
const contentBlocks: Array<TextBlockParam | ImageBlockParam | DocumentBlockParam> = [];
|
|
205
271
|
|
|
206
272
|
for (const file of segment.files || []) {
|
|
207
273
|
if (file.mime_type?.startsWith('image/')) {
|
|
@@ -218,28 +284,34 @@ async function collectFileBlocks(segment: PromptSegment, restrictedTypes = false
|
|
|
218
284
|
media_type: mimeType,
|
|
219
285
|
},
|
|
220
286
|
} satisfies ImageBlockParam);
|
|
221
|
-
} else if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
287
|
+
} else if (file.mime_type?.startsWith('video/')) {
|
|
288
|
+
logger?.warn(
|
|
289
|
+
{
|
|
290
|
+
file_name: file.name,
|
|
291
|
+
mime_type: file.mime_type,
|
|
292
|
+
},
|
|
293
|
+
'[Claude] Skipping unsupported video attachment',
|
|
294
|
+
);
|
|
295
|
+
} else if (file.mime_type === 'application/pdf') {
|
|
296
|
+
contentBlocks.push({
|
|
297
|
+
title: file.name,
|
|
298
|
+
type: 'document',
|
|
299
|
+
source: {
|
|
300
|
+
type: 'base64',
|
|
301
|
+
data: await readStreamAsBase64(await file.getStream()),
|
|
302
|
+
media_type: 'application/pdf',
|
|
303
|
+
},
|
|
304
|
+
} satisfies DocumentBlockParam);
|
|
305
|
+
} else if (file.mime_type?.startsWith('text/')) {
|
|
306
|
+
contentBlocks.push({
|
|
307
|
+
title: file.name,
|
|
308
|
+
type: 'document',
|
|
309
|
+
source: {
|
|
310
|
+
type: 'text',
|
|
311
|
+
data: await readStreamAsString(await file.getStream()),
|
|
312
|
+
media_type: 'text/plain',
|
|
313
|
+
},
|
|
314
|
+
} satisfies DocumentBlockParam);
|
|
243
315
|
}
|
|
244
316
|
}
|
|
245
317
|
|
|
@@ -250,15 +322,20 @@ async function collectFileBlocks(segment: PromptSegment, restrictedTypes = false
|
|
|
250
322
|
// Prompt formatting (PromptSegment[] → ClaudePrompt)
|
|
251
323
|
// ============================================================================
|
|
252
324
|
|
|
253
|
-
export async function formatClaudePrompt(
|
|
325
|
+
export async function formatClaudePrompt(
|
|
326
|
+
segments: PromptSegment[],
|
|
327
|
+
options: ExecutionOptions,
|
|
328
|
+
logger?: WarnLogger,
|
|
329
|
+
): Promise<ClaudePrompt> {
|
|
254
330
|
let system: TextBlockParam[] | undefined = segments
|
|
255
331
|
.filter((s) => s.role === PromptRole.system)
|
|
256
332
|
.map((s) => ({ text: s.content, type: 'text' as const }));
|
|
257
333
|
|
|
258
334
|
if (options.result_schema) {
|
|
259
|
-
const schemaText =
|
|
260
|
-
|
|
261
|
-
|
|
335
|
+
const schemaText =
|
|
336
|
+
options.tools && options.tools.length > 0
|
|
337
|
+
? `When not calling tools, the answer must be a JSON object using the following JSON Schema:\n${JSON.stringify(options.result_schema)}`
|
|
338
|
+
: `The answer must be a JSON object using the following JSON Schema:\n${JSON.stringify(options.result_schema)}`;
|
|
262
339
|
system.push({ text: schemaText, type: 'text' as const });
|
|
263
340
|
}
|
|
264
341
|
|
|
@@ -272,25 +349,27 @@ export async function formatClaudePrompt(segments: PromptSegment[], options: Exe
|
|
|
272
349
|
if (!segment.tool_use_id) {
|
|
273
350
|
throw new Error('Tool prompt segment must have a tool use ID');
|
|
274
351
|
}
|
|
275
|
-
const contentBlocks: Array<TextBlockParam | ImageBlockParam> = [];
|
|
352
|
+
const contentBlocks: Array<TextBlockParam | ImageBlockParam | DocumentBlockParam> = [];
|
|
276
353
|
if (segment.content) {
|
|
277
354
|
contentBlocks.push({ type: 'text', text: segment.content } satisfies TextBlockParam);
|
|
278
355
|
}
|
|
279
|
-
contentBlocks.push(...(await collectFileBlocks(segment,
|
|
356
|
+
contentBlocks.push(...(await collectFileBlocks(segment, logger)));
|
|
280
357
|
messages.push({
|
|
281
358
|
role: 'user',
|
|
282
|
-
content: [
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
359
|
+
content: [
|
|
360
|
+
{
|
|
361
|
+
type: 'tool_result',
|
|
362
|
+
tool_use_id: segment.tool_use_id,
|
|
363
|
+
content: contentBlocks,
|
|
364
|
+
} satisfies ToolResultBlockParam,
|
|
365
|
+
],
|
|
287
366
|
});
|
|
288
367
|
} else {
|
|
289
368
|
const contentBlocks: ContentBlockParam[] = [];
|
|
290
369
|
if (segment.content) {
|
|
291
370
|
contentBlocks.push({ type: 'text', text: segment.content } satisfies TextBlockParam);
|
|
292
371
|
}
|
|
293
|
-
contentBlocks.push(...(await collectFileBlocks(segment,
|
|
372
|
+
contentBlocks.push(...(await collectFileBlocks(segment, logger)));
|
|
294
373
|
if (contentBlocks.length === 0) continue;
|
|
295
374
|
|
|
296
375
|
const messageParam: MessageParam = {
|
|
@@ -326,8 +405,8 @@ export function createPromptFromResponse(response: Message): ClaudePrompt {
|
|
|
326
405
|
export function mergeConsecutiveUserMessages(messages: MessageParam[]): MessageParam[] {
|
|
327
406
|
if (messages.length === 0) return [];
|
|
328
407
|
|
|
329
|
-
const needsMerging = messages.some(
|
|
330
|
-
i < messages.length - 1 && msg.role === 'user' && messages[i + 1].role === 'user'
|
|
408
|
+
const needsMerging = messages.some(
|
|
409
|
+
(msg, i) => i < messages.length - 1 && msg.role === 'user' && messages[i + 1].role === 'user',
|
|
331
410
|
);
|
|
332
411
|
if (!needsMerging) return messages;
|
|
333
412
|
|
|
@@ -383,7 +462,7 @@ export function fixOrphanedToolUse(messages: MessageParam[]): MessageParam[] {
|
|
|
383
462
|
if (current.role === 'assistant' && Array.isArray(current.content)) {
|
|
384
463
|
const toolUseBlocks = current.content.filter(
|
|
385
464
|
(block): block is ContentBlockParam & { type: 'tool_use'; id: string; name: string } =>
|
|
386
|
-
block.type === 'tool_use'
|
|
465
|
+
block.type === 'tool_use',
|
|
387
466
|
);
|
|
388
467
|
|
|
389
468
|
if (toolUseBlocks.length > 0) {
|
|
@@ -393,7 +472,7 @@ export function fixOrphanedToolUse(messages: MessageParam[]): MessageParam[] {
|
|
|
393
472
|
const toolResultIds = new Set(
|
|
394
473
|
nextMessage.content
|
|
395
474
|
.filter((block): block is ToolResultBlockParam => block.type === 'tool_result')
|
|
396
|
-
.map((block) => block.tool_use_id)
|
|
475
|
+
.map((block) => block.tool_use_id),
|
|
397
476
|
);
|
|
398
477
|
const orphaned = toolUseBlocks.filter((block) => !toolResultIds.has(block.id));
|
|
399
478
|
if (orphaned.length > 0) {
|
|
@@ -410,9 +489,10 @@ export function fixOrphanedToolUse(messages: MessageParam[]): MessageParam[] {
|
|
|
410
489
|
tool_use_id: block.id,
|
|
411
490
|
content: `[Tool interrupted: The user stopped the operation before "${block.name}" could execute.]`,
|
|
412
491
|
}));
|
|
413
|
-
const textContent: TextBlockParam =
|
|
414
|
-
|
|
415
|
-
|
|
492
|
+
const textContent: TextBlockParam =
|
|
493
|
+
typeof nextMessage.content === 'string'
|
|
494
|
+
? { type: 'text', text: nextMessage.content }
|
|
495
|
+
: { type: 'text', text: '' };
|
|
416
496
|
messages[i + 1] = { role: 'user', content: [...syntheticResults, textContent] };
|
|
417
497
|
}
|
|
418
498
|
}
|
|
@@ -421,7 +501,62 @@ export function fixOrphanedToolUse(messages: MessageParam[]): MessageParam[] {
|
|
|
421
501
|
return result;
|
|
422
502
|
}
|
|
423
503
|
|
|
424
|
-
|
|
504
|
+
/**
|
|
505
|
+
* Drop tool_result blocks whose tool_use_id has no matching tool_use in the
|
|
506
|
+
* immediately preceding assistant message. This is the mirror of
|
|
507
|
+
* {@link fixOrphanedToolUse}: that function synthesizes results for tool_uses
|
|
508
|
+
* left unanswered (e.g. a cancelled run); this one removes results left dangling
|
|
509
|
+
* after their tool_use was dropped (e.g. by conversation compaction/trimming, or
|
|
510
|
+
* a parallel tool batch whose results were split across messages that cannot be
|
|
511
|
+
* re-paired).
|
|
512
|
+
*
|
|
513
|
+
* Without this, the Anthropic / Vertex-Anthropic API rejects the request with a
|
|
514
|
+
* non-retryable 400: "unexpected `tool_use_id` found in `tool_result` blocks ...
|
|
515
|
+
* Each `tool_result` block must have a corresponding `tool_use` block in the
|
|
516
|
+
* previous message." — which terminates the conversation.
|
|
517
|
+
*
|
|
518
|
+
* Must run AFTER mergeConsecutiveUserMessages so that parallel tool results which
|
|
519
|
+
* were split across separate user messages are first combined into the single
|
|
520
|
+
* user turn that follows the assistant tool_use message (otherwise valid results
|
|
521
|
+
* whose "previous message" is another user message would be wrongly dropped).
|
|
522
|
+
*/
|
|
523
|
+
export function fixOrphanedToolResults(messages: MessageParam[]): MessageParam[] {
|
|
524
|
+
if (messages.length === 0) return messages;
|
|
525
|
+
const result: MessageParam[] = [];
|
|
526
|
+
for (let i = 0; i < messages.length; i++) {
|
|
527
|
+
const message = messages[i];
|
|
528
|
+
if (message.role !== 'user' || !Array.isArray(message.content)) {
|
|
529
|
+
result.push(message);
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
const hasToolResult = message.content.some((block) => block.type === 'tool_result');
|
|
533
|
+
if (!hasToolResult) {
|
|
534
|
+
result.push(message);
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
// Collect the tool_use ids declared by the immediately preceding assistant message.
|
|
538
|
+
const prev = messages[i - 1];
|
|
539
|
+
const allowedIds = new Set<string>();
|
|
540
|
+
if (prev && prev.role === 'assistant' && Array.isArray(prev.content)) {
|
|
541
|
+
for (const block of prev.content) {
|
|
542
|
+
if (block.type === 'tool_use') allowedIds.add(block.id);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const filtered = message.content.filter((block) =>
|
|
546
|
+
block.type === 'tool_result' ? allowedIds.has(block.tool_use_id) : true,
|
|
547
|
+
);
|
|
548
|
+
// If every block was an orphaned tool_result, drop the message rather than
|
|
549
|
+
// emit an empty (and invalid) content array.
|
|
550
|
+
if (filtered.length === 0) continue;
|
|
551
|
+
result.push(filtered.length === message.content.length ? message : { ...message, content: filtered });
|
|
552
|
+
}
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function updateClaudeConversation(
|
|
557
|
+
conversation: ClaudePrompt | undefined | null,
|
|
558
|
+
prompt: ClaudePrompt,
|
|
559
|
+
): ClaudePrompt {
|
|
425
560
|
const baseSystemMessages = conversation?.system || [];
|
|
426
561
|
const baseMessages = conversation?.messages || [];
|
|
427
562
|
const system = baseSystemMessages.concat(prompt.system || []);
|
|
@@ -450,8 +585,12 @@ export function convertClaudeToolBlocksToText(messages: MessageParam[]): Message
|
|
|
450
585
|
if (!Array.isArray(msg.content)) return msg;
|
|
451
586
|
let hasToolBlocks = false;
|
|
452
587
|
for (const block of msg.content) {
|
|
453
|
-
if (
|
|
454
|
-
|
|
588
|
+
if (
|
|
589
|
+
typeof block === 'object' &&
|
|
590
|
+
block !== null &&
|
|
591
|
+
'type' in block &&
|
|
592
|
+
(block.type === 'tool_use' || block.type === 'tool_result')
|
|
593
|
+
) {
|
|
455
594
|
hasToolBlocks = true;
|
|
456
595
|
break;
|
|
457
596
|
}
|
|
@@ -460,22 +599,31 @@ export function convertClaudeToolBlocksToText(messages: MessageParam[]): Message
|
|
|
460
599
|
|
|
461
600
|
const newContent: MessageParam['content'] = [];
|
|
462
601
|
for (const block of msg.content) {
|
|
463
|
-
if (typeof block === 'string') {
|
|
602
|
+
if (typeof block === 'string') {
|
|
603
|
+
newContent.push(block);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
464
606
|
if (block.type === 'tool_use') {
|
|
465
607
|
const inputStr = block.input ? JSON.stringify(block.input) : '';
|
|
466
|
-
const truncated = inputStr.length > 500 ? inputStr.substring(0, 500)
|
|
467
|
-
(newContent as Array<{ type: 'text'; text: string }>).push({
|
|
608
|
+
const truncated = inputStr.length > 500 ? `${inputStr.substring(0, 500)}...` : inputStr;
|
|
609
|
+
(newContent as Array<{ type: 'text'; text: string }>).push({
|
|
610
|
+
type: 'text',
|
|
611
|
+
text: `[Tool call: ${block.name}(${truncated})]`,
|
|
612
|
+
});
|
|
468
613
|
} else if (block.type === 'tool_result') {
|
|
469
614
|
let resultStr = 'No content';
|
|
470
615
|
if (typeof block.content === 'string') {
|
|
471
|
-
resultStr = block.content.length > 500 ? block.content.substring(0, 500)
|
|
616
|
+
resultStr = block.content.length > 500 ? `${block.content.substring(0, 500)}...` : block.content;
|
|
472
617
|
} else if (Array.isArray(block.content)) {
|
|
473
618
|
const texts = block.content
|
|
474
619
|
.filter((c): c is { type: 'text'; text: string } => c.type === 'text')
|
|
475
|
-
.map((c) => (c.text.length > 500 ? c.text.substring(0, 500)
|
|
620
|
+
.map((c) => (c.text.length > 500 ? `${c.text.substring(0, 500)}...` : c.text));
|
|
476
621
|
resultStr = texts.join('\n') || 'No text content';
|
|
477
622
|
}
|
|
478
|
-
(newContent as Array<{ type: 'text'; text: string }>).push({
|
|
623
|
+
(newContent as Array<{ type: 'text'; text: string }>).push({
|
|
624
|
+
type: 'text',
|
|
625
|
+
text: `[Tool result: ${resultStr}]`,
|
|
626
|
+
});
|
|
479
627
|
} else {
|
|
480
628
|
newContent.push(block as ContentBlockParam);
|
|
481
629
|
}
|
|
@@ -509,7 +657,7 @@ function stripClaudeCacheControlFromSystem(system?: TextBlockParam[]): TextBlock
|
|
|
509
657
|
}
|
|
510
658
|
|
|
511
659
|
function stripClaudeCacheControlFromTools(
|
|
512
|
-
tools?: MessageCreateParamsBase['tools']
|
|
660
|
+
tools?: MessageCreateParamsBase['tools'],
|
|
513
661
|
): MessageCreateParamsBase['tools'] | undefined {
|
|
514
662
|
if (!tools) return undefined;
|
|
515
663
|
return tools.map((tool) => {
|
|
@@ -527,24 +675,33 @@ function stripClaudeCacheControlFromTools(
|
|
|
527
675
|
|
|
528
676
|
export function getClaudePayload(
|
|
529
677
|
options: ExecutionOptions,
|
|
530
|
-
prompt: ClaudePrompt
|
|
678
|
+
prompt: ClaudePrompt,
|
|
531
679
|
): { payload: MessageCreateParamsBase; requestOptions: RequestOptions | undefined } {
|
|
532
680
|
const modelName = options.model;
|
|
533
681
|
const model_options = options.model_options as ClaudeBaseOptions | undefined;
|
|
534
682
|
|
|
535
683
|
let requestOptions: RequestOptions | undefined;
|
|
536
|
-
if (
|
|
537
|
-
(
|
|
684
|
+
if (
|
|
685
|
+
modelName.includes('claude-3-7-sonnet') &&
|
|
686
|
+
((model_options?.max_tokens ?? 0) > 64000 || (model_options?.thinking_budget_tokens ?? 0) > 64000)
|
|
687
|
+
) {
|
|
538
688
|
requestOptions = { headers: { 'anthropic-beta': 'output-128k-2025-02-19' } };
|
|
539
689
|
}
|
|
540
690
|
|
|
541
|
-
|
|
691
|
+
// Merge first so parallel tool results split across user messages are recombined
|
|
692
|
+
// into the single user turn after their assistant tool_use message; then fix both
|
|
693
|
+
// orphan directions (tool_use without result, and result without tool_use) so the
|
|
694
|
+
// request can never trip Anthropic/Vertex's tool_use/tool_result pairing validation.
|
|
695
|
+
const mergedMessages = mergeConsecutiveUserMessages(prompt.messages);
|
|
696
|
+
const fixedMessages = fixOrphanedToolResults(fixOrphanedToolUse(mergedMessages));
|
|
542
697
|
let sanitizedMessages = sanitizeMessages(fixedMessages);
|
|
543
698
|
|
|
544
699
|
if (options.tools) {
|
|
545
700
|
for (const tool of options.tools) {
|
|
546
701
|
if (tool.input_schema.type !== 'object') {
|
|
547
|
-
throw new Error(
|
|
702
|
+
throw new Error(
|
|
703
|
+
`Tool "${tool.name}" has invalid input_schema.type: expected "object", got "${tool.input_schema.type}"`,
|
|
704
|
+
);
|
|
548
705
|
}
|
|
549
706
|
}
|
|
550
707
|
}
|
|
@@ -566,7 +723,9 @@ export function getClaudePayload(
|
|
|
566
723
|
const cacheControl = { type: 'ephemeral' as const, ...(cacheTtl && { ttl: cacheTtl }) };
|
|
567
724
|
|
|
568
725
|
if (sanitizedSystem && sanitizedSystem.length > 0) {
|
|
569
|
-
const lastBlock = sanitizedSystem[sanitizedSystem.length - 1] as TextBlockParam & {
|
|
726
|
+
const lastBlock = sanitizedSystem[sanitizedSystem.length - 1] as TextBlockParam & {
|
|
727
|
+
cache_control?: unknown;
|
|
728
|
+
};
|
|
570
729
|
lastBlock.cache_control = cacheControl;
|
|
571
730
|
}
|
|
572
731
|
if (sanitizedTools && sanitizedTools.length > 0) {
|
|
@@ -577,15 +736,23 @@ export function getClaudePayload(
|
|
|
577
736
|
const pivotMsg = sanitizedMessages[sanitizedMessages.length - 2];
|
|
578
737
|
if (Array.isArray(pivotMsg.content) && pivotMsg.content.length > 0) {
|
|
579
738
|
const lastBlock = pivotMsg.content[pivotMsg.content.length - 1];
|
|
580
|
-
if (
|
|
581
|
-
lastBlock
|
|
739
|
+
if (
|
|
740
|
+
typeof lastBlock === 'object' &&
|
|
741
|
+
lastBlock !== null &&
|
|
742
|
+
'type' in lastBlock &&
|
|
743
|
+
lastBlock.type !== 'thinking' &&
|
|
744
|
+
lastBlock.type !== 'redacted_thinking'
|
|
745
|
+
) {
|
|
582
746
|
(lastBlock as TextBlockParam).cache_control = cacheControl;
|
|
583
747
|
}
|
|
584
748
|
}
|
|
585
749
|
}
|
|
586
750
|
}
|
|
587
751
|
|
|
588
|
-
const { thinking, outputConfig, hasSamplingRestriction } = resolveClaudeThinking(
|
|
752
|
+
const { thinking, outputConfig, hasSamplingRestriction } = resolveClaudeThinking(
|
|
753
|
+
modelName,
|
|
754
|
+
model_options as Parameters<typeof resolveClaudeThinking>[1],
|
|
755
|
+
);
|
|
589
756
|
|
|
590
757
|
const payload: MessageCreateParamsBase = {
|
|
591
758
|
messages: sanitizedMessages,
|
|
@@ -594,7 +761,11 @@ export function getClaudePayload(
|
|
|
594
761
|
temperature: hasSamplingRestriction ? undefined : model_options?.temperature,
|
|
595
762
|
model: modelName,
|
|
596
763
|
max_tokens: claudeMaxTokens(options),
|
|
597
|
-
top_p: hasSamplingRestriction
|
|
764
|
+
top_p: hasSamplingRestriction
|
|
765
|
+
? undefined
|
|
766
|
+
: model_options?.temperature != null
|
|
767
|
+
? undefined
|
|
768
|
+
: model_options?.top_p,
|
|
598
769
|
top_k: hasSamplingRestriction ? undefined : model_options?.top_k,
|
|
599
770
|
stop_sequences: model_options?.stop_sequence,
|
|
600
771
|
thinking,
|
|
@@ -613,7 +784,7 @@ export function buildClaudeStreamingConversation(
|
|
|
613
784
|
prompt: ClaudePrompt,
|
|
614
785
|
result: unknown[],
|
|
615
786
|
toolUse: unknown[] | undefined,
|
|
616
|
-
options: ExecutionOptions
|
|
787
|
+
options: ExecutionOptions,
|
|
617
788
|
): ClaudePrompt {
|
|
618
789
|
const completionResults = result as CompletionResult[];
|
|
619
790
|
const text = completionResults
|
|
@@ -641,10 +812,18 @@ export function buildClaudeStreamingConversation(
|
|
|
641
812
|
|
|
642
813
|
conversation = incrementConversationTurn(conversation) as ClaudePrompt;
|
|
643
814
|
const currentTurn = getConversationMeta(conversation).turnNumber;
|
|
815
|
+
// When text trimming is requested, keep the agent's active working set (the
|
|
816
|
+
// most recent messages — the file it just read/wrote, latest diagnostics)
|
|
817
|
+
// fully intact, and aggressively shrink large text only in OLDER messages.
|
|
818
|
+
// Clamp the effective cap so a lax caller value (e.g. 10000) still bites on
|
|
819
|
+
// stale blocks; long agent conversations otherwise balloon context and
|
|
820
|
+
// trigger frequent expensive checkpoints.
|
|
821
|
+
const requestedTextMax = options.stripTextMaxTokens;
|
|
644
822
|
const stripOptions = {
|
|
645
823
|
keepForTurns: options.stripImagesAfterTurns ?? Infinity,
|
|
646
824
|
currentTurn,
|
|
647
|
-
textMaxTokens:
|
|
825
|
+
textMaxTokens: requestedTextMax ? Math.min(requestedTextMax, OLD_MESSAGE_TEXT_MAX_TOKENS) : undefined,
|
|
826
|
+
keepRecentMessages: requestedTextMax ? KEEP_RECENT_MESSAGES : undefined,
|
|
648
827
|
};
|
|
649
828
|
let processed = stripBase64ImagesFromConversation(conversation, stripOptions);
|
|
650
829
|
processed = truncateLargeTextInConversation(processed, stripOptions);
|
|
@@ -674,7 +853,8 @@ export async function executeClaudeCompletion(
|
|
|
674
853
|
|
|
675
854
|
const { payload, requestOptions } = getClaudePayload(options, conversation);
|
|
676
855
|
|
|
677
|
-
const
|
|
856
|
+
const responseStream = await streamClaudeMessages(client, payload as MessageStreamParams, requestOptions);
|
|
857
|
+
const result = await responseStream.finalMessage();
|
|
678
858
|
|
|
679
859
|
const includeThoughts = model_options?.include_thoughts ?? false;
|
|
680
860
|
const text = collectAllTextContent(result.content, includeThoughts);
|
|
@@ -719,7 +899,7 @@ export async function streamClaudeCompletion(
|
|
|
719
899
|
const { payload, requestOptions } = getClaudePayload(options, conversation);
|
|
720
900
|
const streamingPayload: MessageStreamParams = { ...payload, stream: true };
|
|
721
901
|
|
|
722
|
-
const response_stream = await client
|
|
902
|
+
const response_stream = await streamClaudeMessages(client, streamingPayload, requestOptions);
|
|
723
903
|
|
|
724
904
|
let currentToolUse: { id: string; name: string; inputJson: string } | null = null;
|
|
725
905
|
let pendingSpacing = false;
|
|
@@ -739,14 +919,20 @@ export async function streamClaudeCompletion(
|
|
|
739
919
|
} satisfies CompletionChunkObject;
|
|
740
920
|
case 'content_block_start':
|
|
741
921
|
if (streamEvent.content_block.type === 'tool_use') {
|
|
742
|
-
currentToolUse = {
|
|
922
|
+
currentToolUse = {
|
|
923
|
+
id: streamEvent.content_block.id,
|
|
924
|
+
name: streamEvent.content_block.name,
|
|
925
|
+
inputJson: '',
|
|
926
|
+
};
|
|
743
927
|
return {
|
|
744
928
|
result: [],
|
|
745
|
-
tool_use: [
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
929
|
+
tool_use: [
|
|
930
|
+
{
|
|
931
|
+
id: streamEvent.content_block.id,
|
|
932
|
+
tool_name: streamEvent.content_block.name,
|
|
933
|
+
tool_input: '' as unknown as JSONObject,
|
|
934
|
+
},
|
|
935
|
+
],
|
|
750
936
|
} satisfies CompletionChunkObject;
|
|
751
937
|
}
|
|
752
938
|
if (streamEvent.content_block.type === 'redacted_thinking' && model_options?.include_thoughts) {
|
|
@@ -761,25 +947,31 @@ export async function streamClaudeCompletion(
|
|
|
761
947
|
const prefix = pendingSpacing ? '\n\n' : '';
|
|
762
948
|
pendingSpacing = false;
|
|
763
949
|
return {
|
|
764
|
-
result: streamEvent.delta.text
|
|
950
|
+
result: streamEvent.delta.text
|
|
951
|
+
? [{ type: 'text', value: prefix + streamEvent.delta.text }]
|
|
952
|
+
: [],
|
|
765
953
|
} satisfies CompletionChunkObject;
|
|
766
954
|
}
|
|
767
955
|
case 'input_json_delta':
|
|
768
956
|
if (currentToolUse && streamEvent.delta.partial_json) {
|
|
769
957
|
return {
|
|
770
958
|
result: [],
|
|
771
|
-
tool_use: [
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
959
|
+
tool_use: [
|
|
960
|
+
{
|
|
961
|
+
id: currentToolUse.id,
|
|
962
|
+
tool_name: '',
|
|
963
|
+
tool_input: streamEvent.delta.partial_json as unknown as JSONObject,
|
|
964
|
+
},
|
|
965
|
+
],
|
|
776
966
|
} satisfies CompletionChunkObject;
|
|
777
967
|
}
|
|
778
968
|
break;
|
|
779
969
|
case 'thinking_delta':
|
|
780
970
|
if (model_options?.include_thoughts) {
|
|
781
971
|
return {
|
|
782
|
-
result: streamEvent.delta.thinking
|
|
972
|
+
result: streamEvent.delta.thinking
|
|
973
|
+
? [{ type: 'text', value: streamEvent.delta.thinking }]
|
|
974
|
+
: [],
|
|
783
975
|
} satisfies CompletionChunkObject;
|
|
784
976
|
}
|
|
785
977
|
break;
|
|
@@ -813,7 +1005,14 @@ export function formatAnthropicLlumiverseError(error: unknown, context: Llumiver
|
|
|
813
1005
|
// Client-side SDK error (e.g. "Streaming is required for operations that may take longer than 10 minutes").
|
|
814
1006
|
// These are structural/configuration errors — retrying will never succeed.
|
|
815
1007
|
const errorName = error.constructor?.name || 'AnthropicError';
|
|
816
|
-
return new LlumiverseError(
|
|
1008
|
+
return new LlumiverseError(
|
|
1009
|
+
`[${context.provider}] ${error.message}`,
|
|
1010
|
+
false,
|
|
1011
|
+
context,
|
|
1012
|
+
error,
|
|
1013
|
+
undefined,
|
|
1014
|
+
errorName,
|
|
1015
|
+
);
|
|
817
1016
|
}
|
|
818
1017
|
if (!(error instanceof APIError)) {
|
|
819
1018
|
// Not an Anthropic error — rethrow for default handling
|
|
@@ -827,11 +1026,11 @@ export function formatAnthropicLlumiverseError(error: unknown, context: Llumiver
|
|
|
827
1026
|
|
|
828
1027
|
if (apiError.error && typeof apiError.error === 'object') {
|
|
829
1028
|
const nested = apiError.error as Record<string, unknown>;
|
|
830
|
-
if (nested
|
|
831
|
-
const innerError = nested
|
|
832
|
-
errorType = innerError
|
|
833
|
-
if (typeof innerError
|
|
834
|
-
message = innerError
|
|
1029
|
+
if (nested.error && typeof nested.error === 'object') {
|
|
1030
|
+
const innerError = nested.error as Record<string, unknown>;
|
|
1031
|
+
errorType = innerError.type as string | undefined;
|
|
1032
|
+
if (typeof innerError.message === 'string') {
|
|
1033
|
+
message = innerError.message;
|
|
835
1034
|
}
|
|
836
1035
|
}
|
|
837
1036
|
}
|
|
@@ -844,7 +1043,14 @@ export function formatAnthropicLlumiverseError(error: unknown, context: Llumiver
|
|
|
844
1043
|
const retryable = isClaudeErrorRetryable(error, httpStatusCode, errorType, apiError.headers ?? undefined);
|
|
845
1044
|
const errorName = error.constructor?.name || 'AnthropicError';
|
|
846
1045
|
|
|
847
|
-
return new LlumiverseError(
|
|
1046
|
+
return new LlumiverseError(
|
|
1047
|
+
`[${context.provider}] ${userMessage}`,
|
|
1048
|
+
retryable,
|
|
1049
|
+
context,
|
|
1050
|
+
error,
|
|
1051
|
+
httpStatusCode,
|
|
1052
|
+
errorName,
|
|
1053
|
+
);
|
|
848
1054
|
}
|
|
849
1055
|
|
|
850
1056
|
export function isClaudeErrorRetryable(
|
|
@@ -866,7 +1072,7 @@ export function isClaudeErrorRetryable(
|
|
|
866
1072
|
if (error instanceof AuthenticationError) return false;
|
|
867
1073
|
if (error instanceof PermissionDeniedError) return false;
|
|
868
1074
|
if (error instanceof NotFoundError) return false;
|
|
869
|
-
if (error instanceof ConflictError) return true;
|
|
1075
|
+
if (error instanceof ConflictError) return true; // SDK retries 409 (lock timeouts)
|
|
870
1076
|
if (error instanceof UnprocessableEntityError) return false;
|
|
871
1077
|
if (errorType === 'invalid_request_error') return false;
|
|
872
1078
|
if (httpStatusCode !== undefined) {
|