dsh-remote-plugin 0.8.0 → 0.8.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/README.en.md +2 -2
- package/README.md +2 -2
- package/apk/dsh-remote.apk +0 -0
- package/client.js +96 -115
- package/cordis.patch.yml +2 -1
- package/file-delivery.mjs +84 -0
- package/gateway.cjs +506 -15
- package/index.mjs +576 -50
- package/package.json +3 -2
- package/plugin-center.mjs +4 -0
- package/public/activity.js +8 -3
- package/public/admin.html +8 -0
- package/public/admin.js +60 -0
- package/public/announcements.json +202 -0
- package/public/app.js +189 -43
- package/public/approval-records.js +75 -3
- package/public/build.json +2 -2
- package/public/desktop/desktop.css +9 -1
- package/public/desktop/desktop.html +27 -8
- package/public/desktop/desktop.js +44 -22
- package/public/diagnostics.js +115 -21
- package/public/extensions.css +13 -0
- package/public/extensions.js +74 -3
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/history.js +5 -4
- package/public/index.html +42 -22
- package/public/lan-discovery.js +94 -0
- package/public/plugin.js +21 -6
- package/public/session-deck.css +73 -0
- package/public/session-deck.js +180 -0
- package/public/styles.css +25 -2
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +4 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +22 -1
package/public/diagnostics.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* Bounded support evidence. No message bodies, credentials or dependencies. */
|
|
2
2
|
'use strict'
|
|
3
3
|
function createDiagnosticSchema() {
|
|
4
|
-
const MAX_EVENTS=160,MAX_BYTES=48000
|
|
5
|
-
const kinds=new Set(['rpc','history.load','history.cache','history.render','history.row','session.open','session.back','stream.state','stream.retry','poll.state','client.lifecycle','client.error','feedback.submit'])
|
|
4
|
+
const MAX_EVENTS=160,MAX_CRITICAL=40,MAX_BYTES=48000
|
|
5
|
+
const kinds=new Set(['rpc','history.load','history.cache','history.render','history.row','session.open','session.back','stream.state','stream.retry','poll.state','client.lifecycle','client.error','feedback.submit','announcement.storage','announcement.fetch','announcement.show','announcement.close','announcement.vote','storage.write','diagnostics.persist'])
|
|
6
6
|
const enums={phase:['start','response','prepared','rendered','complete','failed','navigate','cleanup','hit','miss','retry'],channel:['mux','host'],status:['open','closed','connecting','poll','ws','visible','hidden','online','offline','running','stopped','starting','disabled','start-failed','timeout','error','unknown','granted','denied','default'],category:['authentication','timeout','network','render','syntax','upstream','unknown'],errorName:['Error','TypeError','RangeError','SyntaxError','ReferenceError','AbortError','TimeoutError','NetworkError']}
|
|
7
7
|
enums.serviceState=['starting','running','stopped','disabled','start-failed','system-timeout','auth-expired']
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
enums.storageKey=['seen','history','votes']
|
|
9
|
+
enums.storageBackend=['session','memory']
|
|
10
|
+
enums.storageBackend.push('local','indexeddb')
|
|
11
|
+
enums.storageKey.push('settings','session-list','diagnostics','approvals','receipts')
|
|
12
|
+
enums.phase.push('received','shown','dismissed','acknowledged','skipped')
|
|
13
|
+
enums.category.push('storage','validation')
|
|
14
|
+
enums.errorName.push('QuotaExceededError','SecurityError','InvalidStateError','DataError','UnknownError')
|
|
15
|
+
enums.reason=['already-open','already-read','version-warning','empty','http','network','invalid-json','too-large','unavailable']
|
|
16
|
+
const numbers=['durationMs','httpStatus','closeCode','attempt','delayMs','count','rawCount','renderedCount','renderErrors','lastSuccessAt','intervalMin','apiLevel','storageChars','storageKeys','legacyCacheChars','legacyCacheKeys','historyCacheChars','sessionCacheChars','announcementChars','diagnosticChars','droppedEvents']
|
|
17
|
+
const booleans=['reset','cached','loading','loaded','hasMore','online','enabled','serviceRunning','loginExpired','powerSave','ignoreBatteryOptimizations','notificationsEnabled','persisted','indexedDbAvailable','storageAvailable']
|
|
10
18
|
const methods=new Set(['session.list','session.history','session.create','session.prompt','session.fork','session.cancel','session.rename','session.selectModel','session.updateQueue','session.getModels','session.getQueue','session.getCompactionStatus','workspace.list','workspace.create','workspace.archiveSession','host.describe','subagent.list','subagent.interrupt','goal.edit','goal.pause','goal.resume','goal.complete','goal.clear'])
|
|
11
19
|
for(const method of ['session.models','llm.discoverModels','llm.providers','credentials.describe','credentials.set','credentials.unset','settings.describe','settings.mutate','settings.openDocument'])methods.add(method)
|
|
12
20
|
const hex=(v,n)=>typeof v==='string'&&new RegExp('^[a-f0-9]{'+n+'}$').test(v)?v:undefined
|
|
@@ -17,52 +25,134 @@ function createDiagnosticSchema() {
|
|
|
17
25
|
for(const key of numbers)if(typeof input[key]==='number'&&Number.isFinite(input[key])&&input[key]>=0)out[key]=Math.min(input[key],Number.MAX_SAFE_INTEGER)
|
|
18
26
|
for(const key of booleans)if(typeof input[key]==='boolean')out[key]=input[key]
|
|
19
27
|
if(methods.has(input.method))out.method=input.method
|
|
20
|
-
for(const key of ['sessionRef','serverRef'])if(hex(input[key],16))out[key]=input[key]
|
|
28
|
+
for(const key of ['sessionRef','serverRef','announcementRef'])if(hex(input[key],16))out[key]=input[key]
|
|
21
29
|
if(hex(input.traceId,24))out.traceId=input.traceId
|
|
22
30
|
if(Array.isArray(input.frames))out.frames=input.frames.slice(0,3).filter(f=>['app.js','desktop.js','history.js','activity.js','turn-results.js','network.js','operations.js','diagnostics.js'].includes(f?.file)&&Number.isSafeInteger(f.line)&&f.line>0&&Number.isSafeInteger(f.column)&&f.column>0).map(f=>({file:f.file,line:f.line,column:f.column}))
|
|
23
31
|
return out
|
|
24
32
|
}
|
|
33
|
+
const critical=row=>row.kind==='client.error'||row.phase==='failed'
|
|
34
|
+
function retain(events) {
|
|
35
|
+
const errors=events.filter(critical).slice(-MAX_CRITICAL),keep=new Set([...events.slice(-(MAX_EVENTS-errors.length)),...errors])
|
|
36
|
+
return events.filter(row=>keep.has(row))
|
|
37
|
+
}
|
|
38
|
+
function shrink(events,budget) {
|
|
39
|
+
while(events.length&&JSON.stringify(events).length>budget){const index=events.findIndex(row=>!critical(row));events.splice(index<0?0:index,1)}
|
|
40
|
+
return events
|
|
41
|
+
}
|
|
25
42
|
function sanitizeReport(input) {
|
|
26
43
|
if(!input||input.schema!==1||!Array.isArray(input.events))return null
|
|
27
44
|
const report={schema:1,reportId:hex(input.reportId,24)||'000000000000000000000000',capturedAt:typeof input.capturedAt==='number'&&Number.isFinite(input.capturedAt)?input.capturedAt:0,
|
|
28
45
|
client:{version:version(input.client?.version),buildId:hex(input.client?.buildId,64)||'unknown',surface:['mobile','desktop'].includes(input.client?.surface)?input.client.surface:'mobile'},
|
|
29
46
|
snapshot:facts(input.snapshot),events:[]}
|
|
30
|
-
for(const item of input.events
|
|
31
|
-
|
|
47
|
+
for(const item of input.events)if(item&&kinds.has(item.kind)&&typeof item.at==='number'&&Number.isFinite(item.at))report.events.push({at:item.at,kind:item.kind,...facts(item)})
|
|
48
|
+
report.events=retain(report.events)
|
|
49
|
+
if(input.persistence&&typeof input.persistence==='object'){
|
|
50
|
+
report.persistence={}
|
|
51
|
+
for(const key of ['local','session','indexeddb'])if(['unknown','saved','failed','unavailable','pending'].includes(input.persistence[key]))report.persistence[key]=input.persistence[key]
|
|
52
|
+
}
|
|
53
|
+
while(JSON.stringify(report).length>MAX_BYTES&&report.events.length){const index=report.events.findIndex(row=>!critical(row));report.events.splice(index<0?0:index,1)}
|
|
32
54
|
return report
|
|
33
55
|
}
|
|
34
|
-
return {MAX_EVENTS,MAX_BYTES,kinds,facts,sanitizeReport
|
|
56
|
+
return {MAX_EVENTS,MAX_CRITICAL,MAX_BYTES,kinds,facts,sanitizeReport,retain,shrink,
|
|
57
|
+
definition:{MAX_EVENTS,MAX_CRITICAL,MAX_BYTES,kinds:[...kinds],enums,numbers,booleans,methods:[...methods]}}
|
|
35
58
|
}
|
|
36
59
|
;(function(root){
|
|
37
60
|
const schema=createDiagnosticSchema()
|
|
38
61
|
function createDiagnostics(env) {
|
|
39
62
|
const KEY='dshRemoteDiagnosticsV1',SALT_KEY=KEY+'Salt',MAX_AGE=86400000
|
|
40
|
-
let rows=[],timer,config={},metadata={},sequence=0,sheet,exportTimer
|
|
63
|
+
let rows=[],timer,config={},metadata={},sequence=0,sheet,exportTimer,droppedEvents=0,epoch=0
|
|
64
|
+
let database,backupJob,pendingBackup,storageAt=0,storageInventory={}
|
|
65
|
+
const persistence={local:'unknown',session:'unknown',indexeddb:'unknown'}
|
|
41
66
|
const random=()=>{const bytes=new Uint8Array(12);env.crypto?.getRandomValues?.(bytes);return [...bytes].map(n=>n.toString(16).padStart(2,'0')).join('')}
|
|
42
67
|
let salt=random(),run=random()
|
|
43
|
-
try{salt=env.localStorage.getItem(SALT_KEY)||salt;env.localStorage.setItem(SALT_KEY,salt)
|
|
68
|
+
try{salt=env.localStorage.getItem(SALT_KEY)||salt;env.localStorage.setItem(SALT_KEY,salt)}catch{}
|
|
69
|
+
for(const storage of [env.localStorage,env.sessionStorage])try{const saved=schema.sanitizeReport(JSON.parse(storage.getItem(KEY)||'null'));if(saved)rows.push(...saved.events)}catch{}
|
|
70
|
+
rows=[...new Map(rows.map(row=>[JSON.stringify(row),row])).values()].sort((a,b)=>a.at-b.at)
|
|
44
71
|
const now=()=>Date.now()
|
|
45
72
|
const pseudonym=value=>{if(!value||!env.SHA256)return undefined;try{return new env.SHA256().update(new TextEncoder().encode(salt+'\0'+value)).hex().slice(0,16)}catch{return undefined}}
|
|
46
|
-
const trim=()=>{rows=rows.filter(row=>row.at>now()-MAX_AGE&&row.at<=now()+60000)
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
const trim=()=>{const before=rows.length;rows=schema.shrink(schema.retain(rows.filter(row=>row.at>now()-MAX_AGE&&row.at<=now()+60000)),schema.MAX_BYTES-3000);droppedEvents+=before-rows.length}
|
|
74
|
+
function storageFacts(force=false){
|
|
75
|
+
if(!force&&storageAt&&now()-storageAt<30000)return storageInventory
|
|
76
|
+
const value={storageChars:0,storageKeys:0,legacyCacheChars:0,legacyCacheKeys:0,historyCacheChars:0,sessionCacheChars:0,announcementChars:0,diagnosticChars:0,indexedDbAvailable:!!env.indexedDB,storageAvailable:false}
|
|
77
|
+
try{const storage=env.localStorage;if(typeof storage.length!=='number')throw Error('storage unavailable');for(let i=0;i<storage.length;i++){
|
|
78
|
+
const key=storage.key(i),size=key.length+(storage.getItem(key)||'').length;value.storageKeys++;value.storageChars+=size
|
|
79
|
+
if(/^historyCache/.test(key)){value.historyCacheChars+=size;if(!key.includes(':session:')&&!key.endsWith(':cache-index')){value.legacyCacheChars+=size;value.legacyCacheKeys++}}
|
|
80
|
+
else if(/^sessionsCache/.test(key))value.sessionCacheChars+=size
|
|
81
|
+
else if(/^(?:seenAnnouncements|announcementHistory|announcementVotes)V1$/.test(key))value.announcementChars+=size
|
|
82
|
+
else if(key===KEY)value.diagnosticChars+=size
|
|
83
|
+
}value.storageAvailable=true}catch{}
|
|
84
|
+
storageAt=now();storageInventory=value;return value
|
|
85
|
+
}
|
|
86
|
+
function snapshot(force=false){let value={};try{value=config.snapshot?.()||{}}catch{};return schema.facts({...value,...storageFacts(force),droppedEvents,sessionRef:pseudonym(value.sessionId),serverRef:pseudonym(value.server||env.location?.origin),online:env.navigator?.onLine!==false})}
|
|
87
|
+
function makeReport(force=false){trim();return schema.sanitizeReport({schema:1,reportId:random(),capturedAt:now(),client:{...metadata,surface:config.surface||'mobile'},snapshot:snapshot(force),persistence,events:rows})}
|
|
88
|
+
const report=()=>makeReport(true)
|
|
89
|
+
function openDatabase(){
|
|
90
|
+
if(database)return database
|
|
91
|
+
if(!env.indexedDB)return Promise.resolve(null)
|
|
92
|
+
database=new Promise(resolve=>{
|
|
93
|
+
let settled=false,request
|
|
94
|
+
const done=value=>{if(settled){value?.close();return}settled=true;env.clearTimeout?.(deadline);resolve(value)}
|
|
95
|
+
const deadline=env.setTimeout?.(()=>done(null),1500)
|
|
96
|
+
try{request=env.indexedDB.open('dshRemoteDiagnosticsV1',1);request.onupgradeneeded=()=>request.result.createObjectStore('reports')
|
|
97
|
+
request.onsuccess=()=>{request.result.onversionchange=()=>{request.result.close();database=null};done(request.result)}
|
|
98
|
+
request.onerror=request.onblocked=()=>done(null)
|
|
99
|
+
}catch{done(null)}
|
|
100
|
+
})
|
|
101
|
+
return database
|
|
102
|
+
}
|
|
103
|
+
function transaction(db,mode,value){return new Promise(resolve=>{
|
|
104
|
+
let tx,result,settled=false
|
|
105
|
+
const done=value=>{if(settled)return;settled=true;env.clearTimeout?.(deadline);resolve(value)}
|
|
106
|
+
const deadline=env.setTimeout?.(()=>{done({ok:false,error:{name:'TimeoutError'}});try{tx?.abort()}catch{}},2000)
|
|
107
|
+
try{tx=db.transaction('reports',mode);const store=tx.objectStore('reports'),request=mode==='readonly'?store.get('latest'):store.put(value,'latest')
|
|
108
|
+
request.onsuccess=()=>{result=request.result}
|
|
109
|
+
tx.oncomplete=()=>done({ok:true,value:result});tx.onerror=tx.onabort=()=>done({ok:false,error:tx.error||{name:'UnknownError'}})
|
|
110
|
+
}catch(error){done({ok:false,error})}
|
|
111
|
+
})}
|
|
112
|
+
function persistFailure(backend,error){rows.push({at:now(),kind:'diagnostics.persist',phase:'failed',storageBackend:backend,...errorFacts(error)});trim()}
|
|
113
|
+
const restoredEpoch=epoch
|
|
114
|
+
const ready=openDatabase().then(async db=>{
|
|
115
|
+
if(!db){persistence.indexeddb='unavailable';return}
|
|
116
|
+
const saved=await transaction(db,'readonly')
|
|
117
|
+
if(saved.ok&&restoredEpoch===epoch){const previous=schema.sanitizeReport(saved.value),unique=new Map();for(const row of [...(previous?.events||[]),...rows])unique.set(JSON.stringify(row),row);rows=[...unique.values()].sort((a,b)=>a.at-b.at);trim()}
|
|
118
|
+
}).catch(()=>{persistence.indexeddb='failed'})
|
|
119
|
+
function backup(value){
|
|
120
|
+
pendingBackup=value
|
|
121
|
+
if(!backupJob)backupJob=(async()=>{
|
|
122
|
+
await ready;const db=await openDatabase()
|
|
123
|
+
if(!db){pendingBackup=null;persistence.indexeddb='unavailable';return}
|
|
124
|
+
while(pendingBackup){const value=makeReport();pendingBackup=null;const result=await transaction(db,'readwrite',value),previous=persistence.indexeddb;persistence.indexeddb=result.ok?'saved':'failed'
|
|
125
|
+
if(!result.ok&&previous!=='failed'){persistFailure('indexeddb',result.error);flush(false)}
|
|
126
|
+
}
|
|
127
|
+
})().catch(()=>{persistence.indexeddb='failed'}).finally(()=>{backupJob=null})
|
|
128
|
+
return backupJob
|
|
129
|
+
}
|
|
130
|
+
function flush(withBackup=true){
|
|
131
|
+
if(timer)env.clearTimeout?.(timer);timer=null
|
|
132
|
+
const previous=persistence.local
|
|
133
|
+
try{persistence.local='saved';const value=JSON.stringify(makeReport());env.localStorage.setItem(KEY,value);if(env.localStorage.getItem(KEY)!==value)throw Error('storage write unconfirmed');persistence.session='unknown';try{env.sessionStorage?.removeItem(KEY)}catch{}}
|
|
134
|
+
catch(error){persistence.local='failed';if(previous!=='failed')persistFailure('local',error)
|
|
135
|
+
try{persistence.session='saved';env.sessionStorage.setItem(KEY,JSON.stringify(makeReport()))}catch{persistence.session=env.sessionStorage?'failed':'unavailable'}
|
|
136
|
+
}
|
|
137
|
+
return withBackup?backup(makeReport()):Promise.resolve()
|
|
138
|
+
}
|
|
50
139
|
function record(kind,fields={}) {
|
|
51
140
|
if(!schema.kinds.has(kind))return
|
|
52
|
-
const row={at:now(),kind,...schema.facts({...fields,sessionRef:fields.sessionRef||pseudonym(fields.sessionId),serverRef:fields.serverRef||pseudonym(fields.server||env.location?.origin)})};rows.push(row);trim()
|
|
141
|
+
const row={at:now(),kind,...schema.facts({...fields,sessionRef:fields.sessionRef||pseudonym(fields.sessionId),serverRef:fields.serverRef||pseudonym(fields.server||env.location?.origin),announcementRef:fields.announcementRef||pseudonym(fields.announcementId)})};rows.push(row);trim()
|
|
53
142
|
if(fields.phase==='failed'||kind==='client.error'||fields.phase==='start'&&['session.open','session.back','history.load','history.render','history.cache'].includes(kind))flush()
|
|
54
143
|
else if(!timer)timer=env.setTimeout?.(flush,500)
|
|
55
144
|
return row
|
|
56
145
|
}
|
|
57
146
|
function errorFacts(error){
|
|
58
|
-
const message=String(error?.message||''),category=/auth|ticket|401|403/i.test(message)?'authentication':/timeout|abort/i.test(message+' '+error?.name)?'timeout':/network|fetch|socket/i.test(message)?'network':error?.name==='SyntaxError'?'syntax':'unknown',frames=[]
|
|
147
|
+
const message=typeof error==='string'?error:String(error?.message||''),category=/quota|storage|indexeddb/i.test(message+' '+error?.name)?'storage':/auth|ticket|401|403/i.test(message)?'authentication':/timeout|abort/i.test(message+' '+error?.name)?'timeout':/network|fetch|socket/i.test(message)?'network':/invalid.*payload|validation|schema/i.test(message)?'validation':error?.name==='SyntaxError'?'syntax':'unknown',frames=[]
|
|
59
148
|
for(const line of String(error?.stack||'').split('\n').slice(1,8)){const match=line.match(/(?:[/\\])(app|desktop|history|activity|turn-results|network|operations|diagnostics)\.js(?:\?[^\s:]*)?:(\d+):(\d+)\)?$/);if(match)frames.push({file:match[1]+'.js',line:Number(match[2]),column:Number(match[3])})}
|
|
60
149
|
return schema.facts({category,errorName:error?.name,frames,...(/^HTTP \d{3}$/.test(message)?{httpStatus:Number(message.slice(5))}:{})})
|
|
61
150
|
}
|
|
62
151
|
function start(kind,fields={}){const begun=now(),traceId=run.slice(0,12)+(++sequence).toString(16).padStart(12,'0');record(kind,{...fields,phase:'start',traceId});return {traceId,end:value=>record(kind,{...fields,...value,traceId,durationMs:now()-begun}),fail:error=>record(kind,{...fields,...errorFacts(error),phase:'failed',traceId,durationMs:now()-begun})}}
|
|
63
152
|
function nativeSnapshot(){try{const value=JSON.parse(env.NativeBackground?.getBackgroundConfig?.()||'{}');return schema.facts({...value,httpStatus:value.lastHttpStatus})}catch{return {}}}
|
|
64
153
|
function configure(value){config=value;record('client.lifecycle',{status:env.document?.visibilityState==='hidden'?'hidden':'visible',...nativeSnapshot()});mount()}
|
|
65
|
-
function clear(){rows=[];flush();refreshPreview()}
|
|
154
|
+
function clear(){epoch++;rows=[];droppedEvents=0;flush();refreshPreview()}
|
|
155
|
+
function storageFailure(key,error,backend='local'){const category=/^historyCache/.test(key)?'history':/^sessionsCache/.test(key)?'session-list':key==='seenAnnouncementsV1'?'seen':key==='announcementHistoryV1'?'history':key==='announcementVotesV1'?'votes':/^dshApprovalRecordsV1/.test(key)?'approvals':'settings';storageFacts(true);return record('storage.write',{phase:'failed',storageKey:category,storageBackend:backend,...errorFacts(error)})}
|
|
66
156
|
function text(){return JSON.stringify(report(),null,2)}
|
|
67
157
|
const label=(zh,en)=>env.I18N?.lang==='en'?en:zh
|
|
68
158
|
const $=id=>env.document?.getElementById(id)
|
|
@@ -84,7 +174,7 @@ function createDiagnosticSchema() {
|
|
|
84
174
|
const panel=details.closest('.client-diagnostics'),entry=env.document.createElement('button');entry.type='button';entry.className='workflow-button';entry.dataset.logLabel='entry';panel.parentNode.insertBefore(entry,panel);entry.addEventListener('click',show)
|
|
85
175
|
sheet=env.document.createElement('dialog');sheet.className='client-log-dialog';sheet.setAttribute('aria-labelledby','client-log-title')
|
|
86
176
|
const head=env.document.createElement('div');head.className='client-log-head';const title=env.document.createElement('h2');title.id='client-log-title';title.dataset.logLabel='title';const close=env.document.createElement('button');close.type='button';close.dataset.logLabel='close';close.addEventListener('click',()=>sheet.close());head.append(title,close);sheet.append(head,panel);env.document.body.append(sheet)
|
|
87
|
-
const labels={entry:['查看本地操作日志','View local operation logs'],title:['本地操作日志','Local operation logs'],close:['关闭','Close'],privacy:['
|
|
177
|
+
const labels={entry:['查看本地操作日志','View local operation logs'],title:['本地操作日志','Local operation logs'],close:['关闭','Close'],privacy:['操作日志默认保存在此设备。提交反馈时勾选诊断选项可附带脱敏日志,也可复制或导出。','Logs stay on this device by default. Select diagnostics when submitting feedback to attach a sanitized report, or copy/export it.'],details:['查看详细记录','View detailed records'],refresh:['刷新预览','Refresh preview'],copy:['复制日志','Copy report'],export:['导出日志','Export report'],clear:['清除日志','Clear report']}
|
|
88
178
|
const translate=()=>{for(const node of env.document.querySelectorAll('[data-log-label]')){const pair=labels[node.dataset.logLabel];if(pair)node.textContent=label(...pair)}}
|
|
89
179
|
translate();if(env.MutationObserver)new env.MutationObserver(translate).observe(env.document.documentElement,{attributes:true,attributeFilter:['lang']})
|
|
90
180
|
details.addEventListener('toggle',()=>{if(details.open)refreshPreview()})
|
|
@@ -93,13 +183,17 @@ function createDiagnosticSchema() {
|
|
|
93
183
|
$('fb-log-export')?.addEventListener('click',download)
|
|
94
184
|
$('fb-log-clear')?.addEventListener('click',clear)
|
|
95
185
|
}
|
|
96
|
-
env.addEventListener?.('error',event=>
|
|
186
|
+
env.addEventListener?.('error',event=>{
|
|
187
|
+
const facts=errorFacts(event.error||event.message),file=String(event.filename||'').split(/[\\/]/).at(-1).split('?')[0]
|
|
188
|
+
if(!facts.frames?.length&&['app.js','desktop.js','history.js','activity.js','turn-results.js','network.js','operations.js','diagnostics.js'].includes(file)&&Number.isSafeInteger(event.lineno)&&event.lineno>0&&Number.isSafeInteger(event.colno)&&event.colno>0)facts.frames=[{file,line:event.lineno,column:event.colno}]
|
|
189
|
+
record('client.error',{...facts,phase:'failed'})
|
|
190
|
+
})
|
|
97
191
|
env.addEventListener?.('unhandledrejection',event=>record('client.error',{...errorFacts(event.reason),phase:'failed'}))
|
|
98
192
|
for(const status of ['online','offline'])env.addEventListener?.(status,()=>record('client.lifecycle',{status,online:status==='online'}))
|
|
99
193
|
env.document?.addEventListener('visibilitychange',()=>{record('client.lifecycle',{status:env.document.visibilityState==='visible'?'visible':'hidden',...nativeSnapshot()});flush()})
|
|
100
194
|
env.addEventListener?.('pagehide',flush)
|
|
101
195
|
function build(value){metadata={version:value?.version,buildId:value?.buildId}}
|
|
102
|
-
return {record,start,errorFacts,report,text,flush,clear,configure,show,download,build,nativeSnapshot}
|
|
196
|
+
return {record,start,errorFacts,report,text,flush,clear,configure,show,download,build,nativeSnapshot,storageFailure,storageFacts,ready}
|
|
103
197
|
}
|
|
104
198
|
if(typeof module!=='undefined'&&module.exports)module.exports={createDiagnostics,createDiagnosticSchema}
|
|
105
199
|
else {
|
package/public/extensions.css
CHANGED
|
@@ -94,3 +94,16 @@
|
|
|
94
94
|
}
|
|
95
95
|
@media(max-width:620px){.ext-page{padding:8px 0}.ext-header{margin-bottom:22px}}
|
|
96
96
|
@media(prefers-reduced-motion:reduce){.ext-disclosure>summary:after{transition:none}}
|
|
97
|
+
.ext-shortcuts { display:flex; align-items:center; }
|
|
98
|
+
.ext-shortcuts-menu { position:absolute; right:10px; top:calc(100% + 4px); z-index:80; width:min(300px,calc(100vw - 20px)); max-height:min(70vh,460px); overflow-y:auto; box-sizing:border-box; padding:8px; border:1px solid var(--dsr-line); border-radius:16px; color:var(--dsr-text); background:var(--dsr-panel); box-shadow:0 14px 40px var(--dsr-shadow); text-align:left; }
|
|
99
|
+
.ext-shortcut-title { margin:4px 8px 8px; color:var(--dsr-muted); font-size:11px; font-weight:600; }
|
|
100
|
+
.ext-shortcut-item,.ext-shortcut-manage { width:100%; min-height:44px; box-sizing:border-box; padding:10px 12px; border:0; border-radius:10px; background:transparent; color:var(--dsr-text); font:inherit; font-size:14px; text-align:left; cursor:pointer; }
|
|
101
|
+
.ext-shortcut-item { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:4px 12px; align-items:center; }
|
|
102
|
+
.ext-shortcut-arrow { color:var(--dsr-muted); }
|
|
103
|
+
.ext-shortcut-item small { grid-column:1/-1; color:var(--dsr-muted); font-size:11px; }
|
|
104
|
+
.ext-shortcut-item:disabled { cursor:default; opacity:.55; }
|
|
105
|
+
.ext-shortcut-item:not(:disabled):hover,.ext-shortcut-manage:hover { background:var(--dsr-accent-soft); }
|
|
106
|
+
.ext-shortcut-manage { margin-top:6px; border-top:1px solid var(--dsr-line); border-radius:0 0 10px 10px; color:var(--dsr-accent-strong); }
|
|
107
|
+
.ext-shortcut-empty { margin:8px; padding:10px 4px; font-size:13px; line-height:1.6; color:var(--dsr-muted); }
|
|
108
|
+
.ext-shortcuts :is(button):focus-visible { outline:2px solid var(--dsr-accent); outline-offset:2px; }
|
|
109
|
+
.ext-sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
|
package/public/extensions.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
window.DshExtensions = (() => {
|
|
4
4
|
let current, cache
|
|
5
|
+
let shortcuts
|
|
5
6
|
const catalog = [
|
|
6
7
|
{ id: 'skills', name: '@linxin666/dsh-client-ui-skill-explorer', label: '打开技能中心', summary: '浏览、搜索和阅读主机上的技能', verified: '0.4.6' },
|
|
7
8
|
{ id: 'teams', name: '@nanmicoder/dsh-agent-teams', label: '查看智能体团队', summary: '查看智能体团队、任务与成员状态', verified: '0.1.24-rc.1' },
|
|
@@ -102,8 +103,78 @@ window.DshExtensions = (() => {
|
|
|
102
103
|
return record.task
|
|
103
104
|
}
|
|
104
105
|
const node=(tag,text,cls)=>{const el=document.createElement(tag);if(text!=null)el.textContent=text;if(cls)el.className=cls;return el}
|
|
106
|
+
const shortcutNames = { skills: ['技能中心', 'Skills'], teams: ['智能体团队', 'Agent teams'], cost: ['费用与额度', 'Costs & quotas'], context: ['上下文分析', 'Context analysis'], tasks: ['任务看板', 'Task board'] }
|
|
107
|
+
const shortcutText = (zh, en) => window.I18N?.lang === 'en' ? en : zh
|
|
108
|
+
function closeShortcuts(restoreFocus = false) {
|
|
109
|
+
if (!shortcuts) return
|
|
110
|
+
const s = shortcuts
|
|
111
|
+
shortcuts = null
|
|
112
|
+
s.menu.classList.add('hidden'); s.trigger.setAttribute('aria-expanded', 'false')
|
|
113
|
+
if (restoreFocus) s.trigger.focus()
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
function bindShortcuts({ trigger, menu, config, connected, hasSession, open, beforeOpen }) {
|
|
117
|
+
if (!trigger || !menu) return
|
|
118
|
+
const items = () => Array.from(menu.querySelectorAll('button[role="menuitem"]:not(:disabled)'))
|
|
119
|
+
async function show() {
|
|
120
|
+
closeShortcuts(); beforeOpen?.()
|
|
121
|
+
const connectionConfig = config(), s = { trigger, menu, config: connectionConfig }
|
|
122
|
+
shortcuts = s
|
|
123
|
+
const valid = () => shortcuts === s && connectionConfig.valid()
|
|
124
|
+
const title = node('p', shortcutText('插件快捷打开', 'Plugin shortcuts'), 'ext-shortcut-title')
|
|
125
|
+
const list = node('div', null, 'ext-shortcut-list')
|
|
126
|
+
const message = text => { const p = node('p', text, 'ext-shortcut-empty'); p.setAttribute('role', 'status'); list.replaceChildren(p) }
|
|
127
|
+
const manage = node('button', shortcutText('插件管理', 'Manage plugins'), 'ext-shortcut-manage')
|
|
128
|
+
manage.type = 'button'; manage.setAttribute('role', 'menuitem')
|
|
129
|
+
manage.addEventListener('click', () => { if (valid()) { closeShortcuts(); open('manage') } })
|
|
130
|
+
menu.replaceChildren(title, list, manage)
|
|
131
|
+
menu.classList.remove('hidden'); trigger.setAttribute('aria-expanded', 'true')
|
|
132
|
+
message(connected() ? shortcutText('正在读取插件…', 'Loading plugins…') : shortcutText('请先连接 DSH 主机', 'Connect to a DSH host first'))
|
|
133
|
+
manage.focus()
|
|
134
|
+
if (!connected()) return
|
|
135
|
+
const available = await getCapabilities(connectionConfig)
|
|
136
|
+
if (!valid()) return
|
|
137
|
+
const features = catalog.filter(feature => available[feature.id])
|
|
138
|
+
if (!features.length) {
|
|
139
|
+
message(available.known ? shortcutText('暂无可快捷打开的插件', 'No plugin views available') : shortcutText('暂时无法读取插件,请稍后重试', 'Could not read plugins; try again'))
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
const focusInside = menu.contains(document.activeElement)
|
|
143
|
+
list.replaceChildren()
|
|
144
|
+
for (const feature of features) {
|
|
145
|
+
const button = node('button', null, 'ext-shortcut-item')
|
|
146
|
+
button.type = 'button'; button.setAttribute('role', 'menuitem'); button.dataset.pluginShortcut = feature.id
|
|
147
|
+
const label = shortcutNames[feature.id]
|
|
148
|
+
button.append(node('span', shortcutText(...label)), node('span', '›', 'ext-shortcut-arrow'))
|
|
149
|
+
if (feature.session && !hasSession()) {
|
|
150
|
+
button.disabled = true
|
|
151
|
+
button.append(node('small', shortcutText('请先打开一个会话', 'Open a session first')))
|
|
152
|
+
}
|
|
153
|
+
button.addEventListener('click', () => {
|
|
154
|
+
if (!valid() || (feature.session && !hasSession())) return
|
|
155
|
+
closeShortcuts(); open(feature.id)
|
|
156
|
+
})
|
|
157
|
+
list.append(button)
|
|
158
|
+
}
|
|
159
|
+
if (focusInside) items()[0]?.focus()
|
|
160
|
+
}
|
|
161
|
+
trigger.addEventListener('click', () => { if (shortcuts?.trigger === trigger) closeShortcuts(); else void show() })
|
|
162
|
+
trigger.addEventListener('keydown', event => {
|
|
163
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); if (shortcuts?.trigger !== trigger) void show(); else items()[0]?.focus() }
|
|
164
|
+
})
|
|
165
|
+
menu.addEventListener('keydown', event => {
|
|
166
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeShortcuts(true); return }
|
|
167
|
+
const buttons = items(), index = buttons.indexOf(document.activeElement)
|
|
168
|
+
const next = event.key === 'ArrowDown' ? (index + 1) % buttons.length : event.key === 'ArrowUp' ? (index - 1 + buttons.length) % buttons.length
|
|
169
|
+
: event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : -1
|
|
170
|
+
if (next >= 0) { event.preventDefault(); buttons[next]?.focus() }
|
|
171
|
+
})
|
|
172
|
+
document.addEventListener('click', event => { if (shortcuts?.trigger === trigger && !trigger.contains(event.target) && !menu.contains(event.target)) closeShortcuts() })
|
|
173
|
+
document.addEventListener('focusin', event => { if (shortcuts?.trigger === trigger && !trigger.contains(event.target) && !menu.contains(event.target)) closeShortcuts() })
|
|
174
|
+
document.addEventListener('keydown', event => { if (shortcuts?.trigger === trigger && event.key === 'Escape') { event.preventDefault(); closeShortcuts(true) } })
|
|
175
|
+
}
|
|
105
176
|
const stopViews=()=>{window.DshSkillsCenter?.close();window.DshInsights?.close();window.DshTeams?.close();window.DshTasks?.close()}
|
|
106
|
-
function close(){if(current){const old=current;current=null;stopViews();window.DshPluginCenter?.close();old.target.replaceChildren()}}
|
|
177
|
+
function close(){closeShortcuts();if(current){const old=current;current=null;stopViews();window.DshPluginCenter?.close();old.target.replaceChildren()}}
|
|
107
178
|
function mount(config,target,initial='manage') {
|
|
108
179
|
close()
|
|
109
180
|
const s={config,target,route:'manage',navigation:0};current=s
|
|
@@ -134,11 +205,11 @@ window.DshExtensions = (() => {
|
|
|
134
205
|
if(valid()&&route!=='manage')config.scrollTop?.()
|
|
135
206
|
}
|
|
136
207
|
back.addEventListener('click',()=>{if(valid()){if(s.route==='manage')config.back?.();else void navigate('manage')}})
|
|
137
|
-
void navigate('
|
|
208
|
+
void navigate(initial === 'home' ? 'manage' : initial)
|
|
138
209
|
}
|
|
139
210
|
function scrollParent(el) {
|
|
140
211
|
for(let parent=el.parentElement;parent;parent=parent.parentElement)if(parent.scrollHeight>parent.clientHeight&&/auto|scroll/.test(getComputedStyle(parent).overflowY))return parent
|
|
141
212
|
return document.scrollingElement
|
|
142
213
|
}
|
|
143
|
-
return {mount,close,capabilitiesOf,featuresFor,diagnosticsFor,reportAvailability,getCapabilities,remember,invalidateCapabilities,catalog:catalog.map(row=>Object.freeze({...row}))}
|
|
214
|
+
return {mount,close,bindShortcuts,closeShortcuts,capabilitiesOf,featuresFor,diagnosticsFor,reportAvailability,getCapabilities,remember,invalidateCapabilities,catalog:catalog.map(row=>Object.freeze({...row}))}
|
|
144
215
|
})()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* File requests share the conversation approval area. */
|
|
2
|
+
.session-attention { flex:0 1 auto; min-height:0; max-height:36vh; max-height:36dvh; overflow-y:auto; overscroll-behavior:contain; }
|
|
3
|
+
.session-attention > .session-pending,.session-attention > .ds-session-pending { max-height:none; flex:none; }
|
|
4
|
+
.session-attention .session-pending-list,.session-attention .ds-session-pending-list { overflow:visible; }
|
|
5
|
+
.file-inbox-session { margin:0 0 10px; padding:10px; border:1px solid var(--dsr-warning-line); border-radius:13px; background:var(--dsr-warning-soft); }
|
|
6
|
+
.file-inbox-session[hidden] { display:none !important; }
|
|
7
|
+
.file-inbox-files { flex:none; margin:0 0 16px; padding:14px; border:1px solid var(--dsr-line); border-radius:14px; background:var(--dsr-panel); color:var(--dsr-text); }
|
|
8
|
+
.file-inbox-head { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
|
|
9
|
+
.file-inbox-head h2,.file-inbox-head h3 { flex:1; min-width:0; margin:0; color:var(--dsr-text); font-size:14px; font-weight:750; }
|
|
10
|
+
.file-inbox-head h3 { font-size:12px; }
|
|
11
|
+
.file-inbox-count { flex:none; min-width:22px; padding:2px 7px; border-radius:999px; color:var(--dsr-warning); background:var(--dsr-warning-soft); text-align:center; font-size:11px; font-weight:700; }
|
|
12
|
+
.file-inbox-list { display:flex; flex-direction:column; gap:8px; }
|
|
13
|
+
.file-inbox-card { min-width:0; padding:12px; border:1px solid var(--dsr-line); border-radius:11px; color:var(--dsr-text); background:var(--dsr-panel); overflow-wrap:anywhere; }
|
|
14
|
+
.file-inbox-card.needs-action { border-left:3px solid var(--dsr-warning); }
|
|
15
|
+
.file-inbox-files .file-inbox-card { background:var(--dsr-bg-2); }
|
|
16
|
+
.file-inbox-card-head { display:flex; align-items:flex-start; gap:9px; }
|
|
17
|
+
.file-inbox-icon { flex:none; display:grid; place-items:center; width:30px; height:34px; border:1px solid var(--dsr-warning-line); border-radius:8px; background:var(--dsr-warning-soft); color:var(--dsr-warning); font-size:20px; }
|
|
18
|
+
.file-inbox-names { flex:1; min-width:0; }
|
|
19
|
+
.file-inbox-eyebrow { display:block; margin-bottom:3px; font-size:10px; line-height:1.2; color:var(--dsr-muted); }
|
|
20
|
+
.file-inbox-filename { display:block; font-size:13px; line-height:1.45; font-weight:700; overflow-wrap:anywhere; }
|
|
21
|
+
.file-inbox-phase { flex:none; max-width:44%; margin-top:2px; padding:2px 6px; border:1px solid var(--dsr-line); border-radius:6px; color:var(--dsr-muted); font-size:10px; line-height:1.5; text-align:right; }
|
|
22
|
+
.file-inbox-phase.pending,.file-inbox-phase.failed { color:var(--dsr-warning); border-color:var(--dsr-warning-line); }
|
|
23
|
+
.file-inbox-phase.complete { color:var(--dsr-success); }
|
|
24
|
+
.file-inbox-meta,.file-inbox-intro,.file-inbox-empty { margin:7px 0; font-size:12px; line-height:1.5; color:var(--dsr-muted); }
|
|
25
|
+
.file-inbox-message { margin:6px 0; font-size:13px; line-height:1.5; white-space:pre-wrap; overflow-wrap:anywhere; }
|
|
26
|
+
.file-inbox-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
|
|
27
|
+
.file-inbox-button { min-height:40px; padding:6px 13px; border:1px solid var(--dsr-line); border-radius:9px; background:var(--dsr-panel); color:var(--dsr-text); font:inherit; font-size:12px; cursor:pointer; }
|
|
28
|
+
.file-inbox-button.primary { background:var(--dsr-accent-soft); border-color:var(--dsr-accent-line); color:var(--dsr-accent-strong); font-weight:700; }
|
|
29
|
+
.file-inbox-button:focus-visible,.file-inbox-device input:focus-visible,.file-inbox-head h2:focus-visible { outline:2px solid var(--dsr-accent); outline-offset:2px; }
|
|
30
|
+
.file-inbox-button:disabled { opacity:.55; cursor:wait; }
|
|
31
|
+
.file-inbox-details { margin-top:6px; font-size:11px; line-height:1.5; color:var(--dsr-muted); }
|
|
32
|
+
.file-inbox-details summary,.file-inbox-history summary,.file-inbox-device summary { cursor:pointer; min-height:32px; align-content:center; }
|
|
33
|
+
.file-inbox-details p { margin:4px 0; }
|
|
34
|
+
.file-inbox-history,.file-inbox-device { margin-top:12px; padding-top:8px; border-top:1px solid var(--dsr-line); font-size:12px; color:var(--dsr-muted); }
|
|
35
|
+
.file-inbox-device input { box-sizing:border-box; max-width:100%; width:180px; min-height:40px; margin:8px 4px 8px 0; padding:6px 9px; border:1px solid var(--dsr-line); border-radius:8px; background:var(--dsr-bg-2); color:var(--dsr-text); }
|
|
36
|
+
.file-inbox-device small { display:block; margin-top:8px; overflow-wrap:anywhere; }
|
|
37
|
+
.file-inbox-note { margin:8px 0 0; color:var(--dsr-warning); font-size:12px; line-height:1.5; overflow-wrap:anywhere; }
|
|
38
|
+
.ds-view .file-inbox-files { margin:0 0 16px; }
|
|
39
|
+
.ds-view .file-inbox-session { margin:10px 22px 0; }
|
|
40
|
+
#view-files.ds-view { overflow-y:auto; }
|
|
41
|
+
@media(min-width:700px) {
|
|
42
|
+
.ds-view .file-inbox-card { display:grid; grid-template-columns:minmax(0,1fr) auto; column-gap:18px; }
|
|
43
|
+
.ds-view .file-inbox-card-head,.ds-view .file-inbox-meta,.ds-view .file-inbox-message,.ds-view .file-inbox-details { grid-column:1; }
|
|
44
|
+
.ds-view .file-inbox-actions { grid-column:2; grid-row:1 / 6; align-self:center; margin:0; }
|
|
45
|
+
.ds-view .file-inbox-note { grid-column:1 / -1; }
|
|
46
|
+
}
|
|
47
|
+
@media(max-width:360px) { .file-inbox-card { padding:10px; } .file-inbox-icon { display:none; } }
|
|
48
|
+
.file-inbox-card.is-compact { display:block; padding:9px 10px; }
|
|
49
|
+
.file-inbox-card.is-compact .file-inbox-card-head { align-items:center; gap:8px; }
|
|
50
|
+
.file-inbox-card.is-compact .file-inbox-filename { display:-webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:2; overflow:hidden; line-height:1.4; }
|
|
51
|
+
.file-inbox-inline-meta { display:flex; flex:none; flex-direction:column; align-items:flex-end; gap:2px; max-width:45%; font-size:11px; color:var(--dsr-muted); }
|
|
52
|
+
.file-inbox-inline-meta .file-inbox-phase { max-width:none; padding:0; margin:0; border:0; font-size:10px; }
|
|
53
|
+
.file-inbox-card.is-compact .file-inbox-message { display:-webkit-box; -webkit-box-orient:vertical; -webkit-line-clamp:2; overflow:hidden; margin:5px 0; line-height:1.45; font-size:12px; }
|
|
54
|
+
.file-inbox-card.is-compact .file-inbox-actions { margin-top:6px; gap:6px; align-items:flex-start; }
|
|
55
|
+
.file-inbox-card.is-compact .file-inbox-button { min-height:36px; padding:5px 11px; }
|
|
56
|
+
.file-inbox-card.is-compact .file-inbox-details { margin:0 0 0 auto; }
|
|
57
|
+
.file-inbox-card.is-compact .file-inbox-details > summary { display:flex; align-items:center; min-height:36px; padding:0 6px; list-style:none; cursor:pointer; }
|
|
58
|
+
.file-inbox-card.is-compact .file-inbox-details > summary::-webkit-details-marker { display:none; }
|
|
59
|
+
.file-inbox-card.is-compact .file-inbox-details > summary::after { content:'⌄'; margin-left:5px; }
|
|
60
|
+
.file-inbox-card.is-compact .file-inbox-details[open] { flex-basis:100%; order:3; }
|
|
61
|
+
.file-inbox-card.is-compact .file-inbox-details[open] > summary::after { content:'⌃'; }
|
|
62
|
+
.file-inbox-card.is-compact .file-inbox-details p { white-space:pre-wrap; }
|
|
63
|
+
@media(min-width:900px) {
|
|
64
|
+
.ds-view .session-deck[data-mounted] .file-inbox-card.is-compact[data-deck-active]:not(:has(details[open])) { display:grid !important; grid-template-columns:minmax(0,1fr) auto; column-gap:18px; }
|
|
65
|
+
.ds-view .file-inbox-card.is-compact .file-inbox-actions { grid-column:2; grid-row:1 / 3; align-self:center; margin:0; }
|
|
66
|
+
}
|