pinokiod 3.9.0 → 3.9.2
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/filepicker/index.js +59 -0
- package/kernel/api/fs/index.js +6 -4
- package/kernel/api/index.js +123 -37
- package/kernel/api/input/index.js +2 -0
- package/kernel/api/web/index.js +6 -0
- package/kernel/bin/caddy.js +127 -0
- package/kernel/bin/cloudflared.js +1 -0
- package/kernel/bin/conda.js +10 -2
- package/kernel/bin/cuda.js +0 -16
- package/kernel/bin/ffmpeg.js +4 -6
- package/kernel/bin/git.js +55 -29
- package/kernel/bin/gxx.js +8 -6
- package/kernel/bin/huggingface.js +4 -5
- package/kernel/bin/index.js +347 -88
- package/kernel/bin/node.js +13 -6
- package/kernel/bin/py.js +1 -1
- package/kernel/bin/setup.js +146 -0
- package/kernel/bin/uv.js +4 -5
- package/kernel/bin/zip.js +7 -8
- package/kernel/connect/index.js +25 -0
- package/kernel/connect/providers/github/README.md +11 -0
- package/kernel/connect/providers/x/README.md +96 -0
- package/kernel/connect/providers/x/index.js +152 -0
- package/kernel/environment.js +50 -1
- package/kernel/index.js +152 -32
- package/kernel/info.js +4 -2
- package/kernel/kv.js +38 -0
- package/kernel/loader.js +13 -3
- package/kernel/peer.js +161 -0
- package/kernel/procs.js +116 -0
- package/kernel/prototype.js +62 -0
- package/kernel/router/common.js +42 -0
- package/kernel/router/connector.js +81 -0
- package/kernel/router/index.js +235 -0
- package/kernel/router/localhost_home_router.js +84 -0
- package/kernel/router/localhost_port_router.js +15 -0
- package/kernel/router/localhost_variable_router.js +37 -0
- package/kernel/router/peer_home_router.js +15 -0
- package/kernel/router/peer_peer_router.js +26 -0
- package/kernel/router/peer_port_router.js +45 -0
- package/kernel/router/peer_variable_router.js +46 -0
- package/kernel/router/processor.js +31 -0
- package/kernel/shell.js +141 -60
- package/kernel/shells.js +32 -17
- package/kernel/store.js +58 -0
- package/kernel/sysinfo.js +0 -1
- package/kernel/util.js +143 -36
- package/package.json +4 -1
- package/pipe/index.js +0 -2
- package/script/index.js +12 -0
- package/server/index.js +1473 -553
- package/server/public/Socket.js +5 -1
- package/server/public/SourceCodePro-Regular.ttf +0 -0
- package/server/public/SpaceMono-Bold.ttf +0 -0
- package/server/public/SpaceMono-BoldItalic.ttf +0 -0
- package/server/public/SpaceMono-Italic.ttf +0 -0
- package/server/public/SpaceMono-Regular.ttf +0 -0
- package/server/public/commander.js +40 -0
- package/server/public/common.js +60 -0
- package/server/public/dropzone-min.js +2 -0
- package/server/public/dropzone.css +1 -0
- package/server/public/filepond-plugin-file-validate-type.min.js +9 -0
- package/server/public/filepond-plugin-image-crop.min.js +9 -0
- package/server/public/filepond-plugin-image-edit.min.css +8 -0
- package/server/public/filepond-plugin-image-edit.min.js +9 -0
- package/server/public/filepond-plugin-image-exif-orientation.min.js +9 -0
- package/server/public/filepond-plugin-image-preview.min.css +8 -0
- package/server/public/filepond-plugin-image-preview.min.js +9 -0
- package/server/public/filepond-plugin-image-resize.min.js +9 -0
- package/server/public/filepond-plugin-image-transform.min.js +9 -0
- package/server/public/filepond.min.css +8 -0
- package/server/public/filepond.min.js +9 -0
- package/server/public/fscreator.js +174 -0
- package/server/public/fseditor.js +212 -0
- package/server/public/github.png +0 -0
- package/server/public/highlight-js.js +81 -0
- package/server/public/highlight.css +9 -0
- package/server/public/highlight.js +1244 -0
- package/server/public/install.js +17 -20
- package/server/public/modalinput.js +105 -9
- package/server/public/opener.js +3 -1
- package/server/public/pinokio-black.png +0 -0
- package/server/public/pinokio-black2.png +0 -0
- package/server/public/redoc.standalone.js +1832 -0
- package/server/public/style.css +211 -17
- package/server/public/swagger-ui-bundle.js +2 -0
- package/server/public/swagger-ui.css +3 -0
- package/server/public/x.js +63 -0
- package/server/socket.js +136 -39
- package/server/views/404.ejs +0 -1
- package/server/views/app.ejs +356 -90
- package/server/views/bootstrap.ejs +22 -19
- package/server/views/connect/x.ejs +324 -0
- package/server/views/connect.ejs +197 -0
- package/server/views/download.ejs +7 -1
- package/server/views/editor.ejs +68 -9
- package/server/views/explore.ejs +13 -10
- package/server/views/file_explorer.ejs +10 -37
- package/server/views/github.ejs +218 -0
- package/server/views/help.ejs +4 -3
- package/server/views/index.ejs +268 -118
- package/server/views/install.ejs +56 -29
- package/server/views/keys.ejs +276 -0
- package/server/views/network.ejs +889 -0
- package/server/views/partials/dynamic.ejs +9 -0
- package/server/views/partials/menu.ejs +7 -1
- package/server/views/prototype/index.ejs +311 -0
- package/server/views/prototype/show.ejs +383 -0
- package/server/views/redoc.ejs +18 -0
- package/server/views/required_env_editor.ejs +11 -2
- package/server/views/settings.ejs +38 -10
- package/server/views/setup.ejs +254 -0
- package/server/views/setup_home.ejs +192 -0
- package/server/views/shell.ejs +781 -0
- package/server/views/swaggerui.ejs +19 -0
- package/server/views/terminal.ejs +174 -42
- package/LICENSE +0 -7
- package/server/views/proxy.ejs +0 -405
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
/*
|
|
4
|
+
{
|
|
5
|
+
method: "filepicker.open",
|
|
6
|
+
params: {
|
|
7
|
+
title, := <dialog title>
|
|
8
|
+
type, := folder | file (default)
|
|
9
|
+
cwd, := <cwd to open from>
|
|
10
|
+
filetypes, := <file types to accept> (example: [["Images", "*.png *.jpg *.jpeg"]] )
|
|
11
|
+
multiple, := True | False (allow multiple)
|
|
12
|
+
save, := True | False ('save as' dialog, which lets the user select a file name)
|
|
13
|
+
initialfile, := In case of "save=True", set the default filename
|
|
14
|
+
confirmoverwrite, := True | False (if set to true, will warn if the selected file name exists, for save=True type dialogs)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
returns an array of selected file paths
|
|
20
|
+
|
|
21
|
+
returns: {
|
|
22
|
+
paths: [
|
|
23
|
+
...,
|
|
24
|
+
....
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
*/
|
|
29
|
+
class Filepicker {
|
|
30
|
+
async open(req, ondata, kernel) {
|
|
31
|
+
if (req.params.cwd) {
|
|
32
|
+
req.params.cwd = path.resolve(req.cwd, req.params.cwd)
|
|
33
|
+
} else {
|
|
34
|
+
req.params.cwd = req.cwd
|
|
35
|
+
}
|
|
36
|
+
let response = await new Promise((resolve, reject) => {
|
|
37
|
+
let picker_path = kernel.path("bin/py/picker.py")
|
|
38
|
+
const proc = spawn("python", [picker_path])
|
|
39
|
+
|
|
40
|
+
let output = "";
|
|
41
|
+
proc.stdout.on("data", (chunk) => output += chunk);
|
|
42
|
+
proc.stderr.on("data", (err) => console.error("Python error:", err.toString()));
|
|
43
|
+
proc.on("close", () => {
|
|
44
|
+
try {
|
|
45
|
+
const result = JSON.parse(output);
|
|
46
|
+
if (result.error) return reject(result.error);
|
|
47
|
+
resolve(result.paths); // Always an array
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject("Failed to parse Python output: " + output);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
proc.stdin.write(JSON.stringify(req.params));
|
|
54
|
+
proc.stdin.end();
|
|
55
|
+
});
|
|
56
|
+
return { paths: response }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
module.exports = Filepicker
|
package/kernel/api/fs/index.js
CHANGED
|
@@ -75,16 +75,18 @@ class FS {
|
|
|
75
75
|
/*
|
|
76
76
|
params := {
|
|
77
77
|
path: <filepath>,
|
|
78
|
-
|
|
78
|
+
command: "view(default)|open|<any command in PATH>"
|
|
79
79
|
}
|
|
80
80
|
open finder/file explorer at path
|
|
81
81
|
*/
|
|
82
82
|
let dirPath = path.resolve(req.cwd, req.params.path)
|
|
83
83
|
ondata({ raw: `\r\nopening path: ${dirPath}\r\n` })
|
|
84
|
-
if (req.params.
|
|
85
|
-
Util.openfs(dirPath, req.params
|
|
84
|
+
if (req.params.command) {
|
|
85
|
+
Util.openfs(dirPath, req.params, kernel)
|
|
86
|
+
} else if (req.params.mode) {
|
|
87
|
+
Util.openfs(dirPath, req.params, kernel)
|
|
86
88
|
} else {
|
|
87
|
-
Util.openfs(dirPath)
|
|
89
|
+
Util.openfs(dirPath, {}, kernel)
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
package/kernel/api/index.js
CHANGED
|
@@ -28,6 +28,21 @@ class Api {
|
|
|
28
28
|
this.child_procs = {}
|
|
29
29
|
this.lproxy = new Lproxy()
|
|
30
30
|
}
|
|
31
|
+
async meta(name) {
|
|
32
|
+
let p = this.kernel.path("api", name, "pinokio.js")
|
|
33
|
+
let pinokio = (await this.kernel.loader.load(p)).resolved
|
|
34
|
+
let p2 = this.kernel.path("api", name, "pinokio_meta.json")
|
|
35
|
+
let pinokio2 = (await this.kernel.loader.load(p2)).resolved
|
|
36
|
+
let p3 = this.kernel.path("api", name, "pinokio.json")
|
|
37
|
+
let pinokio3 = (await this.kernel.loader.load(p3)).resolved
|
|
38
|
+
let meta = Object.assign({}, pinokio, pinokio2, pinokio3)
|
|
39
|
+
meta.iconpath = meta.icon ? this.kernel.path("api", name, meta.icon) : null
|
|
40
|
+
meta.icon = meta.icon ? `/api/${name}/${meta.icon}?raw=true` : "/pinokio-black.png"
|
|
41
|
+
meta.path = this.kernel.path("api", name)
|
|
42
|
+
meta.name = meta.title
|
|
43
|
+
meta.link = `/pinokio/browser/${name}/browse#n1`
|
|
44
|
+
return meta
|
|
45
|
+
}
|
|
31
46
|
get_proxy_url(root, port) {
|
|
32
47
|
if (this.proxies) {
|
|
33
48
|
let proxies = this.proxies[root]
|
|
@@ -124,16 +139,12 @@ class Api {
|
|
|
124
139
|
|
|
125
140
|
let requestPath = this.filePath(req.params.uri)
|
|
126
141
|
|
|
127
|
-
|
|
128
|
-
|
|
129
142
|
let { cwd, script } = await this.resolveScript(requestPath)
|
|
130
|
-
console.log("STOP", { script })
|
|
131
143
|
if (script.on) {
|
|
132
144
|
if (script.on.stop) {
|
|
133
145
|
await this.process(script.on.stop)
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
|
-
|
|
137
148
|
// reset modules
|
|
138
149
|
let modpath = this.resolvePath(cwd, req.params.uri)
|
|
139
150
|
console.log("STOP modpath", modpath)
|
|
@@ -179,6 +190,7 @@ class Api {
|
|
|
179
190
|
id: requestPath,
|
|
180
191
|
type: "disconnect"
|
|
181
192
|
})
|
|
193
|
+
this.kernel.refresh(true)
|
|
182
194
|
return true
|
|
183
195
|
}
|
|
184
196
|
async startScripts() {
|
|
@@ -352,13 +364,20 @@ class Api {
|
|
|
352
364
|
let modpath
|
|
353
365
|
if (matched_repo.length > 0) {
|
|
354
366
|
let repo_uri = matched_repo[0]
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
.slice(1) // remove the leading '/' for relative path
|
|
367
|
+
if (!repo_uri.endsWith(".git")) {
|
|
368
|
+
repo_uri = repo_uri + ".git"
|
|
369
|
+
}
|
|
359
370
|
|
|
360
371
|
let repopath = this.gitPath[repo_uri]
|
|
361
|
-
|
|
372
|
+
if (uri === repo_uri) {
|
|
373
|
+
modpath = path.resolve(repopath)
|
|
374
|
+
} else {
|
|
375
|
+
let relative_path = uri
|
|
376
|
+
.replace(repo_uri, "") // remove the git repo uri
|
|
377
|
+
.slice(1) // remove the leading '/' for relative path
|
|
378
|
+
modpath = path.resolve(repopath, relative_path)
|
|
379
|
+
}
|
|
380
|
+
|
|
362
381
|
} else {
|
|
363
382
|
//console.log("no matching gitpath")
|
|
364
383
|
}
|
|
@@ -426,14 +445,18 @@ class Api {
|
|
|
426
445
|
let method
|
|
427
446
|
let dirname
|
|
428
447
|
let mod
|
|
429
|
-
if (req.
|
|
448
|
+
if (req.method && typeof req.method === "function") {
|
|
449
|
+
modpath = null
|
|
450
|
+
method = req.method
|
|
451
|
+
dirname = __dirname
|
|
452
|
+
mod = null
|
|
453
|
+
} else if (req.uri) {
|
|
430
454
|
modpath = this.resolvePath(cwd, req.uri)
|
|
431
455
|
let m = (await this.loader.load(modpath))
|
|
432
456
|
const stats = await fs.promises.stat(modpath)
|
|
433
457
|
if (!this.child_procs[req.parent.path]) {
|
|
434
458
|
this.child_procs[req.parent.path] = new Set()
|
|
435
459
|
}
|
|
436
|
-
console.log("SCRIPT RESOLVE METHOD", req)
|
|
437
460
|
if (this.mods[modpath]) {
|
|
438
461
|
// use the cached module if unchanged
|
|
439
462
|
if (String(stats.mtime) === String(this.mods[modpath].updated)) {
|
|
@@ -567,15 +590,19 @@ class Api {
|
|
|
567
590
|
|
|
568
591
|
}
|
|
569
592
|
async step (request, rawrpc, input, i, total, args) {
|
|
570
|
-
console.time("STEP INIT")
|
|
571
593
|
await Promise.all([this.init(), this.kernel.update_sysinfo()])
|
|
572
|
-
console.timeEnd("STEP INIT")
|
|
573
594
|
|
|
574
595
|
// clear global regular expression object RegExp.lastMatch (memory leak prevention)
|
|
575
596
|
let r = /\s*/g.exec("");
|
|
576
597
|
|
|
598
|
+
let port = await this.kernel.port()
|
|
599
|
+
|
|
577
600
|
let { cwd, script } = await this.resolveScript(request.path)
|
|
578
601
|
|
|
602
|
+
if (request.cwd) {
|
|
603
|
+
cwd = request.cwd
|
|
604
|
+
}
|
|
605
|
+
|
|
579
606
|
let memory = {
|
|
580
607
|
script: this.kernel.script,
|
|
581
608
|
input,
|
|
@@ -587,6 +614,7 @@ class Api {
|
|
|
587
614
|
uri: request.uri,
|
|
588
615
|
cwd,
|
|
589
616
|
self: script,
|
|
617
|
+
port,
|
|
590
618
|
...this.kernel.vars,
|
|
591
619
|
}
|
|
592
620
|
|
|
@@ -627,7 +655,6 @@ class Api {
|
|
|
627
655
|
break;
|
|
628
656
|
}
|
|
629
657
|
}
|
|
630
|
-
|
|
631
658
|
// replace {{{ }}} with {{ }}
|
|
632
659
|
rpc = this.kernel.template.flatten(rpc)
|
|
633
660
|
|
|
@@ -761,6 +788,7 @@ class Api {
|
|
|
761
788
|
uri: request.path
|
|
762
789
|
}
|
|
763
790
|
})
|
|
791
|
+
console.log(">>>>>> STOPPED", request)
|
|
764
792
|
}
|
|
765
793
|
return { request, input: null, step: rpc.next, total: script.run.length, args }
|
|
766
794
|
} else {
|
|
@@ -979,6 +1007,7 @@ class Api {
|
|
|
979
1007
|
uri: request.path
|
|
980
1008
|
}
|
|
981
1009
|
})
|
|
1010
|
+
console.log("<<<<<< STOPPED", request)
|
|
982
1011
|
return { request, input: result, step: rpc.next, total: script.run.length, args }
|
|
983
1012
|
}
|
|
984
1013
|
|
|
@@ -1056,6 +1085,7 @@ class Api {
|
|
|
1056
1085
|
})
|
|
1057
1086
|
}
|
|
1058
1087
|
}
|
|
1088
|
+
this.kernel.refresh(true)
|
|
1059
1089
|
} catch (e) {
|
|
1060
1090
|
ondata({ raw: e.toString() })
|
|
1061
1091
|
}
|
|
@@ -1121,6 +1151,35 @@ class Api {
|
|
|
1121
1151
|
this.process(request, resolve)
|
|
1122
1152
|
})
|
|
1123
1153
|
}
|
|
1154
|
+
async get_default(repo_path) {
|
|
1155
|
+
let p = path.resolve(repo_path, "pinokio.js")
|
|
1156
|
+
// call 'process' based on the current status
|
|
1157
|
+
let config = (await this.loader.load(p)).resolved
|
|
1158
|
+
if (config && config.menu) {
|
|
1159
|
+
if (typeof config.menu === "function") {
|
|
1160
|
+
if (config.menu.constructor.name === "AsyncFunction") {
|
|
1161
|
+
config.menu = await config.menu(this.kernel, this.kernel.info)
|
|
1162
|
+
} else {
|
|
1163
|
+
config.menu = config.menu(this.kernel, this.kernel.info)
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
// find the default item in the menu
|
|
1167
|
+
let running = config.menu.filter((item) => {
|
|
1168
|
+
return item.default
|
|
1169
|
+
})
|
|
1170
|
+
if (running.length > 0) {
|
|
1171
|
+
let r = running[0]
|
|
1172
|
+
if (r.href) {
|
|
1173
|
+
if (r.href.startsWith("http")) {
|
|
1174
|
+
return r.href
|
|
1175
|
+
} else {
|
|
1176
|
+
let href = path.resolve(repo_path, r.href)
|
|
1177
|
+
return href
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1124
1183
|
async process(request, done) {
|
|
1125
1184
|
/**************************************************************
|
|
1126
1185
|
*
|
|
@@ -1162,43 +1221,66 @@ class Api {
|
|
|
1162
1221
|
// this.kernel.keys = (await this.loader.load(keypath)).resolved
|
|
1163
1222
|
|
|
1164
1223
|
// init shell before running just to make sure the environment variables are fresh
|
|
1165
|
-
console.time("shell.init")
|
|
1166
1224
|
await this.kernel.shell.init()
|
|
1167
|
-
console.timeEnd("shell.init")
|
|
1168
1225
|
|
|
1169
1226
|
if (request.uri){
|
|
1227
|
+
|
|
1170
1228
|
this.counter++;
|
|
1171
1229
|
// API Call
|
|
1172
1230
|
|
|
1173
1231
|
request.path = this.resolvePath(this.userdir, request.uri)
|
|
1174
|
-
let { cwd, script } = await this.resolveScript(request.path)
|
|
1175
|
-
request.cwd = cwd
|
|
1176
|
-
|
|
1177
|
-
if (!script) {
|
|
1178
|
-
this.ondata({
|
|
1179
|
-
id: request.path,
|
|
1180
|
-
type: "error",
|
|
1181
|
-
data: "the endpoint does not exist: " + request.uri,
|
|
1182
|
-
})
|
|
1183
|
-
} else {
|
|
1184
|
-
// 3. Check if the resolved endpoint has the "run" attribute and it's an array
|
|
1185
|
-
//if (script.run && Array.isArray(script.run)) {
|
|
1186
|
-
if (script.run) {
|
|
1187
|
-
|
|
1188
|
-
this.running[request.path] = true
|
|
1189
|
-
|
|
1190
|
-
this.done[request.path] = done
|
|
1191
1232
|
|
|
1192
|
-
this.queue(request, script.run[0], request.input, 0, script.run.length, cwd, request.input)
|
|
1193
1233
|
|
|
1234
|
+
// if the path is
|
|
1235
|
+
let relative = path.relative(this.kernel.homedir, request.path)
|
|
1236
|
+
let chunks = relative.split(path.sep)
|
|
1237
|
+
console.log({ chunks })
|
|
1238
|
+
if (chunks.length == 2) {
|
|
1239
|
+
// the script is requesting a uri of the git repo
|
|
1240
|
+
// look for pinokio.js
|
|
1241
|
+
let p = path.resolve(request.path, "pinokio.js")
|
|
1242
|
+
let exists = await this.exists(p)
|
|
1243
|
+
console.log({ p, exists })
|
|
1244
|
+
if (exists) {
|
|
1245
|
+
await this.launch(request, p)
|
|
1194
1246
|
} else {
|
|
1195
1247
|
this.ondata({
|
|
1196
1248
|
id: request.path,
|
|
1197
1249
|
type: "error",
|
|
1198
|
-
data: "
|
|
1250
|
+
data: "uri doesn't exist \r\n" + JSON.stringify(request, null, 2)
|
|
1251
|
+
})
|
|
1252
|
+
}
|
|
1253
|
+
} else {
|
|
1254
|
+
console.log({ request })
|
|
1255
|
+
let { cwd, script } = await this.resolveScript(request.path)
|
|
1256
|
+
|
|
1257
|
+
if (!script) {
|
|
1258
|
+
this.ondata({
|
|
1259
|
+
id: request.path,
|
|
1260
|
+
type: "error",
|
|
1261
|
+
data: "the endpoint does not exist: " + request.uri,
|
|
1199
1262
|
})
|
|
1263
|
+
} else {
|
|
1264
|
+
// 3. Check if the resolved endpoint has the "run" attribute and it's an array
|
|
1265
|
+
//if (script.run && Array.isArray(script.run)) {
|
|
1266
|
+
if (script.run) {
|
|
1267
|
+
|
|
1268
|
+
this.running[request.path] = true
|
|
1269
|
+
|
|
1270
|
+
this.done[request.path] = done
|
|
1271
|
+
|
|
1272
|
+
this.queue(request, script.run[0], request.input, 0, script.run.length, cwd, request.input)
|
|
1273
|
+
|
|
1274
|
+
} else {
|
|
1275
|
+
this.ondata({
|
|
1276
|
+
id: request.path,
|
|
1277
|
+
type: "error",
|
|
1278
|
+
data: "missing attribute: run"
|
|
1279
|
+
})
|
|
1280
|
+
}
|
|
1200
1281
|
}
|
|
1201
1282
|
}
|
|
1283
|
+
|
|
1202
1284
|
} else if (request.method) {
|
|
1203
1285
|
let pass = 0;
|
|
1204
1286
|
while(true) {
|
|
@@ -1229,12 +1311,16 @@ class Api {
|
|
|
1229
1311
|
|
|
1230
1312
|
// Kernel Call
|
|
1231
1313
|
let resolved = await this.resolveMethod(request)
|
|
1314
|
+
let id = request.id ? request.id : request.method
|
|
1315
|
+
if (request.id) {
|
|
1316
|
+
this.running[request.id] = true
|
|
1317
|
+
}
|
|
1232
1318
|
try {
|
|
1233
1319
|
resolved.dirname = resolved.dirname
|
|
1234
1320
|
let result = await this.run(resolved.method, request, (stream, type) => {
|
|
1235
1321
|
this.ondata({
|
|
1236
1322
|
kernel: true,
|
|
1237
|
-
id
|
|
1323
|
+
id,
|
|
1238
1324
|
type: (type ? type : "stream"),
|
|
1239
1325
|
data: stream,
|
|
1240
1326
|
rpc: request,
|
|
@@ -1243,7 +1329,7 @@ class Api {
|
|
|
1243
1329
|
})
|
|
1244
1330
|
this.ondata({
|
|
1245
1331
|
kernel: true,
|
|
1246
|
-
id
|
|
1332
|
+
id,
|
|
1247
1333
|
type: "result",
|
|
1248
1334
|
data: result,
|
|
1249
1335
|
rpc: request,
|
package/kernel/api/web/index.js
CHANGED
|
@@ -21,5 +21,11 @@ class Web {
|
|
|
21
21
|
kernel.exposed[app] = req.params.uri
|
|
22
22
|
console.log("kernel.exposed", kernel.exposed)
|
|
23
23
|
}
|
|
24
|
+
async open(req, ondata, kernel) {
|
|
25
|
+
ondata(req.params, "browser.open")
|
|
26
|
+
}
|
|
27
|
+
async close(req, ondata, kernel) {
|
|
28
|
+
ondata(req.params, "browser.close")
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
module.exports = Web
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const axios = require('axios')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
|
|
4
|
+
class Caddy {
|
|
5
|
+
cmd() {
|
|
6
|
+
if (this.kernel.platform === "win32") {
|
|
7
|
+
return "caddy"
|
|
8
|
+
} else {
|
|
9
|
+
return "caddy nss"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async running() {
|
|
13
|
+
console.log("caddy running check")
|
|
14
|
+
try {
|
|
15
|
+
let response = await axios.get('http://127.0.0.1:2019/config/')
|
|
16
|
+
return true
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.log(e.message)
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async start() {
|
|
23
|
+
// console.log(">> proc", this.kernel.processes.caddy_pid, this.kernel.processes.info)
|
|
24
|
+
// let running = await this.running()
|
|
25
|
+
// console.log("Running", running)
|
|
26
|
+
// if (running) {
|
|
27
|
+
// // kill first
|
|
28
|
+
// return
|
|
29
|
+
// }
|
|
30
|
+
let installed = await this.installed()
|
|
31
|
+
console.log("Caddy Installed?", installed)
|
|
32
|
+
if (installed) {
|
|
33
|
+
let resolved
|
|
34
|
+
await new Promise((resolve, reject) => {
|
|
35
|
+
this.kernel.exec({
|
|
36
|
+
message: `caddy run --watch`,
|
|
37
|
+
path: this.kernel.homedir,
|
|
38
|
+
}, (e) => {
|
|
39
|
+
if (!resolved) {
|
|
40
|
+
if (/endpoint started/i.test(e.cleaned)) {
|
|
41
|
+
console.log("######### match")
|
|
42
|
+
resolved = true
|
|
43
|
+
resolve()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
this.kernel.refresh(true)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async install(req, ondata, kernel, id) {
|
|
52
|
+
await this.kernel.bin.exec({
|
|
53
|
+
message: [
|
|
54
|
+
"conda clean -y --all",
|
|
55
|
+
`conda install -y -c conda-forge ${this.cmd()}`
|
|
56
|
+
]
|
|
57
|
+
}, ondata)
|
|
58
|
+
let resolved
|
|
59
|
+
await new Promise((resolve, reject) => {
|
|
60
|
+
this.kernel.exec({
|
|
61
|
+
message: `caddy run --watch`,
|
|
62
|
+
path: this.kernel.homedir,
|
|
63
|
+
}, (e) => {
|
|
64
|
+
resolve()
|
|
65
|
+
if (!resolved) {
|
|
66
|
+
if (/endpoint started/i.test(e.cleaned)) {
|
|
67
|
+
console.log("######### match")
|
|
68
|
+
resolved = true
|
|
69
|
+
resolve()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
if (this.kernel.platform === "win32") {
|
|
75
|
+
await this.kernel.exec({
|
|
76
|
+
message: `caddy trust`,
|
|
77
|
+
path: this.kernel.homedir
|
|
78
|
+
}, (e) => {
|
|
79
|
+
ondata(e)
|
|
80
|
+
})
|
|
81
|
+
} else {
|
|
82
|
+
ondata({
|
|
83
|
+
title: "Password",
|
|
84
|
+
description: "Enter your system password to add the HTTPS certificate",
|
|
85
|
+
form: [{
|
|
86
|
+
type: "password",
|
|
87
|
+
autofocus: true,
|
|
88
|
+
key: "password",
|
|
89
|
+
placeholder: "System password",
|
|
90
|
+
}]
|
|
91
|
+
}, "input")
|
|
92
|
+
let response = await this.kernel.api.wait(id)
|
|
93
|
+
await this.kernel.exec({
|
|
94
|
+
message: `echo ${response.password} | sudo -S caddy trust`,
|
|
95
|
+
path: this.kernel.homedir
|
|
96
|
+
}, (e) => {
|
|
97
|
+
// ondata(e)
|
|
98
|
+
// console.log(e)
|
|
99
|
+
// if (/Caddy Local Authority/i.test(e.cleaned)) {
|
|
100
|
+
// trusted = true
|
|
101
|
+
// }
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async installed() {
|
|
106
|
+
let e = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/pki/authorities/local/root.crt"))
|
|
107
|
+
if (e) {
|
|
108
|
+
if (this.kernel.platform === "win32") {
|
|
109
|
+
return this.kernel.bin.installed.conda.has("caddy")
|
|
110
|
+
} else {
|
|
111
|
+
return this.kernel.bin.installed.conda.has("caddy") && this.kernel.bin.installed.conda.has("nss")
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async uninstall(req, ondata) {
|
|
118
|
+
ondata({ raw: "cleaning up\r\n" })
|
|
119
|
+
await this.kernel.bin.exec({
|
|
120
|
+
message: `conda remove ${this.cmd()}`,
|
|
121
|
+
}, ondata)
|
|
122
|
+
const folder = this.kernel.path("cache/XDG_DATA_HOME/caddy")
|
|
123
|
+
await rimraf(folder)
|
|
124
|
+
ondata({ raw: "finished cleaning up\r\n" })
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
module.exports = Caddy
|
package/kernel/bin/conda.js
CHANGED
|
@@ -4,6 +4,7 @@ const fetch = require('cross-fetch')
|
|
|
4
4
|
const { glob } = require('glob')
|
|
5
5
|
const semver = require('semver')
|
|
6
6
|
class Conda {
|
|
7
|
+
description = "Pinokio uses Conda to install various useful programs in an isolated manner."
|
|
7
8
|
urls = {
|
|
8
9
|
darwin: {
|
|
9
10
|
//x64: "https://repo.anaconda.com/miniconda/Miniconda3-py310_23.5.2-0-MacOSX-x86_64.sh",
|
|
@@ -119,6 +120,7 @@ report_errors: false`)
|
|
|
119
120
|
// }
|
|
120
121
|
async check() {
|
|
121
122
|
let res = await this.kernel.bin.exec({ message: `conda list` }, (stream) => {
|
|
123
|
+
// process.stdout.write(stream.raw)
|
|
122
124
|
// console.log("conda list check", { stream })
|
|
123
125
|
})
|
|
124
126
|
|
|
@@ -176,7 +178,6 @@ report_errors: false`)
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
|
-
console.log("> Check", { conda_check, conda })
|
|
180
181
|
this.kernel.bin.installed.conda = conda
|
|
181
182
|
return conda_check.conda && conda_check.mamba && conda_check.sqlite
|
|
182
183
|
//return conda_check.conda && conda_check.mamba
|
|
@@ -250,11 +251,18 @@ report_errors: false`)
|
|
|
250
251
|
// 2. The pinned file says conda-libmamba-solver=24.11.1
|
|
251
252
|
// 3. so after conda update --all, it should be conda-libmamba-solver=24.11.1
|
|
252
253
|
|
|
254
|
+
let mods = this.kernel.bin.mods.filter((m) => {
|
|
255
|
+
return req.dependencies.includes(m.name)
|
|
256
|
+
// return ["zip", "uv", "node", "huggingface", "gxx", "git", "ffmpeg", "caddy"].includes(m.name)
|
|
257
|
+
}).map((m) => {
|
|
258
|
+
return m.mod.cmd()
|
|
259
|
+
}).join(" ")
|
|
260
|
+
console.log("Conda dependencies to install", { mods })
|
|
253
261
|
|
|
254
262
|
let cmds = [
|
|
255
263
|
//"conda clean -y --index-cache",
|
|
256
264
|
"conda clean -y --all",
|
|
257
|
-
|
|
265
|
+
`conda install -y -c conda-forge sqlite=3.47.2 ${mods}`,
|
|
258
266
|
|
|
259
267
|
// `conda config --file ${this.kernel.path('condarc')} --set remote_connect_timeout_secs 20`,
|
|
260
268
|
// `conda config --file ${this.kernel.path('condarc')} --set remote_read_timeout_secs 300`,
|
package/kernel/bin/cuda.js
CHANGED
|
@@ -6,20 +6,12 @@ class Cuda {
|
|
|
6
6
|
"conda clean -y --all",
|
|
7
7
|
"conda install -y cudnn libzlib-wapi -c conda-forge",
|
|
8
8
|
]
|
|
9
|
-
// conda: {
|
|
10
|
-
// name: "base",
|
|
11
|
-
// activate: "minimal"
|
|
12
|
-
// }
|
|
13
9
|
}, ondata)
|
|
14
10
|
await this.kernel.bin.exec({
|
|
15
11
|
message: [
|
|
16
12
|
"conda clean -y --all",
|
|
17
13
|
"conda install -y cuda -c nvidia/label/cuda-12.1.0",
|
|
18
14
|
]
|
|
19
|
-
// conda: {
|
|
20
|
-
// name: "base",
|
|
21
|
-
// activate: "minimal"
|
|
22
|
-
// }
|
|
23
15
|
}, ondata)
|
|
24
16
|
} else {
|
|
25
17
|
await this.kernel.bin.exec({
|
|
@@ -27,20 +19,12 @@ class Cuda {
|
|
|
27
19
|
"conda clean -y --all",
|
|
28
20
|
"conda install -y cudnn -c conda-forge",
|
|
29
21
|
]
|
|
30
|
-
// conda: {
|
|
31
|
-
// name: "base",
|
|
32
|
-
// activate: "minimal"
|
|
33
|
-
// }
|
|
34
22
|
}, ondata)
|
|
35
23
|
await this.kernel.bin.exec({
|
|
36
24
|
message: [
|
|
37
25
|
"conda clean -y --all",
|
|
38
26
|
"conda install -y cuda -c nvidia/label/cuda-12.1.0",
|
|
39
27
|
]
|
|
40
|
-
// conda: {
|
|
41
|
-
// name: "base",
|
|
42
|
-
// activate: "minimal"
|
|
43
|
-
// }
|
|
44
28
|
}, ondata)
|
|
45
29
|
if (this.kernel.platform === "linux") {
|
|
46
30
|
await this.kernel.bin.exec({
|
package/kernel/bin/ffmpeg.js
CHANGED
|
@@ -3,17 +3,15 @@ const fetch = require('cross-fetch')
|
|
|
3
3
|
const { rimraf } = require('rimraf')
|
|
4
4
|
const decompress = require('decompress');
|
|
5
5
|
class Ffmpeg {
|
|
6
|
+
cmd() {
|
|
7
|
+
return "ffmpeg"
|
|
8
|
+
}
|
|
6
9
|
async install(req, ondata) {
|
|
7
10
|
await this.kernel.bin.exec({
|
|
8
11
|
message: [
|
|
9
12
|
"conda clean -y --all",
|
|
10
|
-
|
|
11
|
-
"conda install -y -c conda-forge ffmpeg"
|
|
13
|
+
`conda install -y -c conda-forge ${this.cmd()}`
|
|
12
14
|
]
|
|
13
|
-
// conda: {
|
|
14
|
-
// name: "base",
|
|
15
|
-
// activate: "minimal"
|
|
16
|
-
// }
|
|
17
15
|
}, ondata)
|
|
18
16
|
}
|
|
19
17
|
async installed() {
|