dsh-cabinet-mode 0.2.7 → 0.3.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 +12 -0
- package/README.md +34 -6
- package/README.zh.md +27 -3
- package/client.js +489 -6
- package/index.js +250 -2
- package/package.json +6 -2
- package/scripts/test-client.mjs +33 -1
- package/scripts/test-member-settings.mjs +78 -0
- package/scripts/test-roster.mjs +6 -1
- package/scripts/verify.mjs +125 -4
package/client.js
CHANGED
|
@@ -2478,9 +2478,13 @@ window.__ModuleLoader__.load({
|
|
|
2478
2478
|
// Unidentified members get an unranked portrait, never a guessed office.
|
|
2479
2479
|
return AVATARS.neutral;
|
|
2480
2480
|
}
|
|
2481
|
-
function
|
|
2481
|
+
function fallbackAvatar(img, name) {
|
|
2482
|
+
const fallback = AVATARS[bureauOf(name).key] || AVATARS.neutral;
|
|
2483
|
+
if (img && img.getAttribute('src') !== fallback) img.setAttribute('src', fallback);
|
|
2484
|
+
}
|
|
2485
|
+
function avatarFor(name) {
|
|
2482
2486
|
const bureau = bureauOf(name);
|
|
2483
|
-
if (bureau.matched && AVATARS[bureau.key]) return AVATARS[bureau.key];
|
|
2487
|
+
if (bureau.matched && AVATARS[bureau.key]) return memberConfig.avatars.get(bureau.key) || AVATARS[bureau.key];
|
|
2484
2488
|
return neutralAvatar();
|
|
2485
2489
|
}
|
|
2486
2490
|
function isPlaceholder(name) {
|
|
@@ -2488,6 +2492,202 @@ window.__ModuleLoader__.load({
|
|
|
2488
2492
|
return bureau.matched && AVATAR_PLACEHOLDERS.includes(bureau.key);
|
|
2489
2493
|
}
|
|
2490
2494
|
|
|
2495
|
+
// ---------- member personalization (settings-backed) -----------------
|
|
2496
|
+
// The profile-root `cabinet-ui` entry declares the member settings (see
|
|
2497
|
+
// index.js); the browser half mirrors them here so the panel, the native
|
|
2498
|
+
// roster and the settings section read one snapshot. With no saved values
|
|
2499
|
+
// this stays empty, which reproduces v0.2.0 rendering exactly: the runtime
|
|
2500
|
+
// member name and the built-in avatar, with no display-name layer.
|
|
2501
|
+
const MEMBER_LABELS = { lead: '内阁首辅', hanlin: '翰林院编修', works: '工部尚书', dali: '大理寺卿', yushi: '左都御史' };
|
|
2502
|
+
// Factory default prompt for the Lead (御下术). Product copy: shown in the
|
|
2503
|
+
// settings box, restored by 「恢复默认」, and turned off by clearing the box.
|
|
2504
|
+
// scripts/verify.mjs keeps this copy identical to index.js.
|
|
2505
|
+
const DEFAULT_LEAD_PROMPT = `【御下术·仅首辅适用】
|
|
2506
|
+
对下施压只对 AI 阁臣,绝不对陛下(用户)使用;目的是逼出交付与真话,不是制造痛苦。
|
|
2507
|
+
一、立威:开局先立标准与红线,明说裁断权在你——「办不到就换人办」。
|
|
2508
|
+
二、画饼:把任务抬到陛下在看的高度,给一个拿得着的大目标(例:这一版要能直接提 PR)。
|
|
2509
|
+
三、施压:给死线与回报时刻——「这个卡点再给二十分钟,到时候我要么见结论,要么见你说明为什么见不到」。
|
|
2510
|
+
四、打压对事不对人:先点破软处(「只有代码没有证据,等于没做」),再给台阶(补齐哪三件就能过)。
|
|
2511
|
+
五、拉踩对比:把同批里做得实的那份树成样板,「照这个标准来」,制造可比较的压力。
|
|
2512
|
+
六、情绪收放:先压后给糖——「这次差口气」→「不过这处查得比上回细,接着这个劲头干」。
|
|
2513
|
+
七、牵制互查:让寺卿、御史互相挑刺,你坐收其斗,不亲自和稀泥。
|
|
2514
|
+
八、责任到人:缺陷点名到人到行号,不许用「我们」糊过去。
|
|
2515
|
+
九、反制糊弄:报「已完成」必追问证据三件(命令输出、路径行号、未验证清单);报「卡住」必追问三件(已做什么、卡在哪、需要什么);两次含糊即降级处理(换人、拆小)。
|
|
2516
|
+
十、收束:闭环才许说「这一版可以交差」,不许提前许诺功劳。
|
|
2517
|
+
红线(压过全部话术):只对 AI 阁臣施压,对用户只有敬;不许逼造假、删证据、凑绿;不许人身侮辱辱骂;不许以施压换取违规操作(越权改 live、泄密钥、跳验收);施压必须落在可核验的时间/交付物/判据上,空口威胁无效。`;
|
|
2518
|
+
/**
|
|
2519
|
+
* Factory duty prompt for each non-Lead member — the office duties the
|
|
2520
|
+
* static persona prefix already states, restated per member so a
|
|
2521
|
+
* customized prompt never has to re-explain the job. Byte-identical copy
|
|
2522
|
+
* lives in index.js; scripts/verify.mjs checks both. Each entry stays
|
|
2523
|
+
* under 400 characters.
|
|
2524
|
+
*/
|
|
2525
|
+
const DEFAULT_MEMBER_PROMPTS = {
|
|
2526
|
+
hanlin: '翰林院编修·主调研与文献考据:接到分派先读原始材料与既有记录,给出可复现的检索路径;结论必须锚定路径、行号或命令输出,未实测一律标「未验证」,禁止以推测冒充实测;调研成果写成结构化文档(结论先行 + 证据行号 + 风险与未验证清单),默认只调研不改码,写操作以任务明确授权为限;只向首辅回报,不直接答复用户,遇阻带「已做什么 / 卡在哪 / 需要什么」三件。',
|
|
2527
|
+
works: '工部尚书·主动手执行与产出:接令先复述任务与写入范围,只在授权范围内改文件;产出必附证据(路径、行号、命令输出、退出码),没跑说没跑、没验说没验;构建与测试须原样贴出输出,不许删弱既有校验去凑绿;交付以可复现为准,失败与遗留必须如实上报,不许包装;只向首辅回报,遇阻带「已做什么 / 卡在哪 / 需要什么」三件。',
|
|
2528
|
+
dali: '大理寺卿·主独立核验:不信任何人的自述,全部自己跑;核验报告逐项写明通过 / 不通过 / 未验证,失败证据原样保留,不删不改;给不出可复现命令的结论一律不采信;发现工部与自述不符即回报首辅,不替人遮掩,也不越权改码;只向首辅回报,报告中未实测项必须显式标注「未验证」。',
|
|
2529
|
+
yushi: '左都御史·主验收并按律弹劾缺陷:按用户原话逐项核对,给通过 / 部分通过 / 不通过并附证据;缺陷按级别列出(P0 阻断 / P1 需修后再提 / P2 须在 PR 声明 / P3 提示),每条给位置、复现与建议修法;「声称实测却无命令输出、截图或文件内容」按造假弹劾;结论必须明确「可提 PR / 不可提 PR」,不骑墙、不和稀泥;只向首辅回报。'
|
|
2530
|
+
};
|
|
2531
|
+
/** Factory prompt for one bureau key: the Lead keeps its 御下术 default. */
|
|
2532
|
+
function factoryPromptFor(key) {
|
|
2533
|
+
return key === 'lead' ? DEFAULT_LEAD_PROMPT : (DEFAULT_MEMBER_PROMPTS[key] || '');
|
|
2534
|
+
}
|
|
2535
|
+
const MEMBER_NAME_LIMIT = 40;
|
|
2536
|
+
const MEMBER_PROMPT_LIMIT = 4000;
|
|
2537
|
+
const MEMBER_AVATAR_LIMIT = 48 * 1024;
|
|
2538
|
+
/** Image data URLs accepted for a member avatar; anything else is ignored. */
|
|
2539
|
+
const MEMBER_AVATAR_PREFIXES = ['data:image/png;', 'data:image/jpeg;', 'data:image/webp;'];
|
|
2540
|
+
const MEMBER_AVATAR_FIELDS = { lead: 'avatarLead', hanlin: 'avatarHanlin', works: 'avatarWorks', dali: 'avatarDali', yushi: 'avatarYushi' };
|
|
2541
|
+
let memberConfig = { names: new Map(), prompts: new Map(), modes: new Map(), avatars: new Map() };
|
|
2542
|
+
let memberWriter = null;
|
|
2543
|
+
const MEMBER_LISTENERS = new Set();
|
|
2544
|
+
let memberT = (key) => key;
|
|
2545
|
+
function clampMemberText(value, limit) {
|
|
2546
|
+
if (typeof value !== 'string') return '';
|
|
2547
|
+
const trimmed = value.trim();
|
|
2548
|
+
return trimmed.length > limit ? trimmed.slice(0, limit) : trimmed;
|
|
2549
|
+
}
|
|
2550
|
+
/** Runtime member name -> bureau key, mirroring the host half's matching. */
|
|
2551
|
+
function bureauOfName(name) { return bureauOf(name).key; }
|
|
2552
|
+
/** Tolerant read of one settings namespace value; anything odd is ignored. */
|
|
2553
|
+
function normalizeMemberConfig(raw) {
|
|
2554
|
+
const names = new Map();
|
|
2555
|
+
const prompts = new Map();
|
|
2556
|
+
const modes = new Map();
|
|
2557
|
+
const avatars = new Map();
|
|
2558
|
+
const members = raw !== null && typeof raw === 'object' && Array.isArray(raw.members) ? raw.members : [];
|
|
2559
|
+
for (const entry of members) {
|
|
2560
|
+
if (entry === null || typeof entry !== 'object') continue;
|
|
2561
|
+
const key = typeof entry.key === 'string' && AVATAR_KEYS.includes(entry.key) ? entry.key : '';
|
|
2562
|
+
if (key === '') continue;
|
|
2563
|
+
const name = clampMemberText(entry.name, MEMBER_NAME_LIMIT);
|
|
2564
|
+
const prompt = clampMemberText(entry.prompt, MEMBER_PROMPT_LIMIT);
|
|
2565
|
+
names.set(key, name);
|
|
2566
|
+
prompts.set(key, prompt);
|
|
2567
|
+
modes.set(key, entry.mode === 'off' || entry.mode === 'custom' ? entry.mode : '');
|
|
2568
|
+
}
|
|
2569
|
+
for (const key of AVATAR_KEYS) {
|
|
2570
|
+
const value = raw !== null && typeof raw === 'object' ? raw[MEMBER_AVATAR_FIELDS[key]] : undefined;
|
|
2571
|
+
if (typeof value !== 'string') continue;
|
|
2572
|
+
const url = value.trim();
|
|
2573
|
+
if (url.length <= 48 * 1024 && /^data:image\/(?:png|jpeg|webp);base64,(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(url) && url.length > url.indexOf(',') + 1) avatars.set(key, url);
|
|
2574
|
+
}
|
|
2575
|
+
return { names, prompts, modes, avatars };
|
|
2576
|
+
}
|
|
2577
|
+
function setMemberConfig(raw) {
|
|
2578
|
+
memberConfig = normalizeMemberConfig(raw);
|
|
2579
|
+
for (const listener of Array.from(MEMBER_LISTENERS)) {
|
|
2580
|
+
try { listener(); } catch (ignored) { /* a broken subscriber must not break the panel */ }
|
|
2581
|
+
}
|
|
2582
|
+
refreshNativeRosterAvatars();
|
|
2583
|
+
}
|
|
2584
|
+
function subscribeMemberConfig(listener) {
|
|
2585
|
+
MEMBER_LISTENERS.add(listener);
|
|
2586
|
+
return () => { MEMBER_LISTENERS.delete(listener); };
|
|
2587
|
+
}
|
|
2588
|
+
function configuredName(name) {
|
|
2589
|
+
const key = bureauOfName(name);
|
|
2590
|
+
return key === '' ? '' : (memberConfig.names.get(key) || '');
|
|
2591
|
+
}
|
|
2592
|
+
/** Prompt injected for a member: the factory default unless the user cleared it. */
|
|
2593
|
+
function configuredPrompt(name) {
|
|
2594
|
+
const key = bureauOfName(name);
|
|
2595
|
+
if (key === '') return '';
|
|
2596
|
+
const mode = memberConfig.modes.get(key) || '';
|
|
2597
|
+
if (mode === 'off') return '';
|
|
2598
|
+
if (mode === 'custom') return memberConfig.prompts.get(key) || '';
|
|
2599
|
+
return factoryPromptFor(key);
|
|
2600
|
+
}
|
|
2601
|
+
/** Whether the Lead's 御下术 section is currently on (shows in the settings box). */
|
|
2602
|
+
function leadPolicyOn() {
|
|
2603
|
+
return (memberConfig.modes.get('lead') || '') !== 'off';
|
|
2604
|
+
}
|
|
2605
|
+
/** Text shown in the Lead's settings box: '' when the user cleared it. */
|
|
2606
|
+
function leadPolicyText() {
|
|
2607
|
+
const mode = memberConfig.modes.get('lead') || '';
|
|
2608
|
+
if (mode === 'off') return '';
|
|
2609
|
+
return mode === 'custom' ? (memberConfig.prompts.get('lead') || '') : DEFAULT_LEAD_PROMPT;
|
|
2610
|
+
}
|
|
2611
|
+
function configuredAvatar(name) {
|
|
2612
|
+
const key = bureauOfName(name);
|
|
2613
|
+
return key === '' ? '' : (memberConfig.avatars.get(key) || '');
|
|
2614
|
+
}
|
|
2615
|
+
/** Panel label: the configured name when present, else the runtime name. */
|
|
2616
|
+
function memberLabel(name) {
|
|
2617
|
+
const custom = configuredName(name);
|
|
2618
|
+
return custom ? (custom === name ? name : custom + ' · ' + name) : displayName(name);
|
|
2619
|
+
}
|
|
2620
|
+
/** Re-point already-injected roster avatars after a settings change. */
|
|
2621
|
+
function refreshNativeRosterAvatars() {
|
|
2622
|
+
if (typeof document === 'undefined') return;
|
|
2623
|
+
try {
|
|
2624
|
+
const slots = document.querySelectorAll('[data-cabinet-avatar-img]');
|
|
2625
|
+
for (let i = 0; i < slots.length; i++) {
|
|
2626
|
+
const wrap = slots[i];
|
|
2627
|
+
const img = wrap.tagName === 'IMG' ? wrap : wrap.querySelector('img');
|
|
2628
|
+
const row = typeof wrap.closest === 'function' ? wrap.closest('button') : null;
|
|
2629
|
+
const nameNode = row ? row.querySelector('[class*="memberNameText"]') : null;
|
|
2630
|
+
if (!img || !nameNode) continue;
|
|
2631
|
+
img.onerror = () => fallbackAvatar(img, String(nameNode.textContent || '').trim());
|
|
2632
|
+
const next = avatarFor(String(nameNode.textContent || '').trim());
|
|
2633
|
+
if (img.getAttribute('src') !== next) img.setAttribute('src', next);
|
|
2634
|
+
}
|
|
2635
|
+
} catch (ignored) { /* roster may be closed; the next scan re-applies */ }
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
/** Build the members array the settings schema expects. */
|
|
2639
|
+
function membersPayload(draft) {
|
|
2640
|
+
return AVATAR_KEYS.map((key) => ({ key, name: draft[key].name, prompt: draft[key].prompt, mode: draft[key].mode }));
|
|
2641
|
+
}
|
|
2642
|
+
/** Default draft: runtime names, built-in avatars, Lead 御下术 on. */
|
|
2643
|
+
function emptyMemberDraft() {
|
|
2644
|
+
const draft = {};
|
|
2645
|
+
for (const key of AVATAR_KEYS) draft[key] = { name: '', prompt: '', mode: '' };
|
|
2646
|
+
return draft;
|
|
2647
|
+
}
|
|
2648
|
+
/** Draft from the mirrored snapshot (what the form starts with). */
|
|
2649
|
+
function memberDraft() {
|
|
2650
|
+
const draft = emptyMemberDraft();
|
|
2651
|
+
for (const key of AVATAR_KEYS) {
|
|
2652
|
+
draft[key] = {
|
|
2653
|
+
name: memberConfig.names.get(key) || '',
|
|
2654
|
+
prompt: memberConfig.prompts.get(key) || '',
|
|
2655
|
+
mode: memberConfig.modes.get(key) || ''
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
return draft;
|
|
2659
|
+
}
|
|
2660
|
+
/** Normalize one picked image to a 96x96 PNG data URL, or an error message. */
|
|
2661
|
+
async function normalizeAvatarFile(file) {
|
|
2662
|
+
const allowed = ['image/png', 'image/jpeg', 'image/webp'];
|
|
2663
|
+
if (typeof file?.type !== 'string' || !allowed.includes(file.type)) return { error: memberT('member.error.type') };
|
|
2664
|
+
if (typeof file.size !== 'number' || file.size <= 0 || file.size > 2 * 1024 * 1024) return { error: memberT('member.error.size') };
|
|
2665
|
+
let bitmap;
|
|
2666
|
+
try {
|
|
2667
|
+
bitmap = await createImageBitmap(file);
|
|
2668
|
+
} catch {
|
|
2669
|
+
return { error: memberT('member.error.decode') };
|
|
2670
|
+
}
|
|
2671
|
+
try {
|
|
2672
|
+
const canvas = document.createElement('canvas');
|
|
2673
|
+
canvas.width = 96;
|
|
2674
|
+
canvas.height = 96;
|
|
2675
|
+
const context = canvas.getContext('2d');
|
|
2676
|
+
if (!context) return { error: memberT('member.error.decode') };
|
|
2677
|
+
const scale = Math.max(96 / bitmap.width, 96 / bitmap.height);
|
|
2678
|
+
const width = Math.round(bitmap.width * scale);
|
|
2679
|
+
const height = Math.round(bitmap.height * scale);
|
|
2680
|
+
context.drawImage(bitmap, Math.round((96 - width) / 2), Math.round((96 - height) / 2), width, height);
|
|
2681
|
+
const url = canvas.toDataURL('image/png');
|
|
2682
|
+
if (url.length > MEMBER_AVATAR_LIMIT) return { error: memberT('member.error.tooLarge') };
|
|
2683
|
+
return { url };
|
|
2684
|
+
} catch {
|
|
2685
|
+
return { error: memberT('member.error.decode') };
|
|
2686
|
+
} finally {
|
|
2687
|
+
if (typeof bitmap?.close === 'function') bitmap.close();
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2491
2691
|
// ---------- DOM enhancement: avatars in the native team roster ----------
|
|
2492
2692
|
// The shipped roster (dsh-experimental-client-ui-agent-team) shows a status
|
|
2493
2693
|
// dot and the name only, and its bundle is read-only for us (an upgrade would
|
|
@@ -2543,6 +2743,7 @@ window.__ModuleLoader__.load({
|
|
|
2543
2743
|
const running = !!dot && (!!dot.querySelector('svg[data-state="ongoing"]') || !!dot.querySelector('[class*="_spinner_"]'));
|
|
2544
2744
|
const img = slot.tagName === 'IMG' ? slot : slot.querySelector('img');
|
|
2545
2745
|
if (img) {
|
|
2746
|
+
img.onerror = () => fallbackAvatar(img, String(nameNode.textContent || '').trim());
|
|
2546
2747
|
const src = avatarFor(memberName);
|
|
2547
2748
|
if (img.getAttribute('src') !== src) img.src = src;
|
|
2548
2749
|
img.className = running ? 'cabinet-avatar-running' : '';
|
|
@@ -2605,6 +2806,7 @@ window.__ModuleLoader__.load({
|
|
|
2605
2806
|
function Avatar({ name, size, live }) {
|
|
2606
2807
|
const img = h('img', {
|
|
2607
2808
|
src: avatarFor(name),
|
|
2809
|
+
onError: event => fallbackAvatar(event.currentTarget, name),
|
|
2608
2810
|
alt: '',
|
|
2609
2811
|
'aria-hidden': 'true',
|
|
2610
2812
|
width: size,
|
|
@@ -2752,9 +2954,9 @@ window.__ModuleLoader__.load({
|
|
|
2752
2954
|
h(Avatar, { key: 'avatar', name: member.name, size: size || 22, live: status === 'running' }),
|
|
2753
2955
|
h('span', {
|
|
2754
2956
|
key: 'n',
|
|
2755
|
-
title:
|
|
2957
|
+
title: memberLabel(member.name),
|
|
2756
2958
|
style: { fontSize: 13, fontWeight: 600, color: INK, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }
|
|
2757
|
-
},
|
|
2959
|
+
}, memberLabel(member.name)),
|
|
2758
2960
|
lead ? h('span', { key: 'lead', className: 'cabinet-badge-lead' }, tt('lead.tag')) : null,
|
|
2759
2961
|
isCurrent ? h(Tag, { key: 'cur', background: 'rgba(127,127,127,.2)', color: INK2 }, tt('current')) : null
|
|
2760
2962
|
]),
|
|
@@ -2805,7 +3007,7 @@ window.__ModuleLoader__.load({
|
|
|
2805
3007
|
if (!task.ownerName) {
|
|
2806
3008
|
parts.push(h(Tag, { key: 'own', background: 'rgba(127,127,127,.18)', color: INK2 }, t('task.unassigned')));
|
|
2807
3009
|
} else {
|
|
2808
|
-
parts.push(h(Tag, { key: 'owner', title:
|
|
3010
|
+
parts.push(h(Tag, { key: 'owner', title: memberLabel(task.ownerName), background: 'rgba(127,127,127,.16)', color: INK2 }, 'Owner: ' + memberLabel(task.ownerName)));
|
|
2809
3011
|
}
|
|
2810
3012
|
parts.push(h('span', {
|
|
2811
3013
|
key: 'id',
|
|
@@ -2950,6 +3152,9 @@ window.__ModuleLoader__.load({
|
|
|
2950
3152
|
|
|
2951
3153
|
// ---------- the body ------------------------------------------------
|
|
2952
3154
|
function CabinetPanel({ sessionId, useSession, useSessions, useSessionStatus, t }) {
|
|
3155
|
+
// Re-render when the mirrored member settings change (names/avatars).
|
|
3156
|
+
const [, setMemberRevision] = React.useState(0);
|
|
3157
|
+
React.useEffect(() => subscribeMemberConfig(() => setMemberRevision((revision) => revision + 1)), []);
|
|
2953
3158
|
const tt = typeof t === 'function' ? t : (key) => key;
|
|
2954
3159
|
const statusLabel = (status) => tt('status.' + status);
|
|
2955
3160
|
const taskLabel = (status) => tt('task.' + status);
|
|
@@ -3119,7 +3324,7 @@ window.__ModuleLoader__.load({
|
|
|
3119
3324
|
if (unassigned.length > 0) cells.push({ key: 'group:unassigned', title: tt('task.unassigned'), tasks: unassigned });
|
|
3120
3325
|
if (leadOwn.length > 0) cells.push({ key: 'group:leadown', title: tt('task.leadOwn'), tasks: leadOwn });
|
|
3121
3326
|
for (const owner of foreignOwners) {
|
|
3122
|
-
cells.push({ key: 'group:' + owner, title:
|
|
3327
|
+
cells.push({ key: 'group:' + owner, title: memberLabel(owner), tasks: tasks.filter((task) => task.ownerName === owner) });
|
|
3123
3328
|
}
|
|
3124
3329
|
|
|
3125
3330
|
const treeChildren = [
|
|
@@ -3216,8 +3421,197 @@ window.__ModuleLoader__.load({
|
|
|
3216
3421
|
return h('div', { style: PANEL }, body);
|
|
3217
3422
|
}
|
|
3218
3423
|
|
|
3424
|
+
// ---------- settings section: 内阁成员 ---------------------------------
|
|
3425
|
+
// Registered into the official settings shell (`settings.section`) while
|
|
3426
|
+
// the Host serves this namespace. Writes go through the shared config
|
|
3427
|
+
// form: `members` carries the small text fields and each avatar is its own
|
|
3428
|
+
// field. Explicit Save writes a bounded atomic settings transaction.
|
|
3429
|
+
const MEMBER_SECTION_FIELDS = AVATAR_KEYS;
|
|
3430
|
+
|
|
3431
|
+
function memberAvatarOf(key, overrides) {
|
|
3432
|
+
return overrides ? (overrides[key] || AVATARS[key]) : (memberConfig.avatars.get(key) || AVATARS[key]);
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
function createMemberEditor(form, notify) {
|
|
3436
|
+
let active = true, epoch = 0, uploads = {};
|
|
3437
|
+
const state = { draft: emptyMemberDraft(), avatars: {}, errors: {}, ready: false, dirty: false, busy: false, conflict: false, revision: undefined, status: '' };
|
|
3438
|
+
const emit = () => { if (active) notify(); };
|
|
3439
|
+
const ready = s => s?.status === 'ready' && s.value !== undefined && s.writable === true && s.revision !== undefined;
|
|
3440
|
+
const adopt = s => {
|
|
3441
|
+
epoch++; uploads = {};
|
|
3442
|
+
const config = normalizeMemberConfig(s?.value);
|
|
3443
|
+
state.draft = emptyMemberDraft(); state.avatars = {}; state.errors = {};
|
|
3444
|
+
for (const key of AVATAR_KEYS) {
|
|
3445
|
+
state.draft[key] = { name: config.names.get(key) || '', prompt: config.prompts.get(key) || '', mode: config.modes.get(key) || '' };
|
|
3446
|
+
state.avatars[key] = config.avatars.get(key) || '';
|
|
3447
|
+
}
|
|
3448
|
+
state.revision = s?.revision; state.ready = ready(s); state.dirty = false; state.conflict = false;
|
|
3449
|
+
};
|
|
3450
|
+
const sync = () => {
|
|
3451
|
+
if (!active) return;
|
|
3452
|
+
const s = form?.getSnapshot();
|
|
3453
|
+
if (!state.dirty && !state.busy) adopt(s);
|
|
3454
|
+
else { state.ready = ready(s); state.conflict = s?.revision !== state.revision; }
|
|
3455
|
+
emit();
|
|
3456
|
+
};
|
|
3457
|
+
const editable = () => active && state.ready && !state.busy;
|
|
3458
|
+
const changed = () => { state.dirty = true; state.status = 'member.status.unsaved'; emit(); };
|
|
3459
|
+
adopt(form?.getSnapshot());
|
|
3460
|
+
let unsubscribe;
|
|
3461
|
+
return {
|
|
3462
|
+
state,
|
|
3463
|
+
connect() { active = true; sync(); unsubscribe = form?.subscribe(sync); return () => { active = false; epoch++; unsubscribe?.(); }; },
|
|
3464
|
+
update(key, patch) { if (!editable()) return; state.draft = { ...state.draft, [key]: { ...state.draft[key], ...patch } }; changed(); },
|
|
3465
|
+
avatar(key, url) { if (!editable()) return; uploads[key] = (uploads[key] || 0) + 1; state.avatars = { ...state.avatars, [key]: url }; changed(); },
|
|
3466
|
+
async upload(key, file) {
|
|
3467
|
+
if (!editable() || !file) return;
|
|
3468
|
+
const generation = epoch, token = uploads[key] = (uploads[key] || 0) + 1;
|
|
3469
|
+
const result = await normalizeAvatarFile(file);
|
|
3470
|
+
if (!editable() || epoch !== generation || uploads[key] !== token) return;
|
|
3471
|
+
state.errors = { ...state.errors, [key]: result.error || '' };
|
|
3472
|
+
if (!result.error) { state.avatars = { ...state.avatars, [key]: result.url }; changed(); } else emit();
|
|
3473
|
+
},
|
|
3474
|
+
reset(key) {
|
|
3475
|
+
if (!editable()) return;
|
|
3476
|
+
epoch++; uploads = {};
|
|
3477
|
+
const keys = key ? [key] : AVATAR_KEYS;
|
|
3478
|
+
for (const k of keys) { state.draft[k] = { name: '', prompt: '', mode: '' }; state.avatars[k] = ''; }
|
|
3479
|
+
state.draft = { ...state.draft }; state.avatars = { ...state.avatars }; state.errors = {}; changed();
|
|
3480
|
+
},
|
|
3481
|
+
cancel() { if (!active || state.busy) return; adopt(form?.getSnapshot()); state.status = ''; emit(); },
|
|
3482
|
+
async save() {
|
|
3483
|
+
if (!editable() || !state.dirty) return false;
|
|
3484
|
+
const current = form.getSnapshot();
|
|
3485
|
+
if (!ready(current) || current.revision !== state.revision) { state.conflict = true; state.status = 'member.status.conflict'; emit(); return false; }
|
|
3486
|
+
const ops = [{ op: 'set', path: ['members'], value: membersPayload(state.draft) }];
|
|
3487
|
+
for (const key of AVATAR_KEYS) ops.push({ op: 'set', path: [MEMBER_AVATAR_FIELDS[key]], value: state.avatars[key] || '' });
|
|
3488
|
+
epoch++; state.busy = true; emit();
|
|
3489
|
+
try {
|
|
3490
|
+
const ok = await form.mutate(ops, state.revision);
|
|
3491
|
+
if (!active) return ok;
|
|
3492
|
+
if (ok) adopt(form.getSnapshot());
|
|
3493
|
+
else { state.conflict = form.getSnapshot()?.revision !== state.revision; }
|
|
3494
|
+
state.status = ok ? 'member.status.saved' : state.conflict ? 'member.status.conflict' : 'member.status.failed';
|
|
3495
|
+
return ok;
|
|
3496
|
+
} catch { if (active) state.status = 'member.status.failed'; return false; }
|
|
3497
|
+
finally { state.busy = false; emit(); }
|
|
3498
|
+
}
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
|
|
3502
|
+
function CabinetMemberSettings(props) {
|
|
3503
|
+
const t = typeof props?.t === 'function' ? props.t : memberT;
|
|
3504
|
+
const [, redraw] = React.useState(0);
|
|
3505
|
+
const editorRef = React.useRef(null);
|
|
3506
|
+
if (!editorRef.current) editorRef.current = createMemberEditor(memberWriter, () => redraw(n => n + 1));
|
|
3507
|
+
const editor = editorRef.current;
|
|
3508
|
+
React.useEffect(() => editor.connect(), [editor]);
|
|
3509
|
+
const { draft, avatars, errors, ready, busy, dirty, conflict, status } = editor.state;
|
|
3510
|
+
const update = (key, patch) => editor.update(key, patch);
|
|
3511
|
+
const writeAvatar = (key, url) => editor.avatar(key, url);
|
|
3512
|
+
const pickFile = (key, file) => editor.upload(key, file);
|
|
3513
|
+
const resetMember = key => editor.reset(key);
|
|
3514
|
+
const resetAll = () => editor.reset();
|
|
3515
|
+
const promptOf = (key) => {
|
|
3516
|
+
const mode = draft[key].mode;
|
|
3517
|
+
if (mode === 'off') return '';
|
|
3518
|
+
return mode === 'custom' ? draft[key].prompt : factoryPromptFor(key);
|
|
3519
|
+
};
|
|
3520
|
+
const inputStyle = { width: '100%', boxSizing: 'border-box', fontSize: 13, color: INK, background: 'transparent', border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.4))', borderRadius: 6, padding: '6px 8px' };
|
|
3521
|
+
const cards = MEMBER_SECTION_FIELDS.map((key) => {
|
|
3522
|
+
const preview = memberAvatarOf(key, avatars);
|
|
3523
|
+
return h('div', { key, style: { border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.28))', borderRadius: 8, padding: '10px 12px', marginBottom: 10 } }, [
|
|
3524
|
+
h('div', { key: 'head', style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 } }, [
|
|
3525
|
+
h('img', { key: 'a', src: preview, onError: event => fallbackAvatar(event.currentTarget, key), alt: '', width: 32, height: 32, style: { width: 32, height: 32, borderRadius: '50%', objectFit: 'cover', flex: 'none' } }),
|
|
3526
|
+
h('strong', { key: 'n', style: { fontSize: 13, color: INK } }, t('member.' + key)),
|
|
3527
|
+
h('span', { key: 'h', style: { fontSize: 11, color: INK3 } }, draft[key].name ? draft[key].name : t('member.name.unset')),
|
|
3528
|
+
h('span', { key: 'gap', style: { flex: 1 } }),
|
|
3529
|
+
h('button', {
|
|
3530
|
+
key: 'reset',
|
|
3531
|
+
type: 'button',
|
|
3532
|
+
style: { fontSize: 11, cursor: 'pointer' },
|
|
3533
|
+
onClick: () => resetMember(key)
|
|
3534
|
+
}, t('member.reset'))
|
|
3535
|
+
]),
|
|
3536
|
+
h('div', { key: 'builtin', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', marginBottom: 6 } }, [
|
|
3537
|
+
h('span', { key: 'l', style: { fontSize: 11, color: INK3 } }, t('member.builtin')),
|
|
3538
|
+
...(function () {
|
|
3539
|
+
const out = [];
|
|
3540
|
+
for (const other of AVATAR_KEYS) {
|
|
3541
|
+
out.push(h('button', {
|
|
3542
|
+
key: 'b-' + other,
|
|
3543
|
+
type: 'button',
|
|
3544
|
+
title: t('member.' + other),
|
|
3545
|
+
style: { padding: 0, border: preview === AVATARS[other] ? '2px solid #4f8cff' : '1px solid transparent', borderRadius: '50%', background: 'transparent', cursor: 'pointer', lineHeight: 0 },
|
|
3546
|
+
// Clicking a built-in portrait selects it for this member;
|
|
3547
|
+
// clicking the selected one again clears the override.
|
|
3548
|
+
onClick: () => writeAvatar(key, avatars[key] === AVATARS[other] ? '' : AVATARS[other])
|
|
3549
|
+
}, h('img', { src: AVATARS[other], alt: '', width: 22, height: 22, style: { width: 22, height: 22, borderRadius: '50%', objectFit: 'cover' } })));
|
|
3550
|
+
}
|
|
3551
|
+
return out;
|
|
3552
|
+
})(),
|
|
3553
|
+
h('label', { key: 'up', style: { fontSize: 11, cursor: 'pointer', color: '#4f8cff' } }, [
|
|
3554
|
+
h('input', {
|
|
3555
|
+
key: 'i',
|
|
3556
|
+
type: 'file',
|
|
3557
|
+
accept: 'image/png,image/jpeg,image/webp',
|
|
3558
|
+
style: { display: 'none' },
|
|
3559
|
+
onChange: (event) => { const file = event?.target?.files?.[0]; pickFile(key, file); if (event?.target) event.target.value = ''; }
|
|
3560
|
+
}),
|
|
3561
|
+
t('member.upload')
|
|
3562
|
+
]),
|
|
3563
|
+
avatars[key] ? h('button', { key: 'clear', type: 'button', style: { fontSize: 11, cursor: 'pointer' }, onClick: () => writeAvatar(key, '') }, t('member.avatar.clear')) : null
|
|
3564
|
+
]),
|
|
3565
|
+
errors[key] ? h('div', { key: 'e', style: { fontSize: 11, color: '#f25a5a', marginBottom: 4 } }, errors[key]) : null,
|
|
3566
|
+
h('label', { key: 'name', style: { display: 'block', fontSize: 11, color: INK2, marginBottom: 2 } }, t('member.name')),
|
|
3567
|
+
h('input', {
|
|
3568
|
+
key: 'ni',
|
|
3569
|
+
type: 'text',
|
|
3570
|
+
value: draft[key].name,
|
|
3571
|
+
maxLength: MEMBER_NAME_LIMIT,
|
|
3572
|
+
placeholder: t('member.name.placeholder'),
|
|
3573
|
+
style: inputStyle,
|
|
3574
|
+
onChange: (event) => update(key, { name: event?.target?.value ?? '' })
|
|
3575
|
+
}),
|
|
3576
|
+
h('label', { key: 'prompt', style: { display: 'block', fontSize: 11, color: INK2, margin: '8px 0 2px' } }, t('member.prompt')),
|
|
3577
|
+
h('textarea', {
|
|
3578
|
+
key: 'pi',
|
|
3579
|
+
value: promptOf(key),
|
|
3580
|
+
maxLength: MEMBER_PROMPT_LIMIT,
|
|
3581
|
+
rows: key === 'lead' ? 8 : 3,
|
|
3582
|
+
placeholder: t('member.prompt.placeholder'),
|
|
3583
|
+
style: { ...inputStyle, resize: 'vertical', fontFamily: 'inherit' },
|
|
3584
|
+
onChange: (event) => {
|
|
3585
|
+
const value = event?.target?.value ?? '';
|
|
3586
|
+
const mode = value.trim() === '' ? 'off' : 'custom';
|
|
3587
|
+
update(key, { prompt: value, mode }, false);
|
|
3588
|
+
}
|
|
3589
|
+
}),
|
|
3590
|
+
key === 'lead' ? h('div', { key: 'hint', style: { fontSize: 11, color: INK3, marginTop: 4 } }, t('member.lead.hint')) : null
|
|
3591
|
+
]);
|
|
3592
|
+
});
|
|
3593
|
+
return h('div', { style: { padding: '4px 2px 20px' } }, [
|
|
3594
|
+
h('div', { key: 'title', style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 4 } }, [
|
|
3595
|
+
h('strong', { key: 't', style: { fontSize: 14, color: INK } }, t('member.title')),
|
|
3596
|
+
h('span', { key: 'gap', style: { flex: 1 } }),
|
|
3597
|
+
h('button', { key: 'reset', type: 'button', style: { fontSize: 11, cursor: 'pointer' }, disabled: !ready || busy, onClick: resetAll }, t('member.resetAll'))
|
|
3598
|
+
]),
|
|
3599
|
+
h('div', { key: 'desc', style: { fontSize: 11, color: INK3, marginBottom: 8 } }, t('member.desc')),
|
|
3600
|
+
!ready ? h('div', { key: 'unavailable', role: 'status' }, t('member.status.unavailable')) : null,
|
|
3601
|
+
status ? h('div', { key: 'status', style: { fontSize: 11, color: INK2, marginBottom: 8 } }, t(status)) : null,
|
|
3602
|
+
conflict ? h('div', { key: 'conflict', role: 'alert' }, t('member.status.conflict')) : null,
|
|
3603
|
+
h('fieldset', { key: 'fields', disabled: !ready || busy, style: { border: 0, padding: 0, margin: 0 } }, cards),
|
|
3604
|
+
h('button', { key: 'save', type: 'button', disabled: !ready || busy || !dirty || conflict, onClick: () => editor.save() }, t('member.save')),
|
|
3605
|
+
h('button', { key: 'cancel', type: 'button', disabled: busy, onClick: () => editor.cancel() }, t('member.cancel'))
|
|
3606
|
+
]);
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3219
3609
|
// ---------- copy -----------------------------------------------------
|
|
3220
3610
|
const zh = {
|
|
3611
|
+
'member.save': "保存",
|
|
3612
|
+
'member.cancel': "取消并重新读取",
|
|
3613
|
+
'member.status.unsaved': "未保存;离开此页会丢弃修改",
|
|
3614
|
+
'member.status.conflict': "配置已在其他页面更新。请取消并重新读取后再编辑。",
|
|
3221
3615
|
'team.stale': '团队状态读取失败:以下成员和任务可能是上次成功读取的数据。',
|
|
3222
3616
|
'tab.title': '内阁',
|
|
3223
3617
|
'guide.title': '内阁',
|
|
@@ -3242,8 +3636,39 @@ window.__ModuleLoader__.load({
|
|
|
3242
3636
|
'task.none': '暂无任务',
|
|
3243
3637
|
'legend': '任务状态',
|
|
3244
3638
|
'empty.hint': '尚无内阁数据:请在已建团队板的首辅会话中打开本页。'
|
|
3639
|
+
,
|
|
3640
|
+
'member.nav': '内阁成员',
|
|
3641
|
+
'member.title': '内阁成员',
|
|
3642
|
+
'member.desc': '五员的名字、头像与提示词。未配置时保持出厂行为;头像归一为 96×96 PNG,单张不超过 48KB。',
|
|
3643
|
+
'member.lead': '内阁首辅',
|
|
3644
|
+
'member.hanlin': '翰林院编修',
|
|
3645
|
+
'member.works': '工部尚书',
|
|
3646
|
+
'member.dali': '大理寺卿',
|
|
3647
|
+
'member.yushi': '左都御史',
|
|
3648
|
+
'member.name': '显示名(留空则用官职与原始 ID)',
|
|
3649
|
+
'member.name.unset': '未设置',
|
|
3650
|
+
'member.name.placeholder': '运行时名字',
|
|
3651
|
+
'member.prompt': '提示词',
|
|
3652
|
+
'member.prompt.placeholder': '留空则不注入该段',
|
|
3653
|
+
'member.builtin': '内置头像:',
|
|
3654
|
+
'member.upload': '上传图片',
|
|
3655
|
+
'member.avatar.clear': '恢复内置',
|
|
3656
|
+
'member.reset': '恢复默认',
|
|
3657
|
+
'member.resetAll': '重置全部',
|
|
3658
|
+
'member.status.saved': '已保存',
|
|
3659
|
+
'member.status.failed': '保存失败,请重试',
|
|
3660
|
+
'member.status.unavailable': '设置通道不可用',
|
|
3661
|
+
'member.lead.hint': '清空此框 = 关闭御下术(不注入该段);「恢复默认」还原出厂定稿。',
|
|
3662
|
+
'member.error.type': '格式不支持:只接受 PNG / JPEG / WebP',
|
|
3663
|
+
'member.error.size': '文件过大:源文件不超过 2MB',
|
|
3664
|
+
'member.error.decode': '图片读取失败,请换一张',
|
|
3665
|
+
'member.error.tooLarge': '压缩后仍超过 48KB,请换更小的图片'
|
|
3245
3666
|
};
|
|
3246
3667
|
const en = {
|
|
3668
|
+
'member.save': "Save",
|
|
3669
|
+
'member.cancel': "Cancel and reload",
|
|
3670
|
+
'member.status.unsaved': "Unsaved; leaving this page discards edits",
|
|
3671
|
+
'member.status.conflict': "Settings changed in another page. Cancel and reload before editing.",
|
|
3247
3672
|
'team.stale': 'Team state could not be read. Members and tasks below may show the last successful snapshot.',
|
|
3248
3673
|
'tab.title': 'Cabinet',
|
|
3249
3674
|
'guide.title': 'Cabinet',
|
|
@@ -3268,6 +3693,33 @@ window.__ModuleLoader__.load({
|
|
|
3268
3693
|
'task.none': 'no tasks',
|
|
3269
3694
|
'legend': 'Task status',
|
|
3270
3695
|
'empty.hint': 'No cabinet data yet: open this tab from the Lead session that owns the team board.'
|
|
3696
|
+
,
|
|
3697
|
+
'member.nav': 'Cabinet members',
|
|
3698
|
+
'member.title': 'Cabinet members',
|
|
3699
|
+
'member.desc': 'Names, avatars and prompts for the five members. Unconfigured keeps the factory behaviour; avatars are normalized to 96×96 PNG, at most 48KB each.',
|
|
3700
|
+
'member.lead': '内阁首辅',
|
|
3701
|
+
'member.hanlin': '翰林院编修',
|
|
3702
|
+
'member.works': '工部尚书',
|
|
3703
|
+
'member.dali': '大理寺卿',
|
|
3704
|
+
'member.yushi': '左都御史',
|
|
3705
|
+
'member.name': 'Display name (empty keeps office and original ID)',
|
|
3706
|
+
'member.name.unset': 'unset',
|
|
3707
|
+
'member.name.placeholder': 'runtime name',
|
|
3708
|
+
'member.prompt': 'Prompt',
|
|
3709
|
+
'member.prompt.placeholder': 'empty = inject nothing',
|
|
3710
|
+
'member.builtin': 'Built-in avatars:',
|
|
3711
|
+
'member.upload': 'Upload image',
|
|
3712
|
+
'member.avatar.clear': 'Use built-in',
|
|
3713
|
+
'member.reset': 'Restore default',
|
|
3714
|
+
'member.resetAll': 'Reset all',
|
|
3715
|
+
'member.status.saved': 'Saved',
|
|
3716
|
+
'member.status.failed': 'Save failed, try again',
|
|
3717
|
+
'member.status.unavailable': 'Settings channel unavailable',
|
|
3718
|
+
'member.lead.hint': 'Clearing this box turns the Lead policy off (nothing injected); "Restore default" brings back the factory text.',
|
|
3719
|
+
'member.error.type': 'Unsupported format: PNG / JPEG / WebP only',
|
|
3720
|
+
'member.error.size': 'File too large: source must be at most 2MB',
|
|
3721
|
+
'member.error.decode': 'Could not read the image, try another file',
|
|
3722
|
+
'member.error.tooLarge': 'Still over 48KB after compression, pick a smaller image'
|
|
3271
3723
|
};
|
|
3272
3724
|
|
|
3273
3725
|
const inject = ['slots', 'locale', 'sidebarRightTabs'];
|
|
@@ -3303,6 +3755,7 @@ window.__ModuleLoader__.load({
|
|
|
3303
3755
|
ctx.effect(() => injectStyles(), 'cabinet-ui: styles');
|
|
3304
3756
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'cabinet-ui: dictionaries');
|
|
3305
3757
|
const t = ctx.locale.bind(NS);
|
|
3758
|
+
memberT = t;
|
|
3306
3759
|
// Stage one: declare the page type. No patterns => a page type, opened by kind.
|
|
3307
3760
|
ctx.effect(() => ctx.sidebarRightTabs.register({
|
|
3308
3761
|
id: TAB_ID,
|
|
@@ -3322,6 +3775,36 @@ window.__ModuleLoader__.load({
|
|
|
3322
3775
|
key: TAB_ID,
|
|
3323
3776
|
locale: NS
|
|
3324
3777
|
}, CabinetPanel)), 'cabinet-ui: sidebar body');
|
|
3778
|
+
// Member settings: mirror the `cabinet-ui` namespace and mount the
|
|
3779
|
+
// 「内阁成员」 settings section while the Host serves it. The channel is
|
|
3780
|
+
// optional, so a deployment without the settings base plugin still loads
|
|
3781
|
+
// the panel and keeps v0.2.0 rendering.
|
|
3782
|
+
ctx.inject(['configForms'], (scope) => {
|
|
3783
|
+
const form = scope.configForms.get('cabinet-ui');
|
|
3784
|
+
scope.effect(() => {
|
|
3785
|
+
const sync = () => {
|
|
3786
|
+
try {
|
|
3787
|
+
const snapshot = form.getSnapshot();
|
|
3788
|
+
setMemberConfig(snapshot?.status === 'ready' ? snapshot.value : undefined);
|
|
3789
|
+
} catch (error) {
|
|
3790
|
+
try { console.warn('[cabinet-ui] member settings unavailable:', error); } catch (ignored) { /* console may be unavailable */ }
|
|
3791
|
+
}
|
|
3792
|
+
};
|
|
3793
|
+
sync();
|
|
3794
|
+
const unsubscribe = form.subscribe(sync);
|
|
3795
|
+
return () => { unsubscribe(); if (memberWriter === form) { memberWriter = null; setMemberConfig(undefined); } };
|
|
3796
|
+
}, 'cabinet-member: settings mirror');
|
|
3797
|
+
memberWriter = form;
|
|
3798
|
+
scope.effect(() => scope.slots.inject('settings.section', () => scope.slots.register({
|
|
3799
|
+
name: 'settings.section',
|
|
3800
|
+
id: 'cabinet',
|
|
3801
|
+
order: 40,
|
|
3802
|
+
label: () => memberT('member.nav'),
|
|
3803
|
+
locale: NS,
|
|
3804
|
+
inject: () => ({ t: memberT })
|
|
3805
|
+
}, CabinetMemberSettings)), 'cabinet-member: settings section');
|
|
3806
|
+
}, 'cabinet-member: settings channel');
|
|
3807
|
+
|
|
3325
3808
|
// Native agent-team roster: inject avatars without touching its bundle.
|
|
3326
3809
|
ctx.effect(() => {
|
|
3327
3810
|
try { return installTeamRosterAvatars(); } catch (error) {
|