@copilotkit/aimock 1.45.0 → 1.46.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 +24 -0
- package/README.md +7 -1
- 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.ts.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/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 +61 -80
- 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 +58 -77
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +65 -97
- 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 +62 -94
- 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 +49 -74
- 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 +47 -72
- 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 +37 -42
- 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 +37 -42
- 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 +50 -35
- 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 +49 -34
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +57 -67
- 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 +56 -67
- 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 +11 -68
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +12 -67
- 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.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- 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 +14 -4
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.js +14 -4
- 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 +111 -96
- 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 +109 -95
- 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/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/ollama.cjs +128 -68
- 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 +124 -64
- 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 +76 -71
- 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 +63 -58
- package/dist/openrouter-video.js.map +1 -1
- 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/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/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/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 +45 -58
- 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 +44 -57
- 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 +4 -0
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +3 -0
- 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 +222 -146
- 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 +223 -147
- 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 +7 -0
- package/dist/sse-writer.cjs.map +1 -1
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/sse-writer.js +7 -1
- 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 +12 -10
- 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 +11 -9
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +62 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +62 -3
- 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-gemini-live.cjs +11 -3
- 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 +10 -2
- 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 +28 -54
- 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 +25 -51
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +8 -6
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.js +7 -5
- package/dist/ws-responses.js.map +1 -1
- package/package.json +4 -1
- package/skills/write-fixtures/SKILL.md +25 -16
package/dist/ollama.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderError } from "./response/errors.js";
|
|
2
|
+
import { resolveRequestDecisions, strictOverrideField } from "./response/policy.js";
|
|
3
|
+
import { InvalidToolArgumentsError, MAX_EMBEDDING_DIMENSIONS, flattenHeaders, generateDeterministicEmbedding, getContext, getTestId, isCombinedFixtureResponse, isEmbeddingResponse, isErrorResponse, isJSONResponse, isJsonObject, isTextResponse, isToolCallResponse, normalizeEmbeddingInput, requireEmittedFunctionToolCalls, resolveFixtureBlockOutcome, resolveFixtureBlocks, resolveReasoningForModel, resolveResponse, servedToolArgs, strictNoMatchLogLine, strictNoMatchMessage, toolArgsForWire, validateChatMessages, validateEmbeddingDimensions, validateToolsField } from "./helpers.js";
|
|
2
4
|
import { writeErrorResponse } from "./sse-writer.js";
|
|
3
5
|
import { applyChaosAsync } from "./chaos.js";
|
|
4
6
|
import { planMisbehavior, recordMisbehaviorOutcome } from "./misbehavior.js";
|
|
7
|
+
import { setEmbeddingRequest } from "./embedding-request.js";
|
|
5
8
|
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
|
|
6
9
|
import { proxyAndRecord } from "./recorder.js";
|
|
7
10
|
import { createInterruptionSignal } from "./interruption.js";
|
|
8
11
|
import { writeNDJSONStream } from "./ndjson-writer.js";
|
|
12
|
+
import { render } from "./response/usage/codecs/ollama.js";
|
|
9
13
|
|
|
10
14
|
//#region src/ollama.ts
|
|
11
15
|
const DURATION_FIELDS = {
|
|
12
16
|
done_reason: "stop",
|
|
13
17
|
total_duration: 0,
|
|
14
18
|
load_duration: 0,
|
|
15
|
-
|
|
19
|
+
...render({ kind: "ordinary-zero" }, "prompt"),
|
|
16
20
|
prompt_eval_duration: 0,
|
|
17
|
-
|
|
21
|
+
...render({ kind: "ordinary-zero" }, "completion"),
|
|
18
22
|
eval_duration: 0
|
|
19
23
|
};
|
|
20
24
|
function ollamaToCompletionRequest(req) {
|
|
@@ -393,8 +397,11 @@ function prepareOllamaMisbehavior(plan, request, stream, chunkSize, effectiveStr
|
|
|
393
397
|
const terminal = chunks.length - 1;
|
|
394
398
|
chunks[terminal] = {
|
|
395
399
|
...chunks[terminal],
|
|
396
|
-
|
|
397
|
-
|
|
400
|
+
...render({
|
|
401
|
+
kind: "applied-chat-estimate",
|
|
402
|
+
messages: request.messages,
|
|
403
|
+
completion
|
|
404
|
+
})
|
|
398
405
|
};
|
|
399
406
|
return {
|
|
400
407
|
chunks,
|
|
@@ -467,10 +474,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
467
474
|
fixture: null
|
|
468
475
|
}
|
|
469
476
|
});
|
|
470
|
-
writeErrorResponse(res, 400,
|
|
477
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
471
478
|
message: `Malformed JSON body: ${detail}`,
|
|
472
479
|
type: "invalid_request_error"
|
|
473
|
-
}
|
|
480
|
+
}).body);
|
|
474
481
|
return;
|
|
475
482
|
}
|
|
476
483
|
if (!isJsonObject(ollamaReq)) {
|
|
@@ -484,10 +491,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
484
491
|
fixture: null
|
|
485
492
|
}
|
|
486
493
|
});
|
|
487
|
-
writeErrorResponse(res, 400,
|
|
494
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
488
495
|
message: "Request body must be a JSON object",
|
|
489
496
|
type: "invalid_request_error"
|
|
490
|
-
}
|
|
497
|
+
}).body);
|
|
491
498
|
return;
|
|
492
499
|
}
|
|
493
500
|
let chatShapeError = validateChatMessages(ollamaReq.messages) ?? validateToolsField(ollamaReq.tools);
|
|
@@ -506,10 +513,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
506
513
|
fixture: null
|
|
507
514
|
}
|
|
508
515
|
});
|
|
509
|
-
writeErrorResponse(res, 400,
|
|
516
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
510
517
|
message: `Invalid request: ${chatShapeError}`,
|
|
511
518
|
type: "invalid_request_error"
|
|
512
|
-
}
|
|
519
|
+
}).body);
|
|
513
520
|
return;
|
|
514
521
|
}
|
|
515
522
|
const completionReq = ollamaToCompletionRequest(ollamaReq);
|
|
@@ -528,7 +535,7 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
528
535
|
body: completionReq
|
|
529
536
|
}, fixture ? "fixture" : "proxy", defaults.registry, defaults.logger)) return;
|
|
530
537
|
if (!fixture) {
|
|
531
|
-
if (
|
|
538
|
+
if (resolveRequestDecisions(defaults.strict, req.headers).fixtureMiss) {
|
|
532
539
|
const strictStatus = 503;
|
|
533
540
|
const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
534
541
|
logger.error(strictNoMatchLogLine(req.method ?? "POST", urlPath, skippedBySequenceOrTurn));
|
|
@@ -543,10 +550,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
543
550
|
...strictOverrideField(defaults.strict, req.headers)
|
|
544
551
|
}
|
|
545
552
|
});
|
|
546
|
-
writeErrorResponse(res, strictStatus,
|
|
553
|
+
writeErrorResponse(res, strictStatus, renderError("ollama", "strict-miss", {
|
|
547
554
|
message: strictMessage,
|
|
548
555
|
type: "invalid_request_error"
|
|
549
|
-
}
|
|
556
|
+
}).body);
|
|
550
557
|
return;
|
|
551
558
|
}
|
|
552
559
|
if (defaults.record) {
|
|
@@ -578,10 +585,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
578
585
|
...strictOverrideField(defaults.strict, req.headers)
|
|
579
586
|
}
|
|
580
587
|
});
|
|
581
|
-
writeErrorResponse(res, 404,
|
|
588
|
+
writeErrorResponse(res, 404, renderError("ollama", "fixture-miss", {
|
|
582
589
|
message: "No fixture matched",
|
|
583
590
|
type: "invalid_request_error"
|
|
584
|
-
}
|
|
591
|
+
}).body);
|
|
585
592
|
return;
|
|
586
593
|
}
|
|
587
594
|
const response = await resolveResponse(fixture, completionReq);
|
|
@@ -613,14 +620,17 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
613
620
|
});
|
|
614
621
|
const message = `${misbehavior.code}: ${misbehavior.message}`;
|
|
615
622
|
if (!misbehavior.summary?.evaluations.length) defaults.logger.error(message);
|
|
616
|
-
writeErrorResponse(res, misbehavior.status,
|
|
623
|
+
writeErrorResponse(res, misbehavior.status, renderError("ollama", "misbehavior", {
|
|
624
|
+
message: misbehavior.message,
|
|
625
|
+
code: misbehavior.code
|
|
626
|
+
}).body);
|
|
617
627
|
return;
|
|
618
628
|
}
|
|
619
629
|
const latency = fixture.latency ?? defaults.latency;
|
|
620
630
|
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
621
631
|
const streaming = ollamaReq.stream !== false;
|
|
622
632
|
if (misbehavior.kind === "applied") {
|
|
623
|
-
const prepared = prepareOllamaMisbehavior(misbehavior, completionReq, streaming, chunkSize,
|
|
633
|
+
const prepared = prepareOllamaMisbehavior(misbehavior, completionReq, streaming, chunkSize, resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression, logger);
|
|
624
634
|
const journalEntry = journal.add({
|
|
625
635
|
method: req.method ?? "POST",
|
|
626
636
|
path: urlPath,
|
|
@@ -675,7 +685,7 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
675
685
|
defaults,
|
|
676
686
|
testId
|
|
677
687
|
});
|
|
678
|
-
writeErrorResponse(res, status,
|
|
688
|
+
writeErrorResponse(res, status, renderError("openai", "fixture", response.error).body, { retryAfter: response.retryAfter });
|
|
679
689
|
return;
|
|
680
690
|
}
|
|
681
691
|
if (isCombinedFixtureResponse(response)) {
|
|
@@ -697,7 +707,7 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
697
707
|
testId
|
|
698
708
|
});
|
|
699
709
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Ollama");
|
|
700
|
-
const effectiveStrict =
|
|
710
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
701
711
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, effectiveStrict, logger);
|
|
702
712
|
if (!streaming) {
|
|
703
713
|
const body = buildOllamaChatContentWithToolCallsResponse(response.content ?? "", functionToolCalls, completionReq.model, effReasoning, response.blocks);
|
|
@@ -740,7 +750,7 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
740
750
|
defaults,
|
|
741
751
|
testId
|
|
742
752
|
});
|
|
743
|
-
const effectiveStrict =
|
|
753
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
744
754
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, effectiveStrict, logger);
|
|
745
755
|
if (!streaming) {
|
|
746
756
|
const body = buildOllamaChatTextResponse(response.content, completionReq.model, effReasoning);
|
|
@@ -784,7 +794,7 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
784
794
|
testId
|
|
785
795
|
});
|
|
786
796
|
const functionToolCalls = requireEmittedFunctionToolCalls(response, "Ollama");
|
|
787
|
-
const effectiveStrict =
|
|
797
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
788
798
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, effectiveStrict, logger);
|
|
789
799
|
if (!streaming) {
|
|
790
800
|
const body = buildOllamaChatToolCallResponse(functionToolCalls, completionReq.model, effReasoning);
|
|
@@ -824,10 +834,10 @@ async function handleOllama(req, res, raw, fixtures, journal, defaults, setCorsH
|
|
|
824
834
|
defaults,
|
|
825
835
|
testId
|
|
826
836
|
});
|
|
827
|
-
writeErrorResponse(res, 500,
|
|
837
|
+
writeErrorResponse(res, 500, renderError("ollama", "unknown-response", {
|
|
828
838
|
message: "Fixture response did not match any known type",
|
|
829
839
|
type: "server_error"
|
|
830
|
-
}
|
|
840
|
+
}).body);
|
|
831
841
|
}
|
|
832
842
|
async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults, setCorsHeaders) {
|
|
833
843
|
setCorsHeaders(res);
|
|
@@ -847,10 +857,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
847
857
|
fixture: null
|
|
848
858
|
}
|
|
849
859
|
});
|
|
850
|
-
writeErrorResponse(res, 400,
|
|
860
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
851
861
|
message: `Malformed JSON body: ${detail}`,
|
|
852
862
|
type: "invalid_request_error"
|
|
853
|
-
}
|
|
863
|
+
}).body);
|
|
854
864
|
return;
|
|
855
865
|
}
|
|
856
866
|
if (!isJsonObject(generateReq)) {
|
|
@@ -864,10 +874,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
864
874
|
fixture: null
|
|
865
875
|
}
|
|
866
876
|
});
|
|
867
|
-
writeErrorResponse(res, 400,
|
|
877
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
868
878
|
message: "Request body must be a JSON object",
|
|
869
879
|
type: "invalid_request_error"
|
|
870
|
-
}
|
|
880
|
+
}).body);
|
|
871
881
|
return;
|
|
872
882
|
}
|
|
873
883
|
if (!generateReq.prompt || typeof generateReq.prompt !== "string") {
|
|
@@ -881,10 +891,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
881
891
|
fixture: null
|
|
882
892
|
}
|
|
883
893
|
});
|
|
884
|
-
writeErrorResponse(res, 400,
|
|
894
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
885
895
|
message: "Invalid request: prompt field is required",
|
|
886
896
|
type: "invalid_request_error"
|
|
887
|
-
}
|
|
897
|
+
}).body);
|
|
888
898
|
return;
|
|
889
899
|
}
|
|
890
900
|
const completionReq = ollamaGenerateToCompletionRequest(generateReq);
|
|
@@ -903,7 +913,7 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
903
913
|
body: completionReq
|
|
904
914
|
}, fixture ? "fixture" : "proxy", defaults.registry, defaults.logger)) return;
|
|
905
915
|
if (!fixture) {
|
|
906
|
-
if (
|
|
916
|
+
if (resolveRequestDecisions(defaults.strict, req.headers).fixtureMiss) {
|
|
907
917
|
const strictStatus = 503;
|
|
908
918
|
const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
909
919
|
defaults.logger.error(strictNoMatchLogLine(req.method ?? "POST", urlPath, skippedBySequenceOrTurn));
|
|
@@ -918,10 +928,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
918
928
|
...strictOverrideField(defaults.strict, req.headers)
|
|
919
929
|
}
|
|
920
930
|
});
|
|
921
|
-
writeErrorResponse(res, strictStatus,
|
|
931
|
+
writeErrorResponse(res, strictStatus, renderError("ollama", "strict-miss", {
|
|
922
932
|
message: strictMessage,
|
|
923
933
|
type: "invalid_request_error"
|
|
924
|
-
}
|
|
934
|
+
}).body);
|
|
925
935
|
return;
|
|
926
936
|
}
|
|
927
937
|
if (defaults.record) {
|
|
@@ -953,10 +963,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
953
963
|
...strictOverrideField(defaults.strict, req.headers)
|
|
954
964
|
}
|
|
955
965
|
});
|
|
956
|
-
writeErrorResponse(res, 404,
|
|
966
|
+
writeErrorResponse(res, 404, renderError("ollama", "fixture-miss", {
|
|
957
967
|
message: "No fixture matched",
|
|
958
968
|
type: "invalid_request_error"
|
|
959
|
-
}
|
|
969
|
+
}).body);
|
|
960
970
|
return;
|
|
961
971
|
}
|
|
962
972
|
const response = await resolveResponse(fixture, completionReq);
|
|
@@ -989,7 +999,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
989
999
|
});
|
|
990
1000
|
const message = `${misbehavior.code}: ${misbehavior.message}`;
|
|
991
1001
|
if (!misbehavior.summary?.evaluations.length) defaults.logger.error(message);
|
|
992
|
-
writeErrorResponse(res, misbehavior.status,
|
|
1002
|
+
writeErrorResponse(res, misbehavior.status, renderError("ollama", "misbehavior", {
|
|
1003
|
+
message: misbehavior.message,
|
|
1004
|
+
code: misbehavior.code
|
|
1005
|
+
}).body);
|
|
993
1006
|
return;
|
|
994
1007
|
}
|
|
995
1008
|
const latency = fixture.latency ?? defaults.latency;
|
|
@@ -1012,7 +1025,7 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
1012
1025
|
defaults,
|
|
1013
1026
|
testId
|
|
1014
1027
|
});
|
|
1015
|
-
writeErrorResponse(res, status,
|
|
1028
|
+
writeErrorResponse(res, status, renderError("openai", "fixture", response.error).body, { retryAfter: response.retryAfter });
|
|
1016
1029
|
return;
|
|
1017
1030
|
}
|
|
1018
1031
|
if (isTextResponse(response)) {
|
|
@@ -1032,7 +1045,7 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
1032
1045
|
defaults,
|
|
1033
1046
|
testId
|
|
1034
1047
|
});
|
|
1035
|
-
const effectiveStrict =
|
|
1048
|
+
const effectiveStrict = resolveRequestDecisions(defaults.strict, req.headers).reasoningSuppression;
|
|
1036
1049
|
const effReasoning = resolveReasoningForModel(response.reasoning, completionReq.model, effectiveStrict, defaults.logger);
|
|
1037
1050
|
if (!streaming) {
|
|
1038
1051
|
const body = buildOllamaGenerateTextResponse(response.content, completionReq.model, effReasoning);
|
|
@@ -1073,10 +1086,10 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
1073
1086
|
defaults,
|
|
1074
1087
|
testId
|
|
1075
1088
|
});
|
|
1076
|
-
writeErrorResponse(res, 400,
|
|
1089
|
+
writeErrorResponse(res, 400, renderError("ollama", "validation", {
|
|
1077
1090
|
message: "Tool call fixtures are not supported on /api/generate — use /api/chat instead",
|
|
1078
1091
|
type: "invalid_request_error"
|
|
1079
|
-
}
|
|
1092
|
+
}).body);
|
|
1080
1093
|
return;
|
|
1081
1094
|
}
|
|
1082
1095
|
recordMisbehaviorOutcome({
|
|
@@ -1094,15 +1107,17 @@ async function handleOllamaGenerate(req, res, raw, fixtures, journal, defaults,
|
|
|
1094
1107
|
defaults,
|
|
1095
1108
|
testId
|
|
1096
1109
|
});
|
|
1097
|
-
writeErrorResponse(res, 500,
|
|
1110
|
+
writeErrorResponse(res, 500, renderError("ollama", "unknown-response", {
|
|
1098
1111
|
message: "Fixture response did not match any known type",
|
|
1099
1112
|
type: "server_error"
|
|
1100
|
-
}
|
|
1113
|
+
}).body);
|
|
1101
1114
|
}
|
|
1102
1115
|
async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults, setCorsHeaders) {
|
|
1103
1116
|
const { logger } = defaults;
|
|
1104
1117
|
setCorsHeaders(res);
|
|
1105
1118
|
const urlPath = req.url ?? "/api/embeddings";
|
|
1119
|
+
const currentEndpoint = urlPath.split("?")[0] === "/api/embed";
|
|
1120
|
+
const errorWire = currentEndpoint ? "ollama-embed" : "ollama";
|
|
1106
1121
|
let embReq;
|
|
1107
1122
|
try {
|
|
1108
1123
|
embReq = JSON.parse(raw);
|
|
@@ -1118,10 +1133,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1118
1133
|
fixture: null
|
|
1119
1134
|
}
|
|
1120
1135
|
});
|
|
1121
|
-
writeErrorResponse(res, 400,
|
|
1136
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1122
1137
|
message: `Malformed JSON body: ${detail}`,
|
|
1123
1138
|
type: "invalid_request_error"
|
|
1124
|
-
}
|
|
1139
|
+
}).body);
|
|
1125
1140
|
return;
|
|
1126
1141
|
}
|
|
1127
1142
|
if (!isJsonObject(embReq)) {
|
|
@@ -1135,10 +1150,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1135
1150
|
fixture: null
|
|
1136
1151
|
}
|
|
1137
1152
|
});
|
|
1138
|
-
writeErrorResponse(res, 400,
|
|
1153
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1139
1154
|
message: "Request body must be a JSON object",
|
|
1140
1155
|
type: "invalid_request_error"
|
|
1141
|
-
}
|
|
1156
|
+
}).body);
|
|
1142
1157
|
return;
|
|
1143
1158
|
}
|
|
1144
1159
|
const promptShapeError = embReq.prompt !== void 0 && embReq.prompt !== null && typeof embReq.prompt !== "string" ? "prompt field must be a string" : embReq.input !== void 0 && embReq.input !== null && normalizeEmbeddingInput(embReq.input) === null ? "input field must be a string or an array of strings" : null;
|
|
@@ -1153,14 +1168,15 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1153
1168
|
fixture: null
|
|
1154
1169
|
}
|
|
1155
1170
|
});
|
|
1156
|
-
writeErrorResponse(res, 400,
|
|
1171
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1157
1172
|
message: `Invalid request: ${promptShapeError}`,
|
|
1158
1173
|
type: "invalid_request_error"
|
|
1159
|
-
}
|
|
1174
|
+
}).body);
|
|
1160
1175
|
return;
|
|
1161
1176
|
}
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1177
|
+
const inputs = normalizeEmbeddingInput(currentEndpoint ? embReq.input ?? embReq.prompt : embReq.prompt ?? embReq.input);
|
|
1178
|
+
const inputText = currentEndpoint ? inputs?.join(" ") : embReq.prompt ?? (typeof embReq.input === "string" ? embReq.input : void 0) ?? (Array.isArray(embReq.input) ? embReq.input.join(" ") : void 0);
|
|
1179
|
+
if (!embReq.model || currentEndpoint && typeof embReq.model !== "string") {
|
|
1164
1180
|
journal.add({
|
|
1165
1181
|
method: req.method ?? "POST",
|
|
1166
1182
|
path: urlPath,
|
|
@@ -1171,10 +1187,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1171
1187
|
fixture: null
|
|
1172
1188
|
}
|
|
1173
1189
|
});
|
|
1174
|
-
writeErrorResponse(res, 400,
|
|
1190
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1175
1191
|
message: "Invalid request: model field is required",
|
|
1176
1192
|
type: "invalid_request_error"
|
|
1177
|
-
}
|
|
1193
|
+
}).body);
|
|
1178
1194
|
return;
|
|
1179
1195
|
}
|
|
1180
1196
|
if (!inputText) {
|
|
@@ -1188,10 +1204,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1188
1204
|
fixture: null
|
|
1189
1205
|
}
|
|
1190
1206
|
});
|
|
1191
|
-
writeErrorResponse(res, 400,
|
|
1207
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1192
1208
|
message: "Invalid request: prompt or input field is required",
|
|
1193
1209
|
type: "invalid_request_error"
|
|
1194
|
-
}
|
|
1210
|
+
}).body);
|
|
1195
1211
|
return;
|
|
1196
1212
|
}
|
|
1197
1213
|
const syntheticReq = {
|
|
@@ -1201,6 +1217,11 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1201
1217
|
_endpointType: "embedding",
|
|
1202
1218
|
_context: getContext(req)
|
|
1203
1219
|
};
|
|
1220
|
+
setEmbeddingRequest(syntheticReq, {
|
|
1221
|
+
operation: currentEndpoint ? "/api/embed" : "/api/embeddings",
|
|
1222
|
+
input: currentEndpoint ? embReq.input ?? embReq.prompt ?? "" : embReq.prompt ?? embReq.input ?? "",
|
|
1223
|
+
...embReq.dimensions !== void 0 && { dimensions: embReq.dimensions }
|
|
1224
|
+
});
|
|
1204
1225
|
const testId = getTestId(req);
|
|
1205
1226
|
const { fixture, skippedBySequenceOrTurn } = matchFixtureDiagnostic(fixtures, syntheticReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform, recordMatchOptions(!!defaults.record, defaults.logger));
|
|
1206
1227
|
if (fixture) {
|
|
@@ -1227,7 +1248,23 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1227
1248
|
fixture
|
|
1228
1249
|
}
|
|
1229
1250
|
});
|
|
1230
|
-
writeErrorResponse(res, status,
|
|
1251
|
+
writeErrorResponse(res, status, renderError(currentEndpoint ? "ollama-embed" : "openai", "fixture", response.error).body, { retryAfter: response.retryAfter });
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (currentEndpoint && isJSONResponse(response)) {
|
|
1255
|
+
const status = response.status ?? 200;
|
|
1256
|
+
journal.add({
|
|
1257
|
+
method: req.method ?? "POST",
|
|
1258
|
+
path: urlPath,
|
|
1259
|
+
headers: flattenHeaders(req.headers),
|
|
1260
|
+
body: syntheticReq,
|
|
1261
|
+
response: {
|
|
1262
|
+
status,
|
|
1263
|
+
fixture
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
1267
|
+
res.end(JSON.stringify(response.json));
|
|
1231
1268
|
return;
|
|
1232
1269
|
}
|
|
1233
1270
|
if (isEmbeddingResponse(response)) {
|
|
@@ -1241,7 +1278,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1241
1278
|
fixture
|
|
1242
1279
|
}
|
|
1243
1280
|
});
|
|
1244
|
-
const body = {
|
|
1281
|
+
const body = currentEndpoint ? {
|
|
1282
|
+
model: embReq.model,
|
|
1283
|
+
embeddings: (inputs ?? []).map(() => [...response.embedding])
|
|
1284
|
+
} : {
|
|
1245
1285
|
model: embReq.model,
|
|
1246
1286
|
embedding: [...response.embedding]
|
|
1247
1287
|
};
|
|
@@ -1259,13 +1299,13 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1259
1299
|
fixture
|
|
1260
1300
|
}
|
|
1261
1301
|
});
|
|
1262
|
-
writeErrorResponse(res, 500,
|
|
1302
|
+
writeErrorResponse(res, 500, renderError(errorWire, "unknown-response", {
|
|
1263
1303
|
message: "Fixture response did not match any known embedding type (must have embedding or error)",
|
|
1264
1304
|
type: "server_error"
|
|
1265
|
-
}
|
|
1305
|
+
}).body);
|
|
1266
1306
|
return;
|
|
1267
1307
|
}
|
|
1268
|
-
if (
|
|
1308
|
+
if (resolveRequestDecisions(defaults.strict, req.headers).fixtureMiss) {
|
|
1269
1309
|
const strictMessage = strictNoMatchMessage(skippedBySequenceOrTurn);
|
|
1270
1310
|
logger.error(strictNoMatchLogLine(req.method ?? "POST", urlPath, skippedBySequenceOrTurn));
|
|
1271
1311
|
journal.add({
|
|
@@ -1279,10 +1319,10 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1279
1319
|
...strictOverrideField(defaults.strict, req.headers)
|
|
1280
1320
|
}
|
|
1281
1321
|
});
|
|
1282
|
-
writeErrorResponse(res, 503,
|
|
1322
|
+
writeErrorResponse(res, 503, renderError(errorWire, "strict-miss", {
|
|
1283
1323
|
message: strictMessage,
|
|
1284
1324
|
type: "invalid_request_error"
|
|
1285
|
-
}
|
|
1325
|
+
}).body);
|
|
1286
1326
|
return;
|
|
1287
1327
|
}
|
|
1288
1328
|
if (defaults.record) {
|
|
@@ -1303,8 +1343,25 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1303
1343
|
return;
|
|
1304
1344
|
}
|
|
1305
1345
|
}
|
|
1346
|
+
const dimensions = currentEndpoint ? validateEmbeddingDimensions(embReq.dimensions) : 1536;
|
|
1347
|
+
if (dimensions === null) {
|
|
1348
|
+
journal.add({
|
|
1349
|
+
method: req.method ?? "POST",
|
|
1350
|
+
path: urlPath,
|
|
1351
|
+
headers: flattenHeaders(req.headers),
|
|
1352
|
+
body: syntheticReq,
|
|
1353
|
+
response: {
|
|
1354
|
+
status: 400,
|
|
1355
|
+
fixture: null
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
writeErrorResponse(res, 400, renderError(errorWire, "validation", {
|
|
1359
|
+
message: `Invalid request: dimensions must be an integer between 1 and ${MAX_EMBEDDING_DIMENSIONS}`,
|
|
1360
|
+
type: "invalid_request_error"
|
|
1361
|
+
}).body);
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1306
1364
|
logger.warn(`No embedding fixture matched for "${inputText.slice(0, 80)}" — returning deterministic fallback`);
|
|
1307
|
-
const embedding = generateDeterministicEmbedding(inputText);
|
|
1308
1365
|
journal.add({
|
|
1309
1366
|
method: req.method ?? "POST",
|
|
1310
1367
|
path: urlPath,
|
|
@@ -1315,9 +1372,12 @@ async function handleOllamaEmbeddings(req, res, raw, fixtures, journal, defaults
|
|
|
1315
1372
|
fixture: null
|
|
1316
1373
|
}
|
|
1317
1374
|
});
|
|
1318
|
-
const body = {
|
|
1375
|
+
const body = currentEndpoint ? {
|
|
1376
|
+
model: embReq.model,
|
|
1377
|
+
embeddings: (inputs ?? []).map((input) => generateDeterministicEmbedding(input, dimensions))
|
|
1378
|
+
} : {
|
|
1319
1379
|
model: embReq.model,
|
|
1320
|
-
embedding
|
|
1380
|
+
embedding: generateDeterministicEmbedding(inputText)
|
|
1321
1381
|
};
|
|
1322
1382
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1323
1383
|
res.end(JSON.stringify(body));
|