pinokiod 3.9.3 → 3.9.13
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/index.js +153 -67
- package/kernel/api/rm/index.js +3 -2
- package/kernel/api/set/index.js +4 -2
- package/kernel/bin/caddy.js +0 -2
- package/kernel/bin/index.js +13 -0
- package/kernel/index.js +10 -8
- package/kernel/info.js +3 -0
- package/kernel/plugin.js +34 -0
- package/kernel/router/index.js +1 -1
- package/kernel/router/localhost_variable_router.js +1 -1
- package/kernel/router/peer_variable_router.js +1 -1
- package/kernel/shell.js +14 -0
- package/kernel/util.js +19 -1
- package/package.json +1 -1
- package/server/index.js +296 -98
- package/server/public/electron.css +2 -0
- package/server/public/modalinput.js +7 -2
- package/server/public/opener.js +32 -0
- package/server/public/style.css +33 -2
- package/server/socket.js +7 -3
- package/server/views/app.ejs +188 -72
- package/server/views/env_editor.ejs +1 -0
- package/server/views/file_explorer.ejs +1 -1
- package/server/views/index.ejs +35 -16
- package/server/views/partials/dynamic.ejs +54 -6
- package/server/views/partials/menu.ejs +11 -6
- package/server/views/prototype/index.ejs +366 -31
- package/server/views/prototype/show.ejs +386 -30
- package/server/views/required_env_editor.ejs +1 -0
- package/server/views/settings.ejs +58 -43
- package/server/views/terminal.ejs +6 -0
- package/:w +0 -1247
package/kernel/api/index.js
CHANGED
|
@@ -29,18 +29,53 @@ class Api {
|
|
|
29
29
|
this.lproxy = new Lproxy()
|
|
30
30
|
}
|
|
31
31
|
async meta(name) {
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
-
let
|
|
32
|
+
let p1
|
|
33
|
+
let p2
|
|
34
|
+
let p3
|
|
35
|
+
let api_path
|
|
36
|
+
let api_name
|
|
37
|
+
if (typeof name === "object") {
|
|
38
|
+
if (name.path) {
|
|
39
|
+
api_path = name.path
|
|
40
|
+
api_name = path.relative(this.kernel.path("api"), api_path)
|
|
41
|
+
p1 = path.resolve(name.path, "pinokio.js")
|
|
42
|
+
p2 = path.resolve(name.path, "pinokio_meta.json")
|
|
43
|
+
p3 = path.resolve(name.path, "pinokio.json")
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
api_path = this.kernel.path("api", name)
|
|
47
|
+
api_name = name
|
|
48
|
+
p1 = this.kernel.path("api", name, "pinokio.js")
|
|
49
|
+
p2 = this.kernel.path("api", name, "pinokio_meta.json")
|
|
50
|
+
p3 = this.kernel.path("api", name, "pinokio.json")
|
|
51
|
+
}
|
|
52
|
+
let pinokio = (await this.kernel.loader.load(p1)).resolved
|
|
35
53
|
let pinokio2 = (await this.kernel.loader.load(p2)).resolved
|
|
36
|
-
let p3 = this.kernel.path("api", name, "pinokio.json")
|
|
37
54
|
let pinokio3 = (await this.kernel.loader.load(p3)).resolved
|
|
38
55
|
let meta = Object.assign({}, pinokio, pinokio2, pinokio3)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
|
|
57
|
+
// create pinokio.json if it doesn't exist
|
|
58
|
+
// if (!pinokio3) {
|
|
59
|
+
// await fs.promises.writeFile(p3, JSON.stringify({
|
|
60
|
+
// plugin: {
|
|
61
|
+
// menu: []
|
|
62
|
+
// }
|
|
63
|
+
// }), null, 2)
|
|
64
|
+
// } else {
|
|
65
|
+
// if (!pinokio3.plugin) {
|
|
66
|
+
// pinokio3.plugin.menu = []
|
|
67
|
+
// await fs.promises.writeFile(p3, JSON.stringify(pinokio3, null, 2))
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
|
|
71
|
+
meta.iconpath = meta.icon ? path.resolve(api_path, meta.icon) : null
|
|
72
|
+
meta.icon = meta.icon ? `/api/${api_name}/${meta.icon}?raw=true` : "/pinokio-black.png"
|
|
73
|
+
meta.path = api_path
|
|
42
74
|
meta.name = meta.title
|
|
43
|
-
meta.link = `/pinokio/browser/${
|
|
75
|
+
meta.link = `/pinokio/browser/${api_name}/browse#n1`
|
|
76
|
+
meta.web_path = `/api/${api_name}`
|
|
77
|
+
meta.ui = `/pinokio/browser/${api_name}`
|
|
78
|
+
meta.browse = `/pinokio/browser/${api_name}/browse`
|
|
44
79
|
return meta
|
|
45
80
|
}
|
|
46
81
|
get_proxy_url(root, port) {
|
|
@@ -137,8 +172,16 @@ class Api {
|
|
|
137
172
|
// 1. set the "stop" flag for the uri, so the next execution in the queue for the uri will NOT queue another task
|
|
138
173
|
// 2. stream a message closing the socket
|
|
139
174
|
|
|
140
|
-
|
|
175
|
+
console.log("STOP", req)
|
|
176
|
+
|
|
177
|
+
if (req.params.id) {
|
|
178
|
+
// /Users/x/pinokio/prototype/system/aicode/template/claude.json?cwd=/Users/x/pinokio/api/MMAudio.git
|
|
179
|
+
// take the first part only since the rest is the cwd
|
|
180
|
+
req.params.uri = req.params.id.split("?")[0]
|
|
181
|
+
}
|
|
141
182
|
|
|
183
|
+
// 1. if the scropt has 'on.stop', run it when stopping
|
|
184
|
+
let requestPath = this.filePath(req.params.uri)
|
|
142
185
|
let { cwd, script } = await this.resolveScript(requestPath)
|
|
143
186
|
if (script.on) {
|
|
144
187
|
if (script.on.stop) {
|
|
@@ -182,12 +225,19 @@ class Api {
|
|
|
182
225
|
delete this.waiter[requestPath]
|
|
183
226
|
}
|
|
184
227
|
|
|
185
|
-
|
|
228
|
+
console.log("Stop", { req, requestPath })
|
|
229
|
+
if (req.params.id) {
|
|
230
|
+
console.log("delete", req.params.id, this.running[req.params.id])
|
|
231
|
+
delete this.running[req.params.id]
|
|
232
|
+
delete this.kernel.memory.local[req.params.id]
|
|
233
|
+
} else {
|
|
234
|
+
delete this.running[requestPath]
|
|
235
|
+
delete this.kernel.memory.local[requestPath]
|
|
236
|
+
}
|
|
186
237
|
|
|
187
|
-
delete this.kernel.memory.local[requestPath]
|
|
188
238
|
|
|
189
239
|
this.ondata({
|
|
190
|
-
id: requestPath,
|
|
240
|
+
id: req.params.id || requestPath,
|
|
191
241
|
type: "disconnect"
|
|
192
242
|
})
|
|
193
243
|
this.kernel.refresh(true)
|
|
@@ -603,12 +653,16 @@ class Api {
|
|
|
603
653
|
cwd = request.cwd
|
|
604
654
|
}
|
|
605
655
|
|
|
656
|
+
console.log("STEP", { request, rawrpc, input, args })
|
|
657
|
+
|
|
658
|
+
let id = request.id || request.path
|
|
659
|
+
|
|
606
660
|
let memory = {
|
|
607
661
|
script: this.kernel.script,
|
|
608
662
|
input,
|
|
609
663
|
args,
|
|
610
|
-
global: (this.kernel.memory.global[
|
|
611
|
-
local: (this.kernel.memory.local[
|
|
664
|
+
global: (this.kernel.memory.global[id] || {}),
|
|
665
|
+
local: (this.kernel.memory.local[id] || {}),
|
|
612
666
|
key: this.kernel.memory.key,
|
|
613
667
|
current: i,
|
|
614
668
|
uri: request.uri,
|
|
@@ -631,10 +685,9 @@ class Api {
|
|
|
631
685
|
let env = await Environment.get2(request.path, this.kernel)
|
|
632
686
|
// set template
|
|
633
687
|
this.kernel.template.update({ envs: env, env })
|
|
634
|
-
|
|
635
|
-
this.kernel.memory.
|
|
636
|
-
this.kernel.memory.
|
|
637
|
-
this.kernel.memory.input[request.path] = input
|
|
688
|
+
this.kernel.memory.rpc[id] = rawrpc
|
|
689
|
+
this.kernel.memory.args[id] = args
|
|
690
|
+
this.kernel.memory.input[id] = input
|
|
638
691
|
|
|
639
692
|
// render until `{{ }}` pattern does not exist
|
|
640
693
|
// 1. render once
|
|
@@ -657,11 +710,13 @@ class Api {
|
|
|
657
710
|
}
|
|
658
711
|
// replace {{{ }}} with {{ }}
|
|
659
712
|
rpc = this.kernel.template.flatten(rpc)
|
|
713
|
+
console.log({ rpc })
|
|
660
714
|
|
|
661
715
|
// 6. rpc must have method names
|
|
662
716
|
if (rpc.method) {
|
|
663
717
|
|
|
664
718
|
rpc.parent = {
|
|
719
|
+
id: request.id,
|
|
665
720
|
uri: request.uri,
|
|
666
721
|
path: request.path,
|
|
667
722
|
git: this.parentGitURI(request.path),
|
|
@@ -670,6 +725,8 @@ class Api {
|
|
|
670
725
|
// 7. resolve the rpc
|
|
671
726
|
let resolved = await this.resolveMethod(rpc, cwd)
|
|
672
727
|
|
|
728
|
+
console.log({ resolved })
|
|
729
|
+
|
|
673
730
|
// 8. the endpoint must exist
|
|
674
731
|
if (!resolved.method) {
|
|
675
732
|
this.ondata({
|
|
@@ -706,8 +763,8 @@ class Api {
|
|
|
706
763
|
|
|
707
764
|
rpc.args = args
|
|
708
765
|
|
|
709
|
-
this.kernel.memory.rpc[
|
|
710
|
-
this.kernel.memory.rpc[
|
|
766
|
+
this.kernel.memory.rpc[id].current = rpc.current
|
|
767
|
+
this.kernel.memory.rpc[id].total = rpc.total
|
|
711
768
|
|
|
712
769
|
// this.kernel.memory.rpc[request.path] = rpc
|
|
713
770
|
// this.kernel.memory.args[request.path] = args
|
|
@@ -763,7 +820,7 @@ class Api {
|
|
|
763
820
|
// last call
|
|
764
821
|
if (script.daemon) {
|
|
765
822
|
this.ondata({
|
|
766
|
-
id: request.path,
|
|
823
|
+
id: request.id || request.path,
|
|
767
824
|
type: "start",
|
|
768
825
|
data: {
|
|
769
826
|
title: "Started",
|
|
@@ -772,22 +829,30 @@ class Api {
|
|
|
772
829
|
})
|
|
773
830
|
} else {
|
|
774
831
|
// no next rpc to execute. Finish
|
|
775
|
-
this.kernel.memory.local[
|
|
776
|
-
this.kernel.memory.rpc[
|
|
777
|
-
this.kernel.memory.input[
|
|
778
|
-
this.kernel.memory.args[
|
|
832
|
+
this.kernel.memory.local[id] = {}
|
|
833
|
+
this.kernel.memory.rpc[id] = null
|
|
834
|
+
this.kernel.memory.input[id] = null
|
|
835
|
+
this.kernel.memory.args[id] = null
|
|
779
836
|
this.ondata({
|
|
780
|
-
id: request.path,
|
|
837
|
+
id: request.id || request.path,
|
|
781
838
|
type: "event",
|
|
782
839
|
data: "stop",
|
|
783
840
|
rpc,
|
|
784
841
|
rawrpc
|
|
785
842
|
})
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
843
|
+
if (request.id) {
|
|
844
|
+
await this.stop({
|
|
845
|
+
params: {
|
|
846
|
+
id: request.id
|
|
847
|
+
}
|
|
848
|
+
})
|
|
849
|
+
} else {
|
|
850
|
+
await this.stop({
|
|
851
|
+
params: {
|
|
852
|
+
uri: request.path
|
|
853
|
+
}
|
|
854
|
+
})
|
|
855
|
+
}
|
|
791
856
|
console.log(">>>>>> STOPPED", request)
|
|
792
857
|
}
|
|
793
858
|
return { request, input: null, step: rpc.next, total: script.run.length, args }
|
|
@@ -803,7 +868,7 @@ class Api {
|
|
|
803
868
|
|
|
804
869
|
try {
|
|
805
870
|
this.ondata({
|
|
806
|
-
id: request.path,
|
|
871
|
+
id: request.id || request.path,
|
|
807
872
|
type: "start",
|
|
808
873
|
data: rpc
|
|
809
874
|
})
|
|
@@ -823,7 +888,7 @@ class Api {
|
|
|
823
888
|
// 11. actually make the rpc call
|
|
824
889
|
result = await this.run(resolved.method, rpc, (stream, type) => {
|
|
825
890
|
let m = {
|
|
826
|
-
id: request.path,
|
|
891
|
+
id: request.id || request.path,
|
|
827
892
|
caller: request.caller,
|
|
828
893
|
type: (type ? type : "stream"),
|
|
829
894
|
index: i,
|
|
@@ -850,7 +915,7 @@ class Api {
|
|
|
850
915
|
|
|
851
916
|
if (result && result.error) {
|
|
852
917
|
this.ondata({
|
|
853
|
-
id: request.path,
|
|
918
|
+
id: request.id || request.path,
|
|
854
919
|
type: "error",
|
|
855
920
|
data: result.response,
|
|
856
921
|
event: result.error,
|
|
@@ -901,9 +966,9 @@ class Api {
|
|
|
901
966
|
if (chunks.length === 2) {
|
|
902
967
|
let name = chunks[1]
|
|
903
968
|
if (chunks[0] === "local") {
|
|
904
|
-
this.kernel.memory.local[
|
|
969
|
+
this.kernel.memory.local[id][name] = filled_returns[name]
|
|
905
970
|
} else if (chunks[0] === "global") {
|
|
906
|
-
this.kernel.memory.global[
|
|
971
|
+
this.kernel.memory.global[id][name] = filled_returns[name]
|
|
907
972
|
}
|
|
908
973
|
}
|
|
909
974
|
}
|
|
@@ -918,22 +983,22 @@ class Api {
|
|
|
918
983
|
if (chunks.length === 2) {
|
|
919
984
|
let name = chunks[1]
|
|
920
985
|
if (chunks[0] === "local") {
|
|
921
|
-
if (!this.kernel.memory.local[
|
|
922
|
-
this.kernel.memory.local[
|
|
986
|
+
if (!this.kernel.memory.local[id]) {
|
|
987
|
+
this.kernel.memory.local[id] = {}
|
|
923
988
|
}
|
|
924
|
-
this.kernel.memory.local[
|
|
989
|
+
this.kernel.memory.local[id][name] = result
|
|
925
990
|
} else if (chunks[0] === "global") {
|
|
926
|
-
if (!this.kernel.memory.global[
|
|
927
|
-
this.kernel.memory.global[
|
|
991
|
+
if (!this.kernel.memory.global[id]) {
|
|
992
|
+
this.kernel.memory.global[id] = {}
|
|
928
993
|
}
|
|
929
|
-
this.kernel.memory.global[
|
|
994
|
+
this.kernel.memory.global[id][name] = result
|
|
930
995
|
}
|
|
931
996
|
}
|
|
932
997
|
}
|
|
933
998
|
}
|
|
934
999
|
|
|
935
1000
|
this.ondata({
|
|
936
|
-
id: request.path,
|
|
1001
|
+
id: request.id || request.path,
|
|
937
1002
|
index: i,
|
|
938
1003
|
total,
|
|
939
1004
|
type: "result",
|
|
@@ -949,7 +1014,7 @@ class Api {
|
|
|
949
1014
|
html = `<b>Run complete</b><br>${rawrpc.uri ? '<b>uri</b> ' + rawrpc.uri + '<br>' : ''}<b>method</b> ${rawrpc.method}`
|
|
950
1015
|
}
|
|
951
1016
|
this.ondata({
|
|
952
|
-
id: request.path,
|
|
1017
|
+
id: request.id || request.path,
|
|
953
1018
|
type: "notify",
|
|
954
1019
|
data :{
|
|
955
1020
|
html,
|
|
@@ -957,7 +1022,7 @@ class Api {
|
|
|
957
1022
|
})
|
|
958
1023
|
} else if (typeof rpc.notify === "object") {
|
|
959
1024
|
this.ondata({
|
|
960
|
-
id: request.path,
|
|
1025
|
+
id: request.id || request.path,
|
|
961
1026
|
type: "notify",
|
|
962
1027
|
data: {
|
|
963
1028
|
html: rpc.notify.html,
|
|
@@ -971,7 +1036,12 @@ class Api {
|
|
|
971
1036
|
|
|
972
1037
|
// if not running, don't progress any further
|
|
973
1038
|
// (can happen when the script made a request to a 3rd party module and the 3rd party module returns a response after the stop was triggered)
|
|
974
|
-
if (
|
|
1039
|
+
if (request.id) {
|
|
1040
|
+
if (!this.running[request.id]) {
|
|
1041
|
+
console.log("The script was already canceled")
|
|
1042
|
+
return
|
|
1043
|
+
}
|
|
1044
|
+
} else if (!this.running[request.path]) {
|
|
975
1045
|
console.log("The script was already canceled")
|
|
976
1046
|
return
|
|
977
1047
|
}
|
|
@@ -984,7 +1054,7 @@ class Api {
|
|
|
984
1054
|
// if not daemon
|
|
985
1055
|
if (script.daemon) {
|
|
986
1056
|
this.ondata({
|
|
987
|
-
id: request.path,
|
|
1057
|
+
id: request.id || request.path,
|
|
988
1058
|
type: "start",
|
|
989
1059
|
data: {
|
|
990
1060
|
title: "Started",
|
|
@@ -994,20 +1064,27 @@ class Api {
|
|
|
994
1064
|
return { request, input: result, step: rpc.next, total: script.run.length, args }
|
|
995
1065
|
} else {
|
|
996
1066
|
// no next rpc to execute. Finish
|
|
997
|
-
this.kernel.memory.local[
|
|
1067
|
+
this.kernel.memory.local[id] = {}
|
|
998
1068
|
this.ondata({
|
|
999
|
-
id: request.path,
|
|
1069
|
+
id: request.id || request.path,
|
|
1000
1070
|
type: "event",
|
|
1001
1071
|
data: "stop",
|
|
1002
1072
|
rpc,
|
|
1003
1073
|
rawrpc
|
|
1004
1074
|
})
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1075
|
+
if (request.id) {
|
|
1076
|
+
await this.stop({
|
|
1077
|
+
params: {
|
|
1078
|
+
id: request.id
|
|
1079
|
+
}
|
|
1080
|
+
})
|
|
1081
|
+
} else {
|
|
1082
|
+
await this.stop({
|
|
1083
|
+
params: {
|
|
1084
|
+
uri: request.path
|
|
1085
|
+
}
|
|
1086
|
+
})
|
|
1087
|
+
}
|
|
1011
1088
|
return { request, input: result, step: rpc.next, total: script.run.length, args }
|
|
1012
1089
|
}
|
|
1013
1090
|
|
|
@@ -1020,7 +1097,7 @@ class Api {
|
|
|
1020
1097
|
} catch (e) {
|
|
1021
1098
|
console.log("<>ERROR", e)
|
|
1022
1099
|
this.ondata({
|
|
1023
|
-
id: request.path,
|
|
1100
|
+
id: request.id || request.path,
|
|
1024
1101
|
type: "error",
|
|
1025
1102
|
data: e.stack,
|
|
1026
1103
|
rpc,
|
|
@@ -1031,7 +1108,7 @@ class Api {
|
|
|
1031
1108
|
}
|
|
1032
1109
|
} else {
|
|
1033
1110
|
this.ondata({
|
|
1034
|
-
id: request.path,
|
|
1111
|
+
id: request.id || request.path,
|
|
1035
1112
|
type: "error",
|
|
1036
1113
|
data: "missing RPC attribute: method",
|
|
1037
1114
|
rpc,
|
|
@@ -1062,15 +1139,17 @@ class Api {
|
|
|
1062
1139
|
this.queues[queue_id] = fastq.promise(async ({ request, rawrpc, input, step, total, cwd, args }) => {
|
|
1063
1140
|
try {
|
|
1064
1141
|
let response = await this.step(request, rawrpc, input, step, total, args)
|
|
1142
|
+
console.log("Handle Response", { request, response })
|
|
1065
1143
|
if (response) {
|
|
1066
1144
|
if (response.rawrpc) {
|
|
1067
1145
|
this.queue(response.request, response.rawrpc, response.input, response.step, response.total, cwd, args)
|
|
1068
1146
|
} else {
|
|
1147
|
+
let id = response.request.id || response.request.path
|
|
1069
1148
|
if (response.request.caller) {
|
|
1070
1149
|
if (this.done[response.request.path]) {
|
|
1071
1150
|
this.done[response.request.path]({
|
|
1072
|
-
global: (this.kernel.memory.global[
|
|
1073
|
-
local: (this.kernel.memory.local[
|
|
1151
|
+
global: (this.kernel.memory.global[id] || {}),
|
|
1152
|
+
local: (this.kernel.memory.local[id] || {}),
|
|
1074
1153
|
//return: response.input
|
|
1075
1154
|
input: response.input
|
|
1076
1155
|
})
|
|
@@ -1078,10 +1157,11 @@ class Api {
|
|
|
1078
1157
|
}
|
|
1079
1158
|
}
|
|
1080
1159
|
} else {
|
|
1160
|
+
let id = request.id || request.path
|
|
1081
1161
|
if (this.done[request.path]) {
|
|
1082
1162
|
this.done[request.path]({
|
|
1083
|
-
global: (this.kernel.memory.global[
|
|
1084
|
-
local: (this.kernel.memory.local[
|
|
1163
|
+
global: (this.kernel.memory.global[id] || {}),
|
|
1164
|
+
local: (this.kernel.memory.local[id] || {}),
|
|
1085
1165
|
})
|
|
1086
1166
|
}
|
|
1087
1167
|
}
|
|
@@ -1139,7 +1219,7 @@ class Api {
|
|
|
1139
1219
|
|
|
1140
1220
|
if (queueSize > 0) {
|
|
1141
1221
|
this.ondata({
|
|
1142
|
-
id: request.path,
|
|
1222
|
+
id: request.id || request.path,
|
|
1143
1223
|
type: "info",
|
|
1144
1224
|
data: `<b>Queued</b> waiting for ${queueSize} ${queueSize > 1 ? 'tasks' : 'task'} to finish<br><b>uri</b> ${rawrpc.uri}<br><b>method</b> ${rawrpc.method}`
|
|
1145
1225
|
})
|
|
@@ -1181,6 +1261,7 @@ class Api {
|
|
|
1181
1261
|
}
|
|
1182
1262
|
}
|
|
1183
1263
|
async process(request, done) {
|
|
1264
|
+
console.log("Process", request)
|
|
1184
1265
|
/**************************************************************
|
|
1185
1266
|
*
|
|
1186
1267
|
* req := { uri: <relative path>|<absolute path>|<url> }
|
|
@@ -1245,7 +1326,7 @@ class Api {
|
|
|
1245
1326
|
await this.launch(request, p)
|
|
1246
1327
|
} else {
|
|
1247
1328
|
this.ondata({
|
|
1248
|
-
id: request.path,
|
|
1329
|
+
id: request.id || request.path,
|
|
1249
1330
|
type: "error",
|
|
1250
1331
|
data: "uri doesn't exist \r\n" + JSON.stringify(request, null, 2)
|
|
1251
1332
|
})
|
|
@@ -1256,7 +1337,7 @@ class Api {
|
|
|
1256
1337
|
|
|
1257
1338
|
if (!script) {
|
|
1258
1339
|
this.ondata({
|
|
1259
|
-
id: request.path,
|
|
1340
|
+
id: request.id || request.path,
|
|
1260
1341
|
type: "error",
|
|
1261
1342
|
data: "the endpoint does not exist: " + request.uri,
|
|
1262
1343
|
})
|
|
@@ -1265,15 +1346,20 @@ class Api {
|
|
|
1265
1346
|
//if (script.run && Array.isArray(script.run)) {
|
|
1266
1347
|
if (script.run) {
|
|
1267
1348
|
|
|
1268
|
-
|
|
1349
|
+
if (request.id) {
|
|
1350
|
+
this.running[request.id] = true
|
|
1351
|
+
this.done[request.id] = done
|
|
1352
|
+
} else if (request.path) {
|
|
1353
|
+
this.running[request.path] = true
|
|
1354
|
+
this.done[request.path] = done
|
|
1355
|
+
}
|
|
1269
1356
|
|
|
1270
|
-
this.done[request.path] = done
|
|
1271
1357
|
|
|
1272
1358
|
this.queue(request, script.run[0], request.input, 0, script.run.length, cwd, request.input)
|
|
1273
1359
|
|
|
1274
1360
|
} else {
|
|
1275
1361
|
this.ondata({
|
|
1276
|
-
id: request.path,
|
|
1362
|
+
id: request.id || request.path,
|
|
1277
1363
|
type: "error",
|
|
1278
1364
|
data: "missing attribute: run"
|
|
1279
1365
|
})
|
package/kernel/api/rm/index.js
CHANGED
|
@@ -45,15 +45,16 @@ module.exports = async (req, ondata, kernel) => {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
*/
|
|
48
|
+
let parent_id = req.parent.id || req.parent.path
|
|
48
49
|
|
|
49
50
|
// set the local and global variables
|
|
50
51
|
let types = ["local", "global"]
|
|
51
52
|
for(let type of types) {
|
|
52
53
|
let keys = req.params[type]
|
|
53
54
|
if (keys) {
|
|
54
|
-
let old = kernel.memory[type][
|
|
55
|
+
let old = kernel.memory[type][parent_id]
|
|
55
56
|
old = rm(old, keys)
|
|
56
|
-
kernel.memory[type][
|
|
57
|
+
kernel.memory[type][parent_id] = old
|
|
57
58
|
|
|
58
59
|
}
|
|
59
60
|
}
|
package/kernel/api/set/index.js
CHANGED
|
@@ -90,18 +90,20 @@ module.exports = async (req, ondata, kernel) => {
|
|
|
90
90
|
}
|
|
91
91
|
*/
|
|
92
92
|
|
|
93
|
+
let parent_id = req.parent.id || req.parent.path
|
|
94
|
+
|
|
93
95
|
// set the local and global variables
|
|
94
96
|
let types = ["local", "global"]
|
|
95
97
|
for(let type of types) {
|
|
96
98
|
let kv = req.params[type]
|
|
97
99
|
if (kv) {
|
|
98
100
|
|
|
99
|
-
let old = kernel.memory[type][
|
|
101
|
+
let old = kernel.memory[type][parent_id]
|
|
100
102
|
if (!old) {
|
|
101
103
|
old = {}
|
|
102
104
|
}
|
|
103
105
|
old = await set(old, kv, kernel, req, ondata)
|
|
104
|
-
kernel.memory[type][
|
|
106
|
+
kernel.memory[type][parent_id] = old
|
|
105
107
|
|
|
106
108
|
// if (!kernel.memory[type][req.uri]) {
|
|
107
109
|
// kernel.memory[type][req.uri] = {}
|
package/kernel/bin/caddy.js
CHANGED
|
@@ -38,7 +38,6 @@ class Caddy {
|
|
|
38
38
|
}, (e) => {
|
|
39
39
|
if (!resolved) {
|
|
40
40
|
if (/endpoint started/i.test(e.cleaned)) {
|
|
41
|
-
console.log("######### match")
|
|
42
41
|
resolved = true
|
|
43
42
|
resolve()
|
|
44
43
|
}
|
|
@@ -64,7 +63,6 @@ class Caddy {
|
|
|
64
63
|
resolve()
|
|
65
64
|
if (!resolved) {
|
|
66
65
|
if (/endpoint started/i.test(e.cleaned)) {
|
|
67
|
-
console.log("######### match")
|
|
68
66
|
resolved = true
|
|
69
67
|
resolve()
|
|
70
68
|
}
|
package/kernel/bin/index.js
CHANGED
|
@@ -39,7 +39,20 @@ class Bin {
|
|
|
39
39
|
this.platform = os.platform()
|
|
40
40
|
}
|
|
41
41
|
async shell_kill(params, ondata) {
|
|
42
|
+
console.log("shell_kill", params)
|
|
42
43
|
this.kernel.shell.kill(params.params)
|
|
44
|
+
|
|
45
|
+
// let id = params.params.id
|
|
46
|
+
// console.log("id", id)
|
|
47
|
+
// console.log("api.running", this.kernel.api.running)
|
|
48
|
+
// delete this.kernel.api.running[id]
|
|
49
|
+
// delete this.kernel.memory.local[id]
|
|
50
|
+
//
|
|
51
|
+
// ondata({
|
|
52
|
+
// id,
|
|
53
|
+
// type: "disconnect"
|
|
54
|
+
// })
|
|
55
|
+
// this.kernel.refresh(true)
|
|
43
56
|
}
|
|
44
57
|
async shell_start(params, ondata) {
|
|
45
58
|
params.path = params.path || this.path()
|
package/kernel/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const Pipe = require("../pipe")
|
|
|
30
30
|
const Cloudflare = require('./api/cloudflare')
|
|
31
31
|
const Store = require('./store')
|
|
32
32
|
const Proto = require('./prototype')
|
|
33
|
+
const Plugin = require('./plugin')
|
|
33
34
|
const Router = require("./router")
|
|
34
35
|
const Procs = require('./procs')
|
|
35
36
|
const Peer = require('./peer')
|
|
@@ -416,12 +417,12 @@ class Kernel {
|
|
|
416
417
|
let exists1 = await this.exists(pinokiojson)
|
|
417
418
|
let exists2 = await this.exists(pinokiometajson)
|
|
418
419
|
let exists3 = await this.exists(pinokiojs)
|
|
419
|
-
if (!exists1 && !exists2 && !exists3) {
|
|
420
|
-
await fs.promises.writeFile(pinokiojson, JSON.stringify({
|
|
421
|
-
title: "No title",
|
|
422
|
-
description: ""
|
|
423
|
-
}))
|
|
424
|
-
}
|
|
420
|
+
// if (!exists1 && !exists2 && !exists3) {
|
|
421
|
+
// await fs.promises.writeFile(pinokiojson, JSON.stringify({
|
|
422
|
+
// title: "No title",
|
|
423
|
+
// description: ""
|
|
424
|
+
// }))
|
|
425
|
+
// }
|
|
425
426
|
let pinokio = await this.api.meta(folder)
|
|
426
427
|
if (pinokio) {
|
|
427
428
|
i.api.push({
|
|
@@ -465,7 +466,6 @@ class Kernel {
|
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
468
|
which(name) {
|
|
468
|
-
console.log("which", this.envs.PATH)
|
|
469
469
|
if (this.platform === "win32") {
|
|
470
470
|
try {
|
|
471
471
|
const result = execSync(`where ${name}`, { env: this.envs, encoding: "utf-8" })
|
|
@@ -476,7 +476,6 @@ class Kernel {
|
|
|
476
476
|
return null
|
|
477
477
|
}
|
|
478
478
|
} catch (e) {
|
|
479
|
-
console.log(`>> which ${name}`, e)
|
|
480
479
|
return null
|
|
481
480
|
}
|
|
482
481
|
} else {
|
|
@@ -516,6 +515,7 @@ class Kernel {
|
|
|
516
515
|
this.info = new Info(this)
|
|
517
516
|
this.pipe = new Pipe(this)
|
|
518
517
|
this.proto = new Proto(this)
|
|
518
|
+
this.plugin = new Plugin(this)
|
|
519
519
|
this.processes = new Procs()
|
|
520
520
|
this.kv = new KV(this)
|
|
521
521
|
this.cloudflare = new Cloudflare()
|
|
@@ -637,6 +637,7 @@ class Kernel {
|
|
|
637
637
|
this.shell.init().then(async () => {
|
|
638
638
|
// this.bin.check()
|
|
639
639
|
if (this.envs) {
|
|
640
|
+
console.log("template.update")
|
|
640
641
|
this.template.update({
|
|
641
642
|
env: this.envs,
|
|
642
643
|
envs: this.envs,
|
|
@@ -727,6 +728,7 @@ class Kernel {
|
|
|
727
728
|
|
|
728
729
|
|
|
729
730
|
await this.proto.init()
|
|
731
|
+
await this.plugin.init()
|
|
730
732
|
|
|
731
733
|
// refresh every 5 second
|
|
732
734
|
if (this.refresh_interval) {
|
package/kernel/info.js
CHANGED
package/kernel/plugin.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
class Plugin {
|
|
3
|
+
constructor(kernel) {
|
|
4
|
+
this.kernel = kernel
|
|
5
|
+
}
|
|
6
|
+
async init() {
|
|
7
|
+
// if ~/pinokio/prototype doesn't exist, clone
|
|
8
|
+
let exists = await this.kernel.exists("plugin")
|
|
9
|
+
if (!exists) {
|
|
10
|
+
await this.kernel.exec({
|
|
11
|
+
message: "git clone https://github.com/peanutcocktail/plugin",
|
|
12
|
+
path: this.kernel.homedir
|
|
13
|
+
}, (e) => {
|
|
14
|
+
process.stdout.write(e.raw)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let plugin_dir = path.resolve(this.kernel.homedir, "plugin")
|
|
19
|
+
let pinokiojs = path.resolve(plugin_dir, "pinokio.js")
|
|
20
|
+
this.config = await this.kernel.require(pinokiojs)
|
|
21
|
+
}
|
|
22
|
+
async update() {
|
|
23
|
+
let exists = await this.kernel.exists("plugin")
|
|
24
|
+
if (!exists) {
|
|
25
|
+
await this.kernel.exec({
|
|
26
|
+
message: "git pull",
|
|
27
|
+
path: this.kernel.path("plugin")
|
|
28
|
+
}, (e) => {
|
|
29
|
+
process.stdout.write(e.raw)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
module.exports = Plugin
|
package/kernel/router/index.js
CHANGED
|
@@ -12,7 +12,7 @@ class LocalhostVariableRouter extends Processor {
|
|
|
12
12
|
let local_variables_for_script = local[script_path]
|
|
13
13
|
for(let key in local_variables_for_script) {
|
|
14
14
|
let val = local_variables_for_script[key]
|
|
15
|
-
if (val.startsWith("http")) {
|
|
15
|
+
if (typeof val === "string" && val.startsWith("http")) {
|
|
16
16
|
let dial = val.replace(/https?:\/\//, '')
|
|
17
17
|
let name = this.api_name(this.router.kernel.platform, this.router.kernel.homedir, script_path)
|
|
18
18
|
if (this.has_port(dial)) {
|