@copilotkit/aimock 1.45.1 → 1.47.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +25 -1
- package/README.md +11 -2
- package/dist/agui-mock.cjs +25 -25
- package/dist/agui-mock.cjs.map +1 -1
- package/dist/agui-mock.d.cts.map +1 -1
- package/dist/agui-mock.d.ts.map +1 -1
- package/dist/agui-mock.js +25 -25
- package/dist/agui-mock.js.map +1 -1
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/aimock-cli.cjs +15 -1
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +16 -2
- package/dist/aimock-cli.js.map +1 -1
- package/dist/api-key-auth.cjs +10 -9
- package/dist/api-key-auth.cjs.map +1 -1
- package/dist/api-key-auth.d.cts.map +1 -1
- package/dist/api-key-auth.d.ts.map +1 -1
- package/dist/api-key-auth.js +11 -10
- package/dist/api-key-auth.js.map +1 -1
- package/dist/aws-event-stream.cjs +20 -23
- package/dist/aws-event-stream.cjs.map +1 -1
- package/dist/aws-event-stream.d.cts +0 -1
- package/dist/aws-event-stream.d.ts +0 -1
- package/dist/aws-event-stream.js +20 -24
- package/dist/aws-event-stream.js.map +1 -1
- package/dist/batches.cjs +2 -4
- package/dist/batches.cjs.map +1 -1
- package/dist/batches.d.cts.map +1 -1
- package/dist/batches.d.ts.map +1 -1
- package/dist/batches.js +2 -4
- package/dist/batches.js.map +1 -1
- package/dist/bedrock-converse.cjs +139 -161
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +137 -159
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +175 -216
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +172 -213
- package/dist/bedrock.js.map +1 -1
- package/dist/byteplus-video.cjs +11 -10
- package/dist/byteplus-video.cjs.map +1 -1
- package/dist/byteplus-video.d.cts.map +1 -1
- package/dist/byteplus-video.d.ts.map +1 -1
- package/dist/byteplus-video.js +5 -4
- package/dist/byteplus-video.js.map +1 -1
- package/dist/chaos.cjs +5 -4
- package/dist/chaos.cjs.map +1 -1
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +5 -4
- package/dist/chaos.js.map +1 -1
- package/dist/cli.cjs +15 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +107 -180
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +106 -179
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +29 -1
- package/dist/config-loader.cjs.map +1 -1
- package/dist/config-loader.d.cts +7 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +7 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +29 -2
- package/dist/config-loader.js.map +1 -1
- package/dist/count-tokens.cjs +146 -0
- package/dist/count-tokens.cjs.map +1 -0
- package/dist/count-tokens.js +146 -0
- package/dist/count-tokens.js.map +1 -0
- package/dist/elevenlabs-audio.cjs +36 -34
- package/dist/elevenlabs-audio.cjs.map +1 -1
- package/dist/elevenlabs-audio.d.cts.map +1 -1
- package/dist/elevenlabs-audio.d.ts.map +1 -1
- package/dist/elevenlabs-audio.js +33 -31
- package/dist/elevenlabs-audio.js.map +1 -1
- package/dist/elevenlabs-voice.cjs +38 -37
- package/dist/elevenlabs-voice.cjs.map +1 -1
- package/dist/elevenlabs-voice.d.cts.map +1 -1
- package/dist/elevenlabs-voice.d.ts.map +1 -1
- package/dist/elevenlabs-voice.js +33 -32
- package/dist/elevenlabs-voice.js.map +1 -1
- package/dist/embedding-request.cjs +16 -0
- package/dist/embedding-request.cjs.map +1 -0
- package/dist/embedding-request.js +14 -0
- package/dist/embedding-request.js.map +1 -0
- package/dist/embeddings.cjs +30 -20
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +30 -20
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +45 -43
- package/dist/fal-audio.cjs.map +1 -1
- package/dist/fal-audio.d.cts.map +1 -1
- package/dist/fal-audio.d.ts.map +1 -1
- package/dist/fal-audio.js +42 -40
- package/dist/fal-audio.js.map +1 -1
- package/dist/fal.cjs +17 -15
- package/dist/fal.cjs.map +1 -1
- package/dist/fal.js +16 -14
- package/dist/fal.js.map +1 -1
- package/dist/files.cjs +2 -4
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +2 -4
- package/dist/files.js.map +1 -1
- package/dist/fine-tuning.cjs +2 -4
- package/dist/fine-tuning.cjs.map +1 -1
- package/dist/fine-tuning.d.cts.map +1 -1
- package/dist/fine-tuning.d.ts.map +1 -1
- package/dist/fine-tuning.js +2 -4
- package/dist/fine-tuning.js.map +1 -1
- package/dist/fixture-loader.cjs +140 -44
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +141 -46
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-embeddings.cjs +26 -24
- package/dist/gemini-embeddings.cjs.map +1 -1
- package/dist/gemini-embeddings.js +26 -24
- package/dist/gemini-embeddings.js.map +1 -1
- package/dist/gemini-interactions.cjs +113 -156
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts +0 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts +0 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +113 -156
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +295 -218
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +295 -219
- package/dist/gemini.js.map +1 -1
- package/dist/grok-video.cjs +14 -12
- package/dist/grok-video.cjs.map +1 -1
- package/dist/grok-video.d.cts.map +1 -1
- package/dist/grok-video.d.ts.map +1 -1
- package/dist/grok-video.js +8 -6
- package/dist/grok-video.js.map +1 -1
- package/dist/helpers.cjs +411 -75
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +51 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +51 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +402 -74
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +30 -28
- package/dist/images.cjs.map +1 -1
- package/dist/images.d.cts.map +1 -1
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +27 -25
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/journal.cjs +3 -1
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +2 -1
- package/dist/journal.js.map +1 -1
- package/dist/llmock.cjs +3 -0
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +3 -0
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes.d.cts.map +1 -1
- package/dist/mcp-handler.cjs +7 -3
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.js +7 -3
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-recorder.cjs +2 -1
- package/dist/mcp-recorder.cjs.map +1 -1
- package/dist/mcp-recorder.js +3 -2
- package/dist/mcp-recorder.js.map +1 -1
- package/dist/messages.cjs +235 -202
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +234 -202
- package/dist/messages.js.map +1 -1
- package/dist/metrics.cjs +5 -2
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.cts.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +6 -3
- package/dist/metrics.js.map +1 -1
- package/dist/misbehavior.cjs +62 -3
- package/dist/misbehavior.cjs.map +1 -1
- package/dist/misbehavior.d.cts.map +1 -1
- package/dist/misbehavior.d.ts.map +1 -1
- package/dist/misbehavior.js +63 -4
- package/dist/misbehavior.js.map +1 -1
- package/dist/model-utils.cjs +1 -0
- package/dist/model-utils.cjs.map +1 -1
- package/dist/model-utils.js +1 -1
- package/dist/model-utils.js.map +1 -1
- package/dist/moderation.cjs +15 -12
- package/dist/moderation.cjs.map +1 -1
- package/dist/moderation.js +14 -11
- package/dist/moderation.js.map +1 -1
- package/dist/ndjson-writer.cjs +21 -23
- package/dist/ndjson-writer.cjs.map +1 -1
- package/dist/ndjson-writer.d.cts +0 -1
- package/dist/ndjson-writer.d.cts.map +1 -1
- package/dist/ndjson-writer.d.ts +0 -1
- package/dist/ndjson-writer.d.ts.map +1 -1
- package/dist/ndjson-writer.js +21 -24
- package/dist/ndjson-writer.js.map +1 -1
- package/dist/ollama.cjs +276 -210
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +273 -207
- package/dist/ollama.js.map +1 -1
- package/dist/openapi.cjs +323 -3
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +324 -4
- package/dist/openapi.js.map +1 -1
- package/dist/openrouter-chat.cjs +11 -155
- package/dist/openrouter-chat.cjs.map +1 -1
- package/dist/openrouter-chat.js +11 -155
- package/dist/openrouter-chat.js.map +1 -1
- package/dist/openrouter-video.cjs +51 -74
- package/dist/openrouter-video.cjs.map +1 -1
- package/dist/openrouter-video.d.cts.map +1 -1
- package/dist/openrouter-video.d.ts.map +1 -1
- package/dist/openrouter-video.js +37 -60
- package/dist/openrouter-video.js.map +1 -1
- package/dist/raw-validation.cjs +177 -0
- package/dist/raw-validation.cjs.map +1 -0
- package/dist/raw-validation.js +176 -0
- package/dist/raw-validation.js.map +1 -0
- package/dist/recorder.cjs +176 -95
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +176 -95
- package/dist/recorder.js.map +1 -1
- package/dist/rerank.cjs +13 -11
- package/dist/rerank.cjs.map +1 -1
- package/dist/rerank.js +12 -10
- package/dist/rerank.js.map +1 -1
- package/dist/response/catalog/anthropic-page.cjs +39 -0
- package/dist/response/catalog/anthropic-page.cjs.map +1 -0
- package/dist/response/catalog/anthropic-page.js +38 -0
- package/dist/response/catalog/anthropic-page.js.map +1 -0
- package/dist/response/catalog/collect.cjs +61 -0
- package/dist/response/catalog/collect.cjs.map +1 -0
- package/dist/response/catalog/collect.js +59 -0
- package/dist/response/catalog/collect.js.map +1 -0
- package/dist/response/catalog/gemini-page.cjs +25 -0
- package/dist/response/catalog/gemini-page.cjs.map +1 -0
- package/dist/response/catalog/gemini-page.js +24 -0
- package/dist/response/catalog/gemini-page.js.map +1 -0
- package/dist/response/catalog/render.cjs +182 -0
- package/dist/response/catalog/render.cjs.map +1 -0
- package/dist/response/catalog/render.js +171 -0
- package/dist/response/catalog/render.js.map +1 -0
- package/dist/response/deliver.cjs +144 -0
- package/dist/response/deliver.cjs.map +1 -0
- package/dist/response/deliver.js +143 -0
- package/dist/response/deliver.js.map +1 -0
- package/dist/response/errors.cjs +225 -0
- package/dist/response/errors.cjs.map +1 -0
- package/dist/response/errors.js +224 -0
- package/dist/response/errors.js.map +1 -0
- package/dist/response/finish.cjs +39 -0
- package/dist/response/finish.cjs.map +1 -0
- package/dist/response/finish.js +35 -0
- package/dist/response/finish.js.map +1 -0
- package/dist/response/frame-loop.cjs +102 -0
- package/dist/response/frame-loop.cjs.map +1 -0
- package/dist/response/frame-loop.js +100 -0
- package/dist/response/frame-loop.js.map +1 -0
- package/dist/response/lifecycle.cjs +223 -0
- package/dist/response/lifecycle.cjs.map +1 -0
- package/dist/response/lifecycle.js +211 -0
- package/dist/response/lifecycle.js.map +1 -0
- package/dist/response/policy.cjs +126 -0
- package/dist/response/policy.cjs.map +1 -0
- package/dist/response/policy.js +120 -0
- package/dist/response/policy.js.map +1 -0
- package/dist/response/profiles.cjs +69 -0
- package/dist/response/profiles.cjs.map +1 -0
- package/dist/response/profiles.js +65 -0
- package/dist/response/profiles.js.map +1 -0
- package/dist/response/proxy.cjs +71 -0
- package/dist/response/proxy.cjs.map +1 -0
- package/dist/response/proxy.js +70 -0
- package/dist/response/proxy.js.map +1 -0
- package/dist/response/raw.cjs +228 -0
- package/dist/response/raw.cjs.map +1 -0
- package/dist/response/raw.js +227 -0
- package/dist/response/raw.js.map +1 -0
- package/dist/response/timing.cjs +157 -0
- package/dist/response/timing.cjs.map +1 -0
- package/dist/response/timing.js +150 -0
- package/dist/response/timing.js.map +1 -0
- package/dist/response/usage/codecs/anthropic.cjs +52 -0
- package/dist/response/usage/codecs/anthropic.cjs.map +1 -0
- package/dist/response/usage/codecs/anthropic.js +50 -0
- package/dist/response/usage/codecs/anthropic.js.map +1 -0
- package/dist/response/usage/codecs/cohere.cjs +36 -0
- package/dist/response/usage/codecs/cohere.cjs.map +1 -0
- package/dist/response/usage/codecs/cohere.js +35 -0
- package/dist/response/usage/codecs/cohere.js.map +1 -0
- package/dist/response/usage/codecs/converse.cjs +16 -0
- package/dist/response/usage/codecs/converse.cjs.map +1 -0
- package/dist/response/usage/codecs/converse.js +15 -0
- package/dist/response/usage/codecs/converse.js.map +1 -0
- package/dist/response/usage/codecs/gemini.cjs +31 -0
- package/dist/response/usage/codecs/gemini.cjs.map +1 -0
- package/dist/response/usage/codecs/gemini.js +31 -0
- package/dist/response/usage/codecs/gemini.js.map +1 -0
- package/dist/response/usage/codecs/interactions.cjs +22 -0
- package/dist/response/usage/codecs/interactions.cjs.map +1 -0
- package/dist/response/usage/codecs/interactions.js +21 -0
- package/dist/response/usage/codecs/interactions.js.map +1 -0
- package/dist/response/usage/codecs/ollama.cjs +17 -0
- package/dist/response/usage/codecs/ollama.cjs.map +1 -0
- package/dist/response/usage/codecs/ollama.js +17 -0
- package/dist/response/usage/codecs/ollama.js.map +1 -0
- package/dist/response/usage/codecs/openai.cjs +52 -0
- package/dist/response/usage/codecs/openai.cjs.map +1 -0
- package/dist/response/usage/codecs/openai.js +50 -0
- package/dist/response/usage/codecs/openai.js.map +1 -0
- package/dist/response/usage/codecs/openrouter.cjs +68 -0
- package/dist/response/usage/codecs/openrouter.cjs.map +1 -0
- package/dist/response/usage/codecs/openrouter.js +67 -0
- package/dist/response/usage/codecs/openrouter.js.map +1 -0
- package/dist/response/usage/codecs/realtime.cjs +19 -0
- package/dist/response/usage/codecs/realtime.cjs.map +1 -0
- package/dist/response/usage/codecs/realtime.js +18 -0
- package/dist/response/usage/codecs/realtime.js.map +1 -0
- package/dist/response/usage/codecs/responses.cjs +21 -0
- package/dist/response/usage/codecs/responses.cjs.map +1 -0
- package/dist/response/usage/codecs/responses.js +20 -0
- package/dist/response/usage/codecs/responses.js.map +1 -0
- package/dist/response/usage/estimate.cjs +23 -0
- package/dist/response/usage/estimate.cjs.map +1 -0
- package/dist/response/usage/estimate.js +21 -0
- package/dist/response/usage/estimate.js.map +1 -0
- package/dist/response/usage/fields.cjs +72 -0
- package/dist/response/usage/fields.cjs.map +1 -0
- package/dist/response/usage/fields.js +70 -0
- package/dist/response/usage/fields.js.map +1 -0
- package/dist/response/usage/recording.cjs +52 -0
- package/dist/response/usage/recording.cjs.map +1 -0
- package/dist/response/usage/recording.js +52 -0
- package/dist/response/usage/recording.js.map +1 -0
- package/dist/responses.cjs +304 -196
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +303 -195
- package/dist/responses.js.map +1 -1
- package/dist/route-registry.cjs +45 -0
- package/dist/route-registry.cjs.map +1 -1
- package/dist/route-registry.d.cts.map +1 -1
- package/dist/route-registry.d.ts.map +1 -1
- package/dist/route-registry.js +41 -1
- package/dist/route-registry.js.map +1 -1
- package/dist/router.cjs +24 -4
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts +7 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts +7 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +24 -5
- package/dist/router.js.map +1 -1
- package/dist/search.cjs +13 -11
- package/dist/search.cjs.map +1 -1
- package/dist/search.js +12 -10
- package/dist/search.js.map +1 -1
- package/dist/server.cjs +293 -248
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +294 -249
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +20 -18
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.d.cts.map +1 -1
- package/dist/speech.d.ts.map +1 -1
- package/dist/speech.js +19 -17
- package/dist/speech.js.map +1 -1
- package/dist/sse-writer.cjs +56 -30
- package/dist/sse-writer.cjs.map +1 -1
- package/dist/sse-writer.d.cts +0 -1
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts +0 -1
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/sse-writer.js +55 -31
- package/dist/sse-writer.js.map +1 -1
- package/dist/stream-collapse.cjs +118 -11
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +10 -9
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +10 -9
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +118 -11
- package/dist/stream-collapse.js.map +1 -1
- package/dist/transcription.cjs +31 -43
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +31 -43
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +231 -9
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +231 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vector-mock.cjs +3 -8
- package/dist/vector-mock.cjs.map +1 -1
- package/dist/vector-mock.d.cts.map +1 -1
- package/dist/vector-mock.d.ts.map +1 -1
- package/dist/vector-mock.js +3 -8
- package/dist/vector-mock.js.map +1 -1
- package/dist/vector-stores.cjs +2 -4
- package/dist/vector-stores.cjs.map +1 -1
- package/dist/vector-stores.d.cts.map +1 -1
- package/dist/vector-stores.d.ts.map +1 -1
- package/dist/vector-stores.js +2 -4
- package/dist/vector-stores.js.map +1 -1
- package/dist/veo-video.cjs +16 -14
- package/dist/veo-video.cjs.map +1 -1
- package/dist/veo-video.js +10 -8
- package/dist/veo-video.js.map +1 -1
- package/dist/video.cjs +21 -19
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +20 -18
- package/dist/video.js.map +1 -1
- package/dist/ws-framing.cjs +12 -6
- package/dist/ws-framing.cjs.map +1 -1
- package/dist/ws-framing.d.cts +2 -0
- package/dist/ws-framing.d.cts.map +1 -1
- package/dist/ws-framing.d.ts +2 -0
- package/dist/ws-framing.d.ts.map +1 -1
- package/dist/ws-framing.js +12 -6
- package/dist/ws-framing.js.map +1 -1
- package/dist/ws-gemini-live.cjs +131 -96
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +0 -1
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +0 -1
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +130 -95
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-live.cjs +6 -5
- package/dist/ws-live.cjs.map +1 -1
- package/dist/ws-live.js +5 -4
- package/dist/ws-live.js.map +1 -1
- package/dist/ws-realtime.cjs +108 -124
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +105 -121
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +80 -59
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +79 -58
- package/dist/ws-responses.js.map +1 -1
- package/package.json +4 -1
- package/skills/write-fixtures/SKILL.md +57 -16
package/dist/cohere.js
CHANGED
|
@@ -1,47 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { renderError } from "./response/errors.js";
|
|
2
|
+
import { resolveRequestDecisions, strictOverrideField } from "./response/policy.js";
|
|
3
|
+
import { extractOverrides, flattenHeaders, generateDeterministicEmbedding, generateMessageId, generateToolCallId, getContext, getTestId, isCombinedFixtureResponse, isEmbeddingResponse, isErrorResponse, isJsonObject, isRawResponse, isTextResponse, isToolCallResponse, prepareOpenAIChatMisbehavior, requireEmittedFunctionToolCalls, resolveFixtureBlockOutcome, resolveOpenAIChatMisbehaviorUsage, resolveReasoningForModel, resolveResponse, servedToolArgs, strictNoMatchLogLine, strictNoMatchMessage, validateChatMessages, validateToolsField } from "./helpers.js";
|
|
4
|
+
import { typedSseCodec, writeErrorResponse } from "./sse-writer.js";
|
|
3
5
|
import { applyChaosAsync } from "./chaos.js";
|
|
4
6
|
import { normalizeDirectToolSchema, planMisbehavior, recordMisbehaviorOutcome } from "./misbehavior.js";
|
|
5
7
|
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
|
|
6
8
|
import { proxyAndRecord } from "./recorder.js";
|
|
7
|
-
import {
|
|
9
|
+
import { servedPayloadLength } from "./response/timing.js";
|
|
10
|
+
import { deliverJson, deliverStream } from "./response/deliver.js";
|
|
11
|
+
import { proxyInterruption, withHangUpDetection } from "./response/proxy.js";
|
|
12
|
+
import { serveRawResponse } from "./response/raw.js";
|
|
13
|
+
import { mapCohereFinish } from "./response/finish.js";
|
|
14
|
+
import { render } from "./response/usage/codecs/cohere.js";
|
|
8
15
|
|
|
9
16
|
//#region src/cohere.ts
|
|
10
|
-
const ZERO_USAGE = {
|
|
11
|
-
billed_units: {
|
|
12
|
-
input_tokens: 0,
|
|
13
|
-
output_tokens: 0,
|
|
14
|
-
search_units: 0,
|
|
15
|
-
classifications: 0
|
|
16
|
-
},
|
|
17
|
-
tokens: {
|
|
18
|
-
input_tokens: 0,
|
|
19
|
-
output_tokens: 0
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
17
|
function cohereFinishReason(overrideFinishReason, defaultReason) {
|
|
23
18
|
if (!overrideFinishReason) return defaultReason;
|
|
24
|
-
|
|
25
|
-
if (overrideFinishReason === "tool_calls") return "TOOL_CALL";
|
|
26
|
-
if (overrideFinishReason === "length") return "MAX_TOKENS";
|
|
27
|
-
return overrideFinishReason;
|
|
19
|
+
return mapCohereFinish(overrideFinishReason);
|
|
28
20
|
}
|
|
29
21
|
function cohereUsage(overrides) {
|
|
30
|
-
|
|
31
|
-
const inputTokens = overrides.usage.input_tokens ?? overrides.usage.prompt_tokens ?? 0;
|
|
32
|
-
const outputTokens = overrides.usage.output_tokens ?? overrides.usage.completion_tokens ?? 0;
|
|
33
|
-
return {
|
|
34
|
-
billed_units: {
|
|
35
|
-
input_tokens: inputTokens,
|
|
36
|
-
output_tokens: outputTokens,
|
|
37
|
-
search_units: 0,
|
|
38
|
-
classifications: 0
|
|
39
|
-
},
|
|
40
|
-
tokens: {
|
|
41
|
-
input_tokens: inputTokens,
|
|
42
|
-
output_tokens: outputTokens
|
|
43
|
-
}
|
|
44
|
-
};
|
|
22
|
+
return render(overrides);
|
|
45
23
|
}
|
|
46
24
|
/** Extract plain text from structured content (array of { type, text } parts) or passthrough string. */
|
|
47
25
|
function extractTextContent(content) {
|
|
@@ -530,34 +508,6 @@ function buildCohereContentWithToolCallsStreamEvents(content, toolCalls, chunkSi
|
|
|
530
508
|
});
|
|
531
509
|
return events;
|
|
532
510
|
}
|
|
533
|
-
async function writeCohereSSEStream(res, events, optionsOrLatency) {
|
|
534
|
-
const opts = typeof optionsOrLatency === "number" ? { latency: optionsOrLatency } : optionsOrLatency ?? {};
|
|
535
|
-
const latency = opts.latency ?? 0;
|
|
536
|
-
const profile = opts.streamingProfile;
|
|
537
|
-
const { recordedTimings, replaySpeed } = opts;
|
|
538
|
-
const signal = opts.signal;
|
|
539
|
-
const onChunkSent = opts.onChunkSent;
|
|
540
|
-
if (res.writableEnded) return true;
|
|
541
|
-
res.setHeader("Content-Type", "text/event-stream");
|
|
542
|
-
res.setHeader("Cache-Control", "no-cache");
|
|
543
|
-
res.setHeader("Connection", "keep-alive");
|
|
544
|
-
let chunkIndex = 0;
|
|
545
|
-
for (const event of events) {
|
|
546
|
-
const chunkDelay = calculateDelay(chunkIndex, profile, latency, recordedTimings, replaySpeed);
|
|
547
|
-
if (chunkDelay > 0) await delay(chunkDelay, signal);
|
|
548
|
-
if (signal?.aborted) return false;
|
|
549
|
-
if (res.writableEnded) return true;
|
|
550
|
-
res.write(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`);
|
|
551
|
-
onChunkSent?.();
|
|
552
|
-
if (signal?.aborted) return false;
|
|
553
|
-
chunkIndex++;
|
|
554
|
-
}
|
|
555
|
-
if (!res.writableEnded) {
|
|
556
|
-
if (opts.terminalSentinel && !signal?.aborted) res.write("data: [DONE]\n\n");
|
|
557
|
-
res.end();
|
|
558
|
-
}
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
511
|
async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsHeaders) {
|
|
562
512
|
const { logger } = defaults;
|
|
563
513
|
setCorsHeaders(res);
|
|
@@ -576,10 +526,10 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
576
526
|
fixture: null
|
|
577
527
|
}
|
|
578
528
|
});
|
|
579
|
-
writeErrorResponse(res, 400,
|
|
529
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
580
530
|
message: `Malformed JSON body: ${detail}`,
|
|
581
531
|
type: "invalid_request_error"
|
|
582
|
-
}
|
|
532
|
+
}).body);
|
|
583
533
|
return;
|
|
584
534
|
}
|
|
585
535
|
if (!isJsonObject(cohereReq)) {
|
|
@@ -593,10 +543,10 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
593
543
|
fixture: null
|
|
594
544
|
}
|
|
595
545
|
});
|
|
596
|
-
writeErrorResponse(res, 400,
|
|
546
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
597
547
|
message: "Request body must be a JSON object",
|
|
598
548
|
type: "invalid_request_error"
|
|
599
|
-
}
|
|
549
|
+
}).body);
|
|
600
550
|
return;
|
|
601
551
|
}
|
|
602
552
|
if (!cohereReq.model) {
|
|
@@ -610,10 +560,10 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
610
560
|
fixture: null
|
|
611
561
|
}
|
|
612
562
|
});
|
|
613
|
-
writeErrorResponse(res, 400,
|
|
563
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
614
564
|
message: "model is required",
|
|
615
565
|
type: "invalid_request_error"
|
|
616
|
-
}
|
|
566
|
+
}).body);
|
|
617
567
|
return;
|
|
618
568
|
}
|
|
619
569
|
let shapeError = validateChatMessages(cohereReq.messages) ?? validateToolsField(cohereReq.tools);
|
|
@@ -632,17 +582,20 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
632
582
|
fixture: null
|
|
633
583
|
}
|
|
634
584
|
});
|
|
635
|
-
writeErrorResponse(res, 400,
|
|
585
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
636
586
|
message: `Invalid request: ${shapeError}`,
|
|
637
587
|
type: "invalid_request_error"
|
|
638
|
-
}
|
|
588
|
+
}).body);
|
|
639
589
|
return;
|
|
640
590
|
}
|
|
641
591
|
const completionReq = cohereToCompletionRequest(cohereReq);
|
|
642
592
|
completionReq._endpointType = "chat";
|
|
643
593
|
completionReq._context = getContext(req);
|
|
644
594
|
const testId = getTestId(req);
|
|
645
|
-
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform,
|
|
595
|
+
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, completionReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform, {
|
|
596
|
+
...recordMatchOptions(!!defaults.record, defaults.logger),
|
|
597
|
+
wire: "cohere"
|
|
598
|
+
});
|
|
646
599
|
if (fixture) {
|
|
647
600
|
journal.incrementFixtureMatchCount(fixture, fixtures, testId);
|
|
648
601
|
logger.debug(`Fixture matched: ${JSON.stringify(fixture.match).slice(0, 120)}`);
|
|
@@ -654,7 +607,7 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
654
607
|
body: completionReq
|
|
655
608
|
}, fixture ? "fixture" : "proxy", defaults.registry, defaults.logger)) return;
|
|
656
609
|
if (!fixture) {
|
|
657
|
-
if (
|
|
610
|
+
if (resolveRequestDecisions(defaults.strict, req.headers).fixtureMiss) {
|
|
658
611
|
const strictStatus = 503;
|
|
659
612
|
const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
660
613
|
logger.error(strictNoMatchLogLine(req.method ?? "POST", req.url ?? "/v2/chat", skippedBySequenceOrTurn));
|
|
@@ -669,14 +622,14 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
669
622
|
...strictOverrideField(defaults.strict, req.headers)
|
|
670
623
|
}
|
|
671
624
|
});
|
|
672
|
-
writeErrorResponse(res, strictStatus,
|
|
625
|
+
writeErrorResponse(res, strictStatus, renderError("cohere", "strict-miss", {
|
|
673
626
|
message: strictMessage,
|
|
674
627
|
type: "invalid_request_error"
|
|
675
|
-
}
|
|
628
|
+
}).body);
|
|
676
629
|
return;
|
|
677
630
|
}
|
|
678
631
|
if (defaults.record) {
|
|
679
|
-
const outcome = await proxyAndRecord(req, res, completionReq, "cohere", req.url ?? "/v2/chat", fixtures, defaults, raw);
|
|
632
|
+
const { outcome, clientHungUp } = await withHangUpDetection(req, res, () => proxyAndRecord(req, res, completionReq, "cohere", req.url ?? "/v2/chat", fixtures, defaults, raw));
|
|
680
633
|
if (outcome === "handled_by_hook") return;
|
|
681
634
|
if (outcome !== "not_configured") {
|
|
682
635
|
journal.add({
|
|
@@ -687,7 +640,8 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
687
640
|
response: {
|
|
688
641
|
status: res.statusCode ?? 200,
|
|
689
642
|
fixture: null,
|
|
690
|
-
source: "proxy"
|
|
643
|
+
source: "proxy",
|
|
644
|
+
...proxyInterruption(res, clientHungUp)
|
|
691
645
|
}
|
|
692
646
|
});
|
|
693
647
|
return;
|
|
@@ -704,10 +658,10 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
704
658
|
...strictOverrideField(defaults.strict, req.headers)
|
|
705
659
|
}
|
|
706
660
|
});
|
|
707
|
-
writeErrorResponse(res, 404,
|
|
661
|
+
writeErrorResponse(res, 404, renderError("cohere", "fixture-miss", {
|
|
708
662
|
message: "No fixture matched",
|
|
709
663
|
type: "invalid_request_error"
|
|
710
|
-
}
|
|
664
|
+
}).body);
|
|
711
665
|
return;
|
|
712
666
|
}
|
|
713
667
|
const resolvedResponse = await resolveResponse(fixture, completionReq);
|
|
@@ -739,15 +693,32 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
739
693
|
testId
|
|
740
694
|
});
|
|
741
695
|
if (!misbehavior.summary?.evaluations.length) logger.error(misbehavior.message);
|
|
742
|
-
writeErrorResponse(res, misbehavior.status,
|
|
696
|
+
writeErrorResponse(res, misbehavior.status, renderError("cohere", "misbehavior", {
|
|
743
697
|
message: misbehavior.message,
|
|
744
698
|
code: misbehavior.code
|
|
745
|
-
}));
|
|
699
|
+
}).body);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (isRawResponse(resolvedResponse)) {
|
|
703
|
+
await serveRawResponse({
|
|
704
|
+
wire: "cohere",
|
|
705
|
+
stream: cohereReq.stream === true,
|
|
706
|
+
req,
|
|
707
|
+
res,
|
|
708
|
+
fixture,
|
|
709
|
+
response: resolvedResponse,
|
|
710
|
+
body: completionReq,
|
|
711
|
+
journal,
|
|
712
|
+
defaults,
|
|
713
|
+
testId,
|
|
714
|
+
misbehaviorSummary: misbehavior.summary,
|
|
715
|
+
errorWire: "cohere"
|
|
716
|
+
});
|
|
746
717
|
return;
|
|
747
718
|
}
|
|
748
719
|
const prepared = misbehavior.kind === "applied" ? prepareOpenAIChatMisbehavior(misbehavior) : void 0;
|
|
749
720
|
const observedK5Stream = cohereReq.stream === true && prepared?.summary.fault === "stop-length-mid-tool";
|
|
750
|
-
const appliedReasoning = prepared && "reasoning" in prepared.response ? resolveReasoningForModel(prepared.response.reasoning, cohereReq.model,
|
|
721
|
+
const appliedReasoning = prepared && "reasoning" in prepared.response ? resolveReasoningForModel(prepared.response.reasoning, cohereReq.model, resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression, logger) : void 0;
|
|
751
722
|
const usage = prepared ? resolveOpenAIChatMisbehaviorUsage(prepared, completionReq, appliedReasoning !== void 0) : void 0;
|
|
752
723
|
const response = prepared && usage ? {
|
|
753
724
|
...prepared.response,
|
|
@@ -758,6 +729,22 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
758
729
|
const empty = prepared?.summary.fault === "empty-response";
|
|
759
730
|
const latency = fixture.latency ?? defaults.latency;
|
|
760
731
|
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
732
|
+
const replaySpeed = fixture.replaySpeed ?? defaults.replaySpeed;
|
|
733
|
+
const streamTiming = {
|
|
734
|
+
latency,
|
|
735
|
+
streamingProfile: fixture.streamingProfile,
|
|
736
|
+
recordedTimings: fixture.recordedTimings,
|
|
737
|
+
replaySpeed
|
|
738
|
+
};
|
|
739
|
+
const codec = typedSseCodec({ terminalSentinel: observedK5Stream });
|
|
740
|
+
const jsonOpts = (payloadLength) => ({
|
|
741
|
+
surface: "other",
|
|
742
|
+
payloadLength,
|
|
743
|
+
chunkSize,
|
|
744
|
+
recordedTimings: fixture.recordedTimings,
|
|
745
|
+
duplicateId: !!prepared?.duplicateId,
|
|
746
|
+
replaySpeed
|
|
747
|
+
});
|
|
761
748
|
if (isErrorResponse(response)) {
|
|
762
749
|
const status = response.status ?? 500;
|
|
763
750
|
recordMisbehaviorOutcome({
|
|
@@ -775,13 +762,13 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
775
762
|
defaults,
|
|
776
763
|
testId
|
|
777
764
|
});
|
|
778
|
-
writeErrorResponse(res, status,
|
|
765
|
+
writeErrorResponse(res, status, renderError("openai", "fixture", response.error).body, { retryAfter: response.retryAfter });
|
|
779
766
|
return;
|
|
780
767
|
}
|
|
781
768
|
if (isCombinedFixtureResponse(response)) {
|
|
782
769
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Cohere v2 Chat API — ignoring");
|
|
783
770
|
const overrides = extractOverrides(response);
|
|
784
|
-
const effectiveStrict =
|
|
771
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
785
772
|
const effReasoning = prepared ? appliedReasoning : resolveReasoningForModel(response.reasoning, cohereReq.model, effectiveStrict, logger);
|
|
786
773
|
const journalEntry = journal.add({
|
|
787
774
|
method: req.method ?? "POST",
|
|
@@ -800,34 +787,14 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
800
787
|
testId
|
|
801
788
|
});
|
|
802
789
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Cohere");
|
|
803
|
-
if (cohereReq.stream !== true)
|
|
804
|
-
|
|
805
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
806
|
-
res.end(JSON.stringify(body));
|
|
807
|
-
} else {
|
|
808
|
-
const events = buildCohereContentWithToolCallsStreamEvents(response.content ?? "", functionToolCalls, chunkSize, logger, effReasoning, overrides, response.blocks);
|
|
809
|
-
const interruption = createInterruptionSignal(fixture);
|
|
810
|
-
if (!await writeCohereSSEStream(res, events, {
|
|
811
|
-
terminalSentinel: observedK5Stream,
|
|
812
|
-
latency,
|
|
813
|
-
streamingProfile: fixture.streamingProfile,
|
|
814
|
-
recordedTimings: fixture.recordedTimings,
|
|
815
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
816
|
-
signal: interruption?.signal,
|
|
817
|
-
onChunkSent: interruption?.tick
|
|
818
|
-
})) {
|
|
819
|
-
if (!res.writableEnded) res.destroy();
|
|
820
|
-
journalEntry.response.interrupted = true;
|
|
821
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
822
|
-
}
|
|
823
|
-
interruption?.cleanup();
|
|
824
|
-
}
|
|
790
|
+
if (cohereReq.stream !== true) await deliverJson(res, journalEntry, fixture, () => buildCohereContentWithToolCallsResponse(response.content ?? "", functionToolCalls, logger, effReasoning, overrides, response.blocks), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
791
|
+
else await deliverStream(res, journalEntry, fixture, codec, buildCohereContentWithToolCallsStreamEvents(response.content ?? "", functionToolCalls, chunkSize, logger, effReasoning, overrides, response.blocks), streamTiming);
|
|
825
792
|
return;
|
|
826
793
|
}
|
|
827
794
|
if (isTextResponse(response)) {
|
|
828
795
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Cohere v2 Chat API — ignoring");
|
|
829
796
|
const overrides = extractOverrides(response);
|
|
830
|
-
const effectiveStrict =
|
|
797
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
831
798
|
const effReasoning = prepared ? appliedReasoning : resolveReasoningForModel(response.reasoning, cohereReq.model, effectiveStrict, logger);
|
|
832
799
|
const journalEntry = journal.add({
|
|
833
800
|
method: req.method ?? "POST",
|
|
@@ -845,43 +812,23 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
845
812
|
defaults,
|
|
846
813
|
testId
|
|
847
814
|
});
|
|
848
|
-
if (cohereReq.stream !== true) {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
citations: []
|
|
857
|
-
}
|
|
858
|
-
} : buildCohereTextResponse(response.content, effReasoning, overrides);
|
|
859
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
860
|
-
res.end(JSON.stringify(body));
|
|
861
|
-
} else {
|
|
862
|
-
const events = buildCohereTextStreamEvents(response.content, chunkSize, effReasoning, overrides).filter((event) => !empty || event.type === "message-start" || event.type === "message-end");
|
|
863
|
-
const interruption = createInterruptionSignal(fixture);
|
|
864
|
-
if (!await writeCohereSSEStream(res, events, {
|
|
865
|
-
terminalSentinel: observedK5Stream,
|
|
866
|
-
latency,
|
|
867
|
-
streamingProfile: fixture.streamingProfile,
|
|
868
|
-
recordedTimings: fixture.recordedTimings,
|
|
869
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
870
|
-
signal: interruption?.signal,
|
|
871
|
-
onChunkSent: interruption?.tick
|
|
872
|
-
})) {
|
|
873
|
-
if (!res.writableEnded) res.destroy();
|
|
874
|
-
journalEntry.response.interrupted = true;
|
|
875
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
815
|
+
if (cohereReq.stream !== true) await deliverJson(res, journalEntry, fixture, () => empty ? {
|
|
816
|
+
...buildCohereTextResponse("", void 0, overrides),
|
|
817
|
+
message: {
|
|
818
|
+
role: "assistant",
|
|
819
|
+
content: [],
|
|
820
|
+
tool_calls: [],
|
|
821
|
+
tool_plan: "",
|
|
822
|
+
citations: []
|
|
876
823
|
}
|
|
877
|
-
|
|
878
|
-
|
|
824
|
+
} : buildCohereTextResponse(response.content, effReasoning, overrides), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
825
|
+
else await deliverStream(res, journalEntry, fixture, codec, buildCohereTextStreamEvents(response.content, chunkSize, effReasoning, overrides).filter((event) => !empty || event.type === "message-start" || event.type === "message-end"), streamTiming);
|
|
879
826
|
return;
|
|
880
827
|
}
|
|
881
828
|
if (isToolCallResponse(response)) {
|
|
882
829
|
if (response.webSearches?.length) logger.warn("webSearches in fixture response are not supported for Cohere v2 Chat API — ignoring");
|
|
883
830
|
const overrides = extractOverrides(response);
|
|
884
|
-
const effectiveStrict =
|
|
831
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
885
832
|
const effReasoning = prepared ? appliedReasoning : resolveReasoningForModel(response.reasoning, cohereReq.model, effectiveStrict, logger);
|
|
886
833
|
const journalEntry = journal.add({
|
|
887
834
|
method: req.method ?? "POST",
|
|
@@ -900,28 +847,8 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
900
847
|
testId
|
|
901
848
|
});
|
|
902
849
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Cohere");
|
|
903
|
-
if (cohereReq.stream !== true)
|
|
904
|
-
|
|
905
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
906
|
-
res.end(JSON.stringify(body));
|
|
907
|
-
} else {
|
|
908
|
-
const events = buildCohereToolCallStreamEvents(functionToolCalls, chunkSize, logger, effReasoning, overrides);
|
|
909
|
-
const interruption = createInterruptionSignal(fixture);
|
|
910
|
-
if (!await writeCohereSSEStream(res, events, {
|
|
911
|
-
terminalSentinel: observedK5Stream,
|
|
912
|
-
latency,
|
|
913
|
-
streamingProfile: fixture.streamingProfile,
|
|
914
|
-
recordedTimings: fixture.recordedTimings,
|
|
915
|
-
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed,
|
|
916
|
-
signal: interruption?.signal,
|
|
917
|
-
onChunkSent: interruption?.tick
|
|
918
|
-
})) {
|
|
919
|
-
if (!res.writableEnded) res.destroy();
|
|
920
|
-
journalEntry.response.interrupted = true;
|
|
921
|
-
journalEntry.response.interruptReason = interruption?.reason();
|
|
922
|
-
}
|
|
923
|
-
interruption?.cleanup();
|
|
924
|
-
}
|
|
850
|
+
if (cohereReq.stream !== true) await deliverJson(res, journalEntry, fixture, () => buildCohereToolCallResponse(functionToolCalls, logger, effReasoning, overrides), jsonOpts(servedPayloadLength(response, effReasoning)));
|
|
851
|
+
else await deliverStream(res, journalEntry, fixture, codec, buildCohereToolCallStreamEvents(functionToolCalls, chunkSize, logger, effReasoning, overrides), streamTiming);
|
|
925
852
|
return;
|
|
926
853
|
}
|
|
927
854
|
recordMisbehaviorOutcome({
|
|
@@ -939,10 +866,10 @@ async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
939
866
|
defaults,
|
|
940
867
|
testId
|
|
941
868
|
});
|
|
942
|
-
writeErrorResponse(res, 500,
|
|
869
|
+
writeErrorResponse(res, 500, renderError("cohere", "unknown-response", {
|
|
943
870
|
message: "Fixture response did not match any known type",
|
|
944
871
|
type: "server_error"
|
|
945
|
-
}
|
|
872
|
+
}).body);
|
|
946
873
|
}
|
|
947
874
|
async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, setCorsHeaders) {
|
|
948
875
|
const { logger } = defaults;
|
|
@@ -962,10 +889,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
962
889
|
fixture: null
|
|
963
890
|
}
|
|
964
891
|
});
|
|
965
|
-
writeErrorResponse(res, 400,
|
|
892
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
966
893
|
message: `Malformed JSON body: ${detail}`,
|
|
967
894
|
type: "invalid_request_error"
|
|
968
|
-
}
|
|
895
|
+
}).body);
|
|
969
896
|
return;
|
|
970
897
|
}
|
|
971
898
|
if (!isJsonObject(embedReq)) {
|
|
@@ -979,10 +906,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
979
906
|
fixture: null
|
|
980
907
|
}
|
|
981
908
|
});
|
|
982
|
-
writeErrorResponse(res, 400,
|
|
909
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
983
910
|
message: "Request body must be a JSON object",
|
|
984
911
|
type: "invalid_request_error"
|
|
985
|
-
}
|
|
912
|
+
}).body);
|
|
986
913
|
return;
|
|
987
914
|
}
|
|
988
915
|
if (!embedReq.model) {
|
|
@@ -996,10 +923,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
996
923
|
fixture: null
|
|
997
924
|
}
|
|
998
925
|
});
|
|
999
|
-
writeErrorResponse(res, 400,
|
|
926
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
1000
927
|
message: "model is required",
|
|
1001
928
|
type: "invalid_request_error"
|
|
1002
|
-
}
|
|
929
|
+
}).body);
|
|
1003
930
|
return;
|
|
1004
931
|
}
|
|
1005
932
|
if (!embedReq.texts || !Array.isArray(embedReq.texts)) {
|
|
@@ -1013,10 +940,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1013
940
|
fixture: null
|
|
1014
941
|
}
|
|
1015
942
|
});
|
|
1016
|
-
writeErrorResponse(res, 400,
|
|
943
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
1017
944
|
message: "Invalid request: texts array is required",
|
|
1018
945
|
type: "invalid_request_error"
|
|
1019
|
-
}
|
|
946
|
+
}).body);
|
|
1020
947
|
return;
|
|
1021
948
|
}
|
|
1022
949
|
if (!embedReq.texts.every((text) => typeof text === "string")) {
|
|
@@ -1030,10 +957,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1030
957
|
fixture: null
|
|
1031
958
|
}
|
|
1032
959
|
});
|
|
1033
|
-
writeErrorResponse(res, 400,
|
|
960
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
1034
961
|
message: "Invalid request: texts must be an array of strings",
|
|
1035
962
|
type: "invalid_request_error"
|
|
1036
|
-
}
|
|
963
|
+
}).body);
|
|
1037
964
|
return;
|
|
1038
965
|
}
|
|
1039
966
|
const combinedInput = embedReq.texts.join(" ");
|
|
@@ -1071,10 +998,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1071
998
|
fixture: fixture ?? null
|
|
1072
999
|
}
|
|
1073
1000
|
});
|
|
1074
|
-
writeErrorResponse(res, 400,
|
|
1001
|
+
writeErrorResponse(res, 400, renderError("cohere", "validation", {
|
|
1075
1002
|
message: isArray ? "Invalid request: embedding_types must be an array of strings" : "Invalid request: embedding_types must be an array",
|
|
1076
1003
|
type: "invalid_request_error"
|
|
1077
|
-
}
|
|
1004
|
+
}).body);
|
|
1078
1005
|
return true;
|
|
1079
1006
|
}
|
|
1080
1007
|
if (fixture) {
|
|
@@ -1091,7 +1018,7 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1091
1018
|
fixture
|
|
1092
1019
|
}
|
|
1093
1020
|
});
|
|
1094
|
-
writeErrorResponse(res, status,
|
|
1021
|
+
writeErrorResponse(res, status, renderError("openai", "fixture", response.error).body, { retryAfter: response.retryAfter });
|
|
1095
1022
|
return;
|
|
1096
1023
|
}
|
|
1097
1024
|
if (isEmbeddingResponse(response)) {
|
|
@@ -1129,13 +1056,13 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1129
1056
|
fixture
|
|
1130
1057
|
}
|
|
1131
1058
|
});
|
|
1132
|
-
writeErrorResponse(res, 500,
|
|
1059
|
+
writeErrorResponse(res, 500, renderError("cohere", "unknown-response", {
|
|
1133
1060
|
message: "Fixture response did not match any known embedding type (must have embedding or error)",
|
|
1134
1061
|
type: "server_error"
|
|
1135
|
-
}
|
|
1062
|
+
}).body);
|
|
1136
1063
|
return;
|
|
1137
1064
|
}
|
|
1138
|
-
if (
|
|
1065
|
+
if (resolveRequestDecisions(defaults.strict, req.headers).fixtureMiss) {
|
|
1139
1066
|
const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
1140
1067
|
logger.error(strictNoMatchLogLine(req.method ?? "POST", req.url ?? "/v2/embed", skippedBySequenceOrTurn));
|
|
1141
1068
|
journal.add({
|
|
@@ -1149,10 +1076,10 @@ async function handleCohereEmbed(req, res, raw, fixtures, journal, defaults, set
|
|
|
1149
1076
|
...strictOverrideField(defaults.strict, req.headers)
|
|
1150
1077
|
}
|
|
1151
1078
|
});
|
|
1152
|
-
writeErrorResponse(res, 503,
|
|
1079
|
+
writeErrorResponse(res, 503, renderError("cohere", "strict-miss", {
|
|
1153
1080
|
message: strictMessage,
|
|
1154
1081
|
type: "invalid_request_error"
|
|
1155
|
-
}
|
|
1082
|
+
}).body);
|
|
1156
1083
|
return;
|
|
1157
1084
|
}
|
|
1158
1085
|
if (defaults.record) {
|