natureco-cli 2.23.18 → 2.23.20
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/package.json +1 -1
- package/src/commands/code.js +19 -101
- package/src/utils/api.js +1 -7
package/package.json
CHANGED
package/src/commands/code.js
CHANGED
|
@@ -6,7 +6,7 @@ const { execSync } = require('child_process');
|
|
|
6
6
|
const inquirer = require('../utils/inquirer-wrapper');
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
const { getApiKey, getConfig } = require('../utils/config');
|
|
9
|
-
const { getBots, getProviderConfig, startMcpServers } = require('../utils/api');
|
|
9
|
+
const { getBots, getProviderConfig, startMcpServers, sendMessageOpenAICompatible, streamProviderCompletion } = require('../utils/api');
|
|
10
10
|
const { getMemoryPrompt, loadMemory } = require('../utils/memory');
|
|
11
11
|
const { getAgentsPrompt } = require('../utils/agents');
|
|
12
12
|
const { createSession, addMessageToSession } = require('../utils/sessions');
|
|
@@ -159,13 +159,8 @@ async function generateSummary(messages, providerConfig) {
|
|
|
159
159
|
if (!recent.length) return 'Bu session boş geçti.';
|
|
160
160
|
const prompt = `Bu kod session'ını 3-5 madde halinde Türkçe özetle. Ne yapıldı, hangi dosyalar değiştirildi, hangi sorunlar çözüldü:\n${JSON.stringify(recent).slice(0, 3000)}`;
|
|
161
161
|
try {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
headers: { 'Authorization': `Bearer ${providerConfig.apiKey}`, 'Content-Type': 'application/json' },
|
|
165
|
-
body: JSON.stringify({ model: providerConfig.model, messages: [{ role: 'user', content: prompt }], max_tokens: 400, stream: false }),
|
|
166
|
-
});
|
|
167
|
-
const data = await res.json();
|
|
168
|
-
return data.choices?.[0]?.message?.content || 'Özet oluşturulamadı.';
|
|
162
|
+
const result = await sendMessageOpenAICompatible(providerConfig, [{ role: 'user', content: prompt }], []);
|
|
163
|
+
return result.content || 'Özet oluşturulamadı.';
|
|
169
164
|
} catch {
|
|
170
165
|
return 'Özet oluşturulamadı.';
|
|
171
166
|
}
|
|
@@ -185,106 +180,29 @@ async function saveProjectMemory(messages, providerConfig, workDir) {
|
|
|
185
180
|
|
|
186
181
|
// ── Git helpers ───────────────────────────────────────────────────────────────
|
|
187
182
|
async function generateCommitMessage(diff, providerConfig) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
messages: [
|
|
183
|
+
try {
|
|
184
|
+
const result = await sendMessageOpenAICompatible(providerConfig, [
|
|
191
185
|
{ role: 'system', content: 'Sen bir git commit mesajı üreticisin. Conventional Commits formatında (feat/fix/refactor/chore vb.) kısa ve açıklayıcı bir commit mesajı yaz. Sadece mesajı yaz, başka hiçbir şey yazma.' },
|
|
192
186
|
{ role: 'user', content: `Bu diff için commit mesajı üret:\n\n${diff}` },
|
|
193
|
-
],
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
const res = await fetch(`${providerConfig.url}/chat/completions`, {
|
|
199
|
-
method: 'POST',
|
|
200
|
-
headers: { 'Authorization': `Bearer ${providerConfig.apiKey}`, 'Content-Type': 'application/json' },
|
|
201
|
-
body: JSON.stringify(body),
|
|
202
|
-
});
|
|
203
|
-
const data = await res.json();
|
|
204
|
-
return (data.choices?.[0]?.message?.content || 'chore: update files').trim().replace(/^["']|["']$/g, '');
|
|
187
|
+
], []);
|
|
188
|
+
return (result.content || 'chore: update files').trim().replace(/^["']|["']$/g, '');
|
|
189
|
+
} catch {
|
|
190
|
+
return 'chore: update files';
|
|
191
|
+
}
|
|
205
192
|
}
|
|
206
193
|
|
|
207
194
|
|
|
208
195
|
async function streamMessage(providerConfig, messages, tools) {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
messages,
|
|
213
|
-
tools,
|
|
214
|
-
tool_choice: 'auto',
|
|
215
|
-
temperature: 0.7,
|
|
216
|
-
max_tokens: 4000,
|
|
217
|
-
stream: true,
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const response = await fetch(endpoint, {
|
|
221
|
-
method: 'POST',
|
|
222
|
-
headers: {
|
|
223
|
-
'Authorization': `Bearer ${providerConfig.apiKey}`,
|
|
224
|
-
'Content-Type': 'application/json',
|
|
225
|
-
},
|
|
226
|
-
body: JSON.stringify(body),
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
if (!response.ok) {
|
|
230
|
-
const err = await response.text();
|
|
231
|
-
throw new Error(`API error: ${response.status} — ${err}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const reader = response.body.getReader();
|
|
235
|
-
const decoder = new TextDecoder();
|
|
236
|
-
let fullText = '';
|
|
237
|
-
let toolCallsBuffer = {};
|
|
238
|
-
|
|
239
|
-
process.stdout.write('\n');
|
|
240
|
-
|
|
241
|
-
while (true) {
|
|
242
|
-
const { done, value } = await reader.read();
|
|
243
|
-
if (done) break;
|
|
244
|
-
const chunk = decoder.decode(value);
|
|
245
|
-
const lines = chunk.split('\n').filter(l => l.startsWith('data: '));
|
|
246
|
-
for (const line of lines) {
|
|
247
|
-
const data = line.slice(6).trim();
|
|
248
|
-
if (data === '[DONE]') continue;
|
|
249
|
-
try {
|
|
250
|
-
const json = JSON.parse(data);
|
|
251
|
-
const delta = json.choices?.[0]?.delta;
|
|
252
|
-
if (!delta) continue;
|
|
253
|
-
if (delta.content) { process.stdout.write(delta.content); fullText += delta.content; }
|
|
254
|
-
if (delta.tool_calls) {
|
|
255
|
-
for (const tc of delta.tool_calls) {
|
|
256
|
-
const idx = tc.index ?? 0;
|
|
257
|
-
if (!toolCallsBuffer[idx]) {
|
|
258
|
-
toolCallsBuffer[idx] = { id: '', name: '', arguments: '' };
|
|
259
|
-
}
|
|
260
|
-
if (tc.id != null) {
|
|
261
|
-
toolCallsBuffer[idx].id = tc.id;
|
|
262
|
-
}
|
|
263
|
-
// OpenAI format: tc.function.name / tc.function.arguments
|
|
264
|
-
if (tc.function) {
|
|
265
|
-
if (tc.function.name != null) toolCallsBuffer[idx].name += tc.function.name;
|
|
266
|
-
if (tc.function.arguments != null) toolCallsBuffer[idx].arguments += tc.function.arguments;
|
|
267
|
-
}
|
|
268
|
-
// Alternate format (llama-4-scout etc.): tc.name / tc.arguments directly
|
|
269
|
-
if (tc.name != null) toolCallsBuffer[idx].name += tc.name;
|
|
270
|
-
if (tc.arguments != null) toolCallsBuffer[idx].arguments += tc.arguments;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} catch {}
|
|
274
|
-
}
|
|
196
|
+
const result = await streamProviderCompletion(providerConfig, messages, tools);
|
|
197
|
+
if (result.type === 'text') {
|
|
198
|
+
return { text: result.content, toolCalls: [] };
|
|
275
199
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
id: tc.id,
|
|
283
|
-
name: tc.name,
|
|
284
|
-
input: (() => { try { return JSON.parse(tc.arguments); } catch { return {}; } })(),
|
|
285
|
-
}));
|
|
286
|
-
|
|
287
|
-
return { text: fullText, toolCalls };
|
|
200
|
+
const toolCalls = result.message.tool_calls.map(tc => ({
|
|
201
|
+
id: tc.id,
|
|
202
|
+
name: tc.function.name,
|
|
203
|
+
input: (() => { try { return JSON.parse(tc.function.arguments); } catch { return {}; } })(),
|
|
204
|
+
}));
|
|
205
|
+
return { text: result.message.content || '', toolCalls };
|
|
288
206
|
}
|
|
289
207
|
|
|
290
208
|
// ── Tool execution ────────────────────────────────────────────────────────────
|
package/src/utils/api.js
CHANGED
|
@@ -432,8 +432,6 @@ async function sendMessageOpenAICompatible(providerConfig, messages, tools) {
|
|
|
432
432
|
const endpoint = baseUrl.includes('api.natureco.me')
|
|
433
433
|
? 'https://api.natureco.me/api/v1/chat/completions'
|
|
434
434
|
: `${baseUrl}/chat/completions`;
|
|
435
|
-
console.error('DEBUG endpoint:', endpoint);
|
|
436
|
-
|
|
437
435
|
const requestBody = {
|
|
438
436
|
model: providerConfig.model,
|
|
439
437
|
messages: messages,
|
|
@@ -464,13 +462,11 @@ async function sendMessageOpenAICompatible(providerConfig, messages, tools) {
|
|
|
464
462
|
}
|
|
465
463
|
|
|
466
464
|
const data = await response.json();
|
|
467
|
-
console.error('DEBUG response raw:', JSON.stringify(data).slice(0, 300));
|
|
468
465
|
const content = data.choices?.[0]?.message?.content
|
|
469
466
|
|| data.choices?.[0]?.text
|
|
470
467
|
|| data.response
|
|
471
468
|
|| data.content
|
|
472
469
|
|| '';
|
|
473
|
-
console.error('DEBUG content:', content);
|
|
474
470
|
return {
|
|
475
471
|
role: 'assistant',
|
|
476
472
|
content,
|
|
@@ -536,7 +532,6 @@ async function sendMessageAnthropic(providerConfig, messages, tools) {
|
|
|
536
532
|
*/
|
|
537
533
|
async function sendMessageToProvider(apiKey, message, conversationId = null, systemPrompt = null, options = {}) {
|
|
538
534
|
const providerConfig = getProviderConfig();
|
|
539
|
-
console.error('DEBUG sendMessageToProvider providerUrl:', providerConfig?.url);
|
|
540
535
|
|
|
541
536
|
if (!providerConfig) {
|
|
542
537
|
throw new Error(
|
|
@@ -737,8 +732,7 @@ async function sendMessage(apiKey, botId, message, conversationId = null, chatSy
|
|
|
737
732
|
// Handle legacy 6th param (toolDefinitions array was passed)
|
|
738
733
|
if (Array.isArray(options)) options = {};
|
|
739
734
|
const providerConfig = getProviderConfig();
|
|
740
|
-
|
|
741
|
-
console.error('DEBUG provider type:', providerConfig?.isAnthropic ? 'anthropic' : 'openai');
|
|
735
|
+
|
|
742
736
|
// Get user's home directory
|
|
743
737
|
const homeDir = os.homedir();
|
|
744
738
|
|