pinokiod 1.1.24 → 1.1.26

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.
@@ -240,6 +240,26 @@ class Api {
240
240
  }
241
241
  return null
242
242
  }
243
+ resolveBrowserPath(uri) {
244
+ let repos = Object.keys(this.gitPath)
245
+ let matched_repo = repos.filter((repo) => {
246
+ return uri.includes(repo)
247
+ })
248
+ if (matched_repo.length > 0) {
249
+ let repo_uri = matched_repo[0]
250
+
251
+ let relative_path = uri
252
+ .replace(repo_uri, "") // remove the git repo uri
253
+ .slice(1) // remove the leading '/' for relative path
254
+
255
+ let repopath = this.gitPath[repo_uri]
256
+ let reponame = path.basename(repopath)
257
+
258
+ return `/pinokio/browser/${reponame}/${relative_path}`
259
+ } else {
260
+ return null
261
+ }
262
+ }
243
263
 
244
264
  resolveWebPath(uri) {
245
265
  let repos = Object.keys(this.gitPath)
@@ -682,6 +702,7 @@ class Api {
682
702
  // kill all connected shells
683
703
  // if not daemon
684
704
  if (script.daemon) {
705
+ console.log("## DONE")
685
706
  this.ondata({
686
707
  id: request.path,
687
708
  type: "start",
@@ -0,0 +1,5 @@
1
+ module.exports = async (req, ondata, kernel) => {
2
+ ondata(req.params, "modal")
3
+ let response = await kernel.api.wait(req.parent.path)
4
+ return response
5
+ }
@@ -1,4 +1,126 @@
1
+ const waitOn = require('wait-on');
1
2
  class Process {
3
+ // async start(req, ondata, kernel) {
4
+ // /*
5
+ // req := {
6
+ // method: "process.start",
7
+ // params: {
8
+ // uri: "https://github.com/cocktailpeanutlabs/comfyui.git/start.js",
9
+ // html: "please install ollama",
10
+ // }
11
+ // }
12
+ // */
13
+ // if (kernel.running(req.params.uri)) {
14
+ // // nothing
15
+ // } else {
16
+ // // if exists
17
+ // let uri = req.params.uri
18
+ // let filePath = kernel.api.filePath(uri)
19
+ // if (kernel.exists(filePath)) {
20
+ // // run script
21
+ // await kernel.api.init()
22
+ // console.log("start process", uri)
23
+ // await kernel.api.process({ uri })
24
+ // console.log("process finished")
25
+ // } else {
26
+ // // display html notify
27
+ // let repo = new URL(uri)
28
+ // let href = `https://pinokio.computer/item?uri=${repo}`
29
+ // ondata({
30
+ // html: req.params.html,
31
+ // href,
32
+ // target: "_blank",
33
+ // }, "notify")
34
+ // }
35
+ // }
36
+ // }
37
+ // async run (req, ondata, kernel) {
38
+ // /*
39
+ // // if uri is not specified => just wait
40
+ // req := {
41
+ // method: "process.wait",
42
+ // params: {
43
+ // wait: <waitOn object>,
44
+ // href: "https://ollama.com",
45
+ // html: "please install ollama",
46
+ // }
47
+ // }
48
+ //
49
+ // // if uri is specified => it's pinokio script
50
+ // 1. if the wait condition is met => return immediately
51
+ // 2. if the wait condition is not met
52
+ // 2.1. if the script exists
53
+ // run the script
54
+ // and wait for the wait condition
55
+ // 2.2. if the script does not exist
56
+ // display the 'message' and the 'link'
57
+ //
58
+ // req := {
59
+ // method: "process.wait",
60
+ // params: {
61
+ // start: "https://github.com/cocktailpeanutlabs/comfyui.git/start.js",
62
+ // wait: <waitOn object>,
63
+ // html: "start comfyui",
64
+ // }
65
+ // }
66
+ // */
67
+ //
68
+ // if (req.params) {
69
+ // if (req.params.wait) {
70
+ //
71
+ // await new Promise((resolve, reject) => {
72
+ // let options = req.params.wait
73
+ // waitOn(options).then(() => {
74
+ // resolve()
75
+ // })
76
+ //
77
+ // // 1. if there's a script attribute
78
+ // // 1.0. check if the script repo exists
79
+ // // => if exists, go to the next step
80
+ // // => if not exists, display the message and the link
81
+ // // 1.1. check if the script is running
82
+ // // => if running, don't do anything => waitOn() will automatically return
83
+ // // => if not running, start the script
84
+ // // 1.2. check if the script is not repo exists
85
+ // // 2. if there's no script attribute => display the message and the link
86
+ // if (req.params.start) {
87
+ // if (kernel.running(req.params.start)) {
88
+ // // nothing
89
+ // } else {
90
+ // // if exists
91
+ // let uri = req.params.start
92
+ // let filePath = kernel.api.filePath(uri)
93
+ // if (kernel.exists(filePath)) {
94
+ // // run script
95
+ // //await kernel.api.init()
96
+ // kernel.api.process({ uri })
97
+ // } else {
98
+ // // display html
99
+ // let repo = new URL(uri)
100
+ // let href = `https://pinokio.computer/item?uri=${repo}`
101
+ // ondata({
102
+ // html: req.params.html,
103
+ // href,
104
+ // target: "_blank",
105
+ // }, "notify")
106
+ // }
107
+ // }
108
+ // } else {
109
+ // ondata({
110
+ // html: req.params.html,
111
+ // href: req.params.href,
112
+ // target: "_blank",
113
+ // }, "notify")
114
+ // }
115
+ // })
116
+ // }
117
+ // }
118
+ //
119
+ //
120
+ //
121
+ //
122
+ //
123
+ // }
2
124
  async wait (req, ondata, kernel) {
3
125
  /*
4
126
  params := {
package/kernel/index.js CHANGED
@@ -5,6 +5,7 @@ const jsdom = require("jsdom");
5
5
  const path = require('path')
6
6
  const fastq = require('fastq')
7
7
  const fetch = require('cross-fetch');
8
+ const waitOn = require('wait-on');
8
9
  const system = require('systeminformation');
9
10
  const Sysinfo = require('./sysinfo')
10
11
  const portfinder = require('portfinder');
@@ -27,7 +28,7 @@ const VARS = {
27
28
  //const memwatch = require('@airbnb/node-memwatch');
28
29
  class Kernel {
29
30
  //schema = ">=1.0.0"
30
- schema = "<=1.1.0"
31
+ schema = "<=1.2.0"
31
32
  constructor(store) {
32
33
  this.fetch = fetch
33
34
  this.store = store
@@ -46,7 +47,9 @@ class Kernel {
46
47
  }
47
48
  local(...args) {
48
49
  // get local variables at path
49
- let v = this.memory.local[path.resolve(...args)]
50
+ let filePath = this.api.filePath(path.resolve(...args))
51
+ let v = this.memory.local[filePath]
52
+ //let v = this.memory.local[path.resolve(...args)]
50
53
  if (v) {
51
54
  return v
52
55
  } else {
@@ -55,7 +58,9 @@ class Kernel {
55
58
  }
56
59
  global(...args) {
57
60
  // get local variables at path
58
- let v = this.memory.global[path.resolve(...args)]
61
+ let filePath = this.api.filePath(path.resolve(...args))
62
+ let v = this.memory.global[filePath]
63
+ // let v = this.memory.global[path.resolve(...args)]
59
64
  if (v) {
60
65
  return v
61
66
  } else {
@@ -140,6 +145,9 @@ class Kernel {
140
145
  }
141
146
  }
142
147
 
148
+ async wait(options) {
149
+ await waitOn(options)
150
+ }
143
151
 
144
152
  async init() {
145
153
  let home = this.store.get("home")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,6 @@
26
26
  "fastq": "^1.15.0",
27
27
  "form-data": "^4.0.0",
28
28
  "fs-extra": "^11.1.1",
29
- "gepeto": "^0.0.33",
30
29
  "glob": "^10.3.3",
31
30
  "glob-gitignore": "^1.0.14",
32
31
  "handlebars": "^4.7.7",
@@ -45,6 +44,7 @@
45
44
  "node-calls-python": "^1.8.2",
46
45
  "node-downloader-helper": "^2.1.9",
47
46
  "node-pty-prebuilt-multiarch-cp": "^0.10.1-pre.48",
47
+ "open": "8.4.2",
48
48
  "pdrive": "^0.0.23",
49
49
  "portfinder": "^1.0.32",
50
50
  "random-useragent": "^0.5.0",
@@ -56,6 +56,7 @@
56
56
  "symlink-dir": "^5.2.1",
57
57
  "systeminformation": "^5.18.4",
58
58
  "uuid": "^9.0.0",
59
+ "wait-on": "^7.2.0",
59
60
  "watcher": "^2.2.2",
60
61
  "ws": "^8.13.0",
61
62
  "xterm-addon-fit": "^0.8.0",
package/server/index.js CHANGED
@@ -11,7 +11,6 @@ const cors = require('cors');
11
11
  const path = require("path")
12
12
  const fs = require('fs');
13
13
  const os = require('os')
14
- const gepeto = require('gepeto')
15
14
  const { fork } = require('child_process');
16
15
  const semver = require('semver')
17
16
  const fse = require('fs-extra')
@@ -262,6 +261,7 @@ class Server {
262
261
 
263
262
 
264
263
  let stat = await fs.promises.stat(filepath)
264
+ console.log("ST", { stat, filepath, isfile: stat.isFile() })
265
265
  if (pathComponents.length === 0 && req.query.mode === "explore") {
266
266
  res.render("explore", {
267
267
  version: this.version,
@@ -368,6 +368,7 @@ class Server {
368
368
  query: req.query
369
369
  })
370
370
  } else if (stat.isFile()) {
371
+ console.log("isfile")
371
372
 
372
373
  if (req.query && req.query.raw) {
373
374
  try {
@@ -426,6 +427,8 @@ class Server {
426
427
 
427
428
  let runner = json || js
428
429
 
430
+ console.log({ runner, json, js, editmode, m })
431
+
429
432
  let rawpath = `/raw/${pathComponents.join('/')}` + "?frame=true"
430
433
  if (editmode) {
431
434
  let content = await fs.promises.readFile(filepath, "utf8")
@@ -758,6 +761,7 @@ class Server {
758
761
 
759
762
  res.render(template, result)
760
763
  } else {
764
+ console.log("FRAME", rawpath)
761
765
  res.render("frame", {
762
766
  logo: this.logo,
763
767
  theme: this.theme,
@@ -1065,10 +1069,6 @@ class Server {
1065
1069
  for(let i=0; i<config.menu.length; i++) {
1066
1070
  let menuitem = config.menu[i]
1067
1071
 
1068
-
1069
-
1070
-
1071
-
1072
1072
  if (menuitem.menu) {
1073
1073
  let m = await this.renderMenu(uri, name, { menu: menuitem.menu }, pathComponents)
1074
1074
  menuitem.menu = m.menu
@@ -1883,6 +1883,17 @@ class Server {
1883
1883
  this.tabs[req.body.name] = req.body.tabs
1884
1884
  res.json({ success: true })
1885
1885
  })
1886
+ this.app.get("/pinokio/browser", async (req, res) => {
1887
+ console.log("req.query", req.query)
1888
+ if (req.query && req.query.uri) {
1889
+ let uri = req.query.uri
1890
+ let p = this.kernel.api.resolveBrowserPath(uri)
1891
+ console.log({ uri, p})
1892
+ res.redirect(p)
1893
+ } else {
1894
+ res.redirect("/")
1895
+ }
1896
+ })
1886
1897
  this.app.get("/pinokio/browser/:name", async (req, res) => {
1887
1898
  let name = req.params.name
1888
1899
  let app_path = this.kernel.path("api", name, "pinokio.js")
@@ -2279,14 +2290,6 @@ class Server {
2279
2290
  this.app.get("/check", (req, res) => {
2280
2291
  res.json({ success: true })
2281
2292
  })
2282
- this.app.post("/gepeto", async (req, res) => {
2283
- try {
2284
- await gepeto(path.resolve(this.kernel.homedir, "api", req.body.name))
2285
- } catch (e) {
2286
- console.log("gepeto error", e)
2287
- }
2288
- res.json({ success: true })
2289
- })
2290
2293
  this.app.post("/restart", async (req, res) => {
2291
2294
  console.log("post /restart")
2292
2295
  this.start(this.debug)
@@ -106,28 +106,6 @@ const install = async (name, url, term, socket, options) => {
106
106
  // ask the backend to create install.json and start.json if gradio
107
107
  location.href = `/?selected=${name}`
108
108
 
109
- // await fetch("/gepeto", {
110
- // method: "post",
111
- // headers: {
112
- // "Content-Type": "application/json"
113
- // },
114
- // body: JSON.stringify({
115
- // name
116
- // })
117
- // })
118
- //
119
- // //location.href = "/api/" + name
120
- // location.href = `/?selected=${name}`
121
- // /*
122
- // n.Noty({
123
- // text: "Success! Click here to continue.",
124
- // callbacks: {
125
- // onClose: () => {
126
- // location.href = "/api/" + name
127
- // }
128
- // }
129
- // })
130
- // */
131
109
  }
132
110
  }
133
111
  const createTerm = () => {
@@ -0,0 +1,24 @@
1
+ const SimpleModal = async (params) => {
2
+ let btns = params.menu.map((item) => {
3
+ if (item.href) {
4
+ return `<a class='btn' href='${item.href}' target='_blank'>${item.text}</a>`
5
+ } else if (item.action) {
6
+ return `<a class='btn' target='_blank'>${item.text}</a>`
7
+ }
8
+ }).join("")
9
+ await Swal.fire({
10
+ title: params.title,
11
+ html: `<div class='simple-modal-desc'>
12
+ ${params.description}
13
+ </div>
14
+ <div class='simple-modal-content'>${btns}</div>`,
15
+ // showConfirmButton: false,
16
+ // footer: `<div class='simple-modal-footer'>
17
+ //<div class='flexible'></div>
18
+ //<div id='simple-modal-close'>Done</div>
19
+ //</div>`,
20
+ // didClose: (result) => {
21
+ // // Optional: Handle overall modal closing if needed
22
+ // }
23
+ })
24
+ }
@@ -81,6 +81,25 @@ footer .toggle-expand {
81
81
  footer pre {
82
82
  background: none !important;
83
83
  }
84
+ .simple-modal-desc {
85
+ padding-bottom: 10px;
86
+ text-align: left;
87
+ font-size: 14px;
88
+ }
89
+ .simple-modal-content {
90
+ text-align: left;
91
+ width: 100%;
92
+ box-sizing: border-box;
93
+ }
94
+ .simple-modal-content .btn {
95
+ margin-right: 5px;
96
+ }
97
+ .simple-modal-footer {
98
+ display: flex;
99
+ padding: 10px;
100
+ width: 100%;
101
+ box-sizing: border-box;
102
+ }
84
103
  footer {
85
104
  font-family: verdana;
86
105
  overflow: hidden;
package/server/socket.js CHANGED
@@ -40,10 +40,6 @@ class Socket {
40
40
 
41
41
  console.log("socket ID", { id, req })
42
42
 
43
- // if (req.mode !== "listen") {
44
- // // since the event came from the client, connect the buffer
45
- // this.buffer[id] = []
46
- // }
47
43
  if (req.status) {
48
44
  ws.send(JSON.stringify({
49
45
  data: this.parent.kernel.api.running[id] ? true : false
@@ -18,6 +18,7 @@
18
18
  <script src="/nav.js"></script>
19
19
  <script src="/autoexpand.js"></script>
20
20
  <script src="/modalinput.js"></script>
21
+ <script src="/simplemodal.js"></script>
21
22
  <script src="/notifyinput.js"></script>
22
23
  <script src="/report.js"></script>
23
24
  <link href="/xterm.min.css" rel="stylesheet" />
@@ -308,6 +309,8 @@ document.addEventListener("DOMContentLoaded", async () => {
308
309
  document.querySelector(".run .play").classList.add("hidden")
309
310
  document.querySelector(".run .starting").classList.add("hidden")
310
311
  document.querySelector(".run .stop").classList.remove("hidden")
312
+ } else if (packet.type === "modal") {
313
+ await SimpleModal(packet.data)
311
314
  } else if (packet.type === "input") {
312
315
  let params = packet.data
313
316
  let type = (params.type ? params.type : "modal")
@@ -20,6 +20,7 @@
20
20
  -->
21
21
  <script src="/autoexpand.js"></script>
22
22
  <script src="/modalinput.js"></script>
23
+ <script src="/simplemodal.js"></script>
23
24
  <script src="/notifyinput.js"></script>
24
25
  <script src="/report.js"></script>
25
26
  <link href="/xterm.min.css" rel="stylesheet" />
@@ -287,6 +288,8 @@ document.addEventListener("DOMContentLoaded", async () => {
287
288
  // uri: "~" + location.pathname,
288
289
  // })
289
290
  // }
291
+ } else if (packet.type === "modal") {
292
+ await SimpleModal(packet.data)
290
293
  } else if (packet.type === "input") {
291
294
  let params = packet.data
292
295
  let type = (params.type ? params.type : "modal")