pinokiod 3.9.2 → 3.9.12

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.
@@ -29,18 +29,53 @@ class Api {
29
29
  this.lproxy = new Lproxy()
30
30
  }
31
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")
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
- 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)
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/${name}/browse#n1`
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
- let requestPath = this.filePath(req.params.uri)
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
- delete this.running[requestPath]
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)
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[request.path] || {}),
611
- local: (this.kernel.memory.local[request.path] || {}),
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.rpc[request.path] = rawrpc
636
- this.kernel.memory.args[request.path] = args
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
@@ -662,6 +715,7 @@ class Api {
662
715
  if (rpc.method) {
663
716
 
664
717
  rpc.parent = {
718
+ id: request.id,
665
719
  uri: request.uri,
666
720
  path: request.path,
667
721
  git: this.parentGitURI(request.path),
@@ -706,8 +760,8 @@ class Api {
706
760
 
707
761
  rpc.args = args
708
762
 
709
- this.kernel.memory.rpc[request.path].current = rpc.current
710
- this.kernel.memory.rpc[request.path].total = rpc.total
763
+ this.kernel.memory.rpc[id].current = rpc.current
764
+ this.kernel.memory.rpc[id].total = rpc.total
711
765
 
712
766
  // this.kernel.memory.rpc[request.path] = rpc
713
767
  // this.kernel.memory.args[request.path] = args
@@ -763,7 +817,7 @@ class Api {
763
817
  // last call
764
818
  if (script.daemon) {
765
819
  this.ondata({
766
- id: request.path,
820
+ id: request.id || request.path,
767
821
  type: "start",
768
822
  data: {
769
823
  title: "Started",
@@ -772,22 +826,30 @@ class Api {
772
826
  })
773
827
  } else {
774
828
  // no next rpc to execute. Finish
775
- this.kernel.memory.local[request.path] = {}
776
- this.kernel.memory.rpc[request.path] = null
777
- this.kernel.memory.input[request.path] = null
778
- this.kernel.memory.args[request.path] = null
829
+ this.kernel.memory.local[id] = {}
830
+ this.kernel.memory.rpc[id] = null
831
+ this.kernel.memory.input[id] = null
832
+ this.kernel.memory.args[id] = null
779
833
  this.ondata({
780
- id: request.path,
834
+ id: request.id || request.path,
781
835
  type: "event",
782
836
  data: "stop",
783
837
  rpc,
784
838
  rawrpc
785
839
  })
786
- await this.stop({
787
- params: {
788
- uri: request.path
789
- }
790
- })
840
+ if (request.id) {
841
+ await this.stop({
842
+ params: {
843
+ id: request.id
844
+ }
845
+ })
846
+ } else {
847
+ await this.stop({
848
+ params: {
849
+ uri: request.path
850
+ }
851
+ })
852
+ }
791
853
  console.log(">>>>>> STOPPED", request)
792
854
  }
793
855
  return { request, input: null, step: rpc.next, total: script.run.length, args }
@@ -803,7 +865,7 @@ class Api {
803
865
 
804
866
  try {
805
867
  this.ondata({
806
- id: request.path,
868
+ id: request.id || request.path,
807
869
  type: "start",
808
870
  data: rpc
809
871
  })
@@ -823,7 +885,7 @@ class Api {
823
885
  // 11. actually make the rpc call
824
886
  result = await this.run(resolved.method, rpc, (stream, type) => {
825
887
  let m = {
826
- id: request.path,
888
+ id: request.id || request.path,
827
889
  caller: request.caller,
828
890
  type: (type ? type : "stream"),
829
891
  index: i,
@@ -850,7 +912,7 @@ class Api {
850
912
 
851
913
  if (result && result.error) {
852
914
  this.ondata({
853
- id: request.path,
915
+ id: request.id || request.path,
854
916
  type: "error",
855
917
  data: result.response,
856
918
  event: result.error,
@@ -901,9 +963,9 @@ class Api {
901
963
  if (chunks.length === 2) {
902
964
  let name = chunks[1]
903
965
  if (chunks[0] === "local") {
904
- this.kernel.memory.local[request.path][name] = filled_returns[name]
966
+ this.kernel.memory.local[id][name] = filled_returns[name]
905
967
  } else if (chunks[0] === "global") {
906
- this.kernel.memory.global[request.path][name] = filled_returns[name]
968
+ this.kernel.memory.global[id][name] = filled_returns[name]
907
969
  }
908
970
  }
909
971
  }
@@ -918,22 +980,22 @@ class Api {
918
980
  if (chunks.length === 2) {
919
981
  let name = chunks[1]
920
982
  if (chunks[0] === "local") {
921
- if (!this.kernel.memory.local[request.path]) {
922
- this.kernel.memory.local[request.path] = {}
983
+ if (!this.kernel.memory.local[id]) {
984
+ this.kernel.memory.local[id] = {}
923
985
  }
924
- this.kernel.memory.local[request.path][name] = result
986
+ this.kernel.memory.local[id][name] = result
925
987
  } else if (chunks[0] === "global") {
926
- if (!this.kernel.memory.global[request.path]) {
927
- this.kernel.memory.global[request.path] = {}
988
+ if (!this.kernel.memory.global[id]) {
989
+ this.kernel.memory.global[id] = {}
928
990
  }
929
- this.kernel.memory.global[request.path][name] = result
991
+ this.kernel.memory.global[id][name] = result
930
992
  }
931
993
  }
932
994
  }
933
995
  }
934
996
 
935
997
  this.ondata({
936
- id: request.path,
998
+ id: request.id || request.path,
937
999
  index: i,
938
1000
  total,
939
1001
  type: "result",
@@ -949,7 +1011,7 @@ class Api {
949
1011
  html = `<b>Run complete</b><br>${rawrpc.uri ? '<b>uri</b> ' + rawrpc.uri + '<br>' : ''}<b>method</b> ${rawrpc.method}`
950
1012
  }
951
1013
  this.ondata({
952
- id: request.path,
1014
+ id: request.id || request.path,
953
1015
  type: "notify",
954
1016
  data :{
955
1017
  html,
@@ -957,7 +1019,7 @@ class Api {
957
1019
  })
958
1020
  } else if (typeof rpc.notify === "object") {
959
1021
  this.ondata({
960
- id: request.path,
1022
+ id: request.id || request.path,
961
1023
  type: "notify",
962
1024
  data: {
963
1025
  html: rpc.notify.html,
@@ -971,7 +1033,12 @@ class Api {
971
1033
 
972
1034
  // if not running, don't progress any further
973
1035
  // (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 (!this.running[request.path]) {
1036
+ if (request.id) {
1037
+ if (!this.running[request.id]) {
1038
+ console.log("The script was already canceled")
1039
+ return
1040
+ }
1041
+ } else if (!this.running[request.path]) {
975
1042
  console.log("The script was already canceled")
976
1043
  return
977
1044
  }
@@ -984,7 +1051,7 @@ class Api {
984
1051
  // if not daemon
985
1052
  if (script.daemon) {
986
1053
  this.ondata({
987
- id: request.path,
1054
+ id: request.id || request.path,
988
1055
  type: "start",
989
1056
  data: {
990
1057
  title: "Started",
@@ -994,20 +1061,27 @@ class Api {
994
1061
  return { request, input: result, step: rpc.next, total: script.run.length, args }
995
1062
  } else {
996
1063
  // no next rpc to execute. Finish
997
- this.kernel.memory.local[request.path] = {}
1064
+ this.kernel.memory.local[id] = {}
998
1065
  this.ondata({
999
- id: request.path,
1066
+ id: request.id || request.path,
1000
1067
  type: "event",
1001
1068
  data: "stop",
1002
1069
  rpc,
1003
1070
  rawrpc
1004
1071
  })
1005
- await this.stop({
1006
- params: {
1007
- uri: request.path
1008
- }
1009
- })
1010
- console.log("<<<<<< STOPPED", request)
1072
+ if (request.id) {
1073
+ await this.stop({
1074
+ params: {
1075
+ id: request.id
1076
+ }
1077
+ })
1078
+ } else {
1079
+ await this.stop({
1080
+ params: {
1081
+ uri: request.path
1082
+ }
1083
+ })
1084
+ }
1011
1085
  return { request, input: result, step: rpc.next, total: script.run.length, args }
1012
1086
  }
1013
1087
 
@@ -1020,7 +1094,7 @@ class Api {
1020
1094
  } catch (e) {
1021
1095
  console.log("<>ERROR", e)
1022
1096
  this.ondata({
1023
- id: request.path,
1097
+ id: request.id || request.path,
1024
1098
  type: "error",
1025
1099
  data: e.stack,
1026
1100
  rpc,
@@ -1031,7 +1105,7 @@ class Api {
1031
1105
  }
1032
1106
  } else {
1033
1107
  this.ondata({
1034
- id: request.path,
1108
+ id: request.id || request.path,
1035
1109
  type: "error",
1036
1110
  data: "missing RPC attribute: method",
1037
1111
  rpc,
@@ -1062,15 +1136,17 @@ class Api {
1062
1136
  this.queues[queue_id] = fastq.promise(async ({ request, rawrpc, input, step, total, cwd, args }) => {
1063
1137
  try {
1064
1138
  let response = await this.step(request, rawrpc, input, step, total, args)
1139
+ console.log("Handle Response", { request, response })
1065
1140
  if (response) {
1066
1141
  if (response.rawrpc) {
1067
1142
  this.queue(response.request, response.rawrpc, response.input, response.step, response.total, cwd, args)
1068
1143
  } else {
1144
+ let id = response.request.id || response.request.path
1069
1145
  if (response.request.caller) {
1070
1146
  if (this.done[response.request.path]) {
1071
1147
  this.done[response.request.path]({
1072
- global: (this.kernel.memory.global[response.request.path] || {}),
1073
- local: (this.kernel.memory.local[response.request.path] || {}),
1148
+ global: (this.kernel.memory.global[id] || {}),
1149
+ local: (this.kernel.memory.local[id] || {}),
1074
1150
  //return: response.input
1075
1151
  input: response.input
1076
1152
  })
@@ -1078,10 +1154,11 @@ class Api {
1078
1154
  }
1079
1155
  }
1080
1156
  } else {
1157
+ let id = request.id || request.path
1081
1158
  if (this.done[request.path]) {
1082
1159
  this.done[request.path]({
1083
- global: (this.kernel.memory.global[request.path] || {}),
1084
- local: (this.kernel.memory.local[request.path] || {}),
1160
+ global: (this.kernel.memory.global[id] || {}),
1161
+ local: (this.kernel.memory.local[id] || {}),
1085
1162
  })
1086
1163
  }
1087
1164
  }
@@ -1139,7 +1216,7 @@ class Api {
1139
1216
 
1140
1217
  if (queueSize > 0) {
1141
1218
  this.ondata({
1142
- id: request.path,
1219
+ id: request.id || request.path,
1143
1220
  type: "info",
1144
1221
  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
1222
  })
@@ -1181,6 +1258,7 @@ class Api {
1181
1258
  }
1182
1259
  }
1183
1260
  async process(request, done) {
1261
+ console.log("Process", request)
1184
1262
  /**************************************************************
1185
1263
  *
1186
1264
  * req := { uri: <relative path>|<absolute path>|<url> }
@@ -1245,7 +1323,7 @@ class Api {
1245
1323
  await this.launch(request, p)
1246
1324
  } else {
1247
1325
  this.ondata({
1248
- id: request.path,
1326
+ id: request.id || request.path,
1249
1327
  type: "error",
1250
1328
  data: "uri doesn't exist \r\n" + JSON.stringify(request, null, 2)
1251
1329
  })
@@ -1256,7 +1334,7 @@ class Api {
1256
1334
 
1257
1335
  if (!script) {
1258
1336
  this.ondata({
1259
- id: request.path,
1337
+ id: request.id || request.path,
1260
1338
  type: "error",
1261
1339
  data: "the endpoint does not exist: " + request.uri,
1262
1340
  })
@@ -1265,15 +1343,20 @@ class Api {
1265
1343
  //if (script.run && Array.isArray(script.run)) {
1266
1344
  if (script.run) {
1267
1345
 
1268
- this.running[request.path] = true
1346
+ if (request.id) {
1347
+ this.running[request.id] = true
1348
+ this.done[request.id] = done
1349
+ } else if (request.path) {
1350
+ this.running[request.path] = true
1351
+ this.done[request.path] = done
1352
+ }
1269
1353
 
1270
- this.done[request.path] = done
1271
1354
 
1272
1355
  this.queue(request, script.run[0], request.input, 0, script.run.length, cwd, request.input)
1273
1356
 
1274
1357
  } else {
1275
1358
  this.ondata({
1276
- id: request.path,
1359
+ id: request.id || request.path,
1277
1360
  type: "error",
1278
1361
  data: "missing attribute: run"
1279
1362
  })
@@ -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][req.parent.path]
55
+ let old = kernel.memory[type][parent_id]
55
56
  old = rm(old, keys)
56
- kernel.memory[type][req.parent.path] = old
57
+ kernel.memory[type][parent_id] = old
57
58
 
58
59
  }
59
60
  }
@@ -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][req.parent.path]
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][req.parent.path] = old
106
+ kernel.memory[type][parent_id] = old
105
107
 
106
108
  // if (!kernel.memory[type][req.uri]) {
107
109
  // kernel.memory[type][req.uri] = {}
@@ -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
  }
@@ -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
@@ -26,6 +26,9 @@ class Info {
26
26
  Error.prepareStackTrace = _prepareStackTrace;
27
27
  }
28
28
  }
29
+ cwd() {
30
+ return path.dirname(this.caller())
31
+ }
29
32
  caller () {
30
33
  return this.callsites()[2].getFileName()
31
34
  }
@@ -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
@@ -217,7 +217,7 @@ class Router {
217
217
  // console.log("Caddy Response", { response })
218
218
  this.old_config = this.config
219
219
  } catch (e) {
220
- console.log("EEEEEEEEEEEEE", e)
220
+ console.log("Caddy Request Failed", e.cause)
221
221
  }
222
222
  }
223
223
  }
@@ -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)) {
@@ -12,7 +12,7 @@ class PeerVariableRouter extends Processor {
12
12
  let local_variables = peer.memory.local[script_path]
13
13
  for(let key in local_variables) {
14
14
  let val = local_variables[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(peer.platform, peer.home, script_path)
18
18
  if (this.has_port(dial)) {