pinokiod 0.2.0 → 1.0.1
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/kernel/api/index.js +6 -3
- package/kernel/bin/index.js +21 -17
- package/kernel/index.js +30 -40
- package/package.json +1 -1
- package/server/index.js +61 -21
package/kernel/api/index.js
CHANGED
|
@@ -13,7 +13,6 @@ class Api {
|
|
|
13
13
|
constructor(kernel) {
|
|
14
14
|
this.kernel = kernel
|
|
15
15
|
this.gitPath = {}
|
|
16
|
-
this.userdir = path.resolve(kernel.homedir, "api")
|
|
17
16
|
this.loader = new Loader()
|
|
18
17
|
this.queues = {}
|
|
19
18
|
this.listeners = {}
|
|
@@ -23,8 +22,12 @@ class Api {
|
|
|
23
22
|
this.waiter = {}
|
|
24
23
|
}
|
|
25
24
|
async init() {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
console.log("api.init", { homedir: this.kernel.homedir })
|
|
26
|
+
if (this.kernel.homedir) {
|
|
27
|
+
this.userdir = path.resolve(this.kernel.homedir, "api")
|
|
28
|
+
await fs.promises.mkdir(this.userdir, { recusrive: true, }).catch((e) => { })
|
|
29
|
+
await this.linkGit()
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
respond(req) {
|
|
30
33
|
let requestPath = this.filePath(req.uri)
|
package/kernel/bin/index.js
CHANGED
|
@@ -155,8 +155,10 @@ class Bin {
|
|
|
155
155
|
return e
|
|
156
156
|
}
|
|
157
157
|
async init() {
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
if (this.kernel.homedir) {
|
|
159
|
+
const bin_folder = this.path()
|
|
160
|
+
await fs.promises.mkdir(bin_folder, { recursive: true }).catch((e) => { })
|
|
161
|
+
}
|
|
160
162
|
// ORDERING MATTERS.
|
|
161
163
|
// General purpose package managers like conda, conda needs to come at the end
|
|
162
164
|
|
|
@@ -190,24 +192,26 @@ class Bin {
|
|
|
190
192
|
this.mod[mod.name] = mod.mod
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
this.refreshInstalled().catch((e) => {
|
|
194
|
-
console.log("RefreshInstalled Error", e)
|
|
195
|
-
})
|
|
196
195
|
|
|
197
196
|
|
|
198
197
|
// write to pipconfig if it doesn't exist
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
if (this.kernel.homedir) {
|
|
199
|
+
this.refreshInstalled().catch((e) => {
|
|
200
|
+
console.log("RefreshInstalled Error", e)
|
|
201
|
+
})
|
|
202
|
+
let pipconfig_path = path.resolve(this.kernel.homedir, "pipconfig")
|
|
203
|
+
let pipconfig_exists = await this.kernel.api.exists(pipconfig_path)
|
|
204
|
+
console.log("pipconfig exists?", { pipconfig_path, pipconfig_exists })
|
|
205
|
+
// if not, create one
|
|
206
|
+
if (!pipconfig_exists) {
|
|
207
|
+
const pipconfigStr = `[global]
|
|
208
|
+
timeout = 1000`
|
|
209
|
+
await fs.promises.writeFile(pipconfig_path, pipconfigStr)
|
|
210
|
+
// await fs.promises.copyFile(
|
|
211
|
+
// path.resolve(__dirname, "..", "pipconfig_template"),
|
|
212
|
+
// pipconfig_path
|
|
213
|
+
// )
|
|
214
|
+
}
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
|
package/kernel/index.js
CHANGED
|
@@ -135,22 +135,16 @@ class Kernel {
|
|
|
135
135
|
|
|
136
136
|
async init() {
|
|
137
137
|
let home = this.store.get("home")
|
|
138
|
-
if (home) {
|
|
139
|
-
this.homedir = home
|
|
140
138
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
} else {
|
|
151
|
-
// this.homedir = null
|
|
152
|
-
this.homedir = path.resolve(os.homedir(), "pinokio")
|
|
153
|
-
}
|
|
139
|
+
this.homedir = home
|
|
140
|
+
|
|
141
|
+
console.log("kernel.init", { homedir: this.homedir })
|
|
142
|
+
|
|
143
|
+
// if (home) {
|
|
144
|
+
// this.homedir = home
|
|
145
|
+
// } else {
|
|
146
|
+
// this.homedir = path.resolve(os.homedir(), "pinokio")
|
|
147
|
+
// }
|
|
154
148
|
console.log("homedir", this.homedir)
|
|
155
149
|
if (this.log_queue) {
|
|
156
150
|
this.log_queue.killAndDrain()
|
|
@@ -201,33 +195,29 @@ class Kernel {
|
|
|
201
195
|
this.procs = {}
|
|
202
196
|
this.template = new Template(this)
|
|
203
197
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"GRADIO_TEMP_DIR"
|
|
224
|
-
]
|
|
225
|
-
for(let folder of cache_folders) {
|
|
226
|
-
await fs.promises.mkdir(path.resolve(this.homedir, "cache", folder), { recursive: true }).catch((e) => {})
|
|
227
|
-
}
|
|
198
|
+
if (this.homedir) {
|
|
199
|
+
await fs.promises.mkdir(this.homedir, { recursive: true }).catch((e) => {})
|
|
200
|
+
const cache_folders = [
|
|
201
|
+
"HF_HOME",
|
|
202
|
+
"TORCH_HOME",
|
|
203
|
+
"HOMEBREW_CACHE",
|
|
204
|
+
"XDG_CACHE_HOME",
|
|
205
|
+
"PIP_CACHE_DIR",
|
|
206
|
+
"PIP_TMPDIR",
|
|
207
|
+
"TEMP",
|
|
208
|
+
"TMP",
|
|
209
|
+
"XDG_DATA_HOME",
|
|
210
|
+
"XDG_CONFIG_HOME",
|
|
211
|
+
"XDG_STATE_HOME",
|
|
212
|
+
"GRADIO_TEMP_DIR"
|
|
213
|
+
]
|
|
214
|
+
for(let folder of cache_folders) {
|
|
215
|
+
await fs.promises.mkdir(path.resolve(this.homedir, "cache", folder), { recursive: true }).catch((e) => {})
|
|
216
|
+
}
|
|
228
217
|
|
|
218
|
+
}
|
|
229
219
|
|
|
230
|
-
let contents = await fs.promises.readdir(this.homedir)
|
|
220
|
+
// let contents = await fs.promises.readdir(this.homedir)
|
|
231
221
|
await this.bin.init()
|
|
232
222
|
await this.api.init()
|
|
233
223
|
await this.template.init()
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1482,6 +1482,36 @@ class Server {
|
|
|
1482
1482
|
let new_home = this.kernel.store.get("new_home")
|
|
1483
1483
|
console.log("after setting config", { home, theme, new_home })
|
|
1484
1484
|
}
|
|
1485
|
+
async startLogging() {
|
|
1486
|
+
if (!this.debug) {
|
|
1487
|
+
if (this.logInterval) {
|
|
1488
|
+
clearInterval(this.logInterval)
|
|
1489
|
+
}
|
|
1490
|
+
if (this.kernel.homedir) {
|
|
1491
|
+
let exists = await this.exists(this.kernel.homedir)
|
|
1492
|
+
if (exists) {
|
|
1493
|
+
let logsdir = path.resolve(this.kernel.homedir, "logs")
|
|
1494
|
+
await fs.promises.mkdir(logsdir, { recursive: true }).catch((e) => { })
|
|
1495
|
+
if (!this.log) {
|
|
1496
|
+
this.log = fs.createWriteStream(path.resolve(this.kernel.homedir, "logs/stdout.txt"))
|
|
1497
|
+
process.stdout.write = process.stderr.write = this.log.write.bind(this.log)
|
|
1498
|
+
process.on('uncaughtException', (err) => {
|
|
1499
|
+
console.error((err && err.stack) ? err.stack : err);
|
|
1500
|
+
});
|
|
1501
|
+
this.logInterval = setInterval(async () => {
|
|
1502
|
+
let file = path.resolve(this.kernel.homedir, "logs/stdout.txt")
|
|
1503
|
+
let data = await fs.promises.readFile(file, 'utf8')
|
|
1504
|
+
let lines = data.split('\n')
|
|
1505
|
+
if (lines.length > 100000) {
|
|
1506
|
+
let str = lines.slice(-100000).join("\n")
|
|
1507
|
+
await fs.promises.writeFile(file, str)
|
|
1508
|
+
}
|
|
1509
|
+
}, 1000 * 60 * 10) // 10 minutes
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1485
1515
|
async start(debug) {
|
|
1486
1516
|
|
|
1487
1517
|
|
|
@@ -1502,6 +1532,8 @@ class Server {
|
|
|
1502
1532
|
// initialize kernel
|
|
1503
1533
|
await this.kernel.init()
|
|
1504
1534
|
|
|
1535
|
+
console.log("homedir", this.kernel.homedir)
|
|
1536
|
+
|
|
1505
1537
|
|
|
1506
1538
|
// if (!debug) {
|
|
1507
1539
|
// let logsdir = path.resolve(this.kernel.homedir, "logs")
|
|
@@ -1514,27 +1546,7 @@ class Server {
|
|
|
1514
1546
|
// });
|
|
1515
1547
|
// }
|
|
1516
1548
|
// }
|
|
1517
|
-
|
|
1518
|
-
if (!debug) {
|
|
1519
|
-
let logsdir = path.resolve(this.kernel.homedir, "logs")
|
|
1520
|
-
await fs.promises.mkdir(logsdir, { recursive: true }).catch((e) => { })
|
|
1521
|
-
if (!this.log) {
|
|
1522
|
-
this.log = fs.createWriteStream(path.resolve(this.kernel.homedir, "logs/stdout.txt"))
|
|
1523
|
-
process.stdout.write = process.stderr.write = this.log.write.bind(this.log)
|
|
1524
|
-
process.on('uncaughtException', (err) => {
|
|
1525
|
-
console.error((err && err.stack) ? err.stack : err);
|
|
1526
|
-
});
|
|
1527
|
-
setInterval(async () => {
|
|
1528
|
-
let file = path.resolve(this.kernel.homedir, "logs/stdout.txt")
|
|
1529
|
-
let data = await fs.promises.readFile(file, 'utf8')
|
|
1530
|
-
let lines = data.split('\n')
|
|
1531
|
-
if (lines.length > 100000) {
|
|
1532
|
-
let str = lines.slice(-100000).join("\n")
|
|
1533
|
-
await fs.promises.writeFile(file, str)
|
|
1534
|
-
}
|
|
1535
|
-
}, 1000 * 60 * 10) // 10 minutes
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1549
|
+
await this.startLogging()
|
|
1538
1550
|
|
|
1539
1551
|
|
|
1540
1552
|
|
|
@@ -1562,10 +1574,38 @@ class Server {
|
|
|
1562
1574
|
this.app.get("/", async (req, res) => {
|
|
1563
1575
|
console.log("### req.headers", req.headers)
|
|
1564
1576
|
|
|
1577
|
+
console.log({ mode: req.query.mode, home, homeempty: !home })
|
|
1565
1578
|
if (req.query.mode !== "settings" && !home) {
|
|
1579
|
+
console.log("settings")
|
|
1566
1580
|
res.redirect("/?mode=settings")
|
|
1567
1581
|
return
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
}
|
|
1585
|
+
if (req.query.mode === 'settings') {
|
|
1586
|
+
let configArray = [{
|
|
1587
|
+
key: "home",
|
|
1588
|
+
val: this.kernel.homedir ? this.kernel.homedir : path.resolve(os.homedir(), "pinokio"),
|
|
1589
|
+
placeholder: "Enter the absolute path to use as your Pinokio home folder (D:\\pinokio, /Users/alice/pinokiofs, etc.)"
|
|
1590
|
+
}, {
|
|
1591
|
+
key: "theme",
|
|
1592
|
+
val: this.theme,
|
|
1593
|
+
options: ["light", "dark"]
|
|
1594
|
+
}]
|
|
1595
|
+
console.log("agent", this.agent)
|
|
1596
|
+
res.render("settings", {
|
|
1597
|
+
version: this.version,
|
|
1598
|
+
logo: this.logo,
|
|
1599
|
+
theme: this.theme,
|
|
1600
|
+
agent: this.agent,
|
|
1601
|
+
paths: [],
|
|
1602
|
+
config: configArray,
|
|
1603
|
+
query: req.query
|
|
1604
|
+
})
|
|
1605
|
+
|
|
1606
|
+
return
|
|
1568
1607
|
}
|
|
1608
|
+
console.log("abc")
|
|
1569
1609
|
|
|
1570
1610
|
let apipath = this.kernel.path("api")
|
|
1571
1611
|
let files = await fs.promises.readdir(apipath, { withFileTypes: true })
|