dsh-island 0.4.0 → 0.6.0
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 +56 -11
- package/desktop/index.html +18 -0
- package/desktop/island.css +44 -0
- package/desktop/main.cjs +77 -9
- package/desktop/preload.cjs +5 -0
- package/desktop/renderer.js +136 -18
- package/desktop/stats-preload.cjs +5 -0
- package/desktop/stats.css +86 -0
- package/desktop/stats.html +62 -0
- package/desktop/stats.js +147 -0
- package/package.json +2 -2
- package/src/approvals.js +89 -0
- package/src/chat.js +66 -0
- package/src/host.js +51 -7
- package/src/pricing.js +42 -0
- package/src/settings.js +5 -2
- package/src/state.js +10 -4
- package/src/usage.js +181 -0
- package/web/client.js +16 -1
package/desktop/renderer.js
CHANGED
|
@@ -3,8 +3,8 @@ import {STATES} from '../src/state.js';
|
|
|
3
3
|
const $=id=>document.getElementById(id);
|
|
4
4
|
const island=$('island'),stage=$('stage'),bridge=window.island;
|
|
5
5
|
let current={activity:{state:'idle'},settings:{position:'top-center',scale:1,motion:'full'}};
|
|
6
|
-
let expanded=false,peek=false,burstUntil=0,lastState='',boundsFrame,burstTimer,peekTimer,leaveTimer,armTimer,listKey='',autoOpened=false;
|
|
7
|
-
const drafts=new Map(),seenAsk=new Set();
|
|
6
|
+
let expanded=false,peek=false,burstUntil=0,lastState='',boundsFrame,burstTimer,peekTimer,leaveTimer,armTimer,hoverTimer,listKey='',autoOpened=false,hoverOpened=false,lastReply='';
|
|
7
|
+
const drafts=new Map(),seenAsk=new Set(),seenApproval=new Map(),sentApproval=new Map();
|
|
8
8
|
|
|
9
9
|
// 出现时短暂"弹出"以示提醒;思考仅在新任务开始时弹出。
|
|
10
10
|
const BURST={thinking:1700,waiting:3600,completed:3000,error:3800,paused:2200,offline:2600};
|
|
@@ -41,7 +41,8 @@ function applyShape(){
|
|
|
41
41
|
function fitPanel(){island.style.height=expanded?`${Math.min(innerHeight-24,$('panel').scrollHeight+76)}px`:'';}
|
|
42
42
|
|
|
43
43
|
function expand(value){
|
|
44
|
-
expanded=value;peek=false;clearTimeout(peekTimer);
|
|
44
|
+
expanded=value;peek=false;clearTimeout(peekTimer);clearTimeout(hoverTimer);
|
|
45
|
+
if(!value)hoverOpened=false;
|
|
45
46
|
island.dataset.expanded=String(value);
|
|
46
47
|
$('capsule').setAttribute('aria-expanded',String(value));
|
|
47
48
|
$('capsule').setAttribute('aria-label',value?'收起 DeepSeek 灵动岛':'展开 DeepSeek 灵动岛');
|
|
@@ -56,19 +57,30 @@ function burst(ms){
|
|
|
56
57
|
burstTimer=setTimeout(applyShape,ms+20);applyShape();
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
+
// 悬停:轻停片刻先舒展;停留更久(可在设置里关闭)直接展开面板,离开后收回。
|
|
61
|
+
const busyHere=()=>!!(askOf()||approvalOf()||document.activeElement?.matches('select,input,textarea'));
|
|
60
62
|
island.addEventListener('mouseenter',()=>{
|
|
61
|
-
clearTimeout(leaveTimer);clearTimeout(peekTimer);
|
|
62
|
-
if(
|
|
63
|
+
clearTimeout(leaveTimer);clearTimeout(peekTimer);clearTimeout(hoverTimer);
|
|
64
|
+
if(expanded)return;
|
|
65
|
+
peekTimer=setTimeout(()=>{peek=true;applyShape();},140);
|
|
66
|
+
if(current.prefs?.hoverExpand!==false)hoverTimer=setTimeout(()=>{if(!expanded){hoverOpened=true;autoOpened=false;expand(true);}},700);
|
|
63
67
|
});
|
|
64
68
|
island.addEventListener('mouseleave',()=>{
|
|
65
|
-
clearTimeout(peekTimer);
|
|
69
|
+
clearTimeout(peekTimer);clearTimeout(hoverTimer);
|
|
66
70
|
if(peek){peekTimer=setTimeout(()=>{peek=false;applyShape();},220);}
|
|
67
|
-
if(expanded)leaveTimer=setTimeout(()=>{if(expanded&&!
|
|
71
|
+
if(expanded)leaveTimer=setTimeout(()=>{if(expanded&&!busyHere())expand(false);},hoverOpened?450:6000);
|
|
68
72
|
});
|
|
69
73
|
|
|
70
|
-
$('capsule').addEventListener('click',()=>{autoOpened=false;expand(!expanded);});
|
|
74
|
+
$('capsule').addEventListener('click',()=>{autoOpened=false;const pinned=hoverOpened;hoverOpened=false;clearTimeout(hoverTimer);if(pinned&&expanded){applyShape();return;}expand(!expanded);});
|
|
71
75
|
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&expanded)expand(false);});
|
|
76
|
+
// 点击灵动岛以外的地方即收起:按下时让窗口拿到焦点,失焦时收起(提问草稿保留,重新展开可继续)。
|
|
77
|
+
island.addEventListener('pointerdown',()=>bridge.engage?.(),true);
|
|
78
|
+
function dismiss(){
|
|
79
|
+
clearTimeout(leaveTimer);clearTimeout(hoverTimer);clearTimeout(peekTimer);
|
|
80
|
+
if(peek){peek=false;applyShape();}
|
|
81
|
+
if(expanded){autoOpened=false;expand(false);}
|
|
82
|
+
}
|
|
83
|
+
const offBlur=bridge.onBlur?.(dismiss);
|
|
72
84
|
document.addEventListener('contextmenu',e=>{e.preventDefault();bridge.menu();});
|
|
73
85
|
// 停止任务需要点两次:第一次变红确认,3 秒内再点才真正停止。
|
|
74
86
|
function disarm(){clearTimeout(armTimer);$('stop').dataset.armed='false';$('stop-label').textContent='停止任务';}
|
|
@@ -78,6 +90,8 @@ $('stop').addEventListener('click',()=>{
|
|
|
78
90
|
});
|
|
79
91
|
$('more').addEventListener('click',()=>bridge.menu());
|
|
80
92
|
$('open-harness').addEventListener('click',()=>bridge.open());
|
|
93
|
+
$('stats').addEventListener('click',()=>bridge.stats?.());
|
|
94
|
+
$('reply').addEventListener('click',()=>bridge.open());
|
|
81
95
|
$('hide').addEventListener('click',()=>{expand(false);bridge.hide();});
|
|
82
96
|
for(const [key,value] of Object.entries(STATES)){const o=document.createElement('option');o.value=key;o.textContent=value.label;$('demo-state').append(o);}
|
|
83
97
|
$('demo-state').addEventListener('change',()=>bridge.preview($('demo-state').value));
|
|
@@ -154,6 +168,87 @@ function advance(){
|
|
|
154
168
|
$('ask').addEventListener('submit',e=>{e.preventDefault();if(!$('ask-next').disabled)advance();});
|
|
155
169
|
$('ask-skip').addEventListener('click',()=>{const c=currentAsk();if(!c)return;c.ans.selected=[];c.ans.custom='';$('ask-custom').value='';advance();});
|
|
156
170
|
|
|
171
|
+
// 审批卡:在灵动岛里允许一次或拒绝工具调用;出现后短暂锁定按钮,防止误点。
|
|
172
|
+
function approvalOf(){return current.prefs?.approvals!==false?(current.activity?.approvals||[])[0]:undefined;}
|
|
173
|
+
function renderApprove(){
|
|
174
|
+
const a=approvalOf();$('approve').hidden=!a;
|
|
175
|
+
if(!a)return false;
|
|
176
|
+
if(!seenApproval.has(a.id))seenApproval.set(a.id,Date.now());
|
|
177
|
+
const details=current.prefs?.details!==false,count=(current.activity.approvals||[]).length;
|
|
178
|
+
$('approve-title').textContent=`${toolLabel(a.toolName)} 需要你批准`+(details&&a.title?` · ${a.title}`:'');
|
|
179
|
+
$('approve-count').textContent=count>1?`还有 ${count-1} 个`:'';
|
|
180
|
+
$('approve-reason').textContent=a.reason||'Agent 想执行一个需要授权的操作。';
|
|
181
|
+
const detail=details?a.detail:null;
|
|
182
|
+
$('approve-detail').hidden=!detail;
|
|
183
|
+
if(detail){$('approve-label').textContent=detail.label;$('approve-text').textContent=detail.text;$('approve-text').classList.toggle('plain',!detail.mono);}
|
|
184
|
+
const sent=sentApproval.get(a.id),result=current.approvalResults?.[a.id],failed=result&&!result.ok&&result.at>(sent||0);
|
|
185
|
+
if(failed)sentApproval.delete(a.id);
|
|
186
|
+
const sending=sentApproval.has(a.id),locked=Date.now()-seenApproval.get(a.id)<600;
|
|
187
|
+
$('approve-allow').disabled=$('approve-reject').disabled=sending||locked;
|
|
188
|
+
if(locked)setTimeout(renderApprove,620-(Date.now()-seenApproval.get(a.id)));
|
|
189
|
+
const st=$('approve-status');st.className='ask-status'+(failed?' err':'');
|
|
190
|
+
st.textContent=sending?'正在提交…':failed?result.reason:'持久授权请在 Harness 中设置';
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
function decide(outcome){const a=approvalOf();if(!a||sentApproval.has(a.id)||$('approve-allow').disabled)return;sentApproval.set(a.id,Date.now());bridge.approve(a.id,outcome);renderApprove();}
|
|
194
|
+
$('approve').addEventListener('submit',e=>{e.preventDefault();decide('allowed-once');});
|
|
195
|
+
$('approve-reject').addEventListener('click',()=>decide('rejected'));
|
|
196
|
+
|
|
197
|
+
// 继续对话:给当前(或最近一个)任务发消息,和在 Harness 输入框里发一样;任务进行中可以排队或插话。
|
|
198
|
+
let chatSent=null,chatStatusTimer;
|
|
199
|
+
function chatOf(){return current.prefs?.chat!==false?current.activity?.chat:null;}
|
|
200
|
+
function renderChat(){
|
|
201
|
+
const c=chatOf();$('chat').hidden=!c;
|
|
202
|
+
if(!c)return false;
|
|
203
|
+
const details=current.prefs?.details!==false,running=!!c.running;
|
|
204
|
+
const onShow=current.activity?.sessionId===c.sessionId&&!['idle','offline'].includes(current.activity?.state);
|
|
205
|
+
$('chat-title').textContent=onShow?'给这个任务发消息':details&&c.title?c.title:'继续对话';
|
|
206
|
+
const text=running?`${STATES[c.state]?.label??'正在处理'}…`:details?(c.reply||''):'';
|
|
207
|
+
const box=$('chat-reply');box.classList.toggle('live',running);box.hidden=!text;
|
|
208
|
+
if(box.textContent!==text){box.textContent=text;box.scrollTop=0;}
|
|
209
|
+
$('chat-steer').hidden=!running;
|
|
210
|
+
$('chat-send').textContent=running?'排队':'发送';
|
|
211
|
+
$('chat-send').title=running?'这一轮结束后发送':'';
|
|
212
|
+
const r=chatSent&¤t.chatResults?.[chatSent.id],sending=!!chatSent&&!r;
|
|
213
|
+
if(r){
|
|
214
|
+
if(r.ok&&!chatSent.done){if($('chat-input').value===chatSent.text){$('chat-input').value='';grow();}chatSent.done=Date.now();clearTimeout(chatStatusTimer);chatStatusTimer=setTimeout(()=>{if(chatSent?.done){chatSent=null;renderChat();}},4000);}
|
|
215
|
+
else if(!r.ok&&!chatSent.failed)chatSent.failed=true;
|
|
216
|
+
}
|
|
217
|
+
const empty=!$('chat-input').value.trim();
|
|
218
|
+
$('chat-input').disabled=sending;
|
|
219
|
+
$('chat-send').disabled=$('chat-steer').disabled=sending||empty;
|
|
220
|
+
const st=$('chat-status');
|
|
221
|
+
st.className='ask-status'+(r&&!r.ok?' err':r?.ok?' ok':'');
|
|
222
|
+
st.textContent=sending?'正在发送…':r?(r.ok?(r.mode==='steer'?'已插话,Agent 下一步会看到':chatSent.running?'已排队,这一轮结束后发送':'已发送'):r.reason||'发送失败'):'';
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
function grow(){const t=$('chat-input');t.style.height='auto';t.style.height=`${Math.min(96,t.scrollHeight+2)}px`;if(expanded)fitPanel();}
|
|
226
|
+
function sendChat(mode){
|
|
227
|
+
const c=chatOf(),text=$('chat-input').value.trim();
|
|
228
|
+
if(!c||!text||(chatSent&&!current.chatResults?.[chatSent.id]))return;
|
|
229
|
+
const id=`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;
|
|
230
|
+
chatSent={id,text:$('chat-input').value,running:!!c.running};clearTimeout(chatStatusTimer);
|
|
231
|
+
bridge.chat(id,c.sessionId,text,mode);renderChat();
|
|
232
|
+
}
|
|
233
|
+
$('chat').addEventListener('submit',e=>{e.preventDefault();sendChat('queue');});
|
|
234
|
+
$('chat-steer').addEventListener('click',()=>sendChat('steer'));
|
|
235
|
+
$('chat-open').addEventListener('click',()=>bridge.open());
|
|
236
|
+
$('chat-input').addEventListener('input',()=>{if(chatSent&¤t.chatResults?.[chatSent.id]){chatSent=null;}grow();renderChat();});
|
|
237
|
+
$('chat-input').addEventListener('keydown',e=>{
|
|
238
|
+
if(e.key==='Enter'&&!e.shiftKey&&!e.isComposing&&e.keyCode!==229){e.preventDefault();if(!$('chat-send').disabled)sendChat('queue');}
|
|
239
|
+
if(e.key==='Escape')e.stopPropagation(),expand(false);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// 上下文占用:鲸鱼外圈按占用比例描边,70% 起变黄,90% 起变红。
|
|
243
|
+
function contextOf(d){if(!d?.contextTokens||!d?.contextWindow)return null;return Math.min(100,Math.round(d.contextTokens/d.contextWindow*100));}
|
|
244
|
+
function renderRing(state,d){
|
|
245
|
+
const pct=['idle','offline'].includes(state)?null:contextOf(d);
|
|
246
|
+
if(pct==null){delete island.dataset.ctx;return;}
|
|
247
|
+
island.dataset.ctx=pct>=90?'full':pct>=70?'warn':'ok';
|
|
248
|
+
island.style.setProperty('--ctx-pct',String(Math.max(2,pct)));
|
|
249
|
+
$('capsule').title=`上下文已用 ${pct}%`;
|
|
250
|
+
}
|
|
251
|
+
|
|
157
252
|
// 展开面板:进行中显示当前任务卡和其他任务,空闲时显示今天的统计和最近完成。
|
|
158
253
|
function renderPanel({activity:a,prefs={},history={},balance,preview}){
|
|
159
254
|
const state=Object.hasOwn(STATES,a.state)?a.state:'offline',details=prefs.details!==false;
|
|
@@ -168,7 +263,8 @@ function renderPanel({activity:a,prefs={},history={},balance,preview}){
|
|
|
168
263
|
const trailKey=trail.join('|');
|
|
169
264
|
if($('trail').dataset.key!==trailKey){$('trail').dataset.key=trailKey;$('trail').replaceChildren(...trail.map((n,i)=>{const c=document.createElement('span');c.className='chip';c.textContent=toolLabel(n);c.style.animationDelay=`${i*40}ms`;return c;}));}
|
|
170
265
|
$('trail').hidden=!trail.length;
|
|
171
|
-
const
|
|
266
|
+
const pct=contextOf(d);
|
|
267
|
+
const meta=[d.model,d.contextTokens?(pct!=null?`上下文 ${tokens(d.contextTokens)} / ${tokens(d.contextWindow)} (${pct}%)`:`上下文 ${tokens(d.contextTokens)}`):'',d.cacheRate!=null?`缓存命中 ${d.cacheRate}%`:'',d.toolCount?`工具 ${d.toolCount} 次`:'',d.outputTokens?`输出 ${tokens(d.outputTokens)}`:''].filter(Boolean);
|
|
172
268
|
$('meta').replaceChildren(...meta.map(t=>{const s=document.createElement('span');s.textContent=t;return s;}));
|
|
173
269
|
$('activity-note').textContent=preview?'预览模式 · 示例数据,不代表实际任务':'';
|
|
174
270
|
|
|
@@ -196,14 +292,24 @@ function renderPanel({activity:a,prefs={},history={},balance,preview}){
|
|
|
196
292
|
const day=history.day;
|
|
197
293
|
$('usage').hidden=!idle||!day||!day.tokens;
|
|
198
294
|
if(day&&day.tokens){
|
|
199
|
-
|
|
295
|
+
const cost=history.today?.cost;
|
|
296
|
+
$('usage-sum').textContent=`${tokens(day.tokens)} tokens${day.cacheRate!=null?` · 缓存命中 ${day.cacheRate}%`:''}${cost>=0.005?` · 今日≈¥${cost.toFixed(2)}`:''}`;
|
|
200
297
|
const max=Math.max(...day.hours,1),key=day.hours.join(',');
|
|
201
298
|
if($('usage-bars').dataset.key!==key){$('usage-bars').dataset.key=key;$('usage-bars').replaceChildren(...day.hours.map((v,i)=>{const b=document.createElement('i');if(!v)b.className='zero';b.style.height=v?`${Math.max(8,Math.round(v/max*100))}%`:'';b.style.animationDelay=`${i*18}ms`;b.title=`${tokens(v)} tokens`;return b;}));}
|
|
202
299
|
}
|
|
203
300
|
$('recent').hidden=!(idle||['completed','paused','error'].includes(state))||!recent.length;
|
|
204
301
|
$('hint').hidden=!idle||preview;
|
|
205
302
|
$('stop').hidden=!a.stoppable;if(!a.stoppable)disarm();
|
|
206
|
-
|
|
303
|
+
const reply=details&&state==='completed'?d.reply:'';
|
|
304
|
+
$('reply').hidden=!reply;$('reply-text').textContent=reply||'';
|
|
305
|
+
if(reply)$('recent').hidden=true;
|
|
306
|
+
const approving=renderApprove();
|
|
307
|
+
if(approving)$('ask').hidden=true;
|
|
308
|
+
const asking=!approving&&renderAsk();
|
|
309
|
+
const chatting=renderChat();
|
|
310
|
+
if(approving||asking)for(const id of ['task','others','today','usage','recent','hint','reply','chat'])$(id).hidden=true;
|
|
311
|
+
// 对话卡里已经有最近的回复;空闲时收起柱状图和最近任务(用量窗口里都有),给输入框留出位置。
|
|
312
|
+
else if(chatting){$('reply').hidden=true;if(idle)for(const id of ['usage','recent','hint'])$(id).hidden=true;}
|
|
207
313
|
}
|
|
208
314
|
|
|
209
315
|
// 状态切换:文字与指示器做模糊交叉淡入,异常时整体轻摇。
|
|
@@ -225,22 +331,34 @@ function render(snapshot){
|
|
|
225
331
|
|
|
226
332
|
$('status-label').textContent=copy.label;
|
|
227
333
|
const details=snapshot.prefs?.details!==false;
|
|
228
|
-
const ask=askOf();
|
|
334
|
+
const ask=askOf(),approval=approvalOf(),reply=details&&state==='completed'?a.detail?.reply:'';
|
|
229
335
|
if(ask&&state==='waiting')$('status-label').textContent='有问题等你回答';
|
|
230
|
-
$('
|
|
336
|
+
if(approval)$('status-label').textContent='需要你批准';
|
|
337
|
+
else if(reply)$('status-label').textContent='有新回复';
|
|
338
|
+
$('mini-note').textContent=approval&&!expanded?(details&&approval.detail?.text?approval.detail.text:toolLabel(approval.toolName))
|
|
339
|
+
:ask&&state==='waiting'&&!expanded?ask.questions[0].question
|
|
340
|
+
:reply&&!expanded?reply
|
|
341
|
+
:state==='idle'?(preview?'动画预览':'DeepSeek Harness'):details&&a.title?a.title:copy.detail;
|
|
342
|
+
island.dataset.alert=approval?'approval':reply?'reply':'';
|
|
343
|
+
renderRing(state,a.detail);
|
|
231
344
|
$('badge').hidden=!(a.activeCount>1);$('badge').textContent=a.activeCount>1?String(a.activeCount):'';
|
|
232
345
|
$('demo-controls').hidden=!preview;$('demo-state').value=state;
|
|
233
346
|
renderPanel(snapshot);
|
|
234
347
|
|
|
235
348
|
for(const id of drafts.keys())if(!(a.questions||[]).some(q=>q.callId===id))drafts.delete(id);
|
|
236
|
-
if(
|
|
237
|
-
|
|
349
|
+
for(const id of [...seenApproval.keys()])if(!(a.approvals||[]).some(x=>x.id===id)){seenApproval.delete(id);sentApproval.delete(id);}
|
|
350
|
+
const prompt=approval?'approval:'+approval.id:ask?'ask:'+ask.callId:'';
|
|
351
|
+
if(prompt&&!seenAsk.has(prompt)){seenAsk.add(prompt);if(snapshot.prefs?.popups!==false&&!expanded){autoOpened=true;expand(true);}}
|
|
352
|
+
if(!prompt&&autoOpened){autoOpened=false;if(expanded)expand(false);}
|
|
353
|
+
// 新回复:完成时在胶囊里预览回复开头,并多停留一会儿。
|
|
354
|
+
if(reply&&reply!==lastReply&&lastState===state&&!expanded&&snapshot.prefs?.popups!==false)burst(4200);
|
|
355
|
+
lastReply=reply||'';
|
|
238
356
|
if(lastState!==state){
|
|
239
357
|
const prev=lastState;lastState=state;
|
|
240
358
|
$('announcement').textContent=copy.label;
|
|
241
359
|
choreograph(state,prev);
|
|
242
360
|
const fresh=state!=='thinking'||QUIET.includes(prev);
|
|
243
|
-
if(BURST[state]&&fresh&&prev&&!expanded&&snapshot.prefs?.popups!==false)burst(BURST[state]);
|
|
361
|
+
if(BURST[state]&&fresh&&prev&&!expanded&&snapshot.prefs?.popups!==false)burst(reply?4200:BURST[state]);
|
|
244
362
|
}
|
|
245
363
|
// 切到减少动效时,正在进行的过渡直接落到终点。
|
|
246
364
|
if(!motionOn())document.getAnimations().forEach(x=>{if(x instanceof CSSAnimation)return;try{x.finish();}catch{x.cancel();}});
|
|
@@ -250,4 +368,4 @@ function render(snapshot){
|
|
|
250
368
|
const unsubscribe=bridge.subscribe(render);
|
|
251
369
|
render(await bridge.initial());
|
|
252
370
|
const timer=setInterval(tick,1000);
|
|
253
|
-
window.addEventListener('beforeunload',()=>{unsubscribe();clearInterval(timer);cancelAnimationFrame(boundsFrame);clearTimeout(burstTimer);clearTimeout(peekTimer);clearTimeout(leaveTimer);clearTimeout(armTimer);});
|
|
371
|
+
window.addEventListener('beforeunload',()=>{unsubscribe();offBlur?.();clearTimeout(chatStatusTimer);clearInterval(timer);cancelAnimationFrame(boundsFrame);clearTimeout(burstTimer);clearTimeout(peekTimer);clearTimeout(leaveTimer);clearTimeout(armTimer);clearTimeout(hoverTimer);});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const {contextBridge,ipcRenderer}=require('electron');
|
|
2
|
+
contextBridge.exposeInMainWorld('usageStats',{
|
|
3
|
+
request:range=>ipcRenderer.send('stats:request',range),
|
|
4
|
+
subscribe:callback=>{const fn=(_event,data)=>callback(data);ipcRenderer.on('stats:data',fn);return()=>ipcRenderer.removeListener('stats:data',fn);}
|
|
5
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
:root{
|
|
2
|
+
color-scheme:dark;
|
|
3
|
+
--bg:#0b0e17;--surface:#0d111c;--card:#121726;--line:rgba(255,255,255,.07);
|
|
4
|
+
--ink:#eef1fb;--muted:#8d95ad;--faint:#5c647c;--blue:#4d6bfe;--blue-hi:#7f95ff;
|
|
5
|
+
--s-cache:#3987e5;--s-input:#d95926;--s-output:#199e70;
|
|
6
|
+
font-family:"HarmonyOS Sans SC","MiSans","Microsoft YaHei UI","PingFang SC",system-ui,sans-serif;
|
|
7
|
+
}
|
|
8
|
+
*{box-sizing:border-box}
|
|
9
|
+
html,body{margin:0;background:var(--bg);color:var(--ink)}
|
|
10
|
+
body{min-height:100vh;padding:22px 26px 28px;font-size:13px}
|
|
11
|
+
.num{font-variant-numeric:tabular-nums}
|
|
12
|
+
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer}
|
|
13
|
+
a{color:var(--blue-hi)}
|
|
14
|
+
.top{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:18px;flex-wrap:wrap}
|
|
15
|
+
.brand{display:flex;align-items:center;gap:12px}
|
|
16
|
+
.mark{width:34px;height:34px;border-radius:11px;background:var(--blue) url("../assets/deepseek.svg") center/22px no-repeat;box-shadow:0 6px 22px rgba(77,107,254,.35)}
|
|
17
|
+
h1{margin:0;font-size:18px;font-weight:650;letter-spacing:.3px}
|
|
18
|
+
h2{margin:0;font-size:13px;font-weight:600}
|
|
19
|
+
.sub{margin:2px 0 0;color:var(--muted);font-size:11.5px}
|
|
20
|
+
.sub .tag{margin-left:6px;padding:1px 7px;border-radius:999px;background:rgba(245,181,68,.14);color:#f5c46a;font-size:10.5px}
|
|
21
|
+
.tabs{display:flex;padding:3px;border-radius:12px;background:var(--card);border:1px solid var(--line)}
|
|
22
|
+
.tabs button{height:30px;padding:0 14px;border-radius:9px;color:var(--muted);font-size:12.5px;transition:background-color .2s,color .2s}
|
|
23
|
+
.tabs button:hover{color:var(--ink)}
|
|
24
|
+
.tabs button[aria-selected="true"]{background:var(--blue);color:#fff;box-shadow:0 4px 14px rgba(77,107,254,.35)}
|
|
25
|
+
.tabs button:focus-visible{outline:2px solid var(--blue-hi);outline-offset:2px}
|
|
26
|
+
main{transition:opacity .25s}
|
|
27
|
+
main[aria-busy="true"]{opacity:.55}
|
|
28
|
+
.kpis{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:10px;margin-bottom:12px}
|
|
29
|
+
.kpi{display:flex;flex-direction:column;gap:3px;padding:13px 14px;border-radius:14px;background:var(--card);border:1px solid var(--line);min-width:0}
|
|
30
|
+
.kpi .k{font-size:11px;color:var(--muted)}
|
|
31
|
+
.kpi strong{font-size:21px;font-weight:650;letter-spacing:.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
32
|
+
.kpi .s{font-size:10.5px;color:var(--faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
33
|
+
.card{position:relative;padding:14px 16px;border-radius:16px;background:var(--card);border:1px solid var(--line);min-width:0}
|
|
34
|
+
.card-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px;flex-wrap:wrap}
|
|
35
|
+
.hint{font-size:10.5px;color:var(--faint)}
|
|
36
|
+
.legend{display:flex;gap:14px;font-size:11px;color:var(--muted)}
|
|
37
|
+
.legend span{display:flex;align-items:center;gap:6px}
|
|
38
|
+
.legend i{width:10px;height:10px;border-radius:3px;background:var(--c)}
|
|
39
|
+
.chart{height:230px;background:var(--surface);border-radius:12px;padding:6px 4px 0}
|
|
40
|
+
.chart svg{display:block;width:100%;height:100%;overflow:visible}
|
|
41
|
+
.chart .grid{stroke:rgba(255,255,255,.06);stroke-width:1}
|
|
42
|
+
.chart .axis{fill:var(--faint);font-size:10px}
|
|
43
|
+
.chart .hit{fill:transparent}
|
|
44
|
+
.chart .seg{transition:opacity .15s}
|
|
45
|
+
.chart .col.dim .seg{opacity:.35}
|
|
46
|
+
.chart.still .seg{animation:none}
|
|
47
|
+
.chart .seg{transform-box:fill-box;transform-origin:50% 100%;animation:grow .6s cubic-bezier(.22,1,.36,1) backwards}
|
|
48
|
+
@keyframes grow{from{transform:scaleY(0)}}
|
|
49
|
+
.tip{position:absolute;z-index:3;pointer-events:none;min-width:168px;padding:9px 11px;border-radius:11px;background:rgba(9,12,22,.96);border:1px solid rgba(255,255,255,.1);box-shadow:0 10px 30px rgba(0,0,0,.45);font-size:11.5px;line-height:1.6}
|
|
50
|
+
.tip b{display:block;margin-bottom:3px;font-size:12px}
|
|
51
|
+
.tip .r{display:flex;justify-content:space-between;gap:14px;color:var(--muted)}
|
|
52
|
+
.tip .r span:first-child{display:flex;align-items:center;gap:6px}
|
|
53
|
+
.tip .r i{width:8px;height:8px;border-radius:2px;background:var(--c)}
|
|
54
|
+
.tip .r span:last-child{color:var(--ink);font-variant-numeric:tabular-nums}
|
|
55
|
+
.cols{display:grid;grid-template-columns:minmax(0,4fr) minmax(0,8fr);gap:12px;margin-top:12px;align-items:start}
|
|
56
|
+
table{width:100%;border-collapse:collapse}
|
|
57
|
+
th{font-size:10.5px;font-weight:500;color:var(--faint);text-align:left;padding:0 6px 7px}
|
|
58
|
+
td{padding:8px 6px;border-top:1px solid var(--line);font-size:12px;font-variant-numeric:tabular-nums}
|
|
59
|
+
.r{text-align:right}
|
|
60
|
+
.models .name{display:flex;flex-direction:column;gap:5px}
|
|
61
|
+
.models .share{height:4px;border-radius:2px;background:rgba(255,255,255,.06);overflow:hidden}
|
|
62
|
+
.models .share i{display:block;height:100%;border-radius:2px;background:linear-gradient(90deg,var(--blue),var(--blue-hi))}
|
|
63
|
+
.models .unpriced{font-size:10px;color:var(--faint)}
|
|
64
|
+
.sessions{display:flex;flex-direction:column;max-height:340px;overflow:auto;margin:0 -6px;padding:0 6px}
|
|
65
|
+
.sessions details{border-top:1px solid var(--line)}
|
|
66
|
+
.sessions details:first-child{border-top:0}
|
|
67
|
+
.sessions summary{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:12px;align-items:center;padding:9px 2px;cursor:pointer;list-style:none;border-radius:8px}
|
|
68
|
+
.sessions summary::-webkit-details-marker{display:none}
|
|
69
|
+
.sessions summary:hover{background:rgba(255,255,255,.03)}
|
|
70
|
+
.sessions summary:focus-visible{outline:2px solid var(--blue-hi)}
|
|
71
|
+
.sessions .t{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12.5px}
|
|
72
|
+
.sessions .t::before{content:"›";display:inline-block;width:12px;color:var(--faint);transition:transform .2s}
|
|
73
|
+
.sessions details[open] .t::before{transform:rotate(90deg)}
|
|
74
|
+
.sessions .m{font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
75
|
+
.turns{margin:0 0 10px 12px;width:calc(100% - 12px)}
|
|
76
|
+
.turns td{font-size:11px;padding:6px 5px;color:#cfd5e6;white-space:nowrap}
|
|
77
|
+
.turns th{white-space:nowrap}
|
|
78
|
+
.turns th{padding:4px 5px}
|
|
79
|
+
.state{display:inline-block;width:7px;height:7px;border-radius:50%;margin-right:5px;background:#3ddc91}
|
|
80
|
+
.state.paused{background:#9aa3b8}.state.error{background:#ff6b6b}
|
|
81
|
+
.empty{margin:14px 0 0;text-align:center;color:var(--muted)}
|
|
82
|
+
.note{margin-top:14px;color:var(--faint);font-size:10.5px;line-height:1.7}
|
|
83
|
+
@media (max-width:760px){.kpis{grid-template-columns:repeat(2,minmax(0,1fr))}.cols{grid-template-columns:1fr}}
|
|
84
|
+
@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
|
|
85
|
+
.models th,.models td{white-space:nowrap}
|
|
86
|
+
.models .name span{overflow:hidden;text-overflow:ellipsis}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'none'; object-src 'none'; base-uri 'none'">
|
|
6
|
+
<title>用量统计 · DeepSeek 灵动岛</title><link rel="stylesheet" href="stats.css">
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<header class="top">
|
|
10
|
+
<div class="brand">
|
|
11
|
+
<span class="mark" aria-hidden="true"></span>
|
|
12
|
+
<div><h1>用量统计</h1><p id="source" class="sub">正在读取 Harness 会话记录…</p></div>
|
|
13
|
+
</div>
|
|
14
|
+
<div class="tabs" role="tablist" aria-label="时间范围">
|
|
15
|
+
<button role="tab" data-range="today" aria-selected="true">今天</button>
|
|
16
|
+
<button role="tab" data-range="7d" aria-selected="false">7 天</button>
|
|
17
|
+
<button role="tab" data-range="30d" aria-selected="false">30 天</button>
|
|
18
|
+
</div>
|
|
19
|
+
</header>
|
|
20
|
+
|
|
21
|
+
<main id="main" aria-busy="true">
|
|
22
|
+
<section class="kpis" aria-label="概览">
|
|
23
|
+
<div class="kpi"><span class="k">Tokens</span><strong id="k-tokens" class="num">—</strong><span id="k-tokens-sub" class="s"></span></div>
|
|
24
|
+
<div class="kpi"><span class="k">估算费用</span><strong id="k-cost" class="num">—</strong><span id="k-cost-sub" class="s"></span></div>
|
|
25
|
+
<div class="kpi"><span class="k">缓存命中</span><strong id="k-cache" class="num">—</strong><span class="s">命中部分按缓存价计费</span></div>
|
|
26
|
+
<div class="kpi"><span class="k">轮次</span><strong id="k-turns" class="num">—</strong><span id="k-turns-sub" class="s"></span></div>
|
|
27
|
+
<div class="kpi"><span class="k">工作时长</span><strong id="k-time" class="num">—</strong><span class="s">各轮耗时之和</span></div>
|
|
28
|
+
</section>
|
|
29
|
+
|
|
30
|
+
<section class="card chart-card">
|
|
31
|
+
<div class="card-head">
|
|
32
|
+
<h2 id="chart-title">按小时</h2>
|
|
33
|
+
<div class="legend" aria-label="图例">
|
|
34
|
+
<span><i style="--c:var(--s-cache)"></i>缓存命中</span>
|
|
35
|
+
<span><i style="--c:var(--s-input)"></i>未命中输入</span>
|
|
36
|
+
<span><i style="--c:var(--s-output)"></i>输出</span>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<div id="chart" class="chart"></div>
|
|
40
|
+
<div id="tip" class="tip" role="status" hidden></div>
|
|
41
|
+
</section>
|
|
42
|
+
|
|
43
|
+
<div class="cols">
|
|
44
|
+
<section class="card">
|
|
45
|
+
<div class="card-head"><h2>按模型</h2></div>
|
|
46
|
+
<table class="models"><thead><tr><th>模型</th><th class="r">Tokens</th><th class="r">≈ 费用</th><th class="r">轮次</th></tr></thead><tbody id="models"></tbody></table>
|
|
47
|
+
</section>
|
|
48
|
+
<section class="card">
|
|
49
|
+
<div class="card-head"><h2>按会话</h2><span class="hint">点开查看每一轮</span></div>
|
|
50
|
+
<div id="sessions" class="sessions"></div>
|
|
51
|
+
</section>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<p id="empty" class="empty" hidden>这段时间还没有完成的轮次。</p>
|
|
55
|
+
<footer class="note">
|
|
56
|
+
费用为估算:按 <a id="price-link" href="https://api-docs.deepseek.com/zh-cn/quick_start/pricing" target="_blank" rel="noreferrer">DeepSeek 官方价格</a>(2026-10-27 查询,人民币)和每次调用的时间计算,
|
|
57
|
+
高峰时段(北京时间工作日 9–12 点、14–18 点)按高峰价;法定节假日无法识别,按工作日计。未命中缓存的输入(含写入缓存)按未命中价,输出含思考内容。
|
|
58
|
+
没有官方价格的模型不计入费用。实际扣费以 DeepSeek 账单为准。
|
|
59
|
+
</footer>
|
|
60
|
+
</main>
|
|
61
|
+
<script src="stats.js"></script>
|
|
62
|
+
</body></html>
|
package/desktop/stats.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// 用量统计窗口:今天按小时、7/30 天按天;按模型、按会话(可展开到每一轮)。数据来自 Harness 会话记录。
|
|
2
|
+
const api = window.usageStats;
|
|
3
|
+
const $ = id => document.getElementById(id);
|
|
4
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
5
|
+
const SERIES = [['cacheRead', '缓存命中', 'var(--s-cache)'], ['input', '未命中输入', 'var(--s-input)'], ['output', '输出', 'var(--s-output)']];
|
|
6
|
+
let range = 'today', data = null;
|
|
7
|
+
|
|
8
|
+
const tokens = n => !n ? '0' : n < 1000 ? String(Math.round(n)) : n < 1e6 ? `${(n / 1000).toFixed(n < 1e4 ? 1 : 0)}K` : n < 1e9 ? `${(n / 1e6).toFixed(n < 1e7 ? 2 : 1)}M` : `${(n / 1e9).toFixed(2)}B`;
|
|
9
|
+
const money = n => n == null ? '—' : n === 0 ? '¥0' : n < 0.01 ? '<¥0.01' : `¥${n.toFixed(n < 100 ? 2 : 0)}`;
|
|
10
|
+
const duration = ms => { const m = Math.round(ms / 60000); return m < 1 ? '不到 1 分钟' : m < 60 ? `${m} 分钟` : `${Math.floor(m / 60)} 小时 ${m % 60} 分`; };
|
|
11
|
+
const clock = t => { const d = new Date(t), hm = `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; return d.toDateString() === new Date().toDateString() ? hm : `${d.getMonth() + 1}/${d.getDate()} ${hm}`; };
|
|
12
|
+
const shortModel = m => m ? m.replace(/^deepseek-/i, '') : '—';
|
|
13
|
+
const el = (tag, attrs = {}, ...children) => {
|
|
14
|
+
const node = tag.startsWith('svg:') ? document.createElementNS(NS, tag.slice(4)) : document.createElement(tag);
|
|
15
|
+
for (const [k, v] of Object.entries(attrs)) if (v != null && v !== false) k === 'text' ? node.textContent = v : node.setAttribute(k, v);
|
|
16
|
+
node.append(...children.filter(c => c != null));
|
|
17
|
+
return node;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function load(next) {
|
|
21
|
+
range = next;
|
|
22
|
+
for (const b of document.querySelectorAll('.tabs button')) b.setAttribute('aria-selected', String(b.dataset.range === range));
|
|
23
|
+
$('main').setAttribute('aria-busy', 'true');
|
|
24
|
+
api.request(range);
|
|
25
|
+
}
|
|
26
|
+
for (const b of document.querySelectorAll('.tabs button')) b.addEventListener('click', () => load(b.dataset.range));
|
|
27
|
+
document.querySelector('.tabs').addEventListener('keydown', e => {
|
|
28
|
+
const order = ['today', '7d', '30d'], i = order.indexOf(range);
|
|
29
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') { const n = order[(i + (e.key === 'ArrowRight' ? 1 : 2)) % 3]; load(n); document.querySelector(`[data-range="${n}"]`).focus(); }
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/** A bar segment with only its top corners rounded. */
|
|
33
|
+
function topRounded(x, y, w, h, r) {
|
|
34
|
+
r = Math.min(r, w / 2, h);
|
|
35
|
+
return `M${x},${y + h}V${y + r}Q${x},${y} ${x + r},${y}H${x + w - r}Q${x + w},${y} ${x + w},${y + r}V${y + h}Z`;
|
|
36
|
+
}
|
|
37
|
+
function niceMax(v) { if (v <= 0) return 1; const p = 10 ** Math.floor(Math.log10(v)), f = v / p; return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 2.5 ? 2.5 : f <= 5 ? 5 : 10) * p; }
|
|
38
|
+
|
|
39
|
+
function renderChart(d) {
|
|
40
|
+
const box = $('chart'), W = Math.max(320, box.clientWidth - 8), H = box.clientHeight - 6;
|
|
41
|
+
const left = 46, bottom = 22, top = 8, plotW = W - left - 6, plotH = H - top - bottom;
|
|
42
|
+
const totals = d.buckets.map(b => b.cacheRead + b.input + b.output), max = niceMax(Math.max(...totals, 1000));
|
|
43
|
+
const svg = el('svg:svg', { viewBox: `0 0 ${W} ${H}`, role: 'img', 'aria-label': `${$('chart-title').textContent}的 tokens 用量` });
|
|
44
|
+
for (let i = 0; i <= 4; i++) {
|
|
45
|
+
const y = top + plotH - plotH * i / 4;
|
|
46
|
+
svg.append(el('svg:line', { class: 'grid', x1: left, x2: W - 6, y1: y, y2: y }));
|
|
47
|
+
svg.append(el('svg:text', { class: 'axis', x: left - 8, y: y + 3.5, 'text-anchor': 'end', text: tokens(max * i / 4) }));
|
|
48
|
+
}
|
|
49
|
+
const n = d.buckets.length, slot = plotW / n, bw = Math.max(3, Math.min(26, slot * 0.62));
|
|
50
|
+
const every = d.byHour ? 3 : n > 10 ? 5 : 1;
|
|
51
|
+
d.buckets.forEach((b, i) => {
|
|
52
|
+
const x = left + slot * i + (slot - bw) / 2, g = el('svg:g', { class: 'col', 'data-i': i });
|
|
53
|
+
let y = top + plotH;
|
|
54
|
+
const parts = SERIES.map(([k, , c]) => [b[k], c]).filter(([v]) => v > 0);
|
|
55
|
+
parts.forEach(([v, c], j) => {
|
|
56
|
+
const h = Math.max(1.5, v / max * plotH), gap = j > 0 ? 2 : 0, last = j === parts.length - 1;
|
|
57
|
+
y -= h;
|
|
58
|
+
const segH = Math.max(0.5, h - gap);
|
|
59
|
+
g.append(last ? el('svg:path', { class: 'seg', d: topRounded(x, y, bw, segH, 4), fill: c, style: `animation-delay:${i * 14}ms` })
|
|
60
|
+
: el('svg:rect', { class: 'seg', x, y, width: bw, height: segH, fill: c, style: `animation-delay:${i * 14}ms` }));
|
|
61
|
+
});
|
|
62
|
+
g.append(el('svg:rect', { class: 'hit', x: left + slot * i, y: top, width: slot, height: plotH, tabindex: '0', 'aria-label': `${b.label}:${tokens(totals[i])} tokens` }));
|
|
63
|
+
svg.append(g);
|
|
64
|
+
if (i % every === 0 || (!d.byHour && i === n - 1)) svg.append(el('svg:text', { class: 'axis', x: left + slot * i + slot / 2, y: H - 6, 'text-anchor': 'middle', text: b.label }));
|
|
65
|
+
});
|
|
66
|
+
const show = (i, anchor) => {
|
|
67
|
+
const b = d.buckets[i]; if (!b) return;
|
|
68
|
+
for (const g of svg.querySelectorAll('.col')) g.classList.toggle('dim', g.dataset.i !== String(i));
|
|
69
|
+
const tip = $('tip');
|
|
70
|
+
tip.replaceChildren(el('b', { text: d.byHour ? `${b.label} – ${Number(b.label.split(':')[0]) + 1}:00` : b.label }),
|
|
71
|
+
...SERIES.map(([k, label, c]) => el('div', { class: 'r' }, el('span', {}, el('i', { style: `--c:${c}` }), label), el('span', { text: tokens(b[k]) }))),
|
|
72
|
+
el('div', { class: 'r' }, el('span', { text: '≈ 费用' }), el('span', { text: money(b.cost) })),
|
|
73
|
+
el('div', { class: 'r' }, el('span', { text: '轮次' }), el('span', { text: String(b.turns) })));
|
|
74
|
+
tip.hidden = false;
|
|
75
|
+
const card = box.parentElement.getBoundingClientRect(), r = anchor.getBoundingClientRect();
|
|
76
|
+
let x = r.left - card.left + r.width / 2 + 12;
|
|
77
|
+
if (x + tip.offsetWidth > card.width - 8) x = r.left - card.left + r.width / 2 - tip.offsetWidth - 12;
|
|
78
|
+
tip.style.left = `${Math.max(8, x)}px`; tip.style.top = `${box.offsetTop + 10}px`;
|
|
79
|
+
};
|
|
80
|
+
const hide = () => { $('tip').hidden = true; for (const g of svg.querySelectorAll('.col')) g.classList.remove('dim'); };
|
|
81
|
+
svg.addEventListener('pointerover', e => { const g = e.target.closest('.col'); if (g) show(Number(g.dataset.i), g.querySelector('.hit')); });
|
|
82
|
+
svg.addEventListener('pointerleave', hide);
|
|
83
|
+
svg.addEventListener('focusin', e => { const g = e.target.closest('.col'); if (g) show(Number(g.dataset.i), e.target); });
|
|
84
|
+
svg.addEventListener('focusout', hide);
|
|
85
|
+
box.replaceChildren(svg);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function renderModels(d) {
|
|
89
|
+
const max = Math.max(...d.models.map(m => m.tokens), 1);
|
|
90
|
+
$('models').replaceChildren(...d.models.map(m => el('tr', {},
|
|
91
|
+
el('td', {}, el('div', { class: 'name' }, el('span', { text: m.model }), el('div', { class: 'share' }, el('i', { style: `width:${Math.max(2, m.tokens / max * 100)}%` })))),
|
|
92
|
+
el('td', { class: 'r', text: tokens(m.tokens) }),
|
|
93
|
+
el('td', { class: 'r' }, m.priced ? money(m.cost) : el('span', { class: 'unpriced', text: '无官方价格' })),
|
|
94
|
+
el('td', { class: 'r', text: String(m.turns) }))));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const STATE = { completed: '完成', paused: '已停止', error: '出错' };
|
|
98
|
+
function renderSessions(d) {
|
|
99
|
+
const open = new Set([...document.querySelectorAll('.sessions details[open]')].map(x => x.dataset.id));
|
|
100
|
+
$('sessions').replaceChildren(...d.sessions.map(s => {
|
|
101
|
+
const rows = s.items.map(t => el('tr', {},
|
|
102
|
+
el('td', {}, el('span', { class: `state ${t.state}`, title: STATE[t.state] ?? t.state }), clock(t.end)),
|
|
103
|
+
el('td', { text: shortModel(t.model), title: t.model || '' }),
|
|
104
|
+
el('td', { class: 'r', text: `${t.calls} · ${t.tools}`, title: `模型调用 ${t.calls} 次,工具 ${t.tools} 次` }),
|
|
105
|
+
el('td', { class: 'r', text: tokens(t.cacheRead) }),
|
|
106
|
+
el('td', { class: 'r', text: tokens(t.input) }),
|
|
107
|
+
el('td', { class: 'r', text: tokens(t.output) }),
|
|
108
|
+
el('td', { class: 'r', text: t.priced ? money(t.cost) : '—' })));
|
|
109
|
+
const table = el('table', { class: 'turns' },
|
|
110
|
+
el('thead', {}, el('tr', {}, ...['结束', '模型', '调用·工具', '命中', '未命中', '输出', '≈ 费用'].map((h, i) => el('th', { class: i > 1 ? 'r' : null, text: h })))),
|
|
111
|
+
el('tbody', {}, ...rows));
|
|
112
|
+
const node = el('details', { 'data-id': s.id },
|
|
113
|
+
el('summary', {}, el('span', { class: 't', text: s.title || '未命名会话', title: s.title || '' }), el('span', { class: 'm', text: `${s.turns} 轮 · ${tokens(s.tokens)}` }), el('span', { class: 'm', text: money(s.cost) })),
|
|
114
|
+
table);
|
|
115
|
+
if (open.has(s.id)) node.open = true;
|
|
116
|
+
return node;
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function render(d) {
|
|
121
|
+
$('main').setAttribute('aria-busy', 'false');
|
|
122
|
+
if (!d) { $('source').textContent = '暂时无法读取统计,请确认 Harness 正在运行。'; return; }
|
|
123
|
+
if (d.range !== range) return;
|
|
124
|
+
$('chart').classList.toggle('still', data?.range === d.range);
|
|
125
|
+
data = d;
|
|
126
|
+
const t = d.totals;
|
|
127
|
+
$('source').replaceChildren(document.createTextNode(`来自 Harness 会话记录 · 已读取 ${d.scanned} 个会话`));
|
|
128
|
+
if (d.preview) $('source').append(el('span', { class: 'tag', text: '预览 · 示例数据' }));
|
|
129
|
+
$('chart-title').textContent = d.byHour ? '今天 · 按小时' : `最近 ${d.buckets.length} 天 · 按天`;
|
|
130
|
+
$('k-tokens').textContent = tokens(t.tokens);
|
|
131
|
+
$('k-tokens-sub').textContent = `输入 ${tokens(t.input + t.cacheRead)} · 输出 ${tokens(t.output)}`;
|
|
132
|
+
$('k-cost').textContent = t.cost > 0 || !t.unpricedTokens ? `≈${money(t.cost)}` : '—';
|
|
133
|
+
$('k-cost-sub').textContent = t.unpricedTokens ? `另有 ${tokens(t.unpricedTokens)} 无官方价格` : '按官方价格估算';
|
|
134
|
+
$('k-cache').textContent = t.cacheRate == null ? '—' : `${t.cacheRate}%`;
|
|
135
|
+
$('k-turns').textContent = String(t.turns);
|
|
136
|
+
$('k-turns-sub').textContent = t.turns ? `完成 ${t.completed} · 其他 ${t.turns - t.completed}` : '';
|
|
137
|
+
$('k-time').textContent = duration(t.ms);
|
|
138
|
+
$('empty').hidden = t.turns > 0;
|
|
139
|
+
renderChart(d); renderModels(d); renderSessions(d);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
api.subscribe(render);
|
|
143
|
+
let resizeFrame;
|
|
144
|
+
addEventListener('resize', () => { cancelAnimationFrame(resizeFrame); resizeFrame = requestAnimationFrame(() => { if (!data) return; $('chart').classList.add('still'); renderChart(data); }); });
|
|
145
|
+
load('today');
|
|
146
|
+
// 打开期间每分钟刷新一次。
|
|
147
|
+
setInterval(() => { if (document.visibilityState === 'visible') api.request(range); }, 60000);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-island",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DeepSeek Harness
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "DeepSeek Harness 桌面灵动岛插件:实时任务状态、上下文占用、在灵动岛批准权限与回答提问、用量与费用统计(社区插件)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/host.js",
|