@raingor/pi-web-switch 0.4.2 → 0.4.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/dist/index.html +18 -0
- package/package.json +5 -38
- package/public/apple-touch-icon.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/pi.svg +41 -6
- package/server/pi-reader.ts +28 -219
- package/src/components/dashboard/DashboardPage.tsx +0 -29
- package/src/components/layout/Sidebar.tsx +3 -14
- package/src/components/sessions/MemoryPage.tsx +2 -1
- package/src/components/sessions/SessionsPage.tsx +2 -36
- package/src/lib/translations/en.ts +0 -5
- package/src/lib/translations/ja.ts +0 -5
- package/src/lib/translations/zh-CN.ts +0 -5
- package/src/lib/translations/zh-TW.ts +0 -5
- package/src/main.tsx +5 -29
- package/src/types/index.ts +0 -1
- package/vite.config.ts +3 -27
- package/dist-electron/main/main.cjs +0 -2453
|
@@ -236,11 +236,6 @@ const zhTW: Record<string, string> = {
|
|
|
236
236
|
"sessions.delete_error": "刪除時發生錯誤",
|
|
237
237
|
"sessions.load_failed": "載入會話失敗",
|
|
238
238
|
"sessions.refresh": "重新整理",
|
|
239
|
-
"sessions.auto_expire": "自動清理",
|
|
240
|
-
"sessions.auto_expire_tooltip": "將 {0} 天未活躍的會話移入回收筒",
|
|
241
|
-
"sessions.auto_expire_success": "已將 {0} 個過期會話移入回收筒",
|
|
242
|
-
"sessions.auto_expire_none": "沒有找到過期會話",
|
|
243
|
-
"sessions.auto_expire_error": "自動清理失敗:{0}",
|
|
244
239
|
"sessions.expand_all": "全部展開",
|
|
245
240
|
"sessions.collapse_all": "全部收合",
|
|
246
241
|
"sessions.more_count": "還有 {0} 條",
|
package/src/main.tsx
CHANGED
|
@@ -126,34 +126,10 @@ createRoot(document.getElementById("root")!).render(
|
|
|
126
126
|
// ─── PWA: register service worker (production only — dev must not
|
|
127
127
|
// cache HTML pages, or SPA routes like /providers can return stale HTML
|
|
128
128
|
// to API fetches and break JSON parsing) ─────────────────────
|
|
129
|
-
if ("serviceWorker" in navigator) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.warn("SW registration failed:", err);
|
|
134
|
-
});
|
|
129
|
+
if ("serviceWorker" in navigator && import.meta.env.PROD) {
|
|
130
|
+
window.addEventListener("load", () => {
|
|
131
|
+
navigator.serviceWorker.register("/sw.js").catch((err) => {
|
|
132
|
+
console.warn("SW registration failed:", err);
|
|
135
133
|
});
|
|
136
|
-
}
|
|
137
|
-
// Dev: proactively unregister any leftover service worker (e.g. from a
|
|
138
|
-
// previous `vite preview` or production build on the same origin) and
|
|
139
|
-
// clear its caches. Dev module URLs are not hashed, so a stale SW would
|
|
140
|
-
// serve old code on every plain reload until a hard refresh.
|
|
141
|
-
window.addEventListener("load", () => {
|
|
142
|
-
navigator.serviceWorker
|
|
143
|
-
.getRegistrations()
|
|
144
|
-
.then((registrations) =>
|
|
145
|
-
Promise.all(registrations.map((reg) => reg.unregister()))
|
|
146
|
-
)
|
|
147
|
-
.then(() =>
|
|
148
|
-
window.caches
|
|
149
|
-
? window.caches.keys().then((keys) =>
|
|
150
|
-
Promise.all(keys.map((k) => window.caches.delete(k)))
|
|
151
|
-
)
|
|
152
|
-
: undefined
|
|
153
|
-
)
|
|
154
|
-
.catch((err) => {
|
|
155
|
-
console.warn("SW cleanup failed:", err);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
}
|
|
134
|
+
});
|
|
159
135
|
}
|
package/src/types/index.ts
CHANGED
package/vite.config.ts
CHANGED
|
@@ -7,16 +7,12 @@ import type { Connect } from "vite";
|
|
|
7
7
|
// ─── Pi Config API Plugin ───────────────────────────────
|
|
8
8
|
|
|
9
9
|
function piApiPlugin(): Plugin {
|
|
10
|
-
// Lazy-load the server-side module (Node.js only)
|
|
11
|
-
let pi: typeof import("./server/pi-reader");
|
|
12
|
-
let builtins: typeof import("./src/data/builtin-providers");
|
|
13
|
-
|
|
14
10
|
return {
|
|
15
11
|
name: "pi-api",
|
|
16
12
|
configureServer(server) {
|
|
17
|
-
//
|
|
18
|
-
pi = require("./server/pi-reader");
|
|
19
|
-
builtins = require("./src/data/builtin-providers");
|
|
13
|
+
// Lazy-load the server-side module (Node.js only)
|
|
14
|
+
const pi = require("./server/pi-reader");
|
|
15
|
+
const builtins = require("./src/data/builtin-providers");
|
|
20
16
|
|
|
21
17
|
// Warm the usage cache in the background so the dashboard's first
|
|
22
18
|
// request doesn't block on scanning ~150MB of session JSONL.
|
|
@@ -33,9 +29,6 @@ function piApiPlugin(): Plugin {
|
|
|
33
29
|
}
|
|
34
30
|
}, 0);
|
|
35
31
|
|
|
36
|
-
// Start the auto-expiry timer: scan once at startup, then every 24h.
|
|
37
|
-
try { pi.startAutoExpiryTimer(); } catch { /* ignore */ }
|
|
38
|
-
|
|
39
32
|
const routes: Record<string, (req: Connect.IncomingMessage, res: any) => void> = {
|
|
40
33
|
"GET /api/pi/settings"(_, res) {
|
|
41
34
|
const data = pi.readSettings();
|
|
@@ -187,21 +180,6 @@ function piApiPlugin(): Plugin {
|
|
|
187
180
|
}
|
|
188
181
|
});
|
|
189
182
|
},
|
|
190
|
-
"POST /api/pi/session/auto-expire"(req, res) {
|
|
191
|
-
let body = "";
|
|
192
|
-
req.on("data", (chunk: string) => (body += chunk));
|
|
193
|
-
req.on("end", () => {
|
|
194
|
-
try {
|
|
195
|
-
const result = pi.autoExpireSessions();
|
|
196
|
-
res.setHeader("Content-Type", "application/json");
|
|
197
|
-
res.end(JSON.stringify({ success: true, ...result }));
|
|
198
|
-
} catch {
|
|
199
|
-
res.statusCode = 500;
|
|
200
|
-
res.setHeader("Content-Type", "application/json");
|
|
201
|
-
res.end(JSON.stringify({ success: false, error: "Auto-expire failed" }));
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
},
|
|
205
183
|
"GET /api/pi/session-preview"(req, res) {
|
|
206
184
|
const parsedUrl = new URL(req.url!, "http://localhost");
|
|
207
185
|
const p = parsedUrl.searchParams.get("path") || "";
|
|
@@ -571,8 +549,6 @@ export default defineConfig({
|
|
|
571
549
|
rollupOptions: {
|
|
572
550
|
input: {
|
|
573
551
|
main: path.resolve(__dirname, "index.html"),
|
|
574
|
-
// Menu-bar popup (used by the Electron tray app)
|
|
575
|
-
popup: path.resolve(__dirname, "electron/popup.html"),
|
|
576
552
|
},
|
|
577
553
|
},
|
|
578
554
|
},
|