@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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { resolvePromptCacheKey } from "../auth-gateway/http";
|
|
3
3
|
/**
|
|
4
|
-
* Parsed inbound OpenAI chat-completions request, ready to feed into
|
|
4
|
+
* Parsed inbound OpenAI chat-completions request, ready to feed into Prometheus AI
|
|
5
5
|
* `stream(model, context, options)`.
|
|
6
6
|
*/
|
|
7
|
-
import type { AuthGatewayParsedRequest as ParsedRequest } from "../auth-gateway/types";
|
|
7
|
+
import type { AuthGatewayStreamControl, AuthGatewayParsedRequest as ParsedRequest } from "../auth-gateway/types";
|
|
8
8
|
import type {
|
|
9
9
|
AssistantMessage,
|
|
10
10
|
AssistantMessageEventStream,
|
|
@@ -91,6 +91,7 @@ export function parseRequest(body: unknown, headers?: Headers): ParsedRequest {
|
|
|
91
91
|
buildAssistantMessage(
|
|
92
92
|
(m.content ?? undefined) as string | OpenAIChatContentPart[] | undefined,
|
|
93
93
|
m.tool_calls,
|
|
94
|
+
(m as { reasoning_content?: string | null }).reasoning_content ?? undefined,
|
|
94
95
|
data.model,
|
|
95
96
|
now,
|
|
96
97
|
),
|
|
@@ -197,7 +198,7 @@ function parseUserLikeContent(
|
|
|
197
198
|
}
|
|
198
199
|
if (part.type !== "image_url") continue;
|
|
199
200
|
// input_audio / file / refusal / unknown-type parts are accepted by the
|
|
200
|
-
// schema for forward-compat but dropped here —
|
|
201
|
+
// schema for forward-compat but dropped here — Prometheus AI's canonical user
|
|
201
202
|
// content only models text and image today.
|
|
202
203
|
const url = typeof part.image_url === "string" ? part.image_url : part.image_url.url;
|
|
203
204
|
const decoded = decodeDataUri(url);
|
|
@@ -227,10 +228,17 @@ function decodeDataUri(url: string): { data: string; mimeType: string } | undefi
|
|
|
227
228
|
function buildAssistantMessage(
|
|
228
229
|
content: string | OpenAIChatContentPart[] | undefined,
|
|
229
230
|
toolCalls: OpenAIChatToolCall[] | undefined,
|
|
231
|
+
reasoningContent: string | undefined,
|
|
230
232
|
modelId: string,
|
|
231
233
|
now: number,
|
|
232
234
|
): AssistantMessage {
|
|
233
235
|
const parts: AssistantMessage["content"] = [];
|
|
236
|
+
if (reasoningContent !== undefined && reasoningContent.length > 0) {
|
|
237
|
+
// Replayed reasoning channel. The signature names the wire field so
|
|
238
|
+
// completions providers that demand exact `reasoning_content` replay
|
|
239
|
+
// (DeepSeek/Kimi) echo the model's actual reasoning back verbatim.
|
|
240
|
+
parts.push({ type: "thinking", thinking: reasoningContent, thinkingSignature: "reasoning_content" });
|
|
241
|
+
}
|
|
234
242
|
const text = stringifyContent(content);
|
|
235
243
|
if (text.length > 0) parts.push({ type: "text", text });
|
|
236
244
|
if (toolCalls) {
|
|
@@ -275,7 +283,7 @@ function buildAssistantMessage(
|
|
|
275
283
|
|
|
276
284
|
/**
|
|
277
285
|
* Walk a wire `tool` (or legacy `function`) message into canonical messages.
|
|
278
|
-
* Tool-result content may carry images alongside text;
|
|
286
|
+
* Tool-result content may carry images alongside text; Prometheus AI's
|
|
279
287
|
* `ToolResultMessage` accepts both, but most downstream providers ignore
|
|
280
288
|
* images on tool results. To mirror Rust's `encode_messages` behavior we
|
|
281
289
|
* keep text inside the tool-result message and hoist any image parts into a
|
|
@@ -377,7 +385,7 @@ export function encodeResponse(message: AssistantMessage, requestedModelId: stri
|
|
|
377
385
|
const responseMessage: Record<string, unknown> = {
|
|
378
386
|
role: "assistant",
|
|
379
387
|
content: text.length > 0 ? text : null,
|
|
380
|
-
//
|
|
388
|
+
// Prometheus AI does not surface real refusals yet; emit `null` so SDKs that
|
|
381
389
|
// probe `.refusal` see the documented field shape rather than missing.
|
|
382
390
|
refusal: null,
|
|
383
391
|
};
|
|
@@ -476,7 +484,7 @@ function stringifyArgs(args: Record<string, unknown>): string {
|
|
|
476
484
|
function mapFinishReason(reason: StopReason, hasToolCalls: boolean): string {
|
|
477
485
|
if (reason === "toolUse" || (hasToolCalls && reason === "stop")) return "tool_calls";
|
|
478
486
|
if (reason === "length") return "length";
|
|
479
|
-
//
|
|
487
|
+
// Prometheus AI's StopReason does not currently carry a content-filter signal;
|
|
480
488
|
// when it does, map it to "content_filter" here.
|
|
481
489
|
return "stop";
|
|
482
490
|
}
|
|
@@ -493,11 +501,17 @@ export function encodeStream(
|
|
|
493
501
|
events: AssistantMessageEventStream,
|
|
494
502
|
requestedModelId: string,
|
|
495
503
|
options?: ParsedRequest["options"],
|
|
504
|
+
control?: AuthGatewayStreamControl,
|
|
496
505
|
): ReadableStream<Uint8Array> {
|
|
497
506
|
const encoder = new TextEncoder();
|
|
498
507
|
const id = makeId();
|
|
499
508
|
const created = Math.floor(Date.now() / 1000);
|
|
500
509
|
const includeUsage = options?.extra?.includeStreamingUsage === true;
|
|
510
|
+
let cancelled = control?.signal?.aborted === true;
|
|
511
|
+
const markCancelled = () => {
|
|
512
|
+
cancelled = true;
|
|
513
|
+
};
|
|
514
|
+
control?.signal?.addEventListener("abort", markCancelled, { once: true });
|
|
501
515
|
|
|
502
516
|
const baseChunk = (delta: Record<string, unknown>, finishReason: string | null) => ({
|
|
503
517
|
id,
|
|
@@ -510,7 +524,7 @@ export function encodeStream(
|
|
|
510
524
|
});
|
|
511
525
|
|
|
512
526
|
const writeSse = (controller: ReadableStreamDefaultController<Uint8Array>, payload: unknown): void => {
|
|
513
|
-
controller.enqueue(encoder.encode(`data: ${JSON.stringify(payload)}\n\n`));
|
|
527
|
+
if (!cancelled) controller.enqueue(encoder.encode(`data: ${JSON.stringify(payload)}\n\n`));
|
|
514
528
|
};
|
|
515
529
|
|
|
516
530
|
const writeUsage = (controller: ReadableStreamDefaultController<Uint8Array>, message: AssistantMessage): void => {
|
|
@@ -527,17 +541,25 @@ export function encodeStream(
|
|
|
527
541
|
|
|
528
542
|
return new ReadableStream<Uint8Array>({
|
|
529
543
|
async start(controller) {
|
|
530
|
-
// contentIndex (from
|
|
544
|
+
// contentIndex (from Prometheus AI events) -> tool_calls index on the wire.
|
|
531
545
|
const toolIndexByContentIndex = new Map<number, number>();
|
|
546
|
+
// wire index -> id/name emitted on the start chunk, to detect late-arriving
|
|
547
|
+
// upstream id/name that needs a corrective chunk before the finish.
|
|
548
|
+
const sentToolMeta = new Map<number, { id: string; name: string }>();
|
|
532
549
|
let nextToolIndex = 0;
|
|
533
550
|
let hasToolCalls = false;
|
|
534
551
|
let finishReason: string = "stop";
|
|
535
552
|
|
|
536
553
|
try {
|
|
554
|
+
if (cancelled) {
|
|
555
|
+
controller.close();
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
537
558
|
// Initial role chunk.
|
|
538
559
|
writeSse(controller, baseChunk({ role: "assistant" }, null));
|
|
539
560
|
|
|
540
561
|
for await (const event of events) {
|
|
562
|
+
if (cancelled) return;
|
|
541
563
|
switch (event.type) {
|
|
542
564
|
case "text_delta":
|
|
543
565
|
if (event.delta.length > 0) {
|
|
@@ -559,6 +581,7 @@ export function encodeStream(
|
|
|
559
581
|
toolIndexByContentIndex.set(event.contentIndex, idx);
|
|
560
582
|
const partial = event.partial.content[event.contentIndex];
|
|
561
583
|
const call = partial && partial.type === "toolCall" ? partial : undefined;
|
|
584
|
+
sentToolMeta.set(idx, { id: call?.id ?? "", name: call?.name ?? "" });
|
|
562
585
|
writeSse(
|
|
563
586
|
controller,
|
|
564
587
|
baseChunk(
|
|
@@ -588,6 +611,38 @@ export function encodeStream(
|
|
|
588
611
|
break;
|
|
589
612
|
}
|
|
590
613
|
|
|
614
|
+
case "toolcall_end": {
|
|
615
|
+
const idx = toolIndexByContentIndex.get(event.contentIndex);
|
|
616
|
+
if (idx === undefined) break;
|
|
617
|
+
const sent = sentToolMeta.get(idx);
|
|
618
|
+
if (sent === undefined) break;
|
|
619
|
+
// Upstream completions providers can receive the real id/name in a
|
|
620
|
+
// later chunk than toolcall_start. Emit a corrective chunk only when
|
|
621
|
+
// the streamed value was empty: accumulating clients concatenate
|
|
622
|
+
// string fields, so "" + value is the only safe correction.
|
|
623
|
+
const correctId = sent.id === "" && event.toolCall.id !== "" ? event.toolCall.id : undefined;
|
|
624
|
+
const correctName =
|
|
625
|
+
sent.name === "" && event.toolCall.name !== "" ? event.toolCall.name : undefined;
|
|
626
|
+
if (correctId !== undefined || correctName !== undefined) {
|
|
627
|
+
writeSse(
|
|
628
|
+
controller,
|
|
629
|
+
baseChunk(
|
|
630
|
+
{
|
|
631
|
+
tool_calls: [
|
|
632
|
+
{
|
|
633
|
+
index: idx,
|
|
634
|
+
...(correctId !== undefined ? { id: correctId } : {}),
|
|
635
|
+
...(correctName !== undefined ? { function: { name: correctName } } : {}),
|
|
636
|
+
},
|
|
637
|
+
],
|
|
638
|
+
},
|
|
639
|
+
null,
|
|
640
|
+
),
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
|
|
591
646
|
case "done":
|
|
592
647
|
finishReason =
|
|
593
648
|
event.reason === "toolUse"
|
|
@@ -610,23 +665,34 @@ export function encodeStream(
|
|
|
610
665
|
return;
|
|
611
666
|
}
|
|
612
667
|
|
|
613
|
-
// Drop start / *_start / *_end — chat-completions
|
|
614
|
-
// surfaces deltas and the terminal finish_reason.
|
|
668
|
+
// Drop start / *_start and text/thinking *_end — chat-completions
|
|
669
|
+
// wire only surfaces deltas and the terminal finish_reason.
|
|
615
670
|
default:
|
|
616
671
|
break;
|
|
617
672
|
}
|
|
618
673
|
}
|
|
619
674
|
|
|
620
675
|
// Stream ended without a terminal `done` (defensive). Close gracefully.
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
676
|
+
if (!cancelled) {
|
|
677
|
+
writeSse(controller, baseChunk({}, hasToolCalls ? "tool_calls" : "stop"));
|
|
678
|
+
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
|
679
|
+
controller.close();
|
|
680
|
+
}
|
|
624
681
|
} catch (err) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
682
|
+
if (!cancelled) {
|
|
683
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
684
|
+
writeSse(controller, { error: { message: msg, type: "upstream_error" } });
|
|
685
|
+
controller.close();
|
|
686
|
+
}
|
|
687
|
+
} finally {
|
|
688
|
+
control?.signal?.removeEventListener("abort", markCancelled);
|
|
628
689
|
}
|
|
629
690
|
},
|
|
691
|
+
cancel(reason) {
|
|
692
|
+
cancelled = true;
|
|
693
|
+
control?.signal?.removeEventListener("abort", markCancelled);
|
|
694
|
+
control?.onCancel?.(reason);
|
|
695
|
+
},
|
|
630
696
|
});
|
|
631
697
|
}
|
|
632
698
|
|