gemini-design-mcp 3.2.2 → 3.3.1
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/build/lib/gemini.d.ts +1 -1
- package/build/lib/gemini.js +69 -15
- package/package.json +1 -1
package/build/lib/gemini.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GoogleGenAI } from "@google/genai";
|
|
2
|
-
export declare const ai: GoogleGenAI;
|
|
2
|
+
export declare const ai: GoogleGenAI | null;
|
|
3
3
|
export declare const DEFAULT_MODEL = "gemini-3-flash-preview";
|
|
4
4
|
export declare function generateWithGemini(systemPrompt: string, userPrompt: string, model?: string): Promise<string>;
|
package/build/lib/gemini.js
CHANGED
|
@@ -1,27 +1,81 @@
|
|
|
1
|
-
import { GoogleGenAI
|
|
2
|
-
const apiKey = process.env.
|
|
1
|
+
import { GoogleGenAI } from "@google/genai";
|
|
2
|
+
const apiKey = process.env.API_KEY;
|
|
3
3
|
if (!apiKey) {
|
|
4
|
-
console.error("ERROR:
|
|
4
|
+
console.error("ERROR: API_KEY environment variable is required");
|
|
5
5
|
console.error("Get your API key at: https://aistudio.google.com/app/apikey");
|
|
6
|
+
console.error("Or use a Gemini Design key (gd_xxx) from: https://gemini-design.com");
|
|
6
7
|
process.exit(1);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
// Check if using hosted Gemini Design service
|
|
10
|
+
const isHostedKey = apiKey.startsWith("gd_");
|
|
11
|
+
const PROXY_URL = process.env.GEMINI_DESIGN_PROXY_URL || "https://brave-turtle-253.convex.site/v1/generate";
|
|
12
|
+
// Only initialize SDK if not using hosted service
|
|
13
|
+
export const ai = isHostedKey ? null : new GoogleGenAI({ apiKey });
|
|
9
14
|
// Default model - Gemini 3 Flash Preview (best for design)
|
|
10
15
|
export const DEFAULT_MODEL = "gemini-3-flash-preview";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Generate content via the hosted proxy service
|
|
18
|
+
*/
|
|
19
|
+
async function generateViaProxy(systemPrompt, userPrompt, model) {
|
|
20
|
+
const response = await fetch(PROXY_URL, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({
|
|
14
27
|
model,
|
|
15
|
-
contents:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
thinkingConfig: {
|
|
20
|
-
thinkingLevel: ThinkingLevel.LOW,
|
|
28
|
+
contents: [
|
|
29
|
+
{
|
|
30
|
+
role: "user",
|
|
31
|
+
parts: [{ text: userPrompt }],
|
|
21
32
|
},
|
|
33
|
+
],
|
|
34
|
+
systemInstruction: {
|
|
35
|
+
parts: [{ text: systemPrompt }],
|
|
22
36
|
},
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
generationConfig: {
|
|
38
|
+
temperature: 1,
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const error = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
44
|
+
throw new Error(error.error || `Proxy error: ${response.status}`);
|
|
45
|
+
}
|
|
46
|
+
const result = await response.json();
|
|
47
|
+
// Extract text from Gemini response format
|
|
48
|
+
const text = result.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
49
|
+
if (!text) {
|
|
50
|
+
throw new Error("No text in response");
|
|
51
|
+
}
|
|
52
|
+
return text;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Generate content directly via Google SDK
|
|
56
|
+
*/
|
|
57
|
+
async function generateViaSdk(systemPrompt, userPrompt, model) {
|
|
58
|
+
if (!ai) {
|
|
59
|
+
throw new Error("SDK not initialized");
|
|
60
|
+
}
|
|
61
|
+
const response = await ai.models.generateContent({
|
|
62
|
+
model,
|
|
63
|
+
contents: userPrompt,
|
|
64
|
+
config: {
|
|
65
|
+
systemInstruction: systemPrompt,
|
|
66
|
+
temperature: 1,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return response.text ?? "";
|
|
70
|
+
}
|
|
71
|
+
export async function generateWithGemini(systemPrompt, userPrompt, model = DEFAULT_MODEL) {
|
|
72
|
+
try {
|
|
73
|
+
if (isHostedKey) {
|
|
74
|
+
return await generateViaProxy(systemPrompt, userPrompt, model);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return await generateViaSdk(systemPrompt, userPrompt, model);
|
|
78
|
+
}
|
|
25
79
|
}
|
|
26
80
|
catch (error) {
|
|
27
81
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|