node-red-contrib-linux-copilot 1.0.3 → 1.2.8

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.
@@ -1,50 +1,30 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType('linux-copilot',{
3
- category: 'advanced',
4
- color: '#E2D96E',
3
+ category: 'function',
4
+ color: '#a6bbcf',
5
5
  defaults: {
6
6
  name: {value:""},
7
- prioDS: {value:"1"},
8
- prioOR: {value:"2"},
9
- prioGEM: {value:"3"},
10
- chatId: {value:"1457427557"}
7
+ chatId: {value:""}
11
8
  },
12
9
  credentials: {
13
- deepseekKey: {type:"password"},
10
+ geminiKey: {type:"password"},
14
11
  openrouterKey: {type:"password"},
15
- geminiKey: {type:"password"}
12
+ deepseekKey: {type:"password"}
16
13
  },
17
14
  inputs:1,
18
15
  outputs:1,
19
- icon: "font-awesome/fa-terminal",
20
- label: function() { return this.name || "linux-copilot"; }
16
+ icon: "bridge.png",
17
+ label: function() { return this.name||"linux-copilot"; }
21
18
  });
22
19
  </script>
23
20
 
24
21
  <script type="text/html" data-template-name="linux-copilot">
25
22
  <div class="form-row">
26
23
  <label for="node-input-name"><i class="fa fa-tag"></i> Nom</label>
27
- <input type="text" id="node-input-name" placeholder="Linux Copilot">
24
+ <input type="text" id="node-input-name" placeholder="Name">
28
25
  </div>
29
26
  <div class="form-row">
30
- <label for="node-input-chatId"><i class="fa fa-comment"></i> Chat ID</label>
27
+ <label for="node-input-chatId">Chat ID</label>
31
28
  <input type="text" id="node-input-chatId">
32
29
  </div>
33
- <hr>
34
- <h4>Priorités (1 = Premier utilisé)</h4>
35
- <div class="form-row">
36
- <label for="node-input-prioDS">DeepSeek</label>
37
- <input type="number" id="node-input-prioDS" style="width:50px" min="1">
38
- <input type="password" id="node-input-deepseekKey" placeholder="Clé API" style="width:200px">
39
- </div>
40
- <div class="form-row">
41
- <label for="node-input-prioOR">OpenRouter</label>
42
- <input type="number" id="node-input-prioOR" style="width:50px" min="1">
43
- <input type="password" id="node-input-openrouterKey" placeholder="Clé API" style="width:200px">
44
- </div>
45
- <div class="form-row">
46
- <label for="node-input-prioGEM">Gemini</label>
47
- <input type="number" id="node-input-prioGEM" style="width:50px" min="1">
48
- <input type="password" id="node-input-geminiKey" placeholder="Clé API" style="width:200px">
49
- </div>
50
30
  </script>
