@prometheus-ai/ai 0.5.3 → 0.5.8
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/dist/types/auth-broker/remote-store.d.ts +2 -1
- package/dist/types/auth-broker/wire-schemas.d.ts +4 -1
- package/dist/types/auth-gateway/server.d.ts +19 -0
- package/dist/types/auth-gateway/types.d.ts +9 -3
- package/dist/types/auth-retry.d.ts +119 -0
- package/dist/types/auth-storage.d.ts +217 -8
- package/dist/types/errors.d.ts +24 -0
- package/dist/types/index.d.ts +5 -9
- package/dist/types/provider-details.d.ts +1 -1
- package/dist/types/providers/amazon-bedrock.d.ts +12 -6
- package/dist/types/providers/anthropic-client.d.ts +10 -3
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +2 -2
- package/dist/types/providers/anthropic-messages-server.d.ts +3 -3
- package/dist/types/providers/anthropic-wire.d.ts +3 -3
- package/dist/types/providers/anthropic.d.ts +41 -34
- package/dist/types/providers/aws-credentials.d.ts +8 -0
- package/dist/types/providers/azure-openai-responses.d.ts +1 -0
- package/dist/types/providers/google-gemini-cli.d.ts +22 -1
- package/dist/types/providers/google-shared.d.ts +22 -0
- package/dist/types/providers/google-types.d.ts +13 -1
- package/dist/types/providers/mock.d.ts +8 -3
- package/dist/types/providers/ollama.d.ts +6 -0
- package/dist/types/providers/openai-chat-server-schema.d.ts +6 -3
- package/dist/types/providers/openai-chat-server.d.ts +3 -3
- package/dist/types/providers/openai-chat-wire.d.ts +644 -0
- package/dist/types/providers/openai-codex/request-transformer.d.ts +8 -0
- package/dist/types/providers/openai-codex/response-handler.d.ts +9 -0
- package/dist/types/providers/openai-codex-responses.d.ts +31 -2
- package/dist/types/providers/openai-completions-compat.d.ts +2 -25
- package/dist/types/providers/openai-completions.d.ts +2 -10
- package/dist/types/providers/openai-responses-server-schema.d.ts +4 -4
- package/dist/types/providers/openai-responses-server.d.ts +2 -2
- package/dist/types/providers/openai-responses-shared.d.ts +49 -9
- package/dist/types/providers/openai-responses-wire.d.ts +6065 -0
- package/dist/types/providers/openai-responses.d.ts +13 -4
- package/dist/types/providers/prometheus-native-client.d.ts +9 -0
- package/dist/types/providers/prometheus-native-server.d.ts +4 -3
- package/dist/types/providers/transform-messages.d.ts +1 -2
- package/dist/types/rate-limit-utils.d.ts +3 -2
- package/dist/types/registry/aimlapi.d.ts +4 -0
- package/dist/types/registry/alibaba-coding-plan.d.ts +7 -0
- package/dist/types/registry/amazon-bedrock.d.ts +5 -0
- package/dist/types/registry/anthropic.d.ts +10 -0
- package/dist/types/{utils/oauth → registry}/api-key-login.d.ts +8 -2
- package/dist/types/{utils/oauth → registry}/api-key-validation.d.ts +15 -0
- package/dist/types/registry/cerebras.d.ts +7 -0
- package/dist/types/registry/cloudflare-ai-gateway.d.ts +13 -0
- package/dist/types/registry/cursor.d.ts +7 -0
- package/dist/types/registry/deepseek.d.ts +8 -0
- package/dist/types/registry/derived.d.ts +5 -0
- package/dist/types/registry/firepass.d.ts +16 -0
- package/dist/types/registry/fireworks.d.ts +7 -0
- package/dist/types/registry/github-copilot.d.ts +7 -0
- package/dist/types/registry/gitlab-duo.d.ts +9 -0
- package/dist/types/registry/google-antigravity.d.ts +9 -0
- package/dist/types/registry/google-gemini-cli.d.ts +9 -0
- package/dist/types/registry/google-vertex.d.ts +5 -0
- package/dist/types/registry/google.d.ts +4 -0
- package/dist/types/registry/groq.d.ts +4 -0
- package/dist/types/registry/huggingface.d.ts +7 -0
- package/dist/types/registry/index.d.ts +4 -0
- package/dist/types/registry/kagi.d.ts +14 -0
- package/dist/types/registry/kilo.d.ts +7 -0
- package/dist/types/registry/kimi-code.d.ts +7 -0
- package/dist/types/registry/litellm.d.ts +13 -0
- package/dist/types/registry/lm-studio.d.ts +8 -0
- package/dist/types/registry/minimax-code-cn.d.ts +6 -0
- package/dist/types/registry/minimax-code.d.ts +6 -0
- package/dist/types/registry/minimax.d.ts +4 -0
- package/dist/types/registry/mistral.d.ts +4 -0
- package/dist/types/registry/moonshot.d.ts +7 -0
- package/dist/types/registry/nanogpt.d.ts +7 -0
- package/dist/types/registry/nvidia.d.ts +7 -0
- package/dist/types/registry/oauth/__tests__/xai-oauth.test.d.ts +1 -0
- package/dist/types/{utils → registry}/oauth/anthropic.d.ts +2 -1
- package/dist/types/{utils → registry}/oauth/github-copilot.d.ts +15 -23
- package/dist/types/{utils → registry}/oauth/index.d.ts +1 -0
- package/dist/types/{utils → registry}/oauth/minimax-code.d.ts +5 -5
- package/dist/types/{utils → registry}/oauth/types.d.ts +6 -1
- package/dist/types/{utils → registry}/oauth/xai-oauth.d.ts +2 -1
- package/dist/types/registry/ollama-cloud.d.ts +7 -0
- package/dist/types/registry/ollama.d.ts +12 -0
- package/dist/types/registry/openai-codex-device.d.ts +8 -0
- package/dist/types/registry/openai-codex.d.ts +9 -0
- package/dist/types/registry/openai.d.ts +4 -0
- package/dist/types/registry/opencode-go.d.ts +6 -0
- package/dist/types/registry/opencode-zen.d.ts +6 -0
- package/dist/types/registry/openrouter.d.ts +13 -0
- package/dist/types/registry/parallel.d.ts +14 -0
- package/dist/types/registry/perplexity.d.ts +7 -0
- package/dist/types/registry/qianfan.d.ts +7 -0
- package/dist/types/registry/qwen-portal.d.ts +7 -0
- package/dist/types/registry/registry.d.ts +272 -0
- package/dist/types/registry/synthetic.d.ts +6 -0
- package/dist/types/registry/tavily.d.ts +14 -0
- package/dist/types/registry/together.d.ts +6 -0
- package/dist/types/registry/types.d.ts +51 -0
- package/dist/types/registry/venice.d.ts +13 -0
- package/dist/types/registry/vercel-ai-gateway.d.ts +7 -0
- package/dist/types/registry/vllm.d.ts +7 -0
- package/dist/types/registry/wafer-pass.d.ts +6 -0
- package/dist/types/registry/wafer-serverless.d.ts +6 -0
- package/dist/types/registry/xai-oauth.d.ts +7 -0
- package/dist/types/registry/xai.d.ts +4 -0
- package/dist/types/registry/xiaomi-token-plan-ams.d.ts +6 -0
- package/dist/types/registry/xiaomi-token-plan-cn.d.ts +6 -0
- package/dist/types/registry/xiaomi-token-plan-sgp.d.ts +6 -0
- package/dist/types/registry/xiaomi.d.ts +6 -0
- package/dist/types/registry/zai.d.ts +7 -0
- package/dist/types/registry/zenmux.d.ts +7 -0
- package/dist/types/registry/zhipu-coding-plan.d.ts +7 -0
- package/dist/types/stream.d.ts +9 -1
- package/dist/types/types.d.ts +56 -295
- package/dist/types/usage/google-antigravity.d.ts +15 -1
- package/dist/types/usage/openai-codex-reset.d.ts +79 -0
- package/dist/types/usage/openai-codex.d.ts +1 -0
- package/dist/types/usage.d.ts +77 -4
- package/dist/types/utils/abort.d.ts +6 -0
- package/dist/types/utils/event-stream.d.ts +2 -0
- package/dist/types/utils/http-inspector.d.ts +0 -1
- package/dist/types/utils/idle-iterator.d.ts +35 -0
- package/dist/types/utils/openai-http.d.ts +58 -0
- package/dist/types/utils/request-debug.d.ts +3 -0
- package/dist/types/utils/retry-after.d.ts +1 -0
- package/dist/types/utils/schema/fields.d.ts +5 -0
- package/dist/types/utils/schema/json-schema-validator.d.ts +8 -0
- package/dist/types/utils/schema/stamps.d.ts +7 -15
- package/dist/types/utils/sse-debug.d.ts +0 -5
- package/dist/types/utils/stream-markup-healing.d.ts +2 -0
- package/dist/types/utils.d.ts +1 -5
- package/package.json +17 -29
- package/src/auth-broker/remote-store.ts +10 -1
- package/src/auth-broker/snapshot-cache.ts +1 -1
- package/src/auth-broker/wire-schemas.ts +1 -1
- package/src/auth-gateway/http.ts +1 -1
- package/src/auth-gateway/server.ts +95 -30
- package/src/auth-gateway/types.ts +10 -2
- package/src/auth-retry.ts +238 -0
- package/src/auth-storage.ts +935 -430
- package/src/errors.ts +32 -0
- package/src/index.ts +9 -14
- package/src/provider-details.ts +1 -1
- package/src/providers/__tests__/google-auth.test.ts +144 -0
- package/src/providers/amazon-bedrock.ts +70 -40
- package/src/providers/anthropic-client.ts +15 -13
- package/src/providers/anthropic-messages-server-schema.ts +17 -7
- package/src/providers/anthropic-messages-server.ts +88 -20
- package/src/providers/anthropic-wire.ts +4 -3
- package/src/providers/anthropic.ts +1234 -621
- package/src/providers/aws-credentials.ts +47 -5
- package/src/providers/aws-eventstream.ts +5 -0
- package/src/providers/azure-openai-responses.ts +117 -67
- package/src/providers/cursor.ts +30 -30
- package/src/providers/github-copilot-headers.ts +1 -1
- package/src/providers/gitlab-duo.ts +36 -29
- package/src/providers/google-auth.ts +71 -8
- package/src/providers/google-gemini-cli.ts +118 -22
- package/src/providers/google-shared.ts +163 -43
- package/src/providers/google-types.ts +10 -1
- package/src/providers/kimi.ts +1 -1
- package/src/providers/mock.ts +11 -3
- package/src/providers/ollama.ts +64 -7
- package/src/providers/openai-anthropic-shim.ts +17 -8
- package/src/providers/openai-chat-server-schema.ts +9 -3
- package/src/providers/openai-chat-server.ts +82 -16
- package/src/providers/openai-chat-wire.ts +847 -0
- package/src/providers/openai-codex/request-transformer.ts +129 -34
- package/src/providers/openai-codex/response-handler.ts +22 -1
- package/src/providers/openai-codex-responses.ts +699 -247
- package/src/providers/openai-completions-compat.ts +8 -308
- package/src/providers/openai-completions.ts +416 -267
- package/src/providers/openai-responses-server-schema.ts +15 -9
- package/src/providers/openai-responses-server.ts +162 -114
- package/src/providers/openai-responses-shared.ts +320 -82
- package/src/providers/openai-responses-wire.ts +6391 -0
- package/src/providers/openai-responses.ts +382 -176
- package/src/providers/prometheus-native-client.ts +27 -11
- package/src/providers/prometheus-native-server.ts +44 -17
- package/src/providers/transform-messages.ts +311 -120
- package/src/providers/vision-guard.ts +5 -3
- package/src/rate-limit-utils.ts +13 -3
- package/src/registry/aimlapi.ts +6 -0
- package/src/{utils/oauth → registry}/alibaba-coding-plan.ts +8 -18
- package/src/registry/amazon-bedrock.ts +22 -0
- package/src/registry/anthropic.ts +26 -0
- package/src/{utils/oauth → registry}/api-key-login.ts +25 -3
- package/src/{utils/oauth → registry}/api-key-validation.ts +62 -2
- package/src/{utils/oauth → registry}/cerebras.ts +8 -1
- package/src/{utils/oauth → registry}/cloudflare-ai-gateway.ts +8 -12
- package/src/registry/cursor.ts +20 -0
- package/src/{utils/oauth → registry}/deepseek.ts +9 -17
- package/src/registry/derived.ts +9 -0
- package/src/{utils/oauth → registry}/firepass.ts +10 -2
- package/src/{utils/oauth → registry}/fireworks.ts +8 -1
- package/src/registry/github-copilot.ts +22 -0
- package/src/registry/gitlab-duo.ts +19 -0
- package/src/registry/google-antigravity.ts +21 -0
- package/src/registry/google-gemini-cli.ts +21 -0
- package/src/registry/google-vertex.ts +38 -0
- package/src/registry/google.ts +6 -0
- package/src/registry/groq.ts +6 -0
- package/src/{utils/oauth → registry}/huggingface.ts +8 -19
- package/src/registry/index.ts +4 -0
- package/src/{utils/oauth → registry}/kagi.ts +9 -11
- package/src/{utils/oauth → registry}/kilo.ts +11 -6
- package/src/registry/kimi-code.ts +17 -0
- package/src/{utils/oauth → registry}/litellm.ts +8 -12
- package/src/{utils/oauth → registry}/lm-studio.ts +9 -17
- package/src/registry/minimax-code-cn.ts +12 -0
- package/src/registry/minimax-code.ts +12 -0
- package/src/registry/minimax.ts +6 -0
- package/src/registry/mistral.ts +6 -0
- package/src/{utils/oauth → registry}/moonshot.ts +8 -9
- package/src/{utils/oauth → registry}/nanogpt.ts +8 -1
- package/src/{utils/oauth → registry}/nvidia.ts +8 -18
- package/src/{utils → registry}/oauth/__tests__/xai-oauth.test.ts +4 -7
- package/src/{utils → registry}/oauth/anthropic.ts +38 -17
- package/src/{utils → registry}/oauth/github-copilot.ts +79 -115
- package/src/registry/oauth/gitlab-duo.ts +198 -0
- package/src/{utils → registry}/oauth/google-antigravity.ts +1 -4
- package/src/{utils → registry}/oauth/google-gemini-cli.ts +1 -4
- package/src/registry/oauth/index.ts +164 -0
- package/src/{utils → registry}/oauth/minimax-code.ts +16 -14
- package/src/{utils → registry}/oauth/types.ts +7 -51
- package/src/{utils → registry}/oauth/wafer.ts +1 -1
- package/src/{utils → registry}/oauth/xai-oauth.ts +16 -8
- package/src/{utils → registry}/oauth/xiaomi.ts +9 -4
- package/src/{utils/oauth → registry}/ollama-cloud.ts +8 -1
- package/src/{utils/oauth → registry}/ollama.ts +8 -13
- package/src/registry/openai-codex-device.ts +18 -0
- package/src/registry/openai-codex.ts +19 -0
- package/src/registry/openai.ts +6 -0
- package/src/registry/opencode-go.ts +12 -0
- package/src/registry/opencode-zen.ts +12 -0
- package/src/{utils/oauth → registry}/openrouter.ts +10 -2
- package/src/{utils/oauth → registry}/parallel.ts +9 -11
- package/src/registry/perplexity.ts +13 -0
- package/src/{utils/oauth → registry}/qianfan.ts +8 -17
- package/src/{utils/oauth → registry}/qwen-portal.ts +8 -19
- package/src/registry/registry.ts +149 -0
- package/src/{utils/oauth → registry}/synthetic.ts +7 -1
- package/src/{utils/oauth → registry}/tavily.ts +10 -12
- package/src/{utils/oauth → registry}/together.ts +7 -1
- package/src/registry/types.ts +56 -0
- package/src/{utils/oauth → registry}/venice.ts +8 -12
- package/src/{utils/oauth → registry}/vercel-ai-gateway.ts +8 -18
- package/src/{utils/oauth → registry}/vllm.ts +9 -16
- package/src/registry/wafer-pass.ts +12 -0
- package/src/registry/wafer-serverless.ts +12 -0
- package/src/registry/xai-oauth.ts +17 -0
- package/src/registry/xai.ts +6 -0
- package/src/registry/xiaomi-token-plan-ams.ts +12 -0
- package/src/registry/xiaomi-token-plan-cn.ts +12 -0
- package/src/registry/xiaomi-token-plan-sgp.ts +12 -0
- package/src/registry/xiaomi.ts +12 -0
- package/src/{utils/oauth → registry}/zai.ts +10 -22
- package/src/{utils/oauth → registry}/zenmux.ts +8 -1
- package/src/{utils/oauth/zhipu.ts → registry/zhipu-coding-plan.ts} +9 -21
- package/src/stream.ts +229 -199
- package/src/types.ts +63 -384
- package/src/usage/claude.ts +4 -2
- package/src/usage/github-copilot.ts +4 -2
- package/src/usage/google-antigravity.ts +196 -28
- package/src/usage/kimi.ts +1 -1
- package/src/usage/minimax-code.ts +5 -6
- package/src/usage/openai-codex-reset.ts +174 -0
- package/src/usage/openai-codex.ts +19 -2
- package/src/usage/zai.ts +2 -1
- package/src/usage.ts +93 -4
- package/src/utils/abort.ts +14 -0
- package/src/utils/event-stream.ts +17 -0
- package/src/utils/http-inspector.ts +4 -12
- package/src/utils/idle-iterator.ts +250 -79
- package/src/utils/openai-http.ts +157 -0
- package/src/utils/request-debug.ts +67 -19
- package/src/utils/retry-after.ts +1 -1
- package/src/utils/retry.ts +23 -2
- package/src/utils/schema/CONSTRAINTS.md +4 -2
- package/src/utils/schema/fields.ts +16 -0
- package/src/utils/schema/json-schema-validator.ts +19 -1
- package/src/utils/schema/normalize.ts +80 -8
- package/src/utils/schema/stamps.ts +22 -10
- package/src/utils/schema/wire.ts +2 -2
- package/src/utils/sse-debug.ts +0 -271
- package/src/utils/stream-markup-healing.ts +50 -8
- package/src/utils/validation.ts +49 -13
- package/src/utils.ts +2 -26
- package/dist/types/model-cache.d.ts +0 -17
- package/dist/types/model-manager.d.ts +0 -64
- package/dist/types/model-thinking.d.ts +0 -100
- package/dist/types/models.d.ts +0 -12
- package/dist/types/provider-models/bundled-references.d.ts +0 -4
- package/dist/types/provider-models/descriptors.d.ts +0 -50
- package/dist/types/provider-models/google.d.ts +0 -24
- package/dist/types/provider-models/index.d.ts +0 -5
- package/dist/types/provider-models/ollama.d.ts +0 -7
- package/dist/types/provider-models/openai-compat.d.ts +0 -323
- package/dist/types/provider-models/special.d.ts +0 -16
- package/dist/types/utils/discovery/antigravity.d.ts +0 -61
- package/dist/types/utils/discovery/codex.d.ts +0 -38
- package/dist/types/utils/discovery/cursor.d.ts +0 -23
- package/dist/types/utils/discovery/gemini.d.ts +0 -25
- package/dist/types/utils/discovery/index.d.ts +0 -4
- package/dist/types/utils/discovery/openai-compatible.d.ts +0 -72
- package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +0 -18
- package/dist/types/utils/oauth/cerebras.d.ts +0 -1
- package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +0 -18
- package/dist/types/utils/oauth/deepseek.d.ts +0 -10
- package/dist/types/utils/oauth/firepass.d.ts +0 -1
- package/dist/types/utils/oauth/fireworks.d.ts +0 -1
- package/dist/types/utils/oauth/huggingface.d.ts +0 -19
- package/dist/types/utils/oauth/kagi.d.ts +0 -17
- package/dist/types/utils/oauth/kilo.d.ts +0 -5
- package/dist/types/utils/oauth/litellm.d.ts +0 -18
- package/dist/types/utils/oauth/lm-studio.d.ts +0 -17
- package/dist/types/utils/oauth/moonshot.d.ts +0 -1
- package/dist/types/utils/oauth/nanogpt.d.ts +0 -1
- package/dist/types/utils/oauth/nvidia.d.ts +0 -18
- package/dist/types/utils/oauth/ollama-cloud.d.ts +0 -2
- package/dist/types/utils/oauth/ollama.d.ts +0 -18
- package/dist/types/utils/oauth/openrouter.d.ts +0 -1
- package/dist/types/utils/oauth/parallel.d.ts +0 -17
- package/dist/types/utils/oauth/qianfan.d.ts +0 -17
- package/dist/types/utils/oauth/qwen-portal.d.ts +0 -19
- package/dist/types/utils/oauth/synthetic.d.ts +0 -1
- package/dist/types/utils/oauth/tavily.d.ts +0 -17
- package/dist/types/utils/oauth/together.d.ts +0 -1
- package/dist/types/utils/oauth/venice.d.ts +0 -18
- package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +0 -18
- package/dist/types/utils/oauth/vllm.d.ts +0 -16
- package/dist/types/utils/oauth/zai.d.ts +0 -18
- package/dist/types/utils/oauth/zenmux.d.ts +0 -1
- package/dist/types/utils/oauth/zhipu.d.ts +0 -18
- package/src/model-cache.ts +0 -129
- package/src/model-manager.ts +0 -469
- package/src/model-thinking.ts +0 -756
- package/src/models.json +0 -60287
- package/src/models.json.d.ts +0 -9
- package/src/models.ts +0 -56
- package/src/provider-models/bundled-references.ts +0 -38
- package/src/provider-models/descriptors.ts +0 -364
- package/src/provider-models/google.ts +0 -88
- package/src/provider-models/index.ts +0 -5
- package/src/provider-models/ollama.ts +0 -153
- package/src/provider-models/openai-compat.ts +0 -2904
- package/src/provider-models/special.ts +0 -67
- package/src/utils/discovery/antigravity.ts +0 -261
- package/src/utils/discovery/codex.ts +0 -371
- package/src/utils/discovery/cursor.ts +0 -306
- package/src/utils/discovery/gemini.ts +0 -248
- package/src/utils/discovery/index.ts +0 -4
- package/src/utils/discovery/openai-compatible.ts +0 -224
- package/src/utils/oauth/gitlab-duo.ts +0 -123
- package/src/utils/oauth/index.ts +0 -502
- /package/dist/types/{utils/oauth/__tests__/xai-oauth.test.d.ts → providers/__tests__/google-auth.test.d.ts} +0 -0
- /package/dist/types/{utils → registry}/oauth/callback-server.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/cursor.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/gitlab-duo.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/google-antigravity.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/google-gemini-cli.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/google-oauth-shared.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/kimi.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/openai-codex.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/opencode.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/perplexity.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/pkce.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/wafer.d.ts +0 -0
- /package/dist/types/{utils → registry}/oauth/xiaomi.d.ts +0 -0
- /package/src/{utils → registry}/oauth/callback-server.ts +0 -0
- /package/src/{utils → registry}/oauth/cursor.ts +0 -0
- /package/src/{utils → registry}/oauth/google-oauth-shared.ts +0 -0
- /package/src/{utils → registry}/oauth/kimi.ts +0 -0
- /package/src/{utils → registry}/oauth/oauth.html +0 -0
- /package/src/{utils → registry}/oauth/openai-codex.ts +0 -0
- /package/src/{utils → registry}/oauth/opencode.ts +0 -0
- /package/src/{utils → registry}/oauth/perplexity.ts +0 -0
- /package/src/{utils → registry}/oauth/pkce.ts +0 -0
|
@@ -25,12 +25,12 @@ import {
|
|
|
25
25
|
} from "./anthropic-messages-server-schema";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Anthropic Messages API (https://docs.anthropic.com/en/api/messages) ↔
|
|
28
|
+
* Anthropic Messages API (https://docs.anthropic.com/en/api/messages) ↔ Prometheus AI
|
|
29
29
|
* gateway translation. Inbound: foreign HTTP body → prometheus Context. Outbound:
|
|
30
30
|
* prometheus AssistantMessage[Stream] → Anthropic-shaped JSON / SSE.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
import type { AuthGatewayParsedRequest as ParsedRequest } from "../auth-gateway/types";
|
|
33
|
+
import type { AuthGatewayStreamControl, AuthGatewayParsedRequest as ParsedRequest } from "../auth-gateway/types";
|
|
34
34
|
|
|
35
35
|
export type { ParsedRequest };
|
|
36
36
|
|
|
@@ -53,7 +53,7 @@ function warnUnknownBlockType(category: "user" | "assistant", blockType: string)
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// Prometheus AI's `ImageContent` only carries base64 + mimeType. When the inbound
|
|
57
57
|
// uses `url` or `file_id` sources we surface a text placeholder so the
|
|
58
58
|
// downstream provider still sees a sane history; warn once per source kind.
|
|
59
59
|
const WARNED_NON_BASE64_IMAGE_SOURCES = new Set<string>();
|
|
@@ -61,8 +61,10 @@ function warnNonBase64ImageSource(sourceType: string): void {
|
|
|
61
61
|
if (WARNED_NON_BASE64_IMAGE_SOURCES.has(sourceType)) return;
|
|
62
62
|
WARNED_NON_BASE64_IMAGE_SOURCES.add(sourceType);
|
|
63
63
|
logger.warn(
|
|
64
|
-
"anthropic-messages: image source surfaced as text placeholder (
|
|
65
|
-
{
|
|
64
|
+
"anthropic-messages: image source surfaced as text placeholder (Prometheus AI ImageContent lacks URL channel)",
|
|
65
|
+
{
|
|
66
|
+
sourceType,
|
|
67
|
+
},
|
|
66
68
|
);
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -151,7 +153,7 @@ function walkUserContent(
|
|
|
151
153
|
}
|
|
152
154
|
} else if (block.type === "tool_result") {
|
|
153
155
|
// Anthropic permits tool_result blocks to follow plain text/image
|
|
154
|
-
// siblings in the same user message.
|
|
156
|
+
// siblings in the same user message. Prometheus AI's history is a flat
|
|
155
157
|
// sequence of typed messages, so flush the accumulated parts as a
|
|
156
158
|
// separate UserMessage before emitting the ToolResultMessage.
|
|
157
159
|
flush();
|
|
@@ -255,7 +257,7 @@ function readCacheControl(value: unknown): AnthropicCacheControl | undefined {
|
|
|
255
257
|
|
|
256
258
|
/**
|
|
257
259
|
* Anthropic clients annotate caching breakpoints per block via
|
|
258
|
-
* `cache_control: { type: "ephemeral", ttl?: "1h"|"5m" }`.
|
|
260
|
+
* `cache_control: { type: "ephemeral", ttl?: "1h"|"5m" }`. Prometheus AI's
|
|
259
261
|
* `cacheRetention` is per-request, not per-block, and its anthropic provider
|
|
260
262
|
* re-applies breakpoints itself on the rebuilt outbound wire. Scan every
|
|
261
263
|
* block once and return the strongest retention requested: any `ttl: "1h"`
|
|
@@ -324,7 +326,7 @@ export function parseRequest(body: unknown, headers?: Headers): ParsedRequest {
|
|
|
324
326
|
const toolChoice = mapToolChoice(data.tool_choice as AnthropicToolChoice | undefined);
|
|
325
327
|
if (toolChoice !== undefined) options.toolChoice = toolChoice;
|
|
326
328
|
// `disable_parallel_tool_use === true` means the client wants the model to
|
|
327
|
-
// emit at most one tool call per turn; map to
|
|
329
|
+
// emit at most one tool call per turn; map to Prometheus AI's negated boolean.
|
|
328
330
|
// Leave undefined when the field is absent or explicitly `false` so we
|
|
329
331
|
// don't override provider defaults.
|
|
330
332
|
if (data.tool_choice?.disable_parallel_tool_use === true) {
|
|
@@ -464,7 +466,7 @@ export function encodeResponse(message: AssistantMessage, requestedModelId: stri
|
|
|
464
466
|
model: requestedModelId,
|
|
465
467
|
content: encodeContentBlocks(message),
|
|
466
468
|
stop_reason: mapStopReasonOut(message.stopReason),
|
|
467
|
-
// TODO: surface the matched stop sequence once
|
|
469
|
+
// TODO: surface the matched stop sequence once Prometheus AI's
|
|
468
470
|
// `AssistantMessage.stopReason` carries the matched string. Intentionally
|
|
469
471
|
// `null` for now (Anthropic schema allows it).
|
|
470
472
|
stop_sequence: null,
|
|
@@ -489,17 +491,44 @@ interface OpenBlock {
|
|
|
489
491
|
kind: BlockKind;
|
|
490
492
|
}
|
|
491
493
|
|
|
494
|
+
// Keepalive cadence for the SSE encoder. Anthropic's API pings periodically;
|
|
495
|
+
// without frames between message_start and the first content block (slow first
|
|
496
|
+
// token) SDK first-event/idle watchdogs classify the stream as stalled.
|
|
497
|
+
const STREAM_PING_INTERVAL_MS = 15_000;
|
|
498
|
+
|
|
499
|
+
const ZERO_WIRE_USAGE: Record<string, unknown> = {
|
|
500
|
+
input_tokens: 0,
|
|
501
|
+
output_tokens: 0,
|
|
502
|
+
cache_read_input_tokens: 0,
|
|
503
|
+
cache_creation_input_tokens: 0,
|
|
504
|
+
};
|
|
505
|
+
|
|
492
506
|
export function encodeStream(
|
|
493
507
|
events: AssistantMessageEventStream,
|
|
494
508
|
requestedModelId: string,
|
|
509
|
+
_options?: ParsedRequest["options"],
|
|
510
|
+
control?: AuthGatewayStreamControl,
|
|
495
511
|
): ReadableStream<Uint8Array> {
|
|
512
|
+
let pingTimer: NodeJS.Timeout | undefined;
|
|
513
|
+
let cancelled = control?.signal?.aborted === true;
|
|
514
|
+
const markCancelled = () => {
|
|
515
|
+
cancelled = true;
|
|
516
|
+
};
|
|
517
|
+
control?.signal?.addEventListener("abort", markCancelled, { once: true });
|
|
518
|
+
const stopPings = () => {
|
|
519
|
+
if (pingTimer !== undefined) {
|
|
520
|
+
clearInterval(pingTimer);
|
|
521
|
+
pingTimer = undefined;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
496
524
|
return new ReadableStream<Uint8Array>({
|
|
497
525
|
async start(controller) {
|
|
498
526
|
const messageId = newMessageId();
|
|
499
527
|
let started = false;
|
|
528
|
+
let lastPartial: AssistantMessage | undefined;
|
|
500
529
|
const open = new Map<number, OpenBlock>();
|
|
501
530
|
|
|
502
|
-
const ensureStart = (partial: AssistantMessage) => {
|
|
531
|
+
const ensureStart = (partial: AssistantMessage | undefined) => {
|
|
503
532
|
if (started) return;
|
|
504
533
|
started = true;
|
|
505
534
|
controller.enqueue(
|
|
@@ -513,9 +542,9 @@ export function encodeStream(
|
|
|
513
542
|
content: [],
|
|
514
543
|
stop_reason: null,
|
|
515
544
|
// TODO: same as encodeResponse — surface matched stop sequence
|
|
516
|
-
// once
|
|
545
|
+
// once Prometheus AI propagates it.
|
|
517
546
|
stop_sequence: null,
|
|
518
|
-
usage: encodeUsage(partial),
|
|
547
|
+
usage: partial ? encodeUsage(partial) : ZERO_WIRE_USAGE,
|
|
519
548
|
},
|
|
520
549
|
}),
|
|
521
550
|
);
|
|
@@ -527,8 +556,26 @@ export function encodeStream(
|
|
|
527
556
|
open.delete(index);
|
|
528
557
|
};
|
|
529
558
|
|
|
559
|
+
pingTimer = setInterval(() => {
|
|
560
|
+
try {
|
|
561
|
+
if (cancelled) {
|
|
562
|
+
stopPings();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
controller.enqueue(sseFrame("ping", { type: "ping" }));
|
|
566
|
+
} catch {
|
|
567
|
+
// Controller already closed/errored (client gone); stop the timer.
|
|
568
|
+
stopPings();
|
|
569
|
+
}
|
|
570
|
+
}, STREAM_PING_INTERVAL_MS);
|
|
571
|
+
|
|
530
572
|
try {
|
|
573
|
+
if (cancelled) {
|
|
574
|
+
controller.close();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
531
577
|
for await (const ev of events) {
|
|
578
|
+
if (cancelled) return;
|
|
532
579
|
switch (ev.type) {
|
|
533
580
|
case "start":
|
|
534
581
|
ensureStart(ev.partial);
|
|
@@ -627,7 +674,7 @@ export function encodeStream(
|
|
|
627
674
|
controller.enqueue(
|
|
628
675
|
sseFrame("message_delta", {
|
|
629
676
|
type: "message_delta",
|
|
630
|
-
// TODO: surface matched stop sequence once
|
|
677
|
+
// TODO: surface matched stop sequence once Prometheus AI
|
|
631
678
|
// propagates it on the `done` event.
|
|
632
679
|
delta: { stop_reason: mapStopReasonOut(ev.reason), stop_sequence: null },
|
|
633
680
|
usage: encodeUsage(ev.message),
|
|
@@ -647,20 +694,41 @@ export function encodeStream(
|
|
|
647
694
|
}
|
|
648
695
|
}
|
|
649
696
|
}
|
|
650
|
-
//
|
|
697
|
+
// Stream ended without an explicit done: emit a complete envelope
|
|
698
|
+
// (message_start + message_delta carrying a stop_reason) so strict
|
|
699
|
+
// clients don't reject the response as a protocol error.
|
|
700
|
+
ensureStart(lastPartial);
|
|
651
701
|
for (const idx of [...open.keys()]) closeBlock(idx);
|
|
652
|
-
controller.enqueue(sseFrame("message_stop", { type: "message_stop" }));
|
|
653
|
-
controller.close();
|
|
654
|
-
} catch (err) {
|
|
655
702
|
controller.enqueue(
|
|
656
|
-
sseFrame("
|
|
657
|
-
type: "
|
|
658
|
-
|
|
703
|
+
sseFrame("message_delta", {
|
|
704
|
+
type: "message_delta",
|
|
705
|
+
delta: { stop_reason: "end_turn", stop_sequence: null },
|
|
706
|
+
usage: lastPartial ? encodeUsage(lastPartial) : ZERO_WIRE_USAGE,
|
|
659
707
|
}),
|
|
660
708
|
);
|
|
709
|
+
controller.enqueue(sseFrame("message_stop", { type: "message_stop" }));
|
|
661
710
|
controller.close();
|
|
711
|
+
} catch (err) {
|
|
712
|
+
if (!cancelled) {
|
|
713
|
+
controller.enqueue(
|
|
714
|
+
sseFrame("error", {
|
|
715
|
+
type: "error",
|
|
716
|
+
error: { type: "api_error", message: err instanceof Error ? err.message : String(err) },
|
|
717
|
+
}),
|
|
718
|
+
);
|
|
719
|
+
controller.close();
|
|
720
|
+
}
|
|
721
|
+
} finally {
|
|
722
|
+
control?.signal?.removeEventListener("abort", markCancelled);
|
|
723
|
+
stopPings();
|
|
662
724
|
}
|
|
663
725
|
},
|
|
726
|
+
cancel(reason) {
|
|
727
|
+
cancelled = true;
|
|
728
|
+
control?.signal?.removeEventListener("abort", markCancelled);
|
|
729
|
+
control?.onCancel?.(reason);
|
|
730
|
+
stopPings();
|
|
731
|
+
},
|
|
664
732
|
});
|
|
665
733
|
}
|
|
666
734
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anthropic Messages API wire types.
|
|
3
3
|
*
|
|
4
|
-
* Hand-maintained against https://docs.anthropic.com/en/api/messages so
|
|
4
|
+
* Hand-maintained against https://docs.anthropic.com/en/api/messages so Prometheus AI
|
|
5
5
|
* does not depend on `@anthropic-ai/sdk` for type information. Only the shapes
|
|
6
6
|
* this package actually reads or writes are modeled; fields we never touch are
|
|
7
7
|
* intentionally omitted. Names mirror the SDK so call sites read the same.
|
|
8
8
|
*
|
|
9
|
-
* Unlike the SDK, beta fields
|
|
9
|
+
* Unlike the SDK, beta fields Prometheus AI uses (`speed`, `context_management`,
|
|
10
10
|
* `output_config.effort`/`task_budget`, `thinking.display`, cache-control
|
|
11
11
|
* `scope`, tool `strict`/`eager_input_streaming`, mid-conversation `system`
|
|
12
12
|
* role) are first-class here instead of being patched in via casts.
|
|
@@ -188,7 +188,8 @@ export type StopReason =
|
|
|
188
188
|
| "tool_use"
|
|
189
189
|
| "pause_turn"
|
|
190
190
|
| "refusal"
|
|
191
|
-
| "sensitive"
|
|
191
|
+
| "sensitive"
|
|
192
|
+
| "model_context_window_exceeded";
|
|
192
193
|
|
|
193
194
|
export type CacheCreation = {
|
|
194
195
|
ephemeral_5m_input_tokens?: number | null;
|