dsh-folia 4.26.0-pre.65 → 4.26.0-pre.67

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 CHANGED
@@ -19282,23 +19282,26 @@ window.__ModuleLoader__.load({
19282
19282
  return React.createElement(PetsTabPanel, null);
19283
19283
  }
19284
19284
 
19285
- // ── 内联模块:src/panel-tabs-personas.js —— 「智能大肥鱼 → 人设」:多 Persona 列表 + 7 子页(基本/模型/人设卡/记忆/声音/玩法/权限)(构建期注入;勿手改本段)──
19285
+ // ── 内联模块:src/panel-tabs-personas.js —— 「智能大肥鱼 → 人设」v2:三页签列表 + 全局默认弹窗 + 助手向导 + 卡片库 + 文档卡片化 + 类型裁剪详情(构建期注入;勿手改本段)──
19286
19286
  /**
19287
- * panel-tabs-personas.js — 「智能大肥鱼 → 人设」:列表 + 7 子页(pre.65)。
19287
+ * panel-tabs-personas.js — 「智能大肥鱼 → 人设」v2(pre.65 UI v2)。
19288
19288
  *
19289
- * 设计取舍:
19290
- * · 第一屏只做三件事:看当前人设、切换/进入、新建/导入;
19291
- * · 每个 persona 一张卡,进入后 7 个子页(basic/model/card/memory/voice/play/permissions);
19292
- * · 特殊人设(character)隐藏 permissions,并明确写“不使用系统工具”;
19293
- * · Key 输入只写不读:列表只显示接口返回的掩码。
19289
+ * 信息架构:
19290
+ * · 列表:我的助手 / 特殊人设 / 卡片库 三个页签;右上角只有“全局默认”状态徽标;
19291
+ * · 列表页**没有 Key 输入**;全局 Key 只在状态徽标打开的弹窗里;
19292
+ * · 助手走三步向导;特殊人设走“导入/卡片库一键使用”;
19293
+ * · 详情子页按类型裁剪:
19294
+ * assistant: 基本 / 模型与 Key / 记忆 / 声音 / 权限
19295
+ * character: 基本 / 模型与 Key / 人设卡 / 剧情 / 声音
19294
19296
  *
19295
- * 不依赖新 npm 包;全部用 React.createElement(构建期内联,同其它面板)。
19297
+ * 全部 React.createElement(构建期内联),不新增 npm 依赖。
19296
19298
  */
19297
19299
  const PERSONA_STYLE = {
19298
19300
  card: {
19299
19301
  border: '1px solid rgba(255,255,255,.10)', borderRadius: '12px', padding: '10px 12px',
19300
19302
  margin: '8px 0', background: 'rgba(255,255,255,.025)', fontSize: '12px',
19301
19303
  },
19304
+ cardActive: { borderColor: 'rgba(120,190,255,.65)', boxShadow: '0 0 0 1px rgba(120,190,255,.15) inset' },
19302
19305
  input: {
19303
19306
  width: '100%', boxSizing: 'border-box', padding: '5px 7px', borderRadius: '7px',
19304
19307
  border: '1px solid rgba(255,255,255,.18)', background: 'rgba(0,0,0,.18)', color: 'inherit', fontSize: '12px',
@@ -19316,26 +19319,49 @@ window.__ModuleLoader__.load({
19316
19319
  border: '1px solid rgba(255,255,255,.14)', borderRadius: '8px', padding: '4px 10px',
19317
19320
  background: 'transparent', color: 'inherit', cursor: 'pointer', fontSize: '11px',
19318
19321
  },
19322
+ danger: {
19323
+ border: '1px solid rgba(248,113,113,.35)', borderRadius: '8px', padding: '4px 10px',
19324
+ background: 'rgba(248,113,113,.08)', color: 'inherit', cursor: 'pointer', fontSize: '11px',
19325
+ },
19319
19326
  row: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' },
19320
19327
  label: { fontSize: '11px', opacity: .78, margin: '7px 0 3px' },
19328
+ badge: {
19329
+ display: 'inline-block', padding: '1px 7px', borderRadius: '999px', fontSize: '10px',
19330
+ border: '1px solid rgba(255,255,255,.18)', background: 'rgba(255,255,255,.04)', marginLeft: '5px',
19331
+ },
19332
+ badgeOk: { borderColor: 'rgba(74,222,128,.45)', color: '#86efac' },
19333
+ badgeWarn: { borderColor: 'rgba(251,191,36,.45)', color: '#fcd34d' },
19321
19334
  };
19322
19335
 
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('权限') },
19336
+ const PERSONA_BASE_TABS = [
19337
+ { id: 'basic', label: '基本' },
19338
+ { id: 'model', label: '模型与 Key' },
19339
+ { id: 'memory', label: '记忆' },
19340
+ { id: 'voice', label: '声音' },
19341
+ { id: 'permissions', label: '权限' },
19342
+ ];
19343
+ const CHARACTER_TABS = [
19344
+ { id: 'basic', label: '基本' },
19345
+ { id: 'model', label: '模型与 Key' },
19346
+ { id: 'card', label: '人设卡' },
19347
+ { id: 'story', label: '剧情' },
19348
+ { id: 'voice', label: '声音' },
19349
+ ];
19350
+ const LIST_TABS = [
19351
+ { id: 'assistants', label: '我的助手' },
19352
+ { id: 'characters', label: '特殊人设' },
19353
+ { id: 'library', label: '卡片库' },
19331
19354
  ];
19332
19355
 
19333
- const unwrapPersona = (resp) => (resp && resp.data && resp.data.data) || (resp && resp.data) || {};
19356
+ const unwrap = (resp) => (resp && resp.data && resp.data.data) || (resp && resp.data) || {};
19357
+ const clone = (value) => JSON.parse(JSON.stringify(value));
19358
+ const personaName = (p) => String((p && p.name) || '').trim() || (p && p.type === 'character' ? '未命名角色' : '助手');
19334
19359
 
19335
19360
  function personaInput(props) {
19336
19361
  return React.createElement('input', {
19337
19362
  type: props.type || 'text', value: props.value == null ? '' : String(props.value),
19338
19363
  placeholder: props.placeholder || '', onChange: (e) => props.onChange(e.target.value),
19364
+ disabled: props.disabled === true,
19339
19365
  style: { ...PERSONA_STYLE.input, ...(props.style || {}) },
19340
19366
  });
19341
19367
  }
@@ -19357,415 +19383,704 @@ window.__ModuleLoader__.load({
19357
19383
 
19358
19384
  function personaField(label, child, hint) {
19359
19385
  return React.createElement('div', { key: label, style: { marginBottom: '6px' } },
19360
- React.createElement('div', { style: PERSONA_STYLE.label }, label),
19361
- child,
19386
+ React.createElement('div', { style: PERSONA_STYLE.label }, label), child,
19362
19387
  hint ? React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px', fontSize: '10px', opacity: .7 } }, hint) : null);
19363
19388
  }
19364
19389
 
19365
19390
  function personaButton(label, onClick, opts = {}) {
19366
19391
  return React.createElement('button', {
19367
19392
  type: 'button', disabled: opts.disabled === true, onClick,
19368
- style: { ...(opts.primary ? PERSONA_STYLE.primary : PERSONA_STYLE.ghost), ...(opts.style || {}) },
19393
+ style: { ...(opts.danger ? PERSONA_STYLE.danger : (opts.primary ? PERSONA_STYLE.primary : PERSONA_STYLE.ghost)), ...(opts.style || {}) },
19369
19394
  }, label);
19370
19395
  }
19371
19396
 
19372
- function personaTypeLabel(type) {
19373
- return type === 'character' ? weT('特殊人设') : weT('助手');
19397
+ function KeyBadge({ status }) {
19398
+ if (!status) return null;
19399
+ const ok = Boolean(status.configured);
19400
+ return React.createElement('span', {
19401
+ style: { ...PERSONA_STYLE.badge, ...(ok ? PERSONA_STYLE.badgeOk : PERSONA_STYLE.badgeWarn) },
19402
+ }, status.label || (status.mode === 'inherit' ? '继承全局' : '独立 Key'));
19374
19403
  }
19375
19404
 
19376
19405
  function personaModeLabel(mode) {
19377
- if (mode === 'roleplay') return weT('角色扮演');
19378
- if (mode === 'story') return weT('互动故事');
19379
- return weT('聊天');
19406
+ if (mode === 'roleplay') return '角色扮演';
19407
+ if (mode === 'story') return '互动故事';
19408
+ return '聊天';
19380
19409
  }
19381
19410
 
19382
- /** 弹一个隐藏 file input,读成文本或 base64。 */
19383
- function personaPickFile(accept, onFile) {
19411
+ function personaTypeLabel(type) {
19412
+ return type === 'character' ? '特殊人设' : '助手';
19413
+ }
19414
+
19415
+ function pickFile(accept, onFile) {
19384
19416
  if (typeof document === 'undefined') return;
19385
19417
  const input = document.createElement('input');
19386
- input.type = 'file';
19387
- input.accept = accept;
19388
- input.style.display = 'none';
19418
+ input.type = 'file'; input.accept = accept; input.style.display = 'none';
19389
19419
  input.addEventListener('change', () => {
19390
19420
  const file = input.files && input.files[0];
19391
19421
  if (!file) return;
19392
19422
  const reader = new FileReader();
19393
19423
  reader.onload = () => {
19394
- try { onFile(file, reader.result); } catch { /* ignore */ }
19424
+ try { onFile(file, String(reader.result || '')); } catch { /* ignore */ }
19395
19425
  try { input.remove(); } catch { /* ignore */ }
19396
19426
  };
19397
- if (/\.png$/i.test(file.name) || /png/i.test(file.type)) reader.readAsDataURL(file);
19398
- else reader.readAsText(file);
19427
+ reader.readAsDataURL(file);
19399
19428
  });
19400
19429
  document.body.appendChild(input);
19401
19430
  input.click();
19402
19431
  }
19403
19432
 
19433
+ function GlobalKeyModal({ form, setForm, keyValue, setKeyValue, info, busy, onSave, onTest, onClose, note }) {
19434
+ return React.createElement('div', {
19435
+ style: {
19436
+ position: 'fixed', inset: 0, background: 'rgba(0,0,0,.52)', zIndex: 30,
19437
+ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px',
19438
+ },
19439
+ onMouseDown: (e) => { if (e.target === e.currentTarget) onClose(); },
19440
+ },
19441
+ React.createElement('div', {
19442
+ style: {
19443
+ width: 'min(520px,92vw)', maxHeight: '86vh', overflow: 'auto', background: '#1b1d22',
19444
+ border: '1px solid rgba(255,255,255,.16)', borderRadius: '14px', padding: '14px',
19445
+ },
19446
+ },
19447
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
19448
+ React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, '全局默认'),
19449
+ personaButton('关闭', onClose)),
19450
+ React.createElement('div', { className: 'we-picker__hint', style: { margin: '2px 0 8px' } },
19451
+ '只给“继承全局”的人设使用;Key 不会出现在人设列表里。'),
19452
+ personaField('接口协议', personaSelect({
19453
+ value: form.provider || 'openai', onChange: (v) => setForm((prev) => ({ ...prev, provider: v })),
19454
+ options: [{ value: 'openai', label: 'OpenAI 兼容' }, { value: 'ollama', label: 'Ollama' }],
19455
+ })),
19456
+ personaField('接口地址', personaInput({ value: form.baseUrl || '', placeholder: 'https://api.deepseek.com', onChange: (v) => setForm((prev) => ({ ...prev, baseUrl: v })) })),
19457
+ personaField('模型名', personaInput({ value: form.model || '', placeholder: 'deepseek-chat', onChange: (v) => setForm((prev) => ({ ...prev, model: v })) })),
19458
+ personaField(info && info.hasApiKey ? `Key(已保存:${info.maskedKey || info.apiKeyMasked || '已配置'})` : 'Key',
19459
+ personaInput({ type: 'password', value: keyValue, placeholder: '留空则不修改', onChange: setKeyValue }),
19460
+ '只写不读;测试连接会使用这里填的 Key,或已保存的 Key。'),
19461
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px' } },
19462
+ personaButton('保存', onSave, { primary: true, disabled: busy }),
19463
+ personaButton('测试', onTest, { disabled: busy }),
19464
+ personaButton('取消', onClose))),
19465
+ note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '6px' } }, note.text) : null);
19466
+ }
19467
+
19404
19468
  function PersonaSection() {
19405
- const [list, setList] = React.useState({ loading: true, items: [], activeId: '' });
19469
+ const [view, setView] = React.useState('list');
19470
+ const [listTab, setListTab] = React.useState('assistants');
19471
+ const [list, setList] = React.useState({ loading: true, items: [], activeId: '', global: null });
19406
19472
  const [selected, setSelected] = React.useState(null);
19407
- const [tab, setTab] = React.useState('basic');
19408
19473
  const [draft, setDraft] = React.useState(null);
19474
+ const [detailTab, setDetailTab] = React.useState('basic');
19409
19475
  const [keyInfo, setKeyInfo] = React.useState({ hasKey: false, maskedKey: '' });
19476
+ const [keyStatus, setKeyStatus] = React.useState(null);
19477
+ const [globalInfo, setGlobalInfo] = React.useState(null);
19410
19478
  const [keyValue, setKeyValue] = React.useState('');
19411
- const [memory, setMemory] = React.useState({ loading: false, items: [], growth: [], q: '', total: 0 });
19412
- const [voices, setVoices] = React.useState([]);
19479
+ const [globalOpen, setGlobalOpen] = React.useState(false);
19480
+ const [globalForm, setGlobalForm] = React.useState({ provider: 'openai', baseUrl: '', model: '' });
19481
+ const [globalKey, setGlobalKey] = React.useState('');
19482
+ const [globalNote, setGlobalNote] = React.useState(null);
19413
19483
  const [busy, setBusy] = React.useState(false);
19414
19484
  const [note, setNote] = React.useState(null);
19415
- const [newName, setNewName] = React.useState('');
19416
- const [newType, setNewType] = React.useState('assistant');
19485
+ const [memory, setMemory] = React.useState({ loading: false, items: [], growth: [], total: 0, q: '' });
19486
+ const [voices, setVoices] = React.useState([]);
19487
+ const [wizard, setWizard] = React.useState({ step: 1, name: '', nickname: '', tone: '温柔', relation: '' });
19488
+ const [doc, setDoc] = React.useState(null);
19489
+ const [library, setLibrary] = React.useState({ loading: false, cards: [], categories: [], q: '', category: 'all' });
19490
+ const [previewCard, setPreviewCard] = React.useState(null);
19491
+ const [opening, setOpening] = React.useState(null);
19417
19492
 
19418
19493
  const loadList = React.useCallback(async () => {
19419
19494
  setList((prev) => ({ ...prev, loading: true }));
19420
19495
  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 || '') });
19496
+ const data = unwrap(await apiJson('/pet-chat/personas', { parse: 'always' }));
19497
+ setList({
19498
+ loading: false,
19499
+ items: Array.isArray(data.personas) ? data.personas : [],
19500
+ activeId: String(data.activeId || ''),
19501
+ global: data.global || null,
19502
+ });
19503
+ if (data.global) setGlobalInfo(data.global);
19423
19504
  } catch {
19424
- setList({ loading: false, items: [], activeId: '' });
19505
+ setList({ loading: false, items: [], activeId: '', global: null });
19425
19506
  }
