@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,42 @@
|
|
|
1
|
+
import { type JsonValue } from "@bufbuild/protobuf";
|
|
2
|
+
import type { CursorExecHandlerResult, CursorExecHandlers, CursorToolResultHandler, Message, StreamFunction, StreamOptions, ToolResultMessage } from "../types";
|
|
3
|
+
export declare const CURSOR_API_URL = "https://api2.cursor.sh";
|
|
4
|
+
export declare const CURSOR_CLIENT_VERSION = "cli-2026.01.09-231024f";
|
|
5
|
+
export interface CursorOptions extends StreamOptions {
|
|
6
|
+
customSystemPrompt?: string;
|
|
7
|
+
conversationId?: string;
|
|
8
|
+
execHandlers?: CursorExecHandlers;
|
|
9
|
+
onToolResult?: CursorToolResultHandler;
|
|
10
|
+
}
|
|
11
|
+
export declare const streamCursor: StreamFunction<"cursor-agent">;
|
|
12
|
+
/** Exported for tests: verifies handler is invoked with correct `this` when passed as bound. */
|
|
13
|
+
export declare function resolveExecHandler<TArgs, TResult>(args: TArgs, handler: ((args: TArgs) => Promise<CursorExecHandlerResult<TResult>>) | undefined, onToolResult: CursorToolResultHandler | undefined, buildFromToolResult: (toolResult: ToolResultMessage) => TResult, buildRejected: (reason: string) => TResult, buildError: (error: string) => TResult): Promise<{
|
|
14
|
+
execResult: TResult;
|
|
15
|
+
toolResult?: ToolResultMessage;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Build `ConversationStateStructure.rootPromptMessagesJson` blob IDs for the
|
|
19
|
+
* system prompt plus prior conversation history, as JSON blobs matching
|
|
20
|
+
* Cursor's internal Vercel-AI-SDK-shaped message format.
|
|
21
|
+
*
|
|
22
|
+
* Cursor's server uses `rootPromptMessagesJson` (not `turns[]`) to build the
|
|
23
|
+
* actual model prompt. `turns[]` is UI/display metadata. Without populating
|
|
24
|
+
* this field, multi-turn conversations lose prior context — the model sees
|
|
25
|
+
* only an empty placeholder where historical user turns should be.
|
|
26
|
+
* The last user message is excluded because it is sent in the action.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Build one Cursor system-message JSON blob per ordered system prompt. Emitting separate blobs
|
|
30
|
+
* (rather than a single `\n\n`-joined string) lets Cursor's blob cache hit independently per
|
|
31
|
+
* entry: changing only the last prompt does not invalidate earlier blob ids, so the prefix
|
|
32
|
+
* up to the changed prompt remains cached on the server side.
|
|
33
|
+
*
|
|
34
|
+
* When no system prompts are provided, returns a single default greeting so we never emit
|
|
35
|
+
* an empty `rootPromptMessagesJson` head.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildCursorSystemPromptJsons(systemPrompt: readonly string[] | undefined): string[];
|
|
38
|
+
/** Exported for tests: decodes Cursor history blobs built from conversation messages. */
|
|
39
|
+
export declare function buildCursorHistoryForTest(messages: Message[]): {
|
|
40
|
+
rootPromptMessagesJson: unknown[];
|
|
41
|
+
turnUserMessagesJson: JsonValue[];
|
|
42
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Api, Model } from "../types";
|
|
2
|
+
export declare function createProviderErrorMessage(model: Model<Api>, err: unknown): {
|
|
3
|
+
role: "assistant";
|
|
4
|
+
content: {
|
|
5
|
+
type: "text";
|
|
6
|
+
text: string;
|
|
7
|
+
}[];
|
|
8
|
+
api: Api;
|
|
9
|
+
provider: string;
|
|
10
|
+
model: string;
|
|
11
|
+
usage: {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cacheRead: number;
|
|
15
|
+
cacheWrite: number;
|
|
16
|
+
totalTokens: number;
|
|
17
|
+
cost: {
|
|
18
|
+
input: number;
|
|
19
|
+
output: number;
|
|
20
|
+
cacheRead: number;
|
|
21
|
+
cacheWrite: number;
|
|
22
|
+
total: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
stopReason: "error";
|
|
26
|
+
timestamp: number;
|
|
27
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Message } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Infer whether the current request to Copilot is user-initiated or agent-initiated.
|
|
4
|
+
* Accepts `unknown[]` because providers may pass pre-converted message shapes.
|
|
5
|
+
*/
|
|
6
|
+
export type CopilotInitiator = "user" | "agent";
|
|
7
|
+
export type CopilotPremiumRequests = number;
|
|
8
|
+
export type CopilotDynamicHeaders = {
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
initiator: CopilotInitiator;
|
|
11
|
+
premiumRequests: CopilotPremiumRequests;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveGitHubCopilotBaseUrl(baseUrl: string | undefined, apiKey: string | undefined): string | undefined;
|
|
14
|
+
export declare function inferCopilotInitiator(messages: unknown[]): CopilotInitiator;
|
|
15
|
+
/** Check whether any message in the conversation contains image content. */
|
|
16
|
+
export declare function hasCopilotVisionInput(messages: Message[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve an explicitly configured Copilot initiator header, if present.
|
|
19
|
+
* Handles case-insensitive X-Initiator keys and returns the last valid value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCopilotInitiatorOverride(headers: Record<string, string> | undefined): CopilotInitiator | undefined;
|
|
22
|
+
export type CopilotPlanTier = "free" | "paid";
|
|
23
|
+
export declare function getCopilotPremiumMultiplier(premiumMultiplier: number | undefined, planTier?: string): number;
|
|
24
|
+
export declare function getCopilotPremiumRequests(params: {
|
|
25
|
+
initiator: CopilotInitiator;
|
|
26
|
+
premiumMultiplier?: number;
|
|
27
|
+
planTier?: string;
|
|
28
|
+
}): CopilotPremiumRequests;
|
|
29
|
+
/**
|
|
30
|
+
* Build dynamic Copilot headers that vary per-request.
|
|
31
|
+
* Static headers (User-Agent, Editor-Version, etc.) come from model.headers.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildCopilotDynamicHeaders(params: {
|
|
34
|
+
messages: unknown[];
|
|
35
|
+
hasImages: boolean;
|
|
36
|
+
premiumMultiplier?: number;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
initiatorOverride?: CopilotInitiator;
|
|
39
|
+
planTier?: string;
|
|
40
|
+
}): CopilotDynamicHeaders;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Api, Context, Model, SimpleStreamOptions } from "../types";
|
|
2
|
+
import { AssistantMessageEventStream } from "../utils/event-stream";
|
|
3
|
+
type GitLabProvider = "anthropic" | "openai";
|
|
4
|
+
type GitLabOpenAIApiType = "chat" | "responses";
|
|
5
|
+
export type GitLabModelMapping = {
|
|
6
|
+
provider: GitLabProvider;
|
|
7
|
+
model: string;
|
|
8
|
+
openaiApiType?: GitLabOpenAIApiType;
|
|
9
|
+
name: string;
|
|
10
|
+
reasoning: boolean;
|
|
11
|
+
input: ("text" | "image")[];
|
|
12
|
+
cost: {
|
|
13
|
+
input: number;
|
|
14
|
+
output: number;
|
|
15
|
+
cacheRead: number;
|
|
16
|
+
cacheWrite: number;
|
|
17
|
+
};
|
|
18
|
+
contextWindow: number;
|
|
19
|
+
maxTokens: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const MODEL_MAPPINGS: Record<string, GitLabModelMapping>;
|
|
22
|
+
export declare function getModelMapping(modelId: string): GitLabModelMapping | undefined;
|
|
23
|
+
export declare function getGitLabDuoModels(): Model<Api>[];
|
|
24
|
+
export declare function clearGitLabDuoDirectAccessCache(): void;
|
|
25
|
+
export declare function isGitLabDuoModel(model: Model<Api>): boolean;
|
|
26
|
+
export declare function streamGitLabDuo(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Default Credentials (ADC) resolution for Vertex AI.
|
|
3
|
+
*
|
|
4
|
+
* Replaces `google-auth-library` with a direct WebCrypto + REST implementation.
|
|
5
|
+
* Sources, in priority order:
|
|
6
|
+
* 1. `GOOGLE_APPLICATION_CREDENTIALS` env → file with `type: "service_account"` (RS256 JWT exchange)
|
|
7
|
+
* or `type: "authorized_user"` (refresh-token exchange).
|
|
8
|
+
* 2. `~/.config/gcloud/application_default_credentials.json` (user ADC, same authorized_user flow).
|
|
9
|
+
* 3. GCE / Cloud Run metadata server (`metadata.google.internal`).
|
|
10
|
+
*
|
|
11
|
+
* Tokens are cached per source key and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` before expiry
|
|
12
|
+
* (default 60s). Concurrent callers waiting on a refresh share the same in-flight promise.
|
|
13
|
+
*/
|
|
14
|
+
import type { FetchImpl } from "../types";
|
|
15
|
+
/**
|
|
16
|
+
* Returns a Bearer access token suitable for the `Authorization` header on Vertex AI calls.
|
|
17
|
+
* The token is cached in module scope and refreshed `GOOGLE_VERTEX_REFRESH_SKEW_MS` ms before it expires.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getVertexAccessToken(options?: {
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
fetch?: FetchImpl;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
/** Test seam: clears every cached token. */
|
|
24
|
+
export declare function __resetVertexTokenCache(): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Context, Model, StreamFunction, StreamOptions } from "../types";
|
|
2
|
+
import type { Content, FunctionCallingConfigMode, ThinkingConfig } from "./google-shared";
|
|
3
|
+
import { type GoogleThinkingLevel } from "./google-shared";
|
|
4
|
+
/**
|
|
5
|
+
* Thinking level for Gemini 3 models. Re-exported from `google-shared` so existing
|
|
6
|
+
* `import { GoogleThinkingLevel } from "./google-gemini-cli"` callers keep working.
|
|
7
|
+
*/
|
|
8
|
+
export type { GoogleThinkingLevel };
|
|
9
|
+
export interface GoogleGeminiCliOptions extends StreamOptions {
|
|
10
|
+
toolChoice?: "auto" | "none" | "any";
|
|
11
|
+
/**
|
|
12
|
+
* Thinking/reasoning configuration.
|
|
13
|
+
* - Gemini 2.x models: use `budgetTokens` to set the thinking budget
|
|
14
|
+
* - Gemini 3 models (gemini-3-pro-*, gemini-3-flash-*): use `level` instead
|
|
15
|
+
*
|
|
16
|
+
* When using `streamSimple`, this is handled automatically based on the model.
|
|
17
|
+
*/
|
|
18
|
+
thinking?: {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
/** Thinking budget in tokens. Use for Gemini 2.x models. */
|
|
21
|
+
budgetTokens?: number;
|
|
22
|
+
/** Thinking level. Use for Gemini 3 models (LOW/HIGH for Pro, MINIMAL/LOW/MEDIUM/HIGH for Flash). */
|
|
23
|
+
level?: GoogleThinkingLevel;
|
|
24
|
+
};
|
|
25
|
+
projectId?: string;
|
|
26
|
+
}
|
|
27
|
+
export { ANTIGRAVITY_SYSTEM_INSTRUCTION, getAntigravityUserAgent, getGeminiCliHeaders, getGeminiCliUserAgent, } from "./google-gemini-headers";
|
|
28
|
+
interface ParsedGeminiCliCredentials {
|
|
29
|
+
accessToken: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
refreshToken?: string;
|
|
32
|
+
expiresAt?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function parseGeminiCliCredentials(apiKeyRaw: string): ParsedGeminiCliCredentials;
|
|
35
|
+
export declare function shouldRefreshGeminiCliCredentials(expiresAt: number | undefined, isAntigravity: boolean, nowMs?: number): boolean;
|
|
36
|
+
interface CloudCodeAssistRequest {
|
|
37
|
+
project: string;
|
|
38
|
+
model: string;
|
|
39
|
+
request: {
|
|
40
|
+
contents: Content[];
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
systemInstruction?: {
|
|
43
|
+
role?: string;
|
|
44
|
+
parts: {
|
|
45
|
+
text: string;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
generationConfig?: {
|
|
49
|
+
maxOutputTokens?: number;
|
|
50
|
+
temperature?: number;
|
|
51
|
+
topP?: number;
|
|
52
|
+
topK?: number;
|
|
53
|
+
minP?: number;
|
|
54
|
+
presencePenalty?: number;
|
|
55
|
+
repetitionPenalty?: number;
|
|
56
|
+
thinkingConfig?: ThinkingConfig;
|
|
57
|
+
};
|
|
58
|
+
tools?: {
|
|
59
|
+
functionDeclarations: Record<string, unknown>[];
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
toolConfig?: {
|
|
62
|
+
functionCallingConfig: {
|
|
63
|
+
mode: FunctionCallingConfigMode;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
requestType?: string;
|
|
68
|
+
userAgent?: string;
|
|
69
|
+
requestId?: string;
|
|
70
|
+
}
|
|
71
|
+
export declare const streamGoogleGeminiCli: StreamFunction<"google-gemini-cli">;
|
|
72
|
+
export declare function buildRequest(model: Model<"google-gemini-cli">, context: Context, projectId: string, options?: GoogleGeminiCliOptions, isAntigravity?: boolean): CloudCodeAssistRequest;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a User-Agent string that identifies as Gemini CLI to unlock higher rate limits.
|
|
3
|
+
* Uses the same format as the official Gemini CLI (v0.35+):
|
|
4
|
+
* GeminiCLI/VERSION/MODEL (PLATFORM; ARCH; SURFACE)
|
|
5
|
+
*/
|
|
6
|
+
export declare function getGeminiCliUserAgent(modelId?: string): string;
|
|
7
|
+
export declare const getGeminiCliHeaders: (modelId?: string) => {
|
|
8
|
+
"User-Agent": string;
|
|
9
|
+
"Client-Metadata": string;
|
|
10
|
+
};
|
|
11
|
+
export declare const ANTIGRAVITY_SYSTEM_INSTRUCTION: string;
|
|
12
|
+
/**
|
|
13
|
+
* Antigravity / Cloud Code Assist user agent. Lives in its own file so discovery
|
|
14
|
+
* and usage code can read it without pulling the heavy google-gemini-cli provider
|
|
15
|
+
* (and its @google/genai → google-auth-library dependency chain) into the startup
|
|
16
|
+
* parse graph.
|
|
17
|
+
*/
|
|
18
|
+
export declare let getAntigravityUserAgent: () => string;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for Google Generative AI and Google Cloud Code Assist providers.
|
|
3
|
+
*/
|
|
4
|
+
import type { AssistantMessage, Context, FetchImpl, Model, StopReason, StreamOptions, TextContent, ThinkingContent, Tool, ToolCall } from "../types";
|
|
5
|
+
import { AssistantMessageEventStream } from "../utils/event-stream";
|
|
6
|
+
import { normalizeSchemaForGoogle } from "../utils/schema";
|
|
7
|
+
import type { Content, FinishReason, FunctionCallingConfigMode, GenerateContentParameters, GenerateContentResponse, Part } from "./google-types";
|
|
8
|
+
export type { Content, FunctionCallingConfigMode, GenerateContentParameters, GenerateContentResponse, ThinkingConfig, } from "./google-types";
|
|
9
|
+
export { normalizeSchemaForGoogle };
|
|
10
|
+
type GoogleApiType = "google-generative-ai" | "google-gemini-cli" | "google-vertex";
|
|
11
|
+
/**
|
|
12
|
+
* Thinking level for Gemini 3 models. Mirrors Google's `ThinkingLevel` enum values.
|
|
13
|
+
* Defined here (not in any specific provider) so all Google providers can reference it
|
|
14
|
+
* without inducing a circular dependency.
|
|
15
|
+
*/
|
|
16
|
+
export type GoogleThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
17
|
+
/**
|
|
18
|
+
* Sampling/thinking options shared by `streamGoogle` and `streamGoogleVertex`.
|
|
19
|
+
* `google-gemini-cli` uses a different transport and request shape — do not extend this for it.
|
|
20
|
+
*/
|
|
21
|
+
export interface GoogleSharedStreamOptions extends StreamOptions {
|
|
22
|
+
toolChoice?: "auto" | "none" | "any";
|
|
23
|
+
thinking?: {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
budgetTokens?: number;
|
|
26
|
+
level?: GoogleThinkingLevel;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Determines whether a streamed Gemini `Part` should be treated as "thinking".
|
|
31
|
+
*
|
|
32
|
+
* Protocol note (Gemini / Vertex AI thought signatures):
|
|
33
|
+
* - `thought: true` is the definitive marker for thinking content (thought summaries).
|
|
34
|
+
* - `thoughtSignature` is an encrypted representation of the model's internal thought process
|
|
35
|
+
* used to preserve reasoning context across multi-turn interactions.
|
|
36
|
+
* - `thoughtSignature` can appear on ANY part type (text, functionCall, etc.) - it does NOT
|
|
37
|
+
* indicate the part itself is thinking content.
|
|
38
|
+
* - For non-functionCall responses, the signature appears on the last part for context replay.
|
|
39
|
+
* - When persisting/replaying model outputs, signature-bearing parts must be preserved as-is;
|
|
40
|
+
* do not merge/move signatures across parts.
|
|
41
|
+
*
|
|
42
|
+
* See: https://ai.google.dev/gemini-api/docs/thought-signatures
|
|
43
|
+
*/
|
|
44
|
+
export declare function isThinkingPart(part: Pick<Part, "thought" | "thoughtSignature">): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Retain thought signatures during streaming.
|
|
47
|
+
*
|
|
48
|
+
* Some backends only send `thoughtSignature` on the first delta for a given part/block; later deltas may omit it.
|
|
49
|
+
* This helper preserves the last non-empty signature for the current block.
|
|
50
|
+
*
|
|
51
|
+
* Note: this does NOT merge or move signatures across distinct response parts. It only prevents
|
|
52
|
+
* a signature from being overwritten with `undefined` within the same streamed block.
|
|
53
|
+
*/
|
|
54
|
+
export declare function retainThoughtSignature(existing: string | undefined, incoming: string | undefined): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Anthropic model models via Google APIs require explicit tool call IDs in function calls/responses.
|
|
57
|
+
*/
|
|
58
|
+
export declare function requiresToolCallId(modelId: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Convert internal messages to Gemini Content[] format.
|
|
61
|
+
*/
|
|
62
|
+
export declare function convertMessages<T extends GoogleApiType>(model: Model<T>, context: Context): Content[];
|
|
63
|
+
/**
|
|
64
|
+
* Convert tools to Gemini function declarations format.
|
|
65
|
+
*
|
|
66
|
+
* We prefer `parametersJsonSchema` (full JSON Schema: anyOf/oneOf/const/etc.).
|
|
67
|
+
*
|
|
68
|
+
* Anthropic model models via Cloud Code Assist require the legacy `parameters` field; the API
|
|
69
|
+
* translates it into Anthropic's `input_schema`. When using that path, we sanitize the
|
|
70
|
+
* schema to remove Google-unsupported JSON Schema keywords.
|
|
71
|
+
*/
|
|
72
|
+
export declare function convertTools(tools: Tool[], model: Model<"google-generative-ai" | "google-gemini-cli" | "google-vertex">): {
|
|
73
|
+
functionDeclarations: Record<string, unknown>[];
|
|
74
|
+
}[] | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Map tool choice string to Gemini FunctionCallingConfigMode.
|
|
77
|
+
*/
|
|
78
|
+
export declare function mapToolChoice(choice: string): FunctionCallingConfigMode;
|
|
79
|
+
/**
|
|
80
|
+
* Map Gemini FinishReason to our StopReason.
|
|
81
|
+
*/
|
|
82
|
+
export declare function mapStopReason(reason: FinishReason): StopReason;
|
|
83
|
+
/**
|
|
84
|
+
* Map string finish reason to our StopReason (for raw API responses).
|
|
85
|
+
*/
|
|
86
|
+
export declare function mapStopReasonString(reason: string): StopReason;
|
|
87
|
+
export declare function nextToolCallId(name: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Push the appropriate `text_end` / `thinking_end` event for the given block.
|
|
90
|
+
* Shared between the SDK-backed stream consumer and the gemini-cli SSE consumer so
|
|
91
|
+
* the end-of-block event shape stays in lockstep.
|
|
92
|
+
*/
|
|
93
|
+
export declare function pushBlockEndEvent(block: TextContent | ThinkingContent, contentIndex: number, output: AssistantMessage, stream: AssistantMessageEventStream): void;
|
|
94
|
+
/**
|
|
95
|
+
* Push the three lifecycle events (`toolcall_start` / `toolcall_delta` / `toolcall_end`) for a
|
|
96
|
+
* fully-assembled `ToolCall`. Caller is responsible for appending the toolCall to `output.content`
|
|
97
|
+
* before invoking — this helper does not mutate `output.content`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function pushToolCallEvents(toolCall: ToolCall, contentIndex: number, output: AssistantMessage, stream: AssistantMessageEventStream): void;
|
|
100
|
+
/**
|
|
101
|
+
* Append a new text- or thinking-block to `output.content` and push the matching
|
|
102
|
+
* `text_start` / `thinking_start` event. `onBeforeStartEvent` lets the SSE consumer
|
|
103
|
+
* inject its `ensureStarted()` first-token side effect into the canonical event order.
|
|
104
|
+
*/
|
|
105
|
+
export declare function startTextOrThinkingBlock(isThinking: boolean, output: AssistantMessage, stream: AssistantMessageEventStream, onBeforeStartEvent?: () => void): TextContent | ThinkingContent;
|
|
106
|
+
/**
|
|
107
|
+
* Drives the chunked `generateContentStream` iterator into an `AssistantMessage` and
|
|
108
|
+
* the corresponding `AssistantMessageEventStream`. Shared between `streamGoogle` and
|
|
109
|
+
* `streamGoogleVertex` — every observable event order and stop-reason rule is preserved.
|
|
110
|
+
*
|
|
111
|
+
* The caller still owns: `output` construction, timing fields (`duration`/`ttft`),
|
|
112
|
+
* `rawRequestDump`, the `client.models.generateContentStream(params)` call itself,
|
|
113
|
+
* pushing `start`/`done`/`error` events, and the surrounding try/catch that translates
|
|
114
|
+
* thrown errors into `output.stopReason`/`errorMessage`.
|
|
115
|
+
*
|
|
116
|
+
* This helper handles: the chunk loop, currentBlock flush transitions, usage metadata
|
|
117
|
+
* decoding (`calculateCost` included), tool-call id collision avoidance, finish-reason
|
|
118
|
+
* mapping, and the abort/stop-reason post-checks that re-throw to bubble into the
|
|
119
|
+
* caller's catch.
|
|
120
|
+
*/
|
|
121
|
+
export declare function consumeGoogleStream<T extends GoogleApiType>(args: {
|
|
122
|
+
googleStream: AsyncIterable<GenerateContentResponse>;
|
|
123
|
+
output: AssistantMessage;
|
|
124
|
+
stream: AssistantMessageEventStream;
|
|
125
|
+
model: Model<T>;
|
|
126
|
+
options: {
|
|
127
|
+
signal?: AbortSignal;
|
|
128
|
+
} | undefined;
|
|
129
|
+
/** Vertex preserves `textSignature` on streamed text deltas; google-generative-ai does not. */
|
|
130
|
+
retainTextSignature?: boolean;
|
|
131
|
+
onFirstToken?: () => void;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Build the `GenerateContentParameters` payload for the public Gemini API and Vertex AI.
|
|
135
|
+
* Both surfaces accept the same `GenerateContentConfig` shape — every numeric/string knob,
|
|
136
|
+
* tool-config, thinking-config, and system-instruction conversion is identical.
|
|
137
|
+
*
|
|
138
|
+
* `google-gemini-cli` is NOT routed through here: its `CloudCodeAssistRequest` body has a
|
|
139
|
+
* distinct top-level shape (project/request/requestType) and a different thinking-config
|
|
140
|
+
* placement on `generationConfig`.
|
|
141
|
+
*/
|
|
142
|
+
export declare function buildGoogleGenerateContentParams<T extends "google-generative-ai" | "google-vertex">(model: Model<T>, context: Context, options: GoogleSharedStreamOptions): GenerateContentParameters;
|
|
143
|
+
/**
|
|
144
|
+
* Drive the `streamGoogle` / `streamGoogleVertex` event flow: build the assistant message,
|
|
145
|
+
* push start/done/error events, run `consumeGoogleStream`, and translate thrown errors into
|
|
146
|
+
* the canonical `error` event shape.
|
|
147
|
+
*
|
|
148
|
+
* Caller-supplied `prepare()` runs inside the try-block so any failure (missing project,
|
|
149
|
+
* bad auth, etc.) is funneled through the same error path as a streaming failure.
|
|
150
|
+
*/
|
|
151
|
+
export interface GoogleGenAIRequestPlan {
|
|
152
|
+
params: GenerateContentParameters;
|
|
153
|
+
url: string;
|
|
154
|
+
headers: Record<string, string>;
|
|
155
|
+
fetch?: FetchImpl;
|
|
156
|
+
}
|
|
157
|
+
export declare function streamGoogleGenAI<T extends "google-generative-ai" | "google-vertex">(args: {
|
|
158
|
+
model: Model<T>;
|
|
159
|
+
options: GoogleSharedStreamOptions | undefined;
|
|
160
|
+
api: T;
|
|
161
|
+
retainTextSignature?: boolean;
|
|
162
|
+
prepare: () => GoogleGenAIRequestPlan | Promise<GoogleGenAIRequestPlan>;
|
|
163
|
+
}): AssistantMessageEventStream;
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
/** Mirror of `@google/genai`'s `FinishReason` string enum. */
|
|
13
|
+
export type FinishReason = "FINISH_REASON_UNSPECIFIED" | "STOP" | "MAX_TOKENS" | "SAFETY" | "RECITATION" | "LANGUAGE" | "OTHER" | "BLOCKLIST" | "PROHIBITED_CONTENT" | "SPII" | "MALFORMED_FUNCTION_CALL" | "IMAGE_SAFETY" | "IMAGE_PROHIBITED_CONTENT" | "IMAGE_RECITATION" | "IMAGE_OTHER" | "UNEXPECTED_TOOL_CALL" | "NO_IMAGE";
|
|
14
|
+
/** Mirror of `@google/genai`'s `FunctionCallingConfigMode` string enum. */
|
|
15
|
+
export type FunctionCallingConfigMode = "MODE_UNSPECIFIED" | "AUTO" | "NONE" | "ANY" | "VALIDATED";
|
|
16
|
+
/** Mirror of `@google/genai`'s `ThinkingLevel` string enum. */
|
|
17
|
+
export type ThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH";
|
|
18
|
+
/** Inline base64-encoded data part. */
|
|
19
|
+
export interface InlineDataPart {
|
|
20
|
+
mimeType: string;
|
|
21
|
+
data: string;
|
|
22
|
+
}
|
|
23
|
+
/** Function call emitted by the model. */
|
|
24
|
+
export interface FunctionCallPart {
|
|
25
|
+
name?: string;
|
|
26
|
+
args?: Record<string, unknown>;
|
|
27
|
+
id?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Tool execution result fed back to the model. */
|
|
30
|
+
export interface FunctionResponsePart {
|
|
31
|
+
name: string;
|
|
32
|
+
response: Record<string, unknown>;
|
|
33
|
+
parts?: Part[];
|
|
34
|
+
id?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A single piece of a `Content` message. Mirrors the SDK's union by keeping
|
|
38
|
+
* every optional field — the model and the wire treat shape as discriminator.
|
|
39
|
+
*/
|
|
40
|
+
export interface Part {
|
|
41
|
+
text?: string;
|
|
42
|
+
thought?: boolean;
|
|
43
|
+
thoughtSignature?: string;
|
|
44
|
+
inlineData?: InlineDataPart;
|
|
45
|
+
functionCall?: FunctionCallPart;
|
|
46
|
+
functionResponse?: FunctionResponsePart;
|
|
47
|
+
}
|
|
48
|
+
/** Conversation turn. Roles: `"user"`, `"model"`, optionally absent for system instructions. */
|
|
49
|
+
export interface Content {
|
|
50
|
+
role?: string;
|
|
51
|
+
parts?: Part[];
|
|
52
|
+
}
|
|
53
|
+
/** Thinking/reasoning configuration shared by Gemini 2.x and 3.x models. */
|
|
54
|
+
export interface ThinkingConfig {
|
|
55
|
+
includeThoughts?: boolean;
|
|
56
|
+
thinkingBudget?: number;
|
|
57
|
+
thinkingLevel?: ThinkingLevel;
|
|
58
|
+
}
|
|
59
|
+
/** Function declaration entry inside `tools[].functionDeclarations`. */
|
|
60
|
+
export interface FunctionDeclaration {
|
|
61
|
+
name: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
parameters?: Record<string, unknown>;
|
|
64
|
+
parametersJsonSchema?: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
/** Tool group as accepted at the request top level. */
|
|
67
|
+
export interface ToolDeclaration {
|
|
68
|
+
functionDeclarations: Record<string, unknown>[];
|
|
69
|
+
}
|
|
70
|
+
/** Tool selection mode container. */
|
|
71
|
+
export interface ToolConfig {
|
|
72
|
+
functionCallingConfig?: {
|
|
73
|
+
mode: FunctionCallingConfigMode;
|
|
74
|
+
allowedFunctionNames?: string[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generation/sampling and request-shape options passed via the SDK's `config`.
|
|
79
|
+
*
|
|
80
|
+
* Fields that the wire format places at the request body root (systemInstruction,
|
|
81
|
+
* tools, toolConfig, safetySettings, cachedContent) live here too — the
|
|
82
|
+
* transformer in `google-shared.ts` lifts them out when serializing.
|
|
83
|
+
*/
|
|
84
|
+
export interface GenerateContentConfig {
|
|
85
|
+
temperature?: number;
|
|
86
|
+
maxOutputTokens?: number;
|
|
87
|
+
topP?: number;
|
|
88
|
+
topK?: number;
|
|
89
|
+
candidateCount?: number;
|
|
90
|
+
stopSequences?: string[];
|
|
91
|
+
presencePenalty?: number;
|
|
92
|
+
frequencyPenalty?: number;
|
|
93
|
+
seed?: number;
|
|
94
|
+
responseMimeType?: string;
|
|
95
|
+
responseSchema?: Record<string, unknown>;
|
|
96
|
+
responseJsonSchema?: Record<string, unknown>;
|
|
97
|
+
responseModalities?: string[];
|
|
98
|
+
systemInstruction?: Content | {
|
|
99
|
+
role?: string;
|
|
100
|
+
parts: {
|
|
101
|
+
text: string;
|
|
102
|
+
}[];
|
|
103
|
+
};
|
|
104
|
+
tools?: ToolDeclaration[];
|
|
105
|
+
toolConfig?: ToolConfig;
|
|
106
|
+
safetySettings?: Array<Record<string, unknown>>;
|
|
107
|
+
cachedContent?: string;
|
|
108
|
+
thinkingConfig?: ThinkingConfig;
|
|
109
|
+
abortSignal?: AbortSignal;
|
|
110
|
+
}
|
|
111
|
+
/** Top-level argument to `generateContentStream`. */
|
|
112
|
+
export interface GenerateContentParameters {
|
|
113
|
+
model: string;
|
|
114
|
+
contents: Content[];
|
|
115
|
+
config?: GenerateContentConfig;
|
|
116
|
+
}
|
|
117
|
+
/** Per-stream candidate envelope. */
|
|
118
|
+
export interface Candidate {
|
|
119
|
+
content?: Content;
|
|
120
|
+
finishReason?: FinishReason;
|
|
121
|
+
index?: number;
|
|
122
|
+
}
|
|
123
|
+
/** Cumulative token accounting attached to the trailing chunk. */
|
|
124
|
+
export interface UsageMetadata {
|
|
125
|
+
promptTokenCount?: number;
|
|
126
|
+
candidatesTokenCount?: number;
|
|
127
|
+
thoughtsTokenCount?: number;
|
|
128
|
+
totalTokenCount?: number;
|
|
129
|
+
cachedContentTokenCount?: number;
|
|
130
|
+
}
|
|
131
|
+
/** Single SSE chunk's parsed JSON body. */
|
|
132
|
+
export interface GenerateContentResponse {
|
|
133
|
+
candidates?: Candidate[];
|
|
134
|
+
usageMetadata?: UsageMetadata;
|
|
135
|
+
modelVersion?: string;
|
|
136
|
+
responseId?: string;
|
|
137
|
+
promptFeedback?: Record<string, unknown>;
|
|
138
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StreamFunction } from "../types";
|
|
2
|
+
import { type GoogleSharedStreamOptions } from "./google-shared";
|
|
3
|
+
export interface GoogleVertexOptions extends GoogleSharedStreamOptions {
|
|
4
|
+
project?: string;
|
|
5
|
+
location?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const streamGoogleVertex: StreamFunction<"google-vertex">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compactGrammarDefinition(syntax: "lark" | "regex", definition: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import type { Api, Context, Model } from "../types";
|
|
12
|
+
import type { AssistantMessageEventStream } from "../utils/event-stream";
|
|
13
|
+
import { type OpenAIAnthropicApiFormat, type OpenAIAnthropicShimOptions } from "./openai-anthropic-shim";
|
|
14
|
+
export type KimiApiFormat = OpenAIAnthropicApiFormat;
|
|
15
|
+
export interface KimiOptions extends OpenAIAnthropicShimOptions {
|
|
16
|
+
/** API format: "openai" or "anthropic". Default: "anthropic" */
|
|
17
|
+
format?: KimiApiFormat;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Stream from Kimi Code, routing to either OpenAI or Anthropic API based on format.
|
|
21
|
+
* Returns synchronously like other providers - async header fetching happens internally.
|
|
22
|
+
*/
|
|
23
|
+
export declare function streamKimi(model: Model<"openai-completions">, context: Context, options?: KimiOptions): AssistantMessageEventStream;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a model is a Kimi Code model.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isKimiModel(model: Model<Api>): boolean;
|