samarthya-bot 2.2.0 → 2.3.0

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 (38) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +340 -353
  3. package/backend/bin/samarthya.js +29 -10
  4. package/backend/config/constants.js +4 -4
  5. package/backend/controllers/chatController.js +72 -0
  6. package/backend/controllers/telegramController.js +8 -0
  7. package/backend/package-lock.json +2 -2
  8. package/backend/package.json +2 -2
  9. package/backend/public/assets/index-DiMx9ERJ.css +1 -0
  10. package/backend/public/assets/index-Dn5WYZTH.js +32 -0
  11. package/backend/public/index.html +186 -16
  12. package/backend/public/robots.txt +32 -0
  13. package/backend/public/sitemap.xml +39 -0
  14. package/backend/services/agent/commandService.js +168 -0
  15. package/backend/services/llm/llmService.js +8 -0
  16. package/backend/services/planner/plannerService.js +17 -0
  17. package/backend/services/security/sandboxService.js +11 -4
  18. package/backend/services/system/platform.js +150 -0
  19. package/backend/services/tools/toolRegistry.js +523 -37
  20. package/backend/services/worker/workerClient.js +141 -29
  21. package/package.json +2 -2
  22. package/backend/public/assets/index-6PCzI3K2.js +0 -40
  23. package/backend/public/assets/index-6TF5jVRQ.js +0 -149
  24. package/backend/public/assets/index-B0U7rt6f.js +0 -46
  25. package/backend/public/assets/index-BF0RZh9i.js +0 -149
  26. package/backend/public/assets/index-BFRAq8Y1.js +0 -149
  27. package/backend/public/assets/index-CGw8cc8z.js +0 -149
  28. package/backend/public/assets/index-Ckf0GO1B.css +0 -1
  29. package/backend/public/assets/index-Cx0Ei-z7.js +0 -149
  30. package/backend/public/assets/index-DIPdcLv-.js +0 -25
  31. package/backend/public/assets/index-Da1E-MYB.js +0 -53
  32. package/backend/public/assets/index-DdCKkq38.js +0 -149
  33. package/backend/public/assets/index-Do4jNsZS.js +0 -19
  34. package/backend/public/assets/index-DyjpBYmS.js +0 -51
  35. package/backend/public/assets/index-DzlXcaXT.js +0 -149
  36. package/backend/public/assets/index-J7XSVHCz.css +0 -1
  37. package/backend/public/assets/index-Ui-pyZvK.js +0 -25
  38. package/backend/public/assets/index-kzffNwzo.js +0 -149
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Cross-Platform System Helper for SamarthyaBot
3
+ * ------------------------------------------------------------------
4
+ * Single source of truth for OS-specific behaviour so that every tool
5
+ * (shell exec, file open, browser launch, port kill) works identically
6
+ * on Windows, macOS and Linux.
7
+ *
8
+ * The OS is detected ONCE at load time and cached, so the rest of the
9
+ * codebase never has to re-check `process.platform`.
10
+ */
11
+
12
+ const os = require('os');
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ const PLATFORM = process.platform; // 'win32' | 'darwin' | 'linux' | ...
17
+
18
+ const isWindows = PLATFORM === 'win32';
19
+ const isMac = PLATFORM === 'darwin';
20
+ const isLinux = !isWindows && !isMac;
21
+
22
+ const OS = isWindows ? 'windows' : isMac ? 'mac' : 'linux';
23
+
24
+ /**
25
+ * Returns the shell + flag used to run a raw command string.
26
+ * Mirrors what Node's `exec()` does internally, but lets us pass it to
27
+ * `spawn()` for live streaming.
28
+ */
29
+ function getShell() {
30
+ if (isWindows) {
31
+ return { shell: process.env.ComSpec || 'cmd.exe', flag: '/d /s /c', shellSpawn: true };
32
+ }
33
+ return { shell: process.env.SHELL || '/bin/sh', flag: '-c', shellSpawn: false };
34
+ }
35
+
36
+ /**
37
+ * The native command used to open a URL, file or folder with the
38
+ * system default handler.
39
+ * Windows -> start "" macOS -> open Linux -> xdg-open
40
+ */
41
+ function openCommand() {
42
+ if (isWindows) return 'start ""';
43
+ if (isMac) return 'open';
44
+ return 'xdg-open';
45
+ }
46
+
47
+ /**
48
+ * Build a fully-quoted "open this target" command for the current OS.
49
+ */
50
+ function buildOpenCommand(target) {
51
+ const safe = String(target).replace(/"/g, '');
52
+ if (isWindows) return `start "" "${safe}"`;
53
+ if (isMac) return `open "${safe}"`;
54
+ return `xdg-open "${safe}"`;
55
+ }
56
+
57
+ /**
58
+ * Discover an installed Chromium-based browser executable for Puppeteer.
59
+ * Checks the common install locations for each OS plus a few env hints.
60
+ * Returns an absolute path or `null` if nothing is found.
61
+ */
62
+ function findBrowser() {
63
+ const candidates = [];
64
+
65
+ // Explicit override always wins
66
+ if (process.env.CHROME_PATH) candidates.push(process.env.CHROME_PATH);
67
+ if (process.env.PUPPETEER_EXECUTABLE_PATH) candidates.push(process.env.PUPPETEER_EXECUTABLE_PATH);
68
+
69
+ if (isWindows) {
70
+ const prog = process.env['ProgramFiles'] || 'C:\\Program Files';
71
+ const progx86 = process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)';
72
+ const local = process.env['LOCALAPPDATA'] || path.join(os.homedir(), 'AppData', 'Local');
73
+ candidates.push(
74
+ path.join(prog, 'Google\\Chrome\\Application\\chrome.exe'),
75
+ path.join(progx86, 'Google\\Chrome\\Application\\chrome.exe'),
76
+ path.join(local, 'Google\\Chrome\\Application\\chrome.exe'),
77
+ path.join(prog, 'Microsoft\\Edge\\Application\\msedge.exe'),
78
+ path.join(progx86, 'Microsoft\\Edge\\Application\\msedge.exe'),
79
+ path.join(prog, 'BraveSoftware\\Brave-Browser\\Application\\brave.exe'),
80
+ path.join(progx86, 'BraveSoftware\\Brave-Browser\\Application\\brave.exe')
81
+ );
82
+ } else if (isMac) {
83
+ candidates.push(
84
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
85
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
86
+ '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
87
+ '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
88
+ );
89
+ } else {
90
+ candidates.push(
91
+ '/usr/bin/google-chrome',
92
+ '/usr/bin/google-chrome-stable',
93
+ '/usr/bin/chromium',
94
+ '/usr/bin/chromium-browser',
95
+ '/usr/bin/microsoft-edge',
96
+ '/usr/bin/brave-browser',
97
+ '/snap/bin/chromium'
98
+ );
99
+ }
100
+
101
+ for (const candidate of candidates) {
102
+ try {
103
+ if (candidate && fs.existsSync(candidate)) return candidate;
104
+ } catch (_) { /* ignore */ }
105
+ }
106
+ return null;
107
+ }
108
+
109
+ /**
110
+ * Command to find + kill whatever process is listening on a TCP port.
111
+ * Returned string is safe to run through the platform shell.
112
+ */
113
+ function killPortCommand(port) {
114
+ if (isWindows) {
115
+ // Find PID via netstat, kill via taskkill
116
+ return `for /f "tokens=5" %a in ('netstat -ano ^| findstr :${port} ^| findstr LISTENING') do taskkill /PID %a /F`;
117
+ }
118
+ // lsof first, fuser as fallback
119
+ return `lsof -t -i:${port} | xargs kill -9 2>/dev/null || fuser -k ${port}/tcp 2>/dev/null || true`;
120
+ }
121
+
122
+ /**
123
+ * Command to test whether a port is currently being listened on.
124
+ */
125
+ function checkPortListeningCommand(port) {
126
+ if (isWindows) return `netstat -ano | findstr :${port} | findstr LISTENING`;
127
+ return `lsof -i:${port} -t 2>/dev/null`;
128
+ }
129
+
130
+ /**
131
+ * Human-readable one-liner describing the host, handy for LLM prompts.
132
+ */
133
+ function describe() {
134
+ return `${os.type()} ${os.release()} (${OS}/${os.arch()})`;
135
+ }
136
+
137
+ module.exports = {
138
+ PLATFORM,
139
+ OS,
140
+ isWindows,
141
+ isMac,
142
+ isLinux,
143
+ getShell,
144
+ openCommand,
145
+ buildOpenCommand,
146
+ findBrowser,
147
+ killPortCommand,
148
+ checkPortListeningCommand,
149
+ describe,
150
+ };