gemini-design-mcp 3.2.1 → 3.3.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/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,87 @@
|
|
|
1
1
|
import { GoogleGenAI, ThinkingLevel } from "@google/genai";
|
|
2
|
-
const apiKey = process.env.
|
|
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
|
-
|
|
28
|
+
contents: [
|
|
29
|
+
{
|
|
30
|
+
role: "user",
|
|
31
|
+
parts: [{ text: userPrompt }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
systemInstruction: {
|
|
35
|
+
parts: [{ text: systemPrompt }],
|
|
36
|
+
},
|
|
37
|
+
generationConfig: {
|
|
18
38
|
temperature: 1,
|
|
19
39
|
thinkingConfig: {
|
|
20
|
-
|
|
40
|
+
thinkingBudget: 1024, // LOW thinking level
|
|
21
41
|
},
|
|
22
42
|
},
|
|
23
|
-
})
|
|
24
|
-
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
const error = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
47
|
+
throw new Error(error.error || `Proxy error: ${response.status}`);
|
|
48
|
+
}
|
|
49
|
+
const result = await response.json();
|
|
50
|
+
// Extract text from Gemini response format
|
|
51
|
+
const text = result.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
52
|
+
if (!text) {
|
|
53
|
+
throw new Error("No text in response");
|
|
54
|
+
}
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate content directly via Google SDK
|
|
59
|
+
*/
|
|
60
|
+
async function generateViaSdk(systemPrompt, userPrompt, model) {
|
|
61
|
+
if (!ai) {
|
|
62
|
+
throw new Error("SDK not initialized");
|
|
63
|
+
}
|
|
64
|
+
const response = await ai.models.generateContent({
|
|
65
|
+
model,
|
|
66
|
+
contents: userPrompt,
|
|
67
|
+
config: {
|
|
68
|
+
systemInstruction: systemPrompt,
|
|
69
|
+
temperature: 1,
|
|
70
|
+
thinkingConfig: {
|
|
71
|
+
thinkingLevel: ThinkingLevel.LOW,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return response.text ?? "";
|
|
76
|
+
}
|
|
77
|
+
export async function generateWithGemini(systemPrompt, userPrompt, model = DEFAULT_MODEL) {
|
|
78
|
+
try {
|
|
79
|
+
if (isHostedKey) {
|
|
80
|
+
return await generateViaProxy(systemPrompt, userPrompt, model);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return await generateViaSdk(systemPrompt, userPrompt, model);
|
|
84
|
+
}
|
|
25
85
|
}
|
|
26
86
|
catch (error) {
|
|
27
87
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -3,7 +3,7 @@ export declare const createFrontendSchema: {
|
|
|
3
3
|
request: z.ZodString;
|
|
4
4
|
filePath: z.ZodString;
|
|
5
5
|
techStack: z.ZodString;
|
|
6
|
-
context: z.
|
|
6
|
+
context: z.ZodOptional<z.ZodString>;
|
|
7
7
|
designSystem: z.ZodOptional<z.ZodObject<{
|
|
8
8
|
vibe: z.ZodObject<{
|
|
9
9
|
name: z.ZodString;
|
|
@@ -36,7 +36,7 @@ export declare function createFrontend(params: {
|
|
|
36
36
|
request: string;
|
|
37
37
|
filePath: string;
|
|
38
38
|
techStack: string;
|
|
39
|
-
context
|
|
39
|
+
context?: string;
|
|
40
40
|
designSystem?: {
|
|
41
41
|
vibe: {
|
|
42
42
|
name: string;
|
|
@@ -9,9 +9,9 @@ export const createFrontendSchema = {
|
|
|
9
9
|
"Example: 'src/components/PricingPage.tsx' or 'app/dashboard/page.tsx'"),
|
|
10
10
|
techStack: z.string().describe("The tech stack to use. Be specific. " +
|
|
11
11
|
"Examples: 'React + TypeScript + Tailwind CSS', 'Next.js 14 App Router + shadcn/ui', 'Vue 3 + Composition API + CSS Modules'"),
|
|
12
|
-
context: z.string().
|
|
12
|
+
context: z.string().optional().describe("Existing project code for design consistency. " +
|
|
13
13
|
"Pass relevant files (components, styles, theme config) so Gemini matches your design system. " +
|
|
14
|
-
"
|
|
14
|
+
"Omit this parameter if this is the FIRST file in a new project."),
|
|
15
15
|
designSystem: z.object({
|
|
16
16
|
vibe: z.object({
|
|
17
17
|
name: z.string().describe("Vibe name (e.g., 'Pristine Museum', 'Dark Luxe')"),
|
|
@@ -42,9 +42,9 @@ Interpret this vibe creatively:
|
|
|
42
42
|
- You have freedom in the specific implementation, but the overall feel MUST match this vibe
|
|
43
43
|
`;
|
|
44
44
|
}
|
|
45
|
-
// Build context instructions
|
|
45
|
+
// Build context instructions (ignore empty strings and "null" strings)
|
|
46
46
|
let contextInstructions = '';
|
|
47
|
-
if (context) {
|
|
47
|
+
if (context && context !== "null" && context.trim() !== "") {
|
|
48
48
|
contextInstructions = `
|
|
49
49
|
EXISTING PROJECT CONTEXT (match this design system):
|
|
50
50
|
${context}
|