hermes-web-ui 0.1.1 → 0.1.3
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/README.md +117 -408
- package/bin/hermes-web-ui.mjs +111 -97
- package/dist/assets/{ChatView-WnNeYrS7.js → ChatView-BBqtEbUW.js} +20 -20
- package/dist/assets/ChatView-DC6_7Uwg.css +1 -0
- package/dist/assets/JobsView-sQ8sqrxF.js +356 -0
- package/dist/assets/LogsView-BN_TkDPi.css +1 -0
- package/dist/assets/LogsView-DukKyFJt.js +1 -0
- package/dist/assets/Modal-oIDM0xXN.js +232 -0
- package/dist/assets/Spin-zWt--szS.js +476 -0
- package/dist/assets/Tooltip-BGvPCNBt.js +1 -0
- package/dist/assets/Warning-B9_T2nKK.js +1 -0
- package/dist/assets/_plugin-vue_export-helper-V8xgnEJh.js +231 -0
- package/dist/assets/chat-CGF6ipPC.js +5 -0
- package/dist/assets/fade-in-scale-up.cssr-DQYNrBys.js +45 -0
- package/dist/assets/index-BsLYVWlc.js +307 -0
- package/dist/assets/index-DDAe8BhJ.css +1 -0
- package/dist/assets/{jobs-Cuol6Mqb.js → jobs-QHXENDTQ.js} +1 -1
- package/dist/assets/use-message-42wmA96q.js +117 -0
- package/dist/index.html +8 -6
- package/dist/server/config.d.ts +7 -0
- package/dist/server/config.js +12 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +154 -0
- package/dist/server/routes/logs.d.ts +2 -0
- package/dist/server/routes/logs.js +87 -0
- package/dist/server/routes/proxy-handler.d.ts +2 -0
- package/dist/server/routes/proxy-handler.js +82 -0
- package/dist/server/routes/proxy.d.ts +2 -0
- package/dist/server/routes/proxy.js +12 -0
- package/dist/server/routes/sessions.d.ts +2 -0
- package/dist/server/routes/sessions.js +69 -0
- package/dist/server/routes/upload.d.ts +2 -0
- package/dist/server/routes/upload.js +50 -0
- package/dist/server/routes/webhook.d.ts +2 -0
- package/dist/server/routes/webhook.js +33 -0
- package/dist/server/services/hermes-cli.d.ts +50 -0
- package/dist/server/services/hermes-cli.js +185 -0
- package/dist/server/services/hermes.d.ts +40 -0
- package/dist/server/services/hermes.js +118 -0
- package/package.json +26 -4
- package/dist/assets/ChatView-DrzZz5ex.css +0 -1
- package/dist/assets/JobsView-BF9wWdwU.js +0 -831
- package/dist/assets/Modal-CQVLL_Oc.js +0 -276
- package/dist/assets/_plugin-vue_export-helper-D5N3Hfca.js +0 -231
- package/dist/assets/chat-640V6r6N.js +0 -1
- package/dist/assets/index-4iFlrAYJ.js +0 -307
- package/dist/assets/index-CMJKLUKk.css +0 -1
- package/dist/assets/use-message-B8ClBznx.js +0 -117
- /package/dist/assets/{client-BxIiwrqC.js → client-ZYGCrm9m.js} +0 -0
package/bin/hermes-web-ui.mjs
CHANGED
|
@@ -1,125 +1,139 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
3
|
import { resolve, dirname, join } from 'path'
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
|
-
import {
|
|
5
|
+
import { readFileSync, writeFileSync, unlinkSync, mkdirSync, openSync } from 'fs'
|
|
6
6
|
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const serverEntry = resolve(__dirname, '..', 'dist', 'server', 'index.js')
|
|
9
|
+
const PID_DIR = resolve(__dirname, '..', '.hermes-web-ui')
|
|
10
|
+
const PID_FILE = join(PID_DIR, 'server.pid')
|
|
11
|
+
const LOG_FILE = join(PID_DIR, 'server.log')
|
|
10
12
|
const DEFAULT_PORT = 8648
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'.json': 'application/json',
|
|
17
|
-
'.png': 'image/png',
|
|
18
|
-
'.svg': 'image/svg+xml',
|
|
19
|
-
'.ico': 'image/x-icon',
|
|
20
|
-
'.woff': 'font/woff',
|
|
21
|
-
'.woff2': 'font/woff2',
|
|
14
|
+
function getPort() {
|
|
15
|
+
if (process.argv[3] && !isNaN(process.argv[3])) return parseInt(process.argv[3])
|
|
16
|
+
if (process.argv.includes('--port')) return parseInt(process.argv[process.argv.indexOf('--port') + 1])
|
|
17
|
+
return DEFAULT_PORT
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
function getPid() {
|
|
21
|
+
try {
|
|
22
|
+
return parseInt(readFileSync(PID_FILE, 'utf-8').trim())
|
|
23
|
+
} catch {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
let filePath = join(distDir, reqPath)
|
|
28
|
+
function isRunning(pid) {
|
|
31
29
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const data = await readFile(filePath)
|
|
35
|
-
res.writeHead(200, {
|
|
36
|
-
'Content-Type': getMimeType(filePath),
|
|
37
|
-
'Cache-Control': 'public, max-age=3600',
|
|
38
|
-
})
|
|
39
|
-
res.end(data)
|
|
30
|
+
process.kill(pid, 0)
|
|
31
|
+
return true
|
|
40
32
|
} catch {
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const data = await readFile(join(distDir, 'index.html'))
|
|
44
|
-
res.writeHead(200, { 'Content-Type': 'text/html' })
|
|
45
|
-
res.end(data)
|
|
46
|
-
} catch {
|
|
47
|
-
res.writeHead(404, { 'Content-Type': 'text/plain' })
|
|
48
|
-
res.end('Not Found')
|
|
49
|
-
}
|
|
33
|
+
return false
|
|
50
34
|
}
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
delete headers['origin']
|
|
57
|
-
delete headers['referer']
|
|
37
|
+
function writePid(pid) {
|
|
38
|
+
writeFileSync(PID_FILE, String(pid))
|
|
39
|
+
}
|
|
58
40
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (hasBody) {
|
|
63
|
-
for await (const chunk of req) bodyChunks.push(chunk)
|
|
64
|
-
}
|
|
41
|
+
function removePid() {
|
|
42
|
+
try { unlinkSync(PID_FILE) } catch {}
|
|
43
|
+
}
|
|
65
44
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
function startDaemon(port) {
|
|
46
|
+
const existing = getPid()
|
|
47
|
+
if (existing && isRunning(existing)) {
|
|
48
|
+
console.log(` ✗ hermes-web-ui is already running (PID: ${existing})`)
|
|
49
|
+
console.log(` Use "hermes-web-ui stop" to stop it first`)
|
|
50
|
+
process.exit(1)
|
|
51
|
+
}
|
|
52
|
+
removePid() // stale pid file
|
|
53
|
+
mkdirSync(PID_DIR, { recursive: true })
|
|
71
54
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (done) break
|
|
89
|
-
res.write(value)
|
|
90
|
-
}
|
|
91
|
-
res.end()
|
|
92
|
-
}
|
|
93
|
-
await pump()
|
|
55
|
+
const logStream = openSync(LOG_FILE, 'a')
|
|
56
|
+
const child = spawn(process.execPath, [serverEntry], {
|
|
57
|
+
detached: true,
|
|
58
|
+
stdio: ['ignore', logStream, logStream],
|
|
59
|
+
env: { ...process.env, PORT: String(port) },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
child.unref()
|
|
63
|
+
writePid(child.pid)
|
|
64
|
+
|
|
65
|
+
// Wait a moment and check if the process is still alive
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
if (isRunning(child.pid)) {
|
|
68
|
+
console.log(` ✓ hermes-web-ui started (PID: ${child.pid}, port: ${port})`)
|
|
69
|
+
console.log(` http://localhost:${port}`)
|
|
70
|
+
console.log(` Log: ${LOG_FILE}`)
|
|
94
71
|
} else {
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
res.writeHead(502, { 'Content-Type': 'application/json' })
|
|
72
|
+
console.log(' ✗ Failed to start hermes-web-ui')
|
|
73
|
+
console.log(` Check log: ${LOG_FILE}`)
|
|
74
|
+
removePid()
|
|
75
|
+
process.exit(1)
|
|
100
76
|
}
|
|
101
|
-
|
|
102
|
-
}
|
|
77
|
+
}, 500)
|
|
103
78
|
}
|
|
104
79
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
80
|
+
function stopDaemon() {
|
|
81
|
+
const pid = getPid()
|
|
82
|
+
if (!pid) {
|
|
83
|
+
console.log(' ✗ hermes-web-ui is not running')
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
111
86
|
|
|
112
|
-
|
|
113
|
-
|
|
87
|
+
if (!isRunning(pid)) {
|
|
88
|
+
console.log(` ✗ Process ${pid} is not alive (stale PID file)`)
|
|
89
|
+
removePid()
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
114
92
|
|
|
115
|
-
|
|
116
|
-
|
|
93
|
+
try {
|
|
94
|
+
process.kill(pid, 'SIGTERM')
|
|
95
|
+
removePid()
|
|
96
|
+
console.log(` ✓ hermes-web-ui stopped (PID: ${pid})`)
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.log(` ✗ Failed to stop: ${err.message}`)
|
|
99
|
+
process.exit(1)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
117
102
|
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
function showStatus() {
|
|
104
|
+
const pid = getPid()
|
|
105
|
+
if (pid && isRunning(pid)) {
|
|
106
|
+
console.log(` ✓ hermes-web-ui is running (PID: ${pid})`)
|
|
120
107
|
} else {
|
|
121
|
-
|
|
108
|
+
if (pid) removePid() // clean stale
|
|
109
|
+
console.log(' ✗ hermes-web-ui is not running')
|
|
122
110
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const command = process.argv[2] || 'start'
|
|
114
|
+
|
|
115
|
+
switch (command) {
|
|
116
|
+
case 'start':
|
|
117
|
+
startDaemon(getPort())
|
|
118
|
+
break
|
|
119
|
+
case 'stop':
|
|
120
|
+
stopDaemon()
|
|
121
|
+
break
|
|
122
|
+
case 'restart':
|
|
123
|
+
stopDaemon()
|
|
124
|
+
setTimeout(() => startDaemon(getPort()), 500)
|
|
125
|
+
break
|
|
126
|
+
case 'status':
|
|
127
|
+
showStatus()
|
|
128
|
+
break
|
|
129
|
+
default:
|
|
130
|
+
// Direct run (foreground): hermes-web-ui [port]
|
|
131
|
+
const port = !isNaN(command) ? parseInt(command) : DEFAULT_PORT
|
|
132
|
+
const child = spawn(process.execPath, [serverEntry], {
|
|
133
|
+
stdio: 'inherit',
|
|
134
|
+
env: { ...process.env, PORT: String(port) },
|
|
135
|
+
})
|
|
136
|
+
child.on('exit', (code) => process.exit(code ?? 1))
|
|
137
|
+
process.on('SIGTERM', () => child.kill('SIGTERM'))
|
|
138
|
+
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
139
|
+
}
|