pinokiod 2.15.19 → 2.15.21
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/fs/index.js +18 -3
- package/kernel/api/index.js +2 -6
- package/kernel/api/json/index.js +112 -0
- package/kernel/api/local/index.js +0 -2
- package/kernel/api/rm/index.js +32 -5
- package/kernel/api/set/index.js +63 -38
- package/kernel/bin/index.js +0 -4
- package/kernel/bin/uv.js +20 -0
- package/kernel/index.js +2 -1
- package/kernel/shell.js +6 -6
- package/kernel/shells.js +9 -1
- package/package.json +2 -2
- package/server/index.js +314 -164
- package/server/public/style.css +55 -2
- package/server/public/term-dark.png +0 -0
- package/server/public/term-white.png +0 -0
- package/server/public/term.png +0 -0
- package/server/views/env_editor.ejs +31 -7
- package/server/views/fullscreen_editor.ejs +9 -0
- package/server/views/index.ejs +30 -1
- package/server/views/pre.ejs +38 -4
- package/server/views/proxy.ejs +9 -3
- package/server/views/required_env_editor.ejs +275 -0
- package/server/views/settings.ejs +0 -2
- package/server/views/share_editor.ejs +0 -2
- package/server/views/{disposable.ejs → task.ejs} +19 -15
package/server/index.js
CHANGED
|
@@ -158,8 +158,15 @@ class Server {
|
|
|
158
158
|
name = x.name
|
|
159
159
|
description = ""
|
|
160
160
|
}
|
|
161
|
+
let browser_url
|
|
162
|
+
if (x.run) {
|
|
163
|
+
browser_url = "/env/api/" + x.name
|
|
164
|
+
} else {
|
|
165
|
+
browser_url = "/pinokio/browser/" + x.name
|
|
166
|
+
}
|
|
161
167
|
return {
|
|
162
168
|
icon,
|
|
169
|
+
run: x.run,
|
|
163
170
|
menu: x.menu,
|
|
164
171
|
shortcuts: x.shortcuts,
|
|
165
172
|
index: x.index,
|
|
@@ -170,11 +177,11 @@ class Server {
|
|
|
170
177
|
//description: x.path,
|
|
171
178
|
description,
|
|
172
179
|
url: p + "/" + x.name,
|
|
173
|
-
browser_url
|
|
180
|
+
browser_url,
|
|
174
181
|
}
|
|
175
182
|
})
|
|
176
183
|
}
|
|
177
|
-
async init_env(env_dir_path) {
|
|
184
|
+
async init_env(env_dir_path, options) {
|
|
178
185
|
let current = this.kernel.path(env_dir_path, "ENVIRONMENT")
|
|
179
186
|
// if environment.json doesn't exist,
|
|
180
187
|
let exists = await this.exists(current)
|
|
@@ -187,12 +194,19 @@ class Server {
|
|
|
187
194
|
// if _ENVIRONMENT exists,
|
|
188
195
|
let _environment = this.kernel.path(env_dir_path, "_ENVIRONMENT")
|
|
189
196
|
let _exists = await this.exists(_environment)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
if (options && options.no_inherit) {
|
|
198
|
+
if (_exists) {
|
|
199
|
+
let _environmentStr = await fs.promises.readFile(_environment, "utf8")
|
|
200
|
+
await fs.promises.writeFile(current, _environmentStr)
|
|
201
|
+
}
|
|
194
202
|
} else {
|
|
195
|
-
await
|
|
203
|
+
let content = await Environment.ENV("app", this.kernel.homedir)
|
|
204
|
+
if (_exists) {
|
|
205
|
+
let _environmentStr = await fs.promises.readFile(_environment, "utf8")
|
|
206
|
+
await fs.promises.writeFile(current, _environmentStr + "\n\n\n" + content)
|
|
207
|
+
} else {
|
|
208
|
+
await fs.promises.writeFile(current, content)
|
|
209
|
+
}
|
|
196
210
|
}
|
|
197
211
|
}
|
|
198
212
|
}
|
|
@@ -201,6 +215,34 @@ class Server {
|
|
|
201
215
|
let app_path = this.kernel.path("api", name, "pinokio.js")
|
|
202
216
|
let rawpath = "/api/" + name
|
|
203
217
|
let config = (await this.kernel.loader.load(app_path)).resolved
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
// let requires_instantiation = false
|
|
222
|
+
// console.log("## CONFIG", config)
|
|
223
|
+
// if (config && config.pre) {
|
|
224
|
+
// let env = await Environment.get2(app_path, this.kernel)
|
|
225
|
+
// for(let item of config.pre) {
|
|
226
|
+
// console.log("ITEM" , item)
|
|
227
|
+
// if (item.env) {
|
|
228
|
+
// if (env[item.env]) {
|
|
229
|
+
//
|
|
230
|
+
// } else {
|
|
231
|
+
// requires_instantiation = true
|
|
232
|
+
// break;
|
|
233
|
+
// }
|
|
234
|
+
// }
|
|
235
|
+
// }
|
|
236
|
+
// }
|
|
237
|
+
// console.log({ requires_instantiation })
|
|
238
|
+
// if (requires_instantiation) {
|
|
239
|
+
// // redirect to pre
|
|
240
|
+
// res.redirect("/required_env/api/" + name)
|
|
241
|
+
// return
|
|
242
|
+
// }
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
204
246
|
if (config && config.menu) {
|
|
205
247
|
if (typeof config.menu === "function") {
|
|
206
248
|
if (config.menu.constructor.name === "AsyncFunction") {
|
|
@@ -453,6 +495,8 @@ class Server {
|
|
|
453
495
|
name: "playwright"
|
|
454
496
|
}, {
|
|
455
497
|
name: "huggingface"
|
|
498
|
+
}, {
|
|
499
|
+
name: "uv"
|
|
456
500
|
}])
|
|
457
501
|
|
|
458
502
|
let requirements_pending = !this.kernel.bin.installed_initialized
|
|
@@ -691,6 +735,7 @@ class Server {
|
|
|
691
735
|
// template = "editor"
|
|
692
736
|
// }
|
|
693
737
|
// }
|
|
738
|
+
|
|
694
739
|
|
|
695
740
|
let requirements = [{
|
|
696
741
|
name: "conda",
|
|
@@ -730,6 +775,8 @@ class Server {
|
|
|
730
775
|
name: "playwright"
|
|
731
776
|
}, {
|
|
732
777
|
name: "huggingface"
|
|
778
|
+
}, {
|
|
779
|
+
name: "uv"
|
|
733
780
|
}])
|
|
734
781
|
// if (platform === "linux") {
|
|
735
782
|
// requirements.push({
|
|
@@ -845,42 +892,90 @@ class Server {
|
|
|
845
892
|
edu.searchParams.set("mode", "source")
|
|
846
893
|
let editorUrl = edu.pathname + edu.search
|
|
847
894
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
requirements_pending,
|
|
875
|
-
install_required,
|
|
876
|
-
//current: encodeURIComponent(req.originalUrl),
|
|
877
|
-
current: req.originalUrl,
|
|
878
|
-
editorUrl,
|
|
879
|
-
execUrl: "~" + req.originalUrl.replace(/^\/_api/, "\/api"),
|
|
880
|
-
proxies: this.kernel.api.proxies[filepath],
|
|
895
|
+
let referer = req.get("Referer")
|
|
896
|
+
console.log({ referer })
|
|
897
|
+
|
|
898
|
+
let prev = null
|
|
899
|
+
if (/\/env\/api\/.+/.test(new URL(referer).pathname)) {
|
|
900
|
+
prev = referer
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
let requires_instantiation = false
|
|
905
|
+
console.log("resolved", resolved)
|
|
906
|
+
let pre_items = []
|
|
907
|
+
if (resolved && resolved.pre) {
|
|
908
|
+
let env = await Environment.get2(filepath, this.kernel)
|
|
909
|
+
console.log("_________ENV", env)
|
|
910
|
+
for(let item of resolved.pre) {
|
|
911
|
+
console.log("ITEM" , item)
|
|
912
|
+
if (item.env) {
|
|
913
|
+
if (env[item.env]) {
|
|
914
|
+
item.val = env[item.env]
|
|
915
|
+
} else {
|
|
916
|
+
requires_instantiation = true
|
|
917
|
+
}
|
|
918
|
+
pre_items.push(item)
|
|
919
|
+
}
|
|
920
|
+
}
|
|
881
921
|
}
|
|
922
|
+
console.log({ requires_instantiation, pre_items })
|
|
923
|
+
if (requires_instantiation) {
|
|
924
|
+
let p = Util.api_path(filepath, this.kernel)
|
|
925
|
+
res.render("required_env_editor", {
|
|
926
|
+
agent: this.agent,
|
|
927
|
+
theme: this.theme,
|
|
928
|
+
filename,
|
|
929
|
+
filepath: p,
|
|
930
|
+
items: pre_items
|
|
931
|
+
})
|
|
932
|
+
} else {
|
|
933
|
+
const result = {
|
|
934
|
+
prev,
|
|
935
|
+
error,
|
|
936
|
+
memory: mem,
|
|
937
|
+
// memory: mem,
|
|
938
|
+
logo: this.logo,
|
|
939
|
+
theme: this.theme,
|
|
940
|
+
//run: (req.query && req.query.run ? true : false),
|
|
941
|
+
//run: true, // run mode by default
|
|
942
|
+
run: (req.query && req.query.mode === "source" ? false : true),
|
|
943
|
+
stop: (req.query && req.query.stop ? true : false),
|
|
944
|
+
pinokioPath,
|
|
945
|
+
runnable,
|
|
946
|
+
agent: this.agent,
|
|
947
|
+
rawpath,
|
|
948
|
+
gitRemote,
|
|
949
|
+
filename,
|
|
950
|
+
filepath,
|
|
951
|
+
encodedFilePath: encodeURIComponent(filepath),
|
|
952
|
+
schemaPath,
|
|
953
|
+
uri,
|
|
954
|
+
mod,
|
|
955
|
+
json,
|
|
956
|
+
js,
|
|
957
|
+
content,
|
|
958
|
+
paths,
|
|
959
|
+
requirements,
|
|
960
|
+
requirements_pending,
|
|
961
|
+
install_required,
|
|
962
|
+
//current: encodeURIComponent(req.originalUrl),
|
|
963
|
+
current: req.originalUrl,
|
|
964
|
+
editorUrl,
|
|
965
|
+
execUrl: "~" + req.originalUrl.replace(/^\/_api/, "\/api"),
|
|
966
|
+
proxies: this.kernel.api.proxies[filepath],
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
console.log({ result })
|
|
970
|
+
|
|
971
|
+
res.render(template, result)
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
882
978
|
|
|
883
|
-
res.render(template, result)
|
|
884
979
|
} else {
|
|
885
980
|
res.render("frame", {
|
|
886
981
|
logo: this.logo,
|
|
@@ -1055,19 +1150,22 @@ class Server {
|
|
|
1055
1150
|
error = `Please update Pinokio to the latest version (current script version: ${config.version}, supported: ${this.kernel.schema}`
|
|
1056
1151
|
}
|
|
1057
1152
|
}
|
|
1058
|
-
if (config.
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1153
|
+
// if (config.run) {
|
|
1154
|
+
// items[i].run = config.run
|
|
1155
|
+
// }
|
|
1156
|
+
// if (config.menu) {
|
|
1157
|
+
// if (typeof config.menu === "function") {
|
|
1158
|
+
// if (config.menu.constructor.name === "AsyncFunction") {
|
|
1159
|
+
// config.menu = await config.menu(this.kernel, this.kernel.info)
|
|
1160
|
+
// } else {
|
|
1161
|
+
// config.menu = config.menu(this.kernel, this.kernel.info)
|
|
1162
|
+
// }
|
|
1163
|
+
// }
|
|
1164
|
+
//
|
|
1165
|
+
// await this.renderMenu(uri, item.name, config, pathComponents)
|
|
1166
|
+
//
|
|
1167
|
+
// items[i].menu = config.menu
|
|
1168
|
+
// }
|
|
1071
1169
|
|
|
1072
1170
|
if (config.shortcuts) {
|
|
1073
1171
|
if (typeof config.shortcuts === "function") {
|
|
@@ -1087,6 +1185,11 @@ class Server {
|
|
|
1087
1185
|
continue
|
|
1088
1186
|
}
|
|
1089
1187
|
|
|
1188
|
+
// // if there's a run clause, do not display on the home page
|
|
1189
|
+
// if (config && config.run && Array.isArray(config.run)) {
|
|
1190
|
+
// continue
|
|
1191
|
+
// }
|
|
1192
|
+
|
|
1090
1193
|
|
|
1091
1194
|
// check if there is a running process with this folder name
|
|
1092
1195
|
let runningApps = new Set()
|
|
@@ -1123,10 +1226,63 @@ class Server {
|
|
|
1123
1226
|
|
|
1124
1227
|
// check running for each
|
|
1125
1228
|
// running_items
|
|
1229
|
+
items = items.map((x) => {
|
|
1230
|
+
//let name = (x.name.startsWith("0x") ? Buffer.from(x.name.slice(2), "hex").toString() : x.name)
|
|
1231
|
+
let name
|
|
1232
|
+
let description
|
|
1233
|
+
let icon
|
|
1234
|
+
let uri
|
|
1235
|
+
if (meta) {
|
|
1236
|
+
let m = meta[x.name]
|
|
1237
|
+
name = (m && m.title ? m.title : x.name)
|
|
1238
|
+
description = (m && m.description ? m.description : "")
|
|
1239
|
+
if (m && m.icon) {
|
|
1240
|
+
icon = m.icon
|
|
1241
|
+
} else {
|
|
1242
|
+
icon = null
|
|
1243
|
+
}
|
|
1244
|
+
uri = x.name
|
|
1245
|
+
} else {
|
|
1246
|
+
if (x.isDirectory()) {
|
|
1247
|
+
icon = "fa-solid fa-folder"
|
|
1248
|
+
} else {
|
|
1249
|
+
icon = "fa-regular fa-file"
|
|
1250
|
+
}
|
|
1251
|
+
name = x.name
|
|
1252
|
+
description = ""
|
|
1253
|
+
}
|
|
1254
|
+
return {
|
|
1255
|
+
icon,
|
|
1256
|
+
menu: x.menu,
|
|
1257
|
+
run: x.run,
|
|
1258
|
+
shortcuts: x.shortcuts,
|
|
1259
|
+
//icon: (x.isDirectory() ? "fa-solid fa-folder" : "fa-regular fa-file"),
|
|
1260
|
+
name,
|
|
1261
|
+
uri,
|
|
1262
|
+
//description: x.path,
|
|
1263
|
+
description,
|
|
1264
|
+
//url: p + "/" + x.name,
|
|
1265
|
+
url: _p + "/" + x.name,
|
|
1266
|
+
// url: `${U}/${x.name}`,
|
|
1267
|
+
browser_url: "/pinokio/browser/" + x.name
|
|
1268
|
+
}
|
|
1269
|
+
})
|
|
1126
1270
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1271
|
+
// if (req.query && req.query.mode === "task") {
|
|
1272
|
+
// running = running.filter((x) => {
|
|
1273
|
+
// return x.run && Array.isArray(x.run)
|
|
1274
|
+
// })
|
|
1275
|
+
// notRunning = notRunning.filter((x) => {
|
|
1276
|
+
// return x.run && Array.isArray(x.run)
|
|
1277
|
+
// })
|
|
1278
|
+
// } else {
|
|
1279
|
+
// running = running.filter((x) => {
|
|
1280
|
+
// return !(x.run && Array.isArray(x.run))
|
|
1281
|
+
// })
|
|
1282
|
+
// notRunning = notRunning.filter((x) => {
|
|
1283
|
+
// return !(x.run && Array.isArray(x.run))
|
|
1284
|
+
// })
|
|
1285
|
+
// }
|
|
1130
1286
|
|
|
1131
1287
|
|
|
1132
1288
|
// let U = `${_p}/${pathComponents.join("/")}`
|
|
@@ -1146,7 +1302,6 @@ class Server {
|
|
|
1146
1302
|
if (this.cloudflare_pub) {
|
|
1147
1303
|
qr_cloudflare = await QRCode.toDataURL(this.cloudflare_pub)
|
|
1148
1304
|
}
|
|
1149
|
-
console.log("****************", { items })
|
|
1150
1305
|
|
|
1151
1306
|
res.render("index", {
|
|
1152
1307
|
home_url: `http://localhost:${this.port}`,
|
|
@@ -1172,50 +1327,9 @@ class Server {
|
|
|
1172
1327
|
notRunning,
|
|
1173
1328
|
readme,
|
|
1174
1329
|
filepath,
|
|
1175
|
-
|
|
1176
|
-
//
|
|
1177
|
-
|
|
1178
|
-
// })
|
|
1179
|
-
.map((x) => {
|
|
1180
|
-
//let name = (x.name.startsWith("0x") ? Buffer.from(x.name.slice(2), "hex").toString() : x.name)
|
|
1181
|
-
let name
|
|
1182
|
-
let description
|
|
1183
|
-
let icon
|
|
1184
|
-
let uri
|
|
1185
|
-
if (meta) {
|
|
1186
|
-
let m = meta[x.name]
|
|
1187
|
-
name = (m && m.title ? m.title : x.name)
|
|
1188
|
-
description = (m && m.description ? m.description : "")
|
|
1189
|
-
if (m && m.icon) {
|
|
1190
|
-
icon = m.icon
|
|
1191
|
-
} else {
|
|
1192
|
-
icon = null
|
|
1193
|
-
}
|
|
1194
|
-
uri = x.name
|
|
1195
|
-
} else {
|
|
1196
|
-
if (x.isDirectory()) {
|
|
1197
|
-
icon = "fa-solid fa-folder"
|
|
1198
|
-
} else {
|
|
1199
|
-
icon = "fa-regular fa-file"
|
|
1200
|
-
}
|
|
1201
|
-
name = x.name
|
|
1202
|
-
description = ""
|
|
1203
|
-
}
|
|
1204
|
-
return {
|
|
1205
|
-
icon,
|
|
1206
|
-
menu: x.menu,
|
|
1207
|
-
shortcuts: x.shortcuts,
|
|
1208
|
-
//icon: (x.isDirectory() ? "fa-solid fa-folder" : "fa-regular fa-file"),
|
|
1209
|
-
name,
|
|
1210
|
-
uri,
|
|
1211
|
-
//description: x.path,
|
|
1212
|
-
description,
|
|
1213
|
-
//url: p + "/" + x.name,
|
|
1214
|
-
url: _p + "/" + x.name,
|
|
1215
|
-
// url: `${U}/${x.name}`,
|
|
1216
|
-
browser_url: "/pinokio/browser/" + x.name
|
|
1217
|
-
}
|
|
1218
|
-
}),
|
|
1330
|
+
mode: null,
|
|
1331
|
+
//mode: (req.query && req.query.mode ? req.query.mode : null),
|
|
1332
|
+
items
|
|
1219
1333
|
})
|
|
1220
1334
|
}
|
|
1221
1335
|
}
|
|
@@ -2120,17 +2234,18 @@ class Server {
|
|
|
2120
2234
|
this.app.get("/proxy", ex(async (req, res) => {
|
|
2121
2235
|
let live_proxies = this.kernel.api.proxies["/proxy"]
|
|
2122
2236
|
if (!live_proxies) live_proxies = []
|
|
2123
|
-
let proxies = [
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2237
|
+
let proxies = []
|
|
2238
|
+
// let proxies = [{
|
|
2239
|
+
// icon: "ollama.webp",
|
|
2240
|
+
// name: "Ollama",
|
|
2241
|
+
// target: 'http://127.0.0.1:11434',
|
|
2242
|
+
// port: 44002
|
|
2243
|
+
// }, {
|
|
2244
|
+
// icon: "lmstudio.jpg",
|
|
2245
|
+
// name: "LMStudio",
|
|
2246
|
+
// target: 'http://127.0.0.1:1234',
|
|
2247
|
+
// port: 44003
|
|
2248
|
+
// }]
|
|
2134
2249
|
for(let i=0; i<proxies.length; i++) {
|
|
2135
2250
|
proxies[i].running = false
|
|
2136
2251
|
for(let live_proxy of live_proxies) {
|
|
@@ -2182,8 +2297,6 @@ class Server {
|
|
|
2182
2297
|
})
|
|
2183
2298
|
}
|
|
2184
2299
|
}
|
|
2185
|
-
console.log({ apps })
|
|
2186
|
-
|
|
2187
2300
|
res.render("proxy", {
|
|
2188
2301
|
agent: this.agent,
|
|
2189
2302
|
theme: this.theme,
|
|
@@ -2283,7 +2396,9 @@ class Server {
|
|
|
2283
2396
|
}
|
|
2284
2397
|
}))
|
|
2285
2398
|
this.app.post("/env", ex(async (req, res) => {
|
|
2399
|
+
console.log("req.body", req.body)
|
|
2286
2400
|
let fullpath = path.resolve(this.kernel.homedir, req.body.filepath, "ENVIRONMENT")
|
|
2401
|
+
console.log("fullpath", fullpath)
|
|
2287
2402
|
let updated = req.body.vals
|
|
2288
2403
|
await Util.update_env(fullpath, updated)
|
|
2289
2404
|
res.json({})
|
|
@@ -2313,17 +2428,22 @@ class Server {
|
|
|
2313
2428
|
this.app.get("/env/*", ex(async (req, res) => {
|
|
2314
2429
|
|
|
2315
2430
|
let env_path = req.params[0]
|
|
2316
|
-
await this.init_env(env_path)
|
|
2317
|
-
|
|
2318
|
-
let pathComponents = req.params[0].split("/")
|
|
2319
|
-
let filepath = path.resolve(this.kernel.homedir, req.params[0], "ENVIRONMENT")
|
|
2320
|
-
let editorpath = "/edit/" + req.params[0] + "/ENVIRONMENT"
|
|
2321
|
-
const items = await Util.parse_env_detail(filepath)
|
|
2322
2431
|
let p = path.resolve(this.kernel.homedir, env_path, "pinokio.js")
|
|
2323
2432
|
let config = (await this.kernel.loader.load(p)).resolved
|
|
2433
|
+
if (config.run) {
|
|
2434
|
+
await this.init_env(env_path, { no_inherit: true })
|
|
2435
|
+
} else {
|
|
2436
|
+
await this.init_env(env_path)
|
|
2437
|
+
}
|
|
2324
2438
|
|
|
2439
|
+
let pathComponents = req.params[0].split("/")
|
|
2440
|
+
let filepath = path.resolve(this.kernel.homedir, req.params[0], "ENVIRONMENT")
|
|
2325
2441
|
|
|
2326
|
-
|
|
2442
|
+
let items = []
|
|
2443
|
+
let e = await this.exists(filepath)
|
|
2444
|
+
if (e) {
|
|
2445
|
+
items = await Util.parse_env_detail(filepath)
|
|
2446
|
+
}
|
|
2327
2447
|
if (config.icon) {
|
|
2328
2448
|
config.icon = `/${env_path}/${config.icon}?raw=true`
|
|
2329
2449
|
}
|
|
@@ -2332,62 +2452,92 @@ class Server {
|
|
|
2332
2452
|
if (env_path.startsWith("api")) {
|
|
2333
2453
|
name = env_path.split("/")[1]
|
|
2334
2454
|
}
|
|
2455
|
+
let editorpath = "/edit/" + req.params[0] + "/ENVIRONMENT"
|
|
2335
2456
|
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
// home: null,
|
|
2355
|
-
// config,
|
|
2356
|
-
// name,
|
|
2357
|
-
// init: req.query ? req.query.init : null,
|
|
2358
|
-
// editorpath,
|
|
2359
|
-
// items,
|
|
2360
|
-
// theme: this.theme,
|
|
2361
|
-
// filepath,
|
|
2362
|
-
// agent: this.agent,
|
|
2363
|
-
// })
|
|
2364
|
-
//}
|
|
2365
|
-
res.render("env_editor", {
|
|
2366
|
-
home: null,
|
|
2367
|
-
config,
|
|
2368
|
-
name,
|
|
2369
|
-
init: req.query ? req.query.init : null,
|
|
2370
|
-
editorpath,
|
|
2371
|
-
items,
|
|
2372
|
-
theme: this.theme,
|
|
2373
|
-
filepath,
|
|
2374
|
-
agent: this.agent,
|
|
2375
|
-
})
|
|
2457
|
+
if (config.run) {
|
|
2458
|
+
let configStr = await fs.promises.readFile(p, "utf8")
|
|
2459
|
+
res.render("task", {
|
|
2460
|
+
home: null,
|
|
2461
|
+
config,
|
|
2462
|
+
name,
|
|
2463
|
+
init: true,
|
|
2464
|
+
// init: req.query ? req.query.init : null,
|
|
2465
|
+
editorpath,
|
|
2466
|
+
items,
|
|
2467
|
+
theme: this.theme,
|
|
2468
|
+
filepath,
|
|
2469
|
+
agent: this.agent,
|
|
2470
|
+
path: "/api/" + name + "/pinokio.js",
|
|
2471
|
+
_path: "/_api/" + name,
|
|
2472
|
+
str: configStr
|
|
2473
|
+
})
|
|
2474
|
+
} else {
|
|
2376
2475
|
|
|
2476
|
+
let requires_instantiation = false
|
|
2477
|
+
let pre_items = {}
|
|
2478
|
+
console.log("## CONFIG", config)
|
|
2479
|
+
if (config && config.pre) {
|
|
2480
|
+
let env = await Environment.get2(filepath, this.kernel)
|
|
2481
|
+
console.log("_________ENV", env)
|
|
2482
|
+
for(let item of config.pre) {
|
|
2483
|
+
console.log("ITEM" , item)
|
|
2484
|
+
if (item.env) {
|
|
2485
|
+
pre_items[item.env] = item
|
|
2486
|
+
if (env[item.env]) {
|
|
2487
|
+
|
|
2488
|
+
} else {
|
|
2489
|
+
requires_instantiation = true
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
console.log({ requires_instantiation })
|
|
2495
|
+
|
|
2496
|
+
res.render("env_editor", {
|
|
2497
|
+
home: null,
|
|
2498
|
+
config,
|
|
2499
|
+
name,
|
|
2500
|
+
init: req.query ? req.query.init : null,
|
|
2501
|
+
editorpath,
|
|
2502
|
+
items,
|
|
2503
|
+
theme: this.theme,
|
|
2504
|
+
filepath,
|
|
2505
|
+
agent: this.agent,
|
|
2506
|
+
pre_items,
|
|
2507
|
+
requires_instantiation,
|
|
2508
|
+
})
|
|
2509
|
+
}
|
|
2510
|
+
//res.render("env_editor", {
|
|
2511
|
+
// home: null,
|
|
2512
|
+
// config,
|
|
2513
|
+
// name,
|
|
2514
|
+
// init: req.query ? req.query.init : null,
|
|
2515
|
+
// editorpath,
|
|
2516
|
+
// items,
|
|
2517
|
+
// theme: this.theme,
|
|
2518
|
+
// filepath,
|
|
2519
|
+
// agent: this.agent,
|
|
2520
|
+
//})
|
|
2377
2521
|
}))
|
|
2378
2522
|
this.app.get("/pre/api/:name", ex(async (req, res) => {
|
|
2379
2523
|
let p = path.resolve(this.kernel.homedir, "api", req.params.name, "pinokio.js")
|
|
2524
|
+
let p2 = path.resolve(this.kernel.homedir, "api", req.params.name)
|
|
2380
2525
|
let config = (await this.kernel.loader.load(p)).resolved
|
|
2381
2526
|
if (config && config.pre) {
|
|
2382
2527
|
config.pre.forEach((item) => {
|
|
2383
|
-
item.icon
|
|
2528
|
+
if (item.icon) {
|
|
2529
|
+
item.icon = `/api/${req.params.name}/${item.icon}?raw=true`
|
|
2530
|
+
}
|
|
2384
2531
|
})
|
|
2532
|
+
let env = await Environment.get2(p2, this.kernel)
|
|
2533
|
+
console.log("ENV", env)
|
|
2385
2534
|
res.render("pre", {
|
|
2386
2535
|
name: req.params.name,
|
|
2387
2536
|
theme: this.theme,
|
|
2388
2537
|
agent: this.agent,
|
|
2389
2538
|
name: req.params.name,
|
|
2390
|
-
items: config.pre
|
|
2539
|
+
items: config.pre,
|
|
2540
|
+
env
|
|
2391
2541
|
})
|
|
2392
2542
|
} else {
|
|
2393
2543
|
res.redirect("/env/" + req.params.name + "?init=true")
|