19426
19507
  }, []);
19427
19508
 
19428
19509
  React.useEffect(() => { void loadList(); }, [loadList]);
19429
19510
 
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
19511
  const refreshVoice = React.useCallback(() => {
19449
19512
  try { if (typeof petChatRefreshVoice === 'function') void petChatRefreshVoice(); } catch { /* ignore */ }
19450
19513
  }, []);
19451
19514
 
19452
- const create = async (type, mode) => {
19515
+ const openGlobal = async () => {
19516
+ setGlobalOpen(true);
19517
+ setGlobalNote(null);
19518
+ setGlobalKey('');
19519
+ try {
19520
+ const data = unwrap(await apiJson('/pet-chat/config', { parse: 'always' }));
19521
+ setGlobalInfo(data);
19522
+ setGlobalForm({ provider: data.provider || 'openai', baseUrl: data.baseUrl || '', model: data.model || '' });
19523
+ } catch { /* leave form */ }
19524
+ };
19525
+
19526
+ const saveGlobal = async () => {
19453
19527
  setBusy(true);
19454
19528
  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('');
19529
+ const body = { provider: globalForm.provider, baseUrl: globalForm.baseUrl, model: globalForm.model };
19530
+ if (globalKey.trim()) body.apiKey = globalKey.trim();
19531
+ const data = unwrap(await apiPostJson('/pet-chat/config', body, { parse: 'always' }));
19532
+ if (data.ok === false) throw new Error(data.error || 'save-failed');
19533
+ setGlobalNote({ ok: true, text: '全局默认已保存' });
19534
+ setGlobalKey('');
19535
+ await openGlobal();
19460
19536
  await loadList();
19461
- await loadPersona(doc.persona.id);
19462
- } catch {
19463
- setNote({ ok: false, text: weT('新建失败') });
19464
- } finally { setBusy(false); }
19537
+ } catch { setGlobalNote({ ok: false, text: '保存失败' }); } finally { setBusy(false); }
19465
19538
  };
