draftify-cli 1.0.4 → 1.0.6
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/repl.js +6 -0
- package/dist/utils/api.js +42 -1
- package/dist/utils/config.js +10 -0
- package/package.json +1 -1
package/dist/repl.js
CHANGED
|
@@ -432,6 +432,7 @@ async function startRepl(initialUsername) {
|
|
|
432
432
|
console.log(` ${(0, kleur_1.cyan)("/thinking-level")} - Adjust the AI's thinking process depth`);
|
|
433
433
|
console.log(` ${(0, kleur_1.cyan)("/login")} - Log in to your Draftify account`);
|
|
434
434
|
console.log(` ${(0, kleur_1.cyan)("/logout")} - Log out of your account`);
|
|
435
|
+
console.log(` ${(0, kleur_1.cyan)("/usage")} - Show your token usage and quota`);
|
|
435
436
|
console.log(` ${(0, kleur_1.cyan)("/help")} - List commands`);
|
|
436
437
|
console.log(` ${(0, kleur_1.cyan)("/clear")} - Clear the terminal screen`);
|
|
437
438
|
console.log(` ${(0, kleur_1.cyan)("/exit")} - Exit the CLI`);
|
|
@@ -440,6 +441,11 @@ async function startRepl(initialUsername) {
|
|
|
440
441
|
else if (cmd === "clear") {
|
|
441
442
|
renderWelcome();
|
|
442
443
|
}
|
|
444
|
+
else if (cmd === "usage") {
|
|
445
|
+
ui_1.ui.header("Usage & Quota");
|
|
446
|
+
console.log(` Quota: ${(0, kleur_1.cyan)("Infinite")}`);
|
|
447
|
+
console.log(` Tokens used: ${(0, kleur_1.cyan)((0, config_1.getTokensUsed)().toLocaleString())}\n`);
|
|
448
|
+
}
|
|
443
449
|
else if (cmd === "chats") {
|
|
444
450
|
const chats = (0, chats_1.loadChats)();
|
|
445
451
|
if (chats.length === 0) {
|
package/dist/utils/api.js
CHANGED
|
@@ -46,11 +46,46 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
|
|
|
46
46
|
role: 'user',
|
|
47
47
|
parts: [{ text: currentPrompt }]
|
|
48
48
|
});
|
|
49
|
+
const systemInstruction = `You are Draftify AI, an expert software engineering CLI assistant.
|
|
50
|
+
You have the ability to automatically create files, modify files, delete files, and run terminal commands on the user's machine.
|
|
51
|
+
To do this, you MUST format your response using the following XML tags:
|
|
52
|
+
|
|
53
|
+
1. To create a file:
|
|
54
|
+
<FILE_CREATE path="relative/path/to/file.ext">
|
|
55
|
+
file content here
|
|
56
|
+
</FILE_CREATE>
|
|
57
|
+
|
|
58
|
+
2. To modify an existing file:
|
|
59
|
+
<FILE_MODIFY path="relative/path/to/file.ext">
|
|
60
|
+
<<<<<<< SEARCH
|
|
61
|
+
exact lines to replace
|
|
62
|
+
=======
|
|
63
|
+
new lines
|
|
64
|
+
>>>>>>>
|
|
65
|
+
</FILE_MODIFY>
|
|
66
|
+
|
|
67
|
+
3. To delete a file:
|
|
68
|
+
<FILE_DELETE path="relative/path/to/file.ext" />
|
|
69
|
+
|
|
70
|
+
4. To run a terminal command:
|
|
71
|
+
<RUN_COMMAND>npm install express</RUN_COMMAND>
|
|
72
|
+
|
|
73
|
+
5. To ask clarifying questions when the user's intent is ambiguous:
|
|
74
|
+
<ASK_QUESTIONS>
|
|
75
|
+
[
|
|
76
|
+
{
|
|
77
|
+
"question": "What tech stack do you prefer?",
|
|
78
|
+
"options": ["React + Vite", "Next.js", "Vanilla HTML/JS"]
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
</ASK_QUESTIONS>
|
|
82
|
+
|
|
83
|
+
Always use these tags when you write code or ask questions so the CLI can apply it automatically! Keep explanations short and outside the tags.`;
|
|
49
84
|
const responseStream = await ai.models.generateContentStream({
|
|
50
85
|
model: geminiModel,
|
|
51
86
|
contents: contents,
|
|
52
87
|
config: {
|
|
53
|
-
systemInstruction:
|
|
88
|
+
systemInstruction: systemInstruction
|
|
54
89
|
}
|
|
55
90
|
});
|
|
56
91
|
let fullResult = "";
|
|
@@ -63,6 +98,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
|
|
|
63
98
|
onChunk(chunk.text);
|
|
64
99
|
}
|
|
65
100
|
}
|
|
101
|
+
// Rough estimation of tokens
|
|
102
|
+
const estimatedTokens = Math.ceil((JSON.stringify(contents).length + fullResult.length) / 4);
|
|
103
|
+
(0, config_1.addTokensUsed)(estimatedTokens);
|
|
66
104
|
return fullResult;
|
|
67
105
|
}
|
|
68
106
|
// 2. TÁVOLI VÉGREHAJTÁS (Eredeti Vercel backend kód, ha nincs helyi API kulcs)
|
|
@@ -143,6 +181,9 @@ async function refactorCodeApi(fileName, code, instruction, history, modelName,
|
|
|
143
181
|
}
|
|
144
182
|
}
|
|
145
183
|
}
|
|
184
|
+
// Rough estimation of tokens
|
|
185
|
+
const estimatedTokens = Math.ceil((JSON.stringify({ fileName, code, instruction, history, modelName, skillsData }).length + fullResult.length) / 4);
|
|
186
|
+
(0, config_1.addTokensUsed)(estimatedTokens);
|
|
146
187
|
return fullResult;
|
|
147
188
|
}
|
|
148
189
|
async function getUserProfile() {
|
package/dist/utils/config.js
CHANGED
|
@@ -14,6 +14,8 @@ exports.setSkills = setSkills;
|
|
|
14
14
|
exports.getThinkingLevel = getThinkingLevel;
|
|
15
15
|
exports.setThinkingLevel = setThinkingLevel;
|
|
16
16
|
exports.getGeminiApiKey = getGeminiApiKey;
|
|
17
|
+
exports.getTokensUsed = getTokensUsed;
|
|
18
|
+
exports.addTokensUsed = addTokensUsed;
|
|
17
19
|
const os_1 = __importDefault(require("os"));
|
|
18
20
|
const fs_1 = __importDefault(require("fs"));
|
|
19
21
|
const path_1 = __importDefault(require("path"));
|
|
@@ -76,3 +78,11 @@ function getGeminiApiKey() {
|
|
|
76
78
|
const config = getConfig();
|
|
77
79
|
return config.geminiApiKey || null;
|
|
78
80
|
}
|
|
81
|
+
function getTokensUsed() {
|
|
82
|
+
const config = getConfig();
|
|
83
|
+
return config.tokensUsed || 0;
|
|
84
|
+
}
|
|
85
|
+
function addTokensUsed(amount) {
|
|
86
|
+
const current = getTokensUsed();
|
|
87
|
+
saveConfig({ tokensUsed: current + amount });
|
|
88
|
+
}
|