pinokiod 3.9.0 → 3.9.3

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 (119) hide show
  1. package/:w +1247 -0
  2. package/kernel/api/filepicker/index.js +59 -0
  3. package/kernel/api/fs/index.js +6 -4
  4. package/kernel/api/index.js +123 -37
  5. package/kernel/api/input/index.js +2 -0
  6. package/kernel/api/web/index.js +6 -0
  7. package/kernel/bin/caddy.js +127 -0
  8. package/kernel/bin/cloudflared.js +1 -0
  9. package/kernel/bin/conda.js +10 -2
  10. package/kernel/bin/cuda.js +0 -16
  11. package/kernel/bin/ffmpeg.js +4 -6
  12. package/kernel/bin/git.js +55 -29
  13. package/kernel/bin/gxx.js +8 -6
  14. package/kernel/bin/huggingface.js +4 -5
  15. package/kernel/bin/index.js +347 -88
  16. package/kernel/bin/node.js +13 -6
  17. package/kernel/bin/py.js +1 -1
  18. package/kernel/bin/setup.js +146 -0
  19. package/kernel/bin/uv.js +4 -5
  20. package/kernel/bin/zip.js +7 -8
  21. package/kernel/connect/index.js +25 -0
  22. package/kernel/connect/providers/github/README.md +11 -0
  23. package/kernel/connect/providers/x/README.md +96 -0
  24. package/kernel/connect/providers/x/index.js +152 -0
  25. package/kernel/environment.js +50 -1
  26. package/kernel/index.js +152 -32
  27. package/kernel/info.js +4 -2
  28. package/kernel/kv.js +38 -0
  29. package/kernel/loader.js +13 -3
  30. package/kernel/peer.js +161 -0
  31. package/kernel/procs.js +116 -0
  32. package/kernel/prototype.js +62 -0
  33. package/kernel/router/common.js +42 -0
  34. package/kernel/router/connector.js +81 -0
  35. package/kernel/router/index.js +235 -0
  36. package/kernel/router/localhost_home_router.js +84 -0
  37. package/kernel/router/localhost_port_router.js +15 -0
  38. package/kernel/router/localhost_variable_router.js +37 -0
  39. package/kernel/router/peer_home_router.js +15 -0
  40. package/kernel/router/peer_peer_router.js +26 -0
  41. package/kernel/router/peer_port_router.js +45 -0
  42. package/kernel/router/peer_variable_router.js +46 -0
  43. package/kernel/router/processor.js +31 -0
  44. package/kernel/shell.js +141 -60
  45. package/kernel/shells.js +32 -17
  46. package/kernel/store.js +58 -0
  47. package/kernel/sysinfo.js +0 -1
  48. package/kernel/util.js +143 -36
  49. package/package.json +4 -1
  50. package/pipe/index.js +0 -2
  51. package/script/index.js +12 -0
  52. package/server/index.js +1473 -553
  53. package/server/public/Socket.js +5 -1
  54. package/server/public/SourceCodePro-Regular.ttf +0 -0
  55. package/server/public/SpaceMono-Bold.ttf +0 -0
  56. package/server/public/SpaceMono-BoldItalic.ttf +0 -0
  57. package/server/public/SpaceMono-Italic.ttf +0 -0
  58. package/server/public/SpaceMono-Regular.ttf +0 -0
  59. package/server/public/commander.js +40 -0
  60. package/server/public/common.js +60 -0
  61. package/server/public/dropzone-min.js +2 -0
  62. package/server/public/dropzone.css +1 -0
  63. package/server/public/filepond-plugin-file-validate-type.min.js +9 -0
  64. package/server/public/filepond-plugin-image-crop.min.js +9 -0
  65. package/server/public/filepond-plugin-image-edit.min.css +8 -0
  66. package/server/public/filepond-plugin-image-edit.min.js +9 -0
  67. package/server/public/filepond-plugin-image-exif-orientation.min.js +9 -0
  68. package/server/public/filepond-plugin-image-preview.min.css +8 -0
  69. package/server/public/filepond-plugin-image-preview.min.js +9 -0
  70. package/server/public/filepond-plugin-image-resize.min.js +9 -0
  71. package/server/public/filepond-plugin-image-transform.min.js +9 -0
  72. package/server/public/filepond.min.css +8 -0
  73. package/server/public/filepond.min.js +9 -0
  74. package/server/public/fscreator.js +174 -0
  75. package/server/public/fseditor.js +212 -0
  76. package/server/public/github.png +0 -0
  77. package/server/public/highlight-js.js +81 -0
  78. package/server/public/highlight.css +9 -0
  79. package/server/public/highlight.js +1244 -0
  80. package/server/public/install.js +17 -20
  81. package/server/public/modalinput.js +105 -9
  82. package/server/public/opener.js +3 -1
  83. package/server/public/pinokio-black.png +0 -0
  84. package/server/public/pinokio-black2.png +0 -0
  85. package/server/public/redoc.standalone.js +1832 -0
  86. package/server/public/style.css +215 -17
  87. package/server/public/swagger-ui-bundle.js +2 -0
  88. package/server/public/swagger-ui.css +3 -0
  89. package/server/public/x.js +63 -0
  90. package/server/socket.js +136 -39
  91. package/server/views/404.ejs +0 -1
  92. package/server/views/app.ejs +368 -98
  93. package/server/views/bootstrap.ejs +22 -19
  94. package/server/views/connect/x.ejs +324 -0
  95. package/server/views/connect.ejs +197 -0
  96. package/server/views/download.ejs +7 -1
  97. package/server/views/editor.ejs +68 -9
  98. package/server/views/explore.ejs +13 -10
  99. package/server/views/file_explorer.ejs +10 -37
  100. package/server/views/github.ejs +218 -0
  101. package/server/views/help.ejs +4 -3
  102. package/server/views/index.ejs +275 -121
  103. package/server/views/install.ejs +56 -29
  104. package/server/views/keys.ejs +276 -0
  105. package/server/views/network.ejs +889 -0
  106. package/server/views/partials/dynamic.ejs +9 -0
  107. package/server/views/partials/menu.ejs +7 -1
  108. package/server/views/prototype/index.ejs +311 -0
  109. package/server/views/prototype/show.ejs +383 -0
  110. package/server/views/redoc.ejs +18 -0
  111. package/server/views/required_env_editor.ejs +11 -2
  112. package/server/views/settings.ejs +38 -10
  113. package/server/views/setup.ejs +254 -0
  114. package/server/views/setup_home.ejs +192 -0
  115. package/server/views/shell.ejs +781 -0
  116. package/server/views/swaggerui.ejs +19 -0
  117. package/server/views/terminal.ejs +174 -42
  118. package/LICENSE +0 -7
  119. package/server/views/proxy.ejs +0 -405
