pinokiod 3.41.0 → 3.43.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/browser/index.js +3 -1
- package/kernel/api/cloudflare/index.js +3 -3
- package/kernel/api/index.js +187 -51
- package/kernel/api/loading/index.js +15 -0
- package/kernel/api/process/index.js +7 -0
- package/kernel/api/shell/index.js +0 -2
- package/kernel/bin/browserless.js +22 -0
- package/kernel/bin/caddy.js +36 -4
- package/kernel/bin/index.js +4 -1
- package/kernel/bin/setup.js +38 -5
- package/kernel/connect/backend.js +110 -0
- package/kernel/connect/config.js +171 -0
- package/kernel/connect/index.js +18 -7
- package/kernel/connect/providers/huggingface/index.js +98 -0
- package/kernel/connect/providers/x/index.js +0 -1
- package/kernel/environment.js +91 -19
- package/kernel/git.js +46 -3
- package/kernel/index.js +119 -39
- package/kernel/peer.js +40 -5
- package/kernel/plugin.js +3 -2
- package/kernel/procs.js +27 -20
- package/kernel/prototype.js +30 -16
- package/kernel/router/common.js +1 -1
- package/kernel/router/connector.js +1 -3
- package/kernel/router/index.js +38 -4
- package/kernel/router/localhost_home_router.js +5 -1
- package/kernel/router/localhost_port_router.js +27 -1
- package/kernel/router/localhost_static_router.js +93 -0
- package/kernel/router/localhost_variable_router.js +14 -9
- package/kernel/router/peer_peer_router.js +3 -0
- package/kernel/router/peer_static_router.js +43 -0
- package/kernel/router/peer_variable_router.js +15 -14
- package/kernel/router/processor.js +26 -1
- package/kernel/router/rewriter.js +59 -0
- package/kernel/scripts/git/commit +11 -1
- package/kernel/shell.js +8 -3
- package/kernel/util.js +65 -6
- package/package.json +2 -1
- package/server/index.js +1037 -964
- package/server/public/common.js +382 -1
- package/server/public/fscreator.js +0 -1
- package/server/public/loading.js +17 -0
- package/server/public/notifyinput.js +0 -1
- package/server/public/opener.js +4 -2
- package/server/public/style.css +311 -11
- package/server/socket.js +7 -1
- package/server/views/app.ejs +1747 -351
- package/server/views/columns.ejs +338 -0
- package/server/views/connect/huggingface.ejs +353 -0
- package/server/views/connect/index.ejs +410 -0
- package/server/views/connect/x.ejs +43 -9
- package/server/views/connect.ejs +709 -49
- package/server/views/container.ejs +357 -0
- package/server/views/d.ejs +251 -62
- package/server/views/download.ejs +54 -10
- package/server/views/editor.ejs +11 -0
- package/server/views/explore.ejs +40 -15
- package/server/views/file_explorer.ejs +25 -246
- package/server/views/form.ejs +44 -1
- package/server/views/frame.ejs +39 -1
- package/server/views/github.ejs +48 -11
- package/server/views/help.ejs +48 -7
- package/server/views/index.ejs +119 -58
- package/server/views/index2.ejs +3 -4
- package/server/views/init/index.ejs +651 -197
- package/server/views/install.ejs +1 -1
- package/server/views/mini.ejs +47 -18
- package/server/views/net.ejs +199 -67
- package/server/views/network.ejs +220 -94
- package/server/views/network2.ejs +3 -4
- package/server/views/old_network.ejs +3 -3
- package/server/views/prototype/index.ejs +48 -11
- package/server/views/review.ejs +1005 -0
- package/server/views/rows.ejs +341 -0
- package/server/views/screenshots.ejs +1020 -0
- package/server/views/settings.ejs +160 -23
- package/server/views/setup.ejs +49 -7
- package/server/views/setup_home.ejs +43 -10
- package/server/views/shell.ejs +7 -1
- package/server/views/start.ejs +14 -9
- package/server/views/terminal.ejs +13 -2
- package/server/views/tools.ejs +1015 -0
package/kernel/prototype.js
CHANGED
|
@@ -8,7 +8,6 @@ class Proto {
|
|
|
8
8
|
this.kernel = kernel
|
|
9
9
|
}
|
|
10
10
|
async init() {
|
|
11
|
-
console.log("Proto init")
|
|
12
11
|
this.items = []
|
|
13
12
|
this.kv = {}
|
|
14
13
|
if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
|
|
@@ -48,7 +47,6 @@ class Proto {
|
|
|
48
47
|
})
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
console.log("Proto init done")
|
|
52
50
|
}
|
|
53
51
|
async ai() {
|
|
54
52
|
let ai_path = this.kernel.path("prototype/system/ai/new/static")
|
|
@@ -78,6 +76,10 @@ class Proto {
|
|
|
78
76
|
}
|
|
79
77
|
async create(req, ondata) {
|
|
80
78
|
try {
|
|
79
|
+
if (req.client) {
|
|
80
|
+
this.kernel.client = req.client
|
|
81
|
+
}
|
|
82
|
+
console.log("REQ", JSON.stringify(req, null, 2))
|
|
81
83
|
let projectType = req.params.projectType
|
|
82
84
|
let startType = req.params.cliType || req.params.startType
|
|
83
85
|
|
|
@@ -88,27 +90,39 @@ class Proto {
|
|
|
88
90
|
payload.input = req.params
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
// 1. move mkdir into each launcher
|
|
94
|
+
// 2. run logic
|
|
95
|
+
// 3. add docs
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
let icon_path = path.resolve(payload.cwd, "icon.png")
|
|
95
|
-
await fs.promises.cp(default_icon_path, icon_path)
|
|
97
|
+
// await fs.promises.mkdir(payload.cwd)
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
if (projectType === "blank") {
|
|
100
|
+
return { success: "/p/" + name + "/dev" }
|
|
101
|
+
}
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
// let default_icon_path = path.resolve(__dirname, "../server/public/pinokio-black.png")
|
|
104
|
+
// let icon_path = path.resolve(payload.cwd, "icon.png")
|
|
105
|
+
// await fs.promises.cp(default_icon_path, icon_path)
|
|
101
106
|
|
|
102
|
-
//
|
|
103
|
-
let
|
|
104
|
-
await
|
|
107
|
+
// run the init logic
|
|
108
|
+
let mod_path = this.kernel.path("prototype/system", projectType, startType)
|
|
109
|
+
let mod = await this.kernel.require(mod_path)
|
|
110
|
+
let response = await mod(payload, ondata, this.kernel)
|
|
105
111
|
|
|
106
|
-
// copy
|
|
107
|
-
let
|
|
108
|
-
await fs.promises.cp(
|
|
112
|
+
// // copy readme
|
|
113
|
+
// let readme_path = this.kernel.path("prototype/PINOKIO.md")
|
|
114
|
+
// await fs.promises.cp(readme_path, path.resolve(cwd, name, "PINOKIO.md"))
|
|
115
|
+
//
|
|
116
|
+
// // copy pterm.md
|
|
117
|
+
// let cli_readme_path = this.kernel.path("prototype/PTERM.md")
|
|
118
|
+
// await fs.promises.cp(cli_readme_path, path.resolve(cwd, name, "PTERM.md"))
|
|
109
119
|
|
|
110
120
|
|
|
111
|
-
|
|
121
|
+
if (response) {
|
|
122
|
+
return response
|
|
123
|
+
} else {
|
|
124
|
+
return { success: "/p/" + name + "/dev" }
|
|
125
|
+
}
|
|
112
126
|
} catch (e) {
|
|
113
127
|
console.log("ERROR", e)
|
|
114
128
|
return { error: e.stack }
|
package/kernel/router/common.js
CHANGED
|
@@ -33,7 +33,7 @@ class Common extends Processor {
|
|
|
33
33
|
handler = override_handler
|
|
34
34
|
}
|
|
35
35
|
this.router.config.apps.http.servers.main.routes.push({
|
|
36
|
-
"match": [{ "host": [match] }],
|
|
36
|
+
"match": [{ "host": Array.isArray(match) ? match : [match] }],
|
|
37
37
|
"handle": handler
|
|
38
38
|
})
|
|
39
39
|
this.router.add({ host, dial, match })
|
package/kernel/router/index.js
CHANGED
|
@@ -5,10 +5,12 @@ const Util = require('../util')
|
|
|
5
5
|
const LocalhostHomeRouter = require('./localhost_home_router')
|
|
6
6
|
const LocalhostVariableRouter = require('./localhost_variable_router')
|
|
7
7
|
const LocalhostPortRouter = require('./localhost_port_router')
|
|
8
|
+
const LocalhostStaticRouter = require('./localhost_static_router')
|
|
8
9
|
const PeerHomeRouter = require('./peer_home_router')
|
|
9
10
|
const PeerVariableRouter = require('./peer_variable_router')
|
|
10
11
|
const PeerPortRouter = require('./peer_port_router')
|
|
11
12
|
const PeerPeerRouter = require('./peer_peer_router')
|
|
13
|
+
const PeerStaticRouter = require('./peer_static_router')
|
|
12
14
|
const CustomDomainRouter = require('./custom_domain_router')
|
|
13
15
|
const Environment = require("../environment")
|
|
14
16
|
class Router {
|
|
@@ -21,7 +23,9 @@ class Router {
|
|
|
21
23
|
this.peer_variable_router = new PeerVariableRouter(this)
|
|
22
24
|
this.peer_port_router = new PeerPortRouter(this)
|
|
23
25
|
this.peer_peer_router = new PeerPeerRouter(this)
|
|
26
|
+
this.peer_static_router = new PeerStaticRouter(this)
|
|
24
27
|
this.custom_domain_router = new CustomDomainRouter(this)
|
|
28
|
+
this.localhost_static_router = new LocalhostStaticRouter(this)
|
|
25
29
|
this.default_prefix = "pinokio"
|
|
26
30
|
this.default_suffix = "localhost"
|
|
27
31
|
this.default_match = this.default_prefix + "." + this.default_suffix
|
|
@@ -33,6 +37,7 @@ class Router {
|
|
|
33
37
|
this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
34
38
|
this.local_network_mapping = {}
|
|
35
39
|
this.custom_routers = {}
|
|
40
|
+
this.rewrite_mapping = {}
|
|
36
41
|
}
|
|
37
42
|
async init() {
|
|
38
43
|
// if ~/pinokio/network doesn't exist, clone
|
|
@@ -95,13 +100,24 @@ class Router {
|
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
|
|
98
|
-
let env = await Environment.get(this.kernel.homedir)
|
|
103
|
+
let env = await Environment.get(this.kernel.homedir, this.kernel)
|
|
99
104
|
this.active = false
|
|
100
105
|
if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
|
|
101
106
|
this.active = true
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
|
|
110
|
+
}
|
|
111
|
+
async add_rewrite({ peer, route, match, dial }) {
|
|
112
|
+
if (!this.rewrite_mapping[dial]) {
|
|
113
|
+
this.rewrite_mapping[dial] = {}
|
|
114
|
+
}
|
|
115
|
+
if (!this.rewrite_mapping[dial][route]) {
|
|
116
|
+
this.rewrite_mapping[dial][route] = []
|
|
117
|
+
}
|
|
118
|
+
if (!this.rewrite_mapping[dial][route].includes(match)) {
|
|
119
|
+
this.rewrite_mapping[dial][route].push(match)
|
|
120
|
+
}
|
|
105
121
|
}
|
|
106
122
|
async add({ host, match, dial }) {
|
|
107
123
|
if (!this._mapping[host]) {
|
|
@@ -110,7 +126,13 @@ class Router {
|
|
|
110
126
|
if (!this._mapping[host][dial]) {
|
|
111
127
|
this._mapping[host][dial] = new Set()
|
|
112
128
|
}
|
|
113
|
-
|
|
129
|
+
if (Array.isArray(match)) {
|
|
130
|
+
for(let m of match) {
|
|
131
|
+
this._mapping[host][dial].add(m)
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
this._mapping[host][dial].add(match)
|
|
135
|
+
}
|
|
114
136
|
}
|
|
115
137
|
_info() {
|
|
116
138
|
let mapping = {}
|
|
@@ -194,6 +216,18 @@ class Router {
|
|
|
194
216
|
}
|
|
195
217
|
}
|
|
196
218
|
|
|
219
|
+
async static() {
|
|
220
|
+
this.localhost_static_router.handle()
|
|
221
|
+
for(let host in this.kernel.peer.info) {
|
|
222
|
+
let info = this.kernel.peer.info[host]
|
|
223
|
+
if (info.rewrite_mapping) {
|
|
224
|
+
for(let name in info.rewrite_mapping) {
|
|
225
|
+
this.peer_static_router.handle(info.rewrite_mapping[name])
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
this.mapping = this._mapping
|
|
230
|
+
}
|
|
197
231
|
|
|
198
232
|
// set local config
|
|
199
233
|
async local() {
|
|
@@ -208,7 +242,7 @@ class Router {
|
|
|
208
242
|
for(let host in this.kernel.peer.info) {
|
|
209
243
|
let peer = this.kernel.peer.info[host]
|
|
210
244
|
if (peer.host === this.kernel.peer.host) {
|
|
211
|
-
this.peer_home_router.handle(peer)
|
|
245
|
+
// this.peer_home_router.handle(peer)
|
|
212
246
|
this.peer_variable_router.handle(peer)
|
|
213
247
|
this.peer_port_router.handle(peer)
|
|
214
248
|
}
|
|
@@ -274,7 +308,7 @@ class Router {
|
|
|
274
308
|
// console.log("Caddy Response", { response })
|
|
275
309
|
this.old_config = this.config
|
|
276
310
|
} catch (e) {
|
|
277
|
-
console.log("Caddy Request Failed", e
|
|
311
|
+
console.log("Caddy Request Failed", e)
|
|
278
312
|
}
|
|
279
313
|
}
|
|
280
314
|
}
|
|
@@ -3,7 +3,11 @@ class LocalhostHomeRouter {
|
|
|
3
3
|
this.router = router
|
|
4
4
|
}
|
|
5
5
|
handle () {
|
|
6
|
-
this.router.add({
|
|
6
|
+
this.router.add({
|
|
7
|
+
host: this.router.kernel.peer.host,
|
|
8
|
+
dial: this.router.default_host + ":" + this.router.default_port,
|
|
9
|
+
match: this.router.default_match
|
|
10
|
+
})
|
|
7
11
|
this.router.config = {
|
|
8
12
|
"apps": {
|
|
9
13
|
"tls": {
|
|
@@ -5,8 +5,34 @@ class LocalhostPortRouter {
|
|
|
5
5
|
this.common = new Common(router)
|
|
6
6
|
}
|
|
7
7
|
handle (proc) {
|
|
8
|
+
let name_match
|
|
9
|
+
for(let api_name in this.router.kernel.pinokio_configs) {
|
|
10
|
+
let config = this.router.kernel.pinokio_configs[api_name]
|
|
11
|
+
if (config.dns) {
|
|
12
|
+
let root_routes = config.dns["@"]
|
|
13
|
+
if (root_routes && root_routes.length > 0) {
|
|
14
|
+
for(let route of root_routes) {
|
|
15
|
+
if (route === ":" + proc.port) {
|
|
16
|
+
// matched
|
|
17
|
+
name_match = api_name
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let match
|
|
26
|
+
if (name_match) {
|
|
27
|
+
match = [
|
|
28
|
+
`${name_match}.localhost`,
|
|
29
|
+
`${proc.port}.localhost`
|
|
30
|
+
]
|
|
31
|
+
} else {
|
|
32
|
+
match = `${proc.port}.localhost`
|
|
33
|
+
}
|
|
8
34
|
this.common.handle({
|
|
9
|
-
match
|
|
35
|
+
match,
|
|
10
36
|
dial: proc.ip,
|
|
11
37
|
host: this.router.kernel.peer.host,
|
|
12
38
|
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const Common = require('./common')
|
|
3
|
+
const Rewriter = require('./rewriter')
|
|
4
|
+
const Connector = require('./connector')
|
|
5
|
+
const Processor = require('./processor')
|
|
6
|
+
class LocalhostStaticRouter extends Processor {
|
|
7
|
+
constructor(router) {
|
|
8
|
+
super()
|
|
9
|
+
this.router = router
|
|
10
|
+
this.common = new Common(router)
|
|
11
|
+
this.connector = new Connector(router)
|
|
12
|
+
this.rewriter = new Rewriter(router)
|
|
13
|
+
}
|
|
14
|
+
handle () {
|
|
15
|
+
let configs = []
|
|
16
|
+
for(let api_name in this.router.kernel.pinokio_configs) {
|
|
17
|
+
let config = this.router.kernel.pinokio_configs[api_name]
|
|
18
|
+
if (config.dns) {
|
|
19
|
+
configs.push({
|
|
20
|
+
api_name,
|
|
21
|
+
config
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for(let { api_name, config } of configs) {
|
|
26
|
+
for(let domain in config.dns) {
|
|
27
|
+
let localhost_match
|
|
28
|
+
let peer_match
|
|
29
|
+
if (domain === "@") {
|
|
30
|
+
localhost_match = `${api_name}.localhost`.toLowerCase()
|
|
31
|
+
peer_match = `${api_name}.${this.router.kernel.peer.name}.localhost`.toLowerCase()
|
|
32
|
+
} else {
|
|
33
|
+
localhost_match = `${domain}.${api_name}.localhost`.toLowerCase()
|
|
34
|
+
peer_match = `${domain}.${api_name}.${this.router.kernel.peer.name}.localhost`.toLowerCase()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let routes = config.dns[domain]
|
|
38
|
+
for(let route of routes) {
|
|
39
|
+
if (!route.startsWith("$") && !route.startsWith(":")) {
|
|
40
|
+
let chunks = route.split("/")
|
|
41
|
+
let local_dial = `${this.router.default_host}:${this.router.default_port}`
|
|
42
|
+
let peer_dial = `${this.router.kernel.peer.host}:${this.router.default_port}`
|
|
43
|
+
let rewrite = `/asset/api/${api_name}`
|
|
44
|
+
this.rewriter.handle({
|
|
45
|
+
route: rewrite,
|
|
46
|
+
match: [localhost_match],
|
|
47
|
+
dial: local_dial,
|
|
48
|
+
})
|
|
49
|
+
this.rewriter.handle({
|
|
50
|
+
route: rewrite,
|
|
51
|
+
match: [peer_match],
|
|
52
|
+
dial: peer_dial,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// this.router.add_rewrite({ route: new_path, match, peer, dial })
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
name: web
|
|
60
|
+
internal_router: ["127.0.0.1:42000/asset/api/web", "https://web.localhost"]
|
|
61
|
+
external_ip: ["192.168.1.49:42000/asset/api/web"]
|
|
62
|
+
external_router ["https://web.x.localhost"]
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
this.router.rewrite_mapping[api_name] = {
|
|
68
|
+
name: api_name,
|
|
69
|
+
internal_router: [
|
|
70
|
+
`${local_dial}${rewrite}`,
|
|
71
|
+
localhost_match
|
|
72
|
+
],
|
|
73
|
+
external_ip: `${peer_dial}${rewrite}`,
|
|
74
|
+
external_router: [
|
|
75
|
+
peer_match
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
// this.connector.handle({
|
|
79
|
+
// match: peer_match,
|
|
80
|
+
// connector: {
|
|
81
|
+
// host: this.router.kernel.peer.host,
|
|
82
|
+
// port: this.router.default_port,
|
|
83
|
+
// },
|
|
84
|
+
// dial,
|
|
85
|
+
// host: this.router.kernel.peer.host,
|
|
86
|
+
// })
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
module.exports = LocalhostStaticRouter
|
|
@@ -14,20 +14,25 @@ class LocalhostVariableRouter extends Processor {
|
|
|
14
14
|
let val = local_variables_for_script[key]
|
|
15
15
|
if (typeof val === "string" && val.startsWith("http")) {
|
|
16
16
|
let dial = val.replace(/https?:\/\//, '')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (dial.endsWith("/")) {
|
|
18
|
+
dial = dial.slice(0, -1)
|
|
19
|
+
}
|
|
20
|
+
let api_name = this.api_name(this.router.kernel.platform, this.router.kernel.homedir, script_path)
|
|
21
|
+
let domain = this.domain(api_name, key)
|
|
22
|
+
if (domain) {
|
|
23
|
+
if (this.has_port(dial)) {
|
|
24
|
+
let match
|
|
25
|
+
if (domain === "@") {
|
|
26
|
+
match = `${api_name}.localhost`.toLowerCase()
|
|
27
|
+
} else {
|
|
28
|
+
match = `${domain}.${api_name}.localhost`.toLowerCase()
|
|
29
|
+
}
|
|
20
30
|
this.common.handle({
|
|
21
|
-
match
|
|
31
|
+
match,
|
|
22
32
|
dial,
|
|
23
33
|
host: this.router.kernel.peer.host,
|
|
24
34
|
})
|
|
25
35
|
}
|
|
26
|
-
this.common.handle({
|
|
27
|
-
match: `${key}.${name}.localhost`.toLowerCase(),
|
|
28
|
-
dial,
|
|
29
|
-
host: this.router.kernel.peer.host,
|
|
30
|
-
})
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -6,6 +6,9 @@ class PeerPeerRouter {
|
|
|
6
6
|
}
|
|
7
7
|
handle(peer) {
|
|
8
8
|
for(let dial in peer.router) {
|
|
9
|
+
if (dial.endsWith("/")) {
|
|
10
|
+
dial = dial.slice(0, -1)
|
|
11
|
+
}
|
|
9
12
|
let matches = peer.router[dial]
|
|
10
13
|
let exposed_matches = matches.filter((m) => {
|
|
11
14
|
return m.endsWith(`${peer.name}.localhost`)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const Common = require('./common')
|
|
3
|
+
const Rewriter = require('./rewriter')
|
|
4
|
+
const Connector = require('./connector')
|
|
5
|
+
const Processor = require('./processor')
|
|
6
|
+
class PeerStaticRouter extends Processor {
|
|
7
|
+
constructor(router) {
|
|
8
|
+
super()
|
|
9
|
+
this.router = router
|
|
10
|
+
this.common = new Common(router)
|
|
11
|
+
this.connector = new Connector(router)
|
|
12
|
+
this.rewriter = new Rewriter(router)
|
|
13
|
+
}
|
|
14
|
+
handle (rewrite_mapping) {
|
|
15
|
+
/*
|
|
16
|
+
rewrite_mapping: {
|
|
17
|
+
name: "test",
|
|
18
|
+
internal_router: [
|
|
19
|
+
"127.0.0.1:42000/asset/api/test",
|
|
20
|
+
"test.localhost"
|
|
21
|
+
],
|
|
22
|
+
external_ip: "192.168.1.49:42000/asset/api/test",
|
|
23
|
+
external_router: [
|
|
24
|
+
"test.x.localhost"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
connect
|
|
29
|
+
dial: 192.168.1.49:42000
|
|
30
|
+
rewrite: /asset/api/test
|
|
31
|
+
match: test.x.localhost
|
|
32
|
+
*/
|
|
33
|
+
let url = new URL("http://" + rewrite_mapping.external_ip)
|
|
34
|
+
let dial = url.host
|
|
35
|
+
let rewrite = url.pathname
|
|
36
|
+
this.rewriter.handle({
|
|
37
|
+
route: url.pathname,
|
|
38
|
+
match: rewrite_mapping.external_router,
|
|
39
|
+
dial: url.host,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
module.exports = PeerStaticRouter
|
|
@@ -14,12 +14,22 @@ class PeerVariableRouter extends Processor {
|
|
|
14
14
|
let val = local_variables[key]
|
|
15
15
|
if (typeof val === "string" && val.startsWith("http")) {
|
|
16
16
|
let dial = val.replace(/https?:\/\//, '')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (dial.endsWith("/")) {
|
|
18
|
+
dial = dial.slice(0, -1)
|
|
19
|
+
}
|
|
20
|
+
let api_name = this.api_name(peer.platform, peer.home, script_path)
|
|
21
|
+
let domain = this.domain(api_name, key)
|
|
22
|
+
if (domain) {
|
|
23
|
+
if (this.has_port(dial)) {
|
|
24
|
+
let match
|
|
25
|
+
if (domain === "@") {
|
|
26
|
+
match = `${api_name}.${peer.name}.localhost`.toLowerCase()
|
|
27
|
+
} else {
|
|
28
|
+
match = `${domain}.${api_name}.${peer.name}.localhost`.toLowerCase()
|
|
29
|
+
}
|
|
30
|
+
let parsed_dial = this.parse_ip(dial)
|
|
21
31
|
this.connector.handle({
|
|
22
|
-
match
|
|
32
|
+
match,
|
|
23
33
|
connector: {
|
|
24
34
|
host: peer.host,
|
|
25
35
|
port: parsed_dial.port
|
|
@@ -28,15 +38,6 @@ class PeerVariableRouter extends Processor {
|
|
|
28
38
|
host: peer.host,
|
|
29
39
|
})
|
|
30
40
|
}
|
|
31
|
-
this.connector.handle({
|
|
32
|
-
match:`${key}.${name}.${peer.name}.localhost`.toLowerCase(),
|
|
33
|
-
connector: {
|
|
34
|
-
host: peer.host,
|
|
35
|
-
port: parsed_dial.port
|
|
36
|
-
},
|
|
37
|
-
dial,
|
|
38
|
-
host: peer.host,
|
|
39
|
-
})
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -23,9 +23,34 @@ class Processor {
|
|
|
23
23
|
}
|
|
24
24
|
parse_ip(str) {
|
|
25
25
|
let chunks = str.split(":")
|
|
26
|
-
let port = chunks[chunks.length-1]
|
|
26
|
+
let port = chunks[chunks.length-1].replace(/[^0-9]/g, '')
|
|
27
27
|
let host = chunks.slice(0, chunks.length-1).join(":")
|
|
28
28
|
return { host, port }
|
|
29
29
|
}
|
|
30
|
+
domain (api_name, key) {
|
|
31
|
+
let config = this.router.kernel.pinokio_configs[api_name]
|
|
32
|
+
let dns = config.dns
|
|
33
|
+
for(let domain in dns) {
|
|
34
|
+
let routes = dns[domain]
|
|
35
|
+
for(let route of routes) {
|
|
36
|
+
// $local.url@start ==> start.js/start.json 'url' local variable
|
|
37
|
+
if (route.startsWith("$")) {
|
|
38
|
+
let chunks = route.split("@")
|
|
39
|
+
if (chunks.length === 2) {
|
|
40
|
+
let [memory, filepath] = chunks
|
|
41
|
+
if (memory.startsWith("$local.")) {
|
|
42
|
+
let varname = memory.replace("$local.", "")
|
|
43
|
+
if (key === varname) {
|
|
44
|
+
return domain
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
// file path
|
|
50
|
+
return domain
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
30
55
|
}
|
|
31
56
|
module.exports = Processor
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const Processor = require('./processor')
|
|
2
|
+
class Rewriter extends Processor {
|
|
3
|
+
constructor (router) {
|
|
4
|
+
super()
|
|
5
|
+
this.router = router
|
|
6
|
+
}
|
|
7
|
+
handle({ match, dial, route }) {
|
|
8
|
+
//let rewrite = `${route}/{path}`
|
|
9
|
+
//let rewrite = `${route}{http.request.uri}`
|
|
10
|
+
/*
|
|
11
|
+
let handler = [{
|
|
12
|
+
"handler": "rewrite",
|
|
13
|
+
"uri": rewrite,
|
|
14
|
+
}, {
|
|
15
|
+
"handler": "reverse_proxy",
|
|
16
|
+
"upstreams": [{ "dial": dial }],
|
|
17
|
+
"headers": {
|
|
18
|
+
"request": {
|
|
19
|
+
"set": {
|
|
20
|
+
"X-Forwarded-Proto": ["https"],
|
|
21
|
+
"X-Forwarded-Host": ["{http.request.host}"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"response": {
|
|
25
|
+
"set": {
|
|
26
|
+
"Access-Control-Allow-Origin": ["*"],
|
|
27
|
+
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
28
|
+
"Access-Control-Allow-Headers": ["*"],
|
|
29
|
+
"Vary": ["Origin"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}]
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// stript the leading /asset/ => (/asset/api/test => /api/test)
|
|
37
|
+
const asset_path = this.router.kernel.path(route.replace(/\/asset\//, ''))
|
|
38
|
+
let handler = [{
|
|
39
|
+
"handler": "file_server",
|
|
40
|
+
"root": asset_path,
|
|
41
|
+
"browse": { },
|
|
42
|
+
"index_names": ["index.html"]
|
|
43
|
+
}]
|
|
44
|
+
|
|
45
|
+
// if the dial port has been overridden by router.custom_routers, use that instead
|
|
46
|
+
let parsed_dial = this.parse_ip(dial)
|
|
47
|
+
let override_handler = this.router.custom_routers[String(parsed_dial.port)]
|
|
48
|
+
if (override_handler) {
|
|
49
|
+
handler = override_handler
|
|
50
|
+
}
|
|
51
|
+
this.router.config.apps.http.servers.main.routes.push({
|
|
52
|
+
"match": [{
|
|
53
|
+
"host": match ,
|
|
54
|
+
}],
|
|
55
|
+
"handle": handler
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
module.exports = Rewriter
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"run": [{
|
|
3
|
+
"when": "{{args.message && args.message.length > 0}}",
|
|
4
|
+
"method": "jump",
|
|
5
|
+
"params": {
|
|
6
|
+
"id": "commit",
|
|
7
|
+
"params": {
|
|
8
|
+
"commit": "{{args.message}}"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}, {
|
|
3
12
|
"method": "input",
|
|
4
13
|
"params": {
|
|
5
14
|
"form": [{
|
|
@@ -8,13 +17,14 @@
|
|
|
8
17
|
}]
|
|
9
18
|
}
|
|
10
19
|
}, {
|
|
20
|
+
"id": "commit",
|
|
11
21
|
"method": "shell.run",
|
|
12
22
|
"params": {
|
|
13
23
|
"chain": true,
|
|
14
24
|
"path": "{{args.cwd}}",
|
|
15
25
|
"message": [
|
|
16
26
|
"git add .",
|
|
17
|
-
"git commit -am {{input.commit}}"
|
|
27
|
+
"git commit -am \"{{input.commit}}\""
|
|
18
28
|
]
|
|
19
29
|
}
|
|
20
30
|
}]
|
package/kernel/shell.js
CHANGED
|
@@ -109,9 +109,14 @@ class Shell {
|
|
|
109
109
|
// this.env.npm_config_globalconfig = this.kernel.path("global_npmrc")
|
|
110
110
|
|
|
111
111
|
// First override this.env with system env
|
|
112
|
-
let system_env = await Environment.get(this.kernel.homedir)
|
|
112
|
+
let system_env = await Environment.get(this.kernel.homedir, this.kernel)
|
|
113
113
|
this.env = Object.assign(this.env, system_env)
|
|
114
114
|
|
|
115
|
+
let hf_keys = await this.kernel.connect.keys("huggingface")
|
|
116
|
+
if (hf_keys && hf_keys.access_token) {
|
|
117
|
+
this.env.HF_TOKEN = hf_keys.access_token
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
// if the shell is running from a script file, the params.$parent will include the path to the parent script
|
|
116
121
|
// this means we need to apply app environment as well
|
|
117
122
|
if (params.$parent) {
|
|
@@ -123,10 +128,10 @@ class Shell {
|
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
// initialize folders
|
|
126
|
-
await Environment.init_folders(api_path)
|
|
131
|
+
await Environment.init_folders(api_path, this.kernel)
|
|
127
132
|
|
|
128
133
|
// apply app env to this.env
|
|
129
|
-
let app_env = await Environment.get(api_path)
|
|
134
|
+
let app_env = await Environment.get(api_path, this.kernel)
|
|
130
135
|
this.env = Object.assign(this.env, app_env)
|
|
131
136
|
}
|
|
132
137
|
let PATH_KEY;
|