Skip to content

Commit ad560aa

Browse files
committed
Try refactor
1 parent 204a877 commit ad560aa

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

BACKLOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Backlog
22

33
---
4-
## Feature name
5-
Verify if there are any issues.
4+
## Completed
5+
- Refactor Logo Generation api in cli (2026-01-15)
66

7-
### Description
8-
Verify if there are any issues and if you are using the latest way to call the api. I want to generate logos via chat in my CLI.
97
---

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
### Features
1616

17+
- Refactored AI logo generation to use the latest `gemini-3-pro-image-preview` model via the standard `@google/genai` SDK.
18+
- Added support for `GEMINI_API_KEY` environment variable to skip manual API key entry.
19+
- Improved image processing and response handling for AI-generated logos.
20+
- Enhanced error reporting for Gemini API issues.
21+
1722
### Fixes
1823

1924
## [0.1.25] - 2026-01-15

init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export async function initCommand() {
8888
"",
8989
);
9090

91-
let geminiApiKey = "";
92-
if (logoPrompt) {
91+
let geminiApiKey = Deno.env.get("GEMINI_API_KEY") || "";
92+
if (logoPrompt && !geminiApiKey) {
9393
geminiApiKey = promptInput("🔑 Enter your Google Gemini API key", "", {
9494
required: true,
9595
});

lib/ai.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ export async function generateLogo(
1818
try {
1919
const ai = new GoogleGenAI({ apiKey });
2020

21-
// Initial message to start the chat
2221
const chat = ai.chats.create({
2322
model: "gemini-3-pro-image-preview",
2423
config: {
25-
responseModalities: ["TEXT", "IMAGE"],
24+
imageConfig: {
25+
aspectRatio: "1:1",
26+
},
2627
},
2728
});
2829

@@ -32,9 +33,13 @@ export async function generateLogo(
3233
const response = await chat.sendMessage({ message: currentPrompt });
3334

3435
let base64Image: string | undefined;
35-
for (const part of response.candidates?.[0]?.content?.parts || []) {
36-
if (part.inlineData && part.inlineData.mimeType === "image/png") {
37-
base64Image = part.inlineData.data;
36+
const candidates = response.candidates;
37+
if (candidates && candidates.length > 0) {
38+
for (const part of candidates[0]?.content?.parts ?? []) {
39+
if (part.inlineData && (part.inlineData.mimeType === "image/png" || part.inlineData.mimeType === "image/jpeg")) {
40+
base64Image = part.inlineData.data;
41+
break;
42+
}
3843
}
3944
}
4045

@@ -69,7 +74,11 @@ export async function generateLogo(
6974
}
7075
} catch (err) {
7176
spinner.stop(false);
72-
console.log(` ⚠️ An unexpected error occurred: ${err instanceof Error ? err.message : String(err)}`);
77+
if (err instanceof Error && err.name === "ApiError") {
78+
console.log(` ⚠️ Gemini API Error: ${err.message} (Status: ${(err as any).status})`);
79+
} else {
80+
console.log(` ⚠️ An unexpected error occurred: ${err instanceof Error ? err.message : String(err)}`);
81+
}
7382
return null;
7483
}
7584
}

new-logo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export async function newLogoCommand() {
4141
{ required: true }
4242
);
4343

44-
const geminiApiKey = promptInput("🔑 Enter your Google Gemini API key", "", {
44+
const envApiKey = Deno.env.get("GEMINI_API_KEY");
45+
const geminiApiKey = envApiKey || promptInput("🔑 Enter your Google Gemini API key", "", {
4546
required: true,
4647
});
4748

0 commit comments

Comments
 (0)