@lvx74/openrrouter-ai-agent 1.0.4 → 1.0.5

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/cli.js +23 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvx74/openrrouter-ai-agent",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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/cli.js CHANGED
@@ -18,6 +18,16 @@ export function createChatInterface(agent, options = {}) {
18
18
  historyFile = null
19
19
  } = options
20
20
 
21
+ if (historyFile && !fs.existsSync(historyFile)) {
22
+ try {
23
+ agent.setHistory(fs.readFileSync(historyFile, 'utf8'))
24
+ console.log(`\n📜 Cronologia caricata da ${historyFile}`)
25
+ } catch (error) {
26
+ console.error(`\n❌ Errore nel caricamento della cronologia: ${error.message}`)
27
+ return
28
+ }
29
+ }
30
+
21
31
  const rl = readline.createInterface({
22
32
  input: process.stdin,
23
33
  output: process.stdout,
@@ -27,49 +37,49 @@ export function createChatInterface(agent, options = {}) {
27
37
  // Special commands handler
28
38
  function handleSpecialCommands(input) {
29
39
  const command = input.toLowerCase().trim()
30
-
40
+
31
41
  if (exitCommands.includes(command)) {
32
42
  console.log('\n👋 Arrivederci!')
33
43
  rl.close()
34
44
  return true
35
45
  }
36
-
46
+
37
47
  switch (command) {
38
48
  case '/reset':
39
49
  agent.reset()
40
50
  console.log('\n🔄 Conversazione resettata!')
41
51
  return true
42
-
52
+
43
53
  case '/history':
44
54
  console.log('\n📚 Cronologia:')
45
55
  console.log(agent.getReadableHistory?.() || JSON.stringify(agent.getHistory(), null, 2))
46
56
  return true
47
-
57
+
48
58
  case '/tools':
49
59
  console.log('\n🛠 Tools disponibili:')
50
60
  agent.getTools().forEach(tool => {
51
61
  console.log(` • ${tool.name}: ${tool.description}`)
52
62
  })
53
63
  return true
54
-
64
+
55
65
  case '/verbose on':
56
66
  if (agent.setVerbose) {
57
67
  agent.setVerbose(true)
58
68
  console.log('\n📢 Modalità verbose attivata')
59
69
  }
60
70
  return true
61
-
71
+
62
72
  case '/verbose off':
63
73
  if (agent.setVerbose) {
64
74
  agent.setVerbose(false)
65
75
  console.log('\n🔇 Modalità verbose disattivata')
66
76
  }
67
77
  return true
68
-
78
+
69
79
  case '/help':
70
80
  showHelpMessage()
71
81
  return true
72
-
82
+
73
83
  default:
74
84
  return false
75
85
  }
@@ -87,7 +97,7 @@ export function createChatInterface(agent, options = {}) {
87
97
 
88
98
  // Main input handler
89
99
  async function handleInput(input) {
90
-
100
+
91
101
  if (handleSpecialCommands(input)) {
92
102
  return
93
103
  }
@@ -99,7 +109,7 @@ export function createChatInterface(agent, options = {}) {
99
109
  try {
100
110
  const result = await agent.run(input)
101
111
  console.log(`\n🤖 ${assistantName}: ${result.content}`)
102
- if(historyFile) {
112
+ if (historyFile) {
103
113
  saveHistory(agent, historyFile)
104
114
  console.log(`\n💾 Cronologia salvata in ${historyFile}`)
105
115
  }
@@ -140,7 +150,7 @@ export function saveHistory(agent, filename) {
140
150
  if (!filename) {
141
151
  filename = `chat_history_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.json`
142
152
  }
143
-
153
+
144
154
  const history = agent.getHistory()
145
155
  fs.writeFileSync(filename, JSON.stringify(history, null, 2))
146
156
  return filename
@@ -153,10 +163,10 @@ export function loadHistory(agent, filename) {
153
163
  if (!fs.existsSync(filename)) {
154
164
  throw new Error(`File not found: ${filename}`)
155
165
  }
156
-
166
+
157
167
  const historyData = fs.readFileSync(filename, 'utf8')
158
168
  const history = JSON.parse(historyData)
159
-
169
+
160
170
  agent.setHistory(history)
161
171
  return history
162
172
  }