pinokiod 3.8.11 → 3.8.13

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.
@@ -282,6 +282,8 @@ class Bin {
282
282
  } catch (e) {
283
283
  console.log("RefreshInstalled Error", e)
284
284
  }
285
+
286
+ // initialize pipconfig
285
287
  let pipconfig_path = path.resolve(this.kernel.homedir, "pipconfig")
286
288
  let pipconfig_exists = await this.kernel.api.exists(pipconfig_path)
287
289
  // if not, create one
@@ -289,10 +291,6 @@ class Bin {
289
291
  const pipconfigStr = `[global]
290
292
  timeout = 1000`
291
293
  await fs.promises.writeFile(pipconfig_path, pipconfigStr)
292
- // await fs.promises.copyFile(
293
- // path.resolve(__dirname, "..", "pipconfig_template"),
294
- // pipconfig_path
295
- // )
296
294
  }
297
295
 
298
296
  // add gitconfig => support git lfs, long path, etc.
@@ -302,6 +300,13 @@ class Bin {
302
300
  path.resolve(__dirname, "..", "gitconfig_template"),
303
301
  gitconfig_path
304
302
  )
303
+
304
+ for(let mod of this.mods) {
305
+ if (mod.mod.start) {
306
+ await mod.mod.start()
307
+ }
308
+ }
309
+
305
310
  }
306
311
 
307
312
 
