pinokiod 3.8.11 → 3.8.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/server/index.js CHANGED
@@ -17,6 +17,7 @@ const { fork } = require('child_process');
17
17
  const semver = require('semver')
18
18
  const fse = require('fs-extra')
19
19
  const QRCode = require('qrcode')
20
+ const axios = require('axios')
20
21
 
21
22
  const git = require('isomorphic-git')
22
23
  const http = require('isomorphic-git/http/node')
@@ -799,6 +800,8 @@ class Server {
799
800
  name: "node",
800
801
  }, {
801
802
  name: "ffmpeg",
803
+ }, {
804
+ name: "caddy",
802
805
  // type: "conda",
803
806
  // name: "ffmpeg",
804
807
  // args: "-c conda-forge"
@@ -828,15 +831,15 @@ class Server {
828
831
  })
829
832
  }
830
833
  requirements = requirements.concat([{
831
- name: "py"
832
- }, {
833
834
  name: "cloudflared"
834
- }, {
835
- name: "playwright"
835
+ // }, {
836
+ // name: "playwright"
836
837
  }, {
837
838
  name: "huggingface"
838
839
  }, {
839
840
  name: "uv"
841
+ }, {
842
+ name: "py"
840
843
  }])
841
844
  // if (platform === "linux") {
842
845
  // requirements.push({
