style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { secureLogger } from "@/lib/secure-logger";
|
||||
import { buildGeminiParts, buildItemPrompt, InlineImageData } from "@/lib/ai/item-prompt";
|
||||
import {
|
||||
buildGeminiParts,
|
||||
buildItemPrompt,
|
||||
type InlineImageData,
|
||||
} from "@/lib/ai/item-prompt";
|
||||
import { listCategoryTemplates } from "@/lib/items/sqlite-manager";
|
||||
import { secureLogger } from "@/lib/secure-logger";
|
||||
|
||||
interface GenerateItemStructureInput {
|
||||
name: string;
|
||||
@@ -46,12 +50,14 @@ const FALLBACK_STRUCTURE = {
|
||||
};
|
||||
|
||||
export async function generateItemStructure(
|
||||
input: GenerateItemStructureInput
|
||||
input: GenerateItemStructureInput,
|
||||
): Promise<GeminiResponse> {
|
||||
const apiKey = process.env.GEMINI_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
secureLogger.warn("⚠️ GEMINI_API_KEY ausente – utilizando fallback estático.");
|
||||
secureLogger.warn(
|
||||
"⚠️ GEMINI_API_KEY ausente – utilizando fallback estático.",
|
||||
);
|
||||
return {
|
||||
structure: FALLBACK_STRUCTURE,
|
||||
raw: FALLBACK_STRUCTURE,
|
||||
@@ -66,7 +72,7 @@ export async function generateItemStructure(
|
||||
try {
|
||||
const templates = listCategoryTemplates();
|
||||
if (templates.length > 0) {
|
||||
const lines: string[] = ["Estruturas atuais no SQLite:"];
|
||||
const lines: string[] = ["Estruturas atuais no SQLite:"];
|
||||
templates.forEach((tpl) => {
|
||||
lines.push(`- Tabela: ${tpl.name}`);
|
||||
tpl.columns.forEach((col) => {
|
||||
@@ -75,7 +81,7 @@ export async function generateItemStructure(
|
||||
});
|
||||
sqliteSchemaText = lines.join("\n");
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
sqliteSchemaText = "[Falha ao listar SQLite]";
|
||||
}
|
||||
|
||||
@@ -144,7 +150,8 @@ export async function generateItemStructure(
|
||||
|
||||
if (!response.ok) {
|
||||
const status = response.status;
|
||||
const msg = bodyJson?.error?.message || `Gemini retornou status ${status}`;
|
||||
const msg =
|
||||
bodyJson?.error?.message || `Gemini retornou status ${status}`;
|
||||
const err = new Error(msg);
|
||||
(err as any).status = status;
|
||||
(err as any).response = bodyJson;
|
||||
@@ -210,7 +217,12 @@ export async function generateItemStructure(
|
||||
}
|
||||
}
|
||||
|
||||
function buildPrompt({ name, description, scope, server }: GenerateItemStructureInput) {
|
||||
function _buildPrompt({
|
||||
name,
|
||||
description,
|
||||
scope,
|
||||
server,
|
||||
}: GenerateItemStructureInput) {
|
||||
return `
|
||||
Você é um assistente que prepara carga útil em JSON para inserção de itens em banco de dados.
|
||||
|
||||
@@ -234,7 +246,9 @@ ${description}
|
||||
"""
|
||||
|
||||
Instruções:
|
||||
- Escolha uma tabela coerente com o escopo (ex.: "items_all" para global ou "items_${(server ?? "custom")
|
||||
- Escolha uma tabela coerente com o escopo (ex.: "items_all" para global ou "items_${(
|
||||
server ?? "custom"
|
||||
)
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "_")}" para servidor).
|
||||
- Dentro de "columns", inicie com "name" e "description".
|
||||
@@ -244,4 +258,3 @@ Instruções:
|
||||
- Garante que o JSON seja minuciosamente válido.
|
||||
`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user