@lvx74/openrrouter-ai-agent 1.0.3 → 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.
- package/package.json +1 -1
- package/src/cli.js +28 -12
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lvx74/openrrouter-ai-agent",
|
3
|
-
"version": "1.0.
|
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
@@ -15,8 +15,19 @@ export function createChatInterface(agent, options = {}) {
|
|
15
15
|
exitCommands = ['/exit', '/quit'],
|
16
16
|
showHelp = true,
|
17
17
|
assistantName = 'Assistant',
|
18
|
+
historyFile = null
|
18
19
|
} = options
|
19
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
|
+
|
20
31
|
const rl = readline.createInterface({
|
21
32
|
input: process.stdin,
|
22
33
|
output: process.stdout,
|
@@ -26,49 +37,49 @@ export function createChatInterface(agent, options = {}) {
|
|
26
37
|
// Special commands handler
|
27
38
|
function handleSpecialCommands(input) {
|
28
39
|
const command = input.toLowerCase().trim()
|
29
|
-
|
40
|
+
|
30
41
|
if (exitCommands.includes(command)) {
|
31
42
|
console.log('\n👋 Arrivederci!')
|
32
43
|
rl.close()
|
33
44
|
return true
|
34
45
|
}
|
35
|
-
|
46
|
+
|
36
47
|
switch (command) {
|
37
48
|
case '/reset':
|
38
49
|
agent.reset()
|
39
50
|
console.log('\n🔄 Conversazione resettata!')
|
40
51
|
return true
|
41
|
-
|
52
|
+
|
42
53
|
case '/history':
|
43
54
|
console.log('\n📚 Cronologia:')
|
44
55
|
console.log(agent.getReadableHistory?.() || JSON.stringify(agent.getHistory(), null, 2))
|
45
56
|
return true
|
46
|
-
|
57
|
+
|
47
58
|
case '/tools':
|
48
59
|
console.log('\n🛠 Tools disponibili:')
|
49
60
|
agent.getTools().forEach(tool => {
|
50
61
|
console.log(` • ${tool.name}: ${tool.description}`)
|
51
62
|
})
|
52
63
|
return true
|
53
|
-
|
64
|
+
|
54
65
|
case '/verbose on':
|
55
66
|
if (agent.setVerbose) {
|
56
67
|
agent.setVerbose(true)
|
57
68
|
console.log('\n📢 Modalità verbose attivata')
|
58
69
|
}
|
59
70
|
return true
|
60
|
-
|
71
|
+
|
61
72
|
case '/verbose off':
|
62
73
|
if (agent.setVerbose) {
|
63
74
|
agent.setVerbose(false)
|
64
75
|
console.log('\n🔇 Modalità verbose disattivata')
|
65
76
|
}
|
66
77
|
return true
|
67
|
-
|
78
|
+
|
68
79
|
case '/help':
|
69
80
|
showHelpMessage()
|
70
81
|
return true
|
71
|
-
|
82
|
+
|
72
83
|
default:
|
73
84
|
return false
|
74
85
|
}
|
@@ -76,7 +87,7 @@ export function createChatInterface(agent, options = {}) {
|
|
76
87
|
|
77
88
|
function showHelpMessage() {
|
78
89
|
console.log('\n📖 Comandi disponibili:')
|
79
|
-
console.log(` • ${exitCommands.join('
|
90
|
+
console.log(` • ${exitCommands.join(' ')} - Esci dalla chat`)
|
80
91
|
console.log(' • /reset - Resetta la conversazione')
|
81
92
|
console.log(' • /history - Mostra cronologia')
|
82
93
|
console.log(' • /tools - Lista dei tools disponibili')
|
@@ -86,6 +97,7 @@ export function createChatInterface(agent, options = {}) {
|
|
86
97
|
|
87
98
|
// Main input handler
|
88
99
|
async function handleInput(input) {
|
100
|
+
|
89
101
|
if (handleSpecialCommands(input)) {
|
90
102
|
return
|
91
103
|
}
|
@@ -97,6 +109,10 @@ export function createChatInterface(agent, options = {}) {
|
|
97
109
|
try {
|
98
110
|
const result = await agent.run(input)
|
99
111
|
console.log(`\n🤖 ${assistantName}: ${result.content}`)
|
112
|
+
if (historyFile) {
|
113
|
+
saveHistory(agent, historyFile)
|
114
|
+
console.log(`\n💾 Cronologia salvata in ${historyFile}`)
|
115
|
+
}
|
100
116
|
} catch (error) {
|
101
117
|
console.error('\n❌ Errore:', error.message)
|
102
118
|
}
|
@@ -134,7 +150,7 @@ export function saveHistory(agent, filename) {
|
|
134
150
|
if (!filename) {
|
135
151
|
filename = `chat_history_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.json`
|
136
152
|
}
|
137
|
-
|
153
|
+
|
138
154
|
const history = agent.getHistory()
|
139
155
|
fs.writeFileSync(filename, JSON.stringify(history, null, 2))
|
140
156
|
return filename
|
@@ -147,10 +163,10 @@ export function loadHistory(agent, filename) {
|
|
147
163
|
if (!fs.existsSync(filename)) {
|
148
164
|
throw new Error(`File not found: ${filename}`)
|
149
165
|
}
|
150
|
-
|
166
|
+
|
151
167
|
const historyData = fs.readFileSync(filename, 'utf8')
|
152
168
|
const history = JSON.parse(historyData)
|
153
|
-
|
169
|
+
|
154
170
|
agent.setHistory(history)
|
155
171
|
return history
|
156
172
|
}
|