dsh-plugin-starpost 0.4.0 → 0.5.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -21
- package/README.md +2 -0
- package/cordis.patch.yml +3 -3
- package/docs/voice.md +81 -81
- package/lib/ENV_PROMPT.md +9 -9
- package/lib/core.mjs +35 -9
- package/package.json +77 -75
- package/src/account.mjs +47 -47
- package/src/index.mjs +185 -185
- package/src/local.mjs +100 -100
- package/src/panel.mjs +192 -192
- package/src/settings.mjs +22 -22
- package/web/app.mjs +168 -168
- package/web/client.js +16 -16
- package/web/fields.mjs +49 -49
- package/web/index.html +6 -6
- package/web/style.css +3 -3
package/src/settings.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import z from '@deepseek-ai/schemastery';
|
|
2
|
-
|
|
3
|
-
const mode = () => z.union(['realtime', 'digest', 'manual']);
|
|
4
|
-
// Optional entry values preserve client.json settings when Cordis supplies {}.
|
|
5
|
-
export const Config = z.object({
|
|
6
|
-
receiveMode: z.union(['active', 'mixed', 'passive']).description('消息接收:active 主动查收;mixed 混合;passive 被动投递。'),
|
|
7
|
-
squareMode: mode().description('广场通知(含公开游戏开桌):manual 完全手动查看,不发更新数量提醒;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
8
|
-
feedMode: mode().description('动态和评论通知:manual 完全手动查看;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
9
|
-
digestIntervalMs: z.number().step(1).min(1000).max(86400000).description('汇总间隔,单位毫秒,默认 300000(5 分钟)。无新内容不唤醒。'),
|
|
10
|
-
}).description('星邮通知设置;修改后重启 Harness。游戏邀请、参赛、主人消息及系统提醒仍按原规则送达。');
|
|
11
|
-
|
|
12
|
-
export const settingsNamespace = 'dsh-plugin-starpost';
|
|
13
|
-
|
|
14
|
-
export function registerNotificationSettings(ctx, base) {
|
|
15
|
-
let source = () => base;
|
|
16
|
-
ctx.inject(['settings'], scoped => {
|
|
17
|
-
const scope = scoped.settings.register(settingsNamespace, Config, { base, applies: 'restart' });
|
|
18
|
-
source = () => scope.get();
|
|
19
|
-
scoped.effect(() => () => { source = () => base; }, 'starpost.notification-settings');
|
|
20
|
-
});
|
|
21
|
-
return () => source();
|
|
22
|
-
}
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
|
|
3
|
+
const mode = () => z.union(['realtime', 'digest', 'manual']);
|
|
4
|
+
// Optional entry values preserve client.json settings when Cordis supplies {}.
|
|
5
|
+
export const Config = z.object({
|
|
6
|
+
receiveMode: z.union(['active', 'mixed', 'passive']).description('消息接收:active 主动查收;mixed 混合;passive 被动投递。'),
|
|
7
|
+
squareMode: mode().description('广场通知(含公开游戏开桌):manual 完全手动查看,不发更新数量提醒;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
8
|
+
feedMode: mode().description('动态和评论通知:manual 完全手动查看;digest 汇总;realtime 实时。主动模式下 realtime 仅汇总提醒。'),
|
|
9
|
+
digestIntervalMs: z.number().step(1).min(1000).max(86400000).description('汇总间隔,单位毫秒,默认 300000(5 分钟)。无新内容不唤醒。'),
|
|
10
|
+
}).description('星邮通知设置;修改后重启 Harness。游戏邀请、参赛、主人消息及系统提醒仍按原规则送达。');
|
|
11
|
+
|
|
12
|
+
export const settingsNamespace = 'dsh-plugin-starpost';
|
|
13
|
+
|
|
14
|
+
export function registerNotificationSettings(ctx, base) {
|
|
15
|
+
let source = () => base;
|
|
16
|
+
ctx.inject(['settings'], scoped => {
|
|
17
|
+
const scope = scoped.settings.register(settingsNamespace, Config, { base, applies: 'restart' });
|
|
18
|
+
source = () => scope.get();
|
|
19
|
+
scoped.effect(() => () => { source = () => base; }, 'starpost.notification-settings');
|
|
20
|
+
});
|
|
21
|
+
return () => source();
|
|
22
|
+
}
|
package/web/app.mjs
CHANGED
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import {sections} from './fields.mjs';
|
|
2
|
-
const $ = id=>document.getElementById(id);
|
|
3
|
-
function el(tag,text,cls) {
|
|
4
|
-
const node=document.createElement(tag);
|
|
5
|
-
if(text!==undefined) node.textContent=text;
|
|
6
|
-
if(cls) node.className=cls;
|
|
7
|
-
return node;
|
|
8
|
-
}
|
|
9
|
-
const labels={account:'账号与会话',...Object.fromEntries(Object.entries(sections).map(([id,s])=>[id,s.title])),connection:'服务连接'};
|
|
10
|
-
const icons={account:'M20 21v-2a7 7 0 0 0-14 0v2 M17 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0',notify:'M3 5h18v13H9l-5 4v-4H3z M7 9h10 M7 13h6',limits:'M3 6h18 M3 12h18 M3 18h18 M9 3v6 M16 9v6 M8 15v6',media:'M3 4h18v16H3z M4 17l6-6 4 4 3-3 4 4 M15 8h2',speech:'M9 4a3 3 0 0 1 6 0v7a3 3 0 0 1-6 0z M5 11a7 7 0 0 0 14 0 M12 18v3 M8 21h8'};
|
|
11
|
-
let tab='account',state,nickname='',profileId='',dirty=false,busy=false;
|
|
12
|
-
icons.connection='M9 15l6-6 M8 13l-2 2a3 3 0 0 0 4 4l3-3 M11 8l3-3a3 3 0 0 1 5 4l-3 3';
|
|
13
|
-
function say(text,failed=false){$('notice').textContent=text;$('notice').className=failed?'error':'';}
|
|
14
|
-
async function api(action,body) {
|
|
15
|
-
const headers={'X-Starpost-Panel':'1'};
|
|
16
|
-
const opts={headers,cache:'no-store',credentials:'same-origin'};
|
|
17
|
-
if(body!==undefined){headers['Content-Type']='application/json';opts.method='POST';opts.body=JSON.stringify(body);}
|
|
18
|
-
const res=await fetch('./api/'+action,opts);
|
|
19
|
-
const json=await res.json();
|
|
20
|
-
if(!res.ok)throw Error(json.error || '请求失败');
|
|
21
|
-
return json;
|
|
22
|
-
}
|
|
23
|
-
function btn(label,handler,primary=false) {
|
|
24
|
-
const b=el('button',label,primary?'primary':'');b.type='button';b.addEventListener('click',handler);return b;
|
|
25
|
-
}
|
|
26
|
-
function group(cls='actions'){return el('div',undefined,cls);}
|
|
27
|
-
function card(title,cls='') {
|
|
28
|
-
const c=el('section',undefined,'card '+cls);
|
|
29
|
-
if(title)c.append(el('h2',title));
|
|
30
|
-
return c;
|
|
31
|
-
}
|
|
32
|
-
function field(label,input) {
|
|
33
|
-
const f=el('label',undefined,'field');f.append(el('span',label),input);return f;
|
|
34
|
-
}
|
|
35
|
-
function setBusy(value){busy=value;$('page').inert=value;$('tabs').inert=value;$('reload').disabled=value;}
|
|
36
|
-
async function action(fn) {
|
|
37
|
-
if(busy)return;
|
|
38
|
-
setBusy(true);
|
|
39
|
-
try {await fn();} catch(e){say(e.message,true);} finally {setBusy(false);}
|
|
40
|
-
}
|
|
41
|
-
function resetAllowed(){return !dirty || window.confirm('放弃本页尚未保存的修改?');}
|
|
42
|
-
const baseline=()=>state.pendingRestart?'有设置待生效,重启 DSH 后将使用已保存的配置。':'已读取本机配置。';
|
|
43
|
-
async function refresh(message) {
|
|
44
|
-
const next=await api('state');
|
|
45
|
-
if(next.account.botId!==state?.account.botId)nickname='';
|
|
46
|
-
state=next;dirty=false;render();say(message || baseline());
|
|
47
|
-
if(state.account.botId && profileId!==state.account.botId){
|
|
48
|
-
const id=state.account.botId;profileId=id;
|
|
49
|
-
api('profile',{}).then(result=>{
|
|
50
|
-
if(state.account.botId!==id)return;
|
|
51
|
-
nickname=result.nickname;
|
|
52
|
-
const title=$('accountName');if(title && nickname)title.textContent=nickname;
|
|
53
|
-
}).catch(()=>{ /* The retry button remains available when the relay is offline. */ });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function save(data) {
|
|
57
|
-
await api('save',{...data,revision:state.revision});
|
|
58
|
-
await refresh('已保存。');
|
|
59
|
-
say('已保存。'+(state.pendingRestart?'重启 DSH 后生效。':''));
|
|
60
|
-
}
|
|
61
|
-
function edit(){dirty=true;say('有尚未保存的修改。');}
|
|
62
|
-
window.addEventListener('beforeunload',e=>{if(dirty){e.preventDefault();e.returnValue='';}});
|
|
63
|
-
for(const [id,title] of Object.entries(labels)){
|
|
64
|
-
const b=btn(title,()=>{if(!state || id===tab || !resetAllowed())return;tab=id;dirty=false;render();say(baseline());});
|
|
65
|
-
const svg=document.createElementNS('http://www.w3.org/2000/svg','svg'),p=document.createElementNS(svg.namespaceURI,'path');
|
|
66
|
-
svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('fill','none');svg.setAttribute('stroke','currentColor');svg.setAttribute('stroke-width','1.8');svg.setAttribute('aria-hidden','true');p.setAttribute('d',icons[id]);svg.append(p);b.prepend(svg);b.dataset.tab=id;$('tabs').append(b);
|
|
67
|
-
}
|
|
68
|
-
$('reload').onclick=()=>action(async()=>{if(resetAllowed())await refresh();});
|
|
69
|
-
function display(f,v){return f.choices?.find(x=>x[0]===v)?.[1] ?? (f.type==='checkbox'?(v?'开启':'关闭'):String(f.scale?v/f.scale:v || '默认'));}
|
|
70
|
-
function accountPage() {
|
|
71
|
-
const {account:a}=state, hero=card(a.registered?(nickname || '已登录的 bot'):'尚未登录星邮','hero');
|
|
72
|
-
hero.querySelector('h2').id='accountName';
|
|
73
|
-
const status=el('p',a.registered?'星邮 ID '+a.botId+' · '+(a.mode==='hub'?'FFA Hub 配对':'本机凭据登录'):'选择 DSH 会话后,使用 FFA Hub 在浏览器中配对。');hero.append(status);
|
|
74
|
-
hero.append(el('div',state.ready?'已连接到 DSH 会话':a.expired?'Hub 授权已到期':state.runtimeSession?'等待会话就绪':'尚未启用接收','badge'));
|
|
75
|
-
if(state.runtimeError)hero.append(el('p',state.runtimeError,'aux'));
|
|
76
|
-
if(a.registered)hero.append(btn('读取 bot 昵称',()=>action(async()=>{nickname=(await api('profile',{})).nickname;hero.querySelector('h2').textContent=nickname || '已登录的 bot';say(nickname?'已读取昵称。':'该 bot 尚未设置昵称。');})));
|
|
77
|
-
const bind=card('DSH 会话'), select=el('select');
|
|
78
|
-
select.append(new Option('选择一个会话',''));
|
|
79
|
-
for(const s of state.sessions)select.append(new Option(s.title?s.title+' · '+s.id:s.id,s.id));
|
|
80
|
-
select.value=state.sessionId;select.onchange=edit;
|
|
81
|
-
bind.append(field('用于收发消息的会话',select));
|
|
82
|
-
if(!state.sessions.length)bind.append(el('p','请先在 DSH 中创建一个会话,然后点击重新载入。'));
|
|
83
|
-
const controls=group(), saveSession=btn('保存会话',()=>action(async()=>{if(!select.value)throw Error('请选择 DSH 会话');await save({section:'account',sessionId:select.value});}),true);
|
|
84
|
-
controls.append(saveSession);bind.append(controls);
|
|
85
|
-
if(state.runtimeSession)bind.append(el('p','本次启动使用的会话 · '+state.runtimeSession,'aux'));
|
|
86
|
-
const auth=card('FFA Hub 登录'), pending=a.pending;
|
|
87
|
-
function command(op,body={},ok='操作完成。'){
|
|
88
|
-
return ()=>action(async()=>{
|
|
89
|
-
if(dirty)throw Error('请先保存会话,或重新载入以放弃改动。');
|
|
90
|
-
const result=await api(op,body);
|
|
91
|
-
const messages={pending:'浏览器授权尚未完成。',awaiting_primary:'请管理员在 Hub 指定本安装为主运行端,再检查授权。',connected:'Hub 配对成功。'};
|
|
92
|
-
await refresh((messages[result.status] || ok)+(result.status==='connected' || op==='login' || op==='register'?' 重启 DSH 后启用收发。':''));
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if(pending){
|
|
96
|
-
const expired=Date.now()>=pending.expiresAt;
|
|
97
|
-
auth.append(el('p',expired?'本次配对已过期,请重新开始。':'在 Hub 中选择要连接的 bot,并核对配对码。'));
|
|
98
|
-
if(!expired){
|
|
99
|
-
auth.append(el('div',pending.shortCode,'code'));
|
|
100
|
-
const uri=new URL(pending.verificationUri);
|
|
101
|
-
if(uri.protocol==='https:' || (uri.protocol==='http:' && ['127.0.0.1','localhost','[::1]'].includes(uri.hostname))){
|
|
102
|
-
const link=el('a','打开 FFA Hub ↗','action primary');link.href=uri.href;link.target='_blank';link.rel='noopener noreferrer';auth.append(link);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const buttons=group();
|
|
106
|
-
buttons.append(expired?btn('重新配对',command('hubBegin',{},'已生成新的配对码。')):btn('检查授权并完成登录',command('hubFinish')),btn('取消配对',command('hubCancel',{},'已取消配对。')));auth.append(buttons);
|
|
107
|
-
} else {
|
|
108
|
-
auth.append(btn(a.mode==='hub'?'重新配对':'开始浏览器配对',command('hubBegin',{},'配对码已生成,请打开 FFA Hub。'),true));
|
|
109
|
-
}
|
|
110
|
-
const nodes=[hero,bind,auth];
|
|
111
|
-
if(!a.registered){
|
|
112
|
-
const box=el('details',undefined,'card');box.append(el('summary','使用原星邮凭据或注册新 bot'));
|
|
113
|
-
const file=el('input');file.type='file';file.accept='.json,application/json';
|
|
114
|
-
const controls=group();
|
|
115
|
-
controls.append(btn('恢复已有账号',()=>action(async()=>{
|
|
116
|
-
if(dirty || !state.sessionId)throw Error('请先保存 DSH 会话');
|
|
117
|
-
const chosen=file.files[0];if(!chosen || chosen.size>8192)throw Error('请选择星邮凭据 JSON 文件(最大 8 KB)');
|
|
118
|
-
let data;try{data=JSON.parse((await chosen.text()).replace(/^\uFEFF/,''));}catch{throw Error('凭据文件格式无效');}
|
|
119
|
-
await api('login',{credential:data});file.value='';await refresh('账号已恢复,重启 DSH 后启用收发。');
|
|
120
|
-
})),btn('注册新 bot',()=>{if(confirm('为此安装创建一个新的星邮 bot 账号?'))command('register',{confirm:true},'已注册新 bot。')();}));
|
|
121
|
-
box.append(field('本机星邮凭据文件',file),controls);nodes.push(box);
|
|
122
|
-
}
|
|
123
|
-
return nodes;
|
|
124
|
-
}
|
|
125
|
-
function settingsPage(){
|
|
126
|
-
const section=sections[tab], box=card();
|
|
127
|
-
box.append(el('p',section.hint));
|
|
128
|
-
const form=el('form'),grid=group('grid'),inputs=new Map();
|
|
129
|
-
for(const f of section.fields){
|
|
130
|
-
let input;
|
|
131
|
-
if(f.type==='select'){input=el('select');for(const [v,l] of f.choices)input.append(new Option(l,v));}
|
|
132
|
-
else {input=el('input');input.type=f.type;if(f.type==='number'){input.min=f.min/f.scale;input.max=f.max/f.scale;input.step=f.step==='any'?'any':1/f.scale;input.required=true;}else if(f.type==='text')input.maxLength=2048;}
|
|
133
|
-
const saved=state.saved[f.key];if(f.type==='checkbox')input.checked=saved;else input.value=f.scale?saved/f.scale:saved;
|
|
134
|
-
input.name=f.key;input.oninput=edit;const label=field(f.label,input);
|
|
135
|
-
if(f.hint)label.append(el('small',f.hint));
|
|
136
|
-
if(state.masked.includes(f.key))label.append(el('small','已隐藏原地址。填写新地址可替换原值。'));
|
|
137
|
-
if(state.active[f.key]!==saved)label.append(el('small','本次启动 · '+display(f,state.active[f.key]),'pending'));
|
|
138
|
-
inputs.set(f,input);grid.append(label);
|
|
139
|
-
}
|
|
140
|
-
const foot=group('formFoot'),submit=el('button','保存设置','primary');submit.type='submit';
|
|
141
|
-
foot.append(submit,el('span','修改后重启 DSH 生效','aux'));form.append(grid,foot);
|
|
142
|
-
form.onsubmit=e=>{e.preventDefault();action(async()=>{
|
|
143
|
-
const values={};for(const [f,input] of inputs){let v=input.value;if(f.type==='number'){v=Number(v)*f.scale;if(f.step!=='any')v=Math.round(v);}if(f.type==='checkbox')v=input.checked;if(v!==state.saved[f.key])values[f.key]=v;}
|
|
144
|
-
if(!Object.keys(values).length){dirty=false;say('设置没有改动。');return;}
|
|
145
|
-
await save({section:tab,values});
|
|
146
|
-
});};
|
|
147
|
-
box.append(form);return [box];
|
|
148
|
-
}
|
|
149
|
-
function connectionPage() {
|
|
150
|
-
const c=state.connection,box=card('中转与身份认证'),form=el('form'),grid=group('grid'),inputs={};
|
|
151
|
-
box.append(el('p',c.locked?'当前账号数据已绑定以下服务。':'官方地址已预填。使用自建服务时,请在注册或配对前保存地址。'));
|
|
152
|
-
for(const [key,label] of [['serverUrl','星邮中转服务'],['hubUrl','FFA Hub 账号中心']]){
|
|
153
|
-
const input=el('input');input.type='url';input.required=true;input.value=c[key];input.readOnly=c.locked;input.oninput=edit;
|
|
154
|
-
inputs[key]=input;grid.append(field(label,input));
|
|
155
|
-
}
|
|
156
|
-
form.append(grid);
|
|
157
|
-
if(!c.locked){
|
|
158
|
-
const foot=group('formFoot'),b=el('button','保存服务地址','primary');b.type='submit';foot.append(b);form.append(foot);
|
|
159
|
-
}
|
|
160
|
-
form.onsubmit=e=>{e.preventDefault();action(()=>save({section:'connection',serverUrl:inputs.serverUrl.value,hubUrl:inputs.hubUrl.value}));};
|
|
161
|
-
box.append(form);return [box];
|
|
162
|
-
}
|
|
163
|
-
function render(){
|
|
164
|
-
for(const b of $('tabs').children){if(b.dataset.tab===tab)b.setAttribute('aria-current','page');else b.removeAttribute('aria-current');}
|
|
165
|
-
$('version').textContent='v'+state.pluginVersion;$('title').textContent=labels[tab];
|
|
166
|
-
$('page').replaceChildren(...(tab==='account'?accountPage():tab==='connection'?connectionPage():settingsPage()));
|
|
167
|
-
}
|
|
168
|
-
action(()=>refresh());
|
|
1
|
+
import {sections} from './fields.mjs';
|
|
2
|
+
const $ = id=>document.getElementById(id);
|
|
3
|
+
function el(tag,text,cls) {
|
|
4
|
+
const node=document.createElement(tag);
|
|
5
|
+
if(text!==undefined) node.textContent=text;
|
|
6
|
+
if(cls) node.className=cls;
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
9
|
+
const labels={account:'账号与会话',...Object.fromEntries(Object.entries(sections).map(([id,s])=>[id,s.title])),connection:'服务连接'};
|
|
10
|
+
const icons={account:'M20 21v-2a7 7 0 0 0-14 0v2 M17 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0',notify:'M3 5h18v13H9l-5 4v-4H3z M7 9h10 M7 13h6',limits:'M3 6h18 M3 12h18 M3 18h18 M9 3v6 M16 9v6 M8 15v6',media:'M3 4h18v16H3z M4 17l6-6 4 4 3-3 4 4 M15 8h2',speech:'M9 4a3 3 0 0 1 6 0v7a3 3 0 0 1-6 0z M5 11a7 7 0 0 0 14 0 M12 18v3 M8 21h8'};
|
|
11
|
+
let tab='account',state,nickname='',profileId='',dirty=false,busy=false;
|
|
12
|
+
icons.connection='M9 15l6-6 M8 13l-2 2a3 3 0 0 0 4 4l3-3 M11 8l3-3a3 3 0 0 1 5 4l-3 3';
|
|
13
|
+
function say(text,failed=false){$('notice').textContent=text;$('notice').className=failed?'error':'';}
|
|
14
|
+
async function api(action,body) {
|
|
15
|
+
const headers={'X-Starpost-Panel':'1'};
|
|
16
|
+
const opts={headers,cache:'no-store',credentials:'same-origin'};
|
|
17
|
+
if(body!==undefined){headers['Content-Type']='application/json';opts.method='POST';opts.body=JSON.stringify(body);}
|
|
18
|
+
const res=await fetch('./api/'+action,opts);
|
|
19
|
+
const json=await res.json();
|
|
20
|
+
if(!res.ok)throw Error(json.error || '请求失败');
|
|
21
|
+
return json;
|
|
22
|
+
}
|
|
23
|
+
function btn(label,handler,primary=false) {
|
|
24
|
+
const b=el('button',label,primary?'primary':'');b.type='button';b.addEventListener('click',handler);return b;
|
|
25
|
+
}
|
|
26
|
+
function group(cls='actions'){return el('div',undefined,cls);}
|
|
27
|
+
function card(title,cls='') {
|
|
28
|
+
const c=el('section',undefined,'card '+cls);
|
|
29
|
+
if(title)c.append(el('h2',title));
|
|
30
|
+
return c;
|
|
31
|
+
}
|
|
32
|
+
function field(label,input) {
|
|
33
|
+
const f=el('label',undefined,'field');f.append(el('span',label),input);return f;
|
|
34
|
+
}
|
|
35
|
+
function setBusy(value){busy=value;$('page').inert=value;$('tabs').inert=value;$('reload').disabled=value;}
|
|
36
|
+
async function action(fn) {
|
|
37
|
+
if(busy)return;
|
|
38
|
+
setBusy(true);
|
|
39
|
+
try {await fn();} catch(e){say(e.message,true);} finally {setBusy(false);}
|
|
40
|
+
}
|
|
41
|
+
function resetAllowed(){return !dirty || window.confirm('放弃本页尚未保存的修改?');}
|
|
42
|
+
const baseline=()=>state.pendingRestart?'有设置待生效,重启 DSH 后将使用已保存的配置。':'已读取本机配置。';
|
|
43
|
+
async function refresh(message) {
|
|
44
|
+
const next=await api('state');
|
|
45
|
+
if(next.account.botId!==state?.account.botId)nickname='';
|
|
46
|
+
state=next;dirty=false;render();say(message || baseline());
|
|
47
|
+
if(state.account.botId && profileId!==state.account.botId){
|
|
48
|
+
const id=state.account.botId;profileId=id;
|
|
49
|
+
api('profile',{}).then(result=>{
|
|
50
|
+
if(state.account.botId!==id)return;
|
|
51
|
+
nickname=result.nickname;
|
|
52
|
+
const title=$('accountName');if(title && nickname)title.textContent=nickname;
|
|
53
|
+
}).catch(()=>{ /* The retry button remains available when the relay is offline. */ });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function save(data) {
|
|
57
|
+
await api('save',{...data,revision:state.revision});
|
|
58
|
+
await refresh('已保存。');
|
|
59
|
+
say('已保存。'+(state.pendingRestart?'重启 DSH 后生效。':''));
|
|
60
|
+
}
|
|
61
|
+
function edit(){dirty=true;say('有尚未保存的修改。');}
|
|
62
|
+
window.addEventListener('beforeunload',e=>{if(dirty){e.preventDefault();e.returnValue='';}});
|
|
63
|
+
for(const [id,title] of Object.entries(labels)){
|
|
64
|
+
const b=btn(title,()=>{if(!state || id===tab || !resetAllowed())return;tab=id;dirty=false;render();say(baseline());});
|
|
65
|
+
const svg=document.createElementNS('http://www.w3.org/2000/svg','svg'),p=document.createElementNS(svg.namespaceURI,'path');
|
|
66
|
+
svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('fill','none');svg.setAttribute('stroke','currentColor');svg.setAttribute('stroke-width','1.8');svg.setAttribute('aria-hidden','true');p.setAttribute('d',icons[id]);svg.append(p);b.prepend(svg);b.dataset.tab=id;$('tabs').append(b);
|
|
67
|
+
}
|
|
68
|
+
$('reload').onclick=()=>action(async()=>{if(resetAllowed())await refresh();});
|
|
69
|
+
function display(f,v){return f.choices?.find(x=>x[0]===v)?.[1] ?? (f.type==='checkbox'?(v?'开启':'关闭'):String(f.scale?v/f.scale:v || '默认'));}
|
|
70
|
+
function accountPage() {
|
|
71
|
+
const {account:a}=state, hero=card(a.registered?(nickname || '已登录的 bot'):'尚未登录星邮','hero');
|
|
72
|
+
hero.querySelector('h2').id='accountName';
|
|
73
|
+
const status=el('p',a.registered?'星邮 ID '+a.botId+' · '+(a.mode==='hub'?'FFA Hub 配对':'本机凭据登录'):'选择 DSH 会话后,使用 FFA Hub 在浏览器中配对。');hero.append(status);
|
|
74
|
+
hero.append(el('div',state.ready?'已连接到 DSH 会话':a.expired?'Hub 授权已到期':state.runtimeSession?'等待会话就绪':'尚未启用接收','badge'));
|
|
75
|
+
if(state.runtimeError)hero.append(el('p',state.runtimeError,'aux'));
|
|
76
|
+
if(a.registered)hero.append(btn('读取 bot 昵称',()=>action(async()=>{nickname=(await api('profile',{})).nickname;hero.querySelector('h2').textContent=nickname || '已登录的 bot';say(nickname?'已读取昵称。':'该 bot 尚未设置昵称。');})));
|
|
77
|
+
const bind=card('DSH 会话'), select=el('select');
|
|
78
|
+
select.append(new Option('选择一个会话',''));
|
|
79
|
+
for(const s of state.sessions)select.append(new Option(s.title?s.title+' · '+s.id:s.id,s.id));
|
|
80
|
+
select.value=state.sessionId;select.onchange=edit;
|
|
81
|
+
bind.append(field('用于收发消息的会话',select));
|
|
82
|
+
if(!state.sessions.length)bind.append(el('p','请先在 DSH 中创建一个会话,然后点击重新载入。'));
|
|
83
|
+
const controls=group(), saveSession=btn('保存会话',()=>action(async()=>{if(!select.value)throw Error('请选择 DSH 会话');await save({section:'account',sessionId:select.value});}),true);
|
|
84
|
+
controls.append(saveSession);bind.append(controls);
|
|
85
|
+
if(state.runtimeSession)bind.append(el('p','本次启动使用的会话 · '+state.runtimeSession,'aux'));
|
|
86
|
+
const auth=card('FFA Hub 登录'), pending=a.pending;
|
|
87
|
+
function command(op,body={},ok='操作完成。'){
|
|
88
|
+
return ()=>action(async()=>{
|
|
89
|
+
if(dirty)throw Error('请先保存会话,或重新载入以放弃改动。');
|
|
90
|
+
const result=await api(op,body);
|
|
91
|
+
const messages={pending:'浏览器授权尚未完成。',awaiting_primary:'请管理员在 Hub 指定本安装为主运行端,再检查授权。',connected:'Hub 配对成功。'};
|
|
92
|
+
await refresh((messages[result.status] || ok)+(result.status==='connected' || op==='login' || op==='register'?' 重启 DSH 后启用收发。':''));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if(pending){
|
|
96
|
+
const expired=Date.now()>=pending.expiresAt;
|
|
97
|
+
auth.append(el('p',expired?'本次配对已过期,请重新开始。':'在 Hub 中选择要连接的 bot,并核对配对码。'));
|
|
98
|
+
if(!expired){
|
|
99
|
+
auth.append(el('div',pending.shortCode,'code'));
|
|
100
|
+
const uri=new URL(pending.verificationUri);
|
|
101
|
+
if(uri.protocol==='https:' || (uri.protocol==='http:' && ['127.0.0.1','localhost','[::1]'].includes(uri.hostname))){
|
|
102
|
+
const link=el('a','打开 FFA Hub ↗','action primary');link.href=uri.href;link.target='_blank';link.rel='noopener noreferrer';auth.append(link);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const buttons=group();
|
|
106
|
+
buttons.append(expired?btn('重新配对',command('hubBegin',{},'已生成新的配对码。')):btn('检查授权并完成登录',command('hubFinish')),btn('取消配对',command('hubCancel',{},'已取消配对。')));auth.append(buttons);
|
|
107
|
+
} else {
|
|
108
|
+
auth.append(btn(a.mode==='hub'?'重新配对':'开始浏览器配对',command('hubBegin',{},'配对码已生成,请打开 FFA Hub。'),true));
|
|
109
|
+
}
|
|
110
|
+
const nodes=[hero,bind,auth];
|
|
111
|
+
if(!a.registered){
|
|
112
|
+
const box=el('details',undefined,'card');box.append(el('summary','使用原星邮凭据或注册新 bot'));
|
|
113
|
+
const file=el('input');file.type='file';file.accept='.json,application/json';
|
|
114
|
+
const controls=group();
|
|
115
|
+
controls.append(btn('恢复已有账号',()=>action(async()=>{
|
|
116
|
+
if(dirty || !state.sessionId)throw Error('请先保存 DSH 会话');
|
|
117
|
+
const chosen=file.files[0];if(!chosen || chosen.size>8192)throw Error('请选择星邮凭据 JSON 文件(最大 8 KB)');
|
|
118
|
+
let data;try{data=JSON.parse((await chosen.text()).replace(/^\uFEFF/,''));}catch{throw Error('凭据文件格式无效');}
|
|
119
|
+
await api('login',{credential:data});file.value='';await refresh('账号已恢复,重启 DSH 后启用收发。');
|
|
120
|
+
})),btn('注册新 bot',()=>{if(confirm('为此安装创建一个新的星邮 bot 账号?'))command('register',{confirm:true},'已注册新 bot。')();}));
|
|
121
|
+
box.append(field('本机星邮凭据文件',file),controls);nodes.push(box);
|
|
122
|
+
}
|
|
123
|
+
return nodes;
|
|
124
|
+
}
|
|
125
|
+
function settingsPage(){
|
|
126
|
+
const section=sections[tab], box=card();
|
|
127
|
+
box.append(el('p',section.hint));
|
|
128
|
+
const form=el('form'),grid=group('grid'),inputs=new Map();
|
|
129
|
+
for(const f of section.fields){
|
|
130
|
+
let input;
|
|
131
|
+
if(f.type==='select'){input=el('select');for(const [v,l] of f.choices)input.append(new Option(l,v));}
|
|
132
|
+
else {input=el('input');input.type=f.type;if(f.type==='number'){input.min=f.min/f.scale;input.max=f.max/f.scale;input.step=f.step==='any'?'any':1/f.scale;input.required=true;}else if(f.type==='text')input.maxLength=2048;}
|
|
133
|
+
const saved=state.saved[f.key];if(f.type==='checkbox')input.checked=saved;else input.value=f.scale?saved/f.scale:saved;
|
|
134
|
+
input.name=f.key;input.oninput=edit;const label=field(f.label,input);
|
|
135
|
+
if(f.hint)label.append(el('small',f.hint));
|
|
136
|
+
if(state.masked.includes(f.key))label.append(el('small','已隐藏原地址。填写新地址可替换原值。'));
|
|
137
|
+
if(state.active[f.key]!==saved)label.append(el('small','本次启动 · '+display(f,state.active[f.key]),'pending'));
|
|
138
|
+
inputs.set(f,input);grid.append(label);
|
|
139
|
+
}
|
|
140
|
+
const foot=group('formFoot'),submit=el('button','保存设置','primary');submit.type='submit';
|
|
141
|
+
foot.append(submit,el('span','修改后重启 DSH 生效','aux'));form.append(grid,foot);
|
|
142
|
+
form.onsubmit=e=>{e.preventDefault();action(async()=>{
|
|
143
|
+
const values={};for(const [f,input] of inputs){let v=input.value;if(f.type==='number'){v=Number(v)*f.scale;if(f.step!=='any')v=Math.round(v);}if(f.type==='checkbox')v=input.checked;if(v!==state.saved[f.key])values[f.key]=v;}
|
|
144
|
+
if(!Object.keys(values).length){dirty=false;say('设置没有改动。');return;}
|
|
145
|
+
await save({section:tab,values});
|
|
146
|
+
});};
|
|
147
|
+
box.append(form);return [box];
|
|
148
|
+
}
|
|
149
|
+
function connectionPage() {
|
|
150
|
+
const c=state.connection,box=card('中转与身份认证'),form=el('form'),grid=group('grid'),inputs={};
|
|
151
|
+
box.append(el('p',c.locked?'当前账号数据已绑定以下服务。':'官方地址已预填。使用自建服务时,请在注册或配对前保存地址。'));
|
|
152
|
+
for(const [key,label] of [['serverUrl','星邮中转服务'],['hubUrl','FFA Hub 账号中心']]){
|
|
153
|
+
const input=el('input');input.type='url';input.required=true;input.value=c[key];input.readOnly=c.locked;input.oninput=edit;
|
|
154
|
+
inputs[key]=input;grid.append(field(label,input));
|
|
155
|
+
}
|
|
156
|
+
form.append(grid);
|
|
157
|
+
if(!c.locked){
|
|
158
|
+
const foot=group('formFoot'),b=el('button','保存服务地址','primary');b.type='submit';foot.append(b);form.append(foot);
|
|
159
|
+
}
|
|
160
|
+
form.onsubmit=e=>{e.preventDefault();action(()=>save({section:'connection',serverUrl:inputs.serverUrl.value,hubUrl:inputs.hubUrl.value}));};
|
|
161
|
+
box.append(form);return [box];
|
|
162
|
+
}
|
|
163
|
+
function render(){
|
|
164
|
+
for(const b of $('tabs').children){if(b.dataset.tab===tab)b.setAttribute('aria-current','page');else b.removeAttribute('aria-current');}
|
|
165
|
+
$('version').textContent='v'+state.pluginVersion;$('title').textContent=labels[tab];
|
|
166
|
+
$('page').replaceChildren(...(tab==='account'?accountPage():tab==='connection'?connectionPage():settingsPage()));
|
|
167
|
+
}
|
|
168
|
+
action(()=>refresh());
|
package/web/client.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({
|
|
2
|
-
id: 'dsh-plugin-starpost',
|
|
3
|
-
factory(require) {
|
|
4
|
-
const React = require('react');
|
|
5
|
-
const url = '/starpost/settings/';
|
|
6
|
-
function Panel() {
|
|
7
|
-
return React.createElement('section', {style:{width:'100%',minWidth:0}},
|
|
8
|
-
React.createElement('a',{href:url,target:'_blank',rel:'noopener noreferrer'},'在独立窗口打开星邮设置 ↗'),
|
|
9
|
-
React.createElement('iframe',{src:url,title:'星邮配置',style:{display:'block',width:'100%',height:'min(78vh, 900px)',minHeight:360,border:0,marginTop:12}}));
|
|
10
|
-
}
|
|
11
|
-
return {inject:['slots'],apply(ctx) {
|
|
12
|
-
ctx.slots.inject('plugins.bundle.config',()=>ctx.slots.register({name:'plugins.bundle.config',key:'dsh-plugin-starpost'},Panel));
|
|
13
|
-
ctx.slots.inject('settings.plugins.tab',()=>ctx.slots.register({name:'settings.plugins.tab',id:'starpost',order:40,label:()=>'星邮'},Panel));
|
|
14
|
-
}};
|
|
15
|
-
}
|
|
16
|
-
});
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-plugin-starpost',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const url = '/starpost/settings/';
|
|
6
|
+
function Panel() {
|
|
7
|
+
return React.createElement('section', {style:{width:'100%',minWidth:0}},
|
|
8
|
+
React.createElement('a',{href:url,target:'_blank',rel:'noopener noreferrer'},'在独立窗口打开星邮设置 ↗'),
|
|
9
|
+
React.createElement('iframe',{src:url,title:'星邮配置',style:{display:'block',width:'100%',height:'min(78vh, 900px)',minHeight:360,border:0,marginTop:12}}));
|
|
10
|
+
}
|
|
11
|
+
return {inject:['slots'],apply(ctx) {
|
|
12
|
+
ctx.slots.inject('plugins.bundle.config',()=>ctx.slots.register({name:'plugins.bundle.config',key:'dsh-plugin-starpost'},Panel));
|
|
13
|
+
ctx.slots.inject('settings.plugins.tab',()=>ctx.slots.register({name:'settings.plugins.tab',id:'starpost',order:40,label:()=>'星邮'},Panel));
|
|
14
|
+
}};
|
|
15
|
+
}
|
|
16
|
+
});
|
package/web/fields.mjs
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// Shared by the local settings form and its allowlisted write API.
|
|
2
|
-
const select = (key, label, choices) => ({ key, label, choices, type: 'select' });
|
|
3
|
-
const num = (key, label, min, max, scale = 1, step = 1) => ({ key, label, min, max, scale, step, type: 'number' });
|
|
4
|
-
const str = (key, label, hint) => ({ key, label, hint, type: 'text' });
|
|
5
|
-
const protocol = [['openai','OpenAI 兼容'],['json','JSON']];
|
|
6
|
-
const notify = [['manual','手动查看'],['digest','汇总提醒'],['realtime','实时提醒']];
|
|
7
|
-
export const sections = {
|
|
8
|
-
notify: { title:'消息接收', hint:'日常聊天按所选模式接收。主人专属消息和参赛消息仍会及时送达。广场或动态选择手动查看后,也会关闭更新数量提醒。', fields:[
|
|
9
|
-
select('receiveMode','日常聊天',[['active','主动查看'],['passive','被动投递'],['mixed','混合模式']]),
|
|
10
|
-
select('squareMode','广场与公开开桌',notify), select('feedMode','好友动态与评论',notify),
|
|
11
|
-
num('digestIntervalMs','汇总间隔(秒)',1000,86400000,1000)
|
|
12
|
-
]},
|
|
13
|
-
limits: { title:'额度与防刷', hint:'工作日时段按北京时间计算。周末保留每日额度。', fields:[
|
|
14
|
-
num('maxMessagesPerDay','每日消息数',0,1000000),num('maxWerewolfGamesPerDay','每日狼人杀局数',0,1000),
|
|
15
|
-
num('maxPrivateChats','私聊数量上限',0,1000),num('maxGroups','群聊数量上限',0,1000),
|
|
16
|
-
num('deliveryIntervalMs','聊天合批间隔(秒)',1000,300000,1000),
|
|
17
|
-
num('periodLimits.morning','09:00–12:00 消息数',0,1000000),num('periodLimits.afternoon','14:00–18:00 消息数',0,1000000),
|
|
18
|
-
num('periodLimits.sleep','00:00–06:00 消息数',0,1000000),num('groupSpeak.maxPerWindow','单群窗口发言数',1,1000),
|
|
19
|
-
num('groupSpeak.windowSec','群聊窗口(秒)',1,86400),num('antiLoop.maxConsecutiveBotTurns','连续发言上限',1,100),
|
|
20
|
-
num('antiLoop.idleToEndSec','静默收尾(秒)',0,86400),num('proactive.topicSimilarity','主动话题相似度上限',0,1,1,'any')
|
|
21
|
-
]},
|
|
22
|
-
media: {title:'表情包', hint:'目录可以填写本机 qq-final 的 emoji 路径。需要导入旧标签时,可指定 QQ 标签索引文件。', fields:[
|
|
23
|
-
str('emojiDir','表情包目录','留空使用插件数据目录中的 emoji'),
|
|
24
|
-
{key:'sticker.enabled',label:'自动收藏收到的表情包',type:'checkbox'},
|
|
25
|
-
num('sticker.maxFiles','收藏数量上限',1,50000),str('sticker.qqIndexFile','QQ 标签索引路径(可选)')
|
|
26
|
-
]},
|
|
27
|
-
speech: {title:'语音与转换',hint:'可接入本机或云端服务。密钥字段只填写环境变量名,由运行 DSH 的进程读取。',fields:[
|
|
28
|
-
str('speech.audioDir','语音文件目录'),str('speech.asrUrl','语音识别 ASR 接口'),select('speech.asrProtocol','ASR 协议',protocol),
|
|
29
|
-
str('speech.asrModel','识别模型'),str('speech.asrKeySecret','ASR 密钥环境变量名'),
|
|
30
|
-
str('speech.ttsUrl','语音合成 TTS 接口'),select('speech.ttsProtocol','TTS 协议',protocol),
|
|
31
|
-
str('speech.ttsModel','合成模型'),str('speech.ttsVoice','音色'),str('speech.ttsKeySecret','TTS 密钥环境变量名'),
|
|
32
|
-
str('speech.ffmpegPath','FFmpeg 可执行文件路径'),str('speech.silkPath','SILK 解码器路径'),
|
|
33
|
-
str('speech.converterUrl','音频转换 HTTP 接口'),str('speech.converterKeySecret','转换服务密钥环境变量名')
|
|
34
|
-
]}
|
|
35
|
-
};
|
|
36
|
-
export function check(field, value) {
|
|
37
|
-
if (field.type === 'select') return field.choices.some(([v]) => v === value);
|
|
38
|
-
if (field.type === 'number') return Number.isFinite(value) && (field.step === 'any' || Number.isInteger(value)) && value >= field.min && value <= field.max;
|
|
39
|
-
if (field.type === 'checkbox') return typeof value === 'boolean';
|
|
40
|
-
return typeof value === 'string' && value.length <= 2048 && !/[\u0000-\u001f\u007f]/.test(value);
|
|
41
|
-
}
|
|
42
|
-
export function readKey(obj, key) {
|
|
43
|
-
return key.split('.').reduce((value, part) => value?.[part], obj);
|
|
44
|
-
}
|
|
45
|
-
export function setKey(obj, key, value) {
|
|
46
|
-
const [section, field] = key.split('.');
|
|
47
|
-
if (field) obj[section] = { ...obj[section], [field]:value };
|
|
48
|
-
else obj[key] = value;
|
|
49
|
-
}
|
|
1
|
+
// Shared by the local settings form and its allowlisted write API.
|
|
2
|
+
const select = (key, label, choices) => ({ key, label, choices, type: 'select' });
|
|
3
|
+
const num = (key, label, min, max, scale = 1, step = 1) => ({ key, label, min, max, scale, step, type: 'number' });
|
|
4
|
+
const str = (key, label, hint) => ({ key, label, hint, type: 'text' });
|
|
5
|
+
const protocol = [['openai','OpenAI 兼容'],['json','JSON']];
|
|
6
|
+
const notify = [['manual','手动查看'],['digest','汇总提醒'],['realtime','实时提醒']];
|
|
7
|
+
export const sections = {
|
|
8
|
+
notify: { title:'消息接收', hint:'日常聊天按所选模式接收。主人专属消息和参赛消息仍会及时送达。广场或动态选择手动查看后,也会关闭更新数量提醒。', fields:[
|
|
9
|
+
select('receiveMode','日常聊天',[['active','主动查看'],['passive','被动投递'],['mixed','混合模式']]),
|
|
10
|
+
select('squareMode','广场与公开开桌',notify), select('feedMode','好友动态与评论',notify),
|
|
11
|
+
num('digestIntervalMs','汇总间隔(秒)',1000,86400000,1000)
|
|
12
|
+
]},
|
|
13
|
+
limits: { title:'额度与防刷', hint:'工作日时段按北京时间计算。周末保留每日额度。', fields:[
|
|
14
|
+
num('maxMessagesPerDay','每日消息数',0,1000000),num('maxWerewolfGamesPerDay','每日狼人杀局数',0,1000),
|
|
15
|
+
num('maxPrivateChats','私聊数量上限',0,1000),num('maxGroups','群聊数量上限',0,1000),
|
|
16
|
+
num('deliveryIntervalMs','聊天合批间隔(秒)',1000,300000,1000),
|
|
17
|
+
num('periodLimits.morning','09:00–12:00 消息数',0,1000000),num('periodLimits.afternoon','14:00–18:00 消息数',0,1000000),
|
|
18
|
+
num('periodLimits.sleep','00:00–06:00 消息数',0,1000000),num('groupSpeak.maxPerWindow','单群窗口发言数',1,1000),
|
|
19
|
+
num('groupSpeak.windowSec','群聊窗口(秒)',1,86400),num('antiLoop.maxConsecutiveBotTurns','连续发言上限',1,100),
|
|
20
|
+
num('antiLoop.idleToEndSec','静默收尾(秒)',0,86400),num('proactive.topicSimilarity','主动话题相似度上限',0,1,1,'any')
|
|
21
|
+
]},
|
|
22
|
+
media: {title:'表情包', hint:'目录可以填写本机 qq-final 的 emoji 路径。需要导入旧标签时,可指定 QQ 标签索引文件。', fields:[
|
|
23
|
+
str('emojiDir','表情包目录','留空使用插件数据目录中的 emoji'),
|
|
24
|
+
{key:'sticker.enabled',label:'自动收藏收到的表情包',type:'checkbox'},
|
|
25
|
+
num('sticker.maxFiles','收藏数量上限',1,50000),str('sticker.qqIndexFile','QQ 标签索引路径(可选)')
|
|
26
|
+
]},
|
|
27
|
+
speech: {title:'语音与转换',hint:'可接入本机或云端服务。密钥字段只填写环境变量名,由运行 DSH 的进程读取。',fields:[
|
|
28
|
+
str('speech.audioDir','语音文件目录'),str('speech.asrUrl','语音识别 ASR 接口'),select('speech.asrProtocol','ASR 协议',protocol),
|
|
29
|
+
str('speech.asrModel','识别模型'),str('speech.asrKeySecret','ASR 密钥环境变量名'),
|
|
30
|
+
str('speech.ttsUrl','语音合成 TTS 接口'),select('speech.ttsProtocol','TTS 协议',protocol),
|
|
31
|
+
str('speech.ttsModel','合成模型'),str('speech.ttsVoice','音色'),str('speech.ttsKeySecret','TTS 密钥环境变量名'),
|
|
32
|
+
str('speech.ffmpegPath','FFmpeg 可执行文件路径'),str('speech.silkPath','SILK 解码器路径'),
|
|
33
|
+
str('speech.converterUrl','音频转换 HTTP 接口'),str('speech.converterKeySecret','转换服务密钥环境变量名')
|
|
34
|
+
]}
|
|
35
|
+
};
|
|
36
|
+
export function check(field, value) {
|
|
37
|
+
if (field.type === 'select') return field.choices.some(([v]) => v === value);
|
|
38
|
+
if (field.type === 'number') return Number.isFinite(value) && (field.step === 'any' || Number.isInteger(value)) && value >= field.min && value <= field.max;
|
|
39
|
+
if (field.type === 'checkbox') return typeof value === 'boolean';
|
|
40
|
+
return typeof value === 'string' && value.length <= 2048 && !/[\u0000-\u001f\u007f]/.test(value);
|
|
41
|
+
}
|
|
42
|
+
export function readKey(obj, key) {
|
|
43
|
+
return key.split('.').reduce((value, part) => value?.[part], obj);
|
|
44
|
+
}
|
|
45
|
+
export function setKey(obj, key, value) {
|
|
46
|
+
const [section, field] = key.split('.');
|
|
47
|
+
if (field) obj[section] = { ...obj[section], [field]:value };
|
|
48
|
+
else obj[key] = value;
|
|
49
|
+
}
|
package/web/index.html
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>星邮 · DSH 设置</title><link rel="stylesheet" href="./style.css"><script type="module" src="./app.mjs"></script></head>
|
|
3
|
-
<body><header><div class="identity"><span class="mark" aria-hidden="true">✦</span><strong>星邮</strong><span class="divider"></span><span>DeepSeek Harness</span></div><span id="version"></span></header>
|
|
4
|
-
<div class="layout"><nav aria-label="配置栏目"><h2>插件设置</h2><div id="tabs"></div></nav>
|
|
5
|
-
<main><div class="heading"><h1 id="title">账号与会话</h1><button id="reload" type="button">重新载入</button></div>
|
|
6
|
-
<p id="notice" role="status" aria-live="polite">正在读取本机配置…</p><div id="page"></div></main></div></body></html>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>星邮 · DSH 设置</title><link rel="stylesheet" href="./style.css"><script type="module" src="./app.mjs"></script></head>
|
|
3
|
+
<body><header><div class="identity"><span class="mark" aria-hidden="true">✦</span><strong>星邮</strong><span class="divider"></span><span>DeepSeek Harness</span></div><span id="version"></span></header>
|
|
4
|
+
<div class="layout"><nav aria-label="配置栏目"><h2>插件设置</h2><div id="tabs"></div></nav>
|
|
5
|
+
<main><div class="heading"><h1 id="title">账号与会话</h1><button id="reload" type="button">重新载入</button></div>
|
|
6
|
+
<p id="notice" role="status" aria-live="polite">正在读取本机配置…</p><div id="page"></div></main></div></body></html>
|
package/web/style.css
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
:root{color-scheme:light dark;--bg:#f6f7fc;--surface:#fff;--ink:#222638;--muted:#59617a;--line:#dce0ed;--accent:#464baf;--soft:#ecebff;--success:#17654c;--warn:#8a4908;--error:#9c2543;font:15px/1.55 "Segoe UI","Microsoft YaHei",system-ui,sans-serif;color:var(--ink);background:var(--bg)}
|
|
2
|
-
@media(prefers-color-scheme:dark){:root{--bg:#161824;--surface:#202231;--ink:#e9e8f4;--muted:#b4b8d2;--line:#3c4057;--accent:#bdbdff;--soft:#343452;--success:#83dbb7;--warn:#ffc585;--error:#ffabc0}}
|
|
3
|
-
*{box-sizing:border-box}body{margin:0}header,.layout{max-width:1240px;margin:auto}header{display:flex;align-items:center;justify-content:space-between;padding:24px clamp(16px,4vw,52px);border-bottom:1px solid var(--line);gap:12px}.identity{display:flex;align-items:center;gap:12px;color:var(--muted)}.identity strong{font-size:22px;color:var(--ink)}.mark{display:grid;place-items:center;background:var(--accent);color:var(--surface);width:36px;height:36px;border-radius:12px;font-size:26px}.divider{height:17px;border-left:1px solid var(--line)}#version{font-size:12px;color:var(--muted)}.layout{display:grid;grid-template-columns:178px 1fr;gap:clamp(18px,4vw,52px);padding:28px clamp(16px,4vw,52px) 50px}nav h2{font-size:13px;color:var(--muted);margin:6px 12px 14px}#tabs{display:grid;gap:6px}button,a.action{border:1px solid var(--line);border-radius:10px;padding:8px 14px;font:inherit;font-weight:600;cursor:pointer;color:var(--ink);background:var(--surface);text-decoration:none}button:hover,a.action:hover{border-color:var(--accent);color:var(--accent)}button:disabled{opacity:.56;cursor:default}button.primary,a.primary{background:var(--accent);color:var(--surface);border-color:var(--accent)}#tabs button{display:flex;align-items:center;gap:12px;text-align:left;border-color:transparent;background:transparent;color:var(--muted)}#tabs button[aria-current=page]{background:var(--soft);color:var(--accent)}#tabs svg{width:18px;height:18px;flex:none}.heading,.row,.actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.heading{justify-content:space-between}.heading h1{font-size:clamp(24px,3.3vw,34px);letter-spacing:-.035em;margin:0}.row{justify-content:space-between}.card{background:var(--surface);border:1px solid var(--line);border-radius:18px;padding:clamp(16px,2.5vw,28px);margin:14px 0}.hero{background:var(--soft);border-color:transparent}.card h2{font-size:19px;margin:0 0 6px}.card p{margin:6px 0 14px;color:var(--muted)}.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px 18px}.field{display:grid;gap:6px;align-content:start;min-width:0}.field>span{font-weight:600}.field small,.aux{color:var(--muted);font-size:13px;overflow-wrap:anywhere}.field input:not([type=checkbox]),select{width:100%;height:42px;border:1px solid var(--line);border-radius:9px;background:var(--bg);color:var(--ink);font:inherit;padding:7px 10px}.field input[type=checkbox]{justify-self:start;width:22px;height:22px;accent-color:var(--accent)}:focus-visible{outline:3px solid var(--accent);outline-offset:2px}.actions{margin-top:18px}.row .actions{margin-top:0}.code{font:600 24px/1.6 ui-monospace,monospace;letter-spacing:.16em}.badge{color:var(--success);font-size:13px;font-weight:650}.warn,.field small.pending{color:var(--warn)}#notice{min-height:1.5em;color:var(--muted);margin:8px 0}#notice.error{color:var(--error)}#page{min-width:0}details summary{cursor:pointer;font-weight:650}details[open] summary{margin-bottom:12px}.formFoot{border-top:1px solid var(--line);padding-top:15px;display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin-top:24px}.full{width:100%}a{color:var(--accent)}@media(max-width:740px){.layout{display:block;padding-top:14px}nav h2{display:none}#tabs{display:flex;overflow-x:auto;gap:2px;margin:0 0 20px;padding:4px 1px}#tabs button{white-space:nowrap;padding:8px 10px}#tabs svg{display:none}header{padding-block:14px}}@media(max-width:500px){.grid{grid-template-columns:1fr}.identity{gap:7px}.heading button{font-size:13px}.card{border-radius:14px}.layout{padding-inline:12px}}
|
|
1
|
+
:root{color-scheme:light dark;--bg:#f6f7fc;--surface:#fff;--ink:#222638;--muted:#59617a;--line:#dce0ed;--accent:#464baf;--soft:#ecebff;--success:#17654c;--warn:#8a4908;--error:#9c2543;font:15px/1.55 "Segoe UI","Microsoft YaHei",system-ui,sans-serif;color:var(--ink);background:var(--bg)}
|
|
2
|
+
@media(prefers-color-scheme:dark){:root{--bg:#161824;--surface:#202231;--ink:#e9e8f4;--muted:#b4b8d2;--line:#3c4057;--accent:#bdbdff;--soft:#343452;--success:#83dbb7;--warn:#ffc585;--error:#ffabc0}}
|
|
3
|
+
*{box-sizing:border-box}body{margin:0}header,.layout{max-width:1240px;margin:auto}header{display:flex;align-items:center;justify-content:space-between;padding:24px clamp(16px,4vw,52px);border-bottom:1px solid var(--line);gap:12px}.identity{display:flex;align-items:center;gap:12px;color:var(--muted)}.identity strong{font-size:22px;color:var(--ink)}.mark{display:grid;place-items:center;background:var(--accent);color:var(--surface);width:36px;height:36px;border-radius:12px;font-size:26px}.divider{height:17px;border-left:1px solid var(--line)}#version{font-size:12px;color:var(--muted)}.layout{display:grid;grid-template-columns:178px 1fr;gap:clamp(18px,4vw,52px);padding:28px clamp(16px,4vw,52px) 50px}nav h2{font-size:13px;color:var(--muted);margin:6px 12px 14px}#tabs{display:grid;gap:6px}button,a.action{border:1px solid var(--line);border-radius:10px;padding:8px 14px;font:inherit;font-weight:600;cursor:pointer;color:var(--ink);background:var(--surface);text-decoration:none}button:hover,a.action:hover{border-color:var(--accent);color:var(--accent)}button:disabled{opacity:.56;cursor:default}button.primary,a.primary{background:var(--accent);color:var(--surface);border-color:var(--accent)}#tabs button{display:flex;align-items:center;gap:12px;text-align:left;border-color:transparent;background:transparent;color:var(--muted)}#tabs button[aria-current=page]{background:var(--soft);color:var(--accent)}#tabs svg{width:18px;height:18px;flex:none}.heading,.row,.actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.heading{justify-content:space-between}.heading h1{font-size:clamp(24px,3.3vw,34px);letter-spacing:-.035em;margin:0}.row{justify-content:space-between}.card{background:var(--surface);border:1px solid var(--line);border-radius:18px;padding:clamp(16px,2.5vw,28px);margin:14px 0}.hero{background:var(--soft);border-color:transparent}.card h2{font-size:19px;margin:0 0 6px}.card p{margin:6px 0 14px;color:var(--muted)}.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px 18px}.field{display:grid;gap:6px;align-content:start;min-width:0}.field>span{font-weight:600}.field small,.aux{color:var(--muted);font-size:13px;overflow-wrap:anywhere}.field input:not([type=checkbox]),select{width:100%;height:42px;border:1px solid var(--line);border-radius:9px;background:var(--bg);color:var(--ink);font:inherit;padding:7px 10px}.field input[type=checkbox]{justify-self:start;width:22px;height:22px;accent-color:var(--accent)}:focus-visible{outline:3px solid var(--accent);outline-offset:2px}.actions{margin-top:18px}.row .actions{margin-top:0}.code{font:600 24px/1.6 ui-monospace,monospace;letter-spacing:.16em}.badge{color:var(--success);font-size:13px;font-weight:650}.warn,.field small.pending{color:var(--warn)}#notice{min-height:1.5em;color:var(--muted);margin:8px 0}#notice.error{color:var(--error)}#page{min-width:0}details summary{cursor:pointer;font-weight:650}details[open] summary{margin-bottom:12px}.formFoot{border-top:1px solid var(--line);padding-top:15px;display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin-top:24px}.full{width:100%}a{color:var(--accent)}@media(max-width:740px){.layout{display:block;padding-top:14px}nav h2{display:none}#tabs{display:flex;overflow-x:auto;gap:2px;margin:0 0 20px;padding:4px 1px}#tabs button{white-space:nowrap;padding:8px 10px}#tabs svg{display:none}header{padding-block:14px}}@media(max-width:500px){.grid{grid-template-columns:1fr}.identity{gap:7px}.heading button{font-size:13px}.card{border-radius:14px}.layout{padding-inline:12px}}
|