@tanstack/ai-gemini 0.10.0 → 0.10.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.
@@ -1,4 +1,5 @@
1
1
  import { GoogleGenAI } from "@google/genai";
2
+ import { generateId as generateId$1, getApiKeyFromEnv } from "@tanstack/ai-utils";
2
3
  function createGeminiClient(config) {
3
4
  return new GoogleGenAI({
4
5
  ...config,
@@ -6,17 +7,20 @@ function createGeminiClient(config) {
6
7
  });
7
8
  }
8
9
  function getGeminiApiKeyFromEnv() {
9
- const env = typeof globalThis !== "undefined" && globalThis.window?.env ? globalThis.window.env : typeof process !== "undefined" ? process.env : void 0;
10
- const key = env?.GOOGLE_API_KEY || env?.GEMINI_API_KEY;
11
- if (!key) {
12
- throw new Error(
13
- "GOOGLE_API_KEY or GEMINI_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key."
14
- );
10
+ try {
11
+ return getApiKeyFromEnv("GOOGLE_API_KEY");
12
+ } catch {
13
+ try {
14
+ return getApiKeyFromEnv("GEMINI_API_KEY");
15
+ } catch {
16
+ throw new Error(
17
+ "GOOGLE_API_KEY or GEMINI_API_KEY is not set. Please set one of these environment variables or pass the API key directly."
18
+ );
19
+ }
15
20
  }
16
- return key;
17
21
  }
18
22
  function generateId(prefix) {
19
- return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
23
+ return generateId$1(prefix);
20
24
  }
21
25
  export {
22
26
  createGeminiClient,
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import { GoogleGenAI } from '@google/genai'\nimport type { GoogleGenAIOptions } from '@google/genai'\n\nexport interface GeminiClientConfig extends GoogleGenAIOptions {\n apiKey: string\n}\n\n/**\n * Creates a Google Generative AI client instance\n */\nexport function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {\n return new GoogleGenAI({\n ...config,\n apiKey: config.apiKey,\n })\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 const env =\n typeof globalThis !== 'undefined' && (globalThis as any).window?.env\n ? (globalThis as any).window.env\n : typeof process !== 'undefined'\n ? process.env\n : undefined\n const key = env?.GOOGLE_API_KEY || env?.GEMINI_API_KEY\n\n if (!key) {\n throw new Error(\n 'GOOGLE_API_KEY or GEMINI_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',\n )\n }\n\n return key\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n}\n"],"names":[],"mappings":";AAUO,SAAS,mBAAmB,QAAyC;AAC1E,SAAO,IAAI,YAAY;AAAA,IACrB,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,EAAA,CAChB;AACH;AAMO,SAAS,yBAAiC;AAC/C,QAAM,MACJ,OAAO,eAAe,eAAgB,WAAmB,QAAQ,MAC5D,WAAmB,OAAO,MAC3B,OAAO,YAAY,cACjB,QAAQ,MACR;AACR,QAAM,MAAM,KAAK,kBAAkB,KAAK;AAExC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;AAKO,SAAS,WAAW,QAAwB;AACjD,SAAO,GAAG,MAAM,IAAI,KAAK,KAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAC3E;"}
1
+ {"version":3,"file":"client.js","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 apiKey: string\n}\n\n/**\n * Creates a Google Generative AI client instance\n */\nexport function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {\n return new GoogleGenAI({\n ...config,\n apiKey: config.apiKey,\n })\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"],"names":["_generateId"],"mappings":";;AAWO,SAAS,mBAAmB,QAAyC;AAC1E,SAAO,IAAI,YAAY;AAAA,IACrB,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,EAAA,CAChB;AACH;AAMO,SAAS,yBAAiC;AAC/C,MAAI;AACF,WAAO,iBAAiB,gBAAgB;AAAA,EAC1C,QAAQ;AACN,QAAI;AACF,aAAO,iBAAiB,gBAAgB;AAAA,IAC1C,QAAQ;AACN,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AACF;AAKO,SAAS,WAAW,QAAwB;AACjD,SAAOA,aAAY,MAAM;AAC3B;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-gemini",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Google Gemini adapter for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -34,16 +34,17 @@
34
34
  "adapter"
35
35
  ],
36
36
  "dependencies": {
37
- "@google/genai": "^1.43.0"
37
+ "@google/genai": "^1.43.0",
38
+ "@tanstack/ai-utils": "0.2.0"
38
39
  },
39
40
  "peerDependencies": {
40
- "@tanstack/ai": "^0.14.0"
41
+ "@tanstack/ai": "^0.15.0"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@vitest/coverage-v8": "4.0.14",
44
45
  "vite": "^7.2.7",
45
46
  "zod": "^4.2.0",
46
- "@tanstack/ai": "0.14.0"
47
+ "@tanstack/ai": "0.15.0"
47
48
  },
48
49
  "scripts": {
49
50
  "build": "vite build",
@@ -1,4 +1,5 @@
1
1
  import { GoogleGenAI } from '@google/genai'
2
+ import { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'
2
3
  import type { GoogleGenAIOptions } from '@google/genai'
3
4
 
4
5
  export interface GeminiClientConfig extends GoogleGenAIOptions {
@@ -20,26 +21,22 @@ export function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {
20
21
  * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found
21
22
  */
22
23
  export function getGeminiApiKeyFromEnv(): string {
23
- const env =
24
- typeof globalThis !== 'undefined' && (globalThis as any).window?.env
25
- ? (globalThis as any).window.env
26
- : typeof process !== 'undefined'
27
- ? process.env
28
- : undefined
29
- const key = env?.GOOGLE_API_KEY || env?.GEMINI_API_KEY
30
-
31
- if (!key) {
32
- throw new Error(
33
- 'GOOGLE_API_KEY or GEMINI_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',
34
- )
24
+ try {
25
+ return getApiKeyFromEnv('GOOGLE_API_KEY')
26
+ } catch {
27
+ try {
28
+ return getApiKeyFromEnv('GEMINI_API_KEY')
29
+ } catch {
30
+ throw new Error(
31
+ 'GOOGLE_API_KEY or GEMINI_API_KEY is not set. Please set one of these environment variables or pass the API key directly.',
32
+ )
33
+ }
35
34
  }
36
-
37
- return key
38
35
  }
39
36
 
40
37
  /**
41
38
  * Generates a unique ID with a prefix
42
39
  */
43
40
  export function generateId(prefix: string): string {
44
- return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`
41
+ return _generateId(prefix)
45
42
  }