19466
19539
 
19467
- const activate = async (id) => {
19540
+ const testGlobal = async () => {
19468
19541
  setBusy(true);
19469
19542
  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); }
19543
+ const body = { provider: globalForm.provider, baseUrl: globalForm.baseUrl, model: globalForm.model };
19544
+ if (globalKey.trim()) body.apiKey = globalKey.trim();
19545
+ const data = unwrap(await apiPostJson('/pet-chat/test', body, { parse: 'always' }));
19546
+ setGlobalNote({ ok: data.ok === true, text: data.ok ? '连接成功' : (data.message || data.code || '连接失败') });
19547
+ } catch { setGlobalNote({ ok: false, text: '连接失败' }); } finally { setBusy(false); }
19477
19548
  };
19478
19549
 
19479
- const remove = async (id, name) => {
19480
- if (typeof window !== 'undefined' && typeof window.confirm === 'function'
19481
- && !window.confirm(weT('删除「{name}」会同时删除它的全部记忆,确定吗?', { name: name || id }))) return;
19550
+ const loadLibrary = React.useCallback(async (q = '', category = 'all') => {
19551
+ setLibrary((prev) => ({ ...prev, loading: true, q, category }));
19552
+ try {
19553
+ const query = `?q=${encodeURIComponent(q)}&category=${encodeURIComponent(category)}`;
19554
+ const data = unwrap(await apiJson('/pet-chat/personas/library' + query, { parse: 'always' }));
19555
+ setLibrary({ loading: false, cards: Array.isArray(data.cards) ? data.cards : [], categories: Array.isArray(data.categories) ? data.categories : [], q, category });
19556
+ } catch { setLibrary((prev) => ({ ...prev, loading: false })); }
19557
+ }, []);
19558
+
19559
+ React.useEffect(() => {
19560
+ if (view === 'list' && listTab === 'library' && !library.cards.length) void loadLibrary();
19561
+ }, [view, listTab, library.cards.length, loadLibrary]);
19562
+
19563
+ const openPersona = async (id, tab = 'basic') => {
19482
19564
  setBusy(true);
19483
19565
  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); }
19566
+ const data = unwrap(await apiJson('/pet-chat/personas/' + encodeURIComponent(id), { parse: 'always' }));
19567
+ if (!data.persona) throw new Error('not-found');
19568
+ setSelected(data.persona);
19569
+ setDraft(clone(data.persona));
19570
+ setKeyInfo(data.key || { hasKey: false, maskedKey: '' });
19571
+ setKeyStatus(data.keyStatus || null);
19572
+ setGlobalInfo(data.global || null);
19573
+ setDetailTab(tab);
19574
+ setView('detail');
19575
+ setNote(null);
19576
+ } catch { setNote({ ok: false, text: '读取人设失败' }); } finally { setBusy(false); }
19491
19577
  };
19492
19578
 
19493
- const save = async () => {
19579
+ const saveDetail = async () => {
19494
19580
  if (!draft) return;
19495
19581
  setBusy(true);
19496
19582
  try {
19497
19583
  const payload = {
19498
19584
  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,
19585
+ model: draft.model, core: draft.core, express: draft.express, card: draft.card, story: draft.story,
19501
19586
  };
19502
- const doc = unwrapPersona(await apiFetch('/pet-chat/personas/' + encodeURIComponent(draft.id), {
19587
+ const data = unwrap(await apiFetch('/pet-chat/personas/' + encodeURIComponent(draft.id), {
19503
19588
  method: 'PATCH', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload), parse: 'always',
19504
19589
  }));
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); }
19590
+ if (!data.ok) throw new Error(data.hint || 'save-failed');
19591
+ setSelected(data.persona); setDraft(clone(data.persona));
19592
+ setKeyInfo(data.key || keyInfo);
19593
+ setKeyStatus(data.keyStatus || keyStatus);
19594
+ await loadList(); refreshVoice();
19595
+ setNote({ ok: true, text: '已保存' });
19596
+ } catch { setNote({ ok: false, text: '保存失败' }); } finally { setBusy(false); }
19511
19597
  };
19512
19598
 
19513
- const patchDraft = (fn) => setDraft((prev) => {
19514
- const next = JSON.parse(JSON.stringify(prev));
19515
- fn(next);
19516
- return next;
19517
- });
19599
+ const activate = async (id) => {
19600
+ setBusy(true);
19601
+ try {
19602
+ await apiPostJson('/pet-chat/personas/' + encodeURIComponent(id) + '/active', {}, { parse: 'always' });
19603
+ await loadList(); refreshVoice();
19604
+ setNote({ ok: true, text: '已切换当前人设' });
19605
+ } catch { setNote({ ok: false, text: '切换失败' }); } finally { setBusy(false); }
19606
+ };
19518
19607
 
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) };
19608
+ const remove = async (persona) => {
19609
+ const name = personaName(persona);
19610
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function'
19611
+ && !window.confirm(`删除「${name}」会同时删除它的全部记忆,确定吗?`)) return;
19523
19612
  setBusy(true);
19524
19613
  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); }
19614
+ const data = unwrap(await apiFetch('/pet-chat/personas/' + encodeURIComponent(persona.id) + '?confirm=1', {
19615
+ method: 'DELETE', parse: 'always',
19616
+ }));
19617
+ if (!data.ok) throw new Error(data.hint || 'delete-failed');
19618
+ if (selected && selected.id === persona.id) { setSelected(null); setDraft(null); setView('list'); }
19619
+ await loadList(); refreshVoice();
19620
+ setNote({ ok: true, text: '人设已删除' });
19621
+ } catch { setNote({ ok: false, text: '删除失败' }); } finally { setBusy(false); }
19531
19622
  };
