dsh-folia 4.26.0-pre.64 → 4.26.0-pre.65
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/lib/client.js +602 -5
- package/lib/features.js +2 -2
- package/lib/index.js +5 -0
- package/lib/persona-card.js +220 -0
- package/lib/persona-growth.js +182 -0
- package/lib/persona-memory.js +275 -0
- package/lib/persona-store.js +485 -0
- package/lib/pet-chat-brain.js +98 -0
- package/lib/pet-chat-memory.js +4 -136
- package/lib/pet-chat-tools.js +7 -51
- package/lib/route-registry.js +1 -0
- package/lib/routes/personas.js +334 -0
- package/lib/routes/pet-chat.js +319 -126
- package/lib/settings-schema.js +2166 -2166
- package/package.json +5 -1
package/lib/client.js
CHANGED
|
@@ -761,6 +761,100 @@ window.__ModuleLoader__.load({
|
|
|
761
761
|
"没找到叫「{name}」的壁纸": "No wallpaper named '{name}' was found",
|
|
762
762
|
"没有可用的壁纸": "No wallpapers available",
|
|
763
763
|
"壁纸切换没生效": "The wallpaper change did not take effect",
|
|
764
|
+
// pre.65:人设系统(列表 + 7 子页)
|
|
765
|
+
"人设": "Personas",
|
|
766
|
+
"特殊人设": "Special persona",
|
|
767
|
+
"角色扮演": "Roleplay",
|
|
768
|
+
"互动故事": "Interactive story",
|
|
769
|
+
"聊天": "Chat",
|
|
770
|
+
"人设不存在": "Persona not found",
|
|
771
|
+
"读取人设失败": "Failed to read persona",
|
|
772
|
+
"新建失败": "Create failed",
|
|
773
|
+
"已切换当前人设": "Active persona switched",
|
|
774
|
+
"切换失败": "Switch failed",
|
|
775
|
+
"删除「{name}」会同时删除它的全部记忆,确定吗?": "Deleting '{name}' also deletes all of its memory. Continue?",
|
|
776
|
+
"人设已删除": "Persona deleted",
|
|
777
|
+
"删除失败": "Delete failed",
|
|
778
|
+
"角色卡已导入": "Character card imported",
|
|
779
|
+
"角色卡导入失败": "Character card import failed",
|
|
780
|
+
"刷新": "Refresh",
|
|
781
|
+
"当前使用": "In use",
|
|
782
|
+
"未命名": "Unnamed",
|
|
783
|
+
"还没有人设": "No personas yet",
|
|
784
|
+
"正在读取人设…": "Loading personas…",
|
|
785
|
+
"记忆 {n}": "Memory: {n}",
|
|
786
|
+
"进入": "Open",
|
|
787
|
+
"新建人设": "New persona",
|
|
788
|
+
"名字(可留空)": "Name (optional)",
|
|
789
|
+
"+新建": "+ New",
|
|
790
|
+
"导入角色卡(JSON/PNG)": "Import character card (JSON/PNG)",
|
|
791
|
+
"返回列表": "Back to list",
|
|
792
|
+
"名字": "Name",
|
|
793
|
+
"头像(URL / emoji / 留空)": "Avatar (URL / emoji / blank)",
|
|
794
|
+
"类型": "Type",
|
|
795
|
+
"助手(可用系统工具)": "Assistant (tools allowed)",
|
|
796
|
+
"特殊人设(不使用系统工具)": "Special persona (no system tools)",
|
|
797
|
+
"模式": "Mode",
|
|
798
|
+
"特殊人设不使用任何系统工具。": "Special personas do not use any system tools.",
|
|
799
|
+
"接口协议": "API protocol",
|
|
800
|
+
"继承全局": "Inherit global",
|
|
801
|
+
"接口地址": "Base URL",
|
|
802
|
+
"模型名": "Model",
|
|
803
|
+
"温度": "Temperature",
|
|
804
|
+
"Key": "Key",
|
|
805
|
+
"只写不读;留空不修改": "Write-only; leave blank to keep",
|
|
806
|
+
"保存 Key": "Save key",
|
|
807
|
+
"先填 Key": "Enter a key first",
|
|
808
|
+
"Key 已保存": "Key saved",
|
|
809
|
+
"Key 保存失败": "Failed to save key",
|
|
810
|
+
"测试": "Test",
|
|
811
|
+
"连接成功": "Connected",
|
|
812
|
+
"连接失败": "Connection failed",
|
|
813
|
+
"留空/继承全局时使用「全局默认」里保存的模型与 Key。": "Blank / inherit uses the model and key from Global defaults.",
|
|
814
|
+
"核心身份": "Core identity",
|
|
815
|
+
"价值观(每行一条)": "Values (one per line)",
|
|
816
|
+
"边界(每行一条)": "Boundaries (one per line)",
|
|
817
|
+
"说话习惯(每行一条)": "Speech habits (one per line)",
|
|
818
|
+
"示例对话(空行分隔)": "Example dialogues (blank line separated)",
|
|
819
|
+
"世界书(JSON 数组:keys/content/priority)": "World book (JSON array: keys/content/priority)",
|
|
820
|
+
"开场白 first_mes": "First message (first_mes)",
|
|
821
|
+
"场景 scenario": "Scenario",
|
|
822
|
+
"角色卡系统提示": "Character card system prompt",
|
|
823
|
+
"导出 CCv2 JSON": "Export CCv2 JSON",
|
|
824
|
+
"导出 PNG 卡": "Export PNG card",
|
|
825
|
+
"搜索记忆…": "Search memory…",
|
|
826
|
+
"事件 {n} 条(无上限、不过期)": "{n} events (no cap, never expires)",
|
|
827
|
+
"还没有记忆。": "No memory yet.",
|
|
828
|
+
"它最近学到的": "What it recently learned",
|
|
829
|
+
"还没有成长项。": "No growth entries yet.",
|
|
830
|
+
"回滚到这一天": "Roll back to this date",
|
|
831
|
+
"已回滚": "Rolled back",
|
|
832
|
+
"回滚失败": "Rollback failed",
|
|
833
|
+
"自动 / 继承": "Auto / inherit",
|
|
834
|
+
"语速(-10…10)": "Speech rate (-10…10)",
|
|
835
|
+
"长度策略": "Length policy",
|
|
836
|
+
"自适应": "Adaptive",
|
|
837
|
+
"短": "Short",
|
|
838
|
+
"长": "Long",
|
|
839
|
+
"语音模式由宿主按 1–3 句截断;这里保存的是该人设的音色与语速。": "Voice mode is capped at 1–3 sentences by the host; this page stores the persona voice and rate.",
|
|
840
|
+
"玩法模式": "Play mode",
|
|
841
|
+
"唤醒口令": "Wake phrase",
|
|
842
|
+
"例如:我回来了": "e.g. I'm back",
|
|
843
|
+
"故事章节": "Story chapter",
|
|
844
|
+
"当前场景": "Current scene",
|
|
845
|
+
"角色扮演与互动故事会按人设卡中的场景/开场白注入;故事模式章末给 2–3 个选项。": "Roleplay and story modes inject the card scenario/opening; story mode offers 2–3 choices at chapter end.",
|
|
846
|
+
"助手人设可以使用系统工具(换壁纸、提醒、桌宠设置等)。": "Assistant personas can use system tools (wallpaper, reminders, pet settings, etc.).",
|
|
847
|
+
"特殊人设不使用任何系统工具;切换到「特殊人设」后这一页会隐藏。": "Special personas never use system tools; this page is hidden for them.",
|
|
848
|
+
"设为当前": "Set active",
|
|
849
|
+
"基本": "Basic",
|
|
850
|
+
"模型与 Key": "Model & key",
|
|
851
|
+
"人设卡": "Persona card",
|
|
852
|
+
"记忆": "Memory",
|
|
853
|
+
"玩法": "Play",
|
|
854
|
+
"权限": "Permissions",
|
|
855
|
+
"OpenAI 兼容": "OpenAI-compatible",
|
|
856
|
+
"全局默认(仅“继承全局”的人设使用)": "Global defaults (for personas that inherit)",
|
|
857
|
+
"旧版 config/memory.json 不迁移、不读取;这里只作为所有人设的回落默认。": "Legacy config/memory.json is not migrated or read; this is only the fallback for all personas.",
|
|
764
858
|
"所选音色不可用,已用系统默认:{name}": "Selected voice is unavailable — using the system default: {name}",
|
|
765
859
|
"所选音色不可用,已用系统默认音色": "Selected voice is unavailable — using the system default voice",
|
|
766
860
|
// pre.54:本机音色来源 / 可下载目录骨架。
|
|
@@ -19188,6 +19282,494 @@ window.__ModuleLoader__.load({
|
|
|
19188
19282
|
return React.createElement(PetsTabPanel, null);
|
|
19189
19283
|
}
|
|
19190
19284
|
|
|
19285
|
+
// ── 内联模块:src/panel-tabs-personas.js —— 「智能大肥鱼 → 人设」:多 Persona 列表 + 7 子页(基本/模型/人设卡/记忆/声音/玩法/权限)(构建期注入;勿手改本段)──
|
|
19286
|
+
/**
|
|
19287
|
+
* panel-tabs-personas.js — 「智能大肥鱼 → 人设」:列表 + 7 子页(pre.65)。
|
|
19288
|
+
*
|
|
19289
|
+
* 设计取舍:
|
|
19290
|
+
* · 第一屏只做三件事:看当前人设、切换/进入、新建/导入;
|
|
19291
|
+
* · 每个 persona 一张卡,进入后 7 个子页(basic/model/card/memory/voice/play/permissions);
|
|
19292
|
+
* · 特殊人设(character)隐藏 permissions,并明确写“不使用系统工具”;
|
|
19293
|
+
* · Key 输入只写不读:列表只显示接口返回的掩码。
|
|
19294
|
+
*
|
|
19295
|
+
* 不依赖新 npm 包;全部用 React.createElement(构建期内联,同其它面板)。
|
|
19296
|
+
*/
|
|
19297
|
+
const PERSONA_STYLE = {
|
|
19298
|
+
card: {
|
|
19299
|
+
border: '1px solid rgba(255,255,255,.10)', borderRadius: '12px', padding: '10px 12px',
|
|
19300
|
+
margin: '8px 0', background: 'rgba(255,255,255,.025)', fontSize: '12px',
|
|
19301
|
+
},
|
|
19302
|
+
input: {
|
|
19303
|
+
width: '100%', boxSizing: 'border-box', padding: '5px 7px', borderRadius: '7px',
|
|
19304
|
+
border: '1px solid rgba(255,255,255,.18)', background: 'rgba(0,0,0,.18)', color: 'inherit', fontSize: '12px',
|
|
19305
|
+
},
|
|
19306
|
+
textarea: {
|
|
19307
|
+
width: '100%', minHeight: '64px', boxSizing: 'border-box', padding: '6px 7px', borderRadius: '7px',
|
|
19308
|
+
border: '1px solid rgba(255,255,255,.18)', background: 'rgba(0,0,0,.18)', color: 'inherit', fontSize: '12px',
|
|
19309
|
+
resize: 'vertical',
|
|
19310
|
+
},
|
|
19311
|
+
primary: {
|
|
19312
|
+
border: '1px solid rgba(120,190,255,.55)', borderRadius: '8px', padding: '5px 12px',
|
|
19313
|
+
background: 'rgba(90,160,255,.16)', color: 'inherit', cursor: 'pointer', fontSize: '12px',
|
|
19314
|
+
},
|
|
19315
|
+
ghost: {
|
|
19316
|
+
border: '1px solid rgba(255,255,255,.14)', borderRadius: '8px', padding: '4px 10px',
|
|
19317
|
+
background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: '11px',
|
|
19318
|
+
},
|
|
19319
|
+
row: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' },
|
|
19320
|
+
label: { fontSize: '11px', opacity: .78, margin: '7px 0 3px' },
|
|
19321
|
+
};
|
|
19322
|
+
|
|
19323
|
+
const PERSONA_TABS = [
|
|
19324
|
+
{ id: 'basic', label: weT('基本') },
|
|
19325
|
+
{ id: 'model', label: weT('模型与 Key') },
|
|
19326
|
+
{ id: 'card', label: weT('人设卡') },
|
|
19327
|
+
{ id: 'memory', label: weT('记忆') },
|
|
19328
|
+
{ id: 'voice', label: weT('声音') },
|
|
19329
|
+
{ id: 'play', label: weT('玩法') },
|
|
19330
|
+
{ id: 'permissions', label: weT('权限') },
|
|
19331
|
+
];
|
|
19332
|
+
|
|
19333
|
+
const unwrapPersona = (resp) => (resp && resp.data && resp.data.data) || (resp && resp.data) || {};
|
|
19334
|
+
|
|
19335
|
+
function personaInput(props) {
|
|
19336
|
+
return React.createElement('input', {
|
|
19337
|
+
type: props.type || 'text', value: props.value == null ? '' : String(props.value),
|
|
19338
|
+
placeholder: props.placeholder || '', onChange: (e) => props.onChange(e.target.value),
|
|
19339
|
+
style: { ...PERSONA_STYLE.input, ...(props.style || {}) },
|
|
19340
|
+
});
|
|
19341
|
+
}
|
|
19342
|
+
|
|
19343
|
+
function personaTextarea(props) {
|
|
19344
|
+
return React.createElement('textarea', {
|
|
19345
|
+
value: props.value == null ? '' : String(props.value), placeholder: props.placeholder || '',
|
|
19346
|
+
onChange: (e) => props.onChange(e.target.value), rows: props.rows || 4,
|
|
19347
|
+
style: { ...PERSONA_STYLE.textarea, ...(props.style || {}) },
|
|
19348
|
+
});
|
|
19349
|
+
}
|
|
19350
|
+
|
|
19351
|
+
function personaSelect(props) {
|
|
19352
|
+
return React.createElement('select', {
|
|
19353
|
+
value: props.value, onChange: (e) => props.onChange(e.target.value),
|
|
19354
|
+
style: { ...PERSONA_STYLE.input, width: 'auto', minWidth: '120px' },
|
|
19355
|
+
}, (props.options || []).map((opt) => React.createElement('option', { key: opt.value, value: opt.value }, opt.label)));
|
|
19356
|
+
}
|
|
19357
|
+
|
|
19358
|
+
function personaField(label, child, hint) {
|
|
19359
|
+
return React.createElement('div', { key: label, style: { marginBottom: '6px' } },
|
|
19360
|
+
React.createElement('div', { style: PERSONA_STYLE.label }, label),
|
|
19361
|
+
child,
|
|
19362
|
+
hint ? React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px', fontSize: '10px', opacity: .7 } }, hint) : null);
|
|
19363
|
+
}
|
|
19364
|
+
|
|
19365
|
+
function personaButton(label, onClick, opts = {}) {
|
|
19366
|
+
return React.createElement('button', {
|
|
19367
|
+
type: 'button', disabled: opts.disabled === true, onClick,
|
|
19368
|
+
style: { ...(opts.primary ? PERSONA_STYLE.primary : PERSONA_STYLE.ghost), ...(opts.style || {}) },
|
|
19369
|
+
}, label);
|
|
19370
|
+
}
|
|
19371
|
+
|
|
19372
|
+
function personaTypeLabel(type) {
|
|
19373
|
+
return type === 'character' ? weT('特殊人设') : weT('助手');
|
|
19374
|
+
}
|
|
19375
|
+
|
|
19376
|
+
function personaModeLabel(mode) {
|
|
19377
|
+
if (mode === 'roleplay') return weT('角色扮演');
|
|
19378
|
+
if (mode === 'story') return weT('互动故事');
|
|
19379
|
+
return weT('聊天');
|
|
19380
|
+
}
|
|
19381
|
+
|
|
19382
|
+
/** 弹一个隐藏 file input,读成文本或 base64。 */
|
|
19383
|
+
function personaPickFile(accept, onFile) {
|
|
19384
|
+
if (typeof document === 'undefined') return;
|
|
19385
|
+
const input = document.createElement('input');
|
|
19386
|
+
input.type = 'file';
|
|
19387
|
+
input.accept = accept;
|
|
19388
|
+
input.style.display = 'none';
|
|
19389
|
+
input.addEventListener('change', () => {
|
|
19390
|
+
const file = input.files && input.files[0];
|
|
19391
|
+
if (!file) return;
|
|
19392
|
+
const reader = new FileReader();
|
|
19393
|
+
reader.onload = () => {
|
|
19394
|
+
try { onFile(file, reader.result); } catch { /* ignore */ }
|
|
19395
|
+
try { input.remove(); } catch { /* ignore */ }
|
|
19396
|
+
};
|
|
19397
|
+
if (/\.png$/i.test(file.name) || /png/i.test(file.type)) reader.readAsDataURL(file);
|
|
19398
|
+
else reader.readAsText(file);
|
|
19399
|
+
});
|
|
19400
|
+
document.body.appendChild(input);
|
|
19401
|
+
input.click();
|
|
19402
|
+
}
|
|
19403
|
+
|
|
19404
|
+
function PersonaSection() {
|
|
19405
|
+
const [list, setList] = React.useState({ loading: true, items: [], activeId: '' });
|
|
19406
|
+
const [selected, setSelected] = React.useState(null);
|
|
19407
|
+
const [tab, setTab] = React.useState('basic');
|
|
19408
|
+
const [draft, setDraft] = React.useState(null);
|
|
19409
|
+
const [keyInfo, setKeyInfo] = React.useState({ hasKey: false, maskedKey: '' });
|
|
19410
|
+
const [keyValue, setKeyValue] = React.useState('');
|
|
19411
|
+
const [memory, setMemory] = React.useState({ loading: false, items: [], growth: [], q: '', total: 0 });
|
|
19412
|
+
const [voices, setVoices] = React.useState([]);
|
|
19413
|
+
const [busy, setBusy] = React.useState(false);
|
|
19414
|
+
const [note, setNote] = React.useState(null);
|
|
19415
|
+
const [newName, setNewName] = React.useState('');
|
|
19416
|
+
const [newType, setNewType] = React.useState('assistant');
|
|
19417
|
+
|
|
19418
|
+
const loadList = React.useCallback(async () => {
|
|
19419
|
+
setList((prev) => ({ ...prev, loading: true }));
|
|
19420
|
+
try {
|
|
19421
|
+
const doc = unwrapPersona(await apiJson('/pet-chat/personas', { parse: 'always' }));
|
|
19422
|
+
setList({ loading: false, items: Array.isArray(doc.personas) ? doc.personas : [], activeId: String(doc.activeId || '') });
|
|
19423
|
+
} catch {
|
|
19424
|
+
setList({ loading: false, items: [], activeId: '' });
|
|
19425
|
+
}
|
|
19426
|
+
}, []);
|
|
19427
|
+
|
|
19428
|
+
React.useEffect(() => { void loadList(); }, [loadList]);
|
|
19429
|
+
|
|
19430
|
+
const loadPersona = React.useCallback(async (id) => {
|
|
19431
|
+
setBusy(true);
|
|
19432
|
+
try {
|
|
19433
|
+
const doc = unwrapPersona(await apiJson('/pet-chat/personas/' + encodeURIComponent(id), { parse: 'always' }));
|
|
19434
|
+
if (!doc.persona) { setNote({ ok: false, text: weT('人设不存在') }); return; }
|
|
19435
|
+
setSelected(doc.persona);
|
|
19436
|
+
setDraft(JSON.parse(JSON.stringify(doc.persona)));
|
|
19437
|
+
setKeyInfo(doc.key || { hasKey: false, maskedKey: '' });
|
|
19438
|
+
setKeyValue('');
|
|
19439
|
+
setTab('basic');
|
|
19440
|
+
setNote(null);
|
|
19441
|
+
} catch {
|
|
19442
|
+
setNote({ ok: false, text: weT('读取人设失败') });
|
|
19443
|
+
} finally {
|
|
19444
|
+
setBusy(false);
|
|
19445
|
+
}
|
|
19446
|
+
}, []);
|
|
19447
|
+
|
|
19448
|
+
const refreshVoice = React.useCallback(() => {
|
|
19449
|
+
try { if (typeof petChatRefreshVoice === 'function') void petChatRefreshVoice(); } catch { /* ignore */ }
|
|
19450
|
+
}, []);
|
|
19451
|
+
|
|
19452
|
+
const create = async (type, mode) => {
|
|
19453
|
+
setBusy(true);
|
|
19454
|
+
try {
|
|
19455
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas', {
|
|
19456
|
+
type, mode, name: newName.trim(),
|
|
19457
|
+
}, { parse: 'always' }));
|
|
19458
|
+
if (!doc.ok) { setNote({ ok: false, text: weT('新建失败') }); return; }
|
|
19459
|
+
setNewName('');
|
|
19460
|
+
await loadList();
|
|
19461
|
+
await loadPersona(doc.persona.id);
|
|
19462
|
+
} catch {
|
|
19463
|
+
setNote({ ok: false, text: weT('新建失败') });
|
|
19464
|
+
} finally { setBusy(false); }
|
|
19465
|
+
};
|
|
19466
|
+
|
|
19467
|
+
const activate = async (id) => {
|
|
19468
|
+
setBusy(true);
|
|
19469
|
+
try {
|
|
19470
|
+
await apiPostJson('/pet-chat/personas/' + encodeURIComponent(id) + '/active', {}, { parse: 'always' });
|
|
19471
|
+
await loadList();
|
|
19472
|
+
refreshVoice();
|
|
19473
|
+
setNote({ ok: true, text: weT('已切换当前人设') });
|
|
19474
|
+
} catch {
|
|
19475
|
+
setNote({ ok: false, text: weT('切换失败') });
|
|
19476
|
+
} finally { setBusy(false); }
|
|
19477
|
+
};
|
|
19478
|
+
|
|
19479
|
+
const remove = async (id, name) => {
|
|
19480
|
+
if (typeof window !== 'undefined' && typeof window.confirm === 'function'
|
|
19481
|
+
&& !window.confirm(weT('删除「{name}」会同时删除它的全部记忆,确定吗?', { name: name || id }))) return;
|
|
19482
|
+
setBusy(true);
|
|
19483
|
+
try {
|
|
19484
|
+
const doc = unwrapPersona(await apiFetch('/pet-chat/personas/' + encodeURIComponent(id) + '?confirm=1', { method: 'DELETE', parse: 'always' }));
|
|
19485
|
+
if (doc.ok) {
|
|
19486
|
+
setSelected(null); setDraft(null);
|
|
19487
|
+
await loadList(); refreshVoice();
|
|
19488
|
+
setNote({ ok: true, text: weT('人设已删除') });
|
|
19489
|
+
} else setNote({ ok: false, text: doc.hint || weT('删除失败') });
|
|
19490
|
+
} catch { setNote({ ok: false, text: weT('删除失败') }); } finally { setBusy(false); }
|
|
19491
|
+
};
|
|
19492
|
+
|
|
19493
|
+
const save = async () => {
|
|
19494
|
+
if (!draft) return;
|
|
19495
|
+
setBusy(true);
|
|
19496
|
+
try {
|
|
19497
|
+
const payload = {
|
|
19498
|
+
name: draft.name, avatar: draft.avatar, type: draft.type, mode: draft.mode,
|
|
19499
|
+
model: draft.model, core: draft.core, express: draft.express, card: draft.card,
|
|
19500
|
+
story: draft.story, affect: draft.affect,
|
|
19501
|
+
};
|
|
19502
|
+
const doc = unwrapPersona(await apiFetch('/pet-chat/personas/' + encodeURIComponent(draft.id), {
|
|
19503
|
+
method: 'PATCH', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload), parse: 'always',
|
|
19504
|
+
}));
|
|
19505
|
+
if (doc.ok) {
|
|
19506
|
+
setSelected(doc.persona); setDraft(JSON.parse(JSON.stringify(doc.persona)));
|
|
19507
|
+
await loadList(); refreshVoice();
|
|
19508
|
+
setNote({ ok: true, text: weT('已保存') });
|
|
19509
|
+
} else setNote({ ok: false, text: doc.hint || weT('保存失败') });
|
|
19510
|
+
} catch { setNote({ ok: false, text: weT('保存失败') }); } finally { setBusy(false); }
|
|
19511
|
+
};
|
|
19512
|
+
|
|
19513
|
+
const patchDraft = (fn) => setDraft((prev) => {
|
|
19514
|
+
const next = JSON.parse(JSON.stringify(prev));
|
|
19515
|
+
fn(next);
|
|
19516
|
+
return next;
|
|
19517
|
+
});
|
|
19518
|
+
|
|
19519
|
+
const uploadCard = async (file, result) => {
|
|
19520
|
+
if (!draft) return;
|
|
19521
|
+
const isPng = /\.png$/i.test(file.name) || /png/i.test(file.type);
|
|
19522
|
+
const payload = isPng ? { base64: String(result) } : { json: String(result) };
|
|
19523
|
+
setBusy(true);
|
|
19524
|
+
try {
|
|
19525
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/import-card', payload, { parse: 'always' }));
|
|
19526
|
+
if (doc.ok) {
|
|
19527
|
+
await loadPersona(draft.id);
|
|
19528
|
+
setNote({ ok: true, text: weT('角色卡已导入') });
|
|
19529
|
+
} else setNote({ ok: false, text: doc.hint || weT('角色卡导入失败') });
|
|
19530
|
+
} catch { setNote({ ok: false, text: weT('角色卡导入失败') }); } finally { setBusy(false); }
|
|
19531
|
+
};
|
|
19532
|
+
|
|
19533
|
+
const importNew = () => {
|
|
19534
|
+
personaPickFile('.json,.png,image/png', async (file, result) => {
|
|
19535
|
+
const isPng = /\.png$/i.test(file.name) || /png/i.test(file.type);
|
|
19536
|
+
const name = String(file.name || '').replace(/\.(json|png)$/i, '') || '导入的角色';
|
|
19537
|
+
setBusy(true);
|
|
19538
|
+
try {
|
|
19539
|
+
const created = unwrapPersona(await apiPostJson('/pet-chat/personas', { type: 'character', mode: 'roleplay', name }, { parse: 'always' }));
|
|
19540
|
+
if (!created.ok) { setNote({ ok: false, text: weT('新建失败') }); return; }
|
|
19541
|
+
const id = created.persona.id;
|
|
19542
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(id) + '/import-card', isPng ? { base64: String(result) } : { json: String(result) }, { parse: 'always' }));
|
|
19543
|
+
if (!doc.ok) { setNote({ ok: false, text: doc.hint || weT('角色卡导入失败') }); return; }
|
|
19544
|
+
await loadList(); await loadPersona(id);
|
|
19545
|
+
setNote({ ok: true, text: weT('角色卡已导入') });
|
|
19546
|
+
} catch { setNote({ ok: false, text: weT('角色卡导入失败') }); } finally { setBusy(false); }
|
|
19547
|
+
});
|
|
19548
|
+
};
|
|
19549
|
+
|
|
19550
|
+
const loadMemory = React.useCallback(async (id, q) => {
|
|
19551
|
+
setMemory((prev) => ({ ...prev, loading: true, q }));
|
|
19552
|
+
try {
|
|
19553
|
+
const query = q ? '&q=' + encodeURIComponent(q) : '';
|
|
19554
|
+
const doc = unwrapPersona(await apiJson('/pet-chat/personas/' + encodeURIComponent(id) + '/memory?limit=50' + query, { parse: 'always' }));
|
|
19555
|
+
setMemory({ loading: false, q, items: Array.isArray(doc.items) ? doc.items : [], growth: Array.isArray(doc.growth) ? doc.growth : [], total: Number(doc.total) || 0 });
|
|
19556
|
+
} catch { setMemory((prev) => ({ ...prev, loading: false })); }
|
|
19557
|
+
}, []);
|
|
19558
|
+
|
|
19559
|
+
const loadVoices = React.useCallback(async () => {
|
|
19560
|
+
try {
|
|
19561
|
+
const doc = unwrapPersona(await apiJson('/pet-chat/tts/voices', { parse: 'always' }));
|
|
19562
|
+
setVoices(Array.isArray(doc.voices) ? doc.voices.filter((v) => v && v.usable === true) : []);
|
|
19563
|
+
} catch { setVoices([]); }
|
|
19564
|
+
}, []);
|
|
19565
|
+
|
|
19566
|
+
React.useEffect(() => {
|
|
19567
|
+
if (!selected) return;
|
|
19568
|
+
if (tab === 'memory') void loadMemory(selected.id, '');
|
|
19569
|
+
if (tab === 'voice' && !voices.length) void loadVoices();
|
|
19570
|
+
}, [selected, tab, loadMemory, loadVoices, voices.length]);
|
|
19571
|
+
|
|
19572
|
+
if (!draft) {
|
|
19573
|
+
const active = list.items.find((item) => item.id === list.activeId) || null;
|
|
19574
|
+
const cards = list.items.map((item) => {
|
|
19575
|
+
const actions = [
|
|
19576
|
+
item.id !== list.activeId
|
|
19577
|
+
? personaButton(weT('切换'), () => { void activate(item.id); })
|
|
19578
|
+
: null,
|
|
19579
|
+
personaButton(weT('进入'), () => { void loadPersona(item.id); }),
|
|
19580
|
+
personaButton(weT('删除'), () => { void remove(item.id, item.name); }),
|
|
19581
|
+
].filter(Boolean);
|
|
19582
|
+
return React.createElement('div', {
|
|
19583
|
+
key: item.id,
|
|
19584
|
+
style: { ...PERSONA_STYLE.card, borderColor: item.id === list.activeId ? 'rgba(120,190,255,.55)' : undefined },
|
|
19585
|
+
},
|
|
19586
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
|
|
19587
|
+
React.createElement('div', null,
|
|
19588
|
+
React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } }, item.name || weT('未命名')),
|
|
19589
|
+
React.createElement('div', { style: { fontSize: '11px', opacity: .72 } },
|
|
19590
|
+
`${personaTypeLabel(item.type)} · ${personaModeLabel(item.mode)} · ${weT('记忆 {n}', { n: item.memoryCount || 0 })}`),
|
|
19591
|
+
item.id === list.activeId
|
|
19592
|
+
? React.createElement('div', { style: { fontSize: '10px', color: '#7fc4ff' } }, weT('当前使用'))
|
|
19593
|
+
: null),
|
|
19594
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row } }, actions)));
|
|
19595
|
+
});
|
|
19596
|
+
const createCard = React.createElement('div', { style: { ...PERSONA_STYLE.card, marginTop: '12px' } },
|
|
19597
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, marginBottom: '6px' } }, weT('新建人设')),
|
|
19598
|
+
React.createElement('div', { style: PERSONA_STYLE.row },
|
|
19599
|
+
personaInput({ value: newName, placeholder: weT('名字(可留空)'), onChange: setNewName, style: { width: '150px' } }),
|
|
19600
|
+
personaSelect({
|
|
19601
|
+
value: newType, onChange: setNewType,
|
|
19602
|
+
options: [{ value: 'assistant', label: weT('助手') }, { value: 'character', label: weT('特殊人设') }],
|
|
19603
|
+
}),
|
|
19604
|
+
personaButton(weT('+新建'), () => { void create(newType, newType === 'character' ? 'roleplay' : 'chat'); }, { primary: true, disabled: busy }),
|
|
19605
|
+
personaButton(weT('导入角色卡(JSON/PNG)'), importNew, { disabled: busy })));
|
|
19606
|
+
return React.createElement('div', { id: 'we-persona-section', style: { marginBottom: '14px' } },
|
|
19607
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', marginBottom: '6px' } },
|
|
19608
|
+
React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, weT('人设')),
|
|
19609
|
+
personaButton(weT('刷新'), () => { void loadList(); })),
|
|
19610
|
+
React.createElement('div', { style: PERSONA_STYLE.card },
|
|
19611
|
+
React.createElement('div', { style: { fontSize: '11px', opacity: .75 } }, weT('当前使用')),
|
|
19612
|
+
React.createElement('div', { style: { fontSize: '14px', marginTop: '2px' } },
|
|
19613
|
+
active ? `${active.name || weT('未命名')}(${personaTypeLabel(active.type)})` : weT('还没有人设'))),
|
|
19614
|
+
list.loading ? React.createElement('div', { className: 'we-picker__hint' }, weT('正在读取人设…')) : null,
|
|
19615
|
+
cards,
|
|
19616
|
+
createCard,
|
|
19617
|
+
note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '6px' } }, note.text) : null);
|
|
19618
|
+
}
|
|
19619
|
+
|
|
19620
|
+
const p = draft;
|
|
19621
|
+
const isCharacter = p.type === 'character';
|
|
19622
|
+
const tabList = PERSONA_TABS.filter((item) => item.id !== 'permissions' || !isCharacter);
|
|
19623
|
+
const saveRow = React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
|
|
19624
|
+
personaButton(weT('保存'), () => { void save(); }, { primary: true, disabled: busy }),
|
|
19625
|
+
personaButton(weT('返回列表'), () => { setSelected(null); setDraft(null); setNote(null); void loadList(); }));
|
|
19626
|
+
|
|
19627
|
+
const basicPage = React.createElement('div', null,
|
|
19628
|
+
personaField(weT('名字'), personaInput({ value: p.name, onChange: (v) => patchDraft((d) => { d.name = v; }) })),
|
|
19629
|
+
personaField(weT('头像(URL / emoji / 留空)'), personaInput({ value: p.avatar, onChange: (v) => patchDraft((d) => { d.avatar = v; }) })),
|
|
19630
|
+
personaField(weT('类型'), personaSelect({
|
|
19631
|
+
value: p.type, onChange: (v) => patchDraft((d) => { d.type = v; }),
|
|
19632
|
+
options: [{ value: 'assistant', label: weT('助手(可用系统工具)') }, { value: 'character', label: weT('特殊人设(不使用系统工具)') }],
|
|
19633
|
+
})),
|
|
19634
|
+
personaField(weT('模式'), personaSelect({
|
|
19635
|
+
value: p.mode, onChange: (v) => patchDraft((d) => { d.mode = v; }),
|
|
19636
|
+
options: [{ value: 'chat', label: weT('聊天') }, { value: 'roleplay', label: weT('角色扮演') }, { value: 'story', label: weT('互动故事') }],
|
|
19637
|
+
})),
|
|
19638
|
+
isCharacter ? React.createElement('div', { className: 'we-picker__hint' }, weT('特殊人设不使用任何系统工具。')) : null);
|
|
19639
|
+
|
|
19640
|
+
const modelPage = React.createElement('div', null,
|
|
19641
|
+
personaField(weT('接口协议'), personaSelect({
|
|
19642
|
+
value: p.model.provider || 'inherit', onChange: (v) => patchDraft((d) => { d.model.provider = v; }),
|
|
19643
|
+
options: [{ value: 'inherit', label: weT('继承全局') }, { value: 'openai', label: weT('OpenAI 兼容') }, { value: 'ollama', label: 'Ollama' }],
|
|
19644
|
+
})),
|
|
19645
|
+
personaField(weT('接口地址'), personaInput({ value: p.model.baseUrl, placeholder: 'https://api.deepseek.com', onChange: (v) => patchDraft((d) => { d.model.baseUrl = v; }) })),
|
|
19646
|
+
personaField(weT('模型名'), personaInput({ value: p.model.model, placeholder: 'deepseek-chat', onChange: (v) => patchDraft((d) => { d.model.model = v; }) })),
|
|
19647
|
+
personaField(weT('温度'), personaInput({ type: 'number', value: p.model.temperature, onChange: (v) => patchDraft((d) => { d.model.temperature = Number(v); }) })),
|
|
19648
|
+
personaField(weT('Key') + (keyInfo.hasKey ? `(已保存:${keyInfo.maskedKey})` : ''),
|
|
19649
|
+
React.createElement('div', { style: PERSONA_STYLE.row },
|
|
19650
|
+
personaInput({ type: 'password', value: keyValue, placeholder: weT('只写不读;留空不修改'), onChange: setKeyValue, style: { flex: 1 } }),
|
|
19651
|
+
personaButton(weT('保存 Key'), async () => {
|
|
19652
|
+
if (!keyValue.trim()) { setNote({ ok: false, text: weT('先填 Key') }); return; }
|
|
19653
|
+
setBusy(true);
|
|
19654
|
+
try {
|
|
19655
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/key', { apiKey: keyValue.trim() }, { parse: 'always' }));
|
|
19656
|
+
setKeyInfo(doc.key || keyInfo); setKeyValue('');
|
|
19657
|
+
setNote({ ok: true, text: weT('Key 已保存') });
|
|
19658
|
+
} catch { setNote({ ok: false, text: weT('Key 保存失败') }); } finally { setBusy(false); }
|
|
19659
|
+
}, { primary: true, disabled: busy }),
|
|
19660
|
+
personaButton(weT('测试'), async () => {
|
|
19661
|
+
setBusy(true);
|
|
19662
|
+
try {
|
|
19663
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/key/test', {}, { parse: 'always' }));
|
|
19664
|
+
setNote({ ok: doc.ok === true, text: doc.ok ? weT('连接成功') : (doc.message || doc.code || weT('连接失败')) });
|
|
19665
|
+
} catch { setNote({ ok: false, text: weT('连接失败') }); } finally { setBusy(false); }
|
|
19666
|
+
}, { disabled: busy }))),
|
|
19667
|
+
React.createElement('div', { className: 'we-picker__hint', style: { fontSize: '10px', opacity: .7 } }, weT('留空/继承全局时使用「全局默认」里保存的模型与 Key。')));
|
|
19668
|
+
|
|
19669
|
+
const cardPage = React.createElement('div', null,
|
|
19670
|
+
personaField(weT('核心身份'), personaTextarea({ rows: 6, value: p.core.identity, onChange: (v) => patchDraft((d) => { d.core.identity = v; }) })),
|
|
19671
|
+
personaField(weT('价值观(每行一条)'), personaTextarea({ rows: 3, value: (p.core.values || []).join('\n'), onChange: (v) => patchDraft((d) => { d.core.values = v.split('\n').map((x) => x.trim()).filter(Boolean); }) })),
|
|
19672
|
+
personaField(weT('边界(每行一条)'), personaTextarea({ rows: 3, value: (p.core.boundaries || []).join('\n'), onChange: (v) => patchDraft((d) => { d.core.boundaries = v.split('\n').map((x) => x.trim()).filter(Boolean); }) })),
|
|
19673
|
+
personaField(weT('说话习惯(每行一条)'), personaTextarea({ rows: 3, value: (p.core.speechHabits || []).join('\n'), onChange: (v) => patchDraft((d) => { d.core.speechHabits = v.split('\n').map((x) => x.trim()).filter(Boolean); }) })),
|
|
19674
|
+
personaField(weT('示例对话(空行分隔)'), personaTextarea({ rows: 4, value: (p.core.exampleDialogues || []).join('\n\n'), onChange: (v) => patchDraft((d) => { d.core.exampleDialogues = v.split(/\n{2,}/).map((x) => x.trim()).filter(Boolean); }) })),
|
|
19675
|
+
personaField(weT('世界书(JSON 数组:keys/content/priority)'), personaTextarea({
|
|
19676
|
+
rows: 4, value: JSON.stringify(p.core.worldBook || [], null, 2),
|
|
19677
|
+
onChange: (v) => patchDraft((d) => { try { d.core.worldBook = JSON.parse(v || '[]'); } catch { /* 输入中不报错 */ } }),
|
|
19678
|
+
})),
|
|
19679
|
+
personaField(weT('开场白 first_mes'), personaTextarea({ rows: 3, value: p.card.firstMes, onChange: (v) => patchDraft((d) => { d.card.firstMes = v; }) })),
|
|
19680
|
+
personaField(weT('场景 scenario'), personaTextarea({ rows: 2, value: p.card.scenario, onChange: (v) => patchDraft((d) => { d.card.scenario = v; }) })),
|
|
19681
|
+
personaField(weT('角色卡系统提示'), personaTextarea({ rows: 3, value: p.card.systemPrompt, onChange: (v) => patchDraft((d) => { d.card.systemPrompt = v; }) })),
|
|
19682
|
+
React.createElement('div', { style: PERSONA_STYLE.row },
|
|
19683
|
+
personaButton(weT('导入角色卡(JSON/PNG)'), () => personaPickFile('.json,.png,image/png', uploadCard), { disabled: busy }),
|
|
19684
|
+
personaButton(weT('导出 CCv2 JSON'), () => { try { window.open(apiUrl('/pet-chat/personas/' + encodeURIComponent(p.id) + '/export-card'), '_blank'); } catch { /* ignore */ } }),
|
|
19685
|
+
personaButton(weT('导出 PNG 卡'), () => { try { window.open(apiUrl('/pet-chat/personas/' + encodeURIComponent(p.id) + '/export-card.png'), '_blank'); } catch { /* ignore */ } })));
|
|
19686
|
+
|
|
19687
|
+
const eventCards = memory.items.map((event) => React.createElement('div', { key: event.id, style: PERSONA_STYLE.card },
|
|
19688
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
|
|
19689
|
+
React.createElement('div', { style: { fontSize: '11px' } }, new Date(event.ts).toLocaleString() + ' · ' + event.kind),
|
|
19690
|
+
personaButton(weT('删除'), async () => {
|
|
19691
|
+
try {
|
|
19692
|
+
await apiFetch('/pet-chat/personas/' + encodeURIComponent(p.id) + '/memory/' + encodeURIComponent(event.id), { method: 'DELETE', parse: 'always' });
|
|
19693
|
+
void loadMemory(p.id, memory.q || '');
|
|
19694
|
+
} catch { /* ignore */ }
|
|
19695
|
+
})),
|
|
19696
|
+
React.createElement('div', { style: { marginTop: '3px', fontSize: '12px', whiteSpace: 'pre-wrap' } }, event.text)));
|
|
19697
|
+
const growthCards = memory.growth.map((trait) => React.createElement('div', { key: trait.at + trait.text, style: PERSONA_STYLE.card },
|
|
19698
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
|
|
19699
|
+
React.createElement('div', null,
|
|
19700
|
+
React.createElement('div', null, trait.text),
|
|
19701
|
+
React.createElement('div', { style: { fontSize: '10px', opacity: .65 } }, `confidence=${trait.confidence} · ${new Date(trait.at).toLocaleString()}`)),
|
|
19702
|
+
personaButton(weT('删除'), async () => {
|
|
19703
|
+
try {
|
|
19704
|
+
await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/growth/delete', { text: trait.text }, { parse: 'always' });
|
|
19705
|
+
void loadMemory(p.id, memory.q || '');
|
|
19706
|
+
} catch { /* ignore */ }
|
|
19707
|
+
}))));
|
|
19708
|
+
const memoryPage = React.createElement('div', null,
|
|
19709
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, marginBottom: '6px' } },
|
|
19710
|
+
personaInput({ value: memory.q || '', placeholder: weT('搜索记忆…'), onChange: (v) => { void loadMemory(p.id, v); }, style: { flex: 1 } }),
|
|
19711
|
+
personaButton(weT('刷新'), () => { void loadMemory(p.id, memory.q || ''); })),
|
|
19712
|
+
React.createElement('div', { style: { fontSize: '11px', opacity: .75 } }, weT('事件 {n} 条(无上限、不过期)', { n: memory.total })),
|
|
19713
|
+
eventCards.length ? eventCards : React.createElement('div', { className: 'we-picker__hint' }, weT('还没有记忆。')),
|
|
19714
|
+
React.createElement('div', { style: { marginTop: '12px', fontSize: '13px', fontWeight: 600 } }, weT('它最近学到的')),
|
|
19715
|
+
growthCards.length ? growthCards : React.createElement('div', { className: 'we-picker__hint' }, weT('还没有成长项。')),
|
|
19716
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
|
|
19717
|
+
personaInput({ type: 'date', value: memory.rollbackDate || '', onChange: (v) => setMemory((prev) => ({ ...prev, rollbackDate: v })), style: { width: '150px' } }),
|
|
19718
|
+
personaButton(weT('回滚到这一天'), async () => {
|
|
19719
|
+
if (!memory.rollbackDate) return;
|
|
19720
|
+
setBusy(true);
|
|
19721
|
+
try {
|
|
19722
|
+
const doc = unwrapPersona(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/rollback', { date: memory.rollbackDate }, { parse: 'always' }));
|
|
19723
|
+
setNote({ ok: doc.ok === true, text: doc.ok ? weT('已回滚') : (doc.hint || weT('回滚失败')) });
|
|
19724
|
+
await loadPersona(p.id);
|
|
19725
|
+
} catch { setNote({ ok: false, text: weT('回滚失败') }); } finally { setBusy(false); }
|
|
19726
|
+
}, { disabled: busy })),
|
|
19727
|
+
note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171' } }, note.text) : null);
|
|
19728
|
+
|
|
19729
|
+
const voicePage = React.createElement('div', null,
|
|
19730
|
+
personaField(weT('音色'), personaSelect({
|
|
19731
|
+
value: p.express.voice.name || '', onChange: (v) => patchDraft((d) => { d.express.voice.name = v; }),
|
|
19732
|
+
options: [{ value: '', label: weT('自动 / 继承') }, ...voices.map((voice) => ({ value: voice.name, label: `${voice.name}(${voice.engine || ''})` }))],
|
|
19733
|
+
})),
|
|
19734
|
+
personaField(weT('语速(-10…10)'), personaInput({ type: 'number', value: p.express.voice.rate, onChange: (v) => patchDraft((d) => { d.express.voice.rate = Number(v); }) })),
|
|
19735
|
+
personaField(weT('长度策略'), personaSelect({
|
|
19736
|
+
value: p.express.lengthPolicy, onChange: (v) => patchDraft((d) => { d.express.lengthPolicy = v; }),
|
|
19737
|
+
options: [{ value: 'adaptive', label: weT('自适应') }, { value: 'short', label: weT('短') }, { value: 'long', label: weT('长') }],
|
|
19738
|
+
})),
|
|
19739
|
+
React.createElement('div', { className: 'we-picker__hint', style: { fontSize: '10px', opacity: .7 } }, weT('语音模式由宿主按 1–3 句截断;这里保存的是该人设的音色与语速。')));
|
|
19740
|
+
|
|
19741
|
+
const playPage = React.createElement('div', null,
|
|
19742
|
+
personaField(weT('玩法模式'), personaSelect({
|
|
19743
|
+
value: p.mode, onChange: (v) => patchDraft((d) => { d.mode = v; }),
|
|
19744
|
+
options: [{ value: 'chat', label: weT('聊天') }, { value: 'roleplay', label: weT('角色扮演') }, { value: 'story', label: weT('互动故事') }],
|
|
19745
|
+
})),
|
|
19746
|
+
personaField(weT('唤醒口令'), personaInput({ value: p.card.wakeKeyword || '', placeholder: weT('例如:我回来了'), onChange: (v) => patchDraft((d) => { d.card.wakeKeyword = v; }) })),
|
|
19747
|
+
personaField(weT('故事章节'), personaInput({ value: p.story.chapter, onChange: (v) => patchDraft((d) => { d.story.chapter = v; }) })),
|
|
19748
|
+
personaField(weT('当前场景'), personaTextarea({ rows: 3, value: p.story.scene, onChange: (v) => patchDraft((d) => { d.story.scene = v; }) })),
|
|
19749
|
+
React.createElement('div', { className: 'we-picker__hint' }, weT('角色扮演与互动故事会按人设卡中的场景/开场白注入;故事模式章末给 2–3 个选项。')));
|
|
19750
|
+
|
|
19751
|
+
const permissionsPage = React.createElement('div', null,
|
|
19752
|
+
React.createElement('div', { style: { fontSize: '12px' } }, weT('助手人设可以使用系统工具(换壁纸、提醒、桌宠设置等)。')),
|
|
19753
|
+
React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '4px' } }, weT('特殊人设不使用任何系统工具;切换到「特殊人设」后这一页会隐藏。')));
|
|
19754
|
+
|
|
19755
|
+
const pages = { basic: basicPage, model: modelPage, card: cardPage, memory: memoryPage, voice: voicePage, play: playPage, permissions: permissionsPage };
|
|
19756
|
+
return React.createElement('div', { id: 'we-persona-detail', style: { marginBottom: '14px' } },
|
|
19757
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
|
|
19758
|
+
React.createElement('div', null,
|
|
19759
|
+
React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, draft.name || weT('未命名')),
|
|
19760
|
+
React.createElement('div', { style: { fontSize: '11px', opacity: .75 } }, `${personaTypeLabel(draft.type)} · ${personaModeLabel(draft.mode)}`)),
|
|
19761
|
+
React.createElement('div', { style: PERSONA_STYLE.row },
|
|
19762
|
+
draft.id !== list.activeId ? personaButton(weT('设为当前'), () => { void activate(draft.id); }, { primary: true }) : null,
|
|
19763
|
+
personaButton(weT('返回列表'), () => { setSelected(null); setDraft(null); void loadList(); }))),
|
|
19764
|
+
React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px', gap: '4px' } },
|
|
19765
|
+
tabList.map((item) => personaButton(item.label, () => setTab(item.id), {
|
|
19766
|
+
style: tab === item.id ? { borderColor: 'rgba(120,190,255,.7)' } : {},
|
|
19767
|
+
}))),
|
|
19768
|
+
React.createElement('div', { style: { marginTop: '8px' } }, pages[tab] || basicPage),
|
|
19769
|
+
saveRow,
|
|
19770
|
+
note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '5px' } }, note.text) : null);
|
|
19771
|
+
}
|
|
19772
|
+
|
|
19191
19773
|
// ── 内联模块:src/panel-tabs-assistant.js —— 「智能大肥鱼」一级设置项(pre.51):独立页面承载桌宠语音助手表单(Key/名字/称呼/音色/工作能力)(构建期注入;勿手改本段)──
|
|
19192
19774
|
/**
|
|
19193
19775
|
* panel-tabs-assistant.js — 「智能大肥鱼」一级设置项(v0.2 三分页)。
|
|
@@ -20265,6 +20847,10 @@ window.__ModuleLoader__.load({
|
|
|
20265
20847
|
function AssistantSection() {
|
|
20266
20848
|
return React.createElement('div', { className: 'we-assistant-section', style: { padding: '4px 2px' } },
|
|
20267
20849
|
React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, weT('智能大肥鱼')),
|
|
20850
|
+
React.createElement(PersonaSection, null),
|
|
20851
|
+
React.createElement('div', { style: { fontSize: '12px', fontWeight: 600, margin: '12px 0 2px' } }, weT('全局默认(仅“继承全局”的人设使用)')),
|
|
20852
|
+
React.createElement('div', { className: 'we-picker__hint', style: { fontSize: '10px', opacity: .7, marginBottom: '4px' } },
|
|
20853
|
+
weT('旧版 config/memory.json 不迁移、不读取;这里只作为所有人设的回落默认。')),
|
|
20268
20854
|
React.createElement(PetChatSettings, null),
|
|
20269
20855
|
);
|
|
20270
20856
|
}
|
|
@@ -23144,10 +23730,15 @@ window.__ModuleLoader__.load({
|
|
|
23144
23730
|
* 读不到就保持“不静音”,宁可多念一句,也不要让用户以为朗读坏了。
|
|
23145
23731
|
*/
|
|
23146
23732
|
let petChatVoice = { name: '', muted: false, rate: 0, continuous: true };
|
|
23733
|
+
/** pre.65:本轮输入方式决定长度策略(语音 1–3 句;文字可长)。 */
|
|
23734
|
+
let petChatInputMode = 'text';
|
|
23735
|
+
/** 当前 active persona(只用于提示/排障;宿主以 index.active 为准,避免切换后发旧 id)。 */
|
|
23736
|
+
let petChatPersonaId = '';
|
|
23147
23737
|
async function petChatRefreshVoice() {
|
|
23148
23738
|
try {
|
|
23149
23739
|
const resp = await apiJson('/pet-chat/state', { parse: 'always' });
|
|
23150
23740
|
const doc = (resp && resp.data) || {};
|
|
23741
|
+
if (doc.persona && doc.persona.id) petChatPersonaId = String(doc.persona.id);
|
|
23151
23742
|
if (doc.voice && typeof doc.voice === 'object') {
|
|
23152
23743
|
petChatVoice = {
|
|
23153
23744
|
name: String(doc.voice.name || ''),
|
|
@@ -23594,7 +24185,7 @@ window.__ModuleLoader__.load({
|
|
|
23594
24185
|
/** 语音输入(v0.1):前端不碰麦克风 —— 宿主用 ffmpeg 录,这里只发请求、收文本。 */
|
|
23595
24186
|
const petVoiceIn = petVoiceInputCreate({
|
|
23596
24187
|
// barge-in:**一开录就先停朗读**(判据 verify-voice-tts 断言这个顺序)
|
|
23597
|
-
onBeforeRecord: () => { petSpeakStop(); },
|
|
24188
|
+
onBeforeRecord: () => { petChatInputMode = 'voice'; petSpeakStop(); },
|
|
23598
24189
|
postRecord: async () => {
|
|
23599
24190
|
// pre.62:ffmpeg 不在包里,首次点麦可能在下载。宿主回 ffmpeg-preparing+percent;
|
|
23600
24191
|
// 这里在状态条显示进度并自动重试 /record(下载在宿主后台继续),不显示“没听到声音”。
|
|
@@ -23640,7 +24231,12 @@ window.__ModuleLoader__.load({
|
|
|
23640
24231
|
res = await apiFetch('/pet-chat/chat', {
|
|
23641
24232
|
method: 'POST',
|
|
23642
24233
|
headers: { 'content-type': 'application/json' },
|
|
23643
|
-
body: JSON.stringify({
|
|
24234
|
+
body: JSON.stringify({
|
|
24235
|
+
text,
|
|
24236
|
+
context,
|
|
24237
|
+
// pre.65:显式输入方式让宿主做“语音 1–3 句 / 文字可长”的长度策略。
|
|
24238
|
+
inputMode: petChatInputMode === 'voice' ? 'voice' : 'text',
|
|
24239
|
+
}),
|
|
23644
24240
|
// ⚠️ 必须 parse:'none'。默认路径会 await response.json(),
|
|
23645
24241
|
// 那会把 SSE 流**整个消费掉**(等到生成结束、再解析失败),
|
|
23646
24242
|
// 之后 res.response.body 已 used ⇒ getReader() 抛错 ⇒ 气泡一个字都不出。
|
|
@@ -23672,8 +24268,8 @@ window.__ModuleLoader__.load({
|
|
|
23672
24268
|
const enqueueSpeech = (piece) => {
|
|
23673
24269
|
const line = String(piece || '').trim();
|
|
23674
24270
|
if (!line) return;
|
|
23675
|
-
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10
|
|
23676
|
-
if (petSpeak(line, { rate: petChatSpeechRate })) queuedSpeech += 1;
|
|
24271
|
+
// v2:本轮语速由宿主 meta 给(夜间/疲惫 -1 = -10%);再叠加当前人设的 voice.rate。
|
|
24272
|
+
if (petSpeak(line, { rate: petChatSpeechRate + (Number(petChatVoice.rate) || 0) })) queuedSpeech += 1;
|
|
23677
24273
|
};
|
|
23678
24274
|
const reader = stream.body.getReader();
|
|
23679
24275
|
const decoder = new TextDecoder();
|
|
@@ -23820,6 +24416,7 @@ window.__ModuleLoader__.load({
|
|
|
23820
24416
|
// 新的一轮 = 先掐掉上一轮还在念的(与录音入口同一条 barge-in 纪律)
|
|
23821
24417
|
petSpeakStop();
|
|
23822
24418
|
petChatVoiceAbort = false;
|
|
24419
|
+
petChatInputMode = 'text';
|
|
23823
24420
|
// 打字说的文本**不上气泡**(P4 同理:气泡只显示助手的回答)。
|
|
23824
24421
|
// 这里只把状态切成"思考中",等 SSE 的 delta 逐字填进来。
|
|
23825
24422
|
petBubble.setState('think');
|
|
@@ -23976,7 +24573,7 @@ window.__ModuleLoader__.load({
|
|
|
23976
24573
|
window.__dshFoliaPet = {
|
|
23977
24574
|
speak: (text, speech) => petSpeak(text, speech || {}),
|
|
23978
24575
|
stop: () => petSpeakStop(),
|
|
23979
|
-
chat: (text) => petVoiceIn.postChat(String(text || '')),
|
|
24576
|
+
chat: (text) => { petChatInputMode = 'text'; return petVoiceIn.postChat(String(text || '')); },
|
|
23980
24577
|
isSpeaking: () => petTts.isSpeaking(),
|
|
23981
24578
|
};
|
|
23982
24579
|
} catch { /* 被别的插件占用就只保留事件通道 */ }
|