@lvx74/openrrouter-ai-agent 1.0.15 → 1.0.17

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/package.json +1 -1
  2. package/src/lib/utils.js +20 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvx74/openrrouter-ai-agent",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "A powerful AI agent toolkit compatible with @openai/agents for building conversational AI with tool calling support using OpenRouter",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/lib/utils.js CHANGED
@@ -64,7 +64,7 @@ export async function parseJSON(content, tryAgain = true, logger = console) {
64
64
  return parseJSON(corrected, false); // Riprova senza ulteriori tentativi
65
65
  }
66
66
  } catch (e) {
67
- console.error('❌ Errore fatale nel parsing JSON:', e.message);
67
+ console.error('❌ Errore fatale nel parsing JSON:',e);
68
68
  logger.log('📄 Contenuto originale completo:', content);
69
69
  throw e;
70
70
  }
@@ -77,20 +77,25 @@ export async function checkAndCompressHistory(history) {
77
77
 
78
78
  if (history.length > (process.env.MAX_HISTORY_LENGTH || 40)) {
79
79
  console.log(`🔄 Cronologia troppo lunga (${history.length} messaggi), compressione in corso...`);
80
- const latest = history.slice(-4);
81
- const data = history.slice(0, -4).filter(m => m.role !== 'system').slice(-(process.env.MAX_HISTORY_LENGTH || 40));
82
- const prompt = fs.readFileSync(join(__dirname, '../prompts/summarize_conversation_prompt.txt'), 'utf-8') + '\n' + JSON.stringify(data);
83
- const compressed = await callAI(prompt, 0.2, process.env.COMPRESS_MODEL || 'deepseek/deepseek-chat-v3-0324:free');
84
- try {
85
- const parsed = await parseJSON(compressed, true);
86
- if (!parsed || typeof parsed !== 'object') {
87
- throw new Error('La risposta compressa non è un oggetto JSON valido');
88
- }
89
- return [...parsed, ...latest];
90
- } catch (error) {
91
- console.error('❌ Errore nel parsing della risposta compressa:', error.message);
92
- return history.slice(0, -4).filter(m => m.role !== 'system').slice(-(process.env.MAX_HISTORY_LENGTH || 40))
93
- }
80
+
81
+ const systemMessage = history.find(m => m.role === 'system');
82
+ const data = history.filter(m => m.role !== 'system').slice(-10);
83
+ return [systemMessage, ...data];
84
+
85
+ //const latest = history.slice(-4);
86
+ // const data = history.slice(0, -4).filter(m => m.role !== 'system').slice(-(process.env.MAX_HISTORY_LENGTH || 40));
87
+ // const prompt = fs.readFileSync(join(__dirname, '../prompts/summarize_conversation_prompt.txt'), 'utf-8') + '\n' + JSON.stringify(data);
88
+ // const compressed = await callAI(prompt, 0.2, process.env.COMPRESS_MODEL || 'google/gemma-3n-e2b-it:free');
89
+ // try {
90
+ // const parsed = await parseJSON(compressed, true);
91
+ // if (!parsed || typeof parsed !== 'object') {
92
+ // throw new Error('La risposta compressa non è un oggetto JSON valido');
93
+ // }
94
+ // return [...parsed, ...latest];
95
+ // } catch (error) {
96
+ // console.error('❌ Errore nel parsing della risposta compressa:', error);
97
+ // return history.slice(0, -4).filter(m => m.role !== 'system').slice(-(process.env.MAX_HISTORY_LENGTH || 40))
98
+ // }
94
99
  }
95
100
  return history;
96
101
  }