@@ -971,6 +974,19 @@ class Server {
971
974
  let env = await Environment.get2(filepath, this.kernel)
972
975
  for(let item of resolved.pre) {
973
976
  if (item.env) {
977
+
978
+ if (!item.index) {
979
+ item.index = 0
980
+ }
981
+ if (item.key) {
982
+ const hasProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(item.key);
983
+ const url = new URL(hasProtocol ? item.key : `https://${item.key}`);
984
+ item.host = url.host
985
+ item.val = await this.kernel.kv.get(item.host, item.index)
986
+ } else {
987
+ item.host = ""
988
+ }
989
+
974
990
  if (env[item.env]) {
975
991
  item.val = env[item.env]
976
992
  } else {
@@ -989,6 +1005,7 @@ class Server {
989
1005
  if (platform === "win32") {
990
1006
  p = p.replace(/\\/g, '\\\\')
991
1007
  }
1008
+ console.log({ pre_items })
992
1009
  res.render("required_env_editor", {
993
1010
  agent: this.agent,
994
1011
  theme: this.theme,
@@ -2572,6 +2589,66 @@ class Server {
2572
2589
  Util.openfs(req.body.path, req.body, this.kernel)
2573
2590
  res.json({ success: true })
2574
2591
  }))
2592
+ this.app.get("/docs", ex(async (req, res) => {
2593
+ let url = req.query.url
2594
+ const possiblePaths = [
2595
+ '/openapi.json',
2596
+ '/swagger.json',
2597
+ '/v1/openapi.json',
2598
+ '/v1/swagger.json',
2599
+ '/docs/openapi.json',
2600
+ '/api-docs',
2601
+ '/api-docs.json',
2602
+ ];
2603
+ let selected = null
2604
+ if (req.query.url) {
2605
+ const localHosts = ['localhost', '127.0.0.1', '::1'];
2606
+ const urlObj = new URL(req.query.url)
2607
+ const baseOrigins = [urlObj.origin];
2608
+ if (urlObj.hostname === 'localhost' || urlObj.hostname === '::1' || urlObj.hostname.startsWith('127.')) {
2609
+ for (const host of localHosts) {
2610
+ const origin = urlObj.origin.replace(urlObj.hostname, host);
2611
+ if (!baseOrigins.includes(origin)) {
2612
+ baseOrigins.push(origin);
2613
+ }
2614
+ }
2615
+ }
2616
+
2617
+ for (const origin of baseOrigins) {
2618
+ for (const possiblePath of possiblePaths) {
2619
+ try {
2620
+ const url = new URL(possiblePath, origin).href;
2621
+ const res = await axios.get(url, { timeout: 500 });
2622
+ const contentType = res.headers['content-type'];
2623
+ if (contentType?.includes('application/json')) {
2624
+ const json = res.data;
2625
+ if (json.openapi || json.swagger) {
2626
+ selected = json
2627
+ break
2628
+ }
2629
+ }
2630
+ } catch (e) {
2631
+ console.log("error", e)
2632
+ // ignore errors
2633
+ }
2634
+ }
2635
+ if (selected) break
2636
+ }
2637
+ }
2638
+ let type = "redoc" // "swaggerui"
2639
+ if (req.query.type) {
2640
+ type = req.query.type
2641
+ }
2642
+ if (selected) {
2643
+ res.render(type, {
2644
+ spec: JSON.stringify(selected)
2645
+ })
2646
+ } else {
2647
+ res.render(type, {
2648
+ spec: null
2649
+ })
2650
+ }
2651
+ }))
2575
2652
  this.app.get("/terminal/:api/:id", ex(async (req, res) => {
2576
2653
  res.render("minterm", {
2577
2654
  theme: this.theme,
@@ -2813,8 +2890,12 @@ class Server {
2813
2890
  let script = this.kernel.proto.kv[req.params.type]
2814
2891
  console.log({ script, body: req.body })
2815
2892
  try {
2816
- const folder = await script.run(this.kernel, req.body)
2817
- res.json({ success: folder })
2893
+ if (script.create) {
2894
+ const folder = await script.create(this.kernel, req.body)
2895
+ res.json({ success: folder })
2896
+ } else {
2897
+ res.json({ error: "pinokio.js is missing a create function" })
2898
+ }
2818
2899
  } catch (e) {
2819
2900
  res.json({ error: e.message })
2820
2901
  }
@@ -2822,7 +2903,16 @@ class Server {
2822
2903
  this.app.post("/env", ex(async (req, res) => {
2823
2904
  let fullpath = path.resolve(this.kernel.homedir, req.body.filepath, "ENVIRONMENT")
2824
2905
  let updated = req.body.vals
2906
+ let hosts = req.body.hosts
2825
2907
  await Util.update_env(fullpath, updated)
2908
+ // for all environment variables that have hosts, save the key as well
2909
+ // hosts := { env_key: host }
2910
+ for(let env in hosts) {
2911
+ let host = hosts[env]
2912
+ let val = updated[env]
2913
+ console.log({ hosts, updated, host, val })
2914
+ await this.kernel.kv.set(host.value, val, host.index)
2915
+ }
2826
2916
  res.json({})
2827
2917
  }))
2828
2918
  this.app.get("/env", ex(async (req, res) => {
@@ -3372,6 +3462,7 @@ class Server {
3372
3462
  let info = Object.assign({}, this.kernel.i)
3373
3463
  info.launch_complete = this.kernel.launch_complete
3374
3464
  console.log("kernel.launch_complete", this.kernel.launch_complete)
3465
+ console.log({ info })
3375
3466
  delete info.vars
3376
3467
  delete info.shell_env
3377
3468
  delete info.memory
@@ -3753,16 +3844,16 @@ class Server {
3753
3844
  stack: err.stack
3754
3845
  })
3755
3846
  });
3756
- // process.on('SIGINT', () => {
3757
- // console.log("SIGINT Event")
3758
- // if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3759
- // process.exit()
3760
- // })
3761
- // process.on('SIGTERM', () => {
3762
- // console.log("SIGTERM Event")
3763
- // if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3764
- // process.exit()
3765
- // })
3847
+ process.on('SIGINT', () => {
3848
+ console.log("SIGINT Event")
3849
+ if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3850
+ process.exit()
3851
+ })
3852
+ process.on('SIGTERM', () => {
3853
+ console.log("SIGTERM Event")
3854
+ if (this.kernel && this.kernel.shell) this.kernel.shell.reset()
3855
+ process.exit()
3856
+ })
3766
3857
  // process.on('exit', () => {
3767
3858
  // console.log("exit Event")
3768
3859
  // if (this.kernel && this.kernel.shell) {
@@ -3787,6 +3878,7 @@ class Server {
3787
3878
  })
3788
3879
  console.timeEnd("SERVER START")
3789
3880
 
3881
+
3790
3882
  }
3791
3883
  }
3792
3884
  module.exports = Server
@@ -20,9 +20,10 @@ const ModalInput = async (params) => {
20
20
  title: (params.title || ""),
21
21
  html: description + form.map((field) => {
22
22
  let type = (field.type ? field.type : "text")
23
+ let autofocus = (field.autofocus ? "autofocus" : "")
23
24
  let input
24
25
  if (type === 'textarea') {
25
- input = `<textarea oninput="autoExpand(this)" data-id="${field.key}" class="swal2-input" placeholder="${field.placeholder ? field.placeholder : ''}"></textarea>`
26
+ input = `<textarea ${autofocus} oninput="autoExpand(this)" data-id="${field.key}" class="swal2-input" placeholder="${field.placeholder ? field.placeholder : ''}"></textarea>`
26
27
  } else if (type === 'select') {
27
28
  if (field.items && Array.isArray(field.items)) {
28
29
  let items = field.items.map((item) => {
@@ -31,7 +32,7 @@ const ModalInput = async (params) => {
31
32
  input = `<select>${items}</select>`
32
33
  }
33
34
  } else {
34
- input = `<input type='${type}' data-id="${field.key}" class="swal2-input" placeholder="${field.placeholder ? field.placeholder : ''}">`
35
+ input = `<input ${autofocus} type='${type}' data-id="${field.key}" class="swal2-input" placeholder="${field.placeholder ? field.placeholder : ''}">`
35
36
  }
36
37
  return [
37
38
  "<div class='field'>",