oh-my-opencode 0.3.3 → 0.4.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.
Files changed (52) hide show
  1. package/README.ko.md +162 -37
  2. package/README.md +160 -35
  3. package/dist/auth/antigravity/constants.d.ts +36 -0
  4. package/dist/auth/antigravity/fetch.d.ts +68 -0
  5. package/dist/auth/antigravity/index.d.ts +13 -0
  6. package/dist/auth/antigravity/message-converter.d.ts +54 -0
  7. package/dist/auth/antigravity/oauth.d.ts +85 -0
  8. package/dist/auth/antigravity/plugin.d.ts +54 -0
  9. package/dist/auth/antigravity/project.d.ts +20 -0
  10. package/dist/auth/antigravity/request.d.ts +104 -0
  11. package/dist/auth/antigravity/response.d.ts +137 -0
  12. package/dist/auth/antigravity/thinking.d.ts +234 -0
  13. package/dist/auth/antigravity/thought-signature-store.d.ts +52 -0
  14. package/dist/auth/antigravity/token.d.ts +41 -0
  15. package/dist/auth/antigravity/tools.d.ts +119 -0
  16. package/dist/auth/antigravity/types.d.ts +173 -0
  17. package/dist/config/schema.d.ts +454 -80
  18. package/dist/features/background-agent/index.d.ts +2 -0
  19. package/dist/features/background-agent/manager.d.ts +37 -0
  20. package/dist/features/background-agent/types.d.ts +27 -0
  21. package/dist/google-auth.d.ts +3 -0
  22. package/dist/hooks/anthropic-auto-compact/types.d.ts +11 -0
  23. package/dist/hooks/auto-update-checker/cache.d.ts +1 -0
  24. package/dist/hooks/auto-update-checker/checker.d.ts +6 -0
  25. package/dist/hooks/auto-update-checker/constants.d.ts +8 -0
  26. package/dist/hooks/auto-update-checker/index.d.ts +12 -0
  27. package/dist/hooks/auto-update-checker/types.d.ts +19 -0
  28. package/dist/hooks/background-notification/index.d.ts +12 -0
  29. package/dist/hooks/background-notification/types.d.ts +4 -0
  30. package/dist/hooks/index.d.ts +3 -0
  31. package/dist/hooks/rules-injector/constants.d.ts +6 -0
  32. package/dist/hooks/rules-injector/finder.d.ts +45 -0
  33. package/dist/hooks/rules-injector/index.d.ts +22 -0
  34. package/dist/hooks/rules-injector/matcher.d.ts +21 -0
  35. package/dist/hooks/rules-injector/parser.d.ts +18 -0
  36. package/dist/hooks/rules-injector/storage.d.ts +9 -0
  37. package/dist/hooks/rules-injector/types.d.ts +41 -0
  38. package/dist/hooks/session-recovery/storage.d.ts +1 -0
  39. package/dist/index.js +4320 -1445
  40. package/dist/tools/ast-grep/index.d.ts +4 -4
  41. package/dist/tools/ast-grep/tools.d.ts +4 -4
  42. package/dist/tools/background-task/constants.d.ts +3 -0
  43. package/dist/tools/background-task/index.d.ts +3 -0
  44. package/dist/tools/background-task/tools.d.ts +39 -0
  45. package/dist/tools/background-task/types.d.ts +13 -0
  46. package/dist/tools/call-omo-agent/constants.d.ts +2 -0
  47. package/dist/tools/call-omo-agent/index.d.ts +3 -0
  48. package/dist/tools/call-omo-agent/tools.d.ts +22 -0
  49. package/dist/tools/call-omo-agent/types.d.ts +24 -0
  50. package/dist/tools/index.d.ts +47 -6
  51. package/dist/tools/lsp/tools.d.ts +2 -2
  52. package/package.json +11 -3
