@gajae-code/ai 0.1.1
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/CHANGELOG.md +2644 -0
- package/README.md +1181 -0
- package/dist/types/api-registry.d.ts +30 -0
- package/dist/types/auth-broker/client.d.ts +66 -0
- package/dist/types/auth-broker/index.d.ts +5 -0
- package/dist/types/auth-broker/refresher.d.ts +25 -0
- package/dist/types/auth-broker/remote-store.d.ts +96 -0
- package/dist/types/auth-broker/server.d.ts +32 -0
- package/dist/types/auth-broker/types.d.ts +105 -0
- package/dist/types/auth-broker/wire-schemas.d.ts +412 -0
- package/dist/types/auth-gateway/http.d.ts +39 -0
- package/dist/types/auth-gateway/index.d.ts +3 -0
- package/dist/types/auth-gateway/server.d.ts +17 -0
- package/dist/types/auth-gateway/types.d.ts +115 -0
- package/dist/types/auth-storage.d.ts +641 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/index.d.ts +49 -0
- package/dist/types/model-cache.d.ts +17 -0
- package/dist/types/model-manager.d.ts +62 -0
- package/dist/types/model-thinking.d.ts +71 -0
- package/dist/types/models.d.ts +12 -0
- package/dist/types/provider-details.d.ts +24 -0
- package/dist/types/provider-models/bundled-references.d.ts +4 -0
- package/dist/types/provider-models/descriptors.d.ts +48 -0
- package/dist/types/provider-models/google.d.ts +20 -0
- package/dist/types/provider-models/index.d.ts +5 -0
- package/dist/types/provider-models/ollama.d.ts +7 -0
- package/dist/types/provider-models/openai-compat.d.ts +237 -0
- package/dist/types/provider-models/special.d.ts +16 -0
- package/dist/types/providers/amazon-bedrock.d.ts +36 -0
- package/dist/types/providers/anthropic-messages-server-schema.d.ts +450 -0
- package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
- package/dist/types/providers/anthropic.d.ts +188 -0
- package/dist/types/providers/aws-credentials.d.ts +43 -0
- package/dist/types/providers/aws-eventstream.d.ts +38 -0
- package/dist/types/providers/aws-sigv4.d.ts +55 -0
- package/dist/types/providers/azure-openai-responses.d.ts +15 -0
- package/dist/types/providers/cursor/gen/agent_pb.d.ts +13022 -0
- package/dist/types/providers/cursor.d.ts +42 -0
- package/dist/types/providers/error-message.d.ts +27 -0
- package/dist/types/providers/github-copilot-headers.d.ts +40 -0
- package/dist/types/providers/gitlab-duo.d.ts +27 -0
- package/dist/types/providers/google-auth.d.ts +24 -0
- package/dist/types/providers/google-gemini-cli.d.ts +72 -0
- package/dist/types/providers/google-gemini-headers.d.ts +18 -0
- package/dist/types/providers/google-shared.d.ts +163 -0
- package/dist/types/providers/google-types.d.ts +138 -0
- package/dist/types/providers/google-vertex.d.ts +7 -0
- package/dist/types/providers/google.d.ts +4 -0
- package/dist/types/providers/grammar.d.ts +1 -0
- package/dist/types/providers/kimi.d.ts +27 -0
- package/dist/types/providers/mock.d.ts +175 -0
- package/dist/types/providers/ollama.d.ts +6 -0
- package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
- package/dist/types/providers/openai-chat-server-schema.d.ts +814 -0
- package/dist/types/providers/openai-chat-server.d.ts +16 -0
- package/dist/types/providers/openai-codex/constants.d.ts +26 -0
- package/dist/types/providers/openai-codex/request-transformer.d.ts +49 -0
- package/dist/types/providers/openai-codex/response-handler.d.ts +17 -0
- package/dist/types/providers/openai-codex-responses.d.ts +67 -0
- package/dist/types/providers/openai-completions-compat.d.ts +25 -0
- package/dist/types/providers/openai-completions.d.ts +33 -0
- package/dist/types/providers/openai-responses-server-schema.d.ts +392 -0
- package/dist/types/providers/openai-responses-server.d.ts +17 -0
- package/dist/types/providers/openai-responses-shared.d.ts +89 -0
- package/dist/types/providers/openai-responses.d.ts +32 -0
- package/dist/types/providers/pi-native-client.d.ts +13 -0
- package/dist/types/providers/pi-native-server.d.ts +68 -0
- package/dist/types/providers/register-builtins.d.ts +31 -0
- package/dist/types/providers/synthetic.d.ts +26 -0
- package/dist/types/providers/transform-messages.d.ts +12 -0
- package/dist/types/providers/vision-guard.d.ts +8 -0
- package/dist/types/rate-limit-utils.d.ts +19 -0
- package/dist/types/stream.d.ts +24 -0
- package/dist/types/types.d.ts +746 -0
- package/dist/types/usage/claude.d.ts +3 -0
- package/dist/types/usage/gemini.d.ts +2 -0
- package/dist/types/usage/github-copilot.d.ts +7 -0
- package/dist/types/usage/google-antigravity.d.ts +2 -0
- package/dist/types/usage/kimi.d.ts +2 -0
- package/dist/types/usage/minimax-code.d.ts +2 -0
- package/dist/types/usage/openai-codex.d.ts +3 -0
- package/dist/types/usage/shared.d.ts +1 -0
- package/dist/types/usage/zai.d.ts +2 -0
- package/dist/types/usage.d.ts +258 -0
- package/dist/types/utils/abort.d.ts +19 -0
- package/dist/types/utils/anthropic-auth.d.ts +31 -0
- package/dist/types/utils/discovery/antigravity.d.ts +61 -0
- package/dist/types/utils/discovery/codex.d.ts +38 -0
- package/dist/types/utils/discovery/cursor.d.ts +23 -0
- package/dist/types/utils/discovery/gemini.d.ts +25 -0
- package/dist/types/utils/discovery/index.d.ts +4 -0
- package/dist/types/utils/discovery/openai-compatible.d.ts +72 -0
- package/dist/types/utils/event-stream.d.ts +28 -0
- package/dist/types/utils/fireworks-model-id.d.ts +10 -0
- package/dist/types/utils/foundry.d.ts +1 -0
- package/dist/types/utils/h2-fetch.d.ts +22 -0
- package/dist/types/utils/http-inspector.d.ts +31 -0
- package/dist/types/utils/idle-iterator.d.ts +67 -0
- package/dist/types/utils/json-parse.d.ts +10 -0
- package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +18 -0
- package/dist/types/utils/oauth/anthropic.d.ts +22 -0
- package/dist/types/utils/oauth/api-key-login.d.ts +35 -0
- package/dist/types/utils/oauth/api-key-validation.d.ts +27 -0
- package/dist/types/utils/oauth/callback-server.d.ts +57 -0
- package/dist/types/utils/oauth/cerebras.d.ts +1 -0
- package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +18 -0
- package/dist/types/utils/oauth/cursor.d.ts +15 -0
- package/dist/types/utils/oauth/deepseek.d.ts +10 -0
- package/dist/types/utils/oauth/firepass.d.ts +1 -0
- package/dist/types/utils/oauth/fireworks.d.ts +1 -0
- package/dist/types/utils/oauth/github-copilot.d.ts +38 -0
- package/dist/types/utils/oauth/gitlab-duo.d.ts +3 -0
- package/dist/types/utils/oauth/google-antigravity.d.ts +11 -0
- package/dist/types/utils/oauth/google-gemini-cli.d.ts +10 -0
- package/dist/types/utils/oauth/google-oauth-shared.d.ts +28 -0
- package/dist/types/utils/oauth/huggingface.d.ts +19 -0
- package/dist/types/utils/oauth/index.d.ts +38 -0
- package/dist/types/utils/oauth/kagi.d.ts +17 -0
- package/dist/types/utils/oauth/kilo.d.ts +5 -0
- package/dist/types/utils/oauth/kimi.d.ts +21 -0
- package/dist/types/utils/oauth/litellm.d.ts +18 -0
- package/dist/types/utils/oauth/lm-studio.d.ts +17 -0
- package/dist/types/utils/oauth/minimax-code.d.ts +28 -0
- package/dist/types/utils/oauth/moonshot.d.ts +1 -0
- package/dist/types/utils/oauth/nanogpt.d.ts +1 -0
- package/dist/types/utils/oauth/nvidia.d.ts +18 -0
- package/dist/types/utils/oauth/ollama-cloud.d.ts +2 -0
- package/dist/types/utils/oauth/ollama.d.ts +18 -0
- package/dist/types/utils/oauth/openai-codex.d.ts +21 -0
- package/dist/types/utils/oauth/opencode.d.ts +18 -0
- package/dist/types/utils/oauth/parallel.d.ts +17 -0
- package/dist/types/utils/oauth/perplexity.d.ts +9 -0
- package/dist/types/utils/oauth/pkce.d.ts +8 -0
- package/dist/types/utils/oauth/qianfan.d.ts +17 -0
- package/dist/types/utils/oauth/qwen-portal.d.ts +19 -0
- package/dist/types/utils/oauth/synthetic.d.ts +1 -0
- package/dist/types/utils/oauth/tavily.d.ts +17 -0
- package/dist/types/utils/oauth/together.d.ts +1 -0
- package/dist/types/utils/oauth/types.d.ts +44 -0
- package/dist/types/utils/oauth/venice.d.ts +18 -0
- package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +18 -0
- package/dist/types/utils/oauth/vllm.d.ts +16 -0
- package/dist/types/utils/oauth/xiaomi.d.ts +19 -0
- package/dist/types/utils/oauth/zai.d.ts +18 -0
- package/dist/types/utils/oauth/zenmux.d.ts +1 -0
- package/dist/types/utils/overflow.d.ts +54 -0
- package/dist/types/utils/parse-bind.d.ts +23 -0
- package/dist/types/utils/provider-response.d.ts +3 -0
- package/dist/types/utils/retry-after.d.ts +3 -0
- package/dist/types/utils/retry.d.ts +26 -0
- package/dist/types/utils/schema/adapt.d.ts +24 -0
- package/dist/types/utils/schema/compatibility.d.ts +30 -0
- package/dist/types/utils/schema/dereference.d.ts +11 -0
- package/dist/types/utils/schema/draft.d.ts +10 -0
- package/dist/types/utils/schema/equality.d.ts +4 -0
- package/dist/types/utils/schema/fields.d.ts +49 -0
- package/dist/types/utils/schema/index.d.ts +13 -0
- package/dist/types/utils/schema/json-schema-validator.d.ts +12 -0
- package/dist/types/utils/schema/meta-validator.d.ts +2 -0
- package/dist/types/utils/schema/normalize.d.ts +93 -0
- package/dist/types/utils/schema/spill.d.ts +8 -0
- package/dist/types/utils/schema/stamps.d.ts +25 -0
- package/dist/types/utils/schema/types.d.ts +4 -0
- package/dist/types/utils/schema/wire.d.ts +54 -0
- package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
- package/dist/types/utils/sse-debug.d.ts +10 -0
- package/dist/types/utils/tool-call-healing.d.ts +71 -0
- package/dist/types/utils/tool-choice.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +17 -0
- package/dist/types/utils.d.ts +28 -0
- package/package.json +146 -0
- package/src/api-registry.ts +96 -0
- package/src/auth-broker/client.ts +358 -0
- package/src/auth-broker/index.ts +5 -0
- package/src/auth-broker/refresher.ts +127 -0
- package/src/auth-broker/remote-store.ts +623 -0
- package/src/auth-broker/server.ts +644 -0
- package/src/auth-broker/types.ts +127 -0
- package/src/auth-broker/wire-schemas.ts +200 -0
- package/src/auth-gateway/http.ts +194 -0
- package/src/auth-gateway/index.ts +3 -0
- package/src/auth-gateway/server.ts +717 -0
- package/src/auth-gateway/types.ts +134 -0
- package/src/auth-storage.ts +4104 -0
- package/src/cli.ts +262 -0
- package/src/index.ts +54 -0
- package/src/model-cache.ts +129 -0
- package/src/model-manager.ts +450 -0
- package/src/model-thinking.ts +691 -0
- package/src/models.json +73853 -0
- package/src/models.json.d.ts +9 -0
- package/src/models.ts +56 -0
- package/src/prompts/turn-aborted-guidance.md +4 -0
- package/src/provider-details.ts +90 -0
- package/src/provider-models/bundled-references.ts +38 -0
- package/src/provider-models/descriptors.ts +308 -0
- package/src/provider-models/google.ts +91 -0
- package/src/provider-models/index.ts +5 -0
- package/src/provider-models/ollama.ts +153 -0
- package/src/provider-models/openai-compat.ts +2275 -0
- package/src/provider-models/special.ts +67 -0
- package/src/providers/amazon-bedrock.ts +849 -0
- package/src/providers/anthropic-messages-server-schema.ts +229 -0
- package/src/providers/anthropic-messages-server.ts +677 -0
- package/src/providers/anthropic.ts +2696 -0
- package/src/providers/aws-credentials.ts +501 -0
- package/src/providers/aws-eventstream.ts +185 -0
- package/src/providers/aws-sigv4.ts +218 -0
- package/src/providers/azure-openai-responses.ts +337 -0
- package/src/providers/cursor/gen/agent_pb.ts +15274 -0
- package/src/providers/cursor/proto/agent.proto +3526 -0
- package/src/providers/cursor/proto/buf.gen.yaml +6 -0
- package/src/providers/cursor/proto/buf.yaml +17 -0
- package/src/providers/cursor.ts +2561 -0
- package/src/providers/error-message.ts +21 -0
- package/src/providers/github-copilot-headers.ts +140 -0
- package/src/providers/gitlab-duo.ts +372 -0
- package/src/providers/google-auth.ts +252 -0
- package/src/providers/google-gemini-cli.ts +795 -0
- package/src/providers/google-gemini-headers.ts +41 -0
- package/src/providers/google-shared.ts +902 -0
- package/src/providers/google-types.ts +167 -0
- package/src/providers/google-vertex.ts +88 -0
- package/src/providers/google.ts +41 -0
- package/src/providers/grammar.ts +70 -0
- package/src/providers/kimi.ts +52 -0
- package/src/providers/mock.ts +500 -0
- package/src/providers/ollama.ts +544 -0
- package/src/providers/openai-anthropic-shim.ts +138 -0
- package/src/providers/openai-chat-server-schema.ts +243 -0
- package/src/providers/openai-chat-server.ts +628 -0
- package/src/providers/openai-codex/constants.ts +43 -0
- package/src/providers/openai-codex/request-transformer.ts +161 -0
- package/src/providers/openai-codex/response-handler.ts +81 -0
- package/src/providers/openai-codex-responses.ts +2598 -0
- package/src/providers/openai-completions-compat.ts +279 -0
- package/src/providers/openai-completions.ts +1853 -0
- package/src/providers/openai-responses-server-schema.ts +290 -0
- package/src/providers/openai-responses-server.ts +1183 -0
- package/src/providers/openai-responses-shared.ts +800 -0
- package/src/providers/openai-responses.ts +621 -0
- package/src/providers/pi-native-client.ts +228 -0
- package/src/providers/pi-native-server.ts +210 -0
- package/src/providers/register-builtins.ts +412 -0
- package/src/providers/synthetic.ts +50 -0
- package/src/providers/transform-messages.ts +309 -0
- package/src/providers/vision-guard.ts +31 -0
- package/src/rate-limit-utils.ts +84 -0
- package/src/stream.ts +895 -0
- package/src/types.ts +884 -0
- package/src/usage/claude.ts +431 -0
- package/src/usage/gemini.ts +250 -0
- package/src/usage/github-copilot.ts +421 -0
- package/src/usage/google-antigravity.ts +201 -0
- package/src/usage/kimi.ts +271 -0
- package/src/usage/minimax-code.ts +31 -0
- package/src/usage/openai-codex.ts +503 -0
- package/src/usage/shared.ts +10 -0
- package/src/usage/zai.ts +247 -0
- package/src/usage.ts +183 -0
- package/src/utils/abort.ts +51 -0
- package/src/utils/anthropic-auth.ts +87 -0
- package/src/utils/discovery/antigravity.ts +261 -0
- package/src/utils/discovery/codex.ts +371 -0
- package/src/utils/discovery/cursor.ts +306 -0
- package/src/utils/discovery/gemini.ts +248 -0
- package/src/utils/discovery/index.ts +4 -0
- package/src/utils/discovery/openai-compatible.ts +224 -0
- package/src/utils/event-stream.ts +142 -0
- package/src/utils/fireworks-model-id.ts +30 -0
- package/src/utils/foundry.ts +8 -0
- package/src/utils/h2-fetch.ts +60 -0
- package/src/utils/http-inspector.ts +176 -0
- package/src/utils/idle-iterator.ts +250 -0
- package/src/utils/json-parse.ts +148 -0
- package/src/utils/oauth/alibaba-coding-plan.ts +59 -0
- package/src/utils/oauth/anthropic.ts +200 -0
- package/src/utils/oauth/api-key-login.ts +87 -0
- package/src/utils/oauth/api-key-validation.ts +92 -0
- package/src/utils/oauth/callback-server.ts +276 -0
- package/src/utils/oauth/cerebras.ts +16 -0
- package/src/utils/oauth/cloudflare-ai-gateway.ts +48 -0
- package/src/utils/oauth/cursor.ts +157 -0
- package/src/utils/oauth/deepseek.ts +53 -0
- package/src/utils/oauth/firepass.ts +24 -0
- package/src/utils/oauth/fireworks.ts +15 -0
- package/src/utils/oauth/github-copilot.ts +362 -0
- package/src/utils/oauth/gitlab-duo.ts +123 -0
- package/src/utils/oauth/google-antigravity.ts +200 -0
- package/src/utils/oauth/google-gemini-cli.ts +256 -0
- package/src/utils/oauth/google-oauth-shared.ts +110 -0
- package/src/utils/oauth/huggingface.ts +62 -0
- package/src/utils/oauth/index.ts +444 -0
- package/src/utils/oauth/kagi.ts +47 -0
- package/src/utils/oauth/kilo.ts +87 -0
- package/src/utils/oauth/kimi.ts +254 -0
- package/src/utils/oauth/litellm.ts +47 -0
- package/src/utils/oauth/lm-studio.ts +38 -0
- package/src/utils/oauth/minimax-code.ts +78 -0
- package/src/utils/oauth/moonshot.ts +16 -0
- package/src/utils/oauth/nanogpt.ts +15 -0
- package/src/utils/oauth/nvidia.ts +70 -0
- package/src/utils/oauth/oauth.html +199 -0
- package/src/utils/oauth/ollama-cloud.ts +28 -0
- package/src/utils/oauth/ollama.ts +47 -0
- package/src/utils/oauth/openai-codex.ts +299 -0
- package/src/utils/oauth/opencode.ts +49 -0
- package/src/utils/oauth/parallel.ts +46 -0
- package/src/utils/oauth/perplexity.ts +206 -0
- package/src/utils/oauth/pkce.ts +18 -0
- package/src/utils/oauth/qianfan.ts +58 -0
- package/src/utils/oauth/qwen-portal.ts +60 -0
- package/src/utils/oauth/synthetic.ts +16 -0
- package/src/utils/oauth/tavily.ts +46 -0
- package/src/utils/oauth/together.ts +16 -0
- package/src/utils/oauth/types.ts +94 -0
- package/src/utils/oauth/venice.ts +59 -0
- package/src/utils/oauth/vercel-ai-gateway.ts +47 -0
- package/src/utils/oauth/vllm.ts +40 -0
- package/src/utils/oauth/xiaomi.ts +137 -0
- package/src/utils/oauth/zai.ts +60 -0
- package/src/utils/oauth/zenmux.ts +15 -0
- package/src/utils/overflow.ts +137 -0
- package/src/utils/parse-bind.ts +54 -0
- package/src/utils/provider-response.ts +30 -0
- package/src/utils/retry-after.ts +110 -0
- package/src/utils/retry.ts +54 -0
- package/src/utils/schema/CONSTRAINTS.md +164 -0
- package/src/utils/schema/adapt.ts +36 -0
- package/src/utils/schema/compatibility.ts +435 -0
- package/src/utils/schema/dereference.ts +98 -0
- package/src/utils/schema/draft.ts +341 -0
- package/src/utils/schema/equality.ts +97 -0
- package/src/utils/schema/fields.ts +190 -0
- package/src/utils/schema/index.ts +13 -0
- package/src/utils/schema/json-schema-validator.ts +577 -0
- package/src/utils/schema/meta-validator.ts +167 -0
- package/src/utils/schema/normalize.ts +1588 -0
- package/src/utils/schema/spill.ts +43 -0
- package/src/utils/schema/stamps.ts +97 -0
- package/src/utils/schema/types.ts +11 -0
- package/src/utils/schema/wire.ts +213 -0
- package/src/utils/schema/zod-decontaminate.ts +331 -0
- package/src/utils/sse-debug.ts +289 -0
- package/src/utils/tool-call-healing.ts +271 -0
- package/src/utils/tool-choice.ts +99 -0
- package/src/utils/validation.ts +1019 -0
- package/src/utils.ts +166 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local mirror of the subset of `@google/genai` types this package consumes.
|
|
3
|
+
*
|
|
4
|
+
* Field shapes match Gemini / Vertex AI wire format 1:1. Enum-shaped values are
|
|
5
|
+
* modelled as string literal unions so they pass through `JSON.stringify` and
|
|
6
|
+
* `JSON.parse` unchanged.
|
|
7
|
+
*
|
|
8
|
+
* Keep this file in sync with the actual request/response surface of:
|
|
9
|
+
* - `POST {generativelanguage,aiplatform}.googleapis.com/.../models/{model}:streamGenerateContent?alt=sse`
|
|
10
|
+
* - The Cloud Code Assist endpoint used by `google-gemini-cli.ts`
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Mirror of `@google/genai`'s `FinishReason` string enum. */
|
|
14
|
+
export type FinishReason =
|
|
15
|
+
| "FINISH_REASON_UNSPECIFIED"
|
|
16
|
+
| "STOP"
|
|
17
|
+
| "MAX_TOKENS"
|
|
18
|
+
| "SAFETY"
|
|
19
|
+
| "RECITATION"
|
|
20
|
+
| "LANGUAGE"
|
|
21
|
+
| "OTHER"
|
|
22
|
+
| "BLOCKLIST"
|
|
23
|
+
| "PROHIBITED_CONTENT"
|
|
24
|
+
| "SPII"
|
|
25
|
+
| "MALFORMED_FUNCTION_CALL"
|
|
26
|
+
| "IMAGE_SAFETY"
|
|
27
|
+
| "IMAGE_PROHIBITED_CONTENT"
|
|
28
|
+
| "IMAGE_RECITATION"
|
|
29
|
+
| "IMAGE_OTHER"
|
|
30
|
+
| "UNEXPECTED_TOOL_CALL"
|
|
31
|
+
| "NO_IMAGE";
|
|
32
|
+
|
|
33
|
+
/** Mirror of `@google/genai`'s `FunctionCallingConfigMode` string enum. */
|
|
34
|
+
export type FunctionCallingConfigMode = "MODE_UNSPECIFIED" | "AUTO" | "NONE" | "ANY" | "VALIDATED";
|
|
35
|
+
|
|
36
|
+
/** Mirror of `@google/genai`'s `ThinkingLevel` string enum. */
|
|
37
|
+
export type ThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
38
|
+
|
|
39
|
+
/** Inline base64-encoded data part. */
|
|
40
|
+
export interface InlineDataPart {
|
|
41
|
+
mimeType: string;
|
|
42
|
+
data: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Function call emitted by the model. */
|
|
46
|
+
export interface FunctionCallPart {
|
|
47
|
+
name?: string;
|
|
48
|
+
args?: Record<string, unknown>;
|
|
49
|
+
id?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Tool execution result fed back to the model. */
|
|
53
|
+
export interface FunctionResponsePart {
|
|
54
|
+
name: string;
|
|
55
|
+
response: Record<string, unknown>;
|
|
56
|
+
parts?: Part[];
|
|
57
|
+
id?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A single piece of a `Content` message. Mirrors the SDK's union by keeping
|
|
62
|
+
* every optional field — the model and the wire treat shape as discriminator.
|
|
63
|
+
*/
|
|
64
|
+
export interface Part {
|
|
65
|
+
text?: string;
|
|
66
|
+
thought?: boolean;
|
|
67
|
+
thoughtSignature?: string;
|
|
68
|
+
inlineData?: InlineDataPart;
|
|
69
|
+
functionCall?: FunctionCallPart;
|
|
70
|
+
functionResponse?: FunctionResponsePart;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Conversation turn. Roles: `"user"`, `"model"`, optionally absent for system instructions. */
|
|
74
|
+
export interface Content {
|
|
75
|
+
role?: string;
|
|
76
|
+
parts?: Part[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Thinking/reasoning configuration shared by Gemini 2.x and 3.x models. */
|
|
80
|
+
export interface ThinkingConfig {
|
|
81
|
+
includeThoughts?: boolean;
|
|
82
|
+
thinkingBudget?: number;
|
|
83
|
+
thinkingLevel?: ThinkingLevel;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Function declaration entry inside `tools[].functionDeclarations`. */
|
|
87
|
+
export interface FunctionDeclaration {
|
|
88
|
+
name: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
parameters?: Record<string, unknown>;
|
|
91
|
+
parametersJsonSchema?: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Tool group as accepted at the request top level. */
|
|
95
|
+
export interface ToolDeclaration {
|
|
96
|
+
functionDeclarations: Record<string, unknown>[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Tool selection mode container. */
|
|
100
|
+
export interface ToolConfig {
|
|
101
|
+
functionCallingConfig?: {
|
|
102
|
+
mode: FunctionCallingConfigMode;
|
|
103
|
+
allowedFunctionNames?: string[];
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Generation/sampling and request-shape options passed via the SDK's `config`.
|
|
109
|
+
*
|
|
110
|
+
* Fields that the wire format places at the request body root (systemInstruction,
|
|
111
|
+
* tools, toolConfig, safetySettings, cachedContent) live here too — the
|
|
112
|
+
* transformer in `google-shared.ts` lifts them out when serializing.
|
|
113
|
+
*/
|
|
114
|
+
export interface GenerateContentConfig {
|
|
115
|
+
temperature?: number;
|
|
116
|
+
maxOutputTokens?: number;
|
|
117
|
+
topP?: number;
|
|
118
|
+
topK?: number;
|
|
119
|
+
candidateCount?: number;
|
|
120
|
+
stopSequences?: string[];
|
|
121
|
+
presencePenalty?: number;
|
|
122
|
+
frequencyPenalty?: number;
|
|
123
|
+
seed?: number;
|
|
124
|
+
responseMimeType?: string;
|
|
125
|
+
responseSchema?: Record<string, unknown>;
|
|
126
|
+
responseJsonSchema?: Record<string, unknown>;
|
|
127
|
+
responseModalities?: string[];
|
|
128
|
+
systemInstruction?: Content | { role?: string; parts: { text: string }[] };
|
|
129
|
+
tools?: ToolDeclaration[];
|
|
130
|
+
toolConfig?: ToolConfig;
|
|
131
|
+
safetySettings?: Array<Record<string, unknown>>;
|
|
132
|
+
cachedContent?: string;
|
|
133
|
+
thinkingConfig?: ThinkingConfig;
|
|
134
|
+
abortSignal?: AbortSignal;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Top-level argument to `generateContentStream`. */
|
|
138
|
+
export interface GenerateContentParameters {
|
|
139
|
+
model: string;
|
|
140
|
+
contents: Content[];
|
|
141
|
+
config?: GenerateContentConfig;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Per-stream candidate envelope. */
|
|
145
|
+
export interface Candidate {
|
|
146
|
+
content?: Content;
|
|
147
|
+
finishReason?: FinishReason;
|
|
148
|
+
index?: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Cumulative token accounting attached to the trailing chunk. */
|
|
152
|
+
export interface UsageMetadata {
|
|
153
|
+
promptTokenCount?: number;
|
|
154
|
+
candidatesTokenCount?: number;
|
|
155
|
+
thoughtsTokenCount?: number;
|
|
156
|
+
totalTokenCount?: number;
|
|
157
|
+
cachedContentTokenCount?: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Single SSE chunk's parsed JSON body. */
|
|
161
|
+
export interface GenerateContentResponse {
|
|
162
|
+
candidates?: Candidate[];
|
|
163
|
+
usageMetadata?: UsageMetadata;
|
|
164
|
+
modelVersion?: string;
|
|
165
|
+
responseId?: string;
|
|
166
|
+
promptFeedback?: Record<string, unknown>;
|
|
167
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { $env } from "@gajae-code/utils";
|
|
2
|
+
import type { Context, Model, StreamFunction } from "../types";
|
|
3
|
+
import type { AssistantMessageEventStream } from "../utils/event-stream";
|
|
4
|
+
import { getVertexAccessToken } from "./google-auth";
|
|
5
|
+
import {
|
|
6
|
+
buildGoogleGenerateContentParams,
|
|
7
|
+
type GoogleGenAIRequestPlan,
|
|
8
|
+
type GoogleSharedStreamOptions,
|
|
9
|
+
streamGoogleGenAI,
|
|
10
|
+
} from "./google-shared";
|
|
11
|
+
|
|
12
|
+
export interface GoogleVertexOptions extends GoogleSharedStreamOptions {
|
|
13
|
+
project?: string;
|
|
14
|
+
location?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const API_VERSION = "v1";
|
|
18
|
+
|
|
19
|
+
export const streamGoogleVertex: StreamFunction<"google-vertex"> = (
|
|
20
|
+
model: Model<"google-vertex">,
|
|
21
|
+
context: Context,
|
|
22
|
+
options?: GoogleVertexOptions,
|
|
23
|
+
): AssistantMessageEventStream =>
|
|
24
|
+
streamGoogleGenAI({
|
|
25
|
+
model,
|
|
26
|
+
options,
|
|
27
|
+
api: "google-vertex",
|
|
28
|
+
retainTextSignature: true,
|
|
29
|
+
prepare: async (): Promise<GoogleGenAIRequestPlan> => {
|
|
30
|
+
const apiKey = resolveApiKey(options);
|
|
31
|
+
const params = buildGoogleGenerateContentParams(model, context, options ?? {});
|
|
32
|
+
const baseHeaders: Record<string, string> = {
|
|
33
|
+
...(model.headers ?? {}),
|
|
34
|
+
...(options?.headers ?? {}),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (apiKey) {
|
|
38
|
+
const url = `https://aiplatform.googleapis.com/${API_VERSION}/publishers/google/models/${model.id}:streamGenerateContent?alt=sse`;
|
|
39
|
+
return {
|
|
40
|
+
params,
|
|
41
|
+
url,
|
|
42
|
+
headers: { ...baseHeaders, "x-goog-api-key": apiKey },
|
|
43
|
+
fetch: options?.fetch,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const project = resolveProject(options);
|
|
48
|
+
const location = resolveLocation(options);
|
|
49
|
+
const accessToken = await getVertexAccessToken({ signal: options?.signal, fetch: options?.fetch });
|
|
50
|
+
const host = resolveEndpointHost(location);
|
|
51
|
+
const url = `https://${host}/${API_VERSION}/projects/${project}/locations/${location}/publishers/google/models/${model.id}:streamGenerateContent?alt=sse`;
|
|
52
|
+
return {
|
|
53
|
+
params,
|
|
54
|
+
url,
|
|
55
|
+
headers: { ...baseHeaders, Authorization: `Bearer ${accessToken}` },
|
|
56
|
+
fetch: options?.fetch,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function resolveApiKey(options?: GoogleVertexOptions): string | undefined {
|
|
62
|
+
// options.apiKey may contain sentinel values like "<authenticated>" or "N/A"
|
|
63
|
+
// leaked from the agent loop — only use it if it looks like a real API key.
|
|
64
|
+
const optKey = options?.apiKey;
|
|
65
|
+
const realKey = optKey && !optKey.startsWith("<") && optKey !== "N/A" ? optKey : undefined;
|
|
66
|
+
return realKey || $env.GOOGLE_CLOUD_API_KEY;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveProject(options?: GoogleVertexOptions): string {
|
|
70
|
+
const project = options?.project || $env.GOOGLE_CLOUD_PROJECT || $env.GCLOUD_PROJECT;
|
|
71
|
+
if (!project) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.",
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return project;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveEndpointHost(location: string): string {
|
|
80
|
+
return location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`;
|
|
81
|
+
}
|
|
82
|
+
function resolveLocation(options?: GoogleVertexOptions): string {
|
|
83
|
+
const location = options?.location || $env.GOOGLE_CLOUD_LOCATION;
|
|
84
|
+
if (!location) {
|
|
85
|
+
throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");
|
|
86
|
+
}
|
|
87
|
+
return location;
|
|
88
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getEnvApiKey } from "../stream";
|
|
2
|
+
import type { Context, Model, StreamFunction } from "../types";
|
|
3
|
+
import type { AssistantMessageEventStream } from "../utils/event-stream";
|
|
4
|
+
import {
|
|
5
|
+
buildGoogleGenerateContentParams,
|
|
6
|
+
type GoogleGenAIRequestPlan,
|
|
7
|
+
type GoogleSharedStreamOptions,
|
|
8
|
+
streamGoogleGenAI,
|
|
9
|
+
} from "./google-shared";
|
|
10
|
+
|
|
11
|
+
export type GoogleOptions = GoogleSharedStreamOptions;
|
|
12
|
+
|
|
13
|
+
const DEFAULT_GENERATIVE_LANGUAGE_BASE = "https://generativelanguage.googleapis.com/v1beta";
|
|
14
|
+
|
|
15
|
+
export const streamGoogle: StreamFunction<"google-generative-ai"> = (
|
|
16
|
+
model: Model<"google-generative-ai">,
|
|
17
|
+
context: Context,
|
|
18
|
+
options?: GoogleOptions,
|
|
19
|
+
): AssistantMessageEventStream =>
|
|
20
|
+
streamGoogleGenAI({
|
|
21
|
+
model,
|
|
22
|
+
options,
|
|
23
|
+
api: "google-generative-ai",
|
|
24
|
+
prepare: (): GoogleGenAIRequestPlan => {
|
|
25
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
26
|
+
if (!apiKey) {
|
|
27
|
+
throw new Error("Google Generative AI requires an API key (GEMINI_API_KEY or options.apiKey).");
|
|
28
|
+
}
|
|
29
|
+
const params = buildGoogleGenerateContentParams(model, context, options ?? {});
|
|
30
|
+
// `model.baseUrl` already includes the API version segment when set (mirrors the
|
|
31
|
+
// `apiVersion: ""` reset that the SDK relied on for custom base URLs).
|
|
32
|
+
const base = model.baseUrl?.trim() || DEFAULT_GENERATIVE_LANGUAGE_BASE;
|
|
33
|
+
const url = `${base}/models/${model.id}:streamGenerateContent?alt=sse`;
|
|
34
|
+
const headers: Record<string, string> = {
|
|
35
|
+
"x-goog-api-key": apiKey,
|
|
36
|
+
...(model.headers ?? {}),
|
|
37
|
+
...(options?.headers ?? {}),
|
|
38
|
+
};
|
|
39
|
+
return { params, url, headers, fetch: options?.fetch };
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export function compactGrammarDefinition(syntax: "lark" | "regex", definition: string): string {
|
|
2
|
+
if (syntax !== "lark") {
|
|
3
|
+
return definition;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return compactLarkGrammarDefinition(definition);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function compactLarkGrammarDefinition(definition: string): string {
|
|
10
|
+
const lines: string[] = [];
|
|
11
|
+
|
|
12
|
+
for (const line of definition.split(/\r?\n/)) {
|
|
13
|
+
const uncommented = stripLarkLineComment(line).trimEnd();
|
|
14
|
+
if (uncommented.trim()) {
|
|
15
|
+
lines.push(uncommented);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return lines.join("\n");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function stripLarkLineComment(line: string): string {
|
|
23
|
+
let inString: string | undefined;
|
|
24
|
+
let inRegex = false;
|
|
25
|
+
let escaped = false;
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < line.length; i++) {
|
|
28
|
+
const char = line[i];
|
|
29
|
+
const next = line[i + 1];
|
|
30
|
+
|
|
31
|
+
if (escaped) {
|
|
32
|
+
escaped = false;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (char === "\\") {
|
|
37
|
+
escaped = true;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (inString) {
|
|
42
|
+
if (char === inString) {
|
|
43
|
+
inString = undefined;
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (inRegex) {
|
|
49
|
+
if (char === "/") {
|
|
50
|
+
inRegex = false;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (char === "/" && next === "/") {
|
|
56
|
+
return line.slice(0, i);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (char === '"' || char === "'") {
|
|
60
|
+
inString = char;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (char === "/") {
|
|
65
|
+
inRegex = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return line;
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi Code provider - wraps OpenAI or Anthropic API based on format setting.
|
|
3
|
+
*
|
|
4
|
+
* Kimi offers both OpenAI-compatible and Anthropic-compatible APIs:
|
|
5
|
+
* - OpenAI: https://api.kimi.com/coding/v1/chat/completions
|
|
6
|
+
* - Anthropic: https://api.kimi.com/coding/v1/messages
|
|
7
|
+
*
|
|
8
|
+
* The Anthropic API is generally more stable and recommended.
|
|
9
|
+
* Note: Kimi calculates TPM rate limits based on max_tokens, not actual output.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Api, Context, Model } from "../types";
|
|
13
|
+
import type { AssistantMessageEventStream } from "../utils/event-stream";
|
|
14
|
+
import { getKimiCommonHeaders } from "../utils/oauth/kimi";
|
|
15
|
+
import {
|
|
16
|
+
type OpenAIAnthropicApiFormat,
|
|
17
|
+
type OpenAIAnthropicShimOptions,
|
|
18
|
+
streamOpenAIAnthropicShim,
|
|
19
|
+
} from "./openai-anthropic-shim";
|
|
20
|
+
|
|
21
|
+
export type KimiApiFormat = OpenAIAnthropicApiFormat;
|
|
22
|
+
|
|
23
|
+
// Note: Anthropic SDK appends /v1/messages, so base URL should not include /v1
|
|
24
|
+
const KIMI_ANTHROPIC_BASE_URL = "https://api.kimi.com/coding";
|
|
25
|
+
|
|
26
|
+
export interface KimiOptions extends OpenAIAnthropicShimOptions {
|
|
27
|
+
/** API format: "openai" or "anthropic". Default: "anthropic" */
|
|
28
|
+
format?: KimiApiFormat;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Stream from Kimi Code, routing to either OpenAI or Anthropic API based on format.
|
|
33
|
+
* Returns synchronously like other providers - async header fetching happens internally.
|
|
34
|
+
*/
|
|
35
|
+
export function streamKimi(
|
|
36
|
+
model: Model<"openai-completions">,
|
|
37
|
+
context: Context,
|
|
38
|
+
options?: KimiOptions,
|
|
39
|
+
): AssistantMessageEventStream {
|
|
40
|
+
return streamOpenAIAnthropicShim(model, context, options, {
|
|
41
|
+
anthropicBaseUrl: KIMI_ANTHROPIC_BASE_URL,
|
|
42
|
+
defaultFormat: "anthropic",
|
|
43
|
+
extraHeaders: getKimiCommonHeaders,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if a model is a Kimi Code model.
|
|
49
|
+
*/
|
|
50
|
+
export function isKimiModel(model: Model<Api>): boolean {
|
|
51
|
+
return model.provider === "kimi-code";
|
|
52
|
+
}
|