dsh-remote-plugin 0.8.0-rc.2 → 0.8.0-rc.4
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/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +325 -38
- package/index.mjs +24 -0
- package/package.json +3 -1
- package/peak-reminders.mjs +47 -0
- package/public/activity.js +126 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +8 -0
- package/public/app.js +572 -247
- package/public/build.json +5 -0
- package/public/desktop/desktop.css +10 -10
- package/public/desktop/desktop.html +36 -9
- package/public/desktop/desktop.js +287 -95
- package/public/diagnostics.js +109 -0
- package/public/extensions.js +7 -4
- package/public/history.js +44 -16
- package/public/image-preview.js +132 -0
- package/public/index.html +50 -11
- package/public/md.js +41 -1
- package/public/network.js +30 -6
- package/public/operations.js +1 -1
- package/public/relay-settings.js +19 -10
- package/public/styles.css +15 -15
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/teams.js +76 -0
- package/public/turn-results.js +119 -0
- package/public/update.json +4 -4
- package/public/version.json +1 -1
- package/public/workflow.css +216 -1
- package/public/workflow.js +91 -9
- package/teams.mjs +53 -0
package/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { dirname, extname, normalize, resolve } from 'node:path'
|
|
|
14
14
|
import { fileURLToPath } from 'node:url'
|
|
15
15
|
import { createPluginCenter, detectProfile } from './plugin-center.mjs'
|
|
16
16
|
import { readCostInsights } from './insights.mjs'
|
|
17
|
+
import { readTeamInsights } from './teams.mjs'
|
|
18
|
+
import { readPeakReminders } from './peak-reminders.mjs'
|
|
17
19
|
import { serveSessionFile } from './session-file.mjs'
|
|
18
20
|
import { createSkillsAdapter } from './skills.mjs'
|
|
19
21
|
|
|
@@ -684,6 +686,28 @@ async function serveStatic(req, res, ctx) {
|
|
|
684
686
|
const result = await adapter.handle(req.method, pathname.slice(`${MOUNT}/api/skills`.length), url.searchParams)
|
|
685
687
|
return sendJson(res, result.status, result.body)
|
|
686
688
|
}
|
|
689
|
+
if (pathname === `${MOUNT}/api/teams`) {
|
|
690
|
+
res.setHeader('cache-control', 'no-store')
|
|
691
|
+
if (!remoteCommandAuthorized(req)) return sendJson(res, 401, { ok: false, code: 'unauthorized' })
|
|
692
|
+
if (req.method !== 'GET') return sendJson(res, 405, { ok: false, code: 'read-only' })
|
|
693
|
+
const result = await readTeamInsights(ctx, new URL(req.url, 'http://x').searchParams, async archived => {
|
|
694
|
+
let cookie = ''
|
|
695
|
+
try { cookie = readFileSync(dshUpstreamCookieFile(), 'utf8').trim() } catch {}
|
|
696
|
+
if (cookie.length > 4096 || /[\x00-\x1f]/.test(cookie)) cookie = ''
|
|
697
|
+
return fetch(upstreamUrlForListener(dshListen) + '/plugins/dsh-agent-teams/state' + (archived ? '?archived=1' : ''), {
|
|
698
|
+
headers: cookie ? { cookie } : {}, redirect: 'error', signal: AbortSignal.timeout(20000)
|
|
699
|
+
})
|
|
700
|
+
})
|
|
701
|
+
return sendJson(res, result.status, result.body)
|
|
702
|
+
}
|
|
703
|
+
if (pathname === `${MOUNT}/api/insights/peak-reminders`) {
|
|
704
|
+
res.setHeader('cache-control', 'no-store')
|
|
705
|
+
if (!remoteCommandAuthorized(req)) return sendJson(res, 401, { ok: false, code: 'unauthorized' })
|
|
706
|
+
if (req.method !== 'GET') return sendJson(res, 405, { ok: false, code: 'read-only' })
|
|
707
|
+
if ([...new URL(req.url, 'http://x').searchParams].length) return sendJson(res, 400, { ok: false, code: 'invalid-query' })
|
|
708
|
+
const result = await readPeakReminders(ctx)
|
|
709
|
+
return sendJson(res, result.status, result.body)
|
|
710
|
+
}
|
|
687
711
|
if (pathname === `${MOUNT}/api/insights/cost`) {
|
|
688
712
|
if (!remoteCommandAuthorized(req)) return sendJson(res, 401, { ok: false, code: 'unauthorized' })
|
|
689
713
|
if (req.method !== 'GET') return sendJson(res, 405, { ok: false, code: 'read-only' })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote-plugin",
|
|
3
|
-
"version": "0.8.0-rc.
|
|
3
|
+
"version": "0.8.0-rc.4",
|
|
4
4
|
"description": "DSH Remote 官方 bundle 插件:DSH 左侧原生边栏入口 + 右侧抽屉内嵌管理控制台;内置网关随 DSH 自动启停(systemd 独立单元),抽屉直显令牌与设备监控;网关提供 /fs/* 文件传输端点(列表/断点下载/上传),配合 Android App 远程操控会话/审批/提问/goal 与文件互传(多服务器测速切换、聊天记录离线缓存)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
"*.md",
|
|
22
22
|
"plugin-center.mjs",
|
|
23
23
|
"insights.mjs",
|
|
24
|
+
"teams.mjs",
|
|
25
|
+
"peak-reminders.mjs",
|
|
24
26
|
"skills.mjs",
|
|
25
27
|
"session-file.mjs"
|
|
26
28
|
],
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Only public peak-pricing settings are projected; account configuration stays on the host.
|
|
2
|
+
export function peakReminderSchedule(config, now = Date.now()) {
|
|
3
|
+
const base = { ok: true, schema: 1, source: 'dsh-cost-meter', generatedAt: now, validUntil: now + 7 * 86400000 }
|
|
4
|
+
if (config?.peakEnabled === false || config?.peakAlertEnabled === false) return { ...base, available: true, enabled: false, events: [] }
|
|
5
|
+
const windows = config?.peakWindows, holidays = config?.peakHolidays
|
|
6
|
+
const effectiveAt = Date.parse(config?.peakEffectiveAt || '')
|
|
7
|
+
const validDate = d => typeof d === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(d) && Number.isFinite(Date.parse(d + 'T00:00:00Z')) && new Date(d + 'T00:00:00Z').toISOString().slice(0,10) === d
|
|
8
|
+
const ahead = config?.peakAlertAhead ?? 2, target = config?.peakAlertTarget ?? 'both'
|
|
9
|
+
if (config?.peakEnabled !== true || !Array.isArray(windows) || windows.length > 24 || !Array.isArray(holidays) || holidays.length > 366
|
|
10
|
+
|| !Number.isFinite(effectiveAt) || !Number.isInteger(ahead) || ahead < 1 || ahead > 30 || !['peak','offpeak','both'].includes(target)
|
|
11
|
+
|| windows.some(w => !Number.isInteger(w?.start) || w.start < 0 || w.start > 23 || !Number.isInteger(w?.end) || w.end < 0 || w.end > 24)
|
|
12
|
+
|| holidays.some(d => !validDate(d))) {
|
|
13
|
+
return { ...base, available: false, code: 'unsupported-policy', events: [] }
|
|
14
|
+
}
|
|
15
|
+
const excluded = new Set(holidays)
|
|
16
|
+
const isPeak = at => {
|
|
17
|
+
if (at < effectiveAt) return false
|
|
18
|
+
const beijing = new Date(at + 8 * 3600000), day = beijing.getUTCDay()
|
|
19
|
+
if (day === 0 || day === 6 || excluded.has(beijing.toISOString().slice(0,10))) return false
|
|
20
|
+
const hour = new Date(at).getUTCHours()
|
|
21
|
+
return windows.some(w => w.start < w.end ? hour >= w.start && hour < w.end : hour >= w.start || hour < w.end)
|
|
22
|
+
}
|
|
23
|
+
const candidates = new Set([effectiveAt]), midnight = Math.floor(now / 86400000) * 86400000
|
|
24
|
+
for (let day = -1; day <= 8; day++) {
|
|
25
|
+
const start = midnight + day * 86400000
|
|
26
|
+
candidates.add(start + 16 * 3600000)
|
|
27
|
+
for (const w of windows) { candidates.add(start + w.start * 3600000); candidates.add(start + w.end * 3600000) }
|
|
28
|
+
}
|
|
29
|
+
const events = [...candidates].sort((a,b) => a-b).flatMap(at => {
|
|
30
|
+
const intoPeak = isPeak(at)
|
|
31
|
+
if (at < now - 30 * 60000 || at > base.validUntil || isPeak(at - 1) === intoPeak || target !== 'both' && (target === 'peak') !== intoPeak) return []
|
|
32
|
+
return [{ id: at + ':' + (intoPeak ? 'peak' : 'offpeak'), at, notifyAt: at - ahead * 60000, intoPeak }]
|
|
33
|
+
}).slice(0,64)
|
|
34
|
+
return { ...base, available: true, enabled: true, aheadMinutes: ahead, target, timezone: 'Asia/Shanghai', events }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function readPeakReminders(ctx) {
|
|
38
|
+
let service
|
|
39
|
+
try { service = ctx.get?.('costMeter') } catch {}
|
|
40
|
+
if (!service || typeof service.getState !== 'function') return { status: 200, body: { ok: true, schema: 1, available: false, code: 'not-installed' } }
|
|
41
|
+
let timer
|
|
42
|
+
try {
|
|
43
|
+
const state = await Promise.race([Promise.resolve().then(() => service.getState()), new Promise((_, reject) => { timer = setTimeout(() => reject(Error('timeout')), 20000) })])
|
|
44
|
+
return { status: 200, body: peakReminderSchedule(state?.config) }
|
|
45
|
+
} catch { return { status: 502, body: { ok: false, code: 'peak-policy-unavailable' } } }
|
|
46
|
+
finally { clearTimeout(timer) }
|
|
47
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* Compact, shared conversation activity. Durable events remain untouched. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
const esc=value=>String(value??'').replace(/[&<>"']/g,char=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[char]))
|
|
5
|
+
const text=(zh,en)=>root.I18N?.lang==='en'?en:zh
|
|
6
|
+
const json=value=>{try{return typeof value==='string'?value:JSON.stringify(value,null,2)??''}catch{return String(value)}}
|
|
7
|
+
const cut=(value,length)=>{const source=String(value??'');return source.length>length?source.slice(0,length)+'…':source}
|
|
8
|
+
const brief=value=>cut(String(value??'').replace(/\s+/g,' ').trim(),100)
|
|
9
|
+
const icon=kind=>`<svg class="activity-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${kind==='reasoning'?'m12 3 2.4 6.6L21 12l-6.6 2.4L12 21l-2.4-6.6L3 12l6.6-2.4Z':'m8 7-5 5 5 5m8-10 5 5-5 5m-3-14-2 18'}"/></svg>`
|
|
10
|
+
function argumentHint(value){
|
|
11
|
+
if(typeof value==='string'){try{value=JSON.parse(value)}catch{return brief(value)}}
|
|
12
|
+
if(!value||typeof value!=='object')return ''
|
|
13
|
+
for(const key of ['description','command','cmd','path','file_path','pattern','query','url','line'])if(typeof value[key]==='string')return brief(value[key])
|
|
14
|
+
return ''
|
|
15
|
+
}
|
|
16
|
+
function shell(kind,key,title,hint,state,body,live=false,error=false){
|
|
17
|
+
return `<details class="chat-activity activity-${kind}${live?' is-live':''}${error?' is-error':''}" data-activity-key="${esc(key)}"><summary>${icon(kind)}<span class="activity-copy"><span class="activity-title">${esc(title)}</span>${hint?`<span class="activity-hint">${esc(hint)}</span>`:''}</span><span class="activity-state">${live?'<i aria-hidden="true"></i>':''}${esc(state)}</span><span class="activity-chevron" aria-hidden="true"></span></summary><div class="activity-body">${body}</div></details>`
|
|
18
|
+
}
|
|
19
|
+
function reasoning(value={}){
|
|
20
|
+
const source=String(value.text??'')
|
|
21
|
+
const hint=brief(source.split('\n').filter(line=>line.trim()).at(-1)||'')
|
|
22
|
+
return shell('reasoning',value.key,text(value.live?'思考中':'思考过程',value.live?'Thinking':'Reasoning'),hint,value.live?text('进行中','Live'):'',`<div class="activity-reasoning-text">${esc(cut(source,12000))}</div>`,!!value.live)
|
|
23
|
+
}
|
|
24
|
+
const errorOf=data=>!!(data?.error||data?.ok===false||data?.isError===true)
|
|
25
|
+
function tool(value={}){
|
|
26
|
+
const args=value.args,returned=Object.hasOwn(value,'result'),error=!!value.error
|
|
27
|
+
const section=(title,content)=>`<section><h4>${esc(title)}</h4><pre>${esc(cut(json(content),12000))}</pre></section>`
|
|
28
|
+
const body=(args===undefined?'':section(text('参数','Arguments'),args))+(returned?section(text('结果','Result'),value.result):`<p class="activity-note">${esc(text('当前记录中尚无对应结果。','No matching result in the loaded history.'))}</p>`)
|
|
29
|
+
return shell('tool',value.key,value.name||text(returned?'工具结果':'工具调用',returned?'Tool result':'Tool call'),argumentHint(args),text(error?'返回错误':returned?'已返回':'已调用',error?'Error':returned?'Returned':'Called'),body,false,error)
|
|
30
|
+
}
|
|
31
|
+
const dataOf=entry=>entry.event?.data||{}
|
|
32
|
+
const callId=data=>data.callId||data.message?.source?.callId
|
|
33
|
+
const resultOf=data=>data.error??data.result??data.output??data.message??data.text??data.content??data
|
|
34
|
+
const pairs=new WeakMap()
|
|
35
|
+
function prepare(entries){
|
|
36
|
+
const pending=new Map(),matched=new Map(),consumed=new Set()
|
|
37
|
+
for(const entry of entries){
|
|
38
|
+
const data=dataOf(entry),id=callId(data)
|
|
39
|
+
if(!id)continue
|
|
40
|
+
if(entry.event?.type==='tool/call'){const queue=pending.get(id)||[];queue.push(entry);pending.set(id,queue)}
|
|
41
|
+
else if(entry.event?.type==='tool/result'){
|
|
42
|
+
const queue=pending.get(id)||[]
|
|
43
|
+
const index=queue.findLastIndex(call=>data.turn==null||dataOf(call).turn==null||data.turn===dataOf(call).turn)
|
|
44
|
+
if(index>=0){const [call]=queue.splice(index,1);matched.set(call,entry);consumed.add(entry)}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return entries.filter(entry=>!consumed.has(entry)).map(entry=>{
|
|
48
|
+
if(entry.event?.type!=='tool/call')return entry
|
|
49
|
+
const result=matched.get(entry)
|
|
50
|
+
if(!result)return entry
|
|
51
|
+
const cached=pairs.get(entry)
|
|
52
|
+
if(cached?.result===result)return cached.entry
|
|
53
|
+
const data=dataOf(entry),output=dataOf(result)
|
|
54
|
+
const next={...entry,view:{...entry.view,toolActivity:{key:'tool:'+entry.seq,name:data.name||data.toolName,args:data.arguments??data.args??data.input,result:resultOf(output),error:errorOf(output)}}}
|
|
55
|
+
pairs.set(entry,{result,entry:next});return next
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
function toolEvent(entry){
|
|
59
|
+
if(entry.view?.toolActivity)return tool(entry.view.toolActivity)
|
|
60
|
+
const data=dataOf(entry),isResult=entry.event?.type==='tool/result'
|
|
61
|
+
return tool({key:'tool:'+entry.seq,name:data.name||data.toolName||(isResult?text('工具结果','Tool result'):undefined),...(isResult?{result:resultOf(data),error:errorOf(data)}:{args:data.arguments??data.args??data.input})})
|
|
62
|
+
}
|
|
63
|
+
function reasoningKind(block){return block&&typeof block==='object'&&(block.type==='thinking'||block.type==='reasoning')}
|
|
64
|
+
function messageBlocks(entry){
|
|
65
|
+
const data=entry?.event?.data||{},message=data.message||{}
|
|
66
|
+
const blocks=Array.isArray(message.content)?message.content:(Array.isArray(data.content)?data.content:null)
|
|
67
|
+
return blocks?{data,message,blocks}:null
|
|
68
|
+
}
|
|
69
|
+
function stripReasoning(entry,rest){
|
|
70
|
+
const parts=messageBlocks(entry)
|
|
71
|
+
const data={...parts.data}
|
|
72
|
+
if(Array.isArray(parts.message.content))data.message={...parts.message,content:rest}
|
|
73
|
+
else data.content=rest
|
|
74
|
+
return {...entry,event:{...entry.event,data}}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Collapse a turn's process — every tool activity plus the reasoning blocks that would
|
|
78
|
+
* otherwise occupy a row inside each assistant message — into one disclosure.
|
|
79
|
+
* A user message starts a new turn; a turn without enough items keeps its original rows.
|
|
80
|
+
*/
|
|
81
|
+
function group(entries){
|
|
82
|
+
const isTool=entry=>{const type=entry?.event?.type;return type==='tool/call'||type==='tool/result'}
|
|
83
|
+
// Only a human message starts a new turn; injected system-reminder user events do not.
|
|
84
|
+
const isTurnStart=entry=>{
|
|
85
|
+
if(entry?.event?.type!=='user/message')return false
|
|
86
|
+
const data=entry.event.data||{},source=data.source??data.message?.source
|
|
87
|
+
return !source||source.kind==='user'
|
|
88
|
+
}
|
|
89
|
+
const out=[]
|
|
90
|
+
const emit=segment=>{
|
|
91
|
+
const items=[],stripped=new Map()
|
|
92
|
+
for(const entry of segment){
|
|
93
|
+
if(isTool(entry)){items.push({kind:'tool',seq:entry.seq,entry});continue}
|
|
94
|
+
const parts=messageBlocks(entry)
|
|
95
|
+
if(!parts)continue
|
|
96
|
+
const reasoning=parts.blocks.filter(reasoningKind)
|
|
97
|
+
if(!reasoning.length)continue
|
|
98
|
+
const rest=parts.blocks.filter(block=>!reasoningKind(block))
|
|
99
|
+
const copy=stripReasoning(entry,rest)
|
|
100
|
+
stripped.set(entry,{copy,empty:rest.length===0})
|
|
101
|
+
reasoning.forEach((block,index)=>items.push({kind:'reasoning',seq:Number(entry.seq)+(index+1)/1000,text:String(block.text??block.content??''),key:'reasoning:'+entry.seq+':'+index}))
|
|
102
|
+
}
|
|
103
|
+
if(items.length>1){
|
|
104
|
+
let emitted=false
|
|
105
|
+
for(const entry of segment){
|
|
106
|
+
const decorated=stripped.get(entry)
|
|
107
|
+
if((isTool(entry)||decorated)&&!emitted){out.push({seq:items[0].seq,event:{type:'activity/group'},view:{activityGroup:{items}}});emitted=true}
|
|
108
|
+
if(isTool(entry))continue
|
|
109
|
+
if(decorated){if(!decorated.empty)out.push(decorated.copy);continue}
|
|
110
|
+
out.push(entry)
|
|
111
|
+
}
|
|
112
|
+
}else out.push(...segment)
|
|
113
|
+
}
|
|
114
|
+
let segment=[]
|
|
115
|
+
for(const entry of entries){
|
|
116
|
+
if(isTurnStart(entry)){emit(segment);segment=[];out.push(entry)}
|
|
117
|
+
else segment.push(entry)
|
|
118
|
+
}
|
|
119
|
+
emit(segment)
|
|
120
|
+
return out
|
|
121
|
+
}
|
|
122
|
+
function reasoningKey(data,index,fallback){return data?.turn!=null&&data?.step!=null?'reasoning:'+JSON.stringify([data.turn,data.step,index]):fallback}
|
|
123
|
+
const api={prepare,tool,toolEvent,reasoning,reasoningKey,group}
|
|
124
|
+
if(typeof module!=='undefined'&&module.exports)module.exports=api
|
|
125
|
+
else root.DshActivity=api
|
|
126
|
+
})(typeof window==='undefined'?globalThis:window)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* Shared bounded announcement schema. Embedded into the single-file gateway. */
|
|
2
|
+
'use strict';
|
|
3
|
+
function createAnnouncementForms() {
|
|
4
|
+
const string = (value, max) => typeof value === 'string' && value.trim().length <= max ? value.trim() : ''
|
|
5
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
6
|
+
function normalize(value, announcementId) {
|
|
7
|
+
if (!value || typeof value !== 'object') return null
|
|
8
|
+
const id = string(value.id || announcementId, 120)
|
|
9
|
+
const legacy = !Array.isArray(value.questions) && !value.type || value.legacy === true
|
|
10
|
+
const rows = Array.isArray(value.questions) ? value.questions : [{ ...value, id: 'answer' }]
|
|
11
|
+
if (!id || !rows.length || rows.length > 8) return null
|
|
12
|
+
const ids = new Set(), questions = []
|
|
13
|
+
for (const row of rows) {
|
|
14
|
+
const questionId = string(row?.id, 120), question = string(row?.question || row?.label, 300), type = row?.type || 'single'
|
|
15
|
+
if (!questionId || ids.has(questionId) || !question || !['single','multiple','text'].includes(type)) return null
|
|
16
|
+
ids.add(questionId)
|
|
17
|
+
const required = row.required !== false, options = [], seen = new Set()
|
|
18
|
+
if (type !== 'text') {
|
|
19
|
+
if (!Array.isArray(row.options) || row.options.length < 2 || row.options.length > 12) return null
|
|
20
|
+
for (const option of row.options) {
|
|
21
|
+
const optionId = string(option?.id, 120), label = string(option?.label, 200)
|
|
22
|
+
if (!optionId || !label || seen.has(optionId)) return null
|
|
23
|
+
seen.add(optionId); options.push({ id: optionId, label, description: string(option.description || '', 500) })
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const min = type === 'text' ? (required ? 1 : 0) : row.minSelections ?? row.min ?? (required ? 1 : 0)
|
|
27
|
+
const max = type === 'text' ? row.maxLength ?? row.max ?? 600 : type === 'single' ? 1 : row.maxSelections ?? row.max ?? options.length
|
|
28
|
+
if (!Number.isInteger(min) || !Number.isInteger(max) || min < 0 || max < Math.max(1, min) || max > (type === 'text' ? 1200 : options.length)) return null
|
|
29
|
+
questions.push({ id: questionId, question, type, required, options, min, max, placeholder: string(row.placeholder || '', 200) })
|
|
30
|
+
}
|
|
31
|
+
return { id, legacy: !!legacy, question: string(value.question || value.title, 300) || questions[0].question,
|
|
32
|
+
options: questions.length === 1 ? questions[0].options : [], questions }
|
|
33
|
+
}
|
|
34
|
+
function validate(poll, payload) {
|
|
35
|
+
if (!poll) return { error: 'poll not found' }
|
|
36
|
+
const rows = poll.legacy && typeof payload.optionId === 'string' ? [{ questionId: poll.questions[0].id, optionIds: [payload.optionId] }] : payload.answers
|
|
37
|
+
if (!Array.isArray(rows) || rows.length > poll.questions.length) return { error: 'invalid answers' }
|
|
38
|
+
const byId = new Map()
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
if (!row || typeof row.questionId !== 'string' || byId.has(row.questionId) || !poll.questions.some(q => q.id === row.questionId)) return { error: 'invalid question' }
|
|
41
|
+
byId.set(row.questionId, row)
|
|
42
|
+
}
|
|
43
|
+
const answers = []
|
|
44
|
+
for (const q of poll.questions) {
|
|
45
|
+
const row = byId.get(q.id)
|
|
46
|
+
if (q.type === 'text') {
|
|
47
|
+
const value = row?.text ?? ''
|
|
48
|
+
if (typeof value !== 'string' || value.trim().length < q.min || value.trim().length > q.max || /[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value)) return { error: 'invalid text', questionId: q.id }
|
|
49
|
+
if (value.trim()) answers.push({ questionId: q.id, text: value.trim() })
|
|
50
|
+
} else {
|
|
51
|
+
const values = row?.optionIds ?? []
|
|
52
|
+
if (!Array.isArray(values) || values.length < q.min || values.length > q.max || new Set(values).size !== values.length) return { error: 'invalid selection count', questionId: q.id }
|
|
53
|
+
if (values.some(id => typeof id !== 'string' || !q.options.some(option => option.id === id))) return { error: 'poll option not found', questionId: q.id }
|
|
54
|
+
if (values.length) answers.push({ questionId: q.id, optionIds: q.options.filter(option => values.includes(option.id)).map(option => option.id) })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!answers.length) return { error: 'answer required' }
|
|
58
|
+
return poll.legacy ? { optionId: answers[0].optionIds[0] } : { answers }
|
|
59
|
+
}
|
|
60
|
+
function encode(announcementId, pollId, answer) {
|
|
61
|
+
const message = 'POLL ' + JSON.stringify({ announcementId, pollId, ...answer })
|
|
62
|
+
return message.length <= 2000 ? message : null
|
|
63
|
+
}
|
|
64
|
+
function render(poll, answers = [], disabled = false, english = false) {
|
|
65
|
+
return poll.questions.map((q, index) => {
|
|
66
|
+
const answer = answers.find(row => row.questionId === q.id), off = disabled ? ' disabled' : ''
|
|
67
|
+
const label = q.question + (q.required ? ' *' : '')
|
|
68
|
+
const body = q.type === 'text'
|
|
69
|
+
? `<textarea aria-label="${esc(label)}" id="announcement-field-${index}" maxlength="${q.max}" rows="2" placeholder="${esc(q.placeholder)}"${q.required ? ' required' : ''}${off}>${esc(answer?.text || '')}</textarea>`
|
|
70
|
+
: q.options.map(option => `<label class="announcement-poll-option"><input type="${q.type === 'multiple' ? 'checkbox' : 'radio'}" name="announcement-q-${index}" value="${esc(option.id)}"${answer?.optionIds?.includes(option.id) ? ' checked' : ''}${off}><span><strong>${esc(option.label)}</strong>${option.description ? `<small>${esc(option.description)}</small>` : ''}</span></label>`).join('')
|
|
71
|
+
const hint = q.type === 'multiple' ? (english ? `Choose ${q.min}–${q.max}` : `选择 ${q.min}–${q.max} 项`) : q.type === 'text' ? (english ? `Up to ${q.max} characters` : `最多 ${q.max} 字`) : ''
|
|
72
|
+
return `<fieldset class="announcement-form-field" data-form-question="${esc(q.id)}"><legend>${esc(label)}</legend>${hint ? `<p class="announcement-form-hint">${esc(hint)}</p>` : ''}${body}</fieldset>`
|
|
73
|
+
}).join('')
|
|
74
|
+
}
|
|
75
|
+
function read(panel, poll) {
|
|
76
|
+
const fields = [...panel.querySelectorAll('[data-form-question]')]
|
|
77
|
+
return poll.questions.map(q => {
|
|
78
|
+
const field = fields.find(el => el.dataset.formQuestion === q.id)
|
|
79
|
+
return q.type === 'text' ? { questionId: q.id, text: field?.querySelector('textarea')?.value || '' }
|
|
80
|
+
: { questionId: q.id, optionIds: [...(field?.querySelectorAll('input:checked') || [])].map(el => el.value) }
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
return { normalize, validate, encode, render, read }
|
|
84
|
+
}
|
|
85
|
+
;(function(root) {
|
|
86
|
+
const api = createAnnouncementForms()
|
|
87
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
88
|
+
else root.DshAnnouncementForms = api
|
|
89
|
+
})(typeof window === 'undefined' ? globalThis : window)
|
|
@@ -177,6 +177,14 @@
|
|
|
177
177
|
"publishedAt": "2026-09-19T08:03:06+08:00",
|
|
178
178
|
"actionUrl": "https://github.com/Blank-not-black/dsh-Remote/releases/tag/v0.7.0-rc.1",
|
|
179
179
|
"actionText": "下载 0.7.0-rc.1 测试版"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"id": "2026-10-16-0.8.0-relay-trial",
|
|
183
|
+
"title": "0.8.0 预告 · 云中转试测招募",
|
|
184
|
+
"content": "感谢各位开发者持续使用 DSH Remote,也感谢大家耐心反馈问题和建议。这些来自实际使用的意见,是本次 0.8.0 调整的重要依据。\n\n0.8.0 主要变化\n① 整理为「会话、文件、更多」三个入口,整合待审批、待回答和常用操作。\n② 简化新建会话、工作区选择与设置流程,减少重复操作。\n③ 改进弱网状态反馈和断线恢复;结果未确认的操作不会自动重复发送。\n④ 增加聊天文本文件预览、改进上传体验,并修复 Windows 插件更新时的部分目录占用问题。\n\n目前 0.8.0-rc.2 已发布,正式版将根据试测反馈继续调整。本轮界面改动主要覆盖 Android 和手机、桌面 Web。\n\n云服务器中转试测\n测试版新增云中转:每位测试者连接自己的 DSH,在设置中填写个人中转密钥,绑定后即可通过专属公网地址连接。电脑上的 DSH 和 Remote 网关仍需保持运行。\n\n首批开放 5 个名额,测试周期约一周,具体有效期以授权通知为准。每位用户每日上传与下载合计 5GB,北京时间零点重置。我们主要收集连接成功率、响应延迟、实时输出与断线恢复方面的反馈。\n\n中转采用云端终止 TLS 的方式,运营者在技术上可接触经过的转发内容,请使用适合参与试测的环境和数据。\n\n如何申请\n请复制下方完整申请模板,打开 App 顶部「反馈 → 直接反馈」,选择「其他」,将模板粘贴到反馈内容栏,填写后提交。选择题请保留一个选项即可。\n\n【云中转试测申请】\n昵称:\n邮箱:\nQQ群内昵称/备注名:\nQQ号:\n电脑系统:Windows/Linux/macOS/其他\n主要问题:公网连接困难/延迟高/经常断线/传输慢/希望体验\n是否愿意反馈试测问题:愿意/暂时无法保证\n手机系统及补充说明(选填):\n\n填写的信息仅用于测试资格安排和试测联络,请勿提交中转密钥、Remote 令牌或模型 API Key。感谢大家继续帮助 DSH Remote 改善使用体验!",
|
|
185
|
+
"minVersion": "",
|
|
186
|
+
"maxVersion": "",
|
|
187
|
+
"publishedAt": "2026-10-16T09:27:32.340Z"
|
|
180
188
|
}
|
|
181
189
|
]
|
|
182
190
|
}
|