@dc99-tech/pi-ai 0.0.0-stage → 1.8.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/README.md +2088 -2
- package/dist/api/anthropic-messages.d.ts +71 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -0
- package/dist/api/anthropic-messages.js +1461 -0
- package/dist/api/anthropic-messages.js.map +1 -0
- package/dist/api/anthropic-messages.lazy.d.ts +3 -0
- package/dist/api/anthropic-messages.lazy.d.ts.map +1 -0
- package/dist/api/anthropic-messages.lazy.js +3 -0
- package/dist/api/anthropic-messages.lazy.js.map +1 -0
- package/dist/api/azure-openai-config.d.ts +15 -0
- package/dist/api/azure-openai-config.d.ts.map +1 -0
- package/dist/api/azure-openai-config.js +76 -0
- package/dist/api/azure-openai-config.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts +14 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.js +184 -0
- package/dist/api/azure-openai-responses.js.map +1 -0
- package/dist/api/azure-openai-responses.lazy.d.ts +3 -0
- package/dist/api/azure-openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/azure-openai-responses.lazy.js +3 -0
- package/dist/api/azure-openai-responses.lazy.js.map +1 -0
- package/dist/api/bedrock-converse-stream.d.ts +38 -0
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.js +1202 -0
- package/dist/api/bedrock-converse-stream.js.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts +16 -0
- package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -0
- package/dist/api/bedrock-converse-stream.lazy.js +43 -0
- package/dist/api/bedrock-converse-stream.lazy.js.map +1 -0
- package/dist/api/classifier-shared.d.ts +20 -0
- package/dist/api/classifier-shared.d.ts.map +1 -0
- package/dist/api/classifier-shared.js +46 -0
- package/dist/api/classifier-shared.js.map +1 -0
- package/dist/api/cloudflare-ai-binding.d.ts +77 -0
- package/dist/api/cloudflare-ai-binding.d.ts.map +1 -0
- package/dist/api/cloudflare-ai-binding.js +72 -0
- package/dist/api/cloudflare-ai-binding.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.js +57 -0
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts +3 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.d.ts.map +1 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/dist/api/cloudflare-workers-ai-system-one.lazy.js.map +1 -0
- package/dist/api/cloudflare.d.ts +11 -0
- package/dist/api/cloudflare.d.ts.map +1 -0
- package/dist/api/cloudflare.js +11 -0
- package/dist/api/cloudflare.js.map +1 -0
- package/dist/api/constrained-sampling.d.ts +38 -0
- package/dist/api/constrained-sampling.d.ts.map +1 -0
- package/dist/api/constrained-sampling.js +257 -0
- package/dist/api/constrained-sampling.js.map +1 -0
- package/dist/api/github-copilot-headers.d.ts +8 -0
- package/dist/api/github-copilot-headers.d.ts.map +1 -0
- package/dist/api/github-copilot-headers.js +29 -0
- package/dist/api/github-copilot-headers.js.map +1 -0
- package/dist/api/google-generative-ai.d.ts +13 -0
- package/dist/api/google-generative-ai.d.ts.map +1 -0
- package/dist/api/google-generative-ai.js +339 -0
- package/dist/api/google-generative-ai.js.map +1 -0
- package/dist/api/google-generative-ai.lazy.d.ts +3 -0
- package/dist/api/google-generative-ai.lazy.d.ts.map +1 -0
- package/dist/api/google-generative-ai.lazy.js +3 -0
- package/dist/api/google-generative-ai.lazy.js.map +1 -0
- package/dist/api/google-shared.d.ts +98 -0
- package/dist/api/google-shared.d.ts.map +1 -0
- package/dist/api/google-shared.js +562 -0
- package/dist/api/google-shared.js.map +1 -0
- package/dist/api/google-vertex.d.ts +15 -0
- package/dist/api/google-vertex.d.ts.map +1 -0
- package/dist/api/google-vertex.js +412 -0
- package/dist/api/google-vertex.js.map +1 -0
- package/dist/api/google-vertex.lazy.d.ts +3 -0
- package/dist/api/google-vertex.lazy.d.ts.map +1 -0
- package/dist/api/google-vertex.lazy.js +3 -0
- package/dist/api/google-vertex.lazy.js.map +1 -0
- package/dist/api/json-request.d.ts +20 -0
- package/dist/api/json-request.d.ts.map +1 -0
- package/dist/api/json-request.js +119 -0
- package/dist/api/json-request.js.map +1 -0
- package/dist/api/lazy.d.ts +24 -0
- package/dist/api/lazy.d.ts.map +1 -0
- package/dist/api/lazy.js +91 -0
- package/dist/api/lazy.js.map +1 -0
- package/dist/api/llama-cpp-classify.d.ts +33 -0
- package/dist/api/llama-cpp-classify.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.js +368 -0
- package/dist/api/llama-cpp-classify.js.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts +3 -0
- package/dist/api/llama-cpp-classify.lazy.d.ts.map +1 -0
- package/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/dist/api/llama-cpp-classify.lazy.js.map +1 -0
- package/dist/api/mistral-conversations.d.ts +25 -0
- package/dist/api/mistral-conversations.d.ts.map +1 -0
- package/dist/api/mistral-conversations.js +719 -0
- package/dist/api/mistral-conversations.js.map +1 -0
- package/dist/api/mistral-conversations.lazy.d.ts +3 -0
- package/dist/api/mistral-conversations.lazy.d.ts.map +1 -0
- package/dist/api/mistral-conversations.lazy.js +3 -0
- package/dist/api/mistral-conversations.lazy.js.map +1 -0
- package/dist/api/openai-codex-responses.d.ts +31 -0
- package/dist/api/openai-codex-responses.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.js +1323 -0
- package/dist/api/openai-codex-responses.js.map +1 -0
- package/dist/api/openai-codex-responses.lazy.d.ts +3 -0
- package/dist/api/openai-codex-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-codex-responses.lazy.js +3 -0
- package/dist/api/openai-codex-responses.lazy.js.map +1 -0
- package/dist/api/openai-completions-reasoning.d.ts +62 -0
- package/dist/api/openai-completions-reasoning.d.ts.map +1 -0
- package/dist/api/openai-completions-reasoning.js +144 -0
- package/dist/api/openai-completions-reasoning.js.map +1 -0
- package/dist/api/openai-completions.d.ts +27 -0
- package/dist/api/openai-completions.d.ts.map +1 -0
- package/dist/api/openai-completions.js +1318 -0
- package/dist/api/openai-completions.js.map +1 -0
- package/dist/api/openai-completions.lazy.d.ts +3 -0
- package/dist/api/openai-completions.lazy.d.ts.map +1 -0
- package/dist/api/openai-completions.lazy.js +3 -0
- package/dist/api/openai-completions.lazy.js.map +1 -0
- package/dist/api/openai-decisions.d.ts +4 -0
- package/dist/api/openai-decisions.d.ts.map +1 -0
- package/dist/api/openai-decisions.js +162 -0
- package/dist/api/openai-decisions.js.map +1 -0
- package/dist/api/openai-decisions.lazy.d.ts +3 -0
- package/dist/api/openai-decisions.lazy.d.ts.map +1 -0
- package/dist/api/openai-decisions.lazy.js +4 -0
- package/dist/api/openai-decisions.lazy.js.map +1 -0
- package/dist/api/openai-prompt-cache.d.ts +3 -0
- package/dist/api/openai-prompt-cache.d.ts.map +1 -0
- package/dist/api/openai-prompt-cache.js +10 -0
- package/dist/api/openai-prompt-cache.js.map +1 -0
- package/dist/api/openai-responses-shared.d.ts +63 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -0
- package/dist/api/openai-responses-shared.js +824 -0
- package/dist/api/openai-responses-shared.js.map +1 -0
- package/dist/api/openai-responses.d.ts +14 -0
- package/dist/api/openai-responses.d.ts.map +1 -0
- package/dist/api/openai-responses.js +331 -0
- package/dist/api/openai-responses.js.map +1 -0
- package/dist/api/openai-responses.lazy.d.ts +3 -0
- package/dist/api/openai-responses.lazy.d.ts.map +1 -0
- package/dist/api/openai-responses.lazy.js +3 -0
- package/dist/api/openai-responses.lazy.js.map +1 -0
- package/dist/api/openrouter-chat-images.d.ts +4 -0
- package/dist/api/openrouter-chat-images.d.ts.map +1 -0
- package/dist/api/openrouter-chat-images.js +94 -0
- package/dist/api/openrouter-chat-images.js.map +1 -0
- package/dist/api/openrouter-chat-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-chat-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-chat-images.lazy.js +4 -0
- package/dist/api/openrouter-chat-images.lazy.js.map +1 -0
- package/dist/api/openrouter-images-shared.d.ts +9 -0
- package/dist/api/openrouter-images-shared.d.ts.map +1 -0
- package/dist/api/openrouter-images-shared.js +69 -0
- package/dist/api/openrouter-images-shared.js.map +1 -0
- package/dist/api/openrouter-images.d.ts +4 -0
- package/dist/api/openrouter-images.d.ts.map +1 -0
- package/dist/api/openrouter-images.js +91 -0
- package/dist/api/openrouter-images.js.map +1 -0
- package/dist/api/openrouter-images.lazy.d.ts +3 -0
- package/dist/api/openrouter-images.lazy.d.ts.map +1 -0
- package/dist/api/openrouter-images.lazy.js +4 -0
- package/dist/api/openrouter-images.lazy.js.map +1 -0
- package/dist/api/pi-decision.d.ts +22 -0
- package/dist/api/pi-decision.d.ts.map +1 -0
- package/dist/api/pi-decision.js +120 -0
- package/dist/api/pi-decision.js.map +1 -0
- package/dist/api/pi-decision.lazy.d.ts +3 -0
- package/dist/api/pi-decision.lazy.d.ts.map +1 -0
- package/dist/api/pi-decision.lazy.js +4 -0
- package/dist/api/pi-decision.lazy.js.map +1 -0
- package/dist/api/pi-image.d.ts +25 -0
- package/dist/api/pi-image.d.ts.map +1 -0
- package/dist/api/pi-image.js +82 -0
- package/dist/api/pi-image.js.map +1 -0
- package/dist/api/pi-image.lazy.d.ts +3 -0
- package/dist/api/pi-image.lazy.d.ts.map +1 -0
- package/dist/api/pi-image.lazy.js +4 -0
- package/dist/api/pi-image.lazy.js.map +1 -0
- package/dist/api/pi-messages.d.ts +101 -0
- package/dist/api/pi-messages.d.ts.map +1 -0
- package/dist/api/pi-messages.js +312 -0
- package/dist/api/pi-messages.js.map +1 -0
- package/dist/api/pi-messages.lazy.d.ts +3 -0
- package/dist/api/pi-messages.lazy.d.ts.map +1 -0
- package/dist/api/pi-messages.lazy.js +3 -0
- package/dist/api/pi-messages.lazy.js.map +1 -0
- package/dist/api/simple-options.d.ts +17 -0
- package/dist/api/simple-options.d.ts.map +1 -0
- package/dist/api/simple-options.js +88 -0
- package/dist/api/simple-options.js.map +1 -0
- package/dist/api/strict-tool-limits.d.ts +13 -0
- package/dist/api/strict-tool-limits.d.ts.map +1 -0
- package/dist/api/strict-tool-limits.js +50 -0
- package/dist/api/strict-tool-limits.js.map +1 -0
- package/dist/api/system-one-shared.d.ts +49 -0
- package/dist/api/system-one-shared.d.ts.map +1 -0
- package/dist/api/system-one-shared.js +158 -0
- package/dist/api/system-one-shared.js.map +1 -0
- package/dist/api/transform-messages.d.ts +23 -0
- package/dist/api/transform-messages.d.ts.map +1 -0
- package/dist/api/transform-messages.js +214 -0
- package/dist/api/transform-messages.js.map +1 -0
- package/dist/api/typesafe-system-one.d.ts +4 -0
- package/dist/api/typesafe-system-one.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.js +30 -0
- package/dist/api/typesafe-system-one.js.map +1 -0
- package/dist/api/typesafe-system-one.lazy.d.ts +3 -0
- package/dist/api/typesafe-system-one.lazy.d.ts.map +1 -0
- package/dist/api/typesafe-system-one.lazy.js +4 -0
- package/dist/api/typesafe-system-one.lazy.js.map +1 -0
- package/dist/auth/context.d.ts +7 -0
- package/dist/auth/context.d.ts.map +1 -0
- package/dist/auth/context.js +42 -0
- package/dist/auth/context.js.map +1 -0
- package/dist/auth/credential-store.d.ts +17 -0
- package/dist/auth/credential-store.d.ts.map +1 -0
- package/dist/auth/credential-store.js +51 -0
- package/dist/auth/credential-store.js.map +1 -0
- package/dist/auth/helpers.d.ts +22 -0
- package/dist/auth/helpers.d.ts.map +1 -0
- package/dist/auth/helpers.js +53 -0
- package/dist/auth/helpers.js.map +1 -0
- package/dist/auth/oauth/anthropic.d.ts +9 -0
- package/dist/auth/oauth/anthropic.d.ts.map +1 -0
- package/dist/auth/oauth/anthropic.js +257 -0
- package/dist/auth/oauth/anthropic.js.map +1 -0
- package/dist/auth/oauth/callback-server.d.ts +55 -0
- package/dist/auth/oauth/callback-server.d.ts.map +1 -0
- package/dist/auth/oauth/callback-server.js +151 -0
- package/dist/auth/oauth/callback-server.js.map +1 -0
- package/dist/auth/oauth/device-code.d.ts +24 -0
- package/dist/auth/oauth/device-code.d.ts.map +1 -0
- package/dist/auth/oauth/device-code.js +69 -0
- package/dist/auth/oauth/device-code.js.map +1 -0
- package/dist/auth/oauth/github-copilot.d.ts +6 -0
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -0
- package/dist/auth/oauth/github-copilot.js +389 -0
- package/dist/auth/oauth/github-copilot.js.map +1 -0
- package/dist/auth/oauth/kimi-coding.d.ts +10 -0
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -0
- package/dist/auth/oauth/kimi-coding.js +230 -0
- package/dist/auth/oauth/kimi-coding.js.map +1 -0
- package/dist/auth/oauth/load.d.ts +31 -0
- package/dist/auth/oauth/load.d.ts.map +1 -0
- package/dist/auth/oauth/load.js +72 -0
- package/dist/auth/oauth/load.js.map +1 -0
- package/dist/auth/oauth/meta.d.ts +17 -0
- package/dist/auth/oauth/meta.d.ts.map +1 -0
- package/dist/auth/oauth/meta.js +177 -0
- package/dist/auth/oauth/meta.js.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts +9 -0
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -0
- package/dist/auth/oauth/openai-chatgpt.js +262 -0
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -0
- package/dist/auth/oauth/openai-codex.d.ts +9 -0
- package/dist/auth/oauth/openai-codex.d.ts.map +1 -0
- package/dist/auth/oauth/openai-codex.js +346 -0
- package/dist/auth/oauth/openai-codex.js.map +1 -0
- package/dist/auth/oauth/openrouter.d.ts +15 -0
- package/dist/auth/oauth/openrouter.d.ts.map +1 -0
- package/dist/auth/oauth/openrouter.js +158 -0
- package/dist/auth/oauth/openrouter.js.map +1 -0
- package/dist/auth/oauth/pkce.d.ts +13 -0
- package/dist/auth/oauth/pkce.d.ts.map +1 -0
- package/dist/auth/oauth/pkce.js +31 -0
- package/dist/auth/oauth/pkce.js.map +1 -0
- package/dist/auth/oauth/radius.d.ts +17 -0
- package/dist/auth/oauth/radius.d.ts.map +1 -0
- package/dist/auth/oauth/radius.js +259 -0
- package/dist/auth/oauth/radius.js.map +1 -0
- package/dist/auth/oauth/trusted-url.d.ts +7 -0
- package/dist/auth/oauth/trusted-url.d.ts.map +1 -0
- package/dist/auth/oauth/trusted-url.js +12 -0
- package/dist/auth/oauth/trusted-url.js.map +1 -0
- package/dist/auth/oauth/xai.d.ts +6 -0
- package/dist/auth/oauth/xai.d.ts.map +1 -0
- package/dist/auth/oauth/xai.js +190 -0
- package/dist/auth/oauth/xai.js.map +1 -0
- package/dist/auth/resolve.d.ts +36 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +140 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/types.d.ts +249 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/bedrock-provider.d.ts +5 -0
- package/dist/bedrock-provider.d.ts.map +1 -0
- package/dist/bedrock-provider.js +6 -0
- package/dist/bedrock-provider.js.map +1 -0
- package/dist/bun-oauth.d.ts +3 -0
- package/dist/bun-oauth.d.ts.map +1 -0
- package/dist/bun-oauth.js +25 -0
- package/dist/bun-oauth.js.map +1 -0
- package/dist/cache-warming.d.ts +53 -0
- package/dist/cache-warming.d.ts.map +1 -0
- package/dist/cache-warming.js +82 -0
- package/dist/cache-warming.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +119 -0
- package/dist/cli.js.map +1 -0
- package/dist/compat/extension-oauth-types.d.ts +43 -0
- package/dist/compat/extension-oauth-types.d.ts.map +1 -0
- package/dist/compat/extension-oauth-types.js +2 -0
- package/dist/compat/extension-oauth-types.js.map +1 -0
- package/dist/compat.d.ts +67 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +202 -0
- package/dist/compat.js.map +1 -0
- package/dist/env-api-keys.d.ts +26 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +165 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/image-models.d.ts +21 -0
- package/dist/image-models.d.ts.map +1 -0
- package/dist/image-models.js +24 -0
- package/dist/image-models.js.map +1 -0
- package/dist/images-api-registry.d.ts +14 -0
- package/dist/images-api-registry.d.ts.map +1 -0
- package/dist/images-api-registry.js +22 -0
- package/dist/images-api-registry.js.map +1 -0
- package/dist/images.d.ts +9 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +19 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy-bedrock-provider.d.ts +10 -0
- package/dist/lazy-bedrock-provider.d.ts.map +1 -0
- package/dist/lazy-bedrock-provider.js +13 -0
- package/dist/lazy-bedrock-provider.js.map +1 -0
- package/dist/lazy-oauth.d.ts +10 -0
- package/dist/lazy-oauth.d.ts.map +1 -0
- package/dist/lazy-oauth.js +23 -0
- package/dist/lazy-oauth.js.map +1 -0
- package/dist/legacy-api-aliases.d.ts +42 -0
- package/dist/legacy-api-aliases.d.ts.map +1 -0
- package/dist/legacy-api-aliases.js +49 -0
- package/dist/legacy-api-aliases.js.map +1 -0
- package/dist/model-catalog.d.ts +33 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +16 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models-store.d.ts +30 -0
- package/dist/models-store.d.ts.map +1 -0
- package/dist/models-store.js +17 -0
- package/dist/models-store.js.map +1 -0
- package/dist/models.d.ts +284 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +179 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +181 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +756 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth.d.ts +3 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +2 -0
- package/dist/oauth.js.map +1 -0
- package/dist/providers/all.d.ts +34 -0
- package/dist/providers/all.d.ts.map +1 -0
- package/dist/providers/all.js +139 -0
- package/dist/providers/all.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +3 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +93 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/amazon-bedrock.models.d.ts +6 -0
- package/dist/providers/amazon-bedrock.models.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.models.js +8 -0
- package/dist/providers/amazon-bedrock.models.js.map +1 -0
- package/dist/providers/ant-ling.d.ts +3 -0
- package/dist/providers/ant-ling.d.ts.map +1 -0
- package/dist/providers/ant-ling.js +15 -0
- package/dist/providers/ant-ling.js.map +1 -0
- package/dist/providers/ant-ling.models.d.ts +6 -0
- package/dist/providers/ant-ling.models.d.ts.map +1 -0
- package/dist/providers/ant-ling.models.js +8 -0
- package/dist/providers/ant-ling.models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +78 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.models.d.ts +6 -0
- package/dist/providers/anthropic.models.d.ts.map +1 -0
- package/dist/providers/anthropic.models.js +8 -0
- package/dist/providers/anthropic.models.js.map +1 -0
- package/dist/providers/azure.d.ts +3 -0
- package/dist/providers/azure.d.ts.map +1 -0
- package/dist/providers/azure.js +46 -0
- package/dist/providers/azure.js.map +1 -0
- package/dist/providers/azure.models.d.ts +6 -0
- package/dist/providers/azure.models.d.ts.map +1 -0
- package/dist/providers/azure.models.js +8 -0
- package/dist/providers/azure.models.js.map +1 -0
- package/dist/providers/baseten.d.ts +3 -0
- package/dist/providers/baseten.d.ts.map +1 -0
- package/dist/providers/baseten.js +21 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/baseten.models.d.ts +6 -0
- package/dist/providers/baseten.models.d.ts.map +1 -0
- package/dist/providers/baseten.models.js +8 -0
- package/dist/providers/baseten.models.js.map +1 -0
- package/dist/providers/cerebras.d.ts +3 -0
- package/dist/providers/cerebras.d.ts.map +1 -0
- package/dist/providers/cerebras.js +15 -0
- package/dist/providers/cerebras.js.map +1 -0
- package/dist/providers/cerebras.models.d.ts +6 -0
- package/dist/providers/cerebras.models.d.ts.map +1 -0
- package/dist/providers/cerebras.models.js +8 -0
- package/dist/providers/cerebras.models.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +5 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.js +25 -0
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts +6 -0
- package/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-ai-gateway.models.js +8 -0
- package/dist/providers/cloudflare-ai-gateway.models.js.map +1 -0
- package/dist/providers/cloudflare-auth.d.ts +4 -0
- package/dist/providers/cloudflare-auth.d.ts.map +1 -0
- package/dist/providers/cloudflare-auth.js +86 -0
- package/dist/providers/cloudflare-auth.js.map +1 -0
- package/dist/providers/cloudflare-stream.d.ts +12 -0
- package/dist/providers/cloudflare-stream.d.ts.map +1 -0
- package/dist/providers/cloudflare-stream.js +27 -0
- package/dist/providers/cloudflare-stream.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +3 -0
- package/dist/providers/cloudflare-workers-ai.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.js +22 -0
- package/dist/providers/cloudflare-workers-ai.js.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts +6 -0
- package/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -0
- package/dist/providers/cloudflare-workers-ai.models.js +8 -0
- package/dist/providers/cloudflare-workers-ai.models.js.map +1 -0
- package/dist/providers/compat-schema.d.ts +518 -0
- package/dist/providers/compat-schema.d.ts.map +1 -0
- package/dist/providers/compat-schema.js +471 -0
- package/dist/providers/compat-schema.js.map +1 -0
- package/dist/providers/data/.manifest.json +1 -0
- package/dist/providers/data/amazon-bedrock.json +1 -0
- package/dist/providers/data/ant-ling.json +1 -0
- package/dist/providers/data/anthropic.json +1 -0
- package/dist/providers/data/azure.json +1 -0
- package/dist/providers/data/baseten.json +1 -0
- package/dist/providers/data/cerebras.json +1 -0
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -0
- package/dist/providers/data/cloudflare-workers-ai.json +1 -0
- package/dist/providers/data/deepseek.json +1 -0
- package/dist/providers/data/fireworks.json +1 -0
- package/dist/providers/data/github-copilot.json +1 -0
- package/dist/providers/data/google-vertex.json +1 -0
- package/dist/providers/data/google.json +1 -0
- package/dist/providers/data/groq.json +1 -0
- package/dist/providers/data/huggingface.json +1 -0
- package/dist/providers/data/kimi-coding.json +1 -0
- package/dist/providers/data/meta.json +1 -0
- package/dist/providers/data/minimax-cn.json +1 -0
- package/dist/providers/data/minimax.json +1 -0
- package/dist/providers/data/mistral.json +1 -0
- package/dist/providers/data/moonshotai-cn.json +1 -0
- package/dist/providers/data/moonshotai.json +1 -0
- package/dist/providers/data/nvidia.json +1 -0
- package/dist/providers/data/openai-codex.json +1 -0
- package/dist/providers/data/openai.json +1 -0
- package/dist/providers/data/opencode-go.json +1 -0
- package/dist/providers/data/opencode.json +1 -0
- package/dist/providers/data/openrouter.json +1 -0
- package/dist/providers/data/qwen-token-plan-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
- package/dist/providers/data/qwen-token-plan-individual.json +1 -0
- package/dist/providers/data/qwen-token-plan.json +1 -0
- package/dist/providers/data/radius.json +1 -0
- package/dist/providers/data/together.json +1 -0
- package/dist/providers/data/typesafe.json +1 -0
- package/dist/providers/data/vercel-ai-gateway.json +1 -0
- package/dist/providers/data/xai.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
- package/dist/providers/data/xiaomi.json +1 -0
- package/dist/providers/data/zai-coding-cn.json +1 -0
- package/dist/providers/data/zai.json +1 -0
- package/dist/providers/deepseek.d.ts +3 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +15 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/deepseek.models.d.ts +6 -0
- package/dist/providers/deepseek.models.d.ts.map +1 -0
- package/dist/providers/deepseek.models.js +8 -0
- package/dist/providers/deepseek.models.js.map +1 -0
- package/dist/providers/faux.d.ts +103 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/faux.js +511 -0
- package/dist/providers/faux.js.map +1 -0
- package/dist/providers/fireworks.d.ts +3 -0
- package/dist/providers/fireworks.d.ts.map +1 -0
- package/dist/providers/fireworks.js +19 -0
- package/dist/providers/fireworks.js.map +1 -0
- package/dist/providers/fireworks.models.d.ts +6 -0
- package/dist/providers/fireworks.models.d.ts.map +1 -0
- package/dist/providers/fireworks.models.js +8 -0
- package/dist/providers/fireworks.models.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +5 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +67 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/github-copilot.models.d.ts +6 -0
- package/dist/providers/github-copilot.models.d.ts.map +1 -0
- package/dist/providers/github-copilot.models.js +8 -0
- package/dist/providers/github-copilot.models.js.map +1 -0
- package/dist/providers/google-vertex.d.ts +3 -0
- package/dist/providers/google-vertex.d.ts.map +1 -0
- package/dist/providers/google-vertex.js +94 -0
- package/dist/providers/google-vertex.js.map +1 -0
- package/dist/providers/google-vertex.models.d.ts +6 -0
- package/dist/providers/google-vertex.models.d.ts.map +1 -0
- package/dist/providers/google-vertex.models.js +8 -0
- package/dist/providers/google-vertex.models.js.map +1 -0
- package/dist/providers/google.d.ts +3 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +15 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/google.models.d.ts +6 -0
- package/dist/providers/google.models.d.ts.map +1 -0
- package/dist/providers/google.models.js +8 -0
- package/dist/providers/google.models.js.map +1 -0
- package/dist/providers/groq.d.ts +3 -0
- package/dist/providers/groq.d.ts.map +1 -0
- package/dist/providers/groq.js +15 -0
- package/dist/providers/groq.js.map +1 -0
- package/dist/providers/groq.models.d.ts +6 -0
- package/dist/providers/groq.models.d.ts.map +1 -0
- package/dist/providers/groq.models.js +8 -0
- package/dist/providers/groq.models.js.map +1 -0
- package/dist/providers/huggingface.d.ts +3 -0
- package/dist/providers/huggingface.d.ts.map +1 -0
- package/dist/providers/huggingface.js +15 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/huggingface.models.d.ts +6 -0
- package/dist/providers/huggingface.models.d.ts.map +1 -0
- package/dist/providers/huggingface.models.js +8 -0
- package/dist/providers/huggingface.models.js.map +1 -0
- package/dist/providers/images/register-builtins.d.ts +5 -0
- package/dist/providers/images/register-builtins.d.ts.map +1 -0
- package/dist/providers/images/register-builtins.js +52 -0
- package/dist/providers/images/register-builtins.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +3 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +24 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/kimi-coding.models.d.ts +6 -0
- package/dist/providers/kimi-coding.models.d.ts.map +1 -0
- package/dist/providers/kimi-coding.models.js +8 -0
- package/dist/providers/kimi-coding.models.js.map +1 -0
- package/dist/providers/meta.d.ts +3 -0
- package/dist/providers/meta.d.ts.map +1 -0
- package/dist/providers/meta.js +24 -0
- package/dist/providers/meta.js.map +1 -0
- package/dist/providers/meta.models.d.ts +6 -0
- package/dist/providers/meta.models.d.ts.map +1 -0
- package/dist/providers/meta.models.js +8 -0
- package/dist/providers/meta.models.js.map +1 -0
- package/dist/providers/minimax-cn.d.ts +3 -0
- package/dist/providers/minimax-cn.d.ts.map +1 -0
- package/dist/providers/minimax-cn.js +15 -0
- package/dist/providers/minimax-cn.js.map +1 -0
- package/dist/providers/minimax-cn.models.d.ts +6 -0
- package/dist/providers/minimax-cn.models.d.ts.map +1 -0
- package/dist/providers/minimax-cn.models.js +8 -0
- package/dist/providers/minimax-cn.models.js.map +1 -0
- package/dist/providers/minimax.d.ts +3 -0
- package/dist/providers/minimax.d.ts.map +1 -0
- package/dist/providers/minimax.js +15 -0
- package/dist/providers/minimax.js.map +1 -0
- package/dist/providers/minimax.models.d.ts +6 -0
- package/dist/providers/minimax.models.d.ts.map +1 -0
- package/dist/providers/minimax.models.js +8 -0
- package/dist/providers/minimax.models.js.map +1 -0
- package/dist/providers/mistral.d.ts +3 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/mistral.js +15 -0
- package/dist/providers/mistral.js.map +1 -0
- package/dist/providers/mistral.models.d.ts +6 -0
- package/dist/providers/mistral.models.d.ts.map +1 -0
- package/dist/providers/mistral.models.js +8 -0
- package/dist/providers/mistral.models.js.map +1 -0
- package/dist/providers/model-schema.d.ts +92 -0
- package/dist/providers/model-schema.d.ts.map +1 -0
- package/dist/providers/model-schema.js +71 -0
- package/dist/providers/model-schema.js.map +1 -0
- package/dist/providers/moonshotai-cn.d.ts +3 -0
- package/dist/providers/moonshotai-cn.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.js +15 -0
- package/dist/providers/moonshotai-cn.js.map +1 -0
- package/dist/providers/moonshotai-cn.models.d.ts +6 -0
- package/dist/providers/moonshotai-cn.models.d.ts.map +1 -0
- package/dist/providers/moonshotai-cn.models.js +8 -0
- package/dist/providers/moonshotai-cn.models.js.map +1 -0
- package/dist/providers/moonshotai.d.ts +3 -0
- package/dist/providers/moonshotai.d.ts.map +1 -0
- package/dist/providers/moonshotai.js +15 -0
- package/dist/providers/moonshotai.js.map +1 -0
- package/dist/providers/moonshotai.models.d.ts +6 -0
- package/dist/providers/moonshotai.models.d.ts.map +1 -0
- package/dist/providers/moonshotai.models.js +8 -0
- package/dist/providers/moonshotai.models.js.map +1 -0
- package/dist/providers/nvidia.d.ts +3 -0
- package/dist/providers/nvidia.d.ts.map +1 -0
- package/dist/providers/nvidia.js +15 -0
- package/dist/providers/nvidia.js.map +1 -0
- package/dist/providers/nvidia.models.d.ts +6 -0
- package/dist/providers/nvidia.models.d.ts.map +1 -0
- package/dist/providers/nvidia.models.js +8 -0
- package/dist/providers/nvidia.models.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +3 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +22 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/openai-codex.models.d.ts +6 -0
- package/dist/providers/openai-codex.models.d.ts.map +1 -0
- package/dist/providers/openai-codex.models.js +8 -0
- package/dist/providers/openai-codex.models.js.map +1 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +33 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.models.d.ts +6 -0
- package/dist/providers/openai.models.d.ts.map +1 -0
- package/dist/providers/openai.models.js +8 -0
- package/dist/providers/openai.models.js.map +1 -0
- package/dist/providers/opencode-go.d.ts +5 -0
- package/dist/providers/opencode-go.d.ts.map +1 -0
- package/dist/providers/opencode-go.js +29 -0
- package/dist/providers/opencode-go.js.map +1 -0
- package/dist/providers/opencode-go.models.d.ts +6 -0
- package/dist/providers/opencode-go.models.d.ts.map +1 -0
- package/dist/providers/opencode-go.models.js +8 -0
- package/dist/providers/opencode-go.models.js.map +1 -0
- package/dist/providers/opencode-headers.d.ts +4 -0
- package/dist/providers/opencode-headers.d.ts.map +1 -0
- package/dist/providers/opencode-headers.js +22 -0
- package/dist/providers/opencode-headers.js.map +1 -0
- package/dist/providers/opencode.d.ts +5 -0
- package/dist/providers/opencode.d.ts.map +1 -0
- package/dist/providers/opencode.js +26 -0
- package/dist/providers/opencode.js.map +1 -0
- package/dist/providers/opencode.models.d.ts +6 -0
- package/dist/providers/opencode.models.d.ts.map +1 -0
- package/dist/providers/opencode.models.js +8 -0
- package/dist/providers/opencode.models.js.map +1 -0
- package/dist/providers/openrouter-api.d.ts +47 -0
- package/dist/providers/openrouter-api.d.ts.map +1 -0
- package/dist/providers/openrouter-api.js +51 -0
- package/dist/providers/openrouter-api.js.map +1 -0
- package/dist/providers/openrouter.d.ts +13 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +91 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/openrouter.models.d.ts +6 -0
- package/dist/providers/openrouter.models.d.ts.map +1 -0
- package/dist/providers/openrouter.models.js +8 -0
- package/dist/providers/openrouter.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.js +20 -0
- package/dist/providers/qwen-token-plan-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.js +20 -0
- package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual-cn.models.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.d.ts +3 -0
- package/dist/providers/qwen-token-plan-individual.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.js +20 -0
- package/dist/providers/qwen-token-plan-individual.js.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan-individual.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan-individual.models.js +8 -0
- package/dist/providers/qwen-token-plan-individual.models.js.map +1 -0
- package/dist/providers/qwen-token-plan.d.ts +3 -0
- package/dist/providers/qwen-token-plan.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.js +20 -0
- package/dist/providers/qwen-token-plan.js.map +1 -0
- package/dist/providers/qwen-token-plan.models.d.ts +6 -0
- package/dist/providers/qwen-token-plan.models.d.ts.map +1 -0
- package/dist/providers/qwen-token-plan.models.js +8 -0
- package/dist/providers/qwen-token-plan.models.js.map +1 -0
- package/dist/providers/radius-config.d.ts +45 -0
- package/dist/providers/radius-config.d.ts.map +1 -0
- package/dist/providers/radius-config.js +121 -0
- package/dist/providers/radius-config.js.map +1 -0
- package/dist/providers/radius.d.ts +9 -0
- package/dist/providers/radius.d.ts.map +1 -0
- package/dist/providers/radius.js +83 -0
- package/dist/providers/radius.js.map +1 -0
- package/dist/providers/radius.models.d.ts +6 -0
- package/dist/providers/radius.models.d.ts.map +1 -0
- package/dist/providers/radius.models.js +8 -0
- package/dist/providers/radius.models.js.map +1 -0
- package/dist/providers/schema-builders.d.ts +10 -0
- package/dist/providers/schema-builders.d.ts.map +1 -0
- package/dist/providers/schema-builders.js +18 -0
- package/dist/providers/schema-builders.js.map +1 -0
- package/dist/providers/together.d.ts +3 -0
- package/dist/providers/together.d.ts.map +1 -0
- package/dist/providers/together.js +15 -0
- package/dist/providers/together.js.map +1 -0
- package/dist/providers/together.models.d.ts +6 -0
- package/dist/providers/together.models.d.ts.map +1 -0
- package/dist/providers/together.models.js +8 -0
- package/dist/providers/together.models.js.map +1 -0
- package/dist/providers/typesafe.d.ts +3 -0
- package/dist/providers/typesafe.d.ts.map +1 -0
- package/dist/providers/typesafe.js +18 -0
- package/dist/providers/typesafe.js.map +1 -0
- package/dist/providers/typesafe.models.d.ts +6 -0
- package/dist/providers/typesafe.models.d.ts.map +1 -0
- package/dist/providers/typesafe.models.js +8 -0
- package/dist/providers/typesafe.models.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +3 -0
- package/dist/providers/vercel-ai-gateway.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.js +18 -0
- package/dist/providers/vercel-ai-gateway.js.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts +6 -0
- package/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -0
- package/dist/providers/vercel-ai-gateway.models.js +8 -0
- package/dist/providers/vercel-ai-gateway.models.js.map +1 -0
- package/dist/providers/xai.d.ts +3 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +24 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/providers/xai.models.d.ts +6 -0
- package/dist/providers/xai.models.d.ts.map +1 -0
- package/dist/providers/xai.models.js +8 -0
- package/dist/providers/xai.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-ams.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.js +15 -0
- package/dist/providers/xiaomi-token-plan-ams.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-cn.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.js +15 -0
- package/dist/providers/xiaomi-token-plan-cn.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts +3 -0
- package/dist/providers/xiaomi-token-plan-sgp.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.js +15 -0
- package/dist/providers/xiaomi-token-plan-sgp.js.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts +6 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js +8 -0
- package/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -0
- package/dist/providers/xiaomi.d.ts +3 -0
- package/dist/providers/xiaomi.d.ts.map +1 -0
- package/dist/providers/xiaomi.js +15 -0
- package/dist/providers/xiaomi.js.map +1 -0
- package/dist/providers/xiaomi.models.d.ts +6 -0
- package/dist/providers/xiaomi.models.d.ts.map +1 -0
- package/dist/providers/xiaomi.models.js +8 -0
- package/dist/providers/xiaomi.models.js.map +1 -0
- package/dist/providers/zai-coding-cn.d.ts +3 -0
- package/dist/providers/zai-coding-cn.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.js +15 -0
- package/dist/providers/zai-coding-cn.js.map +1 -0
- package/dist/providers/zai-coding-cn.models.d.ts +6 -0
- package/dist/providers/zai-coding-cn.models.d.ts.map +1 -0
- package/dist/providers/zai-coding-cn.models.js +8 -0
- package/dist/providers/zai-coding-cn.models.js.map +1 -0
- package/dist/providers/zai.d.ts +3 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +15 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/providers/zai.models.d.ts +6 -0
- package/dist/providers/zai.models.d.ts.map +1 -0
- package/dist/providers/zai.models.js +8 -0
- package/dist/providers/zai.models.js.map +1 -0
- package/dist/session-resources.d.ts +4 -0
- package/dist/session-resources.d.ts.map +1 -0
- package/dist/session-resources.js +22 -0
- package/dist/session-resources.js.map +1 -0
- package/dist/telemetry.d.ts +39 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +113 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +729 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/abort-signals.d.ts +6 -0
- package/dist/utils/abort-signals.d.ts.map +1 -0
- package/dist/utils/abort-signals.js +34 -0
- package/dist/utils/abort-signals.js.map +1 -0
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +49 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +20 -0
- package/dist/utils/diagnostics.d.ts.map +1 -0
- package/dist/utils/diagnostics.js +25 -0
- package/dist/utils/diagnostics.js.map +1 -0
- package/dist/utils/error-body.d.ts +33 -0
- package/dist/utils/error-body.d.ts.map +1 -0
- package/dist/utils/error-body.js +161 -0
- package/dist/utils/error-body.js.map +1 -0
- package/dist/utils/estimate.d.ts +17 -0
- package/dist/utils/estimate.d.ts.map +1 -0
- package/dist/utils/estimate.js +95 -0
- package/dist/utils/estimate.js.map +1 -0
- package/dist/utils/event-stream.d.ts +30 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +124 -0
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.d.ts +4 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +20 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/identity.d.ts +65 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +141 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/json-parse.d.ts +26 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +138 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/model-operations.d.ts +13 -0
- package/dist/utils/model-operations.d.ts.map +1 -0
- package/dist/utils/model-operations.js +53 -0
- package/dist/utils/model-operations.js.map +1 -0
- package/dist/utils/models-error.d.ts +8 -0
- package/dist/utils/models-error.d.ts.map +1 -0
- package/dist/utils/models-error.js +19 -0
- package/dist/utils/models-error.js.map +1 -0
- package/dist/utils/node-http-proxy.d.ts +4 -0
- package/dist/utils/node-http-proxy.d.ts.map +1 -0
- package/dist/utils/node-http-proxy.js +133 -0
- package/dist/utils/node-http-proxy.js.map +1 -0
- package/dist/utils/oauth-page.d.ts +3 -0
- package/dist/utils/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth-page.js +105 -0
- package/dist/utils/oauth-page.js.map +1 -0
- package/dist/utils/openrouter-cost.d.ts +25 -0
- package/dist/utils/openrouter-cost.d.ts.map +1 -0
- package/dist/utils/openrouter-cost.js +35 -0
- package/dist/utils/openrouter-cost.js.map +1 -0
- package/dist/utils/openrouter-finish-reason.d.ts +22 -0
- package/dist/utils/openrouter-finish-reason.d.ts.map +1 -0
- package/dist/utils/openrouter-finish-reason.js +41 -0
- package/dist/utils/openrouter-finish-reason.js.map +1 -0
- package/dist/utils/overflow.d.ts +71 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +189 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/provider-env.d.ts +7 -0
- package/dist/utils/provider-env.d.ts.map +1 -0
- package/dist/utils/provider-env.js +44 -0
- package/dist/utils/provider-env.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +24 -0
- package/dist/utils/provider-retry.d.ts.map +1 -0
- package/dist/utils/provider-retry.js +102 -0
- package/dist/utils/provider-retry.js.map +1 -0
- package/dist/utils/retry.d.ts +58 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +269 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/sanitize-unicode.d.ts +22 -0
- package/dist/utils/sanitize-unicode.d.ts.map +1 -0
- package/dist/utils/sanitize-unicode.js +26 -0
- package/dist/utils/sanitize-unicode.js.map +1 -0
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/sse.d.ts +29 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +85 -0
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/streaming-json.d.ts +84 -0
- package/dist/utils/streaming-json.d.ts.map +1 -0
- package/dist/utils/streaming-json.js +513 -0
- package/dist/utils/streaming-json.js.map +1 -0
- package/dist/utils/string-enum.d.ts +17 -0
- package/dist/utils/string-enum.d.ts.map +1 -0
- package/dist/utils/string-enum.js +20 -0
- package/dist/utils/string-enum.js.map +1 -0
- package/dist/utils/text.d.ts +21 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +45 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/transcript.d.ts +101 -0
- package/dist/utils/transcript.d.ts.map +1 -0
- package/dist/utils/transcript.js +218 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +42 -0
- package/dist/utils/uuid.js.map +1 -0
- package/dist/utils/validation.d.ts +20 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +62 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/version.d.ts +2 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +3 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +118 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-chat-images.d.ts","sourceRoot":"","sources":["../../src/api/openrouter-chat-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKX,cAAc,EACd,aAAa,EAEb,MAAM,aAAa,CAAC;AAYrB,oEAAoE;AACpE,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,aAAa,CA4BxD,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
2
|
+
import { readOpenRouterNativeFinishReason } from "../utils/openrouter-finish-reason.js";
|
|
3
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
4
|
+
import { isRecord, postJsonRequest } from "./json-request.js";
|
|
5
|
+
import { failImageResult, parseDataUrl, parseOpenRouterError, parseOpenRouterImageUsage, } from "./openrouter-images-shared.js";
|
|
6
|
+
/** Image generation over OpenRouter's chat completions endpoint. */
|
|
7
|
+
export const generateImages = async (model, context, options) => {
|
|
8
|
+
const output = {
|
|
9
|
+
api: model.api,
|
|
10
|
+
provider: model.provider,
|
|
11
|
+
model: model.id,
|
|
12
|
+
output: [],
|
|
13
|
+
stopReason: "stop",
|
|
14
|
+
timestamp: Date.now(),
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL("chat/completions", `${model.baseUrl.replace(/\/+$/u, "")}/`);
|
|
18
|
+
const params = buildChatParams(model, context, options);
|
|
19
|
+
// Image generation is billed per completed image, so default to no automatic retries.
|
|
20
|
+
const body = await postJsonRequest("OpenRouter Images", url, model, params, {
|
|
21
|
+
...options,
|
|
22
|
+
maxRetries: options?.maxRetries ?? 0,
|
|
23
|
+
});
|
|
24
|
+
return parseChatResponse(body, model, output);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
28
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
29
|
+
return output;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function buildChatParams(model, context, options) {
|
|
33
|
+
const content = context.input.map((item) => item.type === "text"
|
|
34
|
+
? { type: "text", text: sanitizeSurrogates(item.text) }
|
|
35
|
+
: { type: "image_url", image_url: { url: `data:${item.mimeType};base64,${item.data}` } });
|
|
36
|
+
const imageConfig = {
|
|
37
|
+
...(options?.aspectRatio ? { aspect_ratio: options.aspectRatio } : {}),
|
|
38
|
+
...(options?.size ? { image_size: options.size } : {}),
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
model: model.id,
|
|
42
|
+
messages: [{ role: "user", content }],
|
|
43
|
+
stream: false,
|
|
44
|
+
modalities: model.output.includes("text") ? ["image", "text"] : ["image"],
|
|
45
|
+
...(Object.keys(imageConfig).length > 0 ? { image_config: imageConfig } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function parseChatResponse(body, model, output) {
|
|
49
|
+
if (!isRecord(body))
|
|
50
|
+
return failImageResult(output, "Provider returned an unexpected response");
|
|
51
|
+
if (typeof body.id === "string" && body.id.length > 0) {
|
|
52
|
+
output.responseId = body.id;
|
|
53
|
+
}
|
|
54
|
+
const usage = parseOpenRouterImageUsage(body.usage, model);
|
|
55
|
+
if (usage)
|
|
56
|
+
output.usage = usage;
|
|
57
|
+
const choice = Array.isArray(body.choices) && isRecord(body.choices[0]) ? body.choices[0] : undefined;
|
|
58
|
+
if (!choice) {
|
|
59
|
+
return failImageResult(output, parseOpenRouterError(body.error) ?? "Provider returned no choices");
|
|
60
|
+
}
|
|
61
|
+
const choiceError = parseOpenRouterError(choice.error) ?? parseOpenRouterError(body.error);
|
|
62
|
+
if (choiceError) {
|
|
63
|
+
return failImageResult(output, choiceError);
|
|
64
|
+
}
|
|
65
|
+
const finishReason = typeof choice.finish_reason === "string" ? choice.finish_reason : undefined;
|
|
66
|
+
if (finishReason && finishReason !== "stop" && finishReason !== "end") {
|
|
67
|
+
const nativeReason = readOpenRouterNativeFinishReason(choice);
|
|
68
|
+
return failImageResult(output, nativeReason && nativeReason !== finishReason
|
|
69
|
+
? `Provider finish_reason: ${finishReason} (native_finish_reason: ${nativeReason})`
|
|
70
|
+
: `Provider finish_reason: ${finishReason}`);
|
|
71
|
+
}
|
|
72
|
+
const message = isRecord(choice.message) ? choice.message : undefined;
|
|
73
|
+
if (typeof message?.content === "string" && message.content.length > 0) {
|
|
74
|
+
output.output.push({ type: "text", text: message.content });
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(message?.images)) {
|
|
77
|
+
for (const image of message.images) {
|
|
78
|
+
if (!isRecord(image))
|
|
79
|
+
continue;
|
|
80
|
+
const imageUrl = typeof image.image_url === "string"
|
|
81
|
+
? image.image_url
|
|
82
|
+
: isRecord(image.image_url) && typeof image.image_url.url === "string"
|
|
83
|
+
? image.image_url.url
|
|
84
|
+
: undefined;
|
|
85
|
+
if (!imageUrl)
|
|
86
|
+
continue;
|
|
87
|
+
const parsed = parseDataUrl(imageUrl);
|
|
88
|
+
if (parsed)
|
|
89
|
+
output.output.push(parsed);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=openrouter-chat-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-chat-images.js","sourceRoot":"","sources":["../../src/api/openrouter-chat-images.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,eAAe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AM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type {\n\tAssistantImages,\n\tImageApi,\n\tImageModel,\n\tImagesContext,\n\tImagesFunction,\n\tImagesOptions,\n\tTextContent,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { readOpenRouterNativeFinishReason } from \"../utils/openrouter-finish-reason.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { isRecord, postJsonRequest } from \"./json-request.ts\";\nimport {\n\tfailImageResult,\n\tparseDataUrl,\n\tparseOpenRouterError,\n\tparseOpenRouterImageUsage,\n} from \"./openrouter-images-shared.ts\";\n\n/** Image generation over OpenRouter's chat completions endpoint. */\nexport const generateImages: ImagesFunction<ImagesOptions> = async (\n\tmodel: ImageModel<ImageApi>,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tconst url = new URL(\"chat/completions\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`);\n\t\tconst params = buildChatParams(model, context, options);\n\t\t// Image generation is billed per completed image, so default to no automatic retries.\n\t\tconst body = await postJsonRequest(\"OpenRouter Images\", url, model, params, {\n\t\t\t...options,\n\t\t\tmaxRetries: options?.maxRetries ?? 0,\n\t\t});\n\t\treturn parseChatResponse(body, model, output);\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\treturn output;\n\t}\n};\n\nfunction buildChatParams(model: ImageModel<ImageApi>, context: ImagesContext, options?: ImagesOptions) {\n\tconst content = context.input.map((item) =>\n\t\titem.type === \"text\"\n\t\t\t? { type: \"text\" as const, text: sanitizeSurrogates(item.text) }\n\t\t\t: { type: \"image_url\" as const, image_url: { url: `data:${item.mimeType};base64,${item.data}` } },\n\t);\n\tconst imageConfig = {\n\t\t...(options?.aspectRatio ? { aspect_ratio: options.aspectRatio } : {}),\n\t\t...(options?.size ? { image_size: options.size } : {}),\n\t};\n\treturn {\n\t\tmodel: model.id,\n\t\tmessages: [{ role: \"user\" as const, content }],\n\t\tstream: false,\n\t\tmodalities: model.output.includes(\"text\") ? ([\"image\", \"text\"] as const) : ([\"image\"] as const),\n\t\t...(Object.keys(imageConfig).length > 0 ? { image_config: imageConfig } : {}),\n\t};\n}\n\nfunction parseChatResponse(body: unknown, model: ImageModel<ImageApi>, output: AssistantImages): AssistantImages {\n\tif (!isRecord(body)) return failImageResult(output, \"Provider returned an unexpected response\");\n\n\tif (typeof body.id === \"string\" && body.id.length > 0) {\n\t\toutput.responseId = body.id;\n\t}\n\tconst usage = parseOpenRouterImageUsage(body.usage, model);\n\tif (usage) output.usage = usage;\n\n\tconst choice = Array.isArray(body.choices) && isRecord(body.choices[0]) ? body.choices[0] : undefined;\n\tif (!choice) {\n\t\treturn failImageResult(output, parseOpenRouterError(body.error) ?? \"Provider returned no choices\");\n\t}\n\n\tconst choiceError = parseOpenRouterError(choice.error) ?? parseOpenRouterError(body.error);\n\tif (choiceError) {\n\t\treturn failImageResult(output, choiceError);\n\t}\n\n\tconst finishReason = typeof choice.finish_reason === \"string\" ? choice.finish_reason : undefined;\n\tif (finishReason && finishReason !== \"stop\" && finishReason !== \"end\") {\n\t\tconst nativeReason = readOpenRouterNativeFinishReason(choice);\n\t\treturn failImageResult(\n\t\t\toutput,\n\t\t\tnativeReason && nativeReason !== finishReason\n\t\t\t\t? `Provider finish_reason: ${finishReason} (native_finish_reason: ${nativeReason})`\n\t\t\t\t: `Provider finish_reason: ${finishReason}`,\n\t\t);\n\t}\n\n\tconst message = isRecord(choice.message) ? choice.message : undefined;\n\tif (typeof message?.content === \"string\" && message.content.length > 0) {\n\t\toutput.output.push({ type: \"text\", text: message.content } satisfies TextContent);\n\t}\n\n\tif (Array.isArray(message?.images)) {\n\t\tfor (const image of message.images) {\n\t\t\tif (!isRecord(image)) continue;\n\t\t\tconst imageUrl =\n\t\t\t\ttypeof image.image_url === \"string\"\n\t\t\t\t\t? image.image_url\n\t\t\t\t\t: isRecord(image.image_url) && typeof image.image_url.url === \"string\"\n\t\t\t\t\t\t? image.image_url.url\n\t\t\t\t\t\t: undefined;\n\t\t\tif (!imageUrl) continue;\n\t\t\tconst parsed = parseDataUrl(imageUrl);\n\t\t\tif (parsed) output.output.push(parsed);\n\t\t}\n\t}\n\n\treturn output;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-chat-images.lazy.d.ts","sourceRoot":"","sources":["../../src/api/openrouter-chat-images.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,uBAAuB,QAAO,cAGzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-chat-images.lazy.js","sourceRoot":"","sources":["../../src/api/openrouter-chat-images.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAmB,EAAE,CAAC,CAAC;IAC7D,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CACjD,CAAC,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CACtF,CAAC,CAAC","sourcesContent":["import type { ProviderImages } from \"../types.ts\";\n\nexport const openrouterChatImagesApi = (): ProviderImages => ({\n\tgenerateImages: async (model, context, options) =>\n\t\t(await import(\"./openrouter-chat-images.ts\")).generateImages(model, context, options),\n});\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AssistantImages, ImageApi, ImageContent, ImageModel, Usage } from "../types.ts";
|
|
2
|
+
export declare function failImageResult(output: AssistantImages, message: string): AssistantImages;
|
|
3
|
+
export declare function finiteNonNegative(value: unknown): number;
|
|
4
|
+
export declare function parseOpenRouterError(value: unknown): string | undefined;
|
|
5
|
+
export declare function parseDataUrl(value: string): ImageContent | undefined;
|
|
6
|
+
export declare function parseOpenRouterImageUsage(value: unknown, model: ImageModel<ImageApi>, options?: {
|
|
7
|
+
allowDirectCostWithoutByok?: boolean;
|
|
8
|
+
}): Usage | undefined;
|
|
9
|
+
//# sourceMappingURL=openrouter-images-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images-shared.d.ts","sourceRoot":"","sources":["../../src/api/openrouter-images-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAI9F,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAIzF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CASvE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAIpE;AAED,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,OAAO,CAAC,EAAE;IAAE,0BAA0B,CAAC,EAAE,OAAO,CAAA;CAAE,GAChD,KAAK,GAAG,SAAS,CAwCnB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { calculateCost } from "../models.js";
|
|
2
|
+
import { applyOpenRouterReportedCost } from "../utils/openrouter-cost.js";
|
|
3
|
+
import { isRecord } from "./json-request.js";
|
|
4
|
+
export function failImageResult(output, message) {
|
|
5
|
+
output.stopReason = "error";
|
|
6
|
+
output.errorMessage = message;
|
|
7
|
+
return output;
|
|
8
|
+
}
|
|
9
|
+
export function finiteNonNegative(value) {
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
11
|
+
}
|
|
12
|
+
export function parseOpenRouterError(value) {
|
|
13
|
+
if (!isRecord(value))
|
|
14
|
+
return undefined;
|
|
15
|
+
if (typeof value.message === "string" && value.message.trim().length > 0) {
|
|
16
|
+
return value.message.trim();
|
|
17
|
+
}
|
|
18
|
+
if ((typeof value.code === "string" || typeof value.code === "number") && String(value.code).trim().length > 0) {
|
|
19
|
+
return `Provider error (${String(value.code).trim()})`;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function parseDataUrl(value) {
|
|
24
|
+
const matches = value.match(/^data:([^;]+);base64,(.+)$/);
|
|
25
|
+
if (!matches)
|
|
26
|
+
return undefined;
|
|
27
|
+
return { type: "image", mimeType: matches[1], data: matches[2] };
|
|
28
|
+
}
|
|
29
|
+
export function parseOpenRouterImageUsage(value, model, options) {
|
|
30
|
+
if (!isRecord(value))
|
|
31
|
+
return undefined;
|
|
32
|
+
const promptTokens = finiteNonNegative(value.prompt_tokens);
|
|
33
|
+
const promptDetails = isRecord(value.prompt_tokens_details) ? value.prompt_tokens_details : undefined;
|
|
34
|
+
const reportedCachedTokens = finiteNonNegative(promptDetails?.cached_tokens);
|
|
35
|
+
const cacheWriteTokens = finiteNonNegative(promptDetails?.cache_write_tokens);
|
|
36
|
+
const cacheReadTokens = cacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;
|
|
37
|
+
const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
38
|
+
const output = finiteNonNegative(value.completion_tokens);
|
|
39
|
+
const completionDetails = isRecord(value.completion_tokens_details) ? value.completion_tokens_details : undefined;
|
|
40
|
+
const reportedImageTokens = completionDetails?.image_tokens;
|
|
41
|
+
const usage = {
|
|
42
|
+
input,
|
|
43
|
+
output,
|
|
44
|
+
cacheRead: cacheReadTokens,
|
|
45
|
+
cacheWrite: cacheWriteTokens,
|
|
46
|
+
// completion_tokens already includes reasoning_tokens.
|
|
47
|
+
reasoning: finiteNonNegative(completionDetails?.reasoning_tokens),
|
|
48
|
+
// Undefined, not 0, when OpenRouter omits the split: 0 would claim no image tokens.
|
|
49
|
+
...(typeof reportedImageTokens === "number" && Number.isFinite(reportedImageTokens) && reportedImageTokens >= 0
|
|
50
|
+
? { imageOutput: reportedImageTokens }
|
|
51
|
+
: {}),
|
|
52
|
+
totalTokens: Math.max(input + output + cacheReadTokens + cacheWriteTokens, finiteNonNegative(value.total_tokens)),
|
|
53
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
54
|
+
};
|
|
55
|
+
calculateCost(model, usage);
|
|
56
|
+
if (typeof value.is_byok === "boolean") {
|
|
57
|
+
applyOpenRouterReportedCost(usage, value);
|
|
58
|
+
}
|
|
59
|
+
else if (options?.allowDirectCostWithoutByok &&
|
|
60
|
+
typeof value.cost === "number" &&
|
|
61
|
+
Number.isFinite(value.cost) &&
|
|
62
|
+
value.cost >= 0) {
|
|
63
|
+
// POST /api/v1/images may report `usage.cost` directly without `is_byok`.
|
|
64
|
+
usage.cost.total = value.cost;
|
|
65
|
+
usage.cost.totalFromProvider = true;
|
|
66
|
+
}
|
|
67
|
+
return usage;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=openrouter-images-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images-shared.js","sourceRoot":"","sources":["../../src/api/openrouter-images-shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,O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Content, ImageModel, Usage } from \"../types.ts\";\nimport { applyOpenRouterReportedCost, type OpenRouterUsageAccounting } from \"../utils/openrouter-cost.ts\";\nimport { isRecord } from \"./json-request.ts\";\n\nexport function failImageResult(output: AssistantImages, message: string): AssistantImages {\n\toutput.stopReason = \"error\";\n\toutput.errorMessage = message;\n\treturn output;\n}\n\nexport function finiteNonNegative(value: unknown): number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0 ? value : 0;\n}\n\nexport function parseOpenRouterError(value: unknown): string | undefined {\n\tif (!isRecord(value)) return undefined;\n\tif (typeof value.message === \"string\" && value.message.trim().length > 0) {\n\t\treturn value.message.trim();\n\t}\n\tif ((typeof value.code === \"string\" || typeof value.code === \"number\") && String(value.code).trim().length > 0) {\n\t\treturn `Provider error (${String(value.code).trim()})`;\n\t}\n\treturn undefined;\n}\n\nexport function parseDataUrl(value: string): ImageContent | undefined {\n\tconst matches = value.match(/^data:([^;]+);base64,(.+)$/);\n\tif (!matches) return undefined;\n\treturn { type: \"image\", mimeType: matches[1], data: matches[2] };\n}\n\nexport function parseOpenRouterImageUsage(\n\tvalue: unknown,\n\tmodel: ImageModel<ImageApi>,\n\toptions?: { allowDirectCostWithoutByok?: boolean },\n): Usage | undefined {\n\tif (!isRecord(value)) return undefined;\n\tconst promptTokens = finiteNonNegative(value.prompt_tokens);\n\tconst promptDetails = isRecord(value.prompt_tokens_details) ? value.prompt_tokens_details : undefined;\n\tconst reportedCachedTokens = finiteNonNegative(promptDetails?.cached_tokens);\n\tconst cacheWriteTokens = finiteNonNegative(promptDetails?.cache_write_tokens);\n\tconst cacheReadTokens =\n\t\tcacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;\n\tconst input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);\n\tconst output = finiteNonNegative(value.completion_tokens);\n\tconst completionDetails = isRecord(value.completion_tokens_details) ? value.completion_tokens_details : undefined;\n\tconst reportedImageTokens = completionDetails?.image_tokens;\n\tconst usage: Usage = {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead: cacheReadTokens,\n\t\tcacheWrite: cacheWriteTokens,\n\t\t// completion_tokens already includes reasoning_tokens.\n\t\treasoning: finiteNonNegative(completionDetails?.reasoning_tokens),\n\t\t// Undefined, not 0, when OpenRouter omits the split: 0 would claim no image tokens.\n\t\t...(typeof reportedImageTokens === \"number\" && Number.isFinite(reportedImageTokens) && reportedImageTokens >= 0\n\t\t\t? { imageOutput: reportedImageTokens }\n\t\t\t: {}),\n\t\ttotalTokens: Math.max(input + output + cacheReadTokens + cacheWriteTokens, finiteNonNegative(value.total_tokens)),\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t};\n\tcalculateCost(model, usage);\n\tif (typeof value.is_byok === \"boolean\") {\n\t\tapplyOpenRouterReportedCost(usage, value as unknown as OpenRouterUsageAccounting);\n\t} else if (\n\t\toptions?.allowDirectCostWithoutByok &&\n\t\ttypeof value.cost === \"number\" &&\n\t\tNumber.isFinite(value.cost) &&\n\t\tvalue.cost >= 0\n\t) {\n\t\t// POST /api/v1/images may report `usage.cost` directly without `is_byok`.\n\t\tusage.cost.total = value.cost;\n\t\tusage.cost.totalFromProvider = true;\n\t}\n\treturn usage;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images.d.ts","sourceRoot":"","sources":["../../src/api/openrouter-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwD,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAWvH,yEAAyE;AACzE,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,aAAa,CA4BxD,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
2
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
3
|
+
import { isRecord, postJsonRequest } from "./json-request.js";
|
|
4
|
+
import { failImageResult, parseDataUrl, parseOpenRouterError, parseOpenRouterImageUsage, } from "./openrouter-images-shared.js";
|
|
5
|
+
/** Image generation over OpenRouter's `POST /api/v1/images` endpoint. */
|
|
6
|
+
export const generateImages = async (model, context, options) => {
|
|
7
|
+
const output = {
|
|
8
|
+
api: model.api,
|
|
9
|
+
provider: model.provider,
|
|
10
|
+
model: model.id,
|
|
11
|
+
output: [],
|
|
12
|
+
stopReason: "stop",
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL("images", `${model.baseUrl.replace(/\/+$/u, "")}/`);
|
|
17
|
+
const params = buildParams(model, context, options);
|
|
18
|
+
// Image generation is billed per completed image, so default to no automatic retries.
|
|
19
|
+
const body = await postJsonRequest("OpenRouter Images", url, model, params, {
|
|
20
|
+
...options,
|
|
21
|
+
maxRetries: options?.maxRetries ?? 0,
|
|
22
|
+
});
|
|
23
|
+
return parseResponse(body, model, output);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
27
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
28
|
+
return output;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function buildParams(model, context, options) {
|
|
32
|
+
const promptParts = [];
|
|
33
|
+
const inputReferences = [];
|
|
34
|
+
for (const item of context.input) {
|
|
35
|
+
if (item.type === "text") {
|
|
36
|
+
promptParts.push(sanitizeSurrogates(item.text));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
inputReferences.push({
|
|
40
|
+
type: "image_url",
|
|
41
|
+
image_url: { url: `data:${item.mimeType};base64,${item.data}` },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const prompt = promptParts.join("\n\n").trim();
|
|
46
|
+
if (!prompt) {
|
|
47
|
+
throw new Error("Image generation request requires a text prompt");
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
model: model.id,
|
|
51
|
+
prompt,
|
|
52
|
+
response_format: "b64_json",
|
|
53
|
+
...(options?.aspectRatio ? { aspect_ratio: options.aspectRatio } : {}),
|
|
54
|
+
...(options?.size ? { resolution: options.size } : {}),
|
|
55
|
+
...(inputReferences.length > 0 ? { input_references: inputReferences } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function parseResponse(body, model, output) {
|
|
59
|
+
if (!isRecord(body))
|
|
60
|
+
return failImageResult(output, "Provider returned an unexpected response");
|
|
61
|
+
const usage = parseOpenRouterImageUsage(body.usage, model, { allowDirectCostWithoutByok: true });
|
|
62
|
+
if (usage)
|
|
63
|
+
output.usage = usage;
|
|
64
|
+
const responseError = parseOpenRouterError(body.error);
|
|
65
|
+
if (responseError)
|
|
66
|
+
return failImageResult(output, responseError);
|
|
67
|
+
if (!Array.isArray(body.data) || body.data.length === 0) {
|
|
68
|
+
return failImageResult(output, "Provider returned no images");
|
|
69
|
+
}
|
|
70
|
+
const images = [];
|
|
71
|
+
for (const item of body.data) {
|
|
72
|
+
if (!isRecord(item) || typeof item.b64_json !== "string" || item.b64_json.length === 0)
|
|
73
|
+
continue;
|
|
74
|
+
const dataUrl = parseDataUrl(item.b64_json);
|
|
75
|
+
if (dataUrl) {
|
|
76
|
+
images.push(dataUrl);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// OpenRouter omits `media_type` when it cannot determine the format; guessing one would mislabel the image.
|
|
80
|
+
const mimeType = typeof item.media_type === "string" ? item.media_type.trim() : "";
|
|
81
|
+
if (!mimeType)
|
|
82
|
+
return failImageResult(output, "Provider returned an image without a media type");
|
|
83
|
+
images.push({ type: "image", mimeType, data: item.b64_json });
|
|
84
|
+
}
|
|
85
|
+
if (images.length === 0) {
|
|
86
|
+
return failImageResult(output, "Provider returned no inline image data");
|
|
87
|
+
}
|
|
88
|
+
output.output = images;
|
|
89
|
+
return output;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=openrouter-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images.js","sourceRoot":"","sources":["../../src/api/openrouter-images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EACN,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,yBAAyB,GACzB,MAAM,+BAA+B,CAAC;AAEvC,yEAAyE;AACzE,MAAM,CAAC,MAAM,cAAc,GAAkC,KAAK,EACjE,KAA2B,EAC3B,OAAsB,EACtB,OAAuB,EACtB,EAAE;IACH,MAAM,MAAM,GAAoB;QAC/B,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,EAAE;QACf,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CAAC;IAEF,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,sFAAsF;QACtF,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,mBAAmB,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE;YAC3E,GAAG,OAAO;YACV,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,CAAC;SACpC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC,IAAI,EAAE,KAAK,EAA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AAO,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,SAAS;QACV,CAAC;QACD,4GAA4G;QAC5G,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,IAAI,CAAC,QAAQ;YAAE,OAAO,eAAe,CAAC,MAAM,EAAE,iDAAiD,CAAC,CAAC;QACjG,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,eAAe,CAAC,MAAM,EAAE,wCAAwC,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IAEvB,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { AssistantImages, ImageApi, ImageModel, ImagesContext, ImagesFunction, ImagesOptions } from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { isRecord, postJsonRequest } from \"./json-request.ts\";\nimport {\n\tfailImageResult,\n\tparseDataUrl,\n\tparseOpenRouterError,\n\tparseOpenRouterImageUsage,\n} from \"./openrouter-images-shared.ts\";\n\n/** Image generation over OpenRouter's `POST /api/v1/images` endpoint. */\nexport const generateImages: ImagesFunction<ImagesOptions> = async (\n\tmodel: ImageModel<ImageApi>,\n\tcontext: ImagesContext,\n\toptions?: ImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tconst url = new URL(\"images\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`);\n\t\tconst params = buildParams(model, context, options);\n\t\t// Image generation is billed per completed image, so default to no automatic retries.\n\t\tconst body = await postJsonRequest(\"OpenRouter Images\", url, model, params, {\n\t\t\t...options,\n\t\t\tmaxRetries: options?.maxRetries ?? 0,\n\t\t});\n\t\treturn parseResponse(body, model, output);\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\treturn output;\n\t}\n};\n\nfunction buildParams(model: ImageModel<ImageApi>, context: ImagesContext, options?: ImagesOptions) {\n\tconst promptParts: string[] = [];\n\tconst inputReferences: Array<{ type: \"image_url\"; image_url: { url: string } }> = [];\n\tfor (const item of context.input) {\n\t\tif (item.type === \"text\") {\n\t\t\tpromptParts.push(sanitizeSurrogates(item.text));\n\t\t} else {\n\t\t\tinputReferences.push({\n\t\t\t\ttype: \"image_url\",\n\t\t\t\timage_url: { url: `data:${item.mimeType};base64,${item.data}` },\n\t\t\t});\n\t\t}\n\t}\n\tconst prompt = promptParts.join(\"\\n\\n\").trim();\n\tif (!prompt) {\n\t\tthrow new Error(\"Image generation request requires a text prompt\");\n\t}\n\treturn {\n\t\tmodel: model.id,\n\t\tprompt,\n\t\tresponse_format: \"b64_json\" as const,\n\t\t...(options?.aspectRatio ? { aspect_ratio: options.aspectRatio } : {}),\n\t\t...(options?.size ? { resolution: options.size } : {}),\n\t\t...(inputReferences.length > 0 ? { input_references: inputReferences } : {}),\n\t};\n}\n\nfunction parseResponse(body: unknown, model: ImageModel<ImageApi>, output: AssistantImages): AssistantImages {\n\tif (!isRecord(body)) return failImageResult(output, \"Provider returned an unexpected response\");\n\n\tconst usage = parseOpenRouterImageUsage(body.usage, model, { allowDirectCostWithoutByok: true });\n\tif (usage) output.usage = usage;\n\n\tconst responseError = parseOpenRouterError(body.error);\n\tif (responseError) return failImageResult(output, responseError);\n\n\tif (!Array.isArray(body.data) || body.data.length === 0) {\n\t\treturn failImageResult(output, \"Provider returned no images\");\n\t}\n\n\tconst images: AssistantImages[\"output\"] = [];\n\tfor (const item of body.data) {\n\t\tif (!isRecord(item) || typeof item.b64_json !== \"string\" || item.b64_json.length === 0) continue;\n\t\tconst dataUrl = parseDataUrl(item.b64_json);\n\t\tif (dataUrl) {\n\t\t\timages.push(dataUrl);\n\t\t\tcontinue;\n\t\t}\n\t\t// OpenRouter omits `media_type` when it cannot determine the format; guessing one would mislabel the image.\n\t\tconst mimeType = typeof item.media_type === \"string\" ? item.media_type.trim() : \"\";\n\t\tif (!mimeType) return failImageResult(output, \"Provider returned an image without a media type\");\n\t\timages.push({ type: \"image\", mimeType, data: item.b64_json });\n\t}\n\n\tif (images.length === 0) {\n\t\treturn failImageResult(output, \"Provider returned no inline image data\");\n\t}\n\toutput.output = images;\n\n\treturn output;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images.lazy.d.ts","sourceRoot":"","sources":["../../src/api/openrouter-images.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,mBAAmB,QAAO,cAGrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter-images.lazy.js","sourceRoot":"","sources":["../../src/api/openrouter-images.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAmB,EAAE,CAAC,CAAC;IACzD,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CACjD,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CACjF,CAAC,CAAC","sourcesContent":["import type { ProviderImages } from \"../types.ts\";\n\nexport const openrouterImagesApi = (): ProviderImages => ({\n\tgenerateImages: async (model, context, options) =>\n\t\t(await import(\"./openrouter-images.ts\")).generateImages(model, context, options),\n});\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ClassifierAnswer, ClassifierContext, ClassifierFunction, ClassifierOptions, Usage } from "../types.ts";
|
|
2
|
+
export interface PiDecisionOptions extends ClassifierOptions {
|
|
3
|
+
/** Optional session identifier for gateway correlation/analytics. */
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Wire request body sent by `pi-decision` to `POST <baseUrl>/decision`. */
|
|
7
|
+
export type PiDecisionRequest = {
|
|
8
|
+
model: string;
|
|
9
|
+
context: ClassifierContext;
|
|
10
|
+
options?: {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** Wire response body returned by a `pi-decision` backend on `200 OK`. */
|
|
15
|
+
export type PiDecisionResponse = {
|
|
16
|
+
answers: Record<string, ClassifierAnswer>;
|
|
17
|
+
usage?: Usage;
|
|
18
|
+
responseId?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Classification through pi's canonical `POST <baseUrl>/decision` protocol. */
|
|
21
|
+
export declare const classify: ClassifierFunction<PiDecisionOptions>;
|
|
22
|
+
//# sourceMappingURL=pi-decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-decision.d.ts","sourceRoot":"","sources":["../../src/api/pi-decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAGjB,KAAK,EACL,MAAM,aAAa,CAAC;AAiBrB,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC3D,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,CAAC,EAAE;QACT,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACF,CAAC;AAEF,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAiEF,gFAAgF;AAChF,eAAO,MAAM,QAAQ,EAAE,kBAAkB,CAAC,iBAAiB,CAuC1D,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
2
|
+
import { isRecord, postClassifierRequest, requiredNumber } from "./classifier-shared.js";
|
|
3
|
+
import { parsePiUsage } from "./json-request.js";
|
|
4
|
+
/**
|
|
5
|
+
* pi-decision API implementation.
|
|
6
|
+
*
|
|
7
|
+
* Sends pi's own decision protocol directly to a backend: the request is a
|
|
8
|
+
* single POST of `{ model, context, options }` to `<baseUrl>/decision`, and
|
|
9
|
+
* a `200 OK` response is a completed `{ answers, usage?, responseId? }` JSON object. Errors
|
|
10
|
+
* use non-2xx HTTP statuses with the `{ error: { message, code?, details? } }`
|
|
11
|
+
* envelope, matching `pi-messages`.
|
|
12
|
+
*/
|
|
13
|
+
const LABEL = "Pi Decision";
|
|
14
|
+
function requiredUnitInterval(value, field) {
|
|
15
|
+
const num = requiredNumber(LABEL, value, field);
|
|
16
|
+
if (num < 0 || num > 1) {
|
|
17
|
+
throw new Error(`${LABEL} returned out-of-range ${field}: ${num}`);
|
|
18
|
+
}
|
|
19
|
+
return num;
|
|
20
|
+
}
|
|
21
|
+
function parseProbabilities(value, id, criteria) {
|
|
22
|
+
if (!isRecord(value))
|
|
23
|
+
throw new Error(`${LABEL} returned invalid probabilities for ${id}`);
|
|
24
|
+
return Object.fromEntries(Object.entries(value).map(([choice, prob]) => {
|
|
25
|
+
if (!Object.hasOwn(criteria, choice)) {
|
|
26
|
+
throw new Error(`${LABEL} returned unknown choice "${choice}" in probabilities for ${id}`);
|
|
27
|
+
}
|
|
28
|
+
return [choice, requiredUnitInterval(prob, `probability for ${id}.${choice}`)];
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function parseAnswer(id, question, answer) {
|
|
32
|
+
if (!isRecord(answer))
|
|
33
|
+
throw new Error(`${LABEL} returned an invalid answer for ${id}`);
|
|
34
|
+
if (question.type === "choice") {
|
|
35
|
+
if (answer.type !== "choice" || typeof answer.choice !== "string") {
|
|
36
|
+
throw new Error(`${LABEL} did not return a choice answer for ${id}`);
|
|
37
|
+
}
|
|
38
|
+
if (!Object.hasOwn(question.criteria, answer.choice)) {
|
|
39
|
+
throw new Error(`${LABEL} returned unknown choice "${answer.choice}" for ${id}`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
type: "choice",
|
|
43
|
+
choice: answer.choice,
|
|
44
|
+
probabilities: parseProbabilities(answer.probabilities, id, question.criteria),
|
|
45
|
+
confidence: requiredUnitInterval(answer.confidence, `confidence for ${id}`),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (question.type === "score") {
|
|
49
|
+
if (answer.type !== "score")
|
|
50
|
+
throw new Error(`${LABEL} did not return a score answer for ${id}`);
|
|
51
|
+
const score = requiredNumber(LABEL, answer.score, `score for ${id}`);
|
|
52
|
+
const maxScore = Math.max(0, question.criteria.length - 1);
|
|
53
|
+
if (score < 0 || score > maxScore) {
|
|
54
|
+
throw new Error(`${LABEL} returned out-of-range score for ${id}: ${score}`);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
type: "score",
|
|
58
|
+
score,
|
|
59
|
+
confidence: requiredUnitInterval(answer.confidence, `confidence for ${id}`),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (answer.type !== "bool")
|
|
63
|
+
throw new Error(`${LABEL} did not return a bool answer for ${id}`);
|
|
64
|
+
return { type: "bool", probability: requiredUnitInterval(answer.probability, `probability for ${id}`) };
|
|
65
|
+
}
|
|
66
|
+
function parseAnswers(value, context) {
|
|
67
|
+
if (!isRecord(value))
|
|
68
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
69
|
+
return Object.fromEntries(Object.entries(context.questions).map(([id, question]) => {
|
|
70
|
+
if (!Object.hasOwn(value, id))
|
|
71
|
+
throw new Error(`${LABEL} did not return an answer for ${id}`);
|
|
72
|
+
return [id, parseAnswer(id, question, value[id])];
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/** Classification through pi's canonical `POST <baseUrl>/decision` protocol. */
|
|
76
|
+
export const classify = async (model, context, options) => {
|
|
77
|
+
const output = {
|
|
78
|
+
api: model.api,
|
|
79
|
+
provider: model.provider,
|
|
80
|
+
model: model.id,
|
|
81
|
+
answers: {},
|
|
82
|
+
stopReason: "stop",
|
|
83
|
+
timestamp: Date.now(),
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
if (model.api !== "pi-decision")
|
|
87
|
+
throw new Error(`Unsupported classifier API: ${model.api}`);
|
|
88
|
+
const images = context.images ?? [];
|
|
89
|
+
if (images.length > 0 && !model.input.includes("image")) {
|
|
90
|
+
throw new Error(`${LABEL} model ${model.id} does not support image input`);
|
|
91
|
+
}
|
|
92
|
+
const url = new URL("decision", `${model.baseUrl.replace(/\/+$/u, "")}/`);
|
|
93
|
+
const requestBody = {
|
|
94
|
+
model: model.id,
|
|
95
|
+
context: {
|
|
96
|
+
state: context.state,
|
|
97
|
+
...(images.length > 0 ? { images } : {}),
|
|
98
|
+
questions: context.questions,
|
|
99
|
+
},
|
|
100
|
+
...(options?.sessionId !== undefined ? { options: { sessionId: options.sessionId } } : {}),
|
|
101
|
+
};
|
|
102
|
+
const body = await postClassifierRequest(LABEL, url, model, requestBody, options);
|
|
103
|
+
if (!isRecord(body))
|
|
104
|
+
throw new Error(`${LABEL} returned an unexpected response`);
|
|
105
|
+
if (typeof body.responseId === "string" && body.responseId)
|
|
106
|
+
output.responseId = body.responseId;
|
|
107
|
+
const usage = parsePiUsage(body.usage, model);
|
|
108
|
+
if (usage)
|
|
109
|
+
output.usage = usage;
|
|
110
|
+
output.answers = parseAnswers(body.answers, context);
|
|
111
|
+
return output;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
output.answers = {};
|
|
115
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
116
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error), `${LABEL} error`);
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=pi-decision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-decision.js","sourceRoot":"","sources":["../../src/api/pi-decision.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;GAQG;AAEH,MAAM,KAAK,GAAG,aAAa,CAAC;AAuB5B,SAAS,oBAAoB,CAAC,KAAc,EAAE,KAAa;IAC1D,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAChD,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,0BAA0B,KAAK,KAAK,GAAG,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc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,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;QACpB,MAAM,CAAC,UAAU,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,QAAQ,CAAC,CAAC;QAC3F,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC,CAAC","sourcesContent":["import type {\n\tClassifierAnswer,\n\tClassifierContext,\n\tClassifierFunction,\n\tClassifierOptions,\n\tClassifierQuestion,\n\tClassifierResult,\n\tUsage,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { isRecord, postClassifierRequest, requiredNumber } from \"./classifier-shared.ts\";\nimport { parsePiUsage } from \"./json-request.ts\";\n\n/**\n * pi-decision API implementation.\n *\n * Sends pi's own decision protocol directly to a backend: the request is a\n * single POST of `{ model, context, options }` to `<baseUrl>/decision`, and\n * a `200 OK` response is a completed `{ answers, usage?, responseId? }` JSON object. Errors\n * use non-2xx HTTP statuses with the `{ error: { message, code?, details? } }`\n * envelope, matching `pi-messages`.\n */\n\nconst LABEL = \"Pi Decision\";\n\nexport interface PiDecisionOptions extends ClassifierOptions {\n\t/** Optional session identifier for gateway correlation/analytics. */\n\tsessionId?: string;\n}\n\n/** Wire request body sent by `pi-decision` to `POST <baseUrl>/decision`. */\nexport type PiDecisionRequest = {\n\tmodel: string;\n\tcontext: ClassifierContext;\n\toptions?: {\n\t\tsessionId?: string;\n\t};\n};\n\n/** Wire response body returned by a `pi-decision` backend on `200 OK`. */\nexport type PiDecisionResponse = {\n\tanswers: Record<string, ClassifierAnswer>;\n\tusage?: Usage;\n\tresponseId?: string;\n};\n\nfunction requiredUnitInterval(value: unknown, field: string): number {\n\tconst num = requiredNumber(LABEL, value, field);\n\tif (num < 0 || num > 1) {\n\t\tthrow new Error(`${LABEL} returned out-of-range ${field}: ${num}`);\n\t}\n\treturn num;\n}\n\nfunction parseProbabilities(value: unknown, id: string, criteria: Record<string, string>): Record<string, number> {\n\tif (!isRecord(value)) throw new Error(`${LABEL} returned invalid probabilities for ${id}`);\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([choice, prob]) => {\n\t\t\tif (!Object.hasOwn(criteria, choice)) {\n\t\t\t\tthrow new Error(`${LABEL} returned unknown choice \"${choice}\" in probabilities for ${id}`);\n\t\t\t}\n\t\t\treturn [choice, requiredUnitInterval(prob, `probability for ${id}.${choice}`)];\n\t\t}),\n\t);\n}\n\nfunction parseAnswer(id: string, question: ClassifierQuestion, answer: unknown): ClassifierAnswer {\n\tif (!isRecord(answer)) throw new Error(`${LABEL} returned an invalid answer for ${id}`);\n\tif (question.type === \"choice\") {\n\t\tif (answer.type !== \"choice\" || typeof answer.choice !== \"string\") {\n\t\t\tthrow new Error(`${LABEL} did not return a choice answer for ${id}`);\n\t\t}\n\t\tif (!Object.hasOwn(question.criteria, answer.choice)) {\n\t\t\tthrow new Error(`${LABEL} returned unknown choice \"${answer.choice}\" for ${id}`);\n\t\t}\n\t\treturn {\n\t\t\ttype: \"choice\",\n\t\t\tchoice: answer.choice,\n\t\t\tprobabilities: parseProbabilities(answer.probabilities, id, question.criteria),\n\t\t\tconfidence: requiredUnitInterval(answer.confidence, `confidence for ${id}`),\n\t\t};\n\t}\n\tif (question.type === \"score\") {\n\t\tif (answer.type !== \"score\") throw new Error(`${LABEL} did not return a score answer for ${id}`);\n\t\tconst score = requiredNumber(LABEL, answer.score, `score for ${id}`);\n\t\tconst maxScore = Math.max(0, question.criteria.length - 1);\n\t\tif (score < 0 || score > maxScore) {\n\t\t\tthrow new Error(`${LABEL} returned out-of-range score for ${id}: ${score}`);\n\t\t}\n\t\treturn {\n\t\t\ttype: \"score\",\n\t\t\tscore,\n\t\t\tconfidence: requiredUnitInterval(answer.confidence, `confidence for ${id}`),\n\t\t};\n\t}\n\tif (answer.type !== \"bool\") throw new Error(`${LABEL} did not return a bool answer for ${id}`);\n\treturn { type: \"bool\", probability: requiredUnitInterval(answer.probability, `probability for ${id}`) };\n}\n\nfunction parseAnswers(value: unknown, context: ClassifierContext): Record<string, ClassifierAnswer> {\n\tif (!isRecord(value)) throw new Error(`${LABEL} returned an unexpected response`);\n\treturn Object.fromEntries(\n\t\tObject.entries(context.questions).map(([id, question]) => {\n\t\t\tif (!Object.hasOwn(value, id)) throw new Error(`${LABEL} did not return an answer for ${id}`);\n\t\t\treturn [id, parseAnswer(id, question, value[id])];\n\t\t}),\n\t);\n}\n\n/** Classification through pi's canonical `POST <baseUrl>/decision` protocol. */\nexport const classify: ClassifierFunction<PiDecisionOptions> = async (model, context, options) => {\n\tconst output: ClassifierResult = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tanswers: {},\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tif (model.api !== \"pi-decision\") throw new Error(`Unsupported classifier API: ${model.api}`);\n\t\tconst images = context.images ?? [];\n\t\tif (images.length > 0 && !model.input.includes(\"image\")) {\n\t\t\tthrow new Error(`${LABEL} model ${model.id} does not support image input`);\n\t\t}\n\t\tconst url = new URL(\"decision\", `${model.baseUrl.replace(/\\/+$/u, \"\")}/`);\n\t\tconst requestBody: PiDecisionRequest = {\n\t\t\tmodel: model.id,\n\t\t\tcontext: {\n\t\t\t\tstate: context.state,\n\t\t\t\t...(images.length > 0 ? { images } : {}),\n\t\t\t\tquestions: context.questions,\n\t\t\t},\n\t\t\t...(options?.sessionId !== undefined ? { options: { sessionId: options.sessionId } } : {}),\n\t\t};\n\t\tconst body = await postClassifierRequest(LABEL, url, model, requestBody, options);\n\t\tif (!isRecord(body)) throw new Error(`${LABEL} returned an unexpected response`);\n\t\tif (typeof body.responseId === \"string\" && body.responseId) output.responseId = body.responseId;\n\t\tconst usage = parsePiUsage(body.usage, model);\n\t\tif (usage) output.usage = usage;\n\t\toutput.answers = parseAnswers(body.answers, context);\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.answers = {};\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error), `${LABEL} error`);\n\t\treturn output;\n\t}\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-decision.lazy.d.ts","sourceRoot":"","sources":["../../src/api/pi-decision.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,eAAO,MAAM,aAAa,QAAO,kBAE/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-decision.lazy.js","sourceRoot":"","sources":["../../src/api/pi-decision.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,GAAuB,EAAE,CAAC,CAAC;IACvD,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;CACjH,CAAC,CAAC","sourcesContent":["import type { ProviderClassifier } from \"../types.ts\";\n\nexport const piDecisionApi = (): ProviderClassifier => ({\n\tclassify: async (model, context, options) => (await import(\"./pi-decision.ts\")).classify(model, context, options),\n});\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ImagesContext, ImagesFunction, ImagesOptions, ImagesOutputContent, Usage } from "../types.ts";
|
|
2
|
+
export interface PiImageOptions extends ImagesOptions {
|
|
3
|
+
/** Optional session identifier for gateway correlation/analytics. */
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Wire request body sent by `pi-image` to `POST <baseUrl>/image`. */
|
|
7
|
+
export type PiImageRequest = {
|
|
8
|
+
model: string;
|
|
9
|
+
context: ImagesContext;
|
|
10
|
+
options?: {
|
|
11
|
+
aspectRatio?: string;
|
|
12
|
+
size?: string;
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** Wire response body returned by a `pi-image` backend on `200 OK`. */
|
|
18
|
+
export type PiImageResponse = {
|
|
19
|
+
output: ImagesOutputContent[];
|
|
20
|
+
usage?: Usage;
|
|
21
|
+
responseId?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Image generation through pi's canonical `POST <baseUrl>/image` protocol. */
|
|
24
|
+
export declare const generateImages: ImagesFunction<PiImageOptions>;
|
|
25
|
+
//# sourceMappingURL=pi-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-image.d.ts","sourceRoot":"","sources":["../../src/api/pi-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,aAAa,EACb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,MAAM,aAAa,CAAC;AAiBrB,MAAM,WAAW,cAAe,SAAQ,aAAa;IACpD,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,sEAAsE;AACtE,MAAM,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE;QACT,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;CACF,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAsBF,+EAA+E;AAC/E,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,cAAc,CAyCzD,CAAC"}
|