19532
19623
 
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
- });
19624
+ const createWizard = async () => {
19625
+ setBusy(true);
19626
+ try {
19627
+ const data = unwrap(await apiPostJson('/pet-chat/personas/wizard', {
19628
+ name: wizard.name, nickname: wizard.nickname, tone: wizard.tone, relation: wizard.relation,
19629
+ }, { parse: 'always' }));
19630
+ if (!data.ok) throw new Error(data.hint || 'create-failed');
19631
+ await loadList();
19632
+ setWizard({ step: 1, name: '', nickname: '', tone: '温柔', relation: '' });
19633
+ setOpening({ title: `已创建「${personaName(data.persona)}」`, text: data.opening || '', kind: 'assistant' });
19634
+ await openPersona(data.persona.id);
19635
+ } catch { setNote({ ok: false, text: '创建助手失败' }); } finally { setBusy(false); }
19636
+ };
19637
+
19638
+ const useLibrary = async (card) => {
19639
+ setBusy(true);
19640
+ try {
19641
+ const data = unwrap(await apiPostJson('/pet-chat/personas/library/' + encodeURIComponent(card.id) + '/use', {}, { parse: 'always' }));
19642
+ if (!data.ok) throw new Error(data.hint || 'use-failed');
19643
+ setPreviewCard(null); setListTab('characters'); setView('list');
19644
+ setOpening({ title: `已唤醒「${personaName(data.persona)}」`, text: data.opening || '', kind: 'character' });
19645
+ await loadList(); refreshVoice();
19646
+ } catch { setNote({ ok: false, text: '使用卡片失败' }); } finally { setBusy(false); }
19647
+ };
19648
+
19649
+ const importDocument = (file, dataUrl) => {
19650
+ const base64 = String(dataUrl).split(',')[1] || '';
19651
+ setBusy(true); setDoc({ loading: true, fileName: file.name, card: null, text: '', warnings: [] });
19652
+ apiPostJson('/pet-chat/personas/import-document', {
19653
+ fileName: file.name, mime: file.type || '', base64,
19654
+ }, { parse: 'always' }).then((resp) => {
19655
+ const data = unwrap(resp);
19656
+ if (!data.ok) throw new Error(data.hint || 'import-failed');
19657
+ setDoc({ loading: false, fileName: file.name, card: data.card, text: data.text || '', warnings: data.warnings || [], usedModel: data.usedModel, kind: data.kind });
19658
+ setView('import');
19659
+ }).catch(() => setDoc({ loading: false, fileName: file.name, card: null, text: '', warnings: [], error: true }))
19660
+ .finally(() => setBusy(false));
19661
+ };
19662
+
19663
+ const saveDoc = async () => {
19664
+ if (!doc || !doc.card) return;
19665
+ setBusy(true);
19666
+ try {
19667
+ const card = clone(doc.card);
19668
+ if (doc.worldBookText !== undefined) {
19669
+ try { card.data.character_book = { entries: JSON.parse(doc.worldBookText || '[]') }; } catch { throw new Error('world-book-json'); }
19670
+ }
19671
+ const data = unwrap(await apiPostJson('/pet-chat/personas/from-draft', {
19672
+ card, mode: doc.mode || 'roleplay', fileName: doc.fileName, rawText: doc.text, active: true,
19673
+ }, { parse: 'always' }));
19674
+ if (!data.ok) throw new Error(data.hint || 'save-failed');
19675
+ setDoc(null);
19676
+ setOpening({ title: `已收下「${personaName(data.persona)}」`, text: data.opening || '', kind: 'character' });
19677
+ await loadList(); refreshVoice();
19678
+ await openPersona(data.persona.id);
19679
+ } catch { setNote({ ok: false, text: '保存卡片失败' }); } finally { setBusy(false); }
19548
19680
  };
19549
19681
 
19550
- const loadMemory = React.useCallback(async (id, q) => {
19682
+ const loadMemory = React.useCallback(async (id, q = '') => {
19551
19683
  setMemory((prev) => ({ ...prev, loading: true, q }));
19552
19684
  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 });
19685
+ const data = unwrap(await apiJson('/pet-chat/personas/' + encodeURIComponent(id) + '/memory?limit=50&q=' + encodeURIComponent(q), { parse: 'always' }));
19686
+ setMemory({ loading: false, q, items: Array.isArray(data.items) ? data.items : [], growth: Array.isArray(data.growth) ? data.growth : [], total: Number(data.total) || 0 });
19556
19687
  } catch { setMemory((prev) => ({ ...prev, loading: false })); }
19557
19688
  }, []);
19558
19689
 
19559
19690
  const loadVoices = React.useCallback(async () => {
19560
19691
  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) : []);
19692
+ const data = unwrap(await apiJson('/pet-chat/tts/voices', { parse: 'always' }));
19693
+ setVoices(Array.isArray(data.voices) ? data.voices.filter((v) => v && v.usable === true) : []);
19563
19694
  } catch { setVoices([]); }
19564
19695
  }, []);
19565
19696
 
19566
19697
  React.useEffect(() => {
19567
19698
  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]);
