magpie-multi-usage 0.3.4 → 0.3.5
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/src/aggregator.mjs +1 -1
- package/src/github-store.mjs +1 -1
- package/src/http-server.mjs +1 -1
- package/src/sync-engine.mjs +1 -1
- package/src/ui/app.js +50 -4
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ Create a GitHub **fine-grained personal access token** scoped strictly to **Only
|
|
|
46
46
|
|
|
47
47
|
### 3. Configure each machine
|
|
48
48
|
|
|
49
|
-
- **Magpie Desktop / `magpie web`**: open **Multi-Device Usage** → **Settings** gear → set **Device display name** (optional), **Private GitHub repository** (`owner/repo`), and **PAT** → **Test connection** → **Save and sync
|
|
49
|
+
- **Magpie Desktop / `magpie web`**: open **Multi-Device Usage** → **Settings** gear → set **Device display name** (optional), **Private GitHub repository** (`owner/repo`), and **PAT** → **Test connection** → **Save and sync** (the Settings dialog closes automatically once save and sync succeed).
|
|
50
50
|
- **Headless `magpie serve` node**: set non-sensitive options (`repo`, `deviceName`, `pushEnabled`, `pushIntervalSec`) via `magpie plugin options`, and supply the PAT via `MAGPIE_MULTI_USAGE_GITHUB_TOKEN` (or a `0600`-mode `<dataDir>/credentials.json`) — never in plaintext `plugins.json`.
|
|
51
51
|
|
|
52
52
|
> [!NOTE]
|
package/README.zh-CN.md
CHANGED
|
@@ -46,7 +46,7 @@ Magpie 桌面端和 Web 端的模型与供应商标签页均支持加载内置
|
|
|
46
46
|
|
|
47
47
|
### 3. 配置每台机器
|
|
48
48
|
|
|
49
|
-
- **Magpie 桌面 / `magpie web`**:打开 **多端用量** → **设置**齿轮 → 填写 **设备显示名**(可选)、**私有 GitHub 仓库**(`owner/repo`)与 **PAT** → **测试连接** →
|
|
49
|
+
- **Magpie 桌面 / `magpie web`**:打开 **多端用量** → **设置**齿轮 → 填写 **设备显示名**(可选)、**私有 GitHub 仓库**(`owner/repo`)与 **PAT** → **测试连接** → **保存并同步**(保存与同步成功后设置窗口会自动关闭)。
|
|
50
50
|
- **无头 `magpie serve` 节点**:通过 `magpie plugin options` 设置非敏感项(`repo`、`deviceName`、`pushEnabled`、`pushIntervalSec`),PAT 通过环境变量 `MAGPIE_MULTI_USAGE_GITHUB_TOKEN`(或 `0600` 权限的 `<dataDir>/credentials.json`)提供——绝不写入明文 `plugins.json`。
|
|
51
51
|
|
|
52
52
|
> [!NOTE]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magpie-multi-usage",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Multi-device token usage dashboard plugin for Magpie using a dedicated private GitHub repository relay (no decryption passphrase required).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
package/src/aggregator.mjs
CHANGED
package/src/github-store.mjs
CHANGED
|
@@ -236,7 +236,7 @@ export function createGitHubRelayStore({
|
|
|
236
236
|
apiBaseUrl = DEFAULT_API_BASE_URL,
|
|
237
237
|
fetchImpl = globalThis.fetch,
|
|
238
238
|
timeoutMs = 15000,
|
|
239
|
-
pluginVersion = "0.3.
|
|
239
|
+
pluginVersion = "0.3.5",
|
|
240
240
|
} = {}) {
|
|
241
241
|
const normalizedRepo = normalizeRepo(repo);
|
|
242
242
|
if (!normalizedRepo) {
|
package/src/http-server.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { createSyncEngine } from "./sync-engine.mjs";
|
|
|
19
19
|
|
|
20
20
|
export const TOKEN_HEADER = "x-multi-usage-token";
|
|
21
21
|
export const DEFAULT_PORT = DEFAULT_CONFIG.port;
|
|
22
|
-
export const PLUGIN_VERSION = "0.3.
|
|
22
|
+
export const PLUGIN_VERSION = "0.3.5";
|
|
23
23
|
|
|
24
24
|
const MAX_JSON_BODY_BYTES = 256 * 1024;
|
|
25
25
|
const ALLOWED_RANGES = new Set(["today", "7d", "30d", "all"]);
|
package/src/sync-engine.mjs
CHANGED
package/src/ui/app.js
CHANGED
|
@@ -53,6 +53,7 @@ const state = {
|
|
|
53
53
|
sync: null,
|
|
54
54
|
config: null,
|
|
55
55
|
clearTokenRequested: false,
|
|
56
|
+
settingsReturnFocus: null,
|
|
56
57
|
requestGen: 0,
|
|
57
58
|
};
|
|
58
59
|
|
|
@@ -838,7 +839,34 @@ function populateSettingsForm(cfg) {
|
|
|
838
839
|
}
|
|
839
840
|
}
|
|
840
841
|
|
|
842
|
+
function isSettingsDrawerOpen() {
|
|
843
|
+
const drawer = document.getElementById("settings-drawer");
|
|
844
|
+
return Boolean(drawer && !drawer.classList.contains("hidden"));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function restoreSettingsFocus() {
|
|
848
|
+
const target = state.settingsReturnFocus;
|
|
849
|
+
state.settingsReturnFocus = null;
|
|
850
|
+
const canFocus = (node) => Boolean(
|
|
851
|
+
node
|
|
852
|
+
&& typeof node.focus === "function"
|
|
853
|
+
&& node !== document.body
|
|
854
|
+
&& document.body?.contains(node),
|
|
855
|
+
);
|
|
856
|
+
if (canFocus(target)) {
|
|
857
|
+
target.focus();
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const settingsBtn = document.getElementById("settings-btn");
|
|
861
|
+
if (canFocus(settingsBtn)) {
|
|
862
|
+
settingsBtn.focus();
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
841
866
|
async function openSettingsDrawer() {
|
|
867
|
+
if (!isSettingsDrawerOpen()) {
|
|
868
|
+
state.settingsReturnFocus = document.activeElement || null;
|
|
869
|
+
}
|
|
842
870
|
setFeedback("");
|
|
843
871
|
document.getElementById("drawer-backdrop").classList.remove("hidden");
|
|
844
872
|
document.getElementById("settings-drawer").classList.remove("hidden");
|
|
@@ -851,8 +879,12 @@ async function openSettingsDrawer() {
|
|
|
851
879
|
}
|
|
852
880
|
|
|
853
881
|
function closeSettingsDrawer() {
|
|
882
|
+
const wasOpen = isSettingsDrawerOpen();
|
|
854
883
|
document.getElementById("drawer-backdrop").classList.add("hidden");
|
|
855
884
|
document.getElementById("settings-drawer").classList.add("hidden");
|
|
885
|
+
if (wasOpen) {
|
|
886
|
+
restoreSettingsFocus();
|
|
887
|
+
}
|
|
856
888
|
}
|
|
857
889
|
|
|
858
890
|
async function loadConfigMeta() {
|
|
@@ -1035,15 +1067,29 @@ async function handleSaveSettings(event) {
|
|
|
1035
1067
|
if (refreshed.summary) {
|
|
1036
1068
|
handleSummarySuccess(refreshGen, refreshRange, refreshDevice, refreshed.summary);
|
|
1037
1069
|
}
|
|
1038
|
-
const
|
|
1070
|
+
const pullDeviceErrors = Object.values(refreshed.pull?.devices || {})
|
|
1071
|
+
.map((entry) => entry?.error)
|
|
1072
|
+
.filter(Boolean);
|
|
1073
|
+
const syncErrors = Array.from(new Set([
|
|
1039
1074
|
refreshed.local?.error,
|
|
1040
1075
|
refreshed.push?.error,
|
|
1041
1076
|
refreshed.pull?.error,
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1077
|
+
...pullDeviceErrors,
|
|
1078
|
+
].filter(Boolean)));
|
|
1079
|
+
const hasSyncFailure = syncErrors.length > 0
|
|
1080
|
+
|| refreshed.local?.ok === false
|
|
1081
|
+
|| refreshed.push?.ok === false
|
|
1082
|
+
|| refreshed.pull?.ok === false;
|
|
1083
|
+
if (hasSyncFailure) {
|
|
1084
|
+
const message = syncErrors.length > 0
|
|
1085
|
+
? syncErrors.join("; ")
|
|
1086
|
+
: (refreshed.summary?.sync?.lastPushError
|
|
1087
|
+
|| refreshed.summary?.sync?.lastPullError
|
|
1088
|
+
|| t(state.lang, "statusError"));
|
|
1089
|
+
setFeedback(message, "err");
|
|
1045
1090
|
} else {
|
|
1046
1091
|
setFeedback(t(state.lang, "savedSuccess"), "ok");
|
|
1092
|
+
closeSettingsDrawer();
|
|
1047
1093
|
}
|
|
1048
1094
|
} catch (err) {
|
|
1049
1095
|
if (refreshGen !== null) {
|