pinokiod 3.24.0 → 3.25.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/kernel/api/exec/index.js +67 -0
- package/kernel/api/index.js +1 -0
- package/kernel/plugin.js +24 -41
- package/kernel/prototype.js +23 -0
- package/kernel/router/index.js +13 -0
- package/kernel/router/localhost_home_router.js +11 -0
- package/kernel/shell.js +13 -10
- package/kernel/shells.js +52 -47
- package/package.json +2 -1
- package/server/index.js +191 -169
- package/server/public/style.css +1 -1
- package/server/socket.js +0 -19
- package/server/views/app.ejs +45 -11
- package/server/views/d.ejs +71 -12
- package/server/views/index.ejs +69 -1
- package/server/views/init/index.ejs +248 -87
- package/server/views/net.ejs +0 -1
- package/server/views/network.ejs +3 -2
- package/server/views/partials/dynamic.ejs +1 -1
- package/server/views/start.ejs +233 -0
package/server/index.js
CHANGED
|
@@ -188,16 +188,9 @@ class Server {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
} else if (key === "shell") {
|
|
191
|
-
console.log("CHECK SHELL", { name, indexPath, key })
|
|
192
|
-
console.log("obj", obj)
|
|
193
|
-
console.log("running", this.kernel.api.running)
|
|
194
191
|
let unix_path = Util.p2u(this.kernel.path("api", name))
|
|
195
|
-
console.log({ unix_path })
|
|
196
192
|
let shell_id = this.get_shell_id(unix_path, indexPath, obj[key])
|
|
197
|
-
|
|
198
|
-
console.log("SHELL ID 2", shell_id)
|
|
199
193
|
let decoded_shell_id = decodeURIComponent(shell_id)
|
|
200
|
-
console.log({ shell_id, decoded_shell_id })
|
|
201
194
|
if (this.kernel.api.running["shell/" + decoded_shell_id]) {
|
|
202
195
|
obj.running = true
|
|
203
196
|
obj.display = "indent"
|
|
@@ -431,34 +424,8 @@ class Server {
|
|
|
431
424
|
// }
|
|
432
425
|
|
|
433
426
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return
|
|
437
|
-
|
|
438
|
-
// // none of the pinokio.js, pinokio.json, pinokio_meta.json exists => need to initialize
|
|
439
|
-
// // if there is no menu, display all files
|
|
440
|
-
// let p = this.kernel.path("api", name)
|
|
441
|
-
// let files = await fs.promises.readdir(p, { withFileTypes: true })
|
|
442
|
-
// files = files.filter((file) => {
|
|
443
|
-
// return file.name.endsWith(".json") || file.name.endsWith(".js")
|
|
444
|
-
// }).filter((file) => {
|
|
445
|
-
// return file.name !== "pinokio.js" && file.name !== "pinokio.json" && file.name !== "pinokio_meta.json"
|
|
446
|
-
// })
|
|
447
|
-
// config = {
|
|
448
|
-
// init_required: true,
|
|
449
|
-
// icon: config.icon,
|
|
450
|
-
// title: name,
|
|
451
|
-
// menu: files.map((file) => {
|
|
452
|
-
// return {
|
|
453
|
-
// text: file.name,
|
|
454
|
-
// href: file.name
|
|
455
|
-
// }
|
|
456
|
-
// })
|
|
457
|
-
// }
|
|
458
|
-
// let uri = this.kernel.path("api")
|
|
459
|
-
// await this.renderMenu(uri, name, config, [])
|
|
460
|
-
} else {
|
|
461
|
-
let menu = config.menu || []
|
|
427
|
+
let menu = config.menu || []
|
|
428
|
+
try {
|
|
462
429
|
if (typeof config.menu === "function") {
|
|
463
430
|
if (config.menu.constructor.name === "AsyncFunction") {
|
|
464
431
|
config.menu = await config.menu(this.kernel, this.kernel.info)
|
|
@@ -466,11 +433,14 @@ class Server {
|
|
|
466
433
|
config.menu = config.menu(this.kernel, this.kernel.info)
|
|
467
434
|
}
|
|
468
435
|
}
|
|
436
|
+
} catch (e) {
|
|
437
|
+
err = e.stack
|
|
438
|
+
config.menu = []
|
|
439
|
+
}
|
|
469
440
|
|
|
470
|
-
|
|
471
|
-
|
|
441
|
+
let uri = this.kernel.path("api")
|
|
442
|
+
await this.renderMenu(uri, name, config, [])
|
|
472
443
|
|
|
473
|
-
}
|
|
474
444
|
|
|
475
445
|
let platform = os.platform()
|
|
476
446
|
|
|
@@ -585,18 +555,10 @@ class Server {
|
|
|
585
555
|
|
|
586
556
|
let plugin_menu = null
|
|
587
557
|
let plugin = await this.getPlugin(name)
|
|
588
|
-
console.log(">>> Plugin", plugin)
|
|
589
558
|
if (plugin && plugin.menu && Array.isArray(plugin.menu)) {
|
|
590
|
-
console.log(">>> 2")
|
|
591
559
|
plugin = structuredClone(plugin)
|
|
592
560
|
plugin_menu = this.running_dynamic(name, plugin.menu)
|
|
593
|
-
console.log("GOT THE PLUGIN MENU")
|
|
594
|
-
|
|
595
|
-
// plugin_menu = plugin.menu
|
|
596
561
|
}
|
|
597
|
-
console.log("PLUGIN_MENU", plugin_menu)
|
|
598
|
-
|
|
599
|
-
|
|
600
562
|
let menu_hidden = false
|
|
601
563
|
if (this.menu_hidden[name] && this.menu_hidden[name][type]) {
|
|
602
564
|
menu_hidden = true
|
|
@@ -686,7 +648,6 @@ class Server {
|
|
|
686
648
|
is_subpath(parent, child) {
|
|
687
649
|
const relative = path.relative(parent, child);
|
|
688
650
|
let check = !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
689
|
-
console.log({ relative, parent, child, check })
|
|
690
651
|
return check
|
|
691
652
|
}
|
|
692
653
|
async render(req, res, pathComponents, meta) {
|
|
@@ -1375,7 +1336,6 @@ class Server {
|
|
|
1375
1336
|
}
|
|
1376
1337
|
// check if there is a running process with this folder name
|
|
1377
1338
|
let runningApps = new Set()
|
|
1378
|
-
console.log("RUNNING", this.kernel.api.running)
|
|
1379
1339
|
for(let key in this.kernel.api.running) {
|
|
1380
1340
|
//let p = this.kernel.path("api", items[i].name) + path.sep
|
|
1381
1341
|
let p = this.kernel.path("api", items[i].name)
|
|
@@ -1396,23 +1356,17 @@ class Server {
|
|
|
1396
1356
|
} else {
|
|
1397
1357
|
// shell sessions
|
|
1398
1358
|
if (key.startsWith("shell/")) {
|
|
1399
|
-
// if (!path.isAbsolute(key)) {
|
|
1400
1359
|
let unix_path = key.slice(6)
|
|
1401
1360
|
let native_path = Util.u2p(unix_path)
|
|
1402
1361
|
let chunks = native_path.split("_")
|
|
1403
1362
|
if (chunks.length > 1) {
|
|
1404
1363
|
let folder = chunks[0]
|
|
1405
|
-
console.log({ chunks, folder, item: items[i] })
|
|
1406
1364
|
/// if the folder name matches, it's running
|
|
1407
1365
|
let item_path = this.kernel.path("api", items[i].name)
|
|
1408
|
-
console.log({ item_path, folder })
|
|
1409
1366
|
if (item_path === folder) {
|
|
1410
|
-
console.log("is_running = true")
|
|
1411
|
-
// if (folder === items[i].name) {
|
|
1412
1367
|
is_running = true
|
|
1413
1368
|
}
|
|
1414
1369
|
}
|
|
1415
|
-
|
|
1416
1370
|
}
|
|
1417
1371
|
}
|
|
1418
1372
|
}
|
|
@@ -1423,7 +1377,6 @@ class Server {
|
|
|
1423
1377
|
// => check inlcludes and endsWith
|
|
1424
1378
|
|
|
1425
1379
|
//if (key.includes(p) && key.endsWith(p)) {
|
|
1426
|
-
console.log("is_running", is_running)
|
|
1427
1380
|
if (is_running) {
|
|
1428
1381
|
// add to running
|
|
1429
1382
|
running.push(items[i])
|
|
@@ -1453,10 +1406,8 @@ class Server {
|
|
|
1453
1406
|
} else {
|
|
1454
1407
|
let shell = this.kernel.shell.find({
|
|
1455
1408
|
filter: (shell) => {
|
|
1456
|
-
//return shell.id.startsWith(items[i].name + "_")
|
|
1457
1409
|
let item_path = this.kernel.path("api", items[i].name)
|
|
1458
1410
|
let unix_item_path = Util.p2u(item_path)
|
|
1459
|
-
console.log("startsWith", { item_path, unix_item_path, id: shell.id })
|
|
1460
1411
|
return shell.id.startsWith("shell/" + unix_item_path + "_")
|
|
1461
1412
|
}
|
|
1462
1413
|
})
|
|
@@ -1747,6 +1698,89 @@ class Server {
|
|
|
1747
1698
|
}
|
|
1748
1699
|
return config
|
|
1749
1700
|
}
|
|
1701
|
+
renderShell(cwd, indexPath, subIndexPath, menuitem) {
|
|
1702
|
+
if (menuitem.shell) {
|
|
1703
|
+
/*
|
|
1704
|
+
shell :- {
|
|
1705
|
+
id (optional),
|
|
1706
|
+
path (required), // api, bin, quick, network, api/
|
|
1707
|
+
message (optional), // if not specified, start an empty shell
|
|
1708
|
+
venv,
|
|
1709
|
+
input, // input mode if true
|
|
1710
|
+
callback, // callback url after shutting down
|
|
1711
|
+
kill, // when to kill (regular expression)
|
|
1712
|
+
}
|
|
1713
|
+
*/
|
|
1714
|
+
|
|
1715
|
+
let rendered = this.kernel.template.render(menuitem.shell, {})
|
|
1716
|
+
let params = new URLSearchParams()
|
|
1717
|
+
// if (rendered.id) {
|
|
1718
|
+
// params.set("id", encodeURIComponent(rendered.id))
|
|
1719
|
+
// } else {
|
|
1720
|
+
// let shell_id = "sh_" + name + "_" + i
|
|
1721
|
+
// params.set("id", encodeURIComponent(shell_id))
|
|
1722
|
+
// }
|
|
1723
|
+
if (rendered.path) {
|
|
1724
|
+
params.set("path", encodeURIComponent(this.kernel.api.filePath(rendered.path, cwd)))
|
|
1725
|
+
} else {
|
|
1726
|
+
params.set("path", encodeURIComponent(cwd))
|
|
1727
|
+
}
|
|
1728
|
+
if (rendered.message) params.set("message", encodeURIComponent(rendered.message))
|
|
1729
|
+
if (rendered.venv) params.set("venv", encodeURIComponent(rendered.venv))
|
|
1730
|
+
if (rendered.input) params.set("input", true)
|
|
1731
|
+
if (rendered.callback) params.set("callback", encodeURIComponent(rendered.callback))
|
|
1732
|
+
if (rendered.callback_target) params.set("callback_target", rendered_callback_target)
|
|
1733
|
+
if (rendered.kill) params.set("kill", encodeURIComponent(rendered.kill))
|
|
1734
|
+
if (rendered.done) params.set("done", encodeURIComponent(rendered.done))
|
|
1735
|
+
if (rendered.env) {
|
|
1736
|
+
for(let key in rendered.env) {
|
|
1737
|
+
let env_key = "env." + key
|
|
1738
|
+
params.set(env_key, rendered.env[key])
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
if (rendered.conda) {
|
|
1742
|
+
for(let key in rendered.conda) {
|
|
1743
|
+
let conda_key = "conda." + key
|
|
1744
|
+
params.set(conda_key, rendered.conda[key])
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
// deterministic shell id generation
|
|
1749
|
+
// `${api_path}_${i}_${hash}`
|
|
1750
|
+
let currentIndexPath
|
|
1751
|
+
if (indexPath) {
|
|
1752
|
+
currentIndexPath = indexPath + "." + subIndexPath
|
|
1753
|
+
} else {
|
|
1754
|
+
currentIndexPath = "" + subIndexPath
|
|
1755
|
+
}
|
|
1756
|
+
let unix_path = Util.p2u(cwd)
|
|
1757
|
+
let shell_id = this.get_shell_id(unix_path, currentIndexPath, rendered)
|
|
1758
|
+
|
|
1759
|
+
console.log("SHELL ID 1", shell_id)
|
|
1760
|
+
|
|
1761
|
+
// let hash = crypto.createHash('md5').update(JSON.stringify(rendered)).digest('hex')
|
|
1762
|
+
// let shell_id
|
|
1763
|
+
// if (rendered.id) {
|
|
1764
|
+
// shell_id = encodeURIComponent(`${name}_${rendered.id}`)
|
|
1765
|
+
// } else {
|
|
1766
|
+
// shell_id = encodeURIComponent(`${name}_${i}_${hash}`)
|
|
1767
|
+
// }
|
|
1768
|
+
menuitem.href = "/shell/" + shell_id + "?" + params.toString()
|
|
1769
|
+
let decoded_shell_id = decodeURIComponent(shell_id)
|
|
1770
|
+
let shell = this.kernel.shell.get(decoded_shell_id)
|
|
1771
|
+
menuitem.shell_id = "shell/" + decoded_shell_id
|
|
1772
|
+
if (shell) {
|
|
1773
|
+
menuitem.running = true
|
|
1774
|
+
} else {
|
|
1775
|
+
let shell = this.kernel.shell.get(decoded_shell_id)
|
|
1776
|
+
if (shell) {
|
|
1777
|
+
menuitem.running = true
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
console.log("renderShell", menuitem)
|
|
1782
|
+
return menuitem
|
|
1783
|
+
}
|
|
1750
1784
|
|
|
1751
1785
|
async renderMenu(uri, name, config, pathComponents, indexPath) {
|
|
1752
1786
|
if (config.menu) {
|
|
@@ -1830,84 +1864,8 @@ class Server {
|
|
|
1830
1864
|
|
|
1831
1865
|
|
|
1832
1866
|
if (menuitem.shell) {
|
|
1833
|
-
/*
|
|
1834
|
-
shell :- {
|
|
1835
|
-
id (optional),
|
|
1836
|
-
path (required), // api, bin, quick, network, api/
|
|
1837
|
-
message (optional), // if not specified, start an empty shell
|
|
1838
|
-
venv,
|
|
1839
|
-
input, // input mode if true
|
|
1840
|
-
callback, // callback url after shutting down
|
|
1841
|
-
kill, // when to kill (regular expression)
|
|
1842
|
-
}
|
|
1843
|
-
*/
|
|
1844
|
-
|
|
1845
|
-
let rendered = this.kernel.template.render(menuitem.shell, {})
|
|
1846
|
-
let params = new URLSearchParams()
|
|
1847
|
-
// if (rendered.id) {
|
|
1848
|
-
// params.set("id", encodeURIComponent(rendered.id))
|
|
1849
|
-
// } else {
|
|
1850
|
-
// let shell_id = "sh_" + name + "_" + i
|
|
1851
|
-
// params.set("id", encodeURIComponent(shell_id))
|
|
1852
|
-
// }
|
|
1853
1867
|
let basePath = this.kernel.path("api", name)
|
|
1854
|
-
|
|
1855
|
-
params.set("path", encodeURIComponent(this.kernel.api.filePath(rendered.path, basePath)))
|
|
1856
|
-
} else {
|
|
1857
|
-
params.set("path", encodeURIComponent(basePath))
|
|
1858
|
-
}
|
|
1859
|
-
if (rendered.message) params.set("message", encodeURIComponent(rendered.message))
|
|
1860
|
-
if (rendered.venv) params.set("venv", encodeURIComponent(rendered.venv))
|
|
1861
|
-
if (rendered.input) params.set("input", true)
|
|
1862
|
-
if (rendered.callback) params.set("callback", encodeURIComponent(rendered.callback))
|
|
1863
|
-
if (rendered.callback_target) params.set("callback_target", rendered_callback_target)
|
|
1864
|
-
if (rendered.kill) params.set("kill", encodeURIComponent(rendered.kill))
|
|
1865
|
-
if (rendered.done) params.set("done", encodeURIComponent(rendered.done))
|
|
1866
|
-
if (rendered.env) {
|
|
1867
|
-
for(let key in rendered.env) {
|
|
1868
|
-
let env_key = "env." + key
|
|
1869
|
-
params.set(env_key, rendered.env[key])
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
if (rendered.conda) {
|
|
1873
|
-
for(let key in rendered.conda) {
|
|
1874
|
-
let conda_key = "conda." + key
|
|
1875
|
-
params.set(conda_key, rendered.conda[key])
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
// deterministic shell id generation
|
|
1880
|
-
// `${api_path}_${i}_${hash}`
|
|
1881
|
-
let currentIndexPath
|
|
1882
|
-
if (indexPath) {
|
|
1883
|
-
currentIndexPath = indexPath + "." + i
|
|
1884
|
-
} else {
|
|
1885
|
-
currentIndexPath = "" + i
|
|
1886
|
-
}
|
|
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)
|
|
1891
|
-
|
|
1892
|
-
// let hash = crypto.createHash('md5').update(JSON.stringify(rendered)).digest('hex')
|
|
1893
|
-
// let shell_id
|
|
1894
|
-
// if (rendered.id) {
|
|
1895
|
-
// shell_id = encodeURIComponent(`${name}_${rendered.id}`)
|
|
1896
|
-
// } else {
|
|
1897
|
-
// shell_id = encodeURIComponent(`${name}_${i}_${hash}`)
|
|
1898
|
-
// }
|
|
1899
|
-
menuitem.href = "/shell/" + shell_id + "?" + params.toString()
|
|
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
|
|
1903
|
-
if (shell) {
|
|
1904
|
-
menuitem.running = true
|
|
1905
|
-
} else {
|
|
1906
|
-
let shell = this.kernel.shell.get(decoded_shell_id)
|
|
1907
|
-
if (shell) {
|
|
1908
|
-
menuitem.running = true
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1868
|
+
this.renderShell(basePath, indexPath, i, menuitem)
|
|
1911
1869
|
}
|
|
1912
1870
|
|
|
1913
1871
|
if (menuitem.href) {
|
|
@@ -2022,9 +1980,7 @@ class Server {
|
|
|
2022
1980
|
config.menu[i].btn = menuitem.html
|
|
2023
1981
|
}
|
|
2024
1982
|
} else if (menuitem.hasOwnProperty("text")) {
|
|
2025
|
-
if (menuitem.hasOwnProperty("
|
|
2026
|
-
menuitem.html = `<i class="${menuitem.icon}"></i> ${menuitem.text}`
|
|
2027
|
-
} else if (menuitem.hasOwnProperty("image")) {
|
|
1983
|
+
if (menuitem.hasOwnProperty("image")) {
|
|
2028
1984
|
let imagePath
|
|
2029
1985
|
if (menuitem.image.startsWith("/")) {
|
|
2030
1986
|
imagePath = menuitem.image
|
|
@@ -2032,6 +1988,8 @@ class Server {
|
|
|
2032
1988
|
imagePath = `/api/${name}/${menuitem.image}?raw=true`
|
|
2033
1989
|
}
|
|
2034
1990
|
menuitem.html = `<img class='menu-item-image' src='${imagePath}' /> ${menuitem.text}`
|
|
1991
|
+
} else if (menuitem.hasOwnProperty("icon")) {
|
|
1992
|
+
menuitem.html = `<i class="${menuitem.icon}"></i> ${menuitem.text}`
|
|
2035
1993
|
} else {
|
|
2036
1994
|
menuitem.html = `${menuitem.text}`
|
|
2037
1995
|
}
|
|
@@ -2546,7 +2504,6 @@ class Server {
|
|
|
2546
2504
|
...item
|
|
2547
2505
|
}
|
|
2548
2506
|
})
|
|
2549
|
-
console.log("MENU 1", JSON.stringify(menu, null, 2))
|
|
2550
2507
|
// let menu = await this.kernel.plugin.config.menu(this.kernel, info)
|
|
2551
2508
|
let plugin = { menu }
|
|
2552
2509
|
let uri = filepath
|
|
@@ -2594,9 +2551,6 @@ class Server {
|
|
|
2594
2551
|
...item
|
|
2595
2552
|
}
|
|
2596
2553
|
})
|
|
2597
|
-
|
|
2598
|
-
console.log("MENU 2", JSON.stringify(menu, null, 2))
|
|
2599
|
-
|
|
2600
2554
|
let plugin = { menu }
|
|
2601
2555
|
let uri = this.kernel.path("api")
|
|
2602
2556
|
await this.renderMenu(uri, name, plugin, [])
|
|
@@ -2913,6 +2867,44 @@ class Server {
|
|
|
2913
2867
|
|
|
2914
2868
|
//let home = this.kernel.homedir
|
|
2915
2869
|
//let home = this.kernel.store.get("home")
|
|
2870
|
+
this.app.get("/launch", ex(async (req, res) => {
|
|
2871
|
+
// parse the url
|
|
2872
|
+
/*
|
|
2873
|
+
is it https://<name>.localhost ?
|
|
2874
|
+
- is <name> already installed?
|
|
2875
|
+
- yes: display
|
|
2876
|
+
- no: 404
|
|
2877
|
+
else: 404
|
|
2878
|
+
*/
|
|
2879
|
+
let url = req.query.url
|
|
2880
|
+
let u = new URL(url)
|
|
2881
|
+
let host = u.host
|
|
2882
|
+
if (host.endsWith(".localhost")) {
|
|
2883
|
+
let name = host.replace(/\.localhost$/, '')
|
|
2884
|
+
let api_path = this.kernel.path("api", name)
|
|
2885
|
+
let exists = await this.exists(api_path)
|
|
2886
|
+
if (exists) {
|
|
2887
|
+
let meta = await this.kernel.api.meta(name)
|
|
2888
|
+
res.render("start", {
|
|
2889
|
+
logo: this.logo,
|
|
2890
|
+
theme: this.theme,
|
|
2891
|
+
agent: this.agent,
|
|
2892
|
+
name: meta.title,
|
|
2893
|
+
image: meta.icon,
|
|
2894
|
+
link: "/p/" + name
|
|
2895
|
+
})
|
|
2896
|
+
return
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
res.render("start", {
|
|
2900
|
+
logo: this.logo,
|
|
2901
|
+
theme: this.theme,
|
|
2902
|
+
agent: this.agent,
|
|
2903
|
+
name: "Does not exist",
|
|
2904
|
+
image: "/pinokio-black.png",
|
|
2905
|
+
link: null
|
|
2906
|
+
})
|
|
2907
|
+
}))
|
|
2916
2908
|
this.app.get("/", ex(async (req, res) => {
|
|
2917
2909
|
// check bin folder
|
|
2918
2910
|
// let bin_path = this.kernel.path("bin/miniconda")
|
|
@@ -3128,8 +3120,11 @@ class Server {
|
|
|
3128
3120
|
// console.log("this.kernel.proto.init")
|
|
3129
3121
|
// await this.kernel.proto.init()
|
|
3130
3122
|
let list = this.getPeerInfo()
|
|
3123
|
+
let ai = await this.kernel.proto.ai()
|
|
3124
|
+
console.log("ai", ai)
|
|
3131
3125
|
res.render("init/index", {
|
|
3132
3126
|
list,
|
|
3127
|
+
ai,
|
|
3133
3128
|
current_host: this.kernel.peer.host,
|
|
3134
3129
|
cwd: this.kernel.path("api"),
|
|
3135
3130
|
name: null,
|
|
@@ -3798,7 +3793,6 @@ class Server {
|
|
|
3798
3793
|
if (item.name === req.params.name) {
|
|
3799
3794
|
processes = item.processes
|
|
3800
3795
|
host = item.host
|
|
3801
|
-
console.log("matched", processes)
|
|
3802
3796
|
peer = item
|
|
3803
3797
|
}
|
|
3804
3798
|
}
|
|
@@ -4524,9 +4518,6 @@ class Server {
|
|
|
4524
4518
|
} catch (e) {
|
|
4525
4519
|
console.log("ERROR", e)
|
|
4526
4520
|
}
|
|
4527
|
-
|
|
4528
|
-
console.log("gitRemote", gitRemote)
|
|
4529
|
-
|
|
4530
4521
|
res.render("env_editor", {
|
|
4531
4522
|
gitRemote,
|
|
4532
4523
|
home: null,
|
|
@@ -4969,7 +4960,6 @@ console.log("gitRemote", gitRemote)
|
|
|
4969
4960
|
let plugin = await this.getPluginGlobal(filepath)
|
|
4970
4961
|
let html = ""
|
|
4971
4962
|
let plugin_menu
|
|
4972
|
-
console.log("*********** plugin", plugin)
|
|
4973
4963
|
try {
|
|
4974
4964
|
plugin_menu = plugin.menu
|
|
4975
4965
|
//plugin_menu = plugin.menu[0].menu
|
|
@@ -4977,65 +4967,99 @@ console.log("gitRemote", gitRemote)
|
|
|
4977
4967
|
plugin_menu = []
|
|
4978
4968
|
}
|
|
4979
4969
|
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
4970
|
let retry = false
|
|
4983
4971
|
// if plugin_menu is empty, try again in 1 sec
|
|
4984
4972
|
if (plugin_menu.length === 0) {
|
|
4985
4973
|
retry = true
|
|
4986
4974
|
}
|
|
4987
|
-
|
|
4988
4975
|
let venvs = await Util.find_venv(filepath)
|
|
4989
|
-
console.log({ venvs, filepath })
|
|
4990
4976
|
let terminal
|
|
4991
|
-
|
|
4992
4977
|
if (venvs.length > 0) {
|
|
4993
4978
|
let terminals = []
|
|
4994
4979
|
try {
|
|
4995
|
-
for(let
|
|
4980
|
+
for(let i=0; i<venvs.length; i++) {
|
|
4981
|
+
let venv = venvs[i]
|
|
4996
4982
|
let parsed = path.parse(venv)
|
|
4997
|
-
terminals.push({
|
|
4983
|
+
terminals.push(this.renderShell(filepath, i, 0, {
|
|
4998
4984
|
icon: "fa-brands fa-python",
|
|
4999
|
-
title: "
|
|
4985
|
+
title: "Python virtual environment",
|
|
4986
|
+
subtitle: this.kernel.path("api", parsed.name),
|
|
4987
|
+
type: "Start",
|
|
5000
4988
|
shell: {
|
|
5001
4989
|
venv: venv,
|
|
5002
4990
|
input: true,
|
|
5003
4991
|
}
|
|
5004
|
-
})
|
|
4992
|
+
}))
|
|
5005
4993
|
}
|
|
5006
4994
|
} catch (e) {
|
|
5007
4995
|
console.log(e)
|
|
5008
4996
|
}
|
|
5009
4997
|
terminal = {
|
|
5010
4998
|
icon: "fa-solid fa-terminal",
|
|
5011
|
-
|
|
4999
|
+
title: "Open web terminal",
|
|
5000
|
+
subtitle: "Open the terminal in the browser",
|
|
5012
5001
|
menu: terminals
|
|
5013
5002
|
}
|
|
5014
5003
|
} else {
|
|
5015
5004
|
terminal = {
|
|
5016
5005
|
icon: "fa-solid fa-terminal",
|
|
5017
|
-
|
|
5018
|
-
|
|
5006
|
+
title: "Open web terminal",
|
|
5007
|
+
subtitle: "Work with the terminal directly in the browser",
|
|
5008
|
+
menu: [this.renderShell(filepath, 0, 0, {
|
|
5019
5009
|
icon: "fa-solid fa-terminal",
|
|
5020
|
-
title:
|
|
5010
|
+
title: "Terminal",
|
|
5011
|
+
subtitle: filepath,
|
|
5012
|
+
type: "Start",
|
|
5021
5013
|
shell: {
|
|
5022
5014
|
input: true
|
|
5023
5015
|
}
|
|
5024
|
-
}]
|
|
5016
|
+
})]
|
|
5025
5017
|
}
|
|
5026
5018
|
}
|
|
5027
5019
|
|
|
5020
|
+
let exec_menus = []
|
|
5021
|
+
let shell_menus = []
|
|
5022
|
+
if (plugin_menu.length > 0) {
|
|
5023
|
+
for(let item of plugin_menu) {
|
|
5024
|
+
// if shell.run method exists
|
|
5025
|
+
// if exec method exists
|
|
5026
|
+
let mode
|
|
5027
|
+
for(let step of item.run) {
|
|
5028
|
+
if (step.method === "exec") {
|
|
5029
|
+
mode = "exec"
|
|
5030
|
+
break
|
|
5031
|
+
}
|
|
5032
|
+
if (step.method === "shell.run") {
|
|
5033
|
+
mode = "shell"
|
|
5034
|
+
break
|
|
5035
|
+
}
|
|
5036
|
+
}
|
|
5037
|
+
if (mode === "exec") {
|
|
5038
|
+
item.type = "Open"
|
|
5039
|
+
exec_menus.push(item)
|
|
5040
|
+
} else if (mode === "shell") {
|
|
5041
|
+
item.type = "Start"
|
|
5042
|
+
shell_menus.push(item)
|
|
5043
|
+
}
|
|
5044
|
+
}
|
|
5045
|
+
exec_menus.sort((a, b) => { return a > b })
|
|
5046
|
+
shell_menus.sort((a, b) => { return a > b })
|
|
5047
|
+
}
|
|
5028
5048
|
let dynamic = [
|
|
5029
|
-
terminal,
|
|
5030
5049
|
{
|
|
5031
5050
|
icon: "fa-solid fa-robot",
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5051
|
+
title: "Get started building with AI",
|
|
5052
|
+
subtitle: "Start making changes to this project using AI",
|
|
5053
|
+
menu: shell_menus
|
|
5054
|
+
},
|
|
5055
|
+
{
|
|
5056
|
+
icon: "fa-solid fa-arrow-up-right-from-square",
|
|
5057
|
+
title: "Open in external apps",
|
|
5058
|
+
subtitle: "Open this project in 3rd party apps",
|
|
5059
|
+
menu: exec_menus
|
|
5060
|
+
},
|
|
5061
|
+
terminal,
|
|
5035
5062
|
]
|
|
5036
|
-
|
|
5037
|
-
console.log("### dynamic", JSON.stringify(dynamic, null, 2))
|
|
5038
|
-
|
|
5039
5063
|
res.render("d", {
|
|
5040
5064
|
retry,
|
|
5041
5065
|
current_urls,
|
|
@@ -5203,9 +5227,7 @@ console.log("gitRemote", gitRemote)
|
|
|
5203
5227
|
})
|
|
5204
5228
|
})
|
|
5205
5229
|
}
|
|
5206
|
-
} else {
|
|
5207
5230
|
}
|
|
5208
|
-
console.log({ html })
|
|
5209
5231
|
res.send(html)
|
|
5210
5232
|
}))
|
|
5211
5233
|
this.app.get("/pinokio/ai/:name", ex(async (req, res) => {
|
package/server/public/style.css
CHANGED
|
@@ -1408,7 +1408,7 @@ body.dark .not-running-apps .line.align-top h3 .col .title i {
|
|
|
1408
1408
|
color: rgba(255,255,255,0.4);
|
|
1409
1409
|
}
|
|
1410
1410
|
.not-running-apps .line.align-top h3 .col .title i {
|
|
1411
|
-
color: rgba(0,0,0,0.
|
|
1411
|
+
color: rgba(0,0,0,0.4);
|
|
1412
1412
|
}
|
|
1413
1413
|
.running-apps .line.align-top h3 .col .title i {
|
|
1414
1414
|
color: yellowgreen;
|
package/server/socket.js
CHANGED
|
@@ -61,9 +61,6 @@ class Socket {
|
|
|
61
61
|
// link git every time before processing
|
|
62
62
|
await this.parent.kernel.api.init()
|
|
63
63
|
// look for repos that match
|
|
64
|
-
|
|
65
|
-
console.log("REQ", req)
|
|
66
|
-
|
|
67
64
|
if (req.uri) {
|
|
68
65
|
if (req.mode === "open") {
|
|
69
66
|
// get the default script and respond
|
|
@@ -359,15 +356,9 @@ class Socket {
|
|
|
359
356
|
|
|
360
357
|
if (key.startsWith("shell/")) {
|
|
361
358
|
let unix_id = key.slice(6)
|
|
362
|
-
console.log({ key, unix_id })
|
|
363
|
-
|
|
364
359
|
let unix_path = unix_id.split("_")[0]
|
|
365
360
|
let native_path = Util.u2p(unix_path)
|
|
366
|
-
|
|
367
361
|
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
362
|
if (native_path_exists) {
|
|
372
363
|
let cwd = native_path
|
|
373
364
|
let session = this.sessions[key]
|
|
@@ -375,16 +366,6 @@ class Socket {
|
|
|
375
366
|
await Util.log(logpath, buf, session)
|
|
376
367
|
}
|
|
377
368
|
}
|
|
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
|
-
//}
|
|
388
369
|
}
|
|
389
370
|
}
|
|
390
371
|
}
|