draftify-cli 1.0.52 → 1.0.56

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/dist/index.js CHANGED
@@ -11,6 +11,7 @@ const refactor_1 = require("./commands/refactor");
11
11
  const repl_1 = require("./repl");
12
12
  const ui_1 = require("./utils/ui");
13
13
  const config_1 = require("./utils/config");
14
+ const api_1 = require("./utils/api");
14
15
  const program = new commander_1.Command();
15
16
  program
16
17
  .name("draftify")
@@ -87,14 +88,38 @@ async function checkVersion() {
87
88
  await checkVersion();
88
89
  // Custom logic for when `draftify` is run without any arguments
89
90
  if (process.argv.slice(2).length === 0) {
90
- const token = (0, config_1.getToken)();
91
- if (!token) {
92
- // No token, run interactive login flow
93
- (0, login_1.loginCommand)().then((username) => (0, repl_1.startRepl)(username)).catch(() => process.exit(1));
91
+ let isValid = false;
92
+ let username = "Developer";
93
+ if ((0, config_1.getToken)()) {
94
+ try {
95
+ ui_1.ui.info("Hitelesítés ellenőrzése...");
96
+ const profile = await (0, api_1.getUserProfile)();
97
+ if (profile) {
98
+ isValid = true;
99
+ username = profile.username;
100
+ }
101
+ else {
102
+ // Network error but not 401, we allow them in
103
+ isValid = true;
104
+ }
105
+ }
106
+ catch (e) {
107
+ if (e.message === "UNAUTHORIZED") {
108
+ (0, config_1.saveConfig)({ token: null });
109
+ isValid = false;
110
+ }
111
+ else {
112
+ isValid = true;
113
+ }
114
+ }
115
+ }
116
+ if (!isValid) {
117
+ // No valid token, run interactive login flow
118
+ (0, login_1.loginCommand)().then((uname) => (0, repl_1.startRepl)(uname)).catch(() => process.exit(1));
94
119
  }
95
120
  else {
96
- // Token exists, start REPL
97
- (0, repl_1.startRepl)().catch((err) => {
121
+ // Token exists and is valid, start REPL
122
+ (0, repl_1.startRepl)(username).catch((err) => {
98
123
  ui_1.ui.error(`REPL crashed: ${err.message}`);
99
124
  process.exit(1);
100
125
  });
package/dist/utils/api.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.refactorCodeApi = refactorCodeApi;
7
7
  exports.getUserProfile = getUserProfile;
8
8
  const config_1 = require("./config");
9
- const genai_1 = require("@google/genai");
9
+ const vertexai_1 = require("@google-cloud/vertexai");
10
10
  const dotenv_1 = __importDefault(require("dotenv"));
11
11
  dotenv_1.default.config();
12
12
  async function refactorCodeApi(fileName, code, instruction, history, modelName, skillsData, thinkingLevel, onChunk, abortSignal) {
@@ -14,7 +14,7 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
14
14
  // 1. HELYI VÉGREHAJTÁS (Ha van GEMINI_API_KEY a .env-ben, közvetlenül a Geminit hívjuk)
15
15
  // Ez tökéletes a helyi teszteléshez, mielőtt a backendre (Vercel) kerül a kód.
16
16
  if (apiKey) {
17
- const ai = new genai_1.GoogleGenAI({ apiKey: apiKey });
17
+ const ai = new vertexai_1.VertexAI({ project: 'draftify-prod', location: 'us-central1' });
18
18
  // Modell kiválasztása a kívánt logika alapján
19
19
  let geminiModel = 'gemini-3.5-flash'; // Alapértelmezett (Medium, Low, Adaptive)
20
20
  if (thinkingLevel === 'High') {
@@ -160,23 +160,24 @@ Throughout, balance deep technical proficiency with an accessible, friendly, wel
160
160
  abortSignal.addEventListener("abort", onAbort);
161
161
  }
162
162
  try {
163
- const responseStream = await ai.models.generateContentStream({
163
+ const generativeModel = ai.getGenerativeModel({
164
164
  model: geminiModel,
165
- contents: contents,
166
- config: {
167
- systemInstruction: systemInstruction
168
- }
165
+ systemInstruction: { role: 'system', parts: [{ text: systemInstruction }] }
166
+ });
167
+ const responseStream = await generativeModel.generateContentStream({
168
+ contents: contents
169
169
  });
170
170
  let tempResult = "";
171
- for await (const chunk of responseStream) {
171
+ for await (const chunk of responseStream.stream) {
172
172
  if (abortSignal?.aborted) {
173
173
  reject(new Error("Aborted"));
174
174
  return;
175
175
  }
176
- if (chunk.text) {
177
- tempResult += chunk.text;
176
+ const text = chunk.candidates?.[0]?.content?.parts?.[0]?.text || "";
177
+ if (text) {
178
+ tempResult += text;
178
179
  if (onChunk)
179
- onChunk(chunk.text);
180
+ onChunk(text);
180
181
  }
181
182
  }
182
183
  resolve(tempResult);
@@ -276,20 +277,25 @@ Throughout, balance deep technical proficiency with an accessible, friendly, wel
276
277
  async function getUserProfile() {
277
278
  const token = (0, config_1.getToken)();
278
279
  if (!token)
279
- return null;
280
+ throw new Error("UNAUTHORIZED");
280
281
  const apiUrl = (0, config_1.getApiUrl)();
281
282
  try {
282
283
  const response = await fetch(apiUrl, {
283
284
  method: "GET",
284
285
  headers: { Authorization: `Bearer ${token}` }
285
286
  });
287
+ if (response.status === 401 || response.status === 403) {
288
+ throw new Error("UNAUTHORIZED");
289
+ }
286
290
  if (response.ok) {
287
291
  const data = await response.json();
288
292
  return { username: data.username, plan: data.plan };
289
293
  }
290
294
  }
291
295
  catch (e) {
292
- // Ignore errors
296
+ if (e.message === "UNAUTHORIZED")
297
+ throw e;
298
+ // Ignore network errors
293
299
  }
294
300
  return null;
295
301
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.52",
3
+ "version": "1.0.56",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -24,6 +24,7 @@
24
24
  "author": "",
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
+ "@google-cloud/vertexai": "^1.12.0",
27
28
  "@google/genai": "^2.8.0",
28
29
  "ansi-escapes": "^7.3.0",
29
30
  "axios": "^1.7.2",