pinokiod 3.23.0 → 3.24.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.
package/server/index.js CHANGED
@@ -188,8 +188,17 @@ class Server {
188
188
  }
189
189
  }
190
190
  } else if (key === "shell") {
191
- let shell_id = this.get_shell_id(name, indexPath, obj[key])
192
- if (this.kernel.api.running[shell_id]) {
191
+ console.log("CHECK SHELL", { name, indexPath, key })
192
+ console.log("obj", obj)
193
+ console.log("running", this.kernel.api.running)
194
+ let unix_path = Util.p2u(this.kernel.path("api", name))
195
+ console.log({ unix_path })
196
+ let shell_id = this.get_shell_id(unix_path, indexPath, obj[key])
197
+
198
+ console.log("SHELL ID 2", shell_id)
199
+ let decoded_shell_id = decodeURIComponent(shell_id)
200
+ console.log({ shell_id, decoded_shell_id })
201
+ if (this.kernel.api.running["shell/" + decoded_shell_id]) {
193
202
  obj.running = true
194
203
  obj.display = "indent"
195
204
  running_dynamic.push(obj)
@@ -576,18 +585,33 @@ class Server {
576
585
 
577
586
  let plugin_menu = null
578
587
  let plugin = await this.getPlugin(name)
588
+ console.log(">>> Plugin", plugin)
579
589
  if (plugin && plugin.menu && Array.isArray(plugin.menu)) {
590
+ console.log(">>> 2")
580
591
  plugin = structuredClone(plugin)
581
- this.running_dynamic(name, plugin.menu)
582
- plugin_menu = plugin.menu
592
+ plugin_menu = this.running_dynamic(name, plugin.menu)
593
+ console.log("GOT THE PLUGIN MENU")
594
+
595
+ // plugin_menu = plugin.menu
583
596
  }
597
+ console.log("PLUGIN_MENU", plugin_menu)
584
598
 
585
599
 
586
600
  let menu_hidden = false
587
601
  if (this.menu_hidden[name] && this.menu_hidden[name][type]) {
588
602
  menu_hidden = true
589
603
  }
604
+
605
+ let posix_path = Util.p2u(this.kernel.path("api", name))
606
+ let dev_link
607
+ if (posix_path.startsWith("/")) {
608
+ dev_link = "/d" + posix_path
609
+ } else {
610
+ dev_link = "/d/" + posix_path
611
+ }
612
+
590
613
  const result = {
614
+ dev_link,
591
615
  minimized: menu_hidden,
592
616
  // repos,
593
617
  current_urls,
@@ -1351,6 +1375,7 @@ class Server {
1351
1375
  }
1352
1376
  // check if there is a running process with this folder name
1353
1377
  let runningApps = new Set()
1378
+ console.log("RUNNING", this.kernel.api.running)
1354
1379
  for(let key in this.kernel.api.running) {
1355
1380
  //let p = this.kernel.path("api", items[i].name) + path.sep
1356
1381
  let p = this.kernel.path("api", items[i].name)
@@ -1360,19 +1385,30 @@ class Server {
1360
1385
  let is_running
1361
1386
  let api_path = this.kernel.path("api")
1362
1387
  if (this.is_subpath(api_path, key)) {
1388
+ // normal api script at path p
1363
1389
  if (this.is_subpath(p, key)) {
1364
1390
  is_running = true
1365
1391
  }
1366
1392
  } else {
1367
1393
  if (key.endsWith(p)) {
1394
+ // global scripts that run in the path p
1368
1395
  is_running = true
1369
1396
  } else {
1370
- if (!path.isAbsolute(key)) {
1371
- let chunks = key.split("_")
1397
+ // shell sessions
1398
+ if (key.startsWith("shell/")) {
1399
+ // if (!path.isAbsolute(key)) {
1400
+ let unix_path = key.slice(6)
1401
+ let native_path = Util.u2p(unix_path)
1402
+ let chunks = native_path.split("_")
1372
1403
  if (chunks.length > 1) {
1373
1404
  let folder = chunks[0]
1405
+ console.log({ chunks, folder, item: items[i] })
1374
1406
  /// if the folder name matches, it's running
1375
- if (folder === items[i].name) {
1407
+ let item_path = this.kernel.path("api", items[i].name)
1408
+ console.log({ item_path, folder })
1409
+ if (item_path === folder) {
1410
+ console.log("is_running = true")
1411
+ // if (folder === items[i].name) {
1376
1412
  is_running = true
1377
1413
  }
1378
1414
  }
@@ -1387,6 +1423,7 @@ class Server {
1387
1423
  // => check inlcludes and endsWith
1388
1424
 
1389
1425
  //if (key.includes(p) && key.endsWith(p)) {
1426
+ console.log("is_running", is_running)
1390
1427
  if (is_running) {
1391
1428
  // add to running
1392
1429
  running.push(items[i])
@@ -1416,7 +1453,11 @@ class Server {
1416
1453
  } else {
1417
1454
  let shell = this.kernel.shell.find({
1418
1455
  filter: (shell) => {
1419
- return shell.id.startsWith(items[i].name + "_")
1456
+ //return shell.id.startsWith(items[i].name + "_")
1457
+ let item_path = this.kernel.path("api", items[i].name)
1458
+ let unix_item_path = Util.p2u(item_path)
1459
+ console.log("startsWith", { item_path, unix_item_path, id: shell.id })
1460
+ return shell.id.startsWith("shell/" + unix_item_path + "_")
1420
1461
  }
1421
1462
  })
1422
1463
  if (shell.length > 0) {
@@ -1843,7 +1884,10 @@ class Server {
1843
1884
  } else {
1844
1885
  currentIndexPath = "" + i
1845
1886
  }
1846
- let shell_id = this.get_shell_id(name, currentIndexPath, rendered)
1887
+ let unix_path = Util.p2u(this.kernel.path("api", name))
1888
+ let shell_id = this.get_shell_id(unix_path, currentIndexPath, rendered)
1889
+
1890
+ console.log("SHELL ID 1", shell_id)
1847
1891
 
1848
1892
  // let hash = crypto.createHash('md5').update(JSON.stringify(rendered)).digest('hex')
1849
1893
  // let shell_id
@@ -1853,12 +1897,12 @@ class Server {
1853
1897
  // shell_id = encodeURIComponent(`${name}_${i}_${hash}`)
1854
1898
  // }
1855
1899
  menuitem.href = "/shell/" + shell_id + "?" + params.toString()
1856
- menuitem.shell_id = shell_id
1857
- let shell = this.kernel.shell.get(shell_id)
1900
+ let decoded_shell_id = decodeURIComponent(shell_id)
1901
+ let shell = this.kernel.shell.get(decoded_shell_id)
1902
+ menuitem.shell_id = "shell/" + decoded_shell_id
1858
1903
  if (shell) {
1859
1904
  menuitem.running = true
1860
1905
  } else {
1861
- let decoded_shell_id = decodeURIComponent(shell_id)
1862
1906
  let shell = this.kernel.shell.get(decoded_shell_id)
1863
1907
  if (shell) {
1864
1908
  menuitem.running = true
@@ -2494,7 +2538,16 @@ class Server {
2494
2538
  info.cwd = () => {
2495
2539
  return filepath
2496
2540
  }
2497
- let menu = await this.kernel.plugin.config.menu(this.kernel, info)
2541
+ let menu = this.kernel.plugin.config.menu.map((item) => {
2542
+ return {
2543
+ params: {
2544
+ cwd: filepath
2545
+ },
2546
+ ...item
2547
+ }
2548
+ })
2549
+ console.log("MENU 1", JSON.stringify(menu, null, 2))
2550
+ // let menu = await this.kernel.plugin.config.menu(this.kernel, info)
2498
2551
  let plugin = { menu }
2499
2552
  let uri = filepath
2500
2553
  await this.renderMenu(uri, filepath, plugin, [])
@@ -2526,11 +2579,24 @@ class Server {
2526
2579
  let cached = this.kernel.plugin.cache[name]
2527
2580
  return cached
2528
2581
  } else {
2529
- let info = new Info(this.kernel)
2530
- info.caller = () => {
2531
- return this.kernel.path("api", name, "pinokio.js")
2532
- }
2533
- let menu = await this.kernel.plugin.config.menu(this.kernel, info)
2582
+ // let info = new Info(this.kernel)
2583
+ // info.caller = () => {
2584
+ // return this.kernel.path("api", name, "pinokio.js")
2585
+ // }
2586
+ // let menu = await this.kernel.plugin.config.menu(this.kernel, info)
2587
+
2588
+ let menu = this.kernel.plugin.config.menu.map((item) => {
2589
+ return {
2590
+ params: {
2591
+ //cwd: this.kernel.path("api", name, "pinokio.js")
2592
+ cwd: this.kernel.path("api", name)
2593
+ },
2594
+ ...item
2595
+ }
2596
+ })
2597
+
2598
+ console.log("MENU 2", JSON.stringify(menu, null, 2))
2599
+
2534
2600
  let plugin = { menu }
2535
2601
  let uri = this.kernel.path("api")
2536
2602
  await this.renderMenu(uri, name, plugin, [])
@@ -3061,7 +3127,10 @@ class Server {
3061
3127
 
3062
3128
  // console.log("this.kernel.proto.init")
3063
3129
  // await this.kernel.proto.init()
3130
+ let list = this.getPeerInfo()
3064
3131
  res.render("init/index", {
3132
+ list,
3133
+ current_host: this.kernel.peer.host,
3065
3134
  cwd: this.kernel.path("api"),
3066
3135
  name: null,
3067
3136
  // name: req.params.name,
@@ -3527,7 +3596,12 @@ class Server {
3527
3596
  */
3528
3597
 
3529
3598
  // create a new term from cwd
3530
- let id = decodeURIComponent(req.params.id)
3599
+
3600
+ /*
3601
+ GET /shell/:unix_path => shell id: 'shell/:unix_path'
3602
+ */
3603
+
3604
+ let id = "shell/" + decodeURIComponent(req.params.id)
3531
3605
  let target = req.query.target ? req.query.target : null
3532
3606
  let cwd = this.kernel.path(this.kernel.api.filePath(decodeURIComponent(req.query.path)))
3533
3607
  let message = req.query.message ? decodeURIComponent(req.query.message) : null
@@ -4368,7 +4442,6 @@ class Server {
4368
4442
 
4369
4443
  const items = await Util.parse_env_detail(filepath)
4370
4444
 
4371
-
4372
4445
  res.render("env_editor", {
4373
4446
  home: true,
4374
4447
  config: null,
@@ -4436,8 +4509,26 @@ class Server {
4436
4509
  })
4437
4510
  } else {
4438
4511
 
4512
+ let gitRemote = null
4513
+ try {
4514
+ //const repositoryPath = this.kernel.path(pathComponents[0], pathComponents[1])
4515
+ //const repositoryPath = this.kernel.path(pathComponents[0])
4516
+ const repositoryPath = path.resolve(this.kernel.api.userdir, api_path)
4517
+ console.log({ repositoryPath })
4518
+ gitRemote = await git.getConfig({
4519
+ fs,
4520
+ http,
4521
+ dir: repositoryPath,
4522
+ path: 'remote.origin.url'
4523
+ })
4524
+ } catch (e) {
4525
+ console.log("ERROR", e)
4526
+ }
4527
+
4528
+ console.log("gitRemote", gitRemote)
4439
4529
 
4440
4530
  res.render("env_editor", {
4531
+ gitRemote,
4441
4532
  home: null,
4442
4533
  config,
4443
4534
  name,
@@ -4873,6 +4964,90 @@ class Server {
4873
4964
  agent: this.agent,
4874
4965
  })
4875
4966
  }))
4967
+ this.app.get("/d/*", ex(async (req, res) => {
4968
+ let filepath = Util.u2p(req.params[0])
4969
+ let plugin = await this.getPluginGlobal(filepath)
4970
+ let html = ""
4971
+ let plugin_menu
4972
+ console.log("*********** plugin", plugin)
4973
+ try {
4974
+ plugin_menu = plugin.menu
4975
+ //plugin_menu = plugin.menu[0].menu
4976
+ } catch (e) {
4977
+ plugin_menu = []
4978
+ }
4979
+ let current_urls = await this.current_urls(req.originalUrl.slice(1))
4980
+ console.log("RUNNING", this.kernel.api.running)
4981
+ console.log("DYNAMIC", JSON.stringify(plugin_menu, null, 2))
4982
+ let retry = false
4983
+ // if plugin_menu is empty, try again in 1 sec
4984
+ if (plugin_menu.length === 0) {
4985
+ retry = true
4986
+ }
4987
+
4988
+ let venvs = await Util.find_venv(filepath)
4989
+ console.log({ venvs, filepath })
4990
+ let terminal
4991
+
4992
+ if (venvs.length > 0) {
4993
+ let terminals = []
4994
+ try {
4995
+ for(let venv of venvs) {
4996
+ let parsed = path.parse(venv)
4997
+ terminals.push({
4998
+ icon: "fa-brands fa-python",
4999
+ title: "[venv] " + parsed.name,
5000
+ shell: {
5001
+ venv: venv,
5002
+ input: true,
5003
+ }
5004
+ })
5005
+ }
5006
+ } catch (e) {
5007
+ console.log(e)
5008
+ }
5009
+ terminal = {
5010
+ icon: "fa-solid fa-terminal",
5011
+ text: "Terminal",
5012
+ menu: terminals
5013
+ }
5014
+ } else {
5015
+ terminal = {
5016
+ icon: "fa-solid fa-terminal",
5017
+ text: "Terminal",
5018
+ menu: [{
5019
+ icon: "fa-solid fa-terminal",
5020
+ title: `Terminal (${filepath})`,
5021
+ shell: {
5022
+ input: true
5023
+ }
5024
+ }]
5025
+ }
5026
+ }
5027
+
5028
+ let dynamic = [
5029
+ terminal,
5030
+ {
5031
+ icon: "fa-solid fa-robot",
5032
+ text: "Build with AI",
5033
+ menu: plugin_menu
5034
+ }
5035
+ ]
5036
+
5037
+ console.log("### dynamic", JSON.stringify(dynamic, null, 2))
5038
+
5039
+ res.render("d", {
5040
+ retry,
5041
+ current_urls,
5042
+ docs: this.docs,
5043
+ portal: this.portal,
5044
+ install: this.install,
5045
+ agent: this.agent,
5046
+ theme: this.theme,
5047
+ //dynamic: plugin_menu
5048
+ dynamic,
5049
+ })
5050
+ }))
4876
5051
  this.app.get("/dev/*", ex(async (req, res) => {
4877
5052
  console.log("GET /dev/*", req.params)
4878
5053
  let { requirements, install_required, requirements_pending, error } = await this.kernel.bin.check({
@@ -5015,21 +5190,23 @@ class Server {
5015
5190
  this.app.get("/pinokio/dynamic/:name", ex(async (req, res) => {
5016
5191
  // await this.kernel.plugin.init()
5017
5192
  let plugin = await this.getPlugin(req.params.name)
5193
+ let html = ""
5194
+ console.log("plugin", JSON.stringify(plugin, null, 2))
5195
+ let plugin_menu
5018
5196
  if (plugin) {
5019
- let html = ""
5020
5197
  if (plugin && plugin.menu && Array.isArray(plugin.menu)) {
5021
5198
  plugin = structuredClone(plugin)
5022
- this.running_dynamic(req.params.name, plugin.menu)
5199
+ plugin_menu = this.running_dynamic(req.params.name, plugin.menu)
5023
5200
  html = await new Promise((resolve, reject) => {
5024
- ejs.renderFile(path.resolve(__dirname, "views/partials/dynamic.ejs"), { dynamic: plugin.menu }, (err, html) => {
5201
+ ejs.renderFile(path.resolve(__dirname, "views/partials/dynamic.ejs"), { dynamic: plugin_menu }, (err, html) => {
5025
5202
  resolve(html)
5026
5203
  })
5027
5204
  })
5028
5205
  }
5029
- res.send(html)
5030
5206
  } else {
5031
- res.send("")
5032
5207
  }
5208
+ console.log({ html })
5209
+ res.send(html)
5033
5210
  }))
5034
5211
  this.app.get("/pinokio/ai/:name", ex(async (req, res) => {
5035
5212
  /*
@@ -659,10 +659,14 @@ form.search {
659
659
  margin: 0;
660
660
  display: flex;
661
661
  flex-grow: 1;
662
+ padding: 10px 0;
662
663
  /*
663
664
  padding: 0 10px 20px;
664
665
  */
666
+
667
+ /*
665
668
  padding: 0 10px 10px;
669
+ */
666
670
  /*
667
671
  padding: 10px 20px 10px;
668
672
  */
@@ -726,6 +730,16 @@ form.search {
726
730
  font-weight: bold;
727
731
  font-size: 26px;
728
732
  }
733
+ .btn-tab {
734
+ padding: 10px 20px;
735
+ display: flex;
736
+ justify-content: center;
737
+ gap: 5px;
738
+ }
739
+ .btn-tab .btn {
740
+ text-align: center;
741
+ box-sizing: border-box;
742
+ }
729
743
  body.dark form.search input[type=search] {
730
744
  border: none;
731
745
  background: rgba(255,255,255,0.1);
@@ -733,11 +747,14 @@ body.dark form.search input[type=search] {
733
747
  }
734
748
  form.search input[type=search] {
735
749
  flex-grow: 1;
750
+ padding: 10px;
751
+ /*
736
752
  padding: 8px 10px;
753
+ */
737
754
  /*
738
755
  margin: 0 0 0 10px;
739
- */
740
756
  margin: 0 10px;
757
+ */
741
758
  /*
742
759
  border-radius: 6px 0 0 6px;
743
760
  */
@@ -1156,7 +1173,9 @@ body.dark .offline .indicator {
1156
1173
  .container {
1157
1174
  flex-grow: 1;
1158
1175
  box-sizing: border-box;
1176
+ /*
1159
1177
  padding: 0 20px;
1178
+ */
1160
1179
  /*
1161
1180
  max-width: var(--content-width);
1162
1181
  margin: 20px auto;
@@ -1385,6 +1404,12 @@ body.dark .line.align-top h3 .col .title a {
1385
1404
  color: yellowgreen;
1386
1405
  */
1387
1406
  }
1407
+ body.dark .not-running-apps .line.align-top h3 .col .title i {
1408
+ color: rgba(255,255,255,0.4);
1409
+ }
1410
+ .not-running-apps .line.align-top h3 .col .title i {
1411
+ color: rgba(0,0,0,0.04);
1412
+ }
1388
1413
  .running-apps .line.align-top h3 .col .title i {
1389
1414
  color: yellowgreen;
1390
1415
  }
package/server/socket.js CHANGED
@@ -62,6 +62,8 @@ class Socket {
62
62
  await this.parent.kernel.api.init()
63
63
  // look for repos that match
64
64
 
65
+ console.log("REQ", req)
66
+
65
67
  if (req.uri) {
66
68
  if (req.mode === "open") {
67
69
  // get the default script and respond
@@ -351,17 +353,38 @@ class Socket {
351
353
  key: facefusion-pinokio.git_0.0_a56eb7d48c9e96d8a5217d625d83d204
352
354
  key: audioplay_0.0_a56eb7d48c9e96d8a5217d625d83d204
353
355
 
356
+ key: shell:/Users/x/pinokio/api/comfy.git_0.0.0_session_6e89dd5ef73b94e728634729d08a3cf1
357
+
354
358
  */
355
359
 
356
- let api_name = key.split("_")[0]
357
- let api_path = this.parent.kernel.path("api", api_name)
358
- let api_path_exists = await new Promise(r=>fs.access(api_path, fs.constants.F_OK, e => r(!e)))
359
- if (api_path_exists) {
360
- let cwd = api_path
361
- let session = this.sessions[key]
362
- let logpath = path.resolve(cwd, "logs/shell")
363
- await Util.log(logpath, buf, session)
360
+ if (key.startsWith("shell/")) {
361
+ let unix_id = key.slice(6)
362
+ console.log({ key, unix_id })
363
+
364
+ let unix_path = unix_id.split("_")[0]
365
+ let native_path = Util.u2p(unix_path)
366
+
367
+ let native_path_exists = await new Promise(r=>fs.access(native_path, fs.constants.F_OK, e => r(!e)))
368
+
369
+ console.log({ unix_path, native_path, native_path_exists })
370
+
371
+ if (native_path_exists) {
372
+ let cwd = native_path
373
+ let session = this.sessions[key]
374
+ let logpath = path.resolve(cwd, "logs/shell")
375
+ await Util.log(logpath, buf, session)
376
+ }
364
377
  }
378
+
379
+ //let api_name = key.split("_")[0]
380
+ //let api_path = this.parent.kernel.path("api", api_name)
381
+ //let api_path_exists = await new Promise(r=>fs.access(api_path, fs.constants.F_OK, e => r(!e)))
382
+ //if (api_path_exists) {
383
+ // let cwd = api_path
384
+ // let session = this.sessions[key]
385
+ // let logpath = path.resolve(cwd, "logs/shell")
386
+ // await Util.log(logpath, buf, session)
387
+ //}
365
388
  }
366
389
  }
367
390
  }