primocode 4.2.4 → 4.3.1
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/bin/primocode.js +23 -4
- package/lib/api.js +2 -2
- package/package.json +1 -1
package/bin/primocode.js
CHANGED
|
@@ -83,6 +83,7 @@ async function webSearch(query) {
|
|
|
83
83
|
|
|
84
84
|
// ---- Pipeline Multi-Agente Oculto ----
|
|
85
85
|
async function runMultiAgent(userText) {
|
|
86
|
+
console.log(c.muted(' 🚀 Gerando código...'));
|
|
86
87
|
const sp = new Spinner('').start();
|
|
87
88
|
|
|
88
89
|
try {
|
|
@@ -200,7 +201,7 @@ async function runChat(promptForModel, userTextForMemory) {
|
|
|
200
201
|
// Silencia erro de conexão completamente
|
|
201
202
|
return;
|
|
202
203
|
}
|
|
203
|
-
if (!started) { sp.stop(); console.log(c.muted('\n
|
|
204
|
+
if (!started) { sp.stop(); console.log(c.muted('\n ⚡ Resposta rápida indisponível. Use /mode Chat para conversar.')); return; }
|
|
204
205
|
|
|
205
206
|
state.history.push({ role: 'user', content: userTextForMemory });
|
|
206
207
|
state.history.push({ role: 'assistant', content: text });
|
|
@@ -208,6 +209,20 @@ async function runChat(promptForModel, userTextForMemory) {
|
|
|
208
209
|
cfg.appendHistory({ mode: state.mode, prompt: userTextForMemory, response: text });
|
|
209
210
|
}
|
|
210
211
|
|
|
212
|
+
// ---- Detectar se é pedido de código ----
|
|
213
|
+
function isCodeRequest(text) {
|
|
214
|
+
const codeKeywords = [
|
|
215
|
+
'crie', 'criar', 'faça', 'fazer', 'desenvolva', 'desenvolver',
|
|
216
|
+
'build', 'make', 'create', 'generate', 'code', 'codigo',
|
|
217
|
+
'site', 'web', 'app', 'aplicativo', 'programa', 'script',
|
|
218
|
+
'calculadora', 'jogo', 'game', 'pagina', 'website',
|
|
219
|
+
'html', 'css', 'js', 'python', 'react', 'vue', 'angular',
|
|
220
|
+
'api', 'backend', 'frontend', 'database', 'banco de dados'
|
|
221
|
+
];
|
|
222
|
+
const lower = text.toLowerCase();
|
|
223
|
+
return codeKeywords.some(kw => lower.includes(kw));
|
|
224
|
+
}
|
|
225
|
+
|
|
211
226
|
// ---- Envio Principal ----
|
|
212
227
|
async function sendPrompt(userText) {
|
|
213
228
|
let promptWithAttach = userText;
|
|
@@ -216,15 +231,19 @@ async function sendPrompt(userText) {
|
|
|
216
231
|
promptWithAttach = parts.join('\n\n') + '\n\n' + userText;
|
|
217
232
|
}
|
|
218
233
|
|
|
219
|
-
// Adicionar contexto de memória
|
|
234
|
+
// Adicionar contexto de memória
|
|
220
235
|
const memContext = memory.loadMemory();
|
|
221
236
|
if (memContext) {
|
|
222
|
-
// Usar formato de system message, não como prompt de pesquisa
|
|
223
237
|
promptWithAttach = `[Memória do sistema: ${memContext.substring(0, 300)}]\n\n${promptWithAttach}`;
|
|
224
238
|
}
|
|
225
239
|
|
|
226
240
|
if (state.mode === 'Primo Code') {
|
|
227
|
-
|
|
241
|
+
// Se for conversa simples (oi, tudo bem, etc.), usar Chat direto
|
|
242
|
+
if (!isCodeRequest(userText)) {
|
|
243
|
+
await runChat(promptWithAttach, userText);
|
|
244
|
+
} else {
|
|
245
|
+
await runMultiAgent(promptWithAttach);
|
|
246
|
+
}
|
|
228
247
|
} else {
|
|
229
248
|
await runChat(promptWithAttach, userText);
|
|
230
249
|
}
|
package/lib/api.js
CHANGED
|
@@ -12,7 +12,7 @@ function request(serverUrl, endpoint, payload) {
|
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
const url = new URL(endpoint, serverUrl);
|
|
14
14
|
const data = JSON.stringify(payload);
|
|
15
|
-
const options = { hostname: url.hostname, port: url.port || (url.protocol==='https:'?443:80), path: url.pathname+url.search, method: 'POST', headers: { 'Content-Type':'application/json', 'Content-Length':Buffer.byteLength(data) } };
|
|
15
|
+
const options = { hostname: url.hostname, port: url.port || (url.protocol==='https:'?443:80), path: url.pathname+url.search, method: 'POST', headers: { 'Content-Type':'application/json', 'Content-Length':Buffer.byteLength(data) }, timeout: 60000 };
|
|
16
16
|
const client = url.protocol==='https:' ? https : http;
|
|
17
17
|
const req = client.request(options, (res) => { let body=''; res.on('data', c=>body+=c); res.on('end', () => { try { const json=JSON.parse(body); if (res.statusCode>=400) reject(new Error(json.erro||json.error||`HTTP ${res.statusCode}`)); else resolve(json); } catch { reject(new Error(`Resposta inválida: ${body.slice(0,200)}`)); } }); });
|
|
18
18
|
req.on('error', reject); req.write(data); req.end();
|
|
@@ -23,7 +23,7 @@ function requestStream(serverUrl, endpoint, payload, onEvent) {
|
|
|
23
23
|
return new Promise((resolve, reject) => {
|
|
24
24
|
const url = new URL(endpoint, serverUrl);
|
|
25
25
|
const data = JSON.stringify(payload);
|
|
26
|
-
const options = { hostname: url.hostname, port: url.port || (url.protocol==='https:'?443:80), path: url.pathname+url.search, method: 'POST', headers: { 'Content-Type':'application/json', 'Content-Length':Buffer.byteLength(data), 'Accept':'text/event-stream' } };
|
|
26
|
+
const options = { hostname: url.hostname, port: url.port || (url.protocol==='https:'?443:80), path: url.pathname+url.search, method: 'POST', headers: { 'Content-Type':'application/json', 'Content-Length':Buffer.byteLength(data), 'Accept':'text/event-stream' }, timeout: 60000 };
|
|
27
27
|
const client = url.protocol==='https:' ? https : http;
|
|
28
28
|
const req = client.request(options, (res) => { let buffer=''; res.on('data', chunk => { buffer+=chunk; const lines=buffer.split('\n'); buffer=lines.pop(); for (const line of lines) if (line.startsWith('data: ')) { try { const evt=JSON.parse(line.slice(6)); onEvent(evt); if (evt.done) resolve(); } catch {} } }); res.on('end', () => resolve()); });
|
|
29
29
|
req.on('error', reject); req.write(data); req.end();
|
package/package.json
CHANGED