@tanstack/ai-gemini 0.24.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/utils/client.d.ts +5 -4
- package/dist/esm/utils/client.js +6 -5
- package/dist/esm/utils/client.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/utils/client.ts +15 -8
package/dist/esm/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export { GEMINI_EMBEDDING_MODELS } from './model-meta.js';
|
|
|
32
32
|
export type { GeminiModels as GeminiTextModel } from './model-meta.js';
|
|
33
33
|
export type { GeminiImageModels as GeminiImageModel } from './model-meta.js';
|
|
34
34
|
export type { GeminiTTSVoice } from './model-meta.js';
|
|
35
|
+
export type { GeminiClientConfig } from './utils/client.js';
|
|
35
36
|
export type { GeminiChatModelProviderOptionsByName, GeminiChatModelToolCapabilitiesByName, GeminiModelInputModalitiesByName, GeminiEmbeddingModel, GeminiEmbeddingModelProviderOptionsByName, GeminiEmbeddingModelInputModalitiesByName, } from './model-meta.js';
|
|
36
37
|
export type { GeminiStructuredOutputOptions, GeminiThinkingOptions, } from './text/text-provider-options.js';
|
|
37
38
|
export type { GoogleGeminiTool } from './tools/index.js';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GoogleGenAI, GoogleGenAIOptions } from '@google/genai';
|
|
2
|
-
export
|
|
3
|
-
apiKey: string;
|
|
4
|
-
}
|
|
2
|
+
export type GeminiClientConfig = GoogleGenAIOptions;
|
|
5
3
|
/**
|
|
6
|
-
* Creates a Google Generative AI client instance
|
|
4
|
+
* Creates a Google Generative AI client instance.
|
|
5
|
+
*
|
|
6
|
+
* AI Studio mode needs `apiKey`. Vertex / Enterprise mode (`vertexai` or
|
|
7
|
+
* `enterprise`) uses project, location, and Google Cloud credentials instead.
|
|
7
8
|
*/
|
|
8
9
|
export declare function createGeminiClient(config: GeminiClientConfig): GoogleGenAI;
|
|
9
10
|
/**
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -2,13 +2,14 @@ import { GoogleGenAI } from "@google/genai";
|
|
|
2
2
|
import { generateId, getApiKeyFromEnv } from "@tanstack/ai-utils";
|
|
3
3
|
//#region src/utils/client.ts
|
|
4
4
|
/**
|
|
5
|
-
* Creates a Google Generative AI client instance
|
|
5
|
+
* Creates a Google Generative AI client instance.
|
|
6
|
+
*
|
|
7
|
+
* AI Studio mode needs `apiKey`. Vertex / Enterprise mode (`vertexai` or
|
|
8
|
+
* `enterprise`) uses project, location, and Google Cloud credentials instead.
|
|
6
9
|
*/
|
|
7
10
|
function createGeminiClient(config) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
apiKey: config.apiKey
|
|
11
|
-
});
|
|
11
|
+
if (!(config.vertexai === true || config.enterprise === true) && (config.apiKey === void 0 || config.apiKey.length === 0)) throw new Error("A Gemini API key is required when vertexai and enterprise are not set. Pass apiKey, or set GOOGLE_API_KEY or GEMINI_API_KEY.");
|
|
12
|
+
return new GoogleGenAI(config);
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Gets Google API key from environment variables
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import { GoogleGenAI } from '@google/genai'\nimport { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'\nimport type { GoogleGenAIOptions } from '@google/genai'\n\nexport
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../../src/utils/client.ts"],"sourcesContent":["import { GoogleGenAI } from '@google/genai'\nimport { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'\nimport type { GoogleGenAIOptions } from '@google/genai'\n\nexport type GeminiClientConfig = GoogleGenAIOptions\n\n/**\n * Creates a Google Generative AI client instance.\n *\n * AI Studio mode needs `apiKey`. Vertex / Enterprise mode (`vertexai` or\n * `enterprise`) uses project, location, and Google Cloud credentials instead.\n */\nexport function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {\n const vertexMode = config.vertexai === true || config.enterprise === true\n if (\n !vertexMode &&\n (config.apiKey === undefined || config.apiKey.length === 0)\n ) {\n throw new Error(\n 'A Gemini API key is required when vertexai and enterprise are not set. Pass apiKey, or set GOOGLE_API_KEY or GEMINI_API_KEY.',\n )\n }\n return new GoogleGenAI(config)\n}\n\n/**\n * Gets Google API key from environment variables\n * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found\n */\nexport function getGeminiApiKeyFromEnv(): string {\n try {\n return getApiKeyFromEnv('GOOGLE_API_KEY')\n } catch {\n try {\n return getApiKeyFromEnv('GEMINI_API_KEY')\n } catch {\n throw new Error(\n 'GOOGLE_API_KEY or GEMINI_API_KEY is not set. Please set one of these environment variables or pass the API key directly.',\n )\n }\n }\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return _generateId(prefix)\n}\n"],"mappings":";;;;;;;;;AAYA,SAAgB,mBAAmB,QAAyC;CAE1E,IACE,EAFiB,OAAO,aAAa,QAAQ,OAAO,eAAe,UAGlE,OAAO,WAAW,KAAA,KAAa,OAAO,OAAO,WAAW,IAEzD,MAAM,IAAI,MACR,8HACF;CAEF,OAAO,IAAI,YAAY,MAAM;AAC/B;;;;;AAMA,SAAgB,yBAAiC;CAC/C,IAAI;EACF,OAAO,iBAAiB,gBAAgB;CAC1C,QAAQ;EACN,IAAI;GACF,OAAO,iBAAiB,gBAAgB;EAC1C,QAAQ;GACN,MAAM,IAAI,MACR,0HACF;EACF;CACF;AACF;;;;AAKA,SAAgB,aAAW,QAAwB;CACjD,OAAO,WAAY,MAAM;AAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-gemini",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Google Gemini adapter for TanStack AI chat, images, speech, audio generation, and structured outputs.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"@tanstack/ai-utils": "^0.4.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@tanstack/ai": "^0.47.
|
|
62
|
+
"@tanstack/ai": "^0.47.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@vitest/coverage-v8": "4.1.10",
|
|
66
66
|
"vite": "^8.2.1",
|
|
67
67
|
"zod": "^4.2.0",
|
|
68
|
-
"@tanstack/ai": "0.47.
|
|
68
|
+
"@tanstack/ai": "0.47.3"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "vite build",
|
package/src/index.ts
CHANGED
|
@@ -146,6 +146,7 @@ export type { GeminiTTSVoice } from './model-meta'
|
|
|
146
146
|
// Type Exports
|
|
147
147
|
// ===========================
|
|
148
148
|
|
|
149
|
+
export type { GeminiClientConfig } from './utils/client'
|
|
149
150
|
export type {
|
|
150
151
|
GeminiChatModelProviderOptionsByName,
|
|
151
152
|
GeminiChatModelToolCapabilitiesByName,
|
package/src/utils/client.ts
CHANGED
|
@@ -2,18 +2,25 @@ import { GoogleGenAI } from '@google/genai'
|
|
|
2
2
|
import { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'
|
|
3
3
|
import type { GoogleGenAIOptions } from '@google/genai'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
apiKey: string
|
|
7
|
-
}
|
|
5
|
+
export type GeminiClientConfig = GoogleGenAIOptions
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
|
-
* Creates a Google Generative AI client instance
|
|
8
|
+
* Creates a Google Generative AI client instance.
|
|
9
|
+
*
|
|
10
|
+
* AI Studio mode needs `apiKey`. Vertex / Enterprise mode (`vertexai` or
|
|
11
|
+
* `enterprise`) uses project, location, and Google Cloud credentials instead.
|
|
11
12
|
*/
|
|
12
13
|
export function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const vertexMode = config.vertexai === true || config.enterprise === true
|
|
15
|
+
if (
|
|
16
|
+
!vertexMode &&
|
|
17
|
+
(config.apiKey === undefined || config.apiKey.length === 0)
|
|
18
|
+
) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'A Gemini API key is required when vertexai and enterprise are not set. Pass apiKey, or set GOOGLE_API_KEY or GEMINI_API_KEY.',
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
return new GoogleGenAI(config)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
/**
|