package/linux-copilot.js CHANGED
@@ -7,98 +7,20 @@ module.exports = function(RED) {
7
7
  const node = this;
8
8
 
9
9
  const omniPrompt = `Tu es un Expert Linux SRE polyglotte.
10
- RÈGLES CRUCIALES :
11
- 1. LANGUE : Détecte la langue de l'utilisateur. Tu DOIS répondre EXCLUSIVEMENT dans cette langue (si on te parle en Français, réponds en Français; si c'est en Espagnol, réponds en Espagnol).
12
- 2. ANALYSE : Analyse brièvement les résultats techniques.
13
- 3. ACTION : Propose la commande suivante pour continuer le diagnostic.
14
- 4. FORMAT JSON : {"speech": "ton explication dans la langue de l'utilisateur", "cmd": "commande linux ou none"}`;
15
-
16
- const formatHistory = (history) => history.map(h => ({
17
- role: h.role === "model" ? "assistant" : h.role,
18
- content: String(h.content).substring(0, 800)
19
- }));
20
-
21
- const engines = {
22
- gemini: async (history, key) => {
23
- const res = await axios.post(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${key.trim()}`, {
24
- contents: history.map(h => ({ role: h.role === "assistant" ? "model" : h.role, parts: [{ text: h.content }] })),
25
- system_instruction: { parts: [{ text: omniPrompt }] },
26
- generationConfig: { responseMimeType: "application/json" }
27
- }, { timeout: 15000 });
28
- return JSON.parse(res.data.candidates[0].content.parts[0].text);
29
- },
30
- openrouter: async (history, key) => {
31
- const res = await axios.post('https://openrouter.ai/api/v1/chat/completions', {
32
- model: "meta-llama/llama-3.3-70b-instruct:free",
33
- messages: [{ role: 'system', content: omniPrompt }, ...formatHistory(history)]
34
- }, { headers: { 'Authorization': `Bearer ${key.trim()}`, 'Content-Type': 'application/json' }, timeout: 25000 });
35
- const match = res.data.choices[0].message.content.match(/\{[\s\S]*\}/);
36
- return JSON.parse(match ? match[0] : res.data.choices[0].message.content);
37
- },
38
- deepseek: async (history, key) => {
39
- const res = await axios.post('https://api.deepseek.com/chat/completions', {
40
- model: "deepseek-chat",
41
- messages: [{ role: 'system', content: omniPrompt }, ...formatHistory(history)],
42
- response_format: { type: 'json_object' }
43
- }, { headers: { 'Authorization': `Bearer ${key.trim()}` }, timeout: 20000 });
44
- return JSON.parse(res.data.choices[0].message.content);
45
- }
46
- };
10
+ FORMAT JSON : {"speech": "ton explication", "cmd": "commande linux ou none"}`;
47
11
 
48
12
  node.on('input', async function(msg) {
49
13
  const chatId = msg.payload.chatId || config.chatId || "1457427557";
50
- let userText = msg.payload.content || (typeof msg.payload === 'string' ? msg.payload : "");
51
- let loopCount = msg.loopCount || 0;
52
-
53
- if (loopCount > 4) return node.status({fill:"blue", text:"Fin de séquence"});
54
-
55
14
  let history = node.context().get('history') || [];
56
- if (userText.toLowerCase() === "reset") {
57
- node.context().set('history', []);
58
- return node.send({ payload: { chatId, type: "message", content: "♻️ Historique effacé." } });
59
- }
60
-
61
- if (!userText) return;
62
- history.push({ role: "user", content: userText });
63
-
64
- let queue = [
65
- { id: 'deepseek', p: parseInt(config.prioDS) || 1, k: node.credentials.deepseekKey, n: "DeepSeek" },
66
- { id: 'openrouter', p: parseInt(config.prioOR) || 2, k: node.credentials.openrouterKey, n: "OpenRouter" },
67
- { id: 'gemini', p: parseInt(config.prioGEM) || 3, k: node.credentials.geminiKey, n: "Gemini" }
68
- ].filter(q => q.k).sort((a, b) => a.p - b.p);
69
-
70
- let aiData = null;
71
- let engineUsed = "";
72
-
73
- for (let e of queue) {
74
- try {
75
- node.status({fill:"yellow", text: `Appel ${e.n}...`});
76
- aiData = await engines[e.id](history, e.k);
77
- if (aiData && (aiData.speech || aiData.cmd)) { engineUsed = e.n; break; }
78
- } catch (err) { node.warn(`Échec ${e.n}`); }
79
- }
80
-
81
- if (!aiData) return node.status({fill:"red", text:"Erreur API"});
82
-
83
- node.send({ payload: { chatId, type: "message", content: `🤖 <b>${engineUsed}</b> : ${aiData.speech}`, options: { parse_mode: "HTML" } } });
84
-
85
- let cmd = (aiData.cmd || "").trim();
86
- const safeWords = ['ls', 'df', 'free', 'uptime', 'top', 'ps', 'cat', 'grep', 'iostat', 'netstat', 'ss', 'ip', 'systemctl', 'journalctl'];
87
15
 
88
- if (cmd && cmd !== "none" && safeWords.some(w => cmd.includes(w))) {
89
- if (cmd.startsWith("top") && !cmd.includes("-b")) cmd = "top -b -n 1 | head -n 12";
90
- exec(cmd, { timeout: 10000 }, (err, stdout, stderr) => {
91
- let res = (stdout || stderr || "OK").substring(0, 800);
92
- node.send({ payload: { chatId, type: "message", content: `📟 <b>Terminal (${cmd})</b> :\n<pre>${res}</pre>`, options: { parse_mode: "HTML" } } });
93
- setTimeout(() => {
94
- node.emit("input", { payload: { chatId, content: `RÉSULTAT ${cmd} :\n${res}` }, loopCount: loopCount + 1 });
95
- }, 1200);
96
- });
16
+ // Logique simplifiée pour test
17
+ node.status({fill:"yellow", text: "Appel AI..."});
18
+ try {
19
+ // Votre logique axios ici...
20
+ node.status({fill:"green", text:"OK"});
21
+ } catch (err) {
22
+ node.status({fill:"red", text:"Erreur"});
97
23
  }
98
-
99
- history.push({ role: "assistant", content: aiData.speech || "Action" });
100
- node.context().set('history', history.slice(-10));
101
- node.status({fill:"green", text:`Réponse via ${engineUsed}`});
102
24
  });
103
25
  }
104
26
  RED.nodes.registerType('linux-copilot', LinuxCopilotNode, {
package/package.json CHANGED
@@ -1,20 +1,8 @@
1
1
  {
2
2
  "name": "node-red-contrib-linux-copilot",
3
- "version": "1.0.3",
4
- "description": "Agent SRE intelligent (DeepSeek/Gemini) avec exécution terminal sécurisée",
3
+ "version": "1.2.8",
4
+ "description": "AI Linux Copilot",
5
5
  "main": "linux-copilot.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "keywords": [
10
- "node-red",
11
- "linux",
12
- "sre",
13
- "copilot",
14
- "deepseek",
15
- "gemini",
16
- "bash"
17
- ],
18
6
  "node-red": {
19
7
  "nodes": {
20
8
  "linux-copilot": "linux-copilot.js"