@@ -585,7 +590,7 @@ class Bin {
585
590
  // await this.mod(name).rm({}, ondata)
586
591
  // await this.mod(name).install(options, ondata)
587
592
  //}
588
- async tryInstall(requirement, x, i, total, ondata) {
593
+ async tryInstall(id, requirement, x, i, total, ondata) {
589
594
  let current_platform = os.platform()
590
595
  let current_arch = os.arch()
591
596
  let current_gpu = this.kernel.gpu
@@ -645,7 +650,7 @@ class Bin {
645
650
  ondata({ html: `<b><i class="fas fa-circle-notch fa-spin"></i> ${progress} Installing ${name}</b>${message}` }, "notify2")
646
651
  console.log("## Before m.mod.install", requirement)
647
652
  requirement._attempt = x
648
- await m.mod.install(requirement, ondata, this.kernel)
653
+ await m.mod.install(requirement, ondata, this.kernel, id)
649
654
 
650
655
  // // 2 second delay to fix conda issue
651
656
  // await new Promise((resolve, reject) => {
@@ -703,6 +708,8 @@ class Bin {
703
708
 
704
709
  let requirements = JSON.parse(req.params)
705
710
 
711
+ console.time("### Total Install")
712
+
706
713
  for(let x=0; x<10; x++) {
707
714
  console.log(`## Install Attempt ${x}`)
708
715
  let i = 0;
@@ -716,7 +723,9 @@ class Bin {
716
723
  console.log("already installed. skip.")
717
724
  } else {
718
725
  console.log("not installed. install.")
719
- await this.tryInstall(requirement, x, i, requirements.length, ondata)
726
+ console.time("############# Install " +requirement.name)
727
+ await this.tryInstall(req.id, requirement, x, i, requirements.length, ondata)
728
+ console.timeEnd("############# Install " +requirement.name)
720
729
  }
721
730
  }
722
731
 
@@ -772,6 +781,7 @@ class Bin {
772
781
  // }
773
782
  // }
774
783
  //}
784
+ console.timeEnd("### Total Install")
775
785
  await this.init()
776
786
  }
777
787
  async installed(r) {
@@ -810,7 +820,8 @@ class Bin {
810
820
  { name: "git", },
811
821
  { name: "zip", },
812
822
  { name: "node", },
813
- { name: "ffmpeg", }
823
+ { name: "ffmpeg", },
824
+ { name: "caddy", }
814
825
  ]
815
826
  let platform = os.platform()
816
827
  if (platform === "win32") {
@@ -827,11 +838,11 @@ class Bin {
827
838
  requirements.push({ name: "cuda", })
828
839
  }
829
840
  requirements = requirements.concat([
830
- { name: "py" },
831
841
  { name: "cloudflared" },
832
- { name: "playwright" },
842
+ // { name: "playwright" },
833
843
  { name: "huggingface" },
834
- { name: "uv" }
844
+ { name: "uv" },
845
+ { name: "py" },
835
846
  ])
836
847
 
837
848
  let requirements_pending = !this.installed_initialized
@@ -3,18 +3,16 @@ const fetch = require('cross-fetch')
3
3
  const { rimraf } = require('rimraf')
4
4
  const decompress = require('decompress');
5
5
  class Node {
6
+ cmd() {
7
+ return "nodejs pnpm"
8
+ }
6
9
  async install(req, ondata) {
7
10
  await this.kernel.bin.exec({
8
- //message: "conda install -y nodejs=22.12.0 -c conda-forge"
9
11
  message: [
10
12
  "conda clean -y --all",
11
13
  //"conda install -y nodejs=20.17.0 pnpm -c conda-forge"
12
- "conda install -y nodejs pnpm -c conda-forge"
14
+ `conda install -y -c conda-forge ${this.cmd()}`
13
15
  ]
14
- // conda: {
15
- // name: "base",
16
- // activate: "minimal"
17
- // }
18
16
  }, ondata)
19
17
  }
20
18
  async installed() {
package/kernel/bin/py.js CHANGED
@@ -8,7 +8,7 @@ class Py {
8
8
  path: this.kernel.path("bin")
9
9
  }, ondata)
10
10
  await this.kernel.exec({
11
- message: "pip install -r requirements.txt",
11
+ message: "uv pip install -r requirements.txt",
12
12
  venv: "env",
13
13
  path: this.kernel.bin.path("py")
14
14
  }, ondata)
package/kernel/bin/uv.js CHANGED
@@ -3,16 +3,15 @@ const fetch = require('cross-fetch')
3
3
  const { rimraf } = require('rimraf')
4
4
  const decompress = require('decompress');
5
5
  class UV {
6
+ cmd() {
7
+ return "uv"
8
+ }
6
9
  async install(req, ondata) {
7
10
  await this.kernel.bin.exec({
8
11
  message: [
9
12
  "conda clean -y --all",
10
- "conda install -y -c conda-forge uv",
13
+ `conda install -y -c conda-forge ${this.cmd()}`
11
14
  ]
12
- // conda: {
13
- // name: "base",
14
- // activate: "minimal"
15
- // }
16
15
  }, ondata)
17
16
  }
18
17
  async installed() {
package/kernel/bin/zip.js CHANGED
@@ -1,20 +1,19 @@
1
1
  class Zip {
2
- async install(req, ondata) {
2
+ cmd() {
3
3
  let cmd
4
4
  if (this.kernel.platform === 'win32') {
5
- cmd = "conda install -y -c conda-forge 7zip"
5
+ cmd = "7zip"
6
6
  } else {
7
- cmd = "conda install -y -c conda-forge p7zip"
7
+ cmd = "p7zip"
8
8
  }
9
+ return cmd
10
+ }
11
+ async install(req, ondata) {
9
12
  await this.kernel.bin.exec({
10
13
  message: [
11
14
  "conda clean -y --all",
12
- cmd
15
+ `conda install -y -c conda-forge ${this.cmd()}`
13
16
  ]
14
- // conda: {
15
- // name: "base",
16
- // activate: "minimal"
17
- // }
18
17
  }, ondata)
19
18
  }
20
19
  async installed() {
package/kernel/index.js CHANGED
@@ -20,6 +20,7 @@ const Template = require('jimini')
20
20
  const which = require('which')
21
21
  const Shells = require("./shells")
22
22
  const Key = require("./key")
23
+ const KV = require('./kv')
23
24
  const Script = require('./script')
24
25
  const Environment = require("./environment")
25
26
  const Util = require('./util')
@@ -42,7 +43,8 @@ class Kernel {
42
43
  //schema = ">=1.0.0"
43
44
  //schema = "<=2.1.0"
44
45
  //schema = "<=3.2.0"
45
- schema = "<=3.7.0"
46
+ //schema = "<=3.7.0"
47
+ schema = "<=4.0.0"
46
48
  constructor(store) {
47
49
  this.fetch = fetch
48
50
 
@@ -78,6 +80,7 @@ class Kernel {
78
80
  this.info = new Info(this)
79
81
  this.pipe = new Pipe(this)
80
82
  this.proto = new Proto(this)
83
+ this.kv = new KV(this)
81
84
  this.cloudflare = new Cloudflare()
82
85
  this.shellpath = shellPath.sync()
83
86
  }
@@ -107,6 +110,21 @@ class Kernel {
107
110
  }
108
111
  }
109
112
  }
113
+ // path_exists(...args) {
114
+ // return this.info.exists(...args)
115
+ // }
116
+ // path_resolve(...args) {
117
+ // return this.info.path(...args)
118
+ // }
119
+ // script_running(...args) {
120
+ // return this.info.running(...args)
121
+ // }
122
+ // script_local(...args) {
123
+ // return this.info.local(...args)
124
+ // }
125
+ // script_global(...args) {
126
+ // return this.info.global(...args)
127
+ // }
110
128
  async env(...args) {
111
129
  let folderpath
112
130
  if (args) {
@@ -540,6 +558,7 @@ class Kernel {
540
558
  console.log("bin init finished")
541
559
  if (this.homedir) {
542
560
  this.shell.init().then(async () => {
561
+ console.log("shell init finished")
543
562
  this.bin.check_bin()
544
563
  if (this.envs) {
545
564
  this.template.update({
@@ -564,10 +583,12 @@ class Kernel {
564
583
  }
565
584
  }
566
585
  })
586
+ console.log("*******************")
567
587
 
568
588
  // get env
569
589
  if (!this.launch_complete) {
570
590
  let interval = setInterval(async () => {
591
+ console.log("this.i", this.i)
571
592
  if (this.i) {
572
593
  for(let api of this.i.api) {
573
594
  console.log({ api })
package/kernel/info.js CHANGED
@@ -40,13 +40,17 @@ class Info {
40
40
  running(...args) {
41
41
  let cwd = path.dirname(this.caller())
42
42
  let resolved_path = path.resolve(cwd, ...args)
43
- return this.kernel.api.running[resolved_path]
43
+ console.log("api.running", this.kernel.api.running)
44
+ let running = this.kernel.api.running[resolved_path]
45
+ console.log("info.running", { cwd, resolved_path, running })
46
+ return running ? running : false
44
47
  }
45
48
  exists(...args) {
46
49
  let cwd = path.dirname(this.caller())
47
50
  let resolved_path = path.resolve(cwd, ...args)
48
- console.log({ cwd, resolved_path })
49
- return fs.existsSync(resolved_path)
51
+ let exists = fs.existsSync(resolved_path)
52
+ console.log("info.exists", { cwd, resolved_path, exists })
53
+ return exists ? exists: false
50
54
  }
51
55
  local(...args) {
52
56
  let cwd = path.dirname(this.caller())
package/kernel/kv.js ADDED
@@ -0,0 +1,35 @@
1
+ class KV {
2
+ constructor(kernel) {
3
+ this.kernel = kernel
4
+ }
5
+ async set(host, val, index) {
6
+ if (this.kernel.homedir) {
7
+ let filePath = this.kernel.path("key.json")
8
+ let json = await this.kernel.load(filePath)
9
+ if (!json) json = {}
10
+ // if the array at host path doesn't exist, create an empty array
11
+ if (!json[host]) {
12
+ json[host] = []
13
+ }
14
+ // if index doesn't exist, set index 0
15
+ json[host][index] = val
16
+ await fs.promises.writeFile(filePath, JSON.stringify(json, null, 2), 'utf8')
17
+ }
18
+ }
19
+ async get(host, index) {
20
+ if (this.kernel.homedir) {
21
+ let filePath = this.kernel.path("key.json")
22
+ console.log({ host, index, filePath })
23
+ let json = await this.kernel.load(filePath)
24
+ if (!json) {
25
+ return null
26
+ }
27
+ console.log({ json })
28
+ if (json[host]) {
29
+ return json[host][index]
30
+ }
31
+ }
32
+ return null
33
+ }
34
+ }
35
+ module.exports = KV
package/kernel/shell.js CHANGED
@@ -216,7 +216,7 @@ class Shell {
216
216
  console.timeEnd("> 5")
217
217
  }
218
218
  async start(params, ondata) {
219
- console.log("shell start", params)
219
+ this.ondata = ondata
220
220
 
221
221
  /*
222
222
  params := {
@@ -227,6 +227,8 @@ class Shell {
227
227
  }
228
228
  */
229
229
 
230
+ this.kill_messages = params.kill
231
+
230
232
  this.cols = 100
231
233
  this.rows = 30
232
234
 
@@ -265,6 +267,7 @@ class Shell {
265
267
  await this.init_env(params)
266
268
 
267
269
 
270
+ this.ondata({ raw: `\r\n████\r\n██ Starting Shell ${this.id}\r\n` })
268
271
 
269
272
 
270
273
 
@@ -277,13 +280,13 @@ class Shell {
277
280
  if (params.sudo) {
278
281
  let options = {
279
282
  name: "Pinokio",
280
- // env: {}
283
+ env: {}
281
284
  // icns: '/Applications/Electron.app/Contents/Resources/Electron.icns', // (optional)
282
285
  };
283
286
 
284
- // for(let key in this.env) {
285
- // options.env[key] = String(this.env[key])
286
- // }
287
+ for(let key in this.env) {
288
+ options.env[key] = String(this.env[key])
289
+ }
287
290
 
288
291
  // sudo-prompt uses TEMP
289
292
  await fs.promises.mkdir(this.env.TEMP, { recursive: true }).catch((e) => { })
@@ -294,6 +297,7 @@ class Shell {
294
297
  // Modify process.env (and need to immediately revert it back to original process.env so as to not affect other logic)
295
298
  let old_env = process.env
296
299
  process.env = this.env
300
+ console.log("sudo process.env", process.env)
297
301
  sudo.exec(params.message, options, (err, stdout, stderr) => {
298
302
  if (err) {
299
303
  console.log("SUDOPROMPT ERR", err)
@@ -331,13 +335,27 @@ class Shell {
331
335
 
332
336
  // return this.id
333
337
  }
338
+ emit2(message) {
339
+ let i = 0;
340
+ const interval = setInterval(() => {
341
+ if (i >= message.length) {
342
+ clearInterval(interval);
343
+ return;
344
+ }
345
+ let chunk = message.slice(i, i+1024)
346
+ console.log("Writing chunk", chunk)
347
+ this.ptyProcess.write(chunk)
348
+ i += 1024;
349
+ }, 10);
350
+ }
334
351
  emit(message) {
335
- console.log("> 1", { message, input: this.input })
336
- if (this.ptyProcess) {
337
- console.log("> 2")
338
- if (this.input) {
339
- console.log("> 3")
340
- this.ptyProcess.write(message)
352
+ if (message.length > 1024) {
353
+ this.emit2(message)
354
+ } else {
355
+ if (this.ptyProcess) {
356
+ if (this.input) {
357
+ this.ptyProcess.write(message)
358
+ }
341
359
  }
342
360
  }
343
361
  }
@@ -414,7 +432,6 @@ class Shell {
414
432
  return r
415
433
  }
416
434
  async request(params, cb) {
417
- console.log("shell.request", params)
418
435
  // create the path if it doesn't exist
419
436
  await fs.promises.mkdir(params.path, { recursive: true }).catch((e) => { })
420
437
 
@@ -952,8 +969,16 @@ class Shell {
952
969
  this.resolve(buf)
953
970
  }
954
971
  this.resolve = undefined
972
+ this.ondata({ raw: `\r\n\r\n██ Detached from Shell ${this.id}\r\n\r\n` })
955
973
  }
956
974
  }
975
+ runSequentially(tasks) {
976
+ let chain = Promise.resolve();
977
+ for (const task of tasks) {
978
+ chain = chain.then(() => task());
979
+ }
980
+ return chain;
981
+ }
957
982
  kill(message, force) {
958
983
  console.log("KILL")
959
984
 
@@ -979,12 +1004,36 @@ class Shell {
979
1004
  this.vt.dispose()
980
1005
  this.queue.killAndDrain()
981
1006
  if (this.ptyProcess) {
982
- this.ptyProcess.kill()
983
- this.ptyProcess = undefined
1007
+ if (this.kill_messages) {
1008
+ console.log({ kill_messages: this.kill_messages })
1009
+ let promises = this.kill_messages.map((m) => {
1010
+ return new Promise(async (resolve, reject) => {
1011
+ await this.kernel.exec(m, this.ondata)
1012
+ resolve()
1013
+ })
1014
+ })
1015
+ this.runSequentially(promises).then(() => {
1016
+ console.log("Running kill message", { kill_messages })
1017
+ this.ptyProcess.write(kill_messages)
1018
+ this.ptyProcess.kill()
1019
+ this.ptyProcess = undefined
1020
+ // automatically remove the shell from this.kernel.shells
1021
+ this.kernel.shell.rm(this.id)
1022
+ this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1023
+ })
1024
+ } else {
1025
+ this.ptyProcess.kill()
1026
+ this.ptyProcess = undefined
1027
+ // automatically remove the shell from this.kernel.shells
1028
+ this.kernel.shell.rm(this.id)
1029
+ this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
1030
+ }
1031
+ } else {
1032
+ // automatically remove the shell from this.kernel.shells
1033
+ this.kernel.shell.rm(this.id)
1034
+ this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
984
1035
  }
985
1036
 
986
- // automatically remove the shell from this.kernel.shells
987
- this.kernel.shell.rm(this.id)
988
1037
 
989
1038
  }
990
1039
  log() {
package/kernel/shells.js CHANGED
@@ -66,12 +66,14 @@ class Shells {
66
66
  let res
67
67
  for(let i=0; i<params.message.length; i++) {
68
68
  let message = params.message[i]
69
- let params_dup = Object.assign({}, params)
70
- params_dup.message = message
71
- res = await this._launch(params_dup, options, ondata)
72
- // if there's an error, immediately return with the error
73
- if (res.error) {
74
- return res
69
+ if (message) {
70
+ let params_dup = Object.assign({}, params)
71
+ params_dup.message = message
72
+ res = await this._launch(params_dup, options, ondata)
73
+ // if there's an error, immediately return with the error
74
+ if (res.error) {
75
+ return res
76
+ }
75
77
  }
76
78
  }
77
79
  return res
@@ -81,7 +83,6 @@ class Shells {
81
83
  }
82
84
  }
83
85
  async _launch(params, options, ondata) {
84
- console.log("_launch", { params, options })
85
86
  // iterate through all the envs
86
87
  params.env = this.kernel.bin.envs(params.env)
87
88
 
@@ -157,6 +158,7 @@ class Shells {
157
158
  ondata(stream)
158
159
  })
159
160
 
161
+
160
162
  /*
161
163
  {
162
164
  method: "shell.run",
@@ -273,7 +275,6 @@ class Shells {
273
275
  }
274
276
  */
275
277
  let session = this.get(params.id)
276
- console.log("EMIT", { session, params })
277
278
  if (session) {
278
279
  session.emit(params.emit)
279
280
  }
@@ -348,7 +349,6 @@ class Shells {
348
349
  }
349
350
  }
350
351
  async run(req, options, ondata) {
351
- console.log("shells.run",req)
352
352
  let response = await this.launch(req, options, ondata)
353
353
  // req.id = id
354
354
  // let sh = this.get(id)
@@ -381,6 +381,7 @@ class Shells {
381
381
  * - Kill by group ID
382
382
  * request = { group }
383
383
  */
384
+
384
385
  if (request.id) {
385
386
 
386
387
  let shells = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.8.11",
3
+ "version": "3.8.13",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,6 +54,7 @@
54
54
  "random-useragent": "^0.5.0",
55
55
  "rimraf": "^5.0.0",
56
56
  "sanitize-filename": "^1.6.3",
57
+ "selfsigned": "^2.4.1",
57
58
  "semver": "^7.5.4",
58
59
  "shell-path": "^2.0.0",
59
60
  "sudo-prompt-programfiles-x86": "^9.2.10",