19699
+ if (detailTab === 'memory') void loadMemory(selected.id, '');
19700
+ if (detailTab === 'voice' && !voices.length) void loadVoices();
19701
+ }, [selected, detailTab, loadMemory, loadVoices, voices.length]);
19571
19702
 
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 },
19703
+ const patchDraft = (fn) => setDraft((prev) => { const next = clone(prev); fn(next); return next; });
19704
+
19705
+ const saveKey = async (mode) => {
19706
+ if (!draft) return;
19707
+ setBusy(true);
19708
+ try {
19709
+ const body = { mode };
19710
+ if (keyValue.trim()) body.apiKey = keyValue.trim();
19711
+ const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/key', body, { parse: 'always' }));
19712
+ setKeyInfo(data.key || keyInfo); setKeyStatus(data.keyStatus || null); setGlobalInfo(data.global || globalInfo);
19713
+ setKeyValue('');
19714
+ setNote({ ok: true, text: mode === 'inherit' ? '已改为继承全局' : '独立 Key 已保存' });
19715
+ await loadList();
19716
+ } catch { setNote({ ok: false, text: 'Key 保存失败' }); } finally { setBusy(false); }
19717
+ };
19718
+
19719
+ const testKey = async () => {
19720
+ if (!draft) return;
19721
+ setBusy(true);
19722
+ try {
19723
+ const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(draft.id) + '/key/test', {}, { parse: 'always' }));
19724
+ setNote({ ok: data.ok === true, text: data.ok ? '连接成功' : (data.message || data.code || '连接失败') });
19725
+ } catch { setNote({ ok: false, text: '连接失败' }); } finally { setBusy(false); }
19726
+ };
19727
+
19728
+ const listHeader = (title, extra) => React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', marginBottom: '6px' } },
19729
+ React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, title),
19730
+ React.createElement('div', { style: PERSONA_STYLE.row }, extra));
19731
+
19732
+ const globalBadge = () => {
19733
+ const has = Boolean(list.global && list.global.hasKey);
19734
+ return personaButton(`⚙ 全局默认 ${has ? '已配置' : '未配置'}`,
19735
+ () => { void openGlobal(); },
19736
+ { style: { borderColor: has ? 'rgba(74,222,128,.45)' : 'rgba(251,191,36,.35)' } });
19737
+ };
19738
+
19739
+ const openingCard = () => {
19740
+ if (!opening) return null;
19741
+ return React.createElement('div', { style: { ...PERSONA_STYLE.card, borderColor: 'rgba(120,190,255,.55)' } },
19742
+ React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } }, opening.title),
19743
+ React.createElement('div', { style: { marginTop: '4px', whiteSpace: 'pre-wrap', lineHeight: 1.55 } }, opening.text || ''),
19744
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px' } },
19745
+ personaButton('去对话', () => {
19746
+ setOpening(null);
19747
+ try { window.dispatchEvent(new CustomEvent('we-pet-talk')); } catch { /* ignore */ }
19748
+ }, { primary: true }),
19749
+ personaButton('知道了', () => setOpening(null))));
19750
+ };
19751
+
19752
+ const personaListCard = (p) => React.createElement('div', {
19753
+ key: p.id,
19754
+ style: { ...PERSONA_STYLE.card, ...(p.id === list.activeId ? PERSONA_STYLE.cardActive : {}) },
19755
+ },
19756
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', alignItems: 'flex-start' } },
19757
+ React.createElement('div', { style: { minWidth: 0 } },
19758
+ React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } },
19759
+ personaName(p),
19760
+ p.id === list.activeId ? React.createElement('span', { style: { ...PERSONA_STYLE.badge, ...PERSONA_STYLE.badgeOk } }, '当前使用') : null,
19761
+ React.createElement(KeyBadge, { status: p.keyStatus })),
19762
+ React.createElement('div', { style: { fontSize: '11px', opacity: .72, marginTop: '2px' } },
19763
+ `${personaTypeLabel(p.type)} · ${personaModeLabel(p.mode)} · 记忆 `,
19764
+ React.createElement('a', {
19765
+ href: '#', style: { color: 'inherit', textDecoration: 'underline' },
19766
+ onClick: (e) => { e.preventDefault(); void openPersona(p.id, 'memory'); },
19767
+ }, String(p.memoryCount || 0)),
19768
+ p.growthCount ? ` · 成长 ${p.growthCount}` : ''),
19769
+ p.tags && p.tags.length
19770
+ ? React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', marginTop: '4px' } },
19771
+ p.tags.slice(0, 4).map((tag) => React.createElement('span', { key: tag, style: PERSONA_STYLE.badge }, tag)))
19772
+ : null),
19773
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'flex-end' } },
19774
+ p.id !== list.activeId ? personaButton('切换', () => { void activate(p.id); }) : null,
19775
+ personaButton('进入', () => { void openPersona(p.id); }, { primary: p.id === list.activeId }),
19776
+ personaButton('删除', () => { void remove(p); }, { danger: true }))));
19777
+
19778
+ const assistantTab = () => {
19779
+ const items = list.items.filter((p) => p.type === 'assistant');
19780
+ return React.createElement('div', null,
19781
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', margin: '4px 0 6px' } },
19782
+ React.createElement('div', { style: { fontSize: '11px', opacity: .72 } }, '从零开始养一个会记得你的助手。'),
19783
+ personaButton('+ 新建助手', () => { setWizard({ step: 1, name: '', nickname: '', tone: '温柔', relation: '' }); setView('wizard'); }, { primary: true })),
19784
+ items.length ? items.map(personaListCard) : React.createElement('div', { className: 'we-picker__hint' }, '还没有助手。点「+ 新建助手」开始。'));
19785
+ };
19786
+
19787
+ const characterTab = () => {
19788
+ const items = list.items.filter((p) => p.type === 'character');
19789
+ return React.createElement('div', null,
19790
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between', margin: '4px 0 6px' } },
19791
+ React.createElement('div', { style: { fontSize: '11px', opacity: .72 } }, '导入的角色卡,或从卡片库一键唤醒。'),
19792
+ React.createElement('div', { style: PERSONA_STYLE.row },
19793
+ personaButton('+ 导入人设', () => {
19794
+ pickFile('.docx,.md,.markdown,.txt,.json,.png', (file, dataUrl) => importDocument(file, dataUrl));
19795
+ }, { primary: true }),
19796
+ personaButton('去卡片库', () => setListTab('library')))),
19797
+ items.length ? items.map(personaListCard) : React.createElement('div', { className: 'we-picker__hint' }, '还没有特殊人设。可以导入 docx/md/txt/JSON/PNG,或从卡片库挑一个。'));
19798
+ };
19799
+
19800
+ const libraryTab = () => React.createElement('div', null,
19801
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginBottom: '6px' } },
19802
+ personaInput({ value: library.q || '', placeholder: '搜索卡片…', onChange: (v) => { void loadLibrary(v, library.category); }, style: { flex: 1, minWidth: '140px' } }),
19803
+ personaButton('刷新', () => { void loadLibrary(library.q || '', library.category); })),
19804
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '5px', marginBottom: '6px' } },
19805
+ (library.categories.length ? library.categories : [{ id: 'all', label: '全部' }, { id: 'roleplay', label: '角色扮演' }, { id: 'story', label: '互动故事' }])
19806
+ .map((cat) => personaButton(cat.label, () => { void loadLibrary(library.q || '', cat.id); }, {
19807
+ style: library.category === cat.id ? { borderColor: 'rgba(120,190,255,.65)' } : {},
19808
+ }))),
19809
+ library.loading ? React.createElement('div', { className: 'we-picker__hint' }, '正在读取卡片库…') : null,
19810
+ library.cards.length ? library.cards.map((card) => React.createElement('div', {
19811
+ key: card.id, style: { ...PERSONA_STYLE.card, padding: 0, overflow: 'hidden' },
19812
+ },
19813
+ React.createElement('div', {
19814
+ style: {
19815
+ height: '54px', background: card.cover || card.accent || 'linear-gradient(135deg,#333,#666)',
19816
+ display: 'flex', alignItems: 'center', padding: '0 12px', gap: '10px',
19585
19817
  },
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 })));
19818
+ },
19819
+ React.createElement('div', { style: { fontSize: '26px' } }, card.avatar || '🎭'),
19820
+ React.createElement('div', null,
19821
+ React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, card.title),
19822
+ React.createElement('div', { style: { fontSize: '10px', opacity: .82 } }, `${card.sourceLabel || '官方'} · v${card.version || '1.0'} · ${card.mode === 'story' ? '互动故事' : '角色扮演'}`))),
19823
+ React.createElement('div', { style: { padding: '8px 12px' } },
19824
+ React.createElement('div', { style: { fontSize: '12px', opacity: .82 } }, card.summary || card.description || ''),
19825
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', marginTop: '4px' } },
19826
+ (card.tags || []).slice(0, 5).map((tag) => React.createElement('span', { key: tag, style: PERSONA_STYLE.badge }, tag))),
19827
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '6px' } },
19828
+ personaButton('预览', () => { setPreviewCard(card); setView('library-preview'); }),
19829
+ personaButton('使用这个人设', () => { void useLibrary(card); }, { primary: true }))))) : React.createElement('div', { className: 'we-picker__hint' }, '没有匹配的卡片。'));
19830
+
19831
+ if (view === 'list') {
19606
19832
  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);
