pinokiod 1.2.25 → 1.2.27

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.
@@ -40,7 +40,6 @@ class Api {
40
40
  this.checkProxy({ uri, name })
41
41
  // if the name exists, throw error
42
42
  // if the uri exists, throw error
43
- console.log("startProxy", { scriptPath, uri, proxies: this.proxies })
44
43
  let proxy_uri = await this.lproxy.start(uri, options)
45
44
  if (this.proxies[scriptPath]) {
46
45
  this.proxies[scriptPath].push({ target: uri, proxy: proxy_uri, name})
@@ -53,7 +52,6 @@ class Api {
53
52
  }
54
53
  }
55
54
  stopProxy(config) {
56
- console.log("stopProxy", { config, proxies: this.proxies })
57
55
  if (config.script) {
58
56
  // stop all proxies for the script
59
57
  if (this.proxies[config.script]) {
@@ -76,10 +74,8 @@ class Api {
76
74
  })
77
75
  }
78
76
  }
79
- console.log("stopped", { proxies: this.proxies })
80
77
  }
81
78
  async init() {
82
- console.log("api.init", { homedir: this.kernel.homedir })
83
79
  if (this.kernel.homedir) {
84
80
  this.userdir = path.resolve(this.kernel.homedir, "api")
85
81
  await fs.promises.mkdir(this.userdir, { recusrive: true, }).catch((e) => { })
@@ -88,10 +84,14 @@ class Api {
88
84
  }
89
85
  respond(req) {
90
86
  let requestPath = this.filePath(req.uri)
91
- this.waiter[requestPath].resolve(req.response)
92
- delete this.waiter[requestPath]
87
+ console.log("RESPOND", { req, waiter: this.waiter, requestPath })
88
+ if (this.waiter[requestPath]) {
89
+ this.waiter[requestPath].resolve(req.response)
90
+ delete this.waiter[requestPath]
91
+ }
93
92
  }
94
93
  wait(scriptPath) {
94
+ console.log("WAIT", scriptPath)
95
95
  // need to reject if everything fails
96
96
  return new Promise((resolve, reject) => {
97
97
  this.waiter[scriptPath] = { resolve, reject }
@@ -102,7 +102,6 @@ class Api {
102
102
  return result
103
103
  }
104
104
  async stop(req, ondata) {
105
- console.log("STOP")
106
105
  // 1. set the "stop" flag for the uri, so the next execution in the queue for the uri will NOT queue another task
107
106
  // 2. stream a message closing the socket
108
107
 
@@ -204,7 +203,6 @@ class Api {
204
203
  }
205
204
  }
206
205
  }
207
- console.log("gitPath", this.gitPath)
208
206
  }
209
207
  denormalize(gitRemote) {
210
208
  let denormalized
@@ -275,6 +273,19 @@ class Api {
275
273
  return null
276
274
  }
277
275
  }
276
+ getGitURI(uri) {
277
+ // git url
278
+ // test to see if any of the gitPaths match partially
279
+ let chunks = uri.split("/")
280
+ let collect = []
281
+ for(let chunk of chunks) {
282
+ collect.push(chunk)
283
+ if (chunk.endsWith(".git")) {
284
+ break
285
+ }
286
+ }
287
+ return collect.join("/")
288
+ }
278
289
 
279
290
  resolveGitURI(uri) {
280
291
  // git url
@@ -474,9 +485,9 @@ class Api {
474
485
  return mod
475
486
 
476
487
  }
477
- async step (request, rawrpc, input, i, total) {
488
+ async step (request, rawrpc, input, i, total, args) {
478
489
 
479
- console.log("STEP", { request, rawrpc, input, i, total })
490
+ await this.kernel.api.init()
480
491
 
481
492
  // clear global regular expression object RegExp.lastMatch (memory leak prevention)
482
493
  let r = /\s*/g.exec("");
@@ -485,6 +496,7 @@ class Api {
485
496
 
486
497
  let memory = {
487
498
  input,
499
+ args,
488
500
  global: (this.kernel.memory.global[request.path] || {}),
489
501
  local: (this.kernel.memory.local[request.path] || {}),
490
502
  key: this.kernel.memory.key,
@@ -527,14 +539,12 @@ class Api {
527
539
  // replace {{{ }}} with {{ }}
528
540
  rpc = this.kernel.template.flatten(rpc)
529
541
 
530
-
531
542
  // 6. rpc must have method names
532
543
  if (rpc.method) {
533
544
 
534
545
  // 7. resolve the rpc
535
546
  let resolved = await this.resolveMethod(rpc, cwd)
536
547
 
537
-
538
548
  // 8. the endpoint must exist
539
549
  if (!resolved.method) {
540
550
  this.ondata({
@@ -569,6 +579,8 @@ class Api {
569
579
 
570
580
  rpc.input = input
571
581
 
582
+ rpc.args = args
583
+
572
584
  if (i < script.run.length-1) {
573
585
  rpc.next = i+1
574
586
  } else {
@@ -576,11 +588,11 @@ class Api {
576
588
  }
577
589
 
578
590
  if (rpc.hasOwnProperty("when")) {
579
- console.log("rpc.when", { rpc })
580
591
  // if rpc.when is false, don't run this and go to the next step
581
592
  if (!rpc.when) {
582
593
  if (typeof rpc.next === "undefined" || rpc.next === null) {
583
594
  // last call
595
+ console.log("SCRIPT", script)
584
596
  if (script.daemon) {
585
597
  this.ondata({
586
598
  id: request.path,
@@ -606,13 +618,12 @@ class Api {
606
618
  }
607
619
  })
608
620
  }
609
- return
621
+ return { request, input: null, step: rpc.next, total: script.run.length, args }
610
622
  } else {
611
623
  // still ongoing
612
624
  let next_rpc = script.run[rpc.next]
613
- console.log("NEXT RPC", next_rpc, i, rpc.next)
614
625
  if (next_rpc) {
615
- return { request, rawrpc: next_rpc, input: null, step: rpc.next, total: script.run.length }
626
+ return { request, rawrpc: next_rpc, input: null, step: rpc.next, total: script.run.length, args }
616
627
  }
617
628
  }
618
629
  }
@@ -630,6 +641,7 @@ class Api {
630
641
  let result = await this.run(resolved.method, rpc, (stream, type) => {
631
642
  let m = {
632
643
  id: request.path,
644
+ caller: request.caller,
633
645
  type: (type ? type : "stream"),
634
646
  index: i,
635
647
  total,
@@ -637,6 +649,17 @@ class Api {
637
649
  rpc,
638
650
  rawrpc
639
651
  }
652
+
653
+ // if (["input", "modal"].includes(m.type)) {
654
+ // // if a message requires user feedback, do not modify id
655
+ // } else {
656
+ // // if a message does not require user feedback
657
+ // // if the current session has a "caller" (parent process),
658
+ // // set the id to request.caller so the terminal prints the logs
659
+ // if (request.caller) {
660
+ // m.id = request.caller
661
+ // }
662
+ // }
640
663
  this.ondata(m)
641
664
  })
642
665
 
@@ -738,8 +761,10 @@ class Api {
738
761
 
739
762
  if (typeof rpc.next === "undefined" || rpc.next === null) {
740
763
 
764
+
741
765
  // kill all connected shells
742
766
  // if not daemon
767
+ console.log("DEF")
743
768
  if (script.daemon) {
744
769
  this.ondata({
745
770
  id: request.path,
@@ -749,6 +774,7 @@ class Api {
749
774
  description: "All scripts finished running. Running in daemon mode..."
750
775
  }
751
776
  })
777
+ return { request, input: result, step: rpc.next, total: script.run.length, args }
752
778
  } else {
753
779
  // no next rpc to execute. Finish
754
780
  this.kernel.memory.local[request.path] = {}
@@ -764,15 +790,17 @@ class Api {
764
790
  uri: request.path
765
791
  }
766
792
  })
793
+ return { request, input: result, step: rpc.next, total: script.run.length, args }
767
794
  }
768
795
 
769
796
  } else {
770
797
  // still going
771
798
  let next_rpc = script.run[rpc.next]
772
- return { request, rawrpc: next_rpc, input: result, step: rpc.next, total: script.run.length }
799
+ return { request, rawrpc: next_rpc, input: result, step: rpc.next, total: script.run.length, args }
773
800
  }
774
801
 
775
802
  } catch (e) {
803
+ console.log("<>ERROR", e)
776
804
  this.ondata({
777
805
  id: request.path,
778
806
  type: "error",
@@ -813,11 +841,26 @@ class Api {
813
841
  this.listeners[name] = undefined
814
842
  }
815
843
  createQueue(queue_id, concurrency) {
816
- this.queues[queue_id] = fastq.promise(async ({ request, rawrpc, input, step, total, cwd }) => {
844
+ this.queues[queue_id] = fastq.promise(async ({ request, rawrpc, input, step, total, cwd, args }) => {
817
845
  try {
818
- let response = await this.step(request, rawrpc, input, step, total)
846
+ console.log("Before step", { request, rawrpc })
847
+ let response = await this.step(request, rawrpc, input, step, total, args)
848
+ console.log("After step", response)
819
849
  if (response) {
820
- this.queue(response.request, response.rawrpc, response.input, response.step, response.total, cwd)
850
+ if (response.rawrpc) {
851
+ this.queue(response.request, response.rawrpc, response.input, response.step, response.total, cwd, args)
852
+ } else {
853
+ if (response.request.caller) {
854
+ if (this.done[response.request.path]) {
855
+ this.done[response.request.path]({
856
+ global: (this.kernel.memory.global[response.request.path] || {}),
857
+ local: (this.kernel.memory.local[response.request.path] || {}),
858
+ //return: response.input
859
+ input: response.input
860
+ })
861
+ }
862
+ }
863
+ }
821
864
  } else {
822
865
  if (this.done[request.path]) {
823
866
  this.done[request.path]({
@@ -831,7 +874,7 @@ class Api {
831
874
  }
832
875
  }, concurrency)
833
876
  }
834
- queue(request, rawrpc, input, step, total, cwd) {
877
+ queue(request, rawrpc, input, step, total, cwd, args) {
835
878
 
836
879
 
837
880
  // 1. only run one queued task at a time (for each api method)
@@ -872,7 +915,8 @@ class Api {
872
915
  input,
873
916
  step,
874
917
  total,
875
- cwd
918
+ cwd,
919
+ args
876
920
  })
877
921
  let queueSize = this.queues[queue_id].length()
878
922
 
@@ -927,19 +971,17 @@ class Api {
927
971
 
928
972
  // request.uri = this.resolvePath(this.userdir, request.uri)
929
973
 
930
- let keypath = path.resolve(this.kernel.homedir, "key.json")
931
- this.kernel.keys = (await this.loader.load(keypath)).resolved
974
+ // let keypath = path.resolve(this.kernel.homedir, "key.json")
975
+ // this.kernel.keys = (await this.loader.load(keypath)).resolved
932
976
 
933
977
  if (request.uri){
934
978
  this.counter++;
935
979
  // API Call
936
980
 
937
981
  request.path = this.resolvePath(this.userdir, request.uri)
938
- console.log("#PROCESS", { request, userdir: this.userdir })
939
982
  let { cwd, script } = await this.resolveScript(request.path)
940
983
  request.cwd = cwd
941
984
 
942
-
943
985
  if (!script) {
944
986
  this.ondata({
945
987
  id: request.path,
@@ -955,7 +997,7 @@ class Api {
955
997
 
956
998
  this.done[request.path] = done
957
999
 
958
- this.queue(request, script.run[0], request.input, 0, script.run.length, cwd)
1000
+ this.queue(request, script.run[0], request.input, 0, script.run.length, cwd, request.input)
959
1001
 
960
1002
  } else {
961
1003
  this.ondata({
@@ -1024,7 +1066,6 @@ class Api {
1024
1066
 
1025
1067
  // get the core script
1026
1068
  let script = (await this.loader.load(scriptpath)).resolved
1027
- console.log("##### ", { scriptpath, script })
1028
1069
 
1029
1070
  // if the sccript is a function, instantiate first
1030
1071
  if (typeof script === "function") {
@@ -1,4 +1,5 @@
1
1
  module.exports = async (req, ondata, kernel) => {
2
+ console.log("INPUT", req)
2
3
  ondata(req.params, "input")
3
4
  let response = await kernel.api.wait(req.parent.path)
4
5
  return response
@@ -9,6 +9,7 @@ module.exports = async (req, ondata, kernel) => {
9
9
  }
10
10
  }
11
11
  */
12
+ console.log("LLOG", req)
12
13
  if (req.params) {
13
14
  if (typeof req.params.raw !== "undefined") {
14
15
  ondata({
@@ -0,0 +1,92 @@
1
+ const path = require('path')
2
+ class Script {
3
+ async run(req, ondata, kernel) {
4
+ /*
5
+ {
6
+ "method": "script.run",
7
+ "params": {
8
+ "hash": <git commit hash>,
9
+ "branch": <git branch>,
10
+ "latest": true|false,
11
+ "uri": <script uri>,
12
+ "params": {
13
+ }
14
+ }
15
+ }
16
+
17
+ => uri resolve
18
+ - relative path
19
+ - absolute path
20
+ - http path
21
+ */
22
+ let uri
23
+ if (req.params.uri.startsWith("http")) {
24
+ uri = req.params.uri
25
+ let modpath = kernel.api.resolveGitURI(uri)
26
+ const repo_uri = kernel.api.getGitURI(uri)
27
+ console.log("repo_uri", repo_uri)
28
+ const urlWithoutProtocol = repo_uri.replace(/^(https?:\/\/)/, '');
29
+ const folderName = urlWithoutProtocol.replace(/[^a-zA-Z0-9_\-]/g, '_');
30
+ if (modpath) {
31
+ let msg = `Path ${uri} already exists at ${modpath}. Continuing...\r\n`
32
+ ondata({ raw: msg })
33
+ } else {
34
+ let msg = `Path ${uri} does not exist. Cloning...\r\n`
35
+ ondata({ raw: msg })
36
+
37
+ // clone
38
+ await kernel.bin.sh({
39
+ message: `git clone ${repo_uri} ${folderName}`,
40
+ path: kernel.api.userdir
41
+ }, ondata)
42
+ }
43
+
44
+ // switch branch
45
+ if (req.params.branch) {
46
+ await kernel.bin.sh({
47
+ message: `git switch ${req.params.branch}`,
48
+ path: kernel.path("api", folderName)
49
+ }, ondata)
50
+ }
51
+ if (req.params.hash) {
52
+ await kernel.bin.sh({
53
+ message: `git switch --detach ${req.params.hash}`,
54
+ path: kernel.path("api", folderName)
55
+ }, ondata)
56
+ }
57
+ if (req.params.latest) {
58
+ await kernel.bin.sh({
59
+ message: `git pull`,
60
+ path: kernel.path("api", folderName)
61
+ }, ondata)
62
+ }
63
+
64
+ await kernel.api.init()
65
+ } else {
66
+ uri = path.resolve(req.cwd, req.params.uri)
67
+ }
68
+ let res = await new Promise((resolve, reject) => {
69
+ kernel.api.process({
70
+ uri,
71
+ input: req.params.params,
72
+ client: req.client,
73
+ caller: req.parent.path,
74
+ }, (r) => {
75
+ resolve(r.input)
76
+ })
77
+ })
78
+ console.log("** RESPONSE", res)
79
+ // need to call api.linkGit() so the git repositories list is up to date
80
+ return res
81
+ }
82
+ async return(req, ondata, kernel) {
83
+ /*
84
+ {
85
+ "method": "script.return",
86
+ "params": <RETURN OBJECT>
87
+ }
88
+ */
89
+ return req.params
90
+ }
91
+ }
92
+ module.exports = Script
package/kernel/index.js CHANGED
@@ -266,7 +266,6 @@ class Kernel {
266
266
  try {
267
267
  await sysinfo.refresh()
268
268
  let info = sysinfo.info
269
- console.log("sysinfo", info)
270
269
  this.template.update(info)
271
270
  this.sysinfo = info
272
271
  } catch (e) {
package/kernel/shell.js CHANGED
@@ -345,7 +345,6 @@ class Shell {
345
345
  this.persistent = params.persistent
346
346
  }
347
347
  this.prompt_pattern = await this.prompt(params.path)
348
- console.log("this.prompt_pattern", this.prompt_pattern)
349
348
  this.cb = cb
350
349
  let r = await this.exec(params)
351
350
  return r
@@ -374,42 +373,28 @@ class Shell {
374
373
 
375
374
  //let re = /([\r\n]+[^\r\n]+)(\1)/gs
376
375
  let re = /(.+)(\1)/gs
377
- console.log("get prompt - pty.spawn", config)
378
376
  let term = pty.spawn(this.shell, this.args, config)
379
- console.log("terminal spawned", term)
380
377
  let ready
381
- console.log("create terminal for prompt")
382
378
  let vt = new Terminal({
383
379
  allowProposedApi: true
384
380
  })
385
381
  let vts = new SerializeAddon()
386
382
  vt.loadAddon(vts)
387
383
 
388
- console.log("start a queue for prompt")
389
384
  let queue = fastq((data, cb) => {
390
- console.log("incoming queue", { data })
391
385
  vt.write(data, () => {
392
- console.log("written")
393
386
  let buf = vts.serialize()
394
- console.log("serialized buf", buf)
395
387
  let re = /(.+)echo pinokio[\r\n]+pinokio[\r\n]+(\1)/gs
396
388
  const match = re.exec(buf)
397
- console.log({ match })
398
389
  if (match && match.length > 0) {
399
390
  let stripped = this.stripAnsi(match[1])
400
- console.log({ match, stripped })
401
391
  const p = stripped
402
392
  .replaceAll(/[\r\n]/g, "")
403
393
  .trim()
404
394
  .replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&');
405
- console.log("matched path", p)
406
- console.log("kill term")
407
395
  term.kill()
408
- console.log("term killed")
409
396
  vt.dispose()
410
- console.log("vt disposed")
411
397
  queue.killAndDrain()
412
- console.log("queue killAndDrained")
413
398
  resolve(p)
414
399
  }
415
400
  })
@@ -419,16 +404,12 @@ class Shell {
419
404
  console.log("onExit", { result })
420
405
  })
421
406
  term.onData((data) => {
422
- console.log("term.onData", { ready, data })
423
407
  if (ready) {
424
- console.log("push to queue", { data })
425
408
  queue.push(data)
426
409
  } else {
427
410
  setTimeout(() => {
428
- console.log("ready?", ready)
429
411
  if (!ready) {
430
412
  ready = true
431
- console.log("write", `echo pinokio${os.EOL}echo pinokio${os.EOL}`)
432
413
  term.write(`echo pinokio${os.EOL}echo pinokio${os.EOL}`)
433
414
  }
434
415
  }, 500)
@@ -529,8 +510,6 @@ class Shell {
529
510
  conda_name = "base"
530
511
  }
531
512
 
532
- console.log("CONDA STEP 1", { conda: params.conda, conda_path, conda_name, conda_python })
533
-
534
513
 
535
514
  // 2. conda_activation
536
515
  let conda_activation = []
@@ -592,7 +571,6 @@ class Shell {
592
571
  conda_activation = []
593
572
  }
594
573
 
595
- console.log("CONDA STEP 2", { conda_activation })
596
574
 
597
575
 
598
576
  // Update env setting
@@ -813,7 +791,6 @@ ${cleaned}
813
791
  let termination_prompt_re = new RegExp(this.prompt_pattern + "[ \r\n]*$", "g")
814
792
  let line = cleaned.replaceAll(/[\r\n]/g, "")
815
793
  let test = line.match(termination_prompt_re)
816
- console.log({ termination_prompt_re, cleaned, line, test })
817
794
  if (test) {
818
795
  let cache = cleaned
819
796
  let cached_msg = msg
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.2.25",
3
+ "version": "1.2.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -297,9 +297,6 @@ class Server {
297
297
  args: "-c conda-forge"
298
298
  }, {
299
299
  name: "py"
300
- }, {
301
- gpu: "nvidia",
302
- name: "cuda"
303
300
  }]
304
301
  let platform = os.platform()
305
302
  if (platform === "win32") {
@@ -310,6 +307,11 @@ class Server {
310
307
  name: "vs"
311
308
  })
312
309
  }
310
+ if (this.kernel.gpu === "nvidia") {
311
+ requirements.push({
312
+ name: "cuda"
313
+ })
314
+ }
313
315
  let requirements_pending = !this.kernel.bin.installed_initialized
314
316
 
315
317
 
@@ -554,9 +556,6 @@ class Server {
554
556
  args: "-c conda-forge"
555
557
  }, {
556
558
  name: "py"
557
- }, {
558
- gpu: "nvidia",
559
- name: "cuda"
560
559
  }]
561
560
  let platform = os.platform()
562
561
  if (platform === "win32") {
@@ -569,6 +568,11 @@ class Server {
569
568
  name: "brew"
570
569
  })
571
570
  }
571
+ if (this.kernel.gpu === "nvidia") {
572
+ requirements.push({
573
+ name: "cuda"
574
+ })
575
+ }
572
576
  // if (platform === "linux") {
573
577
  // requirements.push({
574
578
  // name: "brew"
@@ -1067,7 +1071,11 @@ class Server {
1067
1071
  notRunning,
1068
1072
  readme,
1069
1073
  filepath,
1070
- items: items.map((x) => {
1074
+ items: items
1075
+ // .filter((x) => {
1076
+ // return x.type !== "lib"
1077
+ // })
1078
+ .map((x) => {
1071
1079
  //let name = (x.name.startsWith("0x") ? Buffer.from(x.name.slice(2), "hex").toString() : x.name)
1072
1080
  let name
1073
1081
  let description
@@ -1156,8 +1164,6 @@ class Server {
1156
1164
  menuitem.menu = m.menu
1157
1165
  }
1158
1166
 
1159
- console.log("MENUITEM", menuitem)
1160
-
1161
1167
  if (menuitem.href && !menuitem.href.startsWith("http")) {
1162
1168
 
1163
1169
  // href resolution
@@ -1189,7 +1195,6 @@ class Server {
1189
1195
 
1190
1196
  // check running
1191
1197
  let fullpath = this.kernel.path(menuitem.src.slice(1))
1192
- console.log("fullpath", fullpath, menuitem.src, this.kernel.api.running)
1193
1198
  if (this.kernel.api.running[fullpath]) {
1194
1199
  menuitem.running = true
1195
1200
  }
@@ -1205,7 +1210,6 @@ class Server {
1205
1210
  let link = p.split(/[\/\\]/).filter((x) => { return x }).join("/")
1206
1211
  let uri = "~/api/" + name + "/" + link
1207
1212
 
1208
- console.log("*uri", uri)
1209
1213
  config.menu[i].action.uri = uri
1210
1214
  }
1211
1215
  }
@@ -1266,8 +1270,6 @@ class Server {
1266
1270
  }
1267
1271
  } else if (menuitem.hasOwnProperty("text")) {
1268
1272
 
1269
- console.log("processing", menuitem)
1270
-
1271
1273
  if (menuitem.hasOwnProperty("icon")) {
1272
1274
  menuitem.html = `<i class="${menuitem.icon}"></i> ${menuitem.text}`
1273
1275
  } else {
@@ -1287,7 +1289,6 @@ class Server {
1287
1289
  }
1288
1290
  }
1289
1291
  }
1290
- console.log("menu item", config.menu[i])
1291
1292
  if (config.menu[i].popout) {
1292
1293
  config.menu[i].target = "_blank"
1293
1294
  } else {
@@ -1311,22 +1312,17 @@ class Server {
1311
1312
 
1312
1313
 
1313
1314
 
1314
- console.log("config", JSON.stringify(config,null,2))
1315
-
1316
1315
 
1317
1316
  // get all proxies that belong to this repository
1318
1317
  let childProxies = []
1319
- console.log("this.kernel.api.proxies=", this.kernel.api.proxies)
1320
1318
  for(let scriptPath in this.kernel.api.proxies) {
1321
1319
  let proxies = this.kernel.api.proxies[scriptPath]
1322
- console.log("PROXIES", proxies)
1323
1320
  for(let proxy of proxies) {
1324
1321
  if (scriptPath.startsWith(this.kernel.path("api", name))) {
1325
1322
  childProxies.push(proxy)
1326
1323
  }
1327
1324
  }
1328
1325
  }
1329
- console.log({ childProxies })
1330
1326
 
1331
1327
  let proxyMenu = []
1332
1328
  for(let proxy of childProxies) {
@@ -1336,7 +1332,6 @@ class Server {
1336
1332
  href: proxy.proxy
1337
1333
  })
1338
1334
  }
1339
- console.log({ proxyMenu })
1340
1335
  config.menu = proxyMenu.concat(config.menu)
1341
1336
 
1342
1337
 
@@ -1925,13 +1920,10 @@ class Server {
1925
1920
 
1926
1921
  let uri = this.kernel.path("api")
1927
1922
  await this.renderMenu(uri, name, config, [])
1928
-
1929
- console.log("#CONFIG", JSON.stringify(config, null, 2))
1930
1923
  }
1931
1924
 
1932
1925
 
1933
1926
  ejs.renderFile(path.resolve(__dirname, "views/partials/menu.ejs"), { menu: config.menu }, (err, html) => {
1934
- console.log("html", html)
1935
1927
  res.send(html)
1936
1928
  })
1937
1929
 
@@ -84,6 +84,7 @@ class Socket {
84
84
  this.ws.addEventListener('message', (message) => {
85
85
  // console.log("message", message)
86
86
  const packet = JSON.parse(message.data);
87
+ console.log("PACKET", packet)
87
88
  ondata(packet)
88
89
  });
89
90
  this.ws.addEventListener('close', () => {
package/server/socket.js CHANGED
@@ -17,6 +17,7 @@ class Socket {
17
17
  });
18
18
  ws.on('message', async (message) => {
19
19
  const req = JSON.parse(message);
20
+ console.log("MESSAGE", req)
20
21
  if (req.response) {
21
22
  this.parent.kernel.api.respond(req)
22
23
  } else {
@@ -94,6 +95,8 @@ class Socket {
94
95
  this.subscriptions.get(id).add(ws);
95
96
  }
96
97
  trigger(e) {
98
+
99
+ // send to id session
97
100
  let id
98
101
  if (e.kernel) {
99
102
  id = e.id
@@ -108,16 +111,30 @@ class Socket {
108
111
  if (subscriber.readyState === WebSocket.OPEN) {
109
112
  delete e.rpc
110
113
  delete e.rawrpc
111
- // if (e.data && e.data.cleaned) delete e.data.cleaned
112
- // if (e.data && e.data.state) delete e.data.state
113
114
  subscriber.send(JSON.stringify(e))
114
115
  }
115
116
  });
116
- } else {
117
- // if (!this.buffer[id]) {
118
- // this.buffer[id] = []
119
- // }
120
- // this.buffer[id].push(e)
117
+ }
118
+
119
+ // send to caller session
120
+ if (e.caller) {
121
+ let caller
122
+ if (e.kernel) {
123
+ caller = e.caller
124
+ } else {
125
+ caller = this.parent.kernel.api.filePath(e.caller)
126
+ }
127
+
128
+ const subscribers = this.subscriptions.get(caller) || new Set();
129
+ if (subscribers.size > 0) {
130
+ subscribers.forEach((subscriber) => {
131
+ if (subscriber.readyState === WebSocket.OPEN) {
132
+ delete e.rpc
133
+ delete e.rawrpc
134
+ subscriber.send(JSON.stringify(e))
135
+ }
136
+ });
137
+ }
121
138
  }
122
139
  }
123
140
  }
@@ -232,6 +232,7 @@ document.addEventListener("DOMContentLoaded", async () => {
232
232
  // </div>`
233
233
  }
234
234
  } else if (packet.type === "stream") {
235
+ console.log("STREAM", packet)
235
236
  if (packet.data.raw) {
236
237
  this.term.write(packet.data.raw)
237
238
  } else if (packet.data.json) {
@@ -245,6 +246,7 @@ document.addEventListener("DOMContentLoaded", async () => {
245
246
  document.querySelector(".run .starting").classList.add("hidden")
246
247
  document.querySelector(".run .stop").classList.remove("hidden")
247
248
  } else if (packet.type === 'disconnect') {
249
+ console.log("DISCONNECT", packet)
248
250
  refreshParent(packet)
249
251
  reloadMemory()
250
252
  this.term.write("\r\nDisconnected...\r\n")
@@ -297,7 +299,9 @@ document.addEventListener("DOMContentLoaded", async () => {
297
299
  }
298
300
  this.socket.respond({
299
301
  response: {},
300
- uri: "~" + location.pathname,
302
+ // uri: "~" + location.pathname,
303
+ uri: packet.id
304
+ // uri: (packet.caller ? packet.caller : packet.id)
301
305
  })
302
306
  } else if (packet.type === 'wait') {
303
307
  await WaitModal(packet.data)
@@ -305,7 +309,9 @@ document.addEventListener("DOMContentLoaded", async () => {
305
309
  await SimpleModal(packet.data)
306
310
  this.socket.respond({
307
311
  response: {},
308
- uri: "~" + location.pathname,
312
+ //uri: "~" + location.pathname,
313
+ uri: packet.id
314
+ // uri: (packet.caller ? packet.caller : packet.id)
309
315
  })
310
316
  } else if (packet.type === "input") {
311
317
  let params = packet.data
@@ -319,7 +325,9 @@ document.addEventListener("DOMContentLoaded", async () => {
319
325
  if (input) {
320
326
  this.socket.respond({
321
327
  response: input,
322
- uri: "~" + location.pathname,
328
+ uri: packet.id
329
+ // uri: "~" + location.pathname,
330
+ // uri: (packet.caller ? packet.caller : packet.id)
323
331
  })
324
332
  }
325
333
  /*
@@ -443,6 +451,7 @@ document.addEventListener("DOMContentLoaded", async () => {
443
451
  document.querySelector(".run .stop").classList.add("hidden")
444
452
 
445
453
  } else if (packet.type === "event") {
454
+ console.log("EVENT", packet)
446
455
  if (packet.data === "stop") {
447
456
  document.querySelector("footer").innerHTML = "<b>Ready</b>"
448
457
  setTimeout(() => {