pi-hub-server 0.0.0-stage → 0.3.2
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 +21 -0
- package/README.md +403 -2
- package/bin/pi-hub.mjs +353 -0
- package/docs/AUTH.md +141 -0
- package/package.json +45 -4
- package/src/config.mjs +54 -0
- package/src/otp.mjs +162 -0
- package/src/pairing.mjs +403 -0
- package/src/pi-args.mjs +51 -0
- package/src/pi-session.mjs +635 -0
- package/src/proxy-auth.mjs +181 -0
- package/src/registry.mjs +145 -0
- package/src/rpc-once.mjs +83 -0
- package/src/server.mjs +1532 -0
- package/src/session-lock.mjs +42 -0
- package/src/sessions-index.mjs +179 -0
- package/src/static.mjs +148 -0
- package/src/totp.mjs +151 -0
- package/src/update-check.mjs +218 -0
- package/src/web-auth.mjs +450 -0
- package/systemd/pi-hub.service +22 -0
- package/web/app.js +1339 -0
- package/web/icons/icon.svg +7 -0
- package/web/index.html +121 -0
- package/web/manifest.webmanifest +20 -0
- package/web/style.css +782 -0
- package/web/sw.js +45 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-label="pi hub">
|
|
2
|
+
<rect width="512" height="512" rx="112" fill="#0f1115" />
|
|
3
|
+
<circle cx="256" cy="256" r="150" fill="none" stroke="#5aa9ff" stroke-width="28" />
|
|
4
|
+
<path d="M256 176v80l58 42" fill="none" stroke="#e6e9ef" stroke-width="26" stroke-linecap="round" />
|
|
5
|
+
<circle cx="256" cy="256" r="16" fill="#e6e9ef" />
|
|
6
|
+
<text x="256" y="452" font-family="system-ui, sans-serif" font-size="56" fill="#97a0b3" text-anchor="middle">π</text>
|
|
7
|
+
</svg>
|
package/web/index.html
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
6
|
+
<meta name="theme-color" content="#0f1115" />
|
|
7
|
+
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
8
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
9
|
+
<title>pi hub</title>
|
|
10
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
11
|
+
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml" />
|
|
12
|
+
<link rel="apple-touch-icon" href="/icons/icon.svg" />
|
|
13
|
+
<link rel="stylesheet" href="/style.css" />
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<!-- 登录页:一块令牌输入 + 「保持登录」说明 -->
|
|
17
|
+
<section id="login" class="screen login" hidden>
|
|
18
|
+
<form id="login-form" class="login-card" autocomplete="off">
|
|
19
|
+
<h1>pi hub</h1>
|
|
20
|
+
<p class="hint">粘贴主机令牌(<code>pi-hub token</code> 可查看),或输入主机上 <code>pi-hub web-login</code> 打印的一次性码。</p>
|
|
21
|
+
<label class="field">
|
|
22
|
+
<span>令牌</span>
|
|
23
|
+
<input id="login-token" type="password" inputmode="text" autocomplete="off" spellcheck="false" placeholder="bearer token" required />
|
|
24
|
+
</label>
|
|
25
|
+
<label class="field" id="login-totp-wrap" hidden>
|
|
26
|
+
<span>验证器码(TOTP)</span>
|
|
27
|
+
<input id="login-totp" type="text" inputmode="numeric" autocomplete="one-time-code" spellcheck="false" placeholder="6 位数字" />
|
|
28
|
+
</label>
|
|
29
|
+
<button id="login-submit" class="btn primary" type="submit">登录</button>
|
|
30
|
+
<p id="login-error" class="error" hidden></p>
|
|
31
|
+
<p class="hint small">
|
|
32
|
+
登录后浏览器会拿到一枚 <code>HttpOnly</code> 会话 cookie,默认 <strong>30 天</strong> 免登录;
|
|
33
|
+
在服务器上 <code>PI_HUB_WEB_TTL_MS</code> 可改有效期。令牌本身不落 localStorage。
|
|
34
|
+
</p>
|
|
35
|
+
</form>
|
|
36
|
+
</section>
|
|
37
|
+
|
|
38
|
+
<!-- 聊天页 -->
|
|
39
|
+
<section id="app" class="screen app" hidden>
|
|
40
|
+
<header class="topbar">
|
|
41
|
+
<button id="btn-drawer" class="icon-btn" type="button" aria-label="会话列表">☰</button>
|
|
42
|
+
<div class="title-block">
|
|
43
|
+
<span id="session-title" class="title">pi hub</span>
|
|
44
|
+
<span id="session-sub" class="sub"></span>
|
|
45
|
+
</div>
|
|
46
|
+
<span id="conn-dot" class="dot off" title="未连接"></span>
|
|
47
|
+
<button id="btn-menu" class="icon-btn" type="button" aria-label="更多">⋯</button>
|
|
48
|
+
</header>
|
|
49
|
+
|
|
50
|
+
<div id="menu" class="menu" hidden>
|
|
51
|
+
<button id="btn-rename" type="button">重命名会话</button>
|
|
52
|
+
<button id="btn-compact" type="button">压缩上下文</button>
|
|
53
|
+
<button id="btn-update" type="button">检查更新</button>
|
|
54
|
+
<button id="btn-logout" type="button" class="danger">退出登录</button>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<main id="messages" class="messages" tabindex="0"></main>
|
|
58
|
+
|
|
59
|
+
<button id="btn-jump" class="jump" type="button" hidden>↓ 最新</button>
|
|
60
|
+
|
|
61
|
+
<footer class="composer">
|
|
62
|
+
<div id="usage-bar" class="usage-bar" hidden>
|
|
63
|
+
<span id="usage-context"></span>
|
|
64
|
+
<span id="usage-cost"></span>
|
|
65
|
+
</div>
|
|
66
|
+
<div id="attachments" class="attachments" hidden></div>
|
|
67
|
+
<div id="ui-requests" class="ui-requests" hidden></div>
|
|
68
|
+
<textarea id="prompt" rows="1" placeholder="发消息…(Shift+Enter 换行)" spellcheck="false"></textarea>
|
|
69
|
+
<div class="composer-row">
|
|
70
|
+
<label class="select" title="模型">
|
|
71
|
+
<span class="sr">模型</span>
|
|
72
|
+
<select id="model-select"><option value="">模型…</option></select>
|
|
73
|
+
</label>
|
|
74
|
+
<label class="select" title="推理强度">
|
|
75
|
+
<span class="sr">推理强度</span>
|
|
76
|
+
<select id="thinking-select"><option value="">强度…</option></select>
|
|
77
|
+
</label>
|
|
78
|
+
<label class="icon-btn file" title="上传图片">
|
|
79
|
+
<input id="image-input" type="file" accept="image/*" multiple hidden />
|
|
80
|
+
<span>🖼</span>
|
|
81
|
+
</label>
|
|
82
|
+
<label class="icon-btn file" title="上传文档">
|
|
83
|
+
<input id="doc-input" type="file" hidden />
|
|
84
|
+
<span>📎</span>
|
|
85
|
+
</label>
|
|
86
|
+
<button id="btn-send" class="btn primary send" type="button">发送</button>
|
|
87
|
+
<button id="btn-stop" class="btn danger send" type="button" hidden>停止</button>
|
|
88
|
+
</div>
|
|
89
|
+
</footer>
|
|
90
|
+
</section>
|
|
91
|
+
|
|
92
|
+
<!-- 会话抽屉:搜索 / 分组 / 新建 -->
|
|
93
|
+
<aside id="drawer" class="drawer" hidden>
|
|
94
|
+
<div class="drawer-head">
|
|
95
|
+
<input id="session-search" type="search" placeholder="搜索会话…" spellcheck="false" />
|
|
96
|
+
<button id="btn-drawer-close" class="icon-btn" type="button" aria-label="关闭">✕</button>
|
|
97
|
+
</div>
|
|
98
|
+
<div id="session-list" class="session-list"></div>
|
|
99
|
+
<form id="new-session" class="new-session" autocomplete="off">
|
|
100
|
+
<div class="drawer-head">
|
|
101
|
+
<strong>新建会话</strong>
|
|
102
|
+
</div>
|
|
103
|
+
<label class="field">
|
|
104
|
+
<span>工作区 cwd</span>
|
|
105
|
+
<input id="new-cwd" list="cwd-options" placeholder="/home/me/project" spellcheck="false" required />
|
|
106
|
+
<datalist id="cwd-options"></datalist>
|
|
107
|
+
</label>
|
|
108
|
+
<label class="field">
|
|
109
|
+
<span>模型(可选)</span>
|
|
110
|
+
<select id="new-model"><option value="">默认</option></select>
|
|
111
|
+
</label>
|
|
112
|
+
<button class="btn primary" type="submit">开始</button>
|
|
113
|
+
<p id="new-error" class="error" hidden></p>
|
|
114
|
+
</form>
|
|
115
|
+
</aside>
|
|
116
|
+
<div id="scrim" class="scrim" hidden></div>
|
|
117
|
+
|
|
118
|
+
<div id="toast" class="toast" hidden></div>
|
|
119
|
+
<script type="module" src="/app.js"></script>
|
|
120
|
+
</body>
|
|
121
|
+
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi hub",
|
|
3
|
+
"short_name": "pi hub",
|
|
4
|
+
"description": "在手机浏览器里控制主机上的 pi 会话",
|
|
5
|
+
"lang": "zh-CN",
|
|
6
|
+
"start_url": "/",
|
|
7
|
+
"scope": "/",
|
|
8
|
+
"display": "standalone",
|
|
9
|
+
"orientation": "portrait-primary",
|
|
10
|
+
"background_color": "#0f1115",
|
|
11
|
+
"theme_color": "#0f1115",
|
|
12
|
+
"icons": [
|
|
13
|
+
{
|
|
14
|
+
"src": "/icons/icon.svg",
|
|
15
|
+
"sizes": "any",
|
|
16
|
+
"type": "image/svg+xml",
|
|
17
|
+
"purpose": "any maskable"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|