19833
+ listHeader('人设', [globalBadge(), personaButton('刷新', () => { void loadList(); })]),
19834
+ openingCard(),
19835
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', marginBottom: '2px' } },
19836
+ LIST_TABS.map((tab) => personaButton(tab.label, () => {
19837
+ setListTab(tab.id);
19838
+ if (tab.id === 'library') void loadLibrary(library.q || '', library.category);
19839
+ }, { style: listTab === tab.id ? { borderColor: 'rgba(120,190,255,.7)' } : {} }))),
19840
+ listTab === 'assistants' ? assistantTab() : (listTab === 'characters' ? characterTab() : libraryTab()),
19841
+ note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '6px' } }, note.text) : null,
19842
+ globalOpen ? React.createElement(GlobalKeyModal, {
19843
+ form: globalForm, setForm: setGlobalForm, keyValue: globalKey, setKeyValue: setGlobalKey,
19844
+ info: globalInfo, busy, onSave: () => { void saveGlobal(); }, onTest: () => { void testGlobal(); },
19845
+ onClose: () => setGlobalOpen(false), note: globalNote,
19846
+ }) : null);
19847
+ }
19848
+
19849
+ if (view === 'library-preview' && previewCard) {
19850
+ return React.createElement('div', { style: { marginBottom: '14px' } },
19851
+ listHeader('卡片预览', personaButton('返回卡片库', () => { setPreviewCard(null); setView('list'); })),
19852
+ React.createElement('div', { style: { ...PERSONA_STYLE.card, overflow: 'hidden', padding: 0 } },
19853
+ React.createElement('div', { style: { height: '100px', background: previewCard.cover || previewCard.accent, display: 'flex', alignItems: 'center', padding: '0 16px', gap: '12px' } },
19854
+ React.createElement('div', { style: { fontSize: '44px' } }, previewCard.avatar || '🎭'),
19855
+ React.createElement('div', null,
19856
+ React.createElement('div', { style: { fontSize: '18px', fontWeight: 700 } }, previewCard.title),
19857
+ React.createElement('div', { style: { fontSize: '11px', opacity: .85 } }, previewCard.subtitle || ''),
19858
+ React.createElement('div', { style: { fontSize: '10px', opacity: .75, marginTop: '2px' } }, `${previewCard.sourceLabel || '官方'} · v${previewCard.version || '1.0'}`))),
19859
+ React.createElement('div', { style: { padding: '10px 14px' } },
19860
+ React.createElement('div', { style: { fontSize: '12px', lineHeight: 1.55, whiteSpace: 'pre-wrap' } }, previewCard.description || previewCard.summary || ''),
19861
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '4px', marginTop: '6px' } },
19862
+ (previewCard.tags || []).map((tag) => React.createElement('span', { key: tag, style: PERSONA_STYLE.badge }, tag))),
19863
+ previewCard.firstMes ? personaField('开场白', React.createElement('div', { style: { ...PERSONA_STYLE.card, background: 'rgba(255,255,255,.03)', whiteSpace: 'pre-wrap' } }, previewCard.firstMes)) : null,
19864
+ React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '4px' } },
19865
+ `使用后:继承全局 Key · 推荐音色 ${previewCard.recommendedVoice || '继承全局'} · 自动设为当前人设 · 特殊人设不使用工具`),
19866
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
19867
+ personaButton('使用这个人设', () => { void useLibrary(previewCard); }, { primary: true, disabled: busy }),
19868
+ personaButton('返回', () => { setPreviewCard(null); setView('list'); })))));
19869
+ }
19870
+
19871
+ if (view === 'wizard') {
19872
+ const step = wizard.step;
19873
+ return React.createElement('div', { style: { marginBottom: '14px' } },
19874
+ listHeader('新建助手', personaButton('取消', () => setView('list'))),
19875
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, gap: '6px', marginBottom: '8px' } },
19876
+ [1, 2, 3].map((n) => React.createElement('span', {
19877
+ key: n, style: { ...PERSONA_STYLE.badge, ...(step === n ? PERSONA_STYLE.badgeOk : {}) },
19878
+ }, `第 ${n} 步`))),
19879
+ step === 1 ? React.createElement('div', null,
19880
+ personaField('名字', personaInput({ value: wizard.name, placeholder: '例如:小满', onChange: (v) => setWizard((prev) => ({ ...prev, name: v })) })),
19881
+ personaField('头像(emoji / URL,可留空)', personaInput({ value: wizard.avatar || '', onChange: (v) => setWizard((prev) => ({ ...prev, avatar: v })) }))) : null,
19882
+ step === 2 ? React.createElement('div', null,
19883
+ personaField('怎么称呼你', personaInput({ value: wizard.nickname, placeholder: '例如:老朱', onChange: (v) => setWizard((prev) => ({ ...prev, nickname: v })) })),
19884
+ personaField('语气', personaSelect({
19885
+ value: wizard.tone, onChange: (v) => setWizard((prev) => ({ ...prev, tone: v })),
19886
+ options: [{ value: '温柔', label: '温柔' }, { value: '活泼', label: '活泼' }, { value: '冷静', label: '冷静' }, { value: '毒舌', label: '毒舌' }],
19887
+ }))) : null,
19888
+ step === 3 ? React.createElement('div', null,
19889
+ personaField('你们的关系', personaInput({ value: wizard.relation, placeholder: '例如:一起生活的搭档', onChange: (v) => setWizard((prev) => ({ ...prev, relation: v })) })),
19890
+ React.createElement('div', { style: { ...PERSONA_STYLE.card, lineHeight: 1.6 } },
19891
+ `助手:${wizard.name || '未命名'} · 称呼:${wizard.nickname || '你'} · 语气:${wizard.tone}`,
19892
+ React.createElement('div', { style: { fontSize: '10px', opacity: .7, marginTop: '3px' } }, '创建后会继承全局 Key;想换模型/Key 再进详情。'))) : null,
19893
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
19894
+ step > 1 ? personaButton('上一步', () => setWizard((prev) => ({ ...prev, step: prev.step - 1 }))) : null,
19895
+ step < 3 ? personaButton('下一步', () => setWizard((prev) => ({ ...prev, step: prev.step + 1 })), { primary: true })
19896
+ : personaButton('创建助手', () => { void createWizard(); }, { primary: true, disabled: busy })),
19897
+ note ? React.createElement('div', { className: 'we-picker__hint', style: { color: '#f87171' } }, note.text) : null);
19898
+ }
19899
+
19900
+ if (view === 'import') {
19901
+ if (!doc) {
19902
+ return React.createElement('div', { style: { marginBottom: '14px' } },
19903
+ listHeader('导入人设', personaButton('返回', () => setView('list'))),
19904
+ React.createElement('div', { style: PERSONA_STYLE.card },
19905
+ React.createElement('div', { style: { fontSize: '13px', fontWeight: 600 } }, '上传人设文档或角色卡'),
19906
+ React.createElement('div', { className: 'we-picker__hint', style: { margin: '4px 0 8px' } },
19907
+ '支持 docx / md / txt / JSON / PNG;文档会抽文本、分块、卡片化,先给你预览,不会直接保存。'),
19908
+ personaButton('选择文件', () => pickFile('.docx,.md,.markdown,.txt,.json,.png', (file, dataUrl) => importDocument(file, dataUrl)), { primary: true })));
19909
+ }
19910
+ if (doc.loading) return React.createElement('div', { className: 'we-picker__hint' }, `正在读取「${doc.fileName}」并卡片化…`);
19911
+ if (!doc.card) return React.createElement('div', null, listHeader('导入人设', personaButton('返回', () => setView('list'))),
19912
+ React.createElement('div', { className: 'we-picker__hint', style: { color: '#f87171' } }, '文档读取/卡片化失败,换一份 docx/md/txt 再试。'));
19913
+ const data = doc.card.data || {};
19914
+ const setCardData = (key, value) => setDoc((prev) => { const next = clone(prev); next.card.data[key] = value; return next; });
19915
+ const entries = (data.character_book && data.character_book.entries) || [];
19916
+ return React.createElement('div', { style: { marginBottom: '14px' } },
19917
+ listHeader('预览卡片', personaButton('返回列表', () => { setDoc(null); setView('list'); })),
19918
+ React.createElement('div', { style: PERSONA_STYLE.row },
19919
+ React.createElement('div', { style: { flex: '1 1 280px', minWidth: 0 } },
19920
+ React.createElement('div', { style: { fontSize: '11px', opacity: .72, marginBottom: '3px' } }, `原文 · ${doc.fileName} · ${doc.chunks || 0} 块`),
19921
+ React.createElement('div', {
19922
+ style: { ...PERSONA_STYLE.card, maxHeight: '360px', overflow: 'auto', whiteSpace: 'pre-wrap', fontSize: '11px', opacity: .85 },
19923
+ }, String(doc.text || '').slice(0, 8000))),
19924
+ React.createElement('div', { style: { flex: '1 1 320px', minWidth: 0 } },
19925
+ React.createElement('div', { style: { fontSize: '11px', opacity: .72, marginBottom: '3px' } },
19926
+ `卡片字段 · ${doc.usedModel ? '模型卡片化' : '本地启发式'}${doc.warnings && doc.warnings.length ? ` · ${doc.warnings.join(';')}` : ''}`),
19927
+ personaField('名字', personaInput({ value: data.name || '', onChange: (v) => setCardData('name', v) })),
19928
+ personaField('设定 / 描述', personaTextarea({ rows: 5, value: data.description || '', onChange: (v) => setCardData('description', v) })),
19929
+ personaField('性格', personaTextarea({ rows: 3, value: data.personality || '', onChange: (v) => setCardData('personality', v) })),
19930
+ personaField('场景', personaTextarea({ rows: 2, value: data.scenario || '', onChange: (v) => setCardData('scenario', v) })),
19931
+ personaField('开场白 first_mes', personaTextarea({ rows: 3, value: data.first_mes || '', onChange: (v) => setCardData('first_mes', v) })),
19932
+ personaField('世界书(JSON entries)', personaTextarea({
19933
+ rows: 4, value: doc.worldBookText === undefined ? JSON.stringify(entries, null, 2) : doc.worldBookText,
19934
+ onChange: (v) => setDoc((prev) => ({ ...prev, worldBookText: v })),
19935
+ }), '保存时会使用这里的 JSON;键为 keys/content/insertion_order。'),
19936
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
19937
+ personaButton('保存为特殊人设', () => { void saveDoc(); }, { primary: true, disabled: busy }),
19938
+ personaButton('重新选文件', () => { setDoc(null); pickFile('.docx,.md,.markdown,.txt,.json,.png', (file, dataUrl) => importDocument(file, dataUrl)); })))));
19618
19939
  }
