@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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { httpSink, runFrameLoop } from "./frame-loop.js";
|
|
2
|
+
import { delay } from "../sse-writer.js";
|
|
3
|
+
import { responseGoneReason } from "../chaos.js";
|
|
4
|
+
import { AIMOCK_DISCONNECTED, closedByClient, httpLifecycle, markInterrupted, noteDeliveryStart, requestSocket, statusLineSent, teardownReason } from "./lifecycle.js";
|
|
5
|
+
import { extendRecordedTimings, nonStreamingDelayMs, nonStreamingRecordedTimings, nonStreamingTimingEnabled } from "./timing.js";
|
|
6
|
+
|
|
7
|
+
//#region src/response/deliver.ts
|
|
8
|
+
/**
|
|
9
|
+
* Journal a delivery that ended early. The reason is always set: the
|
|
10
|
+
* lifecycle's first cause when it fired, else {@link teardownReason} for the
|
|
11
|
+
* response that is gone. When no byte of the response reached the socket
|
|
12
|
+
* ({@link statusLineSent}), the status is 0, the rule the server and the
|
|
13
|
+
* chaos `disconnect` apply to a torn socket. A fixture interruption
|
|
14
|
+
* (`disconnectAfterMs`, `truncateAfterChunks`) keeps the status it was
|
|
15
|
+
* journaled with, as base recorded it.
|
|
16
|
+
*/
|
|
17
|
+
function journalTeardown(entry, res, lifecycle) {
|
|
18
|
+
markInterrupted(entry, lifecycle?.reason() ?? teardownReason(res));
|
|
19
|
+
if (lifecycle?.cause() !== "fixture" && !statusLineSent(res)) entry.response.status = 0;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the response was torn down: the lifecycle fired, the response is
|
|
23
|
+
* destroyed or chaos disconnected it, or the client closed the socket.
|
|
24
|
+
*/
|
|
25
|
+
function tornDown(res, lifecycle) {
|
|
26
|
+
const socket = requestSocket(res);
|
|
27
|
+
const gone = responseGoneReason(res);
|
|
28
|
+
return lifecycle?.reason() !== void 0 || gone === "client-gone" || gone === "chaos-disconnected" || !res.writableEnded && !!socket && closedByClient(socket);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Journal a response that something else on aimock's side already answered
|
|
32
|
+
* (head committed or body ended) as aimock's teardown, with the status the
|
|
33
|
+
* client actually got.
|
|
34
|
+
*/
|
|
35
|
+
function journalAnsweredElsewhere(entry, res) {
|
|
36
|
+
markInterrupted(entry, AIMOCK_DISCONNECTED);
|
|
37
|
+
entry.response.status = statusLineSent(res) ? res.statusCode : 0;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether `deliverJson` can no longer write its reply, journaling why when it
|
|
41
|
+
* cannot. Torn down ({@link tornDown}): {@link journalTeardown}. Already
|
|
42
|
+
* answered by something else on aimock's side (head committed or body
|
|
43
|
+
* ended): writing again would throw `ERR_HTTP_HEADERS_SENT`, so it is
|
|
44
|
+
* journaled by {@link journalAnsweredElsewhere}, and a body that never ended
|
|
45
|
+
* is destroyed so the client does not hang.
|
|
46
|
+
*/
|
|
47
|
+
function journalUnwritable(entry, res, lifecycle) {
|
|
48
|
+
if (tornDown(res, lifecycle)) {
|
|
49
|
+
journalTeardown(entry, res, lifecycle);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (res.headersSent || res.writableEnded) {
|
|
53
|
+
journalAnsweredElsewhere(entry, res);
|
|
54
|
+
if (!res.writableEnded) res.destroy();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Deliver one streamed reply and journal how it ended. Builds the HTTP
|
|
61
|
+
* lifecycle (client close + fixture interruption) and runs the frame loop on
|
|
62
|
+
* it. When the loop stops early it destroys `res` (if it has not ended) and
|
|
63
|
+
* marks the entry with the first cause's reason (or, when no cause fired, who
|
|
64
|
+
* tore the response down). A response other code already answered (head
|
|
65
|
+
* committed before the stream, or body ended) is journaled as
|
|
66
|
+
* {@link deliverJson} journals it. It disposes the lifecycle on every path.
|
|
67
|
+
*/
|
|
68
|
+
async function deliverStream(res, entry, fixture, codec, frames, timing, opts) {
|
|
69
|
+
noteDeliveryStart(res);
|
|
70
|
+
const headSentBefore = res.headersSent;
|
|
71
|
+
const lifecycle = httpLifecycle(res, fixture, { streaming: true });
|
|
72
|
+
try {
|
|
73
|
+
if (!await runFrameLoop(httpSink(res), frames, codec, timing, {
|
|
74
|
+
lifecycle,
|
|
75
|
+
onChunkSent: lifecycle.tick,
|
|
76
|
+
status: opts?.status,
|
|
77
|
+
headers: opts?.headers
|
|
78
|
+
})) {
|
|
79
|
+
const answeredElsewhere = (headSentBefore || res.writableEnded) && !tornDown(res, lifecycle);
|
|
80
|
+
if (!res.writableEnded) res.destroy();
|
|
81
|
+
if (answeredElsewhere) journalAnsweredElsewhere(entry, res);
|
|
82
|
+
else journalTeardown(entry, res, lifecycle);
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
lifecycle.dispose();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Deliver one non-streaming JSON reply. The body is a thunk.
|
|
90
|
+
*
|
|
91
|
+
* On both paths it first checks {@link journalUnwritable}, before any wait. A
|
|
92
|
+
* response that can no longer take the reply (torn down, or already answered)
|
|
93
|
+
* is not written, the thunk is never called, and the entry is marked
|
|
94
|
+
* interrupted. An already-answered response whose body never ended is
|
|
95
|
+
* destroyed, so the client does not hang.
|
|
96
|
+
*
|
|
97
|
+
* With non-streaming timing off (the default) it then runs
|
|
98
|
+
* `JSON.stringify(body())`, then `writeHead`, then `end`: the body is built
|
|
99
|
+
* before anything is written, so a builder that throws leaves the response
|
|
100
|
+
* unwritten.
|
|
101
|
+
*
|
|
102
|
+
* With timing on, it waits the non-streaming delay on the client's close
|
|
103
|
+
* signal, checks {@link journalUnwritable} again (the response can be torn
|
|
104
|
+
* down or answered during the wait), then runs the thunk, so a `created`
|
|
105
|
+
* timestamp reflects the write time.
|
|
106
|
+
*
|
|
107
|
+
* Rejects with a `RangeError` when `chunkSize` is a number below 1: that is
|
|
108
|
+
* a programming error, and the delay math divides by it. No user input reaches
|
|
109
|
+
* it, because every caller clamps with `Math.max(1, ...)`. A user value that
|
|
110
|
+
* is not a number clamps to `NaN`: the reply is still served, with a zero
|
|
111
|
+
* wait when timing is on.
|
|
112
|
+
*/
|
|
113
|
+
async function deliverJson(res, entry, fixture, body, opts) {
|
|
114
|
+
if (opts.chunkSize < 1) throw new RangeError(`deliverJson: chunkSize must be >= 1, got ${opts.chunkSize}`);
|
|
115
|
+
const write = () => {
|
|
116
|
+
const text = JSON.stringify(body());
|
|
117
|
+
res.writeHead(opts.status ?? 200, {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
...opts.headers
|
|
120
|
+
});
|
|
121
|
+
res.end(text);
|
|
122
|
+
};
|
|
123
|
+
noteDeliveryStart(res);
|
|
124
|
+
if (journalUnwritable(entry, res, void 0)) return;
|
|
125
|
+
if (!nonStreamingTimingEnabled(fixture, opts.surface)) {
|
|
126
|
+
write();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const lifecycle = httpLifecycle(res, fixture, { streaming: false });
|
|
130
|
+
try {
|
|
131
|
+
const fixtureTimings = nonStreamingRecordedTimings(fixture, opts.surface, opts.recordedTimings);
|
|
132
|
+
const recordedTimings = opts.duplicateId ? extendRecordedTimings(fixtureTimings, Math.max(1, Math.ceil(opts.payloadLength / opts.chunkSize)), true) : fixtureTimings;
|
|
133
|
+
await delay(nonStreamingDelayMs(fixture, opts.payloadLength, opts.chunkSize, recordedTimings, opts.replaySpeed), lifecycle.signal);
|
|
134
|
+
if (journalUnwritable(entry, res, lifecycle)) return;
|
|
135
|
+
write();
|
|
136
|
+
} finally {
|
|
137
|
+
lifecycle.dispose();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { deliverJson, deliverStream };
|
|
143
|
+
//# sourceMappingURL=deliver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliver.js","names":[],"sources":["../../src/response/deliver.ts"],"sourcesContent":["import type * as http from \"node:http\";\nimport type { Fixture, JournalEntry, RecordedTimings } from \"../types.js\";\nimport { delay } from \"../sse-writer.js\";\nimport { httpSink, runFrameLoop, type FrameCodec, type FrameTiming } from \"./frame-loop.js\";\nimport { responseGoneReason } from \"../chaos.js\";\nimport {\n AIMOCK_DISCONNECTED,\n closedByClient,\n httpLifecycle,\n markInterrupted,\n noteDeliveryStart,\n statusLineSent,\n teardownReason,\n requestSocket,\n type DeliveryLifecycle,\n} from \"./lifecycle.js\";\nimport {\n extendRecordedTimings,\n nonStreamingDelayMs,\n nonStreamingRecordedTimings,\n nonStreamingTimingEnabled,\n type NonStreamingSurface,\n} from \"./timing.js\";\n\n/** The lifecycle fields the teardown journal reads. */\ntype TeardownSource = Pick<DeliveryLifecycle, \"cause\" | \"reason\">;\n\n/**\n * Journal a delivery that ended early. The reason is always set: the\n * lifecycle's first cause when it fired, else {@link teardownReason} for the\n * response that is gone. When no byte of the response reached the socket\n * ({@link statusLineSent}), the status is 0, the rule the server and the\n * chaos `disconnect` apply to a torn socket. A fixture interruption\n * (`disconnectAfterMs`, `truncateAfterChunks`) keeps the status it was\n * journaled with, as base recorded it.\n */\nfunction journalTeardown(\n entry: JournalEntry,\n res: http.ServerResponse,\n lifecycle: TeardownSource | undefined,\n): void {\n markInterrupted(entry, lifecycle?.reason() ?? teardownReason(res));\n if (lifecycle?.cause() !== \"fixture\" && !statusLineSent(res)) entry.response.status = 0;\n}\n\n/**\n * Whether the response was torn down: the lifecycle fired, the response is\n * destroyed or chaos disconnected it, or the client closed the socket.\n */\nfunction tornDown(res: http.ServerResponse, lifecycle: TeardownSource | undefined): boolean {\n const socket = requestSocket(res);\n const gone = responseGoneReason(res);\n return (\n lifecycle?.reason() !== undefined ||\n gone === \"client-gone\" ||\n gone === \"chaos-disconnected\" ||\n (!res.writableEnded && !!socket && closedByClient(socket))\n );\n}\n\n/**\n * Journal a response that something else on aimock's side already answered\n * (head committed or body ended) as aimock's teardown, with the status the\n * client actually got.\n */\nfunction journalAnsweredElsewhere(entry: JournalEntry, res: http.ServerResponse): void {\n markInterrupted(entry, AIMOCK_DISCONNECTED);\n entry.response.status = statusLineSent(res) ? res.statusCode : 0;\n}\n\n/**\n * Whether `deliverJson` can no longer write its reply, journaling why when it\n * cannot. Torn down ({@link tornDown}): {@link journalTeardown}. Already\n * answered by something else on aimock's side (head committed or body\n * ended): writing again would throw `ERR_HTTP_HEADERS_SENT`, so it is\n * journaled by {@link journalAnsweredElsewhere}, and a body that never ended\n * is destroyed so the client does not hang.\n */\nfunction journalUnwritable(\n entry: JournalEntry,\n res: http.ServerResponse,\n lifecycle: TeardownSource | undefined,\n): boolean {\n if (tornDown(res, lifecycle)) {\n journalTeardown(entry, res, lifecycle);\n return true;\n }\n if (res.headersSent || res.writableEnded) {\n journalAnsweredElsewhere(entry, res);\n if (!res.writableEnded) res.destroy();\n return true;\n }\n return false;\n}\n\n/**\n * Deliver one streamed reply and journal how it ended. Builds the HTTP\n * lifecycle (client close + fixture interruption) and runs the frame loop on\n * it. When the loop stops early it destroys `res` (if it has not ended) and\n * marks the entry with the first cause's reason (or, when no cause fired, who\n * tore the response down). A response other code already answered (head\n * committed before the stream, or body ended) is journaled as\n * {@link deliverJson} journals it. It disposes the lifecycle on every path.\n */\nexport async function deliverStream<F>(\n res: http.ServerResponse,\n entry: JournalEntry,\n fixture: Fixture,\n codec: FrameCodec<F>,\n frames: readonly F[],\n timing: FrameTiming,\n opts?: {\n status?: number; // When set, sent with `writeHead` before the first frame (issue #549).\n headers?: Record<string, string>; // Merged over the codec's headers (issue #549).\n },\n): Promise<void> {\n noteDeliveryStart(res);\n const headSentBefore = res.headersSent;\n const lifecycle = httpLifecycle(res, fixture, { streaming: true });\n try {\n const completed = await runFrameLoop(httpSink(res), frames, codec, timing, {\n lifecycle,\n onChunkSent: lifecycle.tick,\n status: opts?.status,\n headers: opts?.headers,\n });\n if (!completed) {\n // Read before the destroy below, which makes any response look torn down.\n const answeredElsewhere = (headSentBefore || res.writableEnded) && !tornDown(res, lifecycle);\n if (!res.writableEnded) res.destroy();\n if (answeredElsewhere) journalAnsweredElsewhere(entry, res);\n else journalTeardown(entry, res, lifecycle);\n }\n } finally {\n lifecycle.dispose();\n }\n}\n\nexport interface DeliverJsonOptions {\n /**\n * Passed to `nonStreamingTimingEnabled` and `nonStreamingRecordedTimings`:\n * OpenAI chat, or any other provider.\n */\n surface: NonStreamingSurface;\n status?: number; // The response status, 200 when unset (issue #549).\n headers?: Record<string, string>; // Merged over the JSON `Content-Type` header (issue #549).\n /** The served payload length the wait is sized from. */\n payloadLength: number;\n /**\n * The wait is sized in chunks of this many characters. Callers pass\n * `Math.max(1, <fixture or server chunkSize>)`: 1 or more, or `NaN` for a\n * non-numeric value. `NaN` gives a zero wait.\n */\n chunkSize: number;\n recordedTimings?: RecordedTimings;\n /** A K4 duplicate-id plan: extend the recorded gaps before sizing the wait. */\n duplicateId?: boolean;\n replaySpeed?: number;\n}\n\n/**\n * Deliver one non-streaming JSON reply. The body is a thunk.\n *\n * On both paths it first checks {@link journalUnwritable}, before any wait. A\n * response that can no longer take the reply (torn down, or already answered)\n * is not written, the thunk is never called, and the entry is marked\n * interrupted. An already-answered response whose body never ended is\n * destroyed, so the client does not hang.\n *\n * With non-streaming timing off (the default) it then runs\n * `JSON.stringify(body())`, then `writeHead`, then `end`: the body is built\n * before anything is written, so a builder that throws leaves the response\n * unwritten.\n *\n * With timing on, it waits the non-streaming delay on the client's close\n * signal, checks {@link journalUnwritable} again (the response can be torn\n * down or answered during the wait), then runs the thunk, so a `created`\n * timestamp reflects the write time.\n *\n * Rejects with a `RangeError` when `chunkSize` is a number below 1: that is\n * a programming error, and the delay math divides by it. No user input reaches\n * it, because every caller clamps with `Math.max(1, ...)`. A user value that\n * is not a number clamps to `NaN`: the reply is still served, with a zero\n * wait when timing is on.\n */\nexport async function deliverJson(\n res: http.ServerResponse,\n entry: JournalEntry,\n fixture: Fixture,\n body: () => unknown,\n opts: DeliverJsonOptions,\n): Promise<void> {\n if (opts.chunkSize < 1) {\n throw new RangeError(`deliverJson: chunkSize must be >= 1, got ${opts.chunkSize}`);\n }\n const write = (): void => {\n const text = JSON.stringify(body());\n res.writeHead(opts.status ?? 200, { \"Content-Type\": \"application/json\", ...opts.headers });\n res.end(text);\n };\n noteDeliveryStart(res);\n // Checked before the lifecycle and the wait on both paths: a response that\n // cannot take the reply is journaled at once, with no wait.\n if (journalUnwritable(entry, res, undefined)) return;\n if (!nonStreamingTimingEnabled(fixture, opts.surface)) {\n write();\n return;\n }\n const lifecycle = httpLifecycle(res, fixture, { streaming: false });\n try {\n const fixtureTimings = nonStreamingRecordedTimings(fixture, opts.surface, opts.recordedTimings);\n const recordedTimings = opts.duplicateId\n ? extendRecordedTimings(\n fixtureTimings,\n Math.max(1, Math.ceil(opts.payloadLength / opts.chunkSize)),\n true,\n )\n : fixtureTimings;\n await delay(\n nonStreamingDelayMs(\n fixture,\n opts.payloadLength,\n opts.chunkSize,\n recordedTimings,\n opts.replaySpeed,\n ),\n lifecycle.signal,\n );\n if (journalUnwritable(entry, res, lifecycle)) return;\n write();\n } finally {\n lifecycle.dispose();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoCA,SAAS,gBACP,OACA,KACA,WACM;AACN,iBAAgB,OAAO,WAAW,QAAQ,IAAI,eAAe,IAAI,CAAC;AAClE,KAAI,WAAW,OAAO,KAAK,aAAa,CAAC,eAAe,IAAI,CAAE,OAAM,SAAS,SAAS;;;;;;AAOxF,SAAS,SAAS,KAA0B,WAAgD;CAC1F,MAAM,SAAS,cAAc,IAAI;CACjC,MAAM,OAAO,mBAAmB,IAAI;AACpC,QACE,WAAW,QAAQ,KAAK,UACxB,SAAS,iBACT,SAAS,wBACR,CAAC,IAAI,iBAAiB,CAAC,CAAC,UAAU,eAAe,OAAO;;;;;;;AAS7D,SAAS,yBAAyB,OAAqB,KAAgC;AACrF,iBAAgB,OAAO,oBAAoB;AAC3C,OAAM,SAAS,SAAS,eAAe,IAAI,GAAG,IAAI,aAAa;;;;;;;;;;AAWjE,SAAS,kBACP,OACA,KACA,WACS;AACT,KAAI,SAAS,KAAK,UAAU,EAAE;AAC5B,kBAAgB,OAAO,KAAK,UAAU;AACtC,SAAO;;AAET,KAAI,IAAI,eAAe,IAAI,eAAe;AACxC,2BAAyB,OAAO,IAAI;AACpC,MAAI,CAAC,IAAI,cAAe,KAAI,SAAS;AACrC,SAAO;;AAET,QAAO;;;;;;;;;;;AAYT,eAAsB,cACpB,KACA,OACA,SACA,OACA,QACA,QACA,MAIe;AACf,mBAAkB,IAAI;CACtB,MAAM,iBAAiB,IAAI;CAC3B,MAAM,YAAY,cAAc,KAAK,SAAS,EAAE,WAAW,MAAM,CAAC;AAClE,KAAI;AAOF,MAAI,CANc,MAAM,aAAa,SAAS,IAAI,EAAE,QAAQ,OAAO,QAAQ;GACzE;GACA,aAAa,UAAU;GACvB,QAA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4
|
+
function buildOpenAIError(input, details) {
|
|
5
|
+
if (input === "service-validation") {
|
|
6
|
+
if (!details) throw new TypeError("Missing service validation error details");
|
|
7
|
+
return { error: {
|
|
8
|
+
message: details.message,
|
|
9
|
+
type: require_profiles.errorProfiles.openai.validationType
|
|
10
|
+
} };
|
|
11
|
+
}
|
|
12
|
+
if (input === "openrouter-error") {
|
|
13
|
+
if (!details || typeof details.code !== "number") throw new TypeError("Missing OpenRouter numeric error details");
|
|
14
|
+
return { error: {
|
|
15
|
+
code: details.code,
|
|
16
|
+
message: details.message,
|
|
17
|
+
...details.metadata !== void 0 && { metadata: details.metadata }
|
|
18
|
+
} };
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
message: input.message,
|
|
22
|
+
type: input.type,
|
|
23
|
+
...input.includeParam === true ? { param: input.param ?? null } : {},
|
|
24
|
+
code: input.code
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Native purpose templates preserve field presence and insertion order. No status or I/O. */
|
|
28
|
+
function renderError(wire, purpose, details) {
|
|
29
|
+
if (wire === "ollama-embed") return { body: JSON.stringify({ error: details.message }) };
|
|
30
|
+
const profile = require_profiles.errorProfiles[wire];
|
|
31
|
+
if (wire === "interactions" && (purpose === "validation" || purpose === "strict-miss" || purpose === "fixture-miss" || purpose === "fixture" || purpose === "misbehavior" || purpose === "unknown-response")) return { body: JSON.stringify({ error: {
|
|
32
|
+
code: details.code ?? "INVALID_ARGUMENT",
|
|
33
|
+
message: details.message
|
|
34
|
+
} }) };
|
|
35
|
+
switch (purpose) {
|
|
36
|
+
case "authentication":
|
|
37
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
38
|
+
type: "error",
|
|
39
|
+
error: {
|
|
40
|
+
type: "authentication_error",
|
|
41
|
+
message: details.message
|
|
42
|
+
}
|
|
43
|
+
}) };
|
|
44
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
45
|
+
code: 401,
|
|
46
|
+
message: details.message,
|
|
47
|
+
status: "UNAUTHENTICATED"
|
|
48
|
+
} }) };
|
|
49
|
+
return renderError(wire, "legacy-auth", details);
|
|
50
|
+
case "legacy-auth": return { body: JSON.stringify({ error: {
|
|
51
|
+
message: details.message,
|
|
52
|
+
type: "authentication_error",
|
|
53
|
+
code: "invalid_api_key"
|
|
54
|
+
} }) };
|
|
55
|
+
case "stream-failure": return { body: JSON.stringify({ error: { message: details.message } }) };
|
|
56
|
+
case "route-failure": return { body: JSON.stringify({ error: {
|
|
57
|
+
message: details.message,
|
|
58
|
+
type: details.type
|
|
59
|
+
} }) };
|
|
60
|
+
case "invalid-misbehavior-header":
|
|
61
|
+
if (wire === "ollama") return { body: JSON.stringify({ error: details.message }) };
|
|
62
|
+
if (wire === "cohere") return { body: JSON.stringify({ message: details.message }) };
|
|
63
|
+
if (wire === "interactions") return { body: JSON.stringify({ error: {
|
|
64
|
+
code: details.code,
|
|
65
|
+
message: details.message
|
|
66
|
+
} }) };
|
|
67
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
68
|
+
code: 400,
|
|
69
|
+
message: details.message,
|
|
70
|
+
status: "INVALID_ARGUMENT"
|
|
71
|
+
} }) };
|
|
72
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
73
|
+
type: "error",
|
|
74
|
+
error: {
|
|
75
|
+
type: profile.validationType,
|
|
76
|
+
code: details.code,
|
|
77
|
+
message: details.message
|
|
78
|
+
}
|
|
79
|
+
}) };
|
|
80
|
+
if (wire === "bedrock" || wire === "bedrock-converse") return { body: JSON.stringify({
|
|
81
|
+
__type: "ValidationException",
|
|
82
|
+
message: details.message
|
|
83
|
+
}) };
|
|
84
|
+
return { body: JSON.stringify({ error: {
|
|
85
|
+
message: details.message,
|
|
86
|
+
type: profile.validationType,
|
|
87
|
+
code: details.code
|
|
88
|
+
} }) };
|
|
89
|
+
case "validation":
|
|
90
|
+
case "strict-miss":
|
|
91
|
+
case "fixture-miss":
|
|
92
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
93
|
+
message: details.message,
|
|
94
|
+
code: details.bodyCode,
|
|
95
|
+
status: details.status
|
|
96
|
+
} }) };
|
|
97
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError({
|
|
98
|
+
...details,
|
|
99
|
+
type: details.type ?? profile.validationType
|
|
100
|
+
}) }) };
|
|
101
|
+
return { body: JSON.stringify({ error: {
|
|
102
|
+
message: details.message,
|
|
103
|
+
type: details.type ?? profile.validationType
|
|
104
|
+
} }) };
|
|
105
|
+
case "thinking": return { body: JSON.stringify({
|
|
106
|
+
type: "error",
|
|
107
|
+
error: {
|
|
108
|
+
type: details.type ?? profile.validationType,
|
|
109
|
+
message: details.message
|
|
110
|
+
},
|
|
111
|
+
...wire === "messages" && details.requestId !== void 0 ? { request_id: details.requestId } : {}
|
|
112
|
+
}) };
|
|
113
|
+
case "fixture":
|
|
114
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
115
|
+
code: details.bodyCode,
|
|
116
|
+
message: details.message,
|
|
117
|
+
status: details.status
|
|
118
|
+
} }) };
|
|
119
|
+
if (wire === "openai") return { body: JSON.stringify({ error: {
|
|
120
|
+
message: details.message,
|
|
121
|
+
type: details.type ?? profile.fixtureType,
|
|
122
|
+
param: details.param ?? null,
|
|
123
|
+
code: details.code ?? null
|
|
124
|
+
} }) };
|
|
125
|
+
return { body: JSON.stringify({
|
|
126
|
+
type: "error",
|
|
127
|
+
error: {
|
|
128
|
+
type: details.type ?? profile.fixtureType,
|
|
129
|
+
message: details.message
|
|
130
|
+
}
|
|
131
|
+
}) };
|
|
132
|
+
case "tool-argument":
|
|
133
|
+
if (wire === "ollama") return { body: JSON.stringify({
|
|
134
|
+
error: details.message,
|
|
135
|
+
code: details.code
|
|
136
|
+
}) };
|
|
137
|
+
if (wire === "interactions") return { body: JSON.stringify({ error: {
|
|
138
|
+
code: details.code,
|
|
139
|
+
message: details.message
|
|
140
|
+
} }) };
|
|
141
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
142
|
+
code: 500,
|
|
143
|
+
message: details.message,
|
|
144
|
+
status: "INTERNAL",
|
|
145
|
+
details: details.googleDetails
|
|
146
|
+
} }) };
|
|
147
|
+
if (wire === "bedrock" || wire === "bedrock-converse") return { body: JSON.stringify({
|
|
148
|
+
__type: details.type ?? require_profiles.errorProfiles.bedrock.toolArgumentType,
|
|
149
|
+
message: details.message,
|
|
150
|
+
reason: details.code
|
|
151
|
+
}) };
|
|
152
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
153
|
+
type: "error",
|
|
154
|
+
error: {
|
|
155
|
+
type: details.type ?? profile.fixtureType,
|
|
156
|
+
code: details.code,
|
|
157
|
+
message: details.message
|
|
158
|
+
}
|
|
159
|
+
}) };
|
|
160
|
+
return { body: JSON.stringify({ error: {
|
|
161
|
+
message: details.message,
|
|
162
|
+
type: details.type ?? profile.fixtureType,
|
|
163
|
+
code: details.code
|
|
164
|
+
} }) };
|
|
165
|
+
case "misbehavior":
|
|
166
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError(details) }) };
|
|
167
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
168
|
+
code: details.bodyCode,
|
|
169
|
+
message: details.message,
|
|
170
|
+
status: details.status
|
|
171
|
+
} }) };
|
|
172
|
+
if (wire === "cohere") return { body: JSON.stringify({
|
|
173
|
+
message: details.message,
|
|
174
|
+
code: details.code
|
|
175
|
+
}) };
|
|
176
|
+
if (wire === "ollama") return { body: JSON.stringify({ error: `${details.code}: ${details.message}` }) };
|
|
177
|
+
if (wire === "bedrock-converse") return {
|
|
178
|
+
body: JSON.stringify({
|
|
179
|
+
__type: details.type,
|
|
180
|
+
message: details.message,
|
|
181
|
+
code: details.code
|
|
182
|
+
}),
|
|
183
|
+
headers: details.type === void 0 || details.type === null ? void 0 : { "x-amzn-errortype": details.type }
|
|
184
|
+
};
|
|
185
|
+
if (wire === "bedrock") return {
|
|
186
|
+
body: JSON.stringify({
|
|
187
|
+
__type: details.type,
|
|
188
|
+
code: details.code,
|
|
189
|
+
message: details.message
|
|
190
|
+
}),
|
|
191
|
+
headers: details.type === void 0 || details.type === null ? void 0 : { "x-amzn-errortype": details.type }
|
|
192
|
+
};
|
|
193
|
+
return { body: JSON.stringify({
|
|
194
|
+
type: "error",
|
|
195
|
+
error: {
|
|
196
|
+
type: details.type,
|
|
197
|
+
code: details.code,
|
|
198
|
+
message: details.message
|
|
199
|
+
}
|
|
200
|
+
}) };
|
|
201
|
+
case "unknown-response":
|
|
202
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
203
|
+
message: details.message,
|
|
204
|
+
code: details.bodyCode,
|
|
205
|
+
status: details.status
|
|
206
|
+
} }) };
|
|
207
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError({
|
|
208
|
+
...details,
|
|
209
|
+
type: details.type ?? "server_error"
|
|
210
|
+
}) }) };
|
|
211
|
+
return { body: JSON.stringify({ error: {
|
|
212
|
+
message: details.message,
|
|
213
|
+
type: details.type ?? "server_error"
|
|
214
|
+
} }) };
|
|
215
|
+
case "transport-failure": return { body: JSON.stringify({ error: {
|
|
216
|
+
message: details.message,
|
|
217
|
+
type: details.type ?? "proxy_error"
|
|
218
|
+
} }) };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
exports.buildOpenAIError = buildOpenAIError;
|
|
224
|
+
exports.renderError = renderError;
|
|
225
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["errorProfiles"],"sources":["../../src/response/errors.ts"],"sourcesContent":["import { errorProfiles, type ErrorWire } from \"./profiles.js\";\n\nexport type ErrorPurpose =\n | \"validation\"\n | \"strict-miss\"\n | \"fixture-miss\"\n | \"thinking\"\n | \"fixture\"\n | \"tool-argument\"\n | \"misbehavior\"\n | \"unknown-response\"\n | \"transport-failure\"\n | \"route-failure\"\n | \"stream-failure\"\n | \"invalid-misbehavior-header\"\n | \"authentication\"\n | \"legacy-auth\";\n\nexport interface ErrorDetails {\n message: string;\n type?: string | null;\n param?: string | null;\n /** Explicitly retain the native OpenAI param slot; omitted preserves legacy templates. */\n includeParam?: true;\n /** Normalized correlation metadata explicitly supplied by native header-policy rejects. */\n requestId?: string;\n code?: string | null;\n bodyCode?: number;\n status?: string | null;\n googleDetails?: {\n \"@type\": string;\n reason: string;\n domain: string;\n metadata: { code: string };\n }[];\n}\n\ntype OpenAIInnerDetails = Pick<\n ErrorDetails,\n \"message\" | \"type\" | \"param\" | \"code\" | \"includeParam\"\n>;\ntype OpenAIInnerBody = {\n message: string;\n type?: string | null;\n param?: string | null;\n code?: string | null;\n};\ntype ServiceValidationBody = { error: { message: string; type: string } };\ntype OpenRouterErrorBody = {\n error: { code: number; message: string; metadata?: Record<string, unknown> };\n};\n\n/** Common error owner; fixed native forms preserve caller signatures and ordering. */\nexport function buildOpenAIError(details: OpenAIInnerDetails): OpenAIInnerBody;\nexport function buildOpenAIError(\n purpose: \"service-validation\",\n details: { message: string },\n): ServiceValidationBody;\nexport function buildOpenAIError(\n purpose: \"openrouter-error\",\n details: { code: number; message: string; metadata?: Record<string, unknown> },\n): OpenRouterErrorBody;\nexport function buildOpenAIError(\n input: OpenAIInnerDetails | \"service-validation\" | \"openrouter-error\",\n details?: { message: string; code?: number; metadata?: Record<string, unknown> },\n): OpenAIInnerBody | ServiceValidationBody | OpenRouterErrorBody {\n if (input === \"service-validation\") {\n if (!details) throw new TypeError(\"Missing service validation error details\");\n return {\n error: { message: details.message, type: errorProfiles.openai.validationType },\n };\n }\n if (input === \"openrouter-error\") {\n if (!details || typeof details.code !== \"number\")\n throw new TypeError(\"Missing OpenRouter numeric error details\");\n return {\n error: {\n code: details.code,\n message: details.message,\n ...(details.metadata !== undefined && { metadata: details.metadata }),\n },\n };\n }\n return {\n message: input.message,\n type: input.type,\n ...(input.includeParam === true ? { param: input.param ?? null } : {}),\n code: input.code,\n };\n}\n\n/** Native purpose templates preserve field presence and insertion order. No status or I/O. */\nexport function renderError(\n wire: ErrorWire,\n purpose: ErrorPurpose,\n details: ErrorDetails,\n): { body: string; headers?: Record<string, string> } {\n if (wire === \"ollama-embed\") {\n return { body: JSON.stringify({ error: details.message }) };\n }\n const profile = errorProfiles[wire];\n if (\n wire === \"interactions\" &&\n (purpose === \"validation\" ||\n purpose === \"strict-miss\" ||\n purpose === \"fixture-miss\" ||\n purpose === \"fixture\" ||\n purpose === \"misbehavior\" ||\n purpose === \"unknown-response\")\n ) {\n return {\n body: JSON.stringify({\n error: { code: details.code ?? \"INVALID_ARGUMENT\", message: details.message },\n }),\n };\n }\n switch (purpose) {\n case \"authentication\":\n if (wire === \"messages\") {\n return {\n body: JSON.stringify({\n type: \"error\",\n error: { type: \"authentication_error\", message: details.message },\n }),\n };\n }\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { code: 401, message: details.message, status: \"UNAUTHENTICATED\" },\n }),\n };\n }\n return renderError(wire, \"legacy-auth\", details);\n case \"legacy-auth\":\n return {\n body: JSON.stringify({\n error: {\n message: details.message,\n type: \"authentication_error\",\n code: \"invalid_api_key\",\n },\n }),\n };\n case \"stream-failure\":\n return { body: JSON.stringify({ error: { message: details.message } }) };\n case \"route-failure\":\n return {\n body: JSON.stringify({ error: { message: details.message, type: details.type } }),\n };\n case \"invalid-misbehavior-header\":\n if (wire === \"ollama\") return { body: JSON.stringify({ error: details.message }) };\n if (wire === \"cohere\") return { body: JSON.stringify({ message: details.message }) };\n if (wire === \"interactions\") {\n return {\n body: JSON.stringify({ error: { code: details.code, message: details.message } }),\n };\n }\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { code: 400, message: details.message, status: \"INVALID_ARGUMENT\" },\n }),\n };\n }\n if (wire === \"messages\") {\n return {\n body: JSON.stringify({\n type: \"error\",\n error: { type: profile.validationType, code: details.code, message: details.message },\n }),\n };\n }\n if (wire === \"bedrock\" || wire === \"bedrock-converse\") {\n return {\n body: JSON.stringify({ __type: \"ValidationException\", message: details.message }),\n };\n }\n return {\n body: JSON.stringify({\n error: { message: details.message, type: profile.validationType, code: details.code },\n }),\n };\n case \"validation\":\n case \"strict-miss\":\n case \"fixture-miss\":\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { message: details.message, code: details.bodyCode, status: details.status },\n }),\n };\n }\n if (wire === \"openai\") {\n return {\n body: JSON.stringify({\n error: buildOpenAIError({\n ...details,\n type: details.type ?? profile.validationType,\n }),\n }),\n };\n }\n return {\n body: JSON.stringify({\n error: { message: details.message, type: details.type ?? profile.validationType },\n }),\n };\n case \"thinking\":\n return {\n body: JSON.stringify({\n type: \"error\",\n error: { type: details.type ?? profile.validationType, message: details.message },\n ...(wire === \"messages\" && details.requestId !== undefined\n ? { request_id: details.requestId }\n : {}),\n }),\n };\n case \"fixture\":\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { code: details.bodyCode, message: details.message, status: details.status },\n }),\n };\n }\n if (wire === \"openai\") {\n return {\n body: JSON.stringify({\n error: {\n message: details.message,\n type: details.type ?? profile.fixtureType,\n param: details.param ?? null,\n code: details.code ?? null,\n },\n }),\n };\n }\n return {\n body: JSON.stringify({\n type: \"error\",\n error: { type: details.type ?? profile.fixtureType, message: details.message },\n }),\n };\n case \"tool-argument\":\n if (wire === \"ollama\") {\n return { body: JSON.stringify({ error: details.message, code: details.code }) };\n }\n if (wire === \"interactions\") {\n return {\n body: JSON.stringify({ error: { code: details.code, message: details.message } }),\n };\n }\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: {\n code: 500,\n message: details.message,\n status: \"INTERNAL\",\n details: details.googleDetails,\n },\n }),\n };\n }\n if (wire === \"bedrock\" || wire === \"bedrock-converse\") {\n return {\n body: JSON.stringify({\n __type: details.type ?? errorProfiles.bedrock.toolArgumentType,\n message: details.message,\n reason: details.code,\n }),\n };\n }\n if (wire === \"messages\") {\n return {\n body: JSON.stringify({\n type: \"error\",\n error: {\n type: details.type ?? profile.fixtureType,\n code: details.code,\n message: details.message,\n },\n }),\n };\n }\n return {\n body: JSON.stringify({\n error: {\n message: details.message,\n type: details.type ?? profile.fixtureType,\n code: details.code,\n },\n }),\n };\n case \"misbehavior\":\n if (wire === \"openai\") {\n return { body: JSON.stringify({ error: buildOpenAIError(details) }) };\n }\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { code: details.bodyCode, message: details.message, status: details.status },\n }),\n };\n }\n if (wire === \"cohere\") {\n return { body: JSON.stringify({ message: details.message, code: details.code }) };\n }\n if (wire === \"ollama\") {\n return { body: JSON.stringify({ error: `${details.code}: ${details.message}` }) };\n }\n if (wire === \"bedrock-converse\") {\n return {\n body: JSON.stringify({\n __type: details.type,\n message: details.message,\n code: details.code,\n }),\n headers:\n details.type === undefined || details.type === null\n ? undefined\n : { \"x-amzn-errortype\": details.type },\n };\n }\n if (wire === \"bedrock\") {\n return {\n body: JSON.stringify({\n __type: details.type,\n code: details.code,\n message: details.message,\n }),\n headers:\n details.type === undefined || details.type === null\n ? undefined\n : { \"x-amzn-errortype\": details.type },\n };\n }\n return {\n body: JSON.stringify({\n type: \"error\",\n error: { type: details.type, code: details.code, message: details.message },\n }),\n };\n case \"unknown-response\":\n if (wire === \"gemini\") {\n return {\n body: JSON.stringify({\n error: { message: details.message, code: details.bodyCode, status: details.status },\n }),\n };\n }\n if (wire === \"openai\") {\n return {\n body: JSON.stringify({\n error: buildOpenAIError({ ...details, type: details.type ?? \"server_error\" }),\n }),\n };\n }\n return {\n body: JSON.stringify({\n error: { message: details.message, type: details.type ?? \"server_error\" },\n }),\n };\n case \"transport-failure\":\n return {\n body: JSON.stringify({\n error: { message: details.message, type: details.type ?? \"proxy_error\" },\n }),\n };\n }\n}\n"],"mappings":";;;AA8DA,SAAgB,iBACd,OACA,SAC+D;AAC/D,KAAI,UAAU,sBAAsB;AAClC,MAAI,CAAC,QAAS,OAAM,IAAI,UAAU,2CAA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AAQ;KAChB,SAAS,QAAQ;KACjB,MAAM,QAAQ;KACf,CAAC;IACF,SACE,QAAQ,SAAS,UAAa,QAAQ,SAAS,OAC3C,SACA,EAAE,oBAAoB,QAAQ,MAAM;IAC3C;AAEH,OAAI,SAAS,UACX,QAAO;IACL,MAAM,KAAK,UAAU;KACnB,QAAQ,QAAQ;KAChB,MAAM,QAAQ;KACd,SAAS,QAAQ;KAClB,CAAC;IACF,SACE,QAAQ,SAAS,UAAa,QAAQ,SAAS,OAC3C,SACA,EAAE,oBAAoB,QAAQ,MAAM;IAC3C;AAEH,UAAO,EACL,MAAM,KAAK,UAAU;IACnB,MAAM;IACN,OAAO;KAAE,MAAM,QAAQ;KAAM,MAAM,QAAQ;KAAM,SAAS,QAAQ;KAAS;IAC5E,CAAC,EACH;EACH,KAAK;AACH,OAAI,SAAS,SACX,QAAO,EACL,MAAM,KAAK,UAAU,EACnB,OAAO;IAAE,SAAS,QAAQ;IAAS,MAAM,QAAQ;IAAU,QAAQ,QAAQ;IAAQ,EACpF,CAAC,EACH;AAEH,OAAI,SAAS,SACX,QAAO,EACL,MAAM,KAAK,UAAU,EACnB,OAAO,iBAAiB;IAAE,GAAG;IAAS,MAAM,QAAQ,QAAQ;IAAgB,CAAC,EAC9E,CAAC,EACH;AAEH,UAAO,EACL,MAAM,KAAK,UAAU,EACnB,OAAO;IAAE,SAAS,QAAQ;IAAS,MAAM,QAAQ,QAAQ;IAAgB,EAC1E,CAAC,EACH;EACH,KAAK,oBACH,QAAO,EACL,MAAM,KAAK,UAAU,EACnB,OAAO;GAAE,SAAS,QAAQ;GAAS,MAAM,QAAQ,QAAQ;GAAe,EACzE,CAAC,EACH"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { errorProfiles } from "./profiles.js";
|
|
2
|
+
|
|
3
|
+
//#region src/response/errors.ts
|
|
4
|
+
function buildOpenAIError(input, details) {
|
|
5
|
+
if (input === "service-validation") {
|
|
6
|
+
if (!details) throw new TypeError("Missing service validation error details");
|
|
7
|
+
return { error: {
|
|
8
|
+
message: details.message,
|
|
9
|
+
type: errorProfiles.openai.validationType
|
|
10
|
+
} };
|
|
11
|
+
}
|
|
12
|
+
if (input === "openrouter-error") {
|
|
13
|
+
if (!details || typeof details.code !== "number") throw new TypeError("Missing OpenRouter numeric error details");
|
|
14
|
+
return { error: {
|
|
15
|
+
code: details.code,
|
|
16
|
+
message: details.message,
|
|
17
|
+
...details.metadata !== void 0 && { metadata: details.metadata }
|
|
18
|
+
} };
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
message: input.message,
|
|
22
|
+
type: input.type,
|
|
23
|
+
...input.includeParam === true ? { param: input.param ?? null } : {},
|
|
24
|
+
code: input.code
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Native purpose templates preserve field presence and insertion order. No status or I/O. */
|
|
28
|
+
function renderError(wire, purpose, details) {
|
|
29
|
+
if (wire === "ollama-embed") return { body: JSON.stringify({ error: details.message }) };
|
|
30
|
+
const profile = errorProfiles[wire];
|
|
31
|
+
if (wire === "interactions" && (purpose === "validation" || purpose === "strict-miss" || purpose === "fixture-miss" || purpose === "fixture" || purpose === "misbehavior" || purpose === "unknown-response")) return { body: JSON.stringify({ error: {
|
|
32
|
+
code: details.code ?? "INVALID_ARGUMENT",
|
|
33
|
+
message: details.message
|
|
34
|
+
} }) };
|
|
35
|
+
switch (purpose) {
|
|
36
|
+
case "authentication":
|
|
37
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
38
|
+
type: "error",
|
|
39
|
+
error: {
|
|
40
|
+
type: "authentication_error",
|
|
41
|
+
message: details.message
|
|
42
|
+
}
|
|
43
|
+
}) };
|
|
44
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
45
|
+
code: 401,
|
|
46
|
+
message: details.message,
|
|
47
|
+
status: "UNAUTHENTICATED"
|
|
48
|
+
} }) };
|
|
49
|
+
return renderError(wire, "legacy-auth", details);
|
|
50
|
+
case "legacy-auth": return { body: JSON.stringify({ error: {
|
|
51
|
+
message: details.message,
|
|
52
|
+
type: "authentication_error",
|
|
53
|
+
code: "invalid_api_key"
|
|
54
|
+
} }) };
|
|
55
|
+
case "stream-failure": return { body: JSON.stringify({ error: { message: details.message } }) };
|
|
56
|
+
case "route-failure": return { body: JSON.stringify({ error: {
|
|
57
|
+
message: details.message,
|
|
58
|
+
type: details.type
|
|
59
|
+
} }) };
|
|
60
|
+
case "invalid-misbehavior-header":
|
|
61
|
+
if (wire === "ollama") return { body: JSON.stringify({ error: details.message }) };
|
|
62
|
+
if (wire === "cohere") return { body: JSON.stringify({ message: details.message }) };
|
|
63
|
+
if (wire === "interactions") return { body: JSON.stringify({ error: {
|
|
64
|
+
code: details.code,
|
|
65
|
+
message: details.message
|
|
66
|
+
} }) };
|
|
67
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
68
|
+
code: 400,
|
|
69
|
+
message: details.message,
|
|
70
|
+
status: "INVALID_ARGUMENT"
|
|
71
|
+
} }) };
|
|
72
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
73
|
+
type: "error",
|
|
74
|
+
error: {
|
|
75
|
+
type: profile.validationType,
|
|
76
|
+
code: details.code,
|
|
77
|
+
message: details.message
|
|
78
|
+
}
|
|
79
|
+
}) };
|
|
80
|
+
if (wire === "bedrock" || wire === "bedrock-converse") return { body: JSON.stringify({
|
|
81
|
+
__type: "ValidationException",
|
|
82
|
+
message: details.message
|
|
83
|
+
}) };
|
|
84
|
+
return { body: JSON.stringify({ error: {
|
|
85
|
+
message: details.message,
|
|
86
|
+
type: profile.validationType,
|
|
87
|
+
code: details.code
|
|
88
|
+
} }) };
|
|
89
|
+
case "validation":
|
|
90
|
+
case "strict-miss":
|
|
91
|
+
case "fixture-miss":
|
|
92
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
93
|
+
message: details.message,
|
|
94
|
+
code: details.bodyCode,
|
|
95
|
+
status: details.status
|
|
96
|
+
} }) };
|
|
97
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError({
|
|
98
|
+
...details,
|
|
99
|
+
type: details.type ?? profile.validationType
|
|
100
|
+
}) }) };
|
|
101
|
+
return { body: JSON.stringify({ error: {
|
|
102
|
+
message: details.message,
|
|
103
|
+
type: details.type ?? profile.validationType
|
|
104
|
+
} }) };
|
|
105
|
+
case "thinking": return { body: JSON.stringify({
|
|
106
|
+
type: "error",
|
|
107
|
+
error: {
|
|
108
|
+
type: details.type ?? profile.validationType,
|
|
109
|
+
message: details.message
|
|
110
|
+
},
|
|
111
|
+
...wire === "messages" && details.requestId !== void 0 ? { request_id: details.requestId } : {}
|
|
112
|
+
}) };
|
|
113
|
+
case "fixture":
|
|
114
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
115
|
+
code: details.bodyCode,
|
|
116
|
+
message: details.message,
|
|
117
|
+
status: details.status
|
|
118
|
+
} }) };
|
|
119
|
+
if (wire === "openai") return { body: JSON.stringify({ error: {
|
|
120
|
+
message: details.message,
|
|
121
|
+
type: details.type ?? profile.fixtureType,
|
|
122
|
+
param: details.param ?? null,
|
|
123
|
+
code: details.code ?? null
|
|
124
|
+
} }) };
|
|
125
|
+
return { body: JSON.stringify({
|
|
126
|
+
type: "error",
|
|
127
|
+
error: {
|
|
128
|
+
type: details.type ?? profile.fixtureType,
|
|
129
|
+
message: details.message
|
|
130
|
+
}
|
|
131
|
+
}) };
|
|
132
|
+
case "tool-argument":
|
|
133
|
+
if (wire === "ollama") return { body: JSON.stringify({
|
|
134
|
+
error: details.message,
|
|
135
|
+
code: details.code
|
|
136
|
+
}) };
|
|
137
|
+
if (wire === "interactions") return { body: JSON.stringify({ error: {
|
|
138
|
+
code: details.code,
|
|
139
|
+
message: details.message
|
|
140
|
+
} }) };
|
|
141
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
142
|
+
code: 500,
|
|
143
|
+
message: details.message,
|
|
144
|
+
status: "INTERNAL",
|
|
145
|
+
details: details.googleDetails
|
|
146
|
+
} }) };
|
|
147
|
+
if (wire === "bedrock" || wire === "bedrock-converse") return { body: JSON.stringify({
|
|
148
|
+
__type: details.type ?? errorProfiles.bedrock.toolArgumentType,
|
|
149
|
+
message: details.message,
|
|
150
|
+
reason: details.code
|
|
151
|
+
}) };
|
|
152
|
+
if (wire === "messages") return { body: JSON.stringify({
|
|
153
|
+
type: "error",
|
|
154
|
+
error: {
|
|
155
|
+
type: details.type ?? profile.fixtureType,
|
|
156
|
+
code: details.code,
|
|
157
|
+
message: details.message
|
|
158
|
+
}
|
|
159
|
+
}) };
|
|
160
|
+
return { body: JSON.stringify({ error: {
|
|
161
|
+
message: details.message,
|
|
162
|
+
type: details.type ?? profile.fixtureType,
|
|
163
|
+
code: details.code
|
|
164
|
+
} }) };
|
|
165
|
+
case "misbehavior":
|
|
166
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError(details) }) };
|
|
167
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
168
|
+
code: details.bodyCode,
|
|
169
|
+
message: details.message,
|
|
170
|
+
status: details.status
|
|
171
|
+
} }) };
|
|
172
|
+
if (wire === "cohere") return { body: JSON.stringify({
|
|
173
|
+
message: details.message,
|
|
174
|
+
code: details.code
|
|
175
|
+
}) };
|
|
176
|
+
if (wire === "ollama") return { body: JSON.stringify({ error: `${details.code}: ${details.message}` }) };
|
|
177
|
+
if (wire === "bedrock-converse") return {
|
|
178
|
+
body: JSON.stringify({
|
|
179
|
+
__type: details.type,
|
|
180
|
+
message: details.message,
|
|
181
|
+
code: details.code
|
|
182
|
+
}),
|
|
183
|
+
headers: details.type === void 0 || details.type === null ? void 0 : { "x-amzn-errortype": details.type }
|
|
184
|
+
};
|
|
185
|
+
if (wire === "bedrock") return {
|
|
186
|
+
body: JSON.stringify({
|
|
187
|
+
__type: details.type,
|
|
188
|
+
code: details.code,
|
|
189
|
+
message: details.message
|
|
190
|
+
}),
|
|
191
|
+
headers: details.type === void 0 || details.type === null ? void 0 : { "x-amzn-errortype": details.type }
|
|
192
|
+
};
|
|
193
|
+
return { body: JSON.stringify({
|
|
194
|
+
type: "error",
|
|
195
|
+
error: {
|
|
196
|
+
type: details.type,
|
|
197
|
+
code: details.code,
|
|
198
|
+
message: details.message
|
|
199
|
+
}
|
|
200
|
+
}) };
|
|
201
|
+
case "unknown-response":
|
|
202
|
+
if (wire === "gemini") return { body: JSON.stringify({ error: {
|
|
203
|
+
message: details.message,
|
|
204
|
+
code: details.bodyCode,
|
|
205
|
+
status: details.status
|
|
206
|
+
} }) };
|
|
207
|
+
if (wire === "openai") return { body: JSON.stringify({ error: buildOpenAIError({
|
|
208
|
+
...details,
|
|
209
|
+
type: details.type ?? "server_error"
|
|
210
|
+
}) }) };
|
|
211
|
+
return { body: JSON.stringify({ error: {
|
|
212
|
+
message: details.message,
|
|
213
|
+
type: details.type ?? "server_error"
|
|
214
|
+
} }) };
|
|
215
|
+
case "transport-failure": return { body: JSON.stringify({ error: {
|
|
216
|
+
message: details.message,
|
|
217
|
+
type: details.type ?? "proxy_error"
|
|
218
|
+
} }) };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
export { buildOpenAIError, renderError };
|
|
224
|
+
//# sourceMappingURL=errors.js.map
|