package/kernel/util.js CHANGED
@@ -14,6 +14,9 @@ const groupReplacement = "$$$";
14
14
  const h = "[^\\S\\r\\n]"; // simulate `\h`
15
15
  const returnPattern = /\r/g;
16
16
  const returnReplacement = "\\r";
17
+ const {
18
+ glob
19
+ } = require('glob')
17
20
 
18
21
 
19
22
  // asar handling for go-get-folder-size
@@ -36,26 +39,20 @@ const du = async (folderpath) => {
36
39
  const is_port_available = async (port) => {
37
40
  return new Promise((resolve) => {
38
41
  const server = http.createServer();
39
- console.log("> Checking port availability", port)
40
42
  try {
41
43
  server.listen(port, (err) => {
42
44
  if (err) {
43
- console.log("> [1 port not available]", err)
44
45
  resolve(false); // Port is occupied
45
46
  } else {
46
- console.log("> [2 port available] test server started. closing test server now.")
47
47
  server.close(() => {
48
- console.log("> Test server closed.")
49
48
  resolve(true); // Port is free
50
49
  }); // Close the server immediately after testing
51
50
  }
52
51
  });
53
52
  server.on('error', (err) => {
54
- console.log("> [3 port not available]", err);
55
53
  resolve(false); // Port is occupied
56
54
  });
57
55
  } catch (e) {
58
- console.log("> [4 port not available]", err)
59
56
  resolve(false) // port not available
60
57
  }
61
58
  });
@@ -94,39 +91,89 @@ const parse_env = async (filename) => {
94
91
  return {}
95
92
  }
96
93
  }
97
- const openfs = (dirPath, options) => {
94
+ const openfs = (dirPath, options, kernel) => {
98
95
  let command = '';
99
96
  const platform = os.platform()
100
- let mode = "view"
101
- if (options && options.mode) {
102
- mode = options.mode
103
- }
104
- if (mode === "view") {
105
- switch (platform) {
106
- case 'darwin':
107
- command = `open -R "${dirPath}"`;
108
- break;
109
- case 'win32':
110
- command = `explorer /select,"${dirPath}" & timeout /t 1 >nul`;
111
- break;
112
- default:
113
- command = `xdg-open "${dirPath}"`;
114
- break;
97
+ console.log("openfs", dirPath, options)
98
+ if (options && options.command) {
99
+ let mode = "view"
100
+ if (options && options.command) {
101
+ mode = options.command
102
+ }
103
+ console.log("> mode", mode)
104
+ if (mode === "view") {
105
+ switch (platform) {
106
+ case 'darwin':
107
+ command = `open -R "${dirPath}"`;
108
+ break;
109
+ case 'win32':
110
+ command = `explorer /select,"${dirPath}" & timeout /t 1 >nul`;
111
+ break;
112
+ default:
113
+ command = `xdg-open "${dirPath}"`;
114
+ break;
115
+ }
116
+ child_process.exec(command)
117
+ } else if (mode === "open") {
118
+ switch (platform) {
119
+ case 'darwin':
120
+ command = `open "${dirPath}"`;
121
+ break;
122
+ case 'win32':
123
+ command = `explorer "${dirPath}"`;
124
+ break;
125
+ default:
126
+ command = `xdg-open "${dirPath}"`;
127
+ break;
128
+ }
129
+ child_process.exec(command)
130
+ } else {
131
+ command = `${mode} "${dirPath}"`
132
+ console.log("> command", command)
133
+ if (kernel) {
134
+ kernel.exec({
135
+ message: command,
136
+ }, (e) => {
137
+ process.stdout.write(e.raw)
138
+ }).then(() => {
139
+ console.log("DONE")
140
+ })
141
+ } else {
142
+ child_process.exec(command)
143
+ }
115
144
  }
116
- } else if (mode === "open") {
117
- switch (platform) {
118
- case 'darwin':
119
- command = `open "${dirPath}"`;
120
- break;
121
- case 'win32':
122
- command = `explorer "${dirPath}"`;
123
- break;
124
- default:
125
- command = `xdg-open "${dirPath}"`;
126
- break;
145
+ } else {
146
+ let mode = "view"
147
+ if (options && options.mode) {
148
+ mode = options.mode
127
149
  }
150
+ if (mode === "view") {
151
+ switch (platform) {
152
+ case 'darwin':
153
+ command = `open -R "${dirPath}"`;
154
+ break;
155
+ case 'win32':
156
+ command = `explorer /select,"${dirPath}" & timeout /t 1 >nul`;
157
+ break;
158
+ default:
159
+ command = `xdg-open "${dirPath}"`;
160
+ break;
161
+ }
162
+ } else if (mode === "open") {
163
+ switch (platform) {
164
+ case 'darwin':
165
+ command = `open "${dirPath}"`;
166
+ break;
167
+ case 'win32':
168
+ command = `explorer "${dirPath}"`;
169
+ break;
170
+ default:
171
+ command = `xdg-open "${dirPath}"`;
172
+ break;
173
+ }
174
+ }
175
+ child_process.exec(command)
128
176
  }
129
- child_process.exec(command)
130
177
  }
131
178
  const parse_env_detail = async (filename) => {
132
179
  // takes env and returns an array
@@ -199,8 +246,31 @@ const escapeStringRegexp = (string) => {
199
246
  .replace(/-/g, '\\x2d');
200
247
  }
201
248
 
249
+ const find_python = async (root) => {
250
+ let python_pattern
251
+ if (os.platform() === "win32") {
252
+ python_pattern = "**/python.exe";
253
+ } else {
254
+ python_pattern = "**/python"; // Matches python, python3, python3.x
255
+ }
256
+ const pythonBinaries = await glob(python_pattern, { nodir: true, cwd: root });
257
+ return pythonBinaries
258
+ }
259
+ const find_venv = async (root) => {
260
+ let python_pattern
261
+ if (os.platform() === "win32") {
262
+ python_pattern = "**/python.exe";
263
+ } else {
264
+ python_pattern = "**/python"; // Matches python, python3, python3.x
265
+ }
266
+ const pythonBinaries = await glob(python_pattern, { nodir: true, cwd: root, absolute: true });
267
+ const venvs = pythonBinaries.map((p) => {
268
+ return path.resolve(p, "../..")
269
+ })
270
+ return venvs
271
+ }
272
+
202
273
  const update_env = async (filepath, changes) => {
203
- console.log("UPDATE_ENV", { filepath, changes })
204
274
  const env = await fs.promises.readFile(filepath, "utf8")
205
275
  let append = false;
206
276
  const newval = Object.keys(changes).reduce((result, varname) => {
@@ -236,6 +306,43 @@ const update_env = async (filepath, changes) => {
236
306
  }, normalizeEOL(env));
237
307
  await fs.promises.writeFile(filepath, newval)
238
308
  };
309
+ function fill_object(obj, pattern, list, cache) {
310
+ const map = {};
311
+ const replaced_map = cache || {}
312
+ let index = 0;
313
+
314
+ function recurse(value) {
315
+ if (typeof value === 'string') {
316
+ return value.replace(pattern, (match) => {
317
+ if (!(match in map)) {
318
+ if (replaced_map[match]) {
319
+ map[match] = replaced_map[match]
320
+ // console.log("filling with cache", { match, replaced: replaced_map[match] })
321
+ } else {
322
+ if (index >= list.length) throw new Error("Not enough items provided");
323
+ map[match] = list[index++];
324
+ replaced_map[match] = map[match]
325
+ // console.log("filling with new", { match, replaced: replaced_map[match] })
326
+ }
327
+ }
328
+ return map[match];
329
+ });
330
+ } else if (Array.isArray(value)) {
331
+ return value.map(recurse);
332
+ } else if (value && typeof value === 'object') {
333
+ const newObj = {};
334
+ for (const [k, v] of Object.entries(value)) {
335
+ newObj[k] = recurse(v);
336
+ }
337
+ return newObj;
338
+ }
339
+ return value;
340
+ }
341
+
342
+ let res = recurse(obj);
343
+ return { result: res, replaced_map }
344
+ }
345
+
239
346
  module.exports = {
240
- parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_available
347
+ parse_env, log_path, api_path, update_env, parse_env_detail, openfs, port_running, du, is_port_available, find_python, find_venv, fill_object
241
348
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.9.0",
3
+ "version": "3.9.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,6 +28,7 @@
28
28
  "express-session": "^1.17.3",
29
29
  "fake-useragent": "^1.0.1",
30
30
  "fastq": "^1.15.0",
31
+ "form-data": "^4.0.2",
31
32
  "fs-extra": "^11.1.1",
32
33
  "glob": "^10.3.3",
33
34
  "glob-gitignore": "^1.0.14",
@@ -40,6 +41,7 @@
40
41
  "jimini": "^0.0.7",
41
42
  "jsdom": "^24.0.0",
42
43
  "key-store": "^1.2.0",
44
+ "kill-sync": "^1.0.3",
43
45
  "kleur": "^4.1.5",
44
46
  "lodash": "^4.17.21",
45
47
  "marked": "^5.0.1",
@@ -59,6 +61,7 @@
59
61
  "sudo-prompt-programfiles-x86": "^9.2.10",
60
62
  "symlink-dir": "^5.2.1",
61
63
  "systeminformation": "^5.18.4",
64
+ "twitter-api-v2": "^1.23.2",
62
65
  "uuid": "^9.0.0",
63
66
  "wait-on": "^7.2.0",
64
67
  "which": "^5.0.0",
package/pipe/index.js CHANGED
@@ -22,7 +22,6 @@ class Pipe {
22
22
  }
23
23
  // a pipe server for creating publicly shareable endpoints
24
24
  async start(url, scriptPath, passcode, config) {
25
- console.log("pipe.start", { url, scriptPath, passcode, config })
26
25
 
27
26
  let port = await this.kernel.port()
28
27
  let app = express();
@@ -100,7 +99,6 @@ class Pipe {
100
99
 
101
100
 
102
101
  await new Promise((resolve, reject) => {
103
- console.log("starting pipe server at port", port)
104
102
  let server = app.listen(port, () => {
105
103
  console.log(`Pipe server listening on port ${port}`)
106
104
  resolve()
package/script/index.js CHANGED
@@ -4,6 +4,16 @@ const os = require('os')
4
4
  const platform = os.platform()
5
5
  const Server = require('../server')
6
6
  class Store {
7
+ constructor() {
8
+ let o
9
+ try {
10
+ let str = fs.readFileSync(path.resolve(__dirname, "pinokio.json"), "utf8")
11
+ o = JSON.parse(str)
12
+ } catch(e) {
13
+ o = {}
14
+ }
15
+ this.store = o
16
+ }
7
17
  set(key, val) {
8
18
  let o
9
19
  try {
@@ -13,6 +23,7 @@ class Store {
13
23
  o = {}
14
24
  }
15
25
  o[key] = val
26
+ this.store = o
16
27
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
17
28
  }
18
29
  get(key) {
@@ -31,6 +42,7 @@ class Store {
31
42
  console.log("before delete", o)
32
43
  delete o[key]
33
44
  console.log("after delete", o)
45
+ this.store = o
34
46
  fs.writeFileSync(path.resolve(__dirname, "pinokio.json"), JSON.stringify(o, null, 2))
35
47
  } catch (e) {
36
48
  }