19619
19940
 
19941
+ if (!draft) {
19942
+ return React.createElement('div', { className: 'we-picker__hint' }, '人设已关闭,点「返回列表」重新打开。');
19943
+ }
19620
19944
  const p = draft;
19621
19945
  const isCharacter = p.type === 'character';
19622
- const tabList = PERSONA_TABS.filter((item) => item.id !== 'permissions' || !isCharacter);
19946
+ const tabs = isCharacter ? CHARACTER_TABS : PERSONA_BASE_TABS;
19947
+ const currentTab = tabs.some((tab) => tab.id === detailTab) ? detailTab : 'basic';
19948
+ const globalHasKey = Boolean(globalInfo && globalInfo.hasKey);
19949
+ const keyMode = p.model && p.model.apiKeyRef === 'inherit' ? 'inherit' : 'persona';
19623
19950
  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(); }));
19951
+ personaButton('保存', () => { void saveDetail(); }, { primary: true, disabled: busy }),
19952
+ personaButton('返回列表', () => { setView('list'); setSelected(null); setDraft(null); setNote(null); void loadList(); }));
19626
19953
 
19627
19954
  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);
19955
+ personaField('名字', personaInput({ value: p.name, onChange: (v) => patchDraft((d) => { d.name = v; }) })),
19956
+ personaField('头像(URL / emoji / 留空)', personaInput({ value: p.avatar, onChange: (v) => patchDraft((d) => { d.avatar = v; }) })),
19957
+ isCharacter ? React.createElement('div', null,
19958
+ personaField('玩法模式', personaSelect({
19959
+ value: p.mode, onChange: (v) => patchDraft((d) => { d.mode = v; }),
19960
+ options: [{ value: 'roleplay', label: '角色扮演' }, { value: 'story', label: '互动故事' }],
19961
+ })),
19962
+ personaField('来源', personaInput({ value: `${p.card.source || 'user'}${p.card.sourceName ? ' · ' + p.card.sourceName : ''}${p.card.version ? ' · v' + p.card.version : ''}`, onChange: () => {}, disabled: true })))
19963
+ : React.createElement('div', null,
19964
+ personaField('称呼 / 关系(写进核心身份)', personaTextarea({ rows: 4, value: p.core.identity, onChange: (v) => patchDraft((d) => { d.core.identity = v; }) })),
19965
+ personaField('说话习惯(每行一条)', 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); }) }))),
19966
+ React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '2px' } },
19967
+ isCharacter ? '特殊人设不使用任何系统工具;删除会同时删除剧情记忆。' : '助手可以使用系统工具(换壁纸、提醒、桌宠设置等)。'));
19639
19968
 
19640
19969
  const modelPage = React.createElement('div', null,
19641
- personaField(weT('接口协议'), personaSelect({
19970
+ personaField('Key 归属', personaSelect({
19971
+ value: keyMode, onChange: (v) => patchDraft((d) => { d.model.apiKeyRef = v === 'inherit' ? 'inherit' : 'vault:' + p.id; }),
19972
+ options: [{ value: 'inherit', label: `继承全局${globalHasKey ? '(已配置)' : '(全局未配置)'}` }, { value: 'persona', label: '独立 Key' }],
19973
+ })),
19974
+ keyMode === 'inherit' ? React.createElement('div', { className: 'we-picker__hint' },
19975
+ `当前使用全局默认:${globalInfo ? `${globalInfo.provider} · ${globalInfo.model}` : '未读取到'}${globalHasKey ? '' : ' · 还没有 Key'}`)
19976
+ : React.createElement('div', null,
19977
+ personaField(keyInfo.hasKey ? `独立 Key(已保存:${keyInfo.maskedKey})` : '独立 Key',
19978
+ React.createElement('div', { style: PERSONA_STYLE.row },
19979
+ personaInput({ type: 'password', value: keyValue, placeholder: '只写不读;留空不修改', onChange: setKeyValue, style: { flex: 1 } }),
19980
+ personaButton('保存 Key', () => { void saveKey('persona'); }, { primary: true, disabled: busy }),
19981
+ personaButton('清除', () => { setKeyValue(''); void saveKey('persona'); }, { danger: true }))),
19982
+ personaButton('测试独立 Key', () => { void testKey(); })),
19983
+ personaField('接口协议', personaSelect({
19642
19984
  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' }],
19985
+ options: [{ value: 'inherit', label: '继承全局' }, { value: 'openai', label: 'OpenAI 兼容' }, { value: 'ollama', label: 'Ollama' }],
19644
19986
  })),
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。')));
19987
+ personaField('接口地址(留空继承)', personaInput({ value: p.model.baseUrl, onChange: (v) => patchDraft((d) => { d.model.baseUrl = v; }) })),
19988
+ personaField('模型名(留空继承)', personaInput({ value: p.model.model, onChange: (v) => patchDraft((d) => { d.model.model = v; }) })),
19989
+ personaField('温度', personaInput({ type: 'number', value: p.model.temperature, onChange: (v) => patchDraft((d) => { d.model.temperature = Number(v); }) })));
19668
19990
 
19669
19991
  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),
19992
+ personaField('核心身份', personaTextarea({ rows: 6, value: p.core.identity, onChange: (v) => patchDraft((d) => { d.core.identity = v; }) })),
19993
+ personaField('价值观(每行一条)', 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); }) })),
19994
+ personaField('边界(每行一条)', 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); }) })),
19995
+ personaField('说话习惯(每行一条)', 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); }) })),
19996
+ personaField('示例对话(空行分隔)', 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); }) })),
19997
+ personaField('世界书(JSON 数组:keys/content/priority)', personaTextarea({
19998
+ rows: 5, value: JSON.stringify(p.core.worldBook || [], null, 2),
19677
19999
  onChange: (v) => patchDraft((d) => { try { d.core.worldBook = JSON.parse(v || '[]'); } catch { /* 输入中不报错 */ } }),
19678
20000
  })),
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; }) })),
20001
+ personaField('开场白 first_mes', personaTextarea({ rows: 3, value: p.card.firstMes, onChange: (v) => patchDraft((d) => { d.card.firstMes = v; }) })),
20002
+ personaField('场景 scenario', personaTextarea({ rows: 2, value: p.card.scenario, onChange: (v) => patchDraft((d) => { d.card.scenario = v; }) })),
20003
+ personaField('角色卡系统提示', personaTextarea({ rows: 3, value: p.card.systemPrompt, onChange: (v) => patchDraft((d) => { d.card.systemPrompt = v; }) })),
20004
+ personaField('标签(逗号分隔)', personaInput({ value: (p.card.tags || []).join(','), onChange: (v) => patchDraft((d) => { d.card.tags = v.split(/[,,]/).map((x) => x.trim()).filter(Boolean); }) })),
19682
20005
  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);
20006
+ personaButton('导出 CCv2 JSON', () => { try { window.open(apiUrl('/pet-chat/personas/' + encodeURIComponent(p.id) + '/export-card'), '_blank'); } catch { /* ignore */ } }),
20007
+ personaButton('导出 PNG 卡', () => { try { window.open(apiUrl('/pet-chat/personas/' + encodeURIComponent(p.id) + '/export-card.png'), '_blank'); } catch { /* ignore */ } })));
20008
+
20009
+ const storyPage = React.createElement('div', null,
20010
+ personaField('章节', personaInput({ value: p.story.chapter, onChange: (v) => patchDraft((d) => { d.story.chapter = v; }) })),
20011
+ personaField('当前场景', personaTextarea({ rows: 3, value: p.story.scene, onChange: (v) => patchDraft((d) => { d.story.scene = v; }) })),
20012
+ personaField('地点', personaInput({ value: p.story.location, onChange: (v) => patchDraft((d) => { d.story.location = v; }) })),
20013
+ personaField('时间', personaInput({ value: p.story.time, onChange: (v) => patchDraft((d) => { d.story.time = v; }) })),
20014
+ personaField('章节选项(每行一条)', personaTextarea({ rows: 3, value: (p.story.choices || []).join('\n'), onChange: (v) => patchDraft((d) => { d.story.choices = v.split('\n').map((x) => x.trim()).filter(Boolean); }) })),
20015
+ personaField('好感 / 信任', React.createElement('div', { style: PERSONA_STYLE.row },
20016
+ personaInput({ type: 'number', value: p.growth.bond.affection, onChange: (v) => patchDraft((d) => { d.growth.bond.affection = Number(v); }), style: { width: '90px' } }),
20017
+ personaInput({ type: 'number', value: p.growth.bond.trust, onChange: (v) => patchDraft((d) => { d.growth.bond.trust = Number(v); }), style: { width: '90px' } }))),
20018
+ React.createElement('div', { className: 'we-picker__hint' }, '剧情状态会进入特殊人设的 system prompt;世界书在「人设卡」页。'));
19728
20019
 
