@tanstack/ai-gemini 0.18.1 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/adapters/audio.d.ts +92 -0
- package/dist/esm/adapters/audio.js +66 -0
- package/dist/esm/adapters/audio.js.map +1 -0
- package/dist/esm/adapters/image.d.ts +101 -0
- package/dist/esm/adapters/image.js +253 -0
- package/dist/esm/adapters/image.js.map +1 -0
- package/dist/esm/adapters/summarize.d.ts +33 -0
- package/dist/esm/adapters/summarize.js +18 -0
- package/dist/esm/adapters/summarize.js.map +1 -0
- package/dist/esm/adapters/text.d.ts +85 -0
- package/dist/esm/adapters/text.js +658 -0
- package/dist/esm/adapters/text.js.map +1 -0
- package/dist/esm/adapters/tts.d.ts +165 -0
- package/dist/esm/adapters/tts.js +192 -0
- package/dist/esm/adapters/tts.js.map +1 -0
- package/dist/esm/adapters/video.d.ts +108 -0
- package/dist/esm/adapters/video.js +227 -0
- package/dist/esm/adapters/video.js.map +1 -0
- package/dist/esm/experimental/index.d.ts +6 -0
- package/dist/esm/experimental/index.js +7 -0
- package/dist/esm/experimental/index.js.map +1 -0
- package/dist/esm/experimental/text-interactions/adapter.d.ts +75 -0
- package/dist/esm/experimental/text-interactions/adapter.js +1052 -0
- package/dist/esm/experimental/text-interactions/adapter.js.map +1 -0
- package/dist/esm/experimental/text-interactions/events.d.ts +147 -0
- package/dist/esm/experimental/text-interactions/provider-options.d.ts +15 -0
- package/dist/esm/image/image-provider-options.d.ts +181 -0
- package/dist/esm/image/image-provider-options.js +67 -0
- package/dist/esm/image/image-provider-options.js.map +1 -0
- package/dist/esm/index.d.ts +33 -0
- package/dist/esm/index.js +38 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/message-types.d.ts +104 -0
- package/dist/esm/model-meta.d.ts +242 -0
- package/dist/esm/model-meta.js +159 -0
- package/dist/esm/model-meta.js.map +1 -0
- package/dist/esm/text/text-provider-options.d.ts +196 -0
- package/dist/esm/tools/code-execution-tool.d.ts +10 -0
- package/dist/esm/tools/code-execution-tool.js +18 -0
- package/dist/esm/tools/code-execution-tool.js.map +1 -0
- package/dist/esm/tools/computer-use-tool.d.ts +13 -0
- package/dist/esm/tools/computer-use-tool.js +33 -0
- package/dist/esm/tools/computer-use-tool.js.map +1 -0
- package/dist/esm/tools/file-search-tool.d.ts +10 -0
- package/dist/esm/tools/file-search-tool.js +19 -0
- package/dist/esm/tools/file-search-tool.js.map +1 -0
- package/dist/esm/tools/function-declaration-tool.d.ts +5 -0
- package/dist/esm/tools/function-declaration-tool.js +28 -0
- package/dist/esm/tools/function-declaration-tool.js.map +1 -0
- package/dist/esm/tools/google-maps-tool.d.ts +10 -0
- package/dist/esm/tools/google-maps-tool.js +19 -0
- package/dist/esm/tools/google-maps-tool.js.map +1 -0
- package/dist/esm/tools/google-search-retriveal-tool.d.ts +10 -0
- package/dist/esm/tools/google-search-retriveal-tool.js +19 -0
- package/dist/esm/tools/google-search-retriveal-tool.js.map +1 -0
- package/dist/esm/tools/google-search-tool.d.ts +10 -0
- package/dist/esm/tools/google-search-tool.js +19 -0
- package/dist/esm/tools/google-search-tool.js.map +1 -0
- package/dist/esm/tools/index.d.ts +18 -0
- package/dist/esm/tools/index.js +21 -0
- package/dist/esm/tools/index.js.map +1 -0
- package/dist/esm/tools/tool-converter.d.ts +22 -0
- package/dist/esm/tools/tool-converter.js +66 -0
- package/dist/esm/tools/tool-converter.js.map +1 -0
- package/dist/esm/tools/url-context-tool.d.ts +10 -0
- package/dist/esm/tools/url-context-tool.js +18 -0
- package/dist/esm/tools/url-context-tool.js.map +1 -0
- package/dist/esm/usage.d.ts +67 -0
- package/dist/esm/usage.js +94 -0
- package/dist/esm/usage.js.map +1 -0
- package/dist/esm/utils/client.d.ts +17 -0
- package/dist/esm/utils/client.js +30 -0
- package/dist/esm/utils/client.js.map +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/video/video-provider-options.d.ts +90 -0
- package/dist/esm/video/video-provider-options.js +15 -0
- package/dist/esm/video/video-provider-options.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { BaseTextAdapter, StructuredOutputOptions, StructuredOutputResult } from '@tanstack/ai/adapters';
|
|
2
|
+
import { GEMINI_MODELS, GeminiChatModelProviderOptionsByName, GeminiChatModelToolCapabilitiesByName, GeminiModelInputModalitiesByName } from '../model-meta.js';
|
|
3
|
+
import { Modality, StreamChunk, TextOptions } from '@tanstack/ai';
|
|
4
|
+
import { ExternalTextProviderOptions } from '../text/text-provider-options.js';
|
|
5
|
+
import { GeminiMessageMetadataByModality, GeminiToolCallMetadata } from '../message-types.js';
|
|
6
|
+
import { GeminiClientConfig } from '../utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for Gemini text adapter
|
|
9
|
+
*/
|
|
10
|
+
export interface GeminiTextConfig extends GeminiClientConfig {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gemini-specific provider options for text/chat
|
|
14
|
+
*/
|
|
15
|
+
export type GeminiTextProviderOptions = ExternalTextProviderOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve provider options for a specific model.
|
|
18
|
+
* If the model has explicit options in the map, use those; otherwise use base options.
|
|
19
|
+
*/
|
|
20
|
+
type ResolveProviderOptions<TModel extends string> = TModel extends keyof GeminiChatModelProviderOptionsByName ? GeminiChatModelProviderOptionsByName[TModel] : GeminiTextProviderOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve input modalities for a specific model.
|
|
23
|
+
* If the model has explicit modalities in the map, use those; otherwise use all modalities.
|
|
24
|
+
*/
|
|
25
|
+
type ResolveInputModalities<TModel extends string> = TModel extends keyof GeminiModelInputModalitiesByName ? GeminiModelInputModalitiesByName[TModel] : readonly ['text', 'image', 'audio', 'video', 'document'];
|
|
26
|
+
/**
|
|
27
|
+
* Resolve tool capabilities for a specific model.
|
|
28
|
+
* If the model has explicit tools in the map, use those; otherwise use empty tuple.
|
|
29
|
+
*/
|
|
30
|
+
type ResolveToolCapabilities<TModel extends string> = TModel extends keyof GeminiChatModelToolCapabilitiesByName ? NonNullable<GeminiChatModelToolCapabilitiesByName[TModel]> : readonly [];
|
|
31
|
+
/**
|
|
32
|
+
* Gemini Text (Chat) Adapter
|
|
33
|
+
*
|
|
34
|
+
* Tree-shakeable adapter for Gemini chat/text completion functionality.
|
|
35
|
+
* Import only what you need for smaller bundle sizes.
|
|
36
|
+
*/
|
|
37
|
+
export declare class GeminiTextAdapter<TModel extends (typeof GEMINI_MODELS)[number], TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>, TInputModalities extends ReadonlyArray<Modality> = ResolveInputModalities<TModel>, TToolCapabilities extends ReadonlyArray<string> = ResolveToolCapabilities<TModel>> extends BaseTextAdapter<TModel, TProviderOptions, TInputModalities, GeminiMessageMetadataByModality, TToolCapabilities, GeminiToolCallMetadata> {
|
|
38
|
+
readonly kind: "text";
|
|
39
|
+
readonly name: "gemini";
|
|
40
|
+
private readonly client;
|
|
41
|
+
constructor(config: GeminiTextConfig, model: TModel);
|
|
42
|
+
chatStream(options: TextOptions<GeminiTextProviderOptions>): AsyncIterable<StreamChunk>;
|
|
43
|
+
/**
|
|
44
|
+
* Generate structured output using Gemini's native JSON response format.
|
|
45
|
+
* Uses responseMimeType: 'application/json' and responseSchema for structured output.
|
|
46
|
+
* The outputSchema is already JSON Schema (converted in the ai layer).
|
|
47
|
+
*/
|
|
48
|
+
structuredOutput(options: StructuredOutputOptions<GeminiTextProviderOptions>): Promise<StructuredOutputResult<unknown>>;
|
|
49
|
+
/**
|
|
50
|
+
* Extract text content from a non-streaming response
|
|
51
|
+
*/
|
|
52
|
+
private extractTextFromResponse;
|
|
53
|
+
private processStreamChunks;
|
|
54
|
+
private convertContentPartToGemini;
|
|
55
|
+
private formatMessages;
|
|
56
|
+
/**
|
|
57
|
+
* Merge consecutive messages of the same role into a single message.
|
|
58
|
+
* Gemini's API requires strictly alternating user/model roles.
|
|
59
|
+
* Tool results are mapped to role:'user', which can collide with actual
|
|
60
|
+
* user messages in multi-turn conversations.
|
|
61
|
+
*
|
|
62
|
+
* Also filters out empty model messages (e.g., from a previous failed request)
|
|
63
|
+
* and deduplicates functionResponse parts with the same name (tool call ID).
|
|
64
|
+
*/
|
|
65
|
+
private mergeConsecutiveSameRoleMessages;
|
|
66
|
+
private mapCommonOptionsToGemini;
|
|
67
|
+
/**
|
|
68
|
+
* Gemini 3.x natively combines `tools` + `responseSchema` in a single
|
|
69
|
+
* streaming `generateContentStream` call (issue #605). Gemini 2.x is
|
|
70
|
+
* documented as brittle for the combination and keeps the engine's
|
|
71
|
+
* legacy finalization path.
|
|
72
|
+
*/
|
|
73
|
+
supportsCombinedToolsAndSchema(): boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a Gemini text adapter with explicit API key.
|
|
77
|
+
* Type resolution happens here at the call site.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createGeminiChat<TModel extends (typeof GEMINI_MODELS)[number]>(model: TModel, apiKey: string, config?: Omit<GeminiTextConfig, 'apiKey'>): GeminiTextAdapter<TModel, ResolveProviderOptions<TModel>, ResolveInputModalities<TModel>, ResolveToolCapabilities<TModel>>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a Gemini text adapter with automatic API key detection.
|
|
82
|
+
* Type resolution happens here at the call site.
|
|
83
|
+
*/
|
|
84
|
+
export declare function geminiText<TModel extends (typeof GEMINI_MODELS)[number]>(model: TModel, config?: Omit<GeminiTextConfig, 'apiKey'>): GeminiTextAdapter<TModel, ResolveProviderOptions<TModel>, ResolveInputModalities<TModel>, ResolveToolCapabilities<TModel>>;
|
|
85
|
+
export {};
|