@tanstack/ai-gemini 0.28.0 → 0.29.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.
@@ -1,5 +1,17 @@
1
1
  import { GoogleGenAI, GoogleGenAIOptions } from '@google/genai';
2
- export type GeminiClientConfig = GoogleGenAIOptions;
2
+ export interface GeminiClientConfig extends GoogleGenAIOptions {
3
+ /**
4
+ * Base URL for every request. Maps onto `httpOptions.baseUrl` and wins
5
+ * over it when both are set. Same option name as the other adapters, so a
6
+ * gateway config can be spread into any of them.
7
+ */
8
+ baseURL?: string;
9
+ /**
10
+ * Headers sent with every request. Maps onto `httpOptions.headers` and wins
11
+ * over it when both are set. Same option name as the other adapters.
12
+ */
13
+ defaultHeaders?: Record<string, string>;
14
+ }
3
15
  /**
4
16
  * Creates a Google Generative AI client instance.
5
17
  *
@@ -9,7 +9,13 @@ import { generateId, getApiKeyFromEnv } from "@tanstack/ai-utils";
9
9
  */
10
10
  function createGeminiClient(config) {
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
+ const { baseURL, defaultHeaders, ...options } = config;
13
+ if (baseURL !== void 0 || defaultHeaders !== void 0) options.httpOptions = {
14
+ ...options.httpOptions,
15
+ ...baseURL !== void 0 ? { baseUrl: baseURL } : {},
16
+ ...defaultHeaders !== void 0 ? { headers: defaultHeaders } : {}
17
+ };
18
+ return new GoogleGenAI(options);
13
19
  }
14
20
  /**
15
21
  * 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 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"}
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 interface GeminiClientConfig extends GoogleGenAIOptions {\n /**\n * Base URL for every request. Maps onto `httpOptions.baseUrl` and wins\n * over it when both are set. Same option name as the other adapters, so a\n * gateway config can be spread into any of them.\n */\n baseURL?: string\n /**\n * Headers sent with every request. Maps onto `httpOptions.headers` and wins\n * over it when both are set. Same option name as the other adapters.\n */\n defaultHeaders?: Record<string, string>\n}\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 const { baseURL, defaultHeaders, ...options } = config\n if (baseURL !== undefined || defaultHeaders !== undefined) {\n options.httpOptions = {\n ...options.httpOptions,\n ...(baseURL !== undefined ? { baseUrl: baseURL } : {}),\n ...(defaultHeaders !== undefined ? { headers: defaultHeaders } : {}),\n }\n }\n return new GoogleGenAI(options)\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":";;;;;;;;;AAwBA,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,MAAM,EAAE,SAAS,gBAAgB,GAAG,YAAY;CAChD,IAAI,YAAY,KAAA,KAAa,mBAAmB,KAAA,GAC9C,QAAQ,cAAc;EACpB,GAAG,QAAQ;EACX,GAAI,YAAY,KAAA,IAAY,EAAE,SAAS,QAAQ,IAAI,CAAC;EACpD,GAAI,mBAAmB,KAAA,IAAY,EAAE,SAAS,eAAe,IAAI,CAAC;CACpE;CAEF,OAAO,IAAI,YAAY,OAAO;AAChC;;;;;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.28.0",
3
+ "version": "0.29.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",
@@ -63,13 +63,13 @@
63
63
  "@tanstack/ai-utils": "^0.4.0"
64
64
  },
65
65
  "peerDependencies": {
66
- "@tanstack/ai": "^0.52.2"
66
+ "@tanstack/ai": "^0.52.3"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@vitest/coverage-v8": "4.1.10",
70
70
  "vite": "^8.2.1",
71
71
  "zod": "^4.2.0",
72
- "@tanstack/ai": "0.52.2"
72
+ "@tanstack/ai": "0.52.3"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "vite build",
@@ -2,7 +2,19 @@ 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 type GeminiClientConfig = GoogleGenAIOptions
5
+ export interface GeminiClientConfig extends GoogleGenAIOptions {
6
+ /**
7
+ * Base URL for every request. Maps onto `httpOptions.baseUrl` and wins
8
+ * over it when both are set. Same option name as the other adapters, so a
9
+ * gateway config can be spread into any of them.
10
+ */
11
+ baseURL?: string
12
+ /**
13
+ * Headers sent with every request. Maps onto `httpOptions.headers` and wins
14
+ * over it when both are set. Same option name as the other adapters.
15
+ */
16
+ defaultHeaders?: Record<string, string>
17
+ }
6
18
 
7
19
  /**
8
20
  * Creates a Google Generative AI client instance.
@@ -20,7 +32,15 @@ export function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {
20
32
  '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
33
  )
22
34
  }
23
- return new GoogleGenAI(config)
35
+ const { baseURL, defaultHeaders, ...options } = config
36
+ if (baseURL !== undefined || defaultHeaders !== undefined) {
37
+ options.httpOptions = {
38
+ ...options.httpOptions,
39
+ ...(baseURL !== undefined ? { baseUrl: baseURL } : {}),
40
+ ...(defaultHeaders !== undefined ? { headers: defaultHeaders } : {}),
41
+ }
42
+ }
43
+ return new GoogleGenAI(options)
24
44
  }
25
45
 
26
46
  /**