@@ -0,0 +1,54 @@
1
+ /**
2
+ * OpenAI → Gemini message format converter
3
+ *
4
+ * Converts OpenAI-style messages to Gemini contents format,
5
+ * injecting thoughtSignature into functionCall parts.
6
+ */
7
+ interface OpenAIMessage {
8
+ role: "system" | "user" | "assistant" | "tool";
9
+ content?: string | OpenAIContentPart[];
10
+ tool_calls?: OpenAIToolCall[];
11
+ tool_call_id?: string;
12
+ name?: string;
13
+ }
14
+ interface OpenAIContentPart {
15
+ type: string;
16
+ text?: string;
17
+ image_url?: {
18
+ url: string;
19
+ };
20
+ [key: string]: unknown;
21
+ }
22
+ interface OpenAIToolCall {
23
+ id: string;
24
+ type: "function";
25
+ function: {
26
+ name: string;
27
+ arguments: string;
28
+ };
29
+ }
30
+ interface GeminiPart {
31
+ text?: string;
32
+ functionCall?: {
33
+ name: string;
34
+ args: Record<string, unknown>;
35
+ };
36
+ functionResponse?: {
37
+ name: string;
38
+ response: Record<string, unknown>;
39
+ };
40
+ inlineData?: {
41
+ mimeType: string;
42
+ data: string;
43
+ };
44
+ thought_signature?: string;
45
+ [key: string]: unknown;
46
+ }
47
+ interface GeminiContent {
48
+ role: "user" | "model";
49
+ parts: GeminiPart[];
50
+ }
51
+ export declare function convertOpenAIToGemini(messages: OpenAIMessage[], thoughtSignature?: string): GeminiContent[];
52
+ export declare function hasOpenAIMessages(body: Record<string, unknown>): boolean;
53
+ export declare function convertRequestBody(body: Record<string, unknown>, thoughtSignature?: string): Record<string, unknown>;
54
+ export {};
@@ -0,0 +1,85 @@
1
+ import type { AntigravityTokenExchangeResult, AntigravityUserInfo } from "./types";
2
+ /**
3
+ * PKCE pair containing verifier and challenge.
4
+ */
5
+ export interface PKCEPair {
6
+ /** PKCE verifier - used during token exchange */
7
+ verifier: string;
8
+ /** PKCE challenge - sent in auth URL */
9
+ challenge: string;
10
+ /** Challenge method - always "S256" */
11
+ method: string;
12
+ }
13
+ /**
14
+ * OAuth state encoded in the auth URL.
15
+ * Contains the PKCE verifier for later retrieval.
16
+ */
17
+ export interface OAuthState {
18
+ /** PKCE verifier */
19
+ verifier: string;
20
+ /** Optional project ID */
21
+ projectId?: string;
22
+ }
23
+ /**
24
+ * Result from building an OAuth authorization URL.
25
+ */
26
+ export interface AuthorizationResult {
27
+ /** Full OAuth URL to open in browser */
28
+ url: string;
29
+ /** PKCE verifier to use during code exchange */
30
+ verifier: string;
31
+ }
32
+ /**
33
+ * Result from the OAuth callback server.
34
+ */
35
+ export interface CallbackResult {
36
+ /** Authorization code from Google */
37
+ code: string;
38
+ /** State parameter from callback */
39
+ state: string;
40
+ /** Error message if any */
41
+ error?: string;
42
+ }
43
+ /**
44
+ * Generate PKCE verifier and challenge pair.
45
+ * Uses @openauthjs/openauth for cryptographically secure generation.
46
+ *
47
+ * @returns PKCE pair with verifier, challenge, and method
48
+ */
49
+ export declare function generatePKCEPair(): Promise<PKCEPair>;
50
+ /**
51
+ * Decode OAuth state from a base64 string.
52
+ *
53
+ * @param encoded - Base64URL or Base64 encoded state
54
+ * @returns Decoded OAuth state
55
+ */
56
+ export declare function decodeState(encoded: string): OAuthState;
57
+ export declare function buildAuthURL(projectId?: string, clientId?: string, port?: number): Promise<AuthorizationResult>;
58
+ /**
59
+ * Exchange authorization code for tokens.
60
+ *
61
+ * @param code - Authorization code from OAuth callback
62
+ * @param verifier - PKCE verifier from initial auth request
63
+ * @param clientId - Optional custom client ID (defaults to ANTIGRAVITY_CLIENT_ID)
64
+ * @param clientSecret - Optional custom client secret (defaults to ANTIGRAVITY_CLIENT_SECRET)
65
+ * @returns Token exchange result with access and refresh tokens
66
+ */
67
+ export declare function exchangeCode(code: string, verifier: string, clientId?: string, clientSecret?: string, port?: number): Promise<AntigravityTokenExchangeResult>;
68
+ /**
69
+ * Fetch user info from Google's userinfo API.
70
+ *
71
+ * @param accessToken - Valid access token
72
+ * @returns User info containing email
73
+ */
74
+ export declare function fetchUserInfo(accessToken: string): Promise<AntigravityUserInfo>;
75
+ export interface CallbackServerHandle {
76
+ port: number;
77
+ waitForCallback: () => Promise<CallbackResult>;
78
+ close: () => void;
79
+ }
80
+ export declare function startCallbackServer(timeoutMs?: number): CallbackServerHandle;
81
+ export declare function performOAuthFlow(projectId?: string, openBrowser?: (url: string) => Promise<void>, clientId?: string, clientSecret?: string): Promise<{
82
+ tokens: AntigravityTokenExchangeResult;
83
+ userInfo: AntigravityUserInfo;
84
+ verifier: string;
85
+ }>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Google Antigravity Auth Plugin for OpenCode
3
+ *
4
+ * Provides OAuth authentication for Google models via Antigravity API.
5
+ * This plugin integrates with OpenCode's auth system to enable:
6
+ * - OAuth 2.0 with PKCE flow for Google authentication
7
+ * - Automatic token refresh
8
+ * - Request/response transformation for Antigravity API
9
+ *
10
+ * @example
11
+ * ```json
12
+ * // opencode.json
13
+ * {
14
+ * "plugin": ["oh-my-opencode"],
15
+ * "provider": {
16
+ * "google": {
17
+ * "options": {
18
+ * "clientId": "custom-client-id",
19
+ * "clientSecret": "custom-client-secret"
20
+ * }
21
+ * }
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ import type { AuthHook, PluginInput } from "@opencode-ai/plugin";
27
+ /**
28
+ * Creates the Google Antigravity OAuth plugin for OpenCode.
29
+ *
30
+ * This factory function creates an auth plugin that:
31
+ * 1. Provides OAuth flow for Google authentication
32
+ * 2. Creates a custom fetch interceptor for Antigravity API
33
+ * 3. Handles token management and refresh
34
+ *
35
+ * @param input - Plugin input containing the OpenCode client
36
+ * @returns Hooks object with auth configuration
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Used by OpenCode automatically when plugin is loaded
41
+ * const hooks = await createGoogleAntigravityAuthPlugin({ client, ... })
42
+ * ```
43
+ */
44
+ export declare function createGoogleAntigravityAuthPlugin({ client, }: PluginInput): Promise<{
45
+ auth: AuthHook;
46
+ }>;
47
+ /**
48
+ * Default export for OpenCode plugin system
49
+ */
50
+ export default createGoogleAntigravityAuthPlugin;
51
+ /**
52
+ * Named export for explicit imports
53
+ */
54
+ export declare const GoogleAntigravityAuthPlugin: typeof createGoogleAntigravityAuthPlugin;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Antigravity project context management.
3
+ * Handles fetching GCP project ID via Google's loadCodeAssist API.
4
+ */
5
+ import type { AntigravityProjectContext } from "./types";
6
+ /**
7
+ * Fetch project context from Google's loadCodeAssist API.
8
+ * Extracts the cloudaicompanionProject from the response.
9
+ *
10
+ * @param accessToken - Valid OAuth access token
11
+ * @returns Project context with cloudaicompanionProject ID
12
+ */
13
+ export declare function fetchProjectContext(accessToken: string): Promise<AntigravityProjectContext>;
14
+ /**
15
+ * Clear the project context cache.
16
+ * Call this when tokens are refreshed or invalidated.
17
+ *
18
+ * @param accessToken - Optional specific token to clear, or clears all if not provided
19
+ */
20
+ export declare function clearProjectContextCache(accessToken?: string): void;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Antigravity request transformer.
3
+ * Transforms OpenAI-format requests to Antigravity format.
4
+ * Does NOT handle tool normalization (handled by tools.ts in Task 9).
5
+ */
6
+ import type { AntigravityRequestBody } from "./types";
7
+ /**
8
+ * Result of request transformation including URL, headers, and body.
9
+ */
10
+ export interface TransformedRequest {
11
+ /** Transformed URL for Antigravity API */
12
+ url: string;
13
+ /** Request headers including Authorization and Antigravity-specific headers */
14
+ headers: Record<string, string>;
15
+ /** Transformed request body in Antigravity format */
16
+ body: AntigravityRequestBody;
17
+ /** Whether this is a streaming request */
18
+ streaming: boolean;
19
+ }
20
+ /**
21
+ * Build Antigravity-specific request headers.
22
+ * Includes Authorization, User-Agent, X-Goog-Api-Client, and Client-Metadata.
23
+ *
24
+ * @param accessToken - OAuth access token for Authorization header
25
+ * @returns Headers object with all required Antigravity headers
26
+ */
27
+ export declare function buildRequestHeaders(accessToken: string): Record<string, string>;
28
+ /**
29
+ * Extract model name from request body.
30
+ * OpenAI-format requests include model in the body.
31
+ *
32
+ * @param body - Request body that may contain a model field
33
+ * @returns Model name or undefined if not found
34
+ */
35
+ export declare function extractModelFromBody(body: Record<string, unknown>): string | undefined;
36
+ /**
37
+ * Extract model name from URL path.
38
+ * Handles Google Generative Language API format: /models/{model}:{action}
39
+ *
40
+ * @param url - Request URL to parse
41
+ * @returns Model name or undefined if not found
42
+ */
43
+ export declare function extractModelFromUrl(url: string): string | undefined;
44
+ /**
45
+ * Determine the action type from the URL path.
46
+ * E.g., generateContent, streamGenerateContent
47
+ *
48
+ * @param url - Request URL to parse
49
+ * @returns Action name or undefined if not found
50
+ */
51
+ export declare function extractActionFromUrl(url: string): string | undefined;
52
+ /**
53
+ * Check if a URL is targeting Google's Generative Language API.
54
+ *
55
+ * @param url - URL to check
56
+ * @returns true if this is a Google Generative Language API request
57
+ */
58
+ export declare function isGenerativeLanguageRequest(url: string): boolean;
59
+ /**
60
+ * Build Antigravity API URL for the given action.
61
+ *
62
+ * @param baseEndpoint - Base Antigravity endpoint URL (from fallbacks)
63
+ * @param action - API action (e.g., generateContent, streamGenerateContent)
64
+ * @param streaming - Whether to append SSE query parameter
65
+ * @returns Formatted Antigravity API URL
66
+ */
67
+ export declare function buildAntigravityUrl(baseEndpoint: string, action: string, streaming: boolean): string;
68
+ /**
69
+ * Get the first available Antigravity endpoint.
70
+ * Can be used with fallback logic in fetch.ts.
71
+ *
72
+ * @returns Default (first) Antigravity endpoint
73
+ */
74
+ export declare function getDefaultEndpoint(): string;
75
+ export declare function wrapRequestBody(body: Record<string, unknown>, projectId: string, modelName: string, sessionId: string): AntigravityRequestBody;
76
+ export declare function injectThoughtSignatureIntoFunctionCalls(body: Record<string, unknown>, signature: string | undefined): Record<string, unknown>;
77
+ /**
78
+ * Detect if request is for streaming.
79
+ * Checks both action name and request body for stream flag.
80
+ *
81
+ * @param url - Request URL
82
+ * @param body - Request body
83
+ * @returns true if streaming is requested
84
+ */
85
+ export declare function isStreamingRequest(url: string, body: Record<string, unknown>): boolean;
86
+ export interface TransformRequestOptions {
87
+ url: string;
88
+ body: Record<string, unknown>;
89
+ accessToken: string;
90
+ projectId: string;
91
+ sessionId: string;
92
+ modelName?: string;
93
+ endpointOverride?: string;
94
+ thoughtSignature?: string;
95
+ }
96
+ export declare function transformRequest(options: TransformRequestOptions): TransformedRequest;
97
+ /**
98
+ * Prepare request headers for streaming responses.
99
+ * Adds Accept header for SSE format.
100
+ *
101
+ * @param headers - Existing headers object
102
+ * @returns Headers with streaming support
103
+ */
104
+ export declare function addStreamingHeaders(headers: Record<string, string>): Record<string, string>;
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Antigravity Response Handler
3
+ * Transforms Antigravity/Gemini API responses to OpenAI-compatible format
4
+ *
5
+ * Key responsibilities:
6
+ * - Non-streaming response transformation
7
+ * - SSE streaming response transformation (buffered - see transformStreamingResponse)
8
+ * - Error response handling with retry-after extraction
9
+ * - Usage metadata extraction from x-antigravity-* headers
10
+ */
11
+ import type { AntigravityError, AntigravityUsage } from "./types";
12
+ /**
13
+ * Usage metadata extracted from Antigravity response headers
14
+ */
15
+ export interface AntigravityUsageMetadata {
16
+ cachedContentTokenCount?: number;
17
+ totalTokenCount?: number;
18
+ promptTokenCount?: number;
19
+ candidatesTokenCount?: number;
20
+ }
21
+ /**
22
+ * Transform result with response and metadata
23
+ */
24
+ export interface TransformResult {
25
+ response: Response;
26
+ usage?: AntigravityUsageMetadata;
27
+ retryAfterMs?: number;
28
+ error?: AntigravityError;
29
+ }
30
+ /**
31
+ * Extract usage metadata from Antigravity response headers
32
+ *
33
+ * Antigravity sets these headers:
34
+ * - x-antigravity-cached-content-token-count
35
+ * - x-antigravity-total-token-count
36
+ * - x-antigravity-prompt-token-count
37
+ * - x-antigravity-candidates-token-count
38
+ *
39
+ * @param headers - Response headers
40
+ * @returns Usage metadata if found
41
+ */
42
+ export declare function extractUsageFromHeaders(headers: Headers): AntigravityUsageMetadata | undefined;
43
+ /**
44
+ * Extract retry-after value from error response
45
+ *
46
+ * Antigravity returns retry info in error.details array:
47
+ * {
48
+ * error: {
49
+ * details: [{
50
+ * "@type": "type.googleapis.com/google.rpc.RetryInfo",
51
+ * "retryDelay": "5.123s"
52
+ * }]
53
+ * }
54
+ * }
55
+ *
56
+ * Also checks standard Retry-After header.
57
+ *
58
+ * @param response - Response object (for headers)
59
+ * @param errorBody - Parsed error body (optional)
60
+ * @returns Retry after value in milliseconds, or undefined
61
+ */
62
+ export declare function extractRetryAfterMs(response: Response, errorBody?: Record<string, unknown>): number | undefined;
63
+ /**
64
+ * Parse error response body and extract useful details
65
+ *
66
+ * @param text - Raw response text
67
+ * @returns Parsed error or undefined
68
+ */
69
+ export declare function parseErrorBody(text: string): AntigravityError | undefined;
70
+ /**
71
+ * Transform a non-streaming Antigravity response to OpenAI-compatible format
72
+ *
73
+ * For non-streaming responses:
74
+ * - Parses the response body
75
+ * - Unwraps the `response` field if present (Antigravity wraps responses)
76
+ * - Extracts usage metadata from headers
77
+ * - Handles error responses
78
+ *
79
+ * Note: Does NOT handle thinking block extraction (Task 10)
80
+ * Note: Does NOT handle tool normalization (Task 9)
81
+ *
82
+ * @param response - Fetch Response object
83
+ * @returns TransformResult with transformed response and metadata
84
+ */
85
+ export declare function transformResponse(response: Response): Promise<TransformResult>;
86
+ /**
87
+ * Transform SSE streaming payload
88
+ *
89
+ * Processes each line in the SSE stream:
90
+ * - Unwraps { response: { ... } } wrapper from data lines
91
+ * - Preserves other SSE control lines (event:, id:, retry:, empty lines)
92
+ *
93
+ * Note: Does NOT extract thinking blocks (Task 10)
94
+ *
95
+ * @param payload - Raw SSE payload text
96
+ * @returns Transformed SSE payload
97
+ */
98
+ export declare function transformStreamingPayload(payload: string): string;
99
+ /**
100
+ * Transforms a streaming SSE response from Antigravity to OpenAI format.
101
+ *
102
+ * Uses TransformStream to process SSE chunks incrementally as they arrive.
103
+ * Each line is transformed immediately and yielded to the client.
104
+ *
105
+ * @param response - The SSE response from Antigravity API
106
+ * @returns TransformResult with transformed streaming response
107
+ */
108
+ export declare function transformStreamingResponse(response: Response): Promise<TransformResult>;
109
+ /**
110
+ * Check if response is a streaming SSE response
111
+ *
112
+ * @param response - Fetch Response object
113
+ * @returns True if response is SSE stream
114
+ */
115
+ export declare function isStreamingResponse(response: Response): boolean;
116
+ /**
117
+ * Extract thought signature from SSE payload text
118
+ *
119
+ * Looks for thoughtSignature in SSE events:
120
+ * data: { "response": { "candidates": [{ "content": { "parts": [{ "thoughtSignature": "..." }] } }] } }
121
+ *
122
+ * Returns the last found signature (most recent in the stream).
123
+ *
124
+ * @param payload - SSE payload text
125
+ * @returns Last thought signature if found
126
+ */
127
+ export declare function extractSignatureFromSsePayload(payload: string): string | undefined;
128
+ /**
129
+ * Extract usage from SSE payload text
130
+ *
131
+ * Looks for usageMetadata in SSE events:
132
+ * data: { "usageMetadata": { ... } }
133
+ *
134
+ * @param payload - SSE payload text
135
+ * @returns Usage if found
136
+ */
137
+ export declare function extractUsageFromSsePayload(payload: string): AntigravityUsage | undefined;
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Antigravity Thinking Block Handler (Gemini only)
3
+ *
4
+ * Handles extraction and transformation of thinking/reasoning blocks
5
+ * from Gemini responses. Thinking blocks contain the model's internal
6
+ * reasoning process, available in `-high` model variants.
7
+ *
8
+ * Key responsibilities:
9
+ * - Extract thinking blocks from Gemini response format
10
+ * - Detect thinking-capable model variants (`-high` suffix)
11
+ * - Format thinking blocks for OpenAI-compatible output
12
+ *
13
+ * Note: This is Gemini-only. Claude models are NOT handled by Antigravity.
14
+ */
15
+ /**
16
+ * Represents a single thinking/reasoning block extracted from Gemini response
17
+ */
18
+ export interface ThinkingBlock {
19
+ /** The thinking/reasoning text content */
20
+ text: string;
21
+ /** Optional signature for signed thinking blocks (required for multi-turn) */
22
+ signature?: string;
23
+ /** Index of the thinking block in sequence */
24
+ index?: number;
25
+ }
26
+ /**
27
+ * Raw part structure from Gemini response candidates
28
+ */
29
+ export interface GeminiPart {
30
+ /** Text content of the part */
31
+ text?: string;
32
+ /** Whether this part is a thinking/reasoning block */
33
+ thought?: boolean;
34
+ /** Signature for signed thinking blocks */
35
+ thoughtSignature?: string;
36
+ /** Type field for Anthropic-style format */
37
+ type?: string;
38
+ /** Signature field for Anthropic-style format */
39
+ signature?: string;
40
+ }
41
+ /**
42
+ * Gemini response candidate structure
43
+ */
44
+ export interface GeminiCandidate {
45
+ /** Content containing parts */
46
+ content?: {
47
+ /** Role of the content (e.g., "model", "assistant") */
48
+ role?: string;
49
+ /** Array of content parts */
50
+ parts?: GeminiPart[];
51
+ };
52
+ /** Index of the candidate */
53
+ index?: number;
54
+ }
55
+ /**
56
+ * Gemini response structure for thinking block extraction
57
+ */
58
+ export interface GeminiResponse {
59
+ /** Response ID */
60
+ id?: string;
61
+ /** Array of response candidates */
62
+ candidates?: GeminiCandidate[];
63
+ /** Direct content (some responses use this instead of candidates) */
64
+ content?: Array<{
65
+ type?: string;
66
+ text?: string;
67
+ signature?: string;
68
+ }>;
69
+ /** Model used for response */
70
+ model?: string;
71
+ }
72
+ /**
73
+ * Result of thinking block extraction
74
+ */
75
+ export interface ThinkingExtractionResult {
76
+ /** Extracted thinking blocks */
77
+ thinkingBlocks: ThinkingBlock[];
78
+ /** Combined thinking text for convenience */
79
+ combinedThinking: string;
80
+ /** Whether any thinking blocks were found */
81
+ hasThinking: boolean;
82
+ }
83
+ /**
84
+ * Default thinking budget in tokens for thinking-enabled models
85
+ */
86
+ export declare const DEFAULT_THINKING_BUDGET = 16000;
87
+ /**
88
+ * Check if a model variant should include thinking blocks
89
+ *
90
+ * Returns true for model variants with `-high` suffix, which have
91
+ * extended thinking capability enabled.
92
+ *
93
+ * Examples:
94
+ * - `gemini-3-pro-high` → true
95
+ * - `gemini-2.5-pro-high` → true
96
+ * - `gemini-3-pro-preview` → false
97
+ * - `gemini-2.5-pro` → false
98
+ *
99
+ * @param model - Model identifier string
100
+ * @returns True if model should include thinking blocks
101
+ */
102
+ export declare function shouldIncludeThinking(model: string): boolean;
103
+ /**
104
+ * Check if a model is thinking-capable (broader check)
105
+ *
106
+ * This is a broader check than shouldIncludeThinking - it detects models
107
+ * that have thinking capability, even if not explicitly requesting thinking output.
108
+ *
109
+ * @param model - Model identifier string
110
+ * @returns True if model supports thinking/reasoning
111
+ */
112
+ export declare function isThinkingCapableModel(model: string): boolean;
113
+ /**
114
+ * Extract thinking blocks from a Gemini response
115
+ *
116
+ * Parses the response structure to identify and extract all thinking/reasoning
117
+ * content. Supports both Gemini-style (thought: true) and Anthropic-style
118
+ * (type: "thinking") formats.
119
+ *
120
+ * @param response - Gemini response object
121
+ * @returns Extraction result with thinking blocks and metadata
122
+ */
123
+ export declare function extractThinkingBlocks(response: GeminiResponse): ThinkingExtractionResult;
124
+ /**
125
+ * Format thinking blocks for OpenAI-compatible output
126
+ *
127
+ * Converts Gemini thinking block format to OpenAI's expected structure.
128
+ * OpenAI expects thinking content as special message blocks or annotations.
129
+ *
130
+ * Output format:
131
+ * ```
132
+ * [
133
+ * { type: "reasoning", text: "thinking content...", signature?: "..." },
134
+ * ...
135
+ * ]
136
+ * ```
137
+ *
138
+ * @param thinking - Array of thinking blocks to format
139
+ * @returns OpenAI-compatible formatted array
140
+ */
141
+ export declare function formatThinkingForOpenAI(thinking: ThinkingBlock[]): Array<{
142
+ type: "reasoning";
143
+ text: string;
144
+ signature?: string;
145
+ }>;
146
+ /**
147
+ * Transform thinking parts in a candidate to OpenAI format
148
+ *
149
+ * Modifies candidate content parts to use OpenAI-style reasoning format
150
+ * while preserving the rest of the response structure.
151
+ *
152
+ * @param candidate - Gemini candidate to transform
153
+ * @returns Transformed candidate with reasoning-formatted thinking
154
+ */
155
+ export declare function transformCandidateThinking(candidate: GeminiCandidate): GeminiCandidate;
156
+ /**
157
+ * Transform Anthropic-style thinking blocks to reasoning format
158
+ *
159
+ * Converts `type: "thinking"` blocks to `type: "reasoning"` for consistency.
160
+ *
161
+ * @param content - Array of content blocks
162
+ * @returns Transformed content array
163
+ */
164
+ export declare function transformAnthropicThinking(content: Array<{
165
+ type?: string;
166
+ text?: string;
167
+ signature?: string;
168
+ }>): Array<{
169
+ type?: string;
170
+ text?: string;
171
+ signature?: string;
172
+ }>;
173
+ /**
174
+ * Filter out unsigned thinking blocks
175
+ *
176
+ * Claude API requires signed thinking blocks for multi-turn conversations.
177
+ * This function removes thinking blocks without valid signatures.
178
+ *
179
+ * @param parts - Array of content parts
180
+ * @returns Filtered array without unsigned thinking blocks
181
+ */
182
+ export declare function filterUnsignedThinkingBlocks(parts: GeminiPart[]): GeminiPart[];
183
+ /**
184
+ * Transform entire response thinking parts
185
+ *
186
+ * Main transformation function that handles both Gemini-style and
187
+ * Anthropic-style thinking blocks in a response.
188
+ *
189
+ * @param response - Response object to transform
190
+ * @returns Transformed response with standardized reasoning format
191
+ */
192
+ export declare function transformResponseThinking(response: GeminiResponse): GeminiResponse;
193
+ /**
194
+ * Thinking configuration for requests
195
+ */
196
+ export interface ThinkingConfig {
197
+ /** Token budget for thinking/reasoning */
198
+ thinkingBudget?: number;
199
+ /** Whether to include thoughts in response */
200
+ includeThoughts?: boolean;
201
+ }
202
+ /**
203
+ * Normalize thinking configuration
204
+ *
205
+ * Ensures thinkingConfig is valid: includeThoughts only allowed when budget > 0.
206
+ *
207
+ * @param config - Raw thinking configuration
208
+ * @returns Normalized configuration or undefined
209
+ */
210
+ export declare function normalizeThinkingConfig(config: unknown): ThinkingConfig | undefined;
211
+ /**
212
+ * Extract thinking configuration from request payload
213
+ *
214
+ * Supports both Gemini-style thinkingConfig and Anthropic-style thinking options.
215
+ *
216
+ * @param requestPayload - Request body
217
+ * @param generationConfig - Generation config from request
218
+ * @param extraBody - Extra body options
219
+ * @returns Extracted thinking configuration or undefined
220
+ */
221
+ export declare function extractThinkingConfig(requestPayload: Record<string, unknown>, generationConfig?: Record<string, unknown>, extraBody?: Record<string, unknown>): ThinkingConfig | undefined;
222
+ /**
223
+ * Resolve final thinking configuration based on model and context
224
+ *
225
+ * Handles special cases like Claude models requiring signed thinking blocks
226
+ * for multi-turn conversations.
227
+ *
228
+ * @param userConfig - User-provided thinking configuration
229
+ * @param isThinkingModel - Whether model supports thinking
230
+ * @param isClaudeModel - Whether model is Claude (not used in Antigravity, but kept for compatibility)
231
+ * @param hasAssistantHistory - Whether conversation has assistant history
232
+ * @returns Final thinking configuration
233
+ */
234
+ export declare function resolveThinkingConfig(userConfig: ThinkingConfig | undefined, isThinkingModel: boolean, isClaudeModel: boolean, hasAssistantHistory: boolean): ThinkingConfig | undefined;