19729
20020
  const voicePage = React.createElement('div', null,
19730
- personaField(weT('音色'), personaSelect({
20021
+ personaField('音色', personaSelect({
19731
20022
  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 || ''})` }))],
20023
+ options: [{ value: '', label: '自动 / 继承全局' }, ...voices.map((voice) => ({ value: voice.name, label: `${voice.name}(${voice.engine || ''})` }))],
19733
20024
  })),
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({
20025
+ personaField('语速(-10…10)', personaInput({ type: 'number', value: p.express.voice.rate, onChange: (v) => patchDraft((d) => { d.express.voice.rate = Number(v); }) })),
20026
+ personaField('长度策略', personaSelect({
19736
20027
  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('长') }],
20028
+ options: [{ value: 'adaptive', label: '自适应' }, { value: 'short', label: '短' }, { value: 'long', label: '长' }],
19738
20029
  })),
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 个选项。')));
20030
+ React.createElement('div', { className: 'we-picker__hint' }, '语音模式由宿主按 1–3 句截断;这里保存该人设的音色与语速。'));
19750
20031
 
19751
20032
  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('特殊人设不使用任何系统工具;切换到「特殊人设」后这一页会隐藏。')));
20033
+ React.createElement('div', { style: { fontSize: '12px' } }, '助手人设可以使用系统工具(换壁纸、提醒、桌宠设置等)。'),
20034
+ React.createElement('div', { className: 'we-picker__hint', style: { marginTop: '4px' } }, '特殊人设没有这一页,也不能使用任何系统工具。'));
20035
+
20036
+ const memoryPage = React.createElement('div', null,
20037
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginBottom: '6px' } },
20038
+ personaInput({ value: memory.q || '', placeholder: '搜索记忆…', onChange: (v) => { void loadMemory(p.id, v); }, style: { flex: 1 } }),
20039
+ personaButton('刷新', () => { void loadMemory(p.id, memory.q || ''); })),
20040
+ React.createElement('div', { style: { fontSize: '11px', opacity: .75 } }, `事件 ${memory.total} 条(无上限、不过期)`),
20041
+ memory.items.length ? memory.items.map((event) => React.createElement('div', { key: event.id, style: PERSONA_STYLE.card },
20042
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
20043
+ React.createElement('div', { style: { fontSize: '11px' } }, `${new Date(event.ts).toLocaleString()} · ${event.kind}`),
20044
+ personaButton('删除', async () => {
20045
+ try { await apiFetch('/pet-chat/personas/' + encodeURIComponent(p.id) + '/memory/' + encodeURIComponent(event.id), { method: 'DELETE', parse: 'always' }); void loadMemory(p.id, memory.q || ''); } catch { /* ignore */ }
20046
+ })),
20047
+ React.createElement('div', { style: { marginTop: '3px', fontSize: '12px', whiteSpace: 'pre-wrap' } }, event.text)))
20048
+ : React.createElement('div', { className: 'we-picker__hint' }, '还没有记忆。'),
20049
+ React.createElement('div', { style: { marginTop: '12px', fontSize: '13px', fontWeight: 600 } }, '它最近学到的'),
20050
+ memory.growth.length ? memory.growth.map((trait) => React.createElement('div', { key: trait.at + trait.text, style: PERSONA_STYLE.card },
20051
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
20052
+ React.createElement('div', null,
20053
+ React.createElement('div', null, trait.text),
20054
+ React.createElement('div', { style: { fontSize: '10px', opacity: .65 } }, `confidence=${trait.confidence} · ${new Date(trait.at).toLocaleString()}`)),
20055
+ personaButton('删除', async () => {
20056
+ try { await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/growth/delete', { text: trait.text }, { parse: 'always' }); void loadMemory(p.id, memory.q || ''); } catch { /* ignore */ }
20057
+ })))) : React.createElement('div', { className: 'we-picker__hint' }, '还没有成长项。'),
20058
+ React.createElement('div', { style: { ...PERSONA_STYLE.row, marginTop: '8px' } },
20059
+ personaInput({ type: 'date', value: memory.rollbackDate || '', onChange: (v) => setMemory((prev) => ({ ...prev, rollbackDate: v })), style: { width: '150px' } }),
20060
+ personaButton('回滚到这一天', async () => {
20061
+ if (!memory.rollbackDate) return;
20062
+ setBusy(true);
20063
+ try {
20064
+ const data = unwrap(await apiPostJson('/pet-chat/personas/' + encodeURIComponent(p.id) + '/rollback', { date: memory.rollbackDate }, { parse: 'always' }));
20065
+ setNote({ ok: data.ok === true, text: data.ok ? '已回滚' : (data.hint || '回滚失败') });
20066
+ await openPersona(p.id, 'memory');
20067
+ } catch { setNote({ ok: false, text: '回滚失败' }); } finally { setBusy(false); }
20068
+ }, { disabled: busy })));
19754
20069
 
19755
- const pages = { basic: basicPage, model: modelPage, card: cardPage, memory: memoryPage, voice: voicePage, play: playPage, permissions: permissionsPage };
20070
+ const pages = { basic: basicPage, model: modelPage, card: cardPage, story: storyPage, memory: memoryPage, voice: voicePage, permissions: permissionsPage };
19756
20071
  return React.createElement('div', { id: 'we-persona-detail', style: { marginBottom: '14px' } },
19757
20072
  React.createElement('div', { style: { ...PERSONA_STYLE.row, justifyContent: 'space-between' } },
19758
20073
  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)}`)),
20074
+ React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, personaName(p), React.createElement(KeyBadge, { status: keyStatus })),
20075
+ React.createElement('div', { style: { fontSize: '11px', opacity: .75 } }, `${personaTypeLabel(p.type)} · ${personaModeLabel(p.mode)}`)),
19761
20076
  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(); }))),
20077
+ p.id !== list.activeId ? personaButton('设为当前', () => { void activate(p.id); }, { primary: true }) : null,
20078
+ personaButton('返回列表', () => { setView('list'); setSelected(null); setDraft(null); void loadList(); }))),
19764
20079
  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)' } : {},
20080
+ tabs.map((tab) => personaButton(tab.label, () => setDetailTab(tab.id), {
20081
+ style: currentTab === tab.id ? { borderColor: 'rgba(120,190,255,.7)' } : {},
19767
20082
  }))),
19768
- React.createElement('div', { style: { marginTop: '8px' } }, pages[tab] || basicPage),
20083
+ React.createElement('div', { style: { marginTop: '8px' } }, pages[currentTab] || basicPage),
19769
20084
  saveRow,
19770
20085
  note ? React.createElement('div', { className: 'we-picker__hint', style: { color: note.ok ? undefined : '#f87171', marginTop: '5px' } }, note.text) : null);
19771
20086
  }
@@ -20848,10 +21163,6 @@ window.__ModuleLoader__.load({
20848
21163
  return React.createElement('div', { className: 'we-assistant-section', style: { padding: '4px 2px' } },
20849
21164
  React.createElement('div', { style: { fontSize: '14px', fontWeight: 600 } }, weT('智能大肥鱼')),
20850
21165
  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 不迁移、不读取;这里只作为所有人设的回落默认。')),
20854
- React.createElement(PetChatSettings, null),
20855
21166
  );
20856
21167
  }
20857
21168