draftify-cli 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/dist/utils/api.js +61 -1
  2. package/package.json +4 -1
package/dist/utils/api.js CHANGED
@@ -1,9 +1,70 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.refactorCodeApi = refactorCodeApi;
4
7
  exports.getUserProfile = getUserProfile;
5
8
  const config_1 = require("./config");
9
+ const genai_1 = require("@google/genai");
10
+ const dotenv_1 = __importDefault(require("dotenv"));
11
+ dotenv_1.default.config();
6
12
  async function refactorCodeApi(fileName, code, instruction, history, modelName, skillsData, thinkingLevel, onChunk, abortSignal) {
13
+ // 1. HELYI VÉGREHAJTÁS (Ha van GEMINI_API_KEY a .env-ben, közvetlenül a Geminit hívjuk)
14
+ // Ez tökéletes a helyi teszteléshez, mielőtt a backendre (Vercel) kerül a kód.
15
+ if (process.env.GEMINI_API_KEY) {
16
+ const ai = new genai_1.GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
17
+ // Modell kiválasztása a kívánt logika alapján
18
+ let geminiModel = 'gemini-3.5-flash'; // Alapértelmezett (Medium, Low, Adaptive)
19
+ if (thinkingLevel === 'High') {
20
+ geminiModel = 'gemini-3.1-pro-preview';
21
+ }
22
+ // Üzenetek összeállítása a Gemini számára
23
+ const contents = [];
24
+ // Előzmények hozzáadása (a 'assistant' szerepkört 'model'-re kell cserélni)
25
+ if (history && history.length > 0) {
26
+ for (const msg of history) {
27
+ contents.push({
28
+ role: msg.role === 'assistant' ? 'model' : 'user',
29
+ parts: [{ text: msg.content }]
30
+ });
31
+ }
32
+ }
33
+ // Aktuális prompt összeállítása
34
+ let currentPrompt = `Task/Instruction: ${instruction}\n\n`;
35
+ if (fileName && code) {
36
+ currentPrompt += `Context from workspace:\n${code}\n\n`;
37
+ }
38
+ if (skillsData && skillsData.length > 0) {
39
+ currentPrompt += `Available skills context:\n`;
40
+ skillsData.forEach(skill => {
41
+ currentPrompt += `--- Skill: ${skill.name} ---\n${skill.content}\n\n`;
42
+ });
43
+ }
44
+ contents.push({
45
+ role: 'user',
46
+ parts: [{ text: currentPrompt }]
47
+ });
48
+ const responseStream = await ai.models.generateContentStream({
49
+ model: geminiModel,
50
+ contents: contents,
51
+ config: {
52
+ systemInstruction: "You are an expert AI software engineering CLI assistant. You provide solutions, refactorings, and terminal commands."
53
+ }
54
+ });
55
+ let fullResult = "";
56
+ for await (const chunk of responseStream) {
57
+ if (abortSignal?.aborted)
58
+ throw new Error("Aborted");
59
+ if (chunk.text) {
60
+ fullResult += chunk.text;
61
+ if (onChunk)
62
+ onChunk(chunk.text);
63
+ }
64
+ }
65
+ return fullResult;
66
+ }
67
+ // 2. TÁVOLI VÉGREHAJTÁS (Eredeti Vercel backend kód, ha nincs helyi API kulcs)
7
68
  const token = (0, config_1.getToken)();
8
69
  if (!token) {
9
70
  throw new Error("No token found. Please run 'draftify login' first.");
@@ -69,7 +130,6 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
69
130
  }
70
131
  }
71
132
  else if (line.startsWith('{"result":')) {
72
- // Fallback for non-streaming response
73
133
  try {
74
134
  const dataObj = JSON.parse(line);
75
135
  if (dataObj.result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -24,9 +24,12 @@
24
24
  "author": "",
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
+ "@google-cloud/vertexai": "^1.12.0",
28
+ "@google/genai": "^2.7.0",
27
29
  "ansi-escapes": "^7.3.0",
28
30
  "axios": "^1.7.2",
29
31
  "commander": "^12.1.0",
32
+ "dotenv": "^17.4.2",
30
33
  "enquirer": "^2.4.1",
31
34
  "kleur": "^4.1.5",
32
35
  "open": "^8.4.2",