pinokiod 3.8.11 → 3.8.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.
package/LICENSE CHANGED
@@ -1,7 +0,0 @@
1
- Copyright 2023 Pinokio
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -588,6 +588,8 @@ class Api {
588
588
  // clear global regular expression object RegExp.lastMatch (memory leak prevention)
589
589
  let r = /\s*/g.exec("");
590
590
 
591
+ let port = await this.kernel.port()
592
+
591
593
  let { cwd, script } = await this.resolveScript(request.path)
592
594
 
593
595
  let memory = {
@@ -601,6 +603,7 @@ class Api {
601
603
  uri: request.uri,
602
604
  cwd,
603
605
  self: script,
606
+ port,
604
607
  ...this.kernel.vars,
605
608
  }
606
609
 
@@ -1,5 +1,7 @@
1
1
  module.exports = async (req, ondata, kernel) => {
2
+ // send "input" type event so the frontend triggers a modal
2
3
  ondata(req.params, "input")
4
+ // then, wait until the frontend responds
3
5
  let response = await kernel.api.wait(req.parent.path)
4
6
  return response
5
7
  }
@@ -1,6 +1,7 @@
1
1
  const path = require('path')
2
2
  class Script {
3
3
  async start(req, ondata, kernel) {
4
+ console.log(">>>>>>>>> script.start", req)
4
5
  let res = await this.run(req, ondata, kernel)
5
6
  return res
6
7
  }
@@ -43,6 +44,7 @@ class Script {
43
44
  */
44
45
  // if already running, print that it's already running
45
46
  let id = kernel.api.filePath(req.params.uri, req.cwd)
47
+ console.log({ id , uri: req.params.uri, cwd: req.cwd })
46
48
  if (kernel.api.running[id]) {
47
49
  let msg = `${req.params.uri} already running. Continuing...\r\n`
48
50
  ondata({ raw: msg })
@@ -0,0 +1,381 @@
1
+ const axios = require('axios')
2
+ const selfsigned = require('selfsigned')
3
+ const fs = require('fs')
4
+
5
+ class Caddy {
6
+ cmd() {
7
+ if (this.kernel.platform === "win32") {
8
+ return "caddy"
9
+ } else {
10
+ return "caddy nss"
11
+ }
12
+ }
13
+ async running() {
14
+ try {
15
+ let response = await axios.get('http://localhost:2019/config')
16
+ return true
17
+ } catch (e) {
18
+ return false
19
+ }
20
+ }
21
+ async start() {
22
+ let running = await this.running()
23
+ console.log("Running", running)
24
+ if (running) {
25
+ return
26
+ }
27
+ let installed = await this.installed()
28
+ console.log("Caddy Installed?", installed)
29
+ if (installed) {
30
+ let resolved
31
+ await new Promise((resolve, reject) => {
32
+ this.kernel.exec({
33
+ message: `caddy run --watch`,
34
+ path: this.kernel.homedir,
35
+ kill: [{
36
+ message: "caddy stop"
37
+ }]
38
+ }, (e) => {
39
+ console.log("[CADDY] " + e.cleaned)
40
+ if (!resolved) {
41
+ if (/endpoint started/i.test(e.cleaned)) {
42
+ console.log("######### match")
43
+ resolved = true
44
+ resolve()
45
+ }
46
+ }
47
+ })
48
+ })
49
+ }
50
+ const config = {
51
+ "apps": {
52
+ "http": {
53
+ "servers": {
54
+ "main": {
55
+ "listen": [":443"],
56
+ "routes": [
57
+ {
58
+ "match": [{ "method": ["OPTIONS"] }],
59
+ "handle": [
60
+ {
61
+ "handler": "headers",
62
+ "response": {
63
+ "set": {
64
+ "Access-Control-Allow-Origin": ["*"],
65
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
66
+ "Access-Control-Allow-Headers": ["*"]
67
+ }
68
+ }
69
+ },
70
+ {
71
+ "handler": "static_response",
72
+ "status_code": 204
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ "match": [{ "host": ["pinokio.localhost"] }],
78
+ "handle": [
79
+ {
80
+ "handler": "reverse_proxy",
81
+ "upstreams": [{ "dial": "localhost:42000" }]
82
+ },
83
+ {
84
+ "handler": "headers",
85
+ "response": {
86
+ "set": {
87
+ "Access-Control-Allow-Origin": ["*"],
88
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
89
+ "Access-Control-Allow-Headers": ["*"]
90
+ }
91
+ }
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "match": [{ "host": ["l.pinokio.localhost"] }],
97
+ "handle": [
98
+ {
99
+ "handler": "reverse_proxy",
100
+ "upstreams": [{ "dial": "localhost:1234" }]
101
+ },
102
+ {
103
+ "handler": "headers",
104
+ "response": {
105
+ "set": {
106
+ "Access-Control-Allow-Origin": ["*"],
107
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
108
+ "Access-Control-Allow-Headers": ["*"]
109
+ }
110
+ }
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ "match": [{ "host": ["o.pinokio.localhost"] }],
116
+ "handle": [
117
+ {
118
+ "handler": "reverse_proxy",
119
+ "upstreams": [{ "dial": "localhost:11434" }]
120
+ },
121
+ {
122
+ "handler": "headers",
123
+ "response": {
124
+ "set": {
125
+ "Access-Control-Allow-Origin": ["*"],
126
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
127
+ "Access-Control-Allow-Headers": ["*"]
128
+ }
129
+ }
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ "match": [{ "host": ["b.pinokio.localhost"] }],
135
+ "handle": [
136
+ {
137
+ "handler": "reverse_proxy",
138
+ "upstreams": [{ "dial": "localhost:7861" }]
139
+ },
140
+ {
141
+ "handler": "headers",
142
+ "response": {
143
+ "set": {
144
+ "Access-Control-Allow-Origin": ["*"],
145
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
146
+ "Access-Control-Allow-Headers": ["*"]
147
+ }
148
+ }
149
+ }
150
+ ]
151
+ },
152
+ {
153
+ "match": [{ "host": ["c.pinokio.localhost"] }],
154
+ "handle": [
155
+ {
156
+ "handler": "reverse_proxy",
157
+ "upstreams": [{ "dial": "localhost:7862" }]
158
+ },
159
+ {
160
+ "handler": "headers",
161
+ "response": {
162
+ "set": {
163
+ "Access-Control-Allow-Origin": ["*"],
164
+ "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
165
+ "Access-Control-Allow-Headers": ["*"]
166
+ }
167
+ }
168
+ }
169
+ ]
170
+ }
171
+ ]
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ const config2 = {
179
+ "apps": {
180
+ "http": {
181
+ "servers": {
182
+ "main": {
183
+ "listen": [":443"],
184
+ //"listen": [":80"],
185
+ "handle_response": [
186
+ {
187
+ "handler": "headers",
188
+ "headers": {
189
+ "Access-Control-Allow-Origin": ["*"],
190
+ "Access-Control-Allow-Methods": ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
191
+ "Access-Control-Allow-Headers": ["*"]
192
+ }
193
+ }
194
+ ],
195
+ "routes": [
196
+ {
197
+ "match": [{ "method": ["OPTIONS"] }],
198
+ "handle": [
199
+ {
200
+ "handler": "static_response",
201
+ "headers": {
202
+ "Access-Control-Allow-Origin": ["*"],
203
+ "Access-Control-Allow-Methods": ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
204
+ "Access-Control-Allow-Headers": ["*"]
205
+ },
206
+ "status_code": 204
207
+ }
208
+ ]
209
+ },
210
+ {
211
+ "match": [{ "host": ["pinokio.localhost"] }],
212
+ "handle": [
213
+ {
214
+ "handler": "reverse_proxy",
215
+ "upstreams": [{ "dial": "localhost:42000" }]
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ "match": [{ "host": ["l.pinokio.localhost"] }],
221
+ "handle": [
222
+ {
223
+ "handler": "reverse_proxy",
224
+ "upstreams": [{ "dial": "localhost:1234" }]
225
+ }
226
+ ]
227
+ },
228
+ {
229
+ "match": [{ "host": ["a.pinokio.localhost"] }],
230
+ "handle": [
231
+ {
232
+ "handler": "reverse_proxy",
233
+ "upstreams": [{ "dial": "localhost:7860" }]
234
+ }
235
+ ]
236
+ },
237
+ {
238
+ "match": [{ "host": ["b.pinokio.localhost"] }],
239
+ "handle": [
240
+ {
241
+ "handler": "reverse_proxy",
242
+ "upstreams": [{ "dial": "localhost:7861" }]
243
+ }
244
+ ]
245
+ },
246
+ {
247
+ "match": [{ "host": ["c.pinokio.localhost"] }],
248
+ "handle": [
249
+ {
250
+ "handler": "reverse_proxy",
251
+ "upstreams": [{ "dial": "localhost:7862" }]
252
+ }
253
+ ]
254
+ }
255
+ ]
256
+ }
257
+ }
258
+ },
259
+ // "tls": {
260
+ // "automation": {
261
+ // "policies": [
262
+ // {
263
+ // "subjects": [
264
+ // "pinokio.localhost",
265
+ // "a.pinokio.localhost",
266
+ // "b.pinokio.localhost",
267
+ // "c.pinokio.localhost"
268
+ // ],
269
+ // "issuers": [
270
+ // {
271
+ // "module": "internal"
272
+ // }
273
+ // ]
274
+ // }
275
+ // ]
276
+ // }
277
+ // }
278
+ }
279
+ }
280
+
281
+
282
+
283
+
284
+ console.log("Make request to caddy", config)
285
+ let response = await axios.post('http://127.0.0.1:2019/load', config, {
286
+ headers: { 'Content-Type': 'application/json' }
287
+ }).catch((e) => {
288
+ console.log("EEEEEEEEEEEEE", e)
289
+ })
290
+ console.log("Caddy Response", { response })
291
+ }
292
+ async install(req, ondata, kernel, id) {
293
+ await this.kernel.bin.exec({
294
+ message: [
295
+ "conda clean -y --all",
296
+ `conda install -y -c conda-forge ${this.cmd()}`
297
+ ]
298
+ }, ondata)
299
+ let resolved
300
+ await new Promise((resolve, reject) => {
301
+ this.kernel.exec({
302
+ message: `caddy run --watch`,
303
+ path: this.kernel.homedir,
304
+ kill: [{
305
+ message: "caddy stop"
306
+ }]
307
+ }, (e) => {
308
+ resolve()
309
+ console.log("[CADDY] " + e.cleaned)
310
+ if (!resolved) {
311
+ if (/endpoint started/i.test(e.cleaned)) {
312
+ console.log("######### match")
313
+ resolved = true
314
+ resolve()
315
+ }
316
+ }
317
+ })
318
+ })
319
+ console.log("req", req)
320
+ ondata({
321
+ title: "Password",
322
+ description: "Enter your system password to add the HTTPS certificate",
323
+ form: [{
324
+ type: "password",
325
+ autofocus: true,
326
+ key: "password",
327
+ placeholder: "System password",
328
+ }]
329
+ }, "input")
330
+ console.log("Wait until", id)
331
+ let response = await this.kernel.api.wait(id)
332
+ console.log({ response })
333
+ if (this.kernel.ploatform === "win32") {
334
+ await this.kernel.exec({
335
+ message: `caddy trust`,
336
+ path: this.kernel.homedir
337
+ }, (e) => {
338
+ ondata(e)
339
+ // console.log(e)
340
+ // if (/Caddy Local Authority/i.test(e.cleaned)) {
341
+ // trusted = true
342
+ // }
343
+ })
344
+ } else {
345
+ await this.kernel.exec({
346
+ message: `echo ${response.password} | sudo -S caddy trust`,
347
+ path: this.kernel.homedir
348
+ }, (e) => {
349
+ // ondata(e)
350
+ // console.log(e)
351
+ // if (/Caddy Local Authority/i.test(e.cleaned)) {
352
+ // trusted = true
353
+ // }
354
+ })
355
+ }
356
+ console.log("FINISHED")
357
+ }
358
+ async installed() {
359
+ // let e = true
360
+ let e = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/pki/authorities/local/root.crt"))
361
+ // let exists = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/certificates/local/pinokio.localhost/pinokio.localhost.crt"))
362
+ // let exists2 = await this.kernel.exists(this.kernel.path("cache/XDG_DATA_HOME/caddy/certificates/local/pinokio.localhost/pinokio.localhost.key"))
363
+ // if (exists && exists2) {
364
+ console.log("checking installed", e)
365
+ if (e) {
366
+ if (this.kernel.platform === "win32") {
367
+ return this.kernel.bin.installed.conda.has("caddy")
368
+ } else {
369
+ return this.kernel.bin.installed.conda.has("caddy") && this.kernel.bin.installed.conda.has("nss")
370
+ }
371
+ } else {
372
+ return false
373
+ }
374
+ }
375
+ async uninstall(req, ondata) {
376
+ await this.kernel.bin.exec({
377
+ message: `conda remove ${this.cmd()}`,
378
+ }, ondata)
379
+ }
380
+ }
381
+ module.exports = Caddy
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs')
2
2
  class Cloudflared {
3
+ description = "Cloudflared lets you expose your local apps to the outside world via Cloudflare Tunnel."
3
4
  async uninstall(req, ondata) {
4
5
  ondata({ raw: "cleaning up\r\n" })
5
6
  let bin = this.kernel.bin
@@ -4,6 +4,7 @@ const fetch = require('cross-fetch')
4
4
  const { glob } = require('glob')
5
5
  const semver = require('semver')
6
6
  class Conda {
7
+ description = "Pinokio uses Conda to install various useful programs in an isolated manner."
7
8
  urls = {
8
9
  darwin: {
9
10
  //x64: "https://repo.anaconda.com/miniconda/Miniconda3-py310_23.5.2-0-MacOSX-x86_64.sh",
@@ -250,11 +251,18 @@ report_errors: false`)
250
251
  // 2. The pinned file says conda-libmamba-solver=24.11.1
251
252
  // 3. so after conda update --all, it should be conda-libmamba-solver=24.11.1
252
253
 
254
+ let mods = this.kernel.bin.mods.filter((m) => {
255
+ return ["zip", "uv", "node", "huggingface", "gxx", "git", "ffmpeg", "caddy"].includes(m.name)
256
+ }).map((m) => {
257
+ return m.mod.cmd()
258
+ }).join(" ")
259
+ console.log("To install", { mods })
253
260
 
254
261
  let cmds = [
255
262
  //"conda clean -y --index-cache",
256
263
  "conda clean -y --all",
257
- "conda install -y -c conda-forge sqlite=3.47.2",
264
+ //"conda install -y -c conda-forge sqlite=3.47.2",
265
+ `conda install -y -c conda-forge sqlite=3.47.2 ${mods}`,
258
266
 
259
267
  // `conda config --file ${this.kernel.path('condarc')} --set remote_connect_timeout_secs 20`,
260
268
  // `conda config --file ${this.kernel.path('condarc')} --set remote_read_timeout_secs 300`,
@@ -6,20 +6,12 @@ class Cuda {
6
6
  "conda clean -y --all",
7
7
  "conda install -y cudnn libzlib-wapi -c conda-forge",
8
8
  ]
9
- // conda: {
10
- // name: "base",
11
- // activate: "minimal"
12
- // }
13
9
  }, ondata)
14
10
  await this.kernel.bin.exec({
15
11
  message: [
16
12
  "conda clean -y --all",
17
13
  "conda install -y cuda -c nvidia/label/cuda-12.1.0",
18
14
  ]
19
- // conda: {
20
- // name: "base",
21
- // activate: "minimal"
22
- // }
23
15
  }, ondata)
24
16
  } else {
25
17
  await this.kernel.bin.exec({
@@ -27,20 +19,12 @@ class Cuda {
27
19
  "conda clean -y --all",
28
20
  "conda install -y cudnn -c conda-forge",
29
21
  ]
30
- // conda: {
31
- // name: "base",
32
- // activate: "minimal"
33
- // }
34
22
  }, ondata)
35
23
  await this.kernel.bin.exec({
36
24
  message: [
37
25
  "conda clean -y --all",
38
26
  "conda install -y cuda -c nvidia/label/cuda-12.1.0",
39
27
  ]
40
- // conda: {
41
- // name: "base",
42
- // activate: "minimal"
43
- // }
44
28
  }, ondata)
45
29
  if (this.kernel.platform === "linux") {
46
30
  await this.kernel.bin.exec({
@@ -3,17 +3,15 @@ const fetch = require('cross-fetch')
3
3
  const { rimraf } = require('rimraf')
4
4
  const decompress = require('decompress');
5
5
  class Ffmpeg {
6
+ cmd() {
7
+ return "ffmpeg"
8
+ }
6
9
  async install(req, ondata) {
7
10
  await this.kernel.bin.exec({
8
11
  message: [
9
12
  "conda clean -y --all",
10
- //"conda install -y -c conda-forge ffmpeg=5.1.2",
11
- "conda install -y -c conda-forge ffmpeg"
13
+ `conda install -y -c conda-forge ${this.cmd()}`
12
14
  ]
13
- // conda: {
14
- // name: "base",
15
- // activate: "minimal"
16
- // }
17
15
  }, ondata)
18
16
  }
19
17
  async installed() {
package/kernel/bin/git.js CHANGED
@@ -4,35 +4,34 @@ const fetch = require('cross-fetch')
4
4
  const { rimraf } = require('rimraf')
5
5
  const path = require("path")
6
6
  class Git {
7
+ cmd() {
8
+ return "git git-lfs gh"
9
+ }
7
10
  async install(req, ondata) {
8
11
  await this.kernel.bin.exec({
9
12
  message: [
10
13
  "conda clean -y --all",
11
- "conda install --no-shortcuts -y -c conda-forge git git-lfs"
14
+ `conda install -y -c conda-forge ${this.cmd()}`
12
15
  ]
13
- // conda: {
14
- // name: "base",
15
- // activate: "minimal"
16
- // }
17
16
  }, ondata)
18
- if (this.kernel.platform === 'win32') {
19
- let gitconfig_path = path.resolve(this.kernel.homedir, "gitconfig")
20
- // check if gitconfig exists
21
- let exists = await this.kernel.api.exists(gitconfig_path)
22
- // if not, create one
23
- if (!exists) {
24
- await fs.promises.copyFile(
25
- path.resolve(__dirname, "..", "gitconfig_template"),
26
- gitconfig_path
27
- )
28
- }
29
- }
17
+ // if (this.kernel.platform === 'win32') {
18
+ // let gitconfig_path = path.resolve(this.kernel.homedir, "gitconfig")
19
+ // // check if gitconfig exists
20
+ // let exists = await this.kernel.api.exists(gitconfig_path)
21
+ // // if not, create one
22
+ // if (!exists) {
23
+ // await fs.promises.copyFile(
24
+ // path.resolve(__dirname, "..", "gitconfig_template"),
25
+ // gitconfig_path
26
+ // )
27
+ // }
28
+ // }
30
29
  }
31
30
  async installed() {
32
- return this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")
31
+ return this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git") && this.kernel.bin.installed.conda.has("gh")
33
32
  }
34
33
  async uninstall(req, ondata) {
35
- await this.kernel.bin.exec({ message: "conda remove git" }, ondata)
34
+ await this.kernel.bin.exec({ message: "conda remove git gh" }, ondata)
36
35
  }
37
36
  env() {
38
37
  // if (this.kernel.platform === 'win32') {
package/kernel/bin/gxx.js CHANGED
@@ -1,15 +1,17 @@
1
1
  class GXX {
2
+ cmd() {
3
+ if (this.kernel.platform === "linux") {
4
+ return "'gxx<12'"
5
+ } else {
6
+ return ""
7
+ }
8
+ }
2
9
  async install(req, ondata) {
3
10
  await this.kernel.bin.exec({
4
- //message: "conda install -y nodejs=22.12.0 -c conda-forge"
5
11
  message: [
6
12
  "conda clean -y --all",
7
- "conda install -y -c conda-forge 'gxx<12'"
13
+ `conda install -y -c conda-forge ${this.cmd()}`
8
14
  ]
9
- // conda: {
10
- // name: "base",
11
- // activate: "minimal"
12
- // }
13
15
  }, ondata)
14
16
  }
15
17
  async installed() {
@@ -1,14 +1,13 @@
1
1
  class Huggingface {
2
+ cmd() {
3
+ return "huggingface_hub"
4
+ }
2
5
  async install(req, ondata) {
3
6
  await this.kernel.bin.exec({
4
7
  message: [
5
8
  "conda clean -y --all",
6
- "conda install -y -c conda-forge huggingface_hub"
9
+ `conda install -y -c conda-forge ${this.cmd()}`
7
10
  ]
8
- // conda: {
9
- // name: "base",
10
- // activate: "minimal"
11
- // }
12
11
  }, ondata)
13
12
  }
14
13
  async installed() {