@juejin-opensource/jusage 0.1.6 → 0.1.8
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 -0
- package/dist/args.d.ts +20 -0
- package/dist/args.js +121 -0
- package/dist/daemon.d.ts +2 -2
- package/dist/daemon.js +8 -7
- package/dist/dashboard/assets/click-idle-CXAVCmiH.png +0 -0
- package/dist/dashboard/assets/dashboard-BcYn7CaU.js +55 -0
- package/dist/dashboard/assets/download-CteP_gYs.js +6 -0
- package/dist/dashboard/assets/downloads-dKq4xNjC.js +1 -0
- package/dist/dashboard/assets/hawking-idle-QoXt5bST.png +0 -0
- package/dist/dashboard/assets/index-BfeJy_UY.js +1 -0
- package/dist/dashboard/assets/index-CWwN4M6h.css +1 -0
- package/dist/dashboard/assets/{index-C-ulpYDE.js → index-flWmwEjH.js} +31 -31
- package/dist/dashboard/assets/model-provider-0f_aGOIG.js +1 -0
- package/dist/dashboard/assets/pricing-OObJBgJw.js +1 -0
- package/dist/dashboard/assets/rank-CuAJ5i73.js +16 -0
- package/dist/dashboard/assets/{settings-Cud6Sr27.js → settings-KbZOVhnT.js} +1 -1
- package/dist/dashboard/assets/useLocalStorage-BdF6kE3i.js +1 -0
- package/dist/dashboard/assets/yoyo-idle-DDvV3ieO.png +0 -0
- package/dist/dashboard/captain-wechat.jpg +0 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/index.d.ts +1 -10
- package/dist/index.js +21 -93
- package/dist/service.d.ts +4 -1
- package/dist/service.js +19 -8
- package/package.json +3 -3
- package/dist/dashboard/assets/ChevronDown-hI5eRGzD.js +0 -1
- package/dist/dashboard/assets/click-idle-6pQvdt8N.png +0 -0
- package/dist/dashboard/assets/dashboard-CAkIFa6U.js +0 -55
- package/dist/dashboard/assets/download-ByMnRiaK.js +0 -1
- package/dist/dashboard/assets/downloads-C3JkgIXC.js +0 -1
- package/dist/dashboard/assets/env-Cw7aSECu.js +0 -1
- package/dist/dashboard/assets/hawking-idle-C6M3ZvDm.png +0 -0
- package/dist/dashboard/assets/index-CeqvL8Jz.js +0 -1
- package/dist/dashboard/assets/index-CmpX7J2H.css +0 -1
- package/dist/dashboard/assets/pricing-J0aEt4op.js +0 -1
- package/dist/dashboard/assets/rank-DNcLrJpg.js +0 -16
- package/dist/dashboard/assets/yoyo-idle-DmXh5tLT.png +0 -0
package/dist/service.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { platform } from 'node:os';
|
|
2
|
-
import { DEFAULT_DATA_DIR, DEFAULT_PORT, getRunningOwner, loadConfig, runtimeKindLabel, touchStatsSince, } from '@juejin-opensource/jusage-core';
|
|
2
|
+
import { DEFAULT_DATA_DIR, DEFAULT_PORT, getRunningOwner, loadConfig, runtimeKindLabel, saveConfig, touchStatsSince, } from '@juejin-opensource/jusage-core';
|
|
3
3
|
import { clearPid, daemonLogPath, readDaemonLogTail, stopPid, waitForServiceReady, } from './daemon.js';
|
|
4
|
+
import { DEFAULT_HOST, formatListenUrl } from './args.js';
|
|
4
5
|
import { isLinuxAutostartRegistered, registerLinuxAutostart, unregisterLinuxAutostart, } from './service-linux.js';
|
|
5
6
|
import { isMacosAutostartRegistered, registerMacosAutostart, unregisterMacosAutostart, } from './service-macos.js';
|
|
6
7
|
import { isWindowsAutostartRegistered, registerWindowsAutostart, unregisterWindowsAutostart, } from './service-windows.js';
|
|
@@ -42,7 +43,7 @@ async function unregisterAutostart() {
|
|
|
42
43
|
}
|
|
43
44
|
await unregisterLinuxAutostart();
|
|
44
45
|
}
|
|
45
|
-
export async function cmdServiceStart(cliBinPath, daysAgo) {
|
|
46
|
+
export async function cmdServiceStart(cliBinPath, daysAgo, listen) {
|
|
46
47
|
assertSupportedPlatform();
|
|
47
48
|
const startedAt = Date.now();
|
|
48
49
|
const waitTimer = setInterval(() => {
|
|
@@ -50,16 +51,23 @@ export async function cmdServiceStart(cliBinPath, daysAgo) {
|
|
|
50
51
|
console.log(` 仍在等待检测中(已 ${elapsed}s)…`);
|
|
51
52
|
}, 3_000);
|
|
52
53
|
try {
|
|
53
|
-
await cmdServiceStartBody(cliBinPath, daysAgo);
|
|
54
|
+
await cmdServiceStartBody(cliBinPath, daysAgo, listen);
|
|
54
55
|
}
|
|
55
56
|
finally {
|
|
56
57
|
clearInterval(waitTimer);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
async function cmdServiceStartBody(cliBinPath, daysAgo) {
|
|
60
|
+
async function cmdServiceStartBody(cliBinPath, daysAgo, listen) {
|
|
60
61
|
const { dir, config } = await loadConfig();
|
|
61
62
|
// Seed statsSince before launchd starts `jusage start` (do not bake --days into plist).
|
|
62
63
|
await touchStatsSince(dir, config, daysAgo != null ? { daysAgo } : undefined);
|
|
64
|
+
if (listen?.port != null)
|
|
65
|
+
config.serverPort = listen.port;
|
|
66
|
+
if (listen?.host != null)
|
|
67
|
+
config.serverHost = listen.host;
|
|
68
|
+
if (listen?.port != null || listen?.host != null) {
|
|
69
|
+
await saveConfig(dir, config);
|
|
70
|
+
}
|
|
63
71
|
const existing = await getRunningOwner(dir);
|
|
64
72
|
if (existing != null) {
|
|
65
73
|
// Already running: still ensure autostart is registered.
|
|
@@ -76,12 +84,13 @@ async function cmdServiceStartBody(cliBinPath, daysAgo) {
|
|
|
76
84
|
console.log(' 提示: 当前 runtime owner 是桌面端,同步/上报由桌面负责');
|
|
77
85
|
console.log(' 如需浏览器面板,可另开终端执行 jusage start(观察模式,只读)');
|
|
78
86
|
}
|
|
79
|
-
console.log(` 面板:
|
|
87
|
+
console.log(` 面板: ${formatListenUrl(config.serverHost || DEFAULT_HOST, config.serverPort || DEFAULT_PORT)}`);
|
|
80
88
|
return;
|
|
81
89
|
}
|
|
82
90
|
await registerAutostart(cliBinPath, dir);
|
|
83
91
|
const port = config.serverPort || DEFAULT_PORT;
|
|
84
|
-
const
|
|
92
|
+
const host = config.serverHost || DEFAULT_HOST;
|
|
93
|
+
const ready = await waitForServiceReady(dir, port, host);
|
|
85
94
|
if (ready.pid == null && !ready.health) {
|
|
86
95
|
const logPath = daemonLogPath(dir);
|
|
87
96
|
const tail = await readDaemonLogTail(dir);
|
|
@@ -90,13 +99,14 @@ async function cmdServiceStartBody(cliBinPath, daysAgo) {
|
|
|
90
99
|
}
|
|
91
100
|
const { config: refreshed } = await loadConfig(dir);
|
|
92
101
|
const panelPort = refreshed.serverPort || DEFAULT_PORT;
|
|
102
|
+
const panelHost = refreshed.serverHost || DEFAULT_HOST;
|
|
93
103
|
if (ready.pid != null) {
|
|
94
104
|
console.log(`✓ 服务已在后台启动 (pid ${ready.pid})`);
|
|
95
105
|
}
|
|
96
106
|
else {
|
|
97
107
|
console.log('✓ 服务已在后台启动(面板 /health 已就绪)');
|
|
98
108
|
}
|
|
99
|
-
console.log(` 面板:
|
|
109
|
+
console.log(` 面板: ${formatListenUrl(panelHost, panelPort)}`);
|
|
100
110
|
console.log(` 数据: ${dir}`);
|
|
101
111
|
console.log(` 开机自启: 已注册`);
|
|
102
112
|
console.log(` 日志: ${dir}/logs/daemon.log`);
|
|
@@ -127,6 +137,7 @@ export async function cmdServiceStatus() {
|
|
|
127
137
|
const owner = await getRunningOwner(dir);
|
|
128
138
|
const registered = await isAutostartRegistered();
|
|
129
139
|
const port = config.serverPort || DEFAULT_PORT;
|
|
140
|
+
const host = config.serverHost || DEFAULT_HOST;
|
|
130
141
|
if (owner != null) {
|
|
131
142
|
console.log(`服务: 运行中(${runtimeKindLabel(owner.kind)} pid ${owner.pid})`);
|
|
132
143
|
}
|
|
@@ -134,7 +145,7 @@ export async function cmdServiceStatus() {
|
|
|
134
145
|
console.log('服务: 未运行');
|
|
135
146
|
}
|
|
136
147
|
console.log(`开机自启: ${registered ? '已注册' : '未注册'}`);
|
|
137
|
-
console.log(`面板:
|
|
148
|
+
console.log(`面板: ${formatListenUrl(host, port)}`);
|
|
138
149
|
console.log(`数据: ${dir || DEFAULT_DATA_DIR}`);
|
|
139
150
|
console.log(`云端同步: ${config.juejin.enabled ? '已开启' : '未开启'} → ${config.juejin.apiUrl}`);
|
|
140
151
|
console.log(`上次同步: ${config.lastSyncAt ?? '从未'}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juejin-opensource/jusage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Juejin AI Usage 统计 CLI:Token 用量明细追踪,本地记录、云端同步,内置用量看板。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@juejin-opensource/jusage-core": "0.1.
|
|
37
|
+
"@juejin-opensource/jusage-core": "0.1.8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^22.13.10",
|
|
41
41
|
"typescript": "^5.8.2",
|
|
42
|
-
"@juejin-opensource/jusage-dashboard": "0.1.
|
|
42
|
+
"@juejin-opensource/jusage-dashboard": "0.1.8"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=20"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as p,R as l,j as t,cc as v,r as s,cd as g,a9 as c,be as f,c8 as x,a7 as h,bQ as w,ce as u,cf as m,b4 as b}from"./index-C-ulpYDE.js";const $=p({slots:{base:"popover",dialog:"popover__dialog",heading:"popover__heading",trigger:"popover__trigger"}}),n=s.createContext({}),d=({children:o,...r})=>{const a=l.useMemo(()=>$(),[]);return t.jsx(n,{value:{slots:a},children:t.jsx(v,{"data-slot":"popover-root",...r,children:o})})},j=({children:o,className:r,...a})=>{const{slots:e}=s.use(n);return t.jsx(n,{value:{slots:e},children:t.jsx(f,{value:{variant:"default"},children:t.jsx(x,{...a,className:h(r,e==null?void 0:e.base()),children:o})})})},C=({children:o,className:r,...a})=>{const e=t.jsx("svg",{"data-slot":"popover-overlay-arrow",fill:"none",height:"12",viewBox:"0 0 12 12",width:"12",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M0 0C5.48483 8 6.5 8 12 0Z"})}),i=l.isValidElement(o)?l.cloneElement(o,{"data-slot":"popover-overlay-arrow"}):e;return t.jsx(w,{"data-slot":"popover-overlay-arrow-group",...a,className:r,children:i})},P=({children:o,className:r,...a})=>{const{slots:e}=s.use(n);return t.jsx(u,{"data-slot":"popover-dialog",...a,className:c(e==null?void 0:e.dialog,r),children:o})},R=({children:o,className:r,...a})=>{const{slots:e}=s.use(n);return t.jsx(m,{children:t.jsx(b.div,{className:c(e==null?void 0:e.trigger,r),"data-slot":"popover-trigger",role:"button",...a,children:o})})},E=({children:o,className:r,...a})=>{const{slots:e}=s.use(n);return t.jsx(g,{slot:"title",...a,className:c(e==null?void 0:e.heading,r),children:o})},_=Object.assign(d,{Root:d,Trigger:R,Dialog:P,Arrow:C,Content:j,Heading:E}),A=o=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",width:16,height:16,fill:"none",viewBox:"0 0 16 16"},o),s.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M13.488 3.43a.75.75 0 0 1 .081 1.058l-6 7a.75.75 0 0 1-1.1.042l-3.5-3.5A.75.75 0 0 1 4.03 6.97l2.928 2.927 5.473-6.385a.75.75 0 0 1 1.057-.081",clipRule:"evenodd"})),M=o=>s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",width:16,height:16,fill:"none",viewBox:"0 0 16 16"},o),s.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06",clipRule:"evenodd"}));export{M as C,_ as P,A as a};
|
|
Binary file
|