dsh-chat-comprehension 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +14 -0
- package/README.md +124 -2
- package/client.js +1731 -0
- package/cordis.patch.yml +6 -0
- package/lib/index.js +1184 -0
- package/lib/qq-cards.mjs +220 -0
- package/lib/qqbot-0.5.3-patches.json +76 -0
- package/lib/qqbot-patch.mjs +137 -0
- package/lib/qwen3-local.mjs +214 -0
- package/lib/qwen3_tts_server.py +264 -0
- package/lib/silk.mjs +116 -0
- package/lib/tts-local.mjs +286 -0
- package/lib/tts_sambert.py +38 -0
- package/lib/video.mjs +164 -0
- package/lib/voices.mjs +137 -0
- package/package.json +77 -4
package/client.js
ADDED
|
@@ -0,0 +1,1731 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-chat-comprehension —— 浏览器半侧:主界面左侧栏一个图标 + 一整页「陪伴」。
|
|
3
|
+
*
|
|
4
|
+
* 页面不自己实现引擎:人格/QQ 走 dsh-agent-md 的接口,B站 走 dsh-bili-scroll 的接口,
|
|
5
|
+
* 记忆走 dsh-world 的接口与 /api/companion/state。这里只负责把它们拼成一个入口。
|
|
6
|
+
*/
|
|
7
|
+
window.__ModuleLoader__.load({
|
|
8
|
+
id: 'dsh-chat-comprehension',
|
|
9
|
+
factory: function (require) {
|
|
10
|
+
const React = require('react')
|
|
11
|
+
const h = React.createElement
|
|
12
|
+
const { useState, useEffect, useRef, useMemo, useCallback } = React
|
|
13
|
+
|
|
14
|
+
const AG = '/api/agent-md'
|
|
15
|
+
const BILI = '/api/bili-duty'
|
|
16
|
+
const CC = '/api/companion'
|
|
17
|
+
const WORLD = '/dsh-world'
|
|
18
|
+
|
|
19
|
+
let CTX = null
|
|
20
|
+
|
|
21
|
+
function service(name) {
|
|
22
|
+
if (!CTX) return null
|
|
23
|
+
try {
|
|
24
|
+
if (typeof CTX.get === 'function') {
|
|
25
|
+
const found = CTX.get(name)
|
|
26
|
+
if (found !== undefined && found !== null) return found
|
|
27
|
+
}
|
|
28
|
+
const direct = CTX[name]
|
|
29
|
+
return direct === undefined ? null : direct
|
|
30
|
+
} catch {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function request(url, options) {
|
|
36
|
+
const res = await fetch(url, { credentials: 'same-origin', cache: 'no-store', ...(options || {}) })
|
|
37
|
+
const text = await res.text()
|
|
38
|
+
let body = null
|
|
39
|
+
try { body = text === '' ? null : JSON.parse(text) } catch { body = null }
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const error = new Error((body && (body.error || body.message)) || ('HTTP ' + res.status))
|
|
42
|
+
error.status = res.status
|
|
43
|
+
throw error
|
|
44
|
+
}
|
|
45
|
+
return body
|
|
46
|
+
}
|
|
47
|
+
const get = (url) => request(url)
|
|
48
|
+
const post = (url, body) => request(url, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'content-type': 'application/json' },
|
|
51
|
+
body: JSON.stringify(body || {}),
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const CSS = `
|
|
55
|
+
.dc-root {
|
|
56
|
+
--cy-bg: #07070f; --cy-bg-2: #0b0c1a; --cy-panel: rgba(16, 18, 36, .78); --cy-panel-solid: #11132a; --cy-sunken: rgba(5, 6, 16, .72);
|
|
57
|
+
--cy-line: rgba(0, 240, 255, .16); --cy-line-strong: rgba(0, 240, 255, .42);
|
|
58
|
+
--cy-text: #e8f6ff; --cy-dim: #a3acd2; --cy-faint: #8790b8;
|
|
59
|
+
--cy-cyan: #00f0ff; --cy-cyan-soft: rgba(0, 240, 255, .12); --cy-magenta: #ff2bd6; --cy-magenta-soft: rgba(255, 43, 214, .14);
|
|
60
|
+
--cy-yellow: #f8e45c; --cy-green: #39ffa0; --cy-red: #ff4d6d;
|
|
61
|
+
--cy-glow: 0 0 0 1px rgba(0, 240, 255, .35), 0 0 18px rgba(0, 240, 255, .28);
|
|
62
|
+
--cy-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
|
|
63
|
+
/* Apple 风:大圆角 + 连续曲率(支持 corner-shape 的浏览器里是 squircle) */
|
|
64
|
+
--r-xl: 30px; --r-lg: 22px; --r-md: 14px; --r-sm: 11px;
|
|
65
|
+
color-scheme: dark; height: 100%; overflow: auto; color: var(--cy-text);
|
|
66
|
+
background:
|
|
67
|
+
radial-gradient(900px 520px at 8% -10%, rgba(255, 43, 214, .16), transparent 60%),
|
|
68
|
+
radial-gradient(800px 600px at 105% 10%, rgba(0, 240, 255, .14), transparent 55%),
|
|
69
|
+
linear-gradient(rgba(0, 240, 255, .035) 1px, transparent 1px) 0 0 / 100% 32px,
|
|
70
|
+
linear-gradient(90deg, rgba(0, 240, 255, .035) 1px, transparent 1px) 0 0 / 32px 100%,
|
|
71
|
+
var(--cy-bg);
|
|
72
|
+
scrollbar-color: rgba(0, 240, 255, .35) transparent; scrollbar-width: thin; }
|
|
73
|
+
@supports (corner-shape: superellipse(2)) {
|
|
74
|
+
.dc-root, .dc-root *, .dc-root *::before, .dc-root *::after, .dc-toast { corner-shape: superellipse(1.8); }
|
|
75
|
+
.dc-root .dc-chip, .dc-root .dc-badge, .dc-root .dc-toggle, .dc-root .dc-toggle i, .dc-root .dc-dot, .dc-root .dc-state-dot { corner-shape: round; }
|
|
76
|
+
}
|
|
77
|
+
.dc-root :focus-visible { outline: 2px solid var(--cy-cyan); outline-offset: 2px; box-shadow: 0 0 14px rgba(0, 240, 255, .45); }
|
|
78
|
+
.dc-root ::selection { background: rgba(255, 43, 214, .35); color: #fff; }
|
|
79
|
+
.dc-page { max-width: 1120px; margin: 0 auto; padding: 28px 30px 76px; }
|
|
80
|
+
|
|
81
|
+
.dc-hero { position: relative; overflow: hidden; border-radius: var(--r-xl); padding: 28px 30px 26px; color: var(--cy-text);
|
|
82
|
+
background:
|
|
83
|
+
linear-gradient(135deg, rgba(255, 43, 214, .20), rgba(0, 240, 255, .10) 55%, rgba(7, 7, 15, 0) 80%),
|
|
84
|
+
repeating-linear-gradient(0deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 4px),
|
|
85
|
+
var(--cy-panel-solid);
|
|
86
|
+
border: 1px solid var(--cy-line-strong);
|
|
87
|
+
box-shadow: 0 0 0 1px rgba(255, 43, 214, .18) inset, 0 30px 60px -30px rgba(255, 43, 214, .45), 0 0 40px -10px rgba(0, 240, 255, .30); }
|
|
88
|
+
.dc-hero::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; pointer-events: none;
|
|
89
|
+
background: linear-gradient(90deg, transparent, var(--cy-cyan) 20%, var(--cy-magenta) 70%, transparent); opacity: .9; }
|
|
90
|
+
.dc-hero::after { content: ""; position: absolute; right: -120px; top: -160px; width: 420px; height: 420px; border-radius: 50%; pointer-events: none;
|
|
91
|
+
background: radial-gradient(circle, rgba(0, 240, 255, .22), rgba(0, 240, 255, 0) 62%); }
|
|
92
|
+
.dc-hero-top { display: flex; align-items: center; gap: 16px; position: relative; z-index: 1; }
|
|
93
|
+
.dc-avatar { width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center; color: var(--cy-cyan); flex: 0 0 auto;
|
|
94
|
+
background: rgba(0, 240, 255, .08); border: 1px solid var(--cy-line-strong); box-shadow: var(--cy-glow); }
|
|
95
|
+
.dc-hero h1 { margin: 0; font-family: var(--cy-mono); font-size: 23px; font-weight: 700; letter-spacing: .6px; overflow-wrap: anywhere;
|
|
96
|
+
color: #fff; text-shadow: 0 0 12px rgba(0, 240, 255, .55), 2px 0 0 rgba(255, 43, 214, .55); }
|
|
97
|
+
.dc-hero p { margin: 6px 0 0; font-size: 12.5px; color: var(--cy-dim); letter-spacing: .3px; }
|
|
98
|
+
.dc-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
|
|
99
|
+
.dc-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; font-size: 11.5px;
|
|
100
|
+
background: rgba(5, 6, 16, .55); border: 1px solid var(--cy-line); color: var(--cy-text); backdrop-filter: blur(8px); }
|
|
101
|
+
.dc-chip b { font-weight: 600; font-family: var(--cy-mono); color: var(--cy-cyan); }
|
|
102
|
+
.dc-dot { width: 7px; height: 7px; border-radius: 50%; background: #4a5078; }
|
|
103
|
+
.dc-dot.ok { background: var(--cy-green); box-shadow: 0 0 8px var(--cy-green); }
|
|
104
|
+
.dc-dot.warn { background: var(--cy-yellow); box-shadow: 0 0 8px var(--cy-yellow); }
|
|
105
|
+
.dc-hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; position: relative; z-index: 1; }
|
|
106
|
+
|
|
107
|
+
.dc-tabs { display: flex; gap: 4px; margin: 22px 0 18px; padding: 5px; border-radius: 18px; width: fit-content; max-width: 100%;
|
|
108
|
+
box-sizing: border-box; overflow-x: auto; scrollbar-width: none;
|
|
109
|
+
background: rgba(10, 11, 24, .82); border: 1px solid var(--cy-line); backdrop-filter: blur(12px); }
|
|
110
|
+
.dc-tabs::-webkit-scrollbar { display: none; }
|
|
111
|
+
.dc-tab { flex: 0 0 auto; white-space: nowrap; border: 1px solid transparent; background: transparent; color: var(--cy-dim); font: inherit; font-size: 12.5px;
|
|
112
|
+
padding: 8px 15px; border-radius: 13px; cursor: pointer; letter-spacing: .3px; transition: color .15s, background .15s, border-color .15s; }
|
|
113
|
+
.dc-tab:hover { color: var(--cy-text); background: rgba(0, 240, 255, .06); }
|
|
114
|
+
.dc-tab[aria-selected=true] { color: var(--cy-cyan); font-weight: 600; background: rgba(0, 240, 255, .10); border-color: var(--cy-line-strong);
|
|
115
|
+
box-shadow: 0 0 16px -4px rgba(0, 240, 255, .6), inset 0 -2px 0 var(--cy-magenta); }
|
|
116
|
+
|
|
117
|
+
.dc-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
|
|
118
|
+
.dc-grid.two { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
|
|
119
|
+
.dc-card { position: relative; min-width: 0; background: var(--cy-panel); border: 1px solid var(--cy-line);
|
|
120
|
+
border-radius: var(--r-lg); padding: 20px 20px 18px; backdrop-filter: blur(14px);
|
|
121
|
+
box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 18px 40px -28px rgba(0, 0, 0, .9); transition: border-color .2s, box-shadow .2s; }
|
|
122
|
+
.dc-card:hover { border-color: rgba(0, 240, 255, .28); box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 18px 40px -28px rgba(0, 0, 0, .9), 0 0 24px -12px rgba(0, 240, 255, .5); }
|
|
123
|
+
.dc-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
|
|
124
|
+
.dc-card-title { font-size: 13.5px; font-weight: 650; letter-spacing: .4px; color: #fff; }
|
|
125
|
+
.dc-card-title:not(:empty)::before { content: "//"; margin-right: 7px; font-family: var(--cy-mono); color: var(--cy-magenta); font-weight: 700; }
|
|
126
|
+
.dc-card-sub { margin-top: 4px; font-size: 11.5px; color: var(--cy-faint); line-height: 1.55; }
|
|
127
|
+
.dc-metric { font-family: var(--cy-mono); font-size: 30px; font-weight: 700; letter-spacing: .5px; line-height: 1.1; overflow-wrap: anywhere;
|
|
128
|
+
color: var(--cy-cyan); text-shadow: 0 0 16px rgba(0, 240, 255, .55); }
|
|
129
|
+
.dc-metric[data-loading] { color: var(--cy-faint); text-shadow: none; }
|
|
130
|
+
.dc-metric small { font-family: inherit; font-size: 12px; font-weight: 500; color: var(--cy-magenta); text-shadow: none; margin-left: 5px; }
|
|
131
|
+
.dc-metric-label { margin-top: 8px; font-size: 11.5px; color: var(--cy-dim); letter-spacing: .3px; }
|
|
132
|
+
.dc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
133
|
+
.dc-spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
|
|
134
|
+
|
|
135
|
+
.dc-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--cy-line-strong);
|
|
136
|
+
background: rgba(0, 240, 255, .05); color: var(--cy-text); font: inherit; font-size: 12px; letter-spacing: .3px;
|
|
137
|
+
padding: 8px 14px; border-radius: var(--r-md); cursor: pointer; white-space: nowrap;
|
|
138
|
+
transition: background .15s, box-shadow .15s, transform .12s, border-color .15s; }
|
|
139
|
+
.dc-btn:hover:not([disabled]) { background: rgba(0, 240, 255, .12); box-shadow: 0 0 16px -4px rgba(0, 240, 255, .7); }
|
|
140
|
+
.dc-btn:active:not([disabled]) { transform: scale(.97); }
|
|
141
|
+
.dc-btn[data-kind=primary] { color: #04050c; font-weight: 650; border-color: transparent;
|
|
142
|
+
background: linear-gradient(135deg, #00f0ff, #4fc3ff 55%, #b48cff); box-shadow: 0 0 18px -6px rgba(0, 240, 255, .9); }
|
|
143
|
+
.dc-btn[data-kind=primary]:hover:not([disabled]) { background: linear-gradient(135deg, #5cf6ff, #7fd3ff 55%, #c9a8ff); box-shadow: 0 0 22px -4px rgba(0, 240, 255, 1); }
|
|
144
|
+
.dc-btn[data-kind=ghost] { background: transparent; border-color: transparent; color: var(--cy-dim); }
|
|
145
|
+
.dc-btn[data-kind=danger] { color: var(--cy-red); border-color: rgba(255, 77, 109, .45); background: rgba(255, 77, 109, .06); }
|
|
146
|
+
.dc-btn[data-kind=danger]:hover:not([disabled]) { background: rgba(255, 77, 109, .14); box-shadow: 0 0 16px -4px rgba(255, 77, 109, .8); }
|
|
147
|
+
.dc-btn[disabled] { opacity: .38; cursor: not-allowed; box-shadow: none; }
|
|
148
|
+
.dc-hero-actions .dc-btn:not([data-kind=primary]) { background: rgba(5, 6, 16, .55); }
|
|
149
|
+
|
|
150
|
+
.dc-input, .dc-textarea, .dc-select { width: 100%; box-sizing: border-box; font: inherit; font-size: 12.5px; color: var(--cy-text);
|
|
151
|
+
background: var(--cy-sunken); border: 1px solid var(--cy-line); border-radius: var(--r-sm); padding: 9px 12px;
|
|
152
|
+
transition: border-color .15s, box-shadow .15s; }
|
|
153
|
+
.dc-input::placeholder, .dc-textarea::placeholder { color: #6a7299; }
|
|
154
|
+
.dc-select option { background: var(--cy-panel-solid); color: var(--cy-text); }
|
|
155
|
+
.dc-row > .dc-input, .dc-row > .dc-select { flex: 1 1 140px; }
|
|
156
|
+
.dc-row > .dc-input[data-narrow], .dc-row > .dc-select[data-narrow] { flex: 0 0 auto; }
|
|
157
|
+
.dc-input[disabled], .dc-textarea[disabled], .dc-select[disabled] { opacity: .5; cursor: not-allowed; }
|
|
158
|
+
.dc-input[type=file] { padding: 6px 8px; cursor: pointer; }
|
|
159
|
+
.dc-input[type=file]::file-selector-button { margin-right: 10px; padding: 6px 12px; border-radius: var(--r-sm); border: 1px solid var(--cy-line-strong);
|
|
160
|
+
background: rgba(0, 240, 255, .08); color: var(--cy-text); font: inherit; cursor: pointer; }
|
|
161
|
+
.dc-input[type=file]::file-selector-button:hover { background: rgba(0, 240, 255, .16); }
|
|
162
|
+
.dc-textarea { min-height: 260px; line-height: 1.7; resize: vertical; }
|
|
163
|
+
.dc-input:focus, .dc-textarea:focus, .dc-select:focus { outline: none; border-color: var(--cy-cyan); box-shadow: 0 0 0 3px var(--cy-cyan-soft), 0 0 18px -6px rgba(0, 240, 255, .8); }
|
|
164
|
+
.dc-label { display: block; font-size: 11.5px; color: var(--cy-dim); margin: 14px 0 7px; letter-spacing: .3px; }
|
|
165
|
+
.dc-note { font-size: 11px; color: var(--cy-faint); line-height: 1.65; }
|
|
166
|
+
.dc-note code, .dc-code { font-family: var(--cy-mono); }
|
|
167
|
+
|
|
168
|
+
.dc-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0;
|
|
169
|
+
border-bottom: 1px solid rgba(0, 240, 255, .08); }
|
|
170
|
+
.dc-switch:last-child { border-bottom: 0; }
|
|
171
|
+
.dc-switch-label { font-size: 12.5px; color: var(--cy-text); }
|
|
172
|
+
.dc-switch-note { margin-top: 3px; font-size: 11px; color: var(--cy-faint); line-height: 1.5; }
|
|
173
|
+
/* iOS 尺寸的开关:关 = 暗灰底 + 灰钮,开 = 霓虹渐变 + 发光 */
|
|
174
|
+
.dc-toggle { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; padding: 0; cursor: pointer; position: relative;
|
|
175
|
+
border: 1px solid #3a3f63; background: #1c1f38; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6); transition: background .22s, border-color .22s, box-shadow .22s; }
|
|
176
|
+
.dc-toggle[aria-checked=true] { background: linear-gradient(135deg, #00d8ff, #ff2bd6); border-color: transparent; box-shadow: 0 0 14px -2px rgba(0, 240, 255, .75); }
|
|
177
|
+
.dc-toggle i { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #8a90b2;
|
|
178
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, .5); transition: left .22s cubic-bezier(.3, .7, .4, 1.2), background .22s; }
|
|
179
|
+
.dc-toggle[aria-checked=true] i { left: 20px; background: #fff; }
|
|
180
|
+
.dc-toggle[disabled] { opacity: .4; cursor: not-allowed; }
|
|
181
|
+
.dc-switch-ctl { display: inline-flex; align-items: center; gap: 9px; flex: 0 0 auto; }
|
|
182
|
+
.dc-switch-state { min-width: 14px; text-align: right; font-family: var(--cy-mono); font-size: 11px; font-weight: 700; color: var(--cy-faint); }
|
|
183
|
+
.dc-switch-state[data-on] { color: var(--cy-cyan); text-shadow: 0 0 8px rgba(0, 240, 255, .7); }
|
|
184
|
+
|
|
185
|
+
.dc-block { background: var(--cy-sunken); border: 1px solid var(--cy-line); border-radius: 16px; overflow: hidden; transition: border-color .15s, box-shadow .15s; }
|
|
186
|
+
.dc-block[data-on] { border-color: var(--cy-cyan); box-shadow: 0 0 18px -8px rgba(0, 240, 255, .9); background: rgba(0, 240, 255, .04); }
|
|
187
|
+
.dc-block-head { display: flex; align-items: center; gap: 10px; padding: 11px 13px; cursor: pointer; border-radius: 16px; }
|
|
188
|
+
.dc-block-head:hover { background: rgba(0, 240, 255, .06); }
|
|
189
|
+
.dc-block-head:focus-visible { outline-offset: -2px; }
|
|
190
|
+
.dc-caret { width: 12px; flex: 0 0 auto; font-size: 11px; color: var(--cy-magenta); transition: transform .18s; }
|
|
191
|
+
.dc-caret[data-open] { transform: rotate(90deg); }
|
|
192
|
+
.dc-block-body { padding: 2px 13px 13px 35px; display: flex; flex-direction: column; gap: 6px; }
|
|
193
|
+
.dc-list { display: flex; flex-direction: column; gap: 8px; }
|
|
194
|
+
.dc-item { display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 16px; background: var(--cy-sunken); border: 1px solid var(--cy-line); }
|
|
195
|
+
.dc-item[data-on] { border-color: var(--cy-cyan); }
|
|
196
|
+
.dc-item[data-off] .dc-item-title { color: var(--cy-faint); }
|
|
197
|
+
.dc-item-main { flex: 1; min-width: 0; }
|
|
198
|
+
.dc-item-title { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--cy-text); }
|
|
199
|
+
.dc-item-sub { margin-top: 3px; font-size: 10.5px; color: var(--cy-faint); overflow-wrap: anywhere; }
|
|
200
|
+
.dc-code { display: block; margin-top: 5px; font-size: 10.5px; word-break: break-all; color: var(--cy-yellow); opacity: .9; }
|
|
201
|
+
.dc-badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 10px; white-space: nowrap; letter-spacing: .3px;
|
|
202
|
+
background: rgba(163, 172, 210, .10); border: 1px solid rgba(163, 172, 210, .22); color: var(--cy-dim); }
|
|
203
|
+
.dc-badge[data-tone=ok] { background: rgba(57, 255, 160, .10); border-color: rgba(57, 255, 160, .40); color: var(--cy-green); }
|
|
204
|
+
.dc-badge[data-tone=warn] { background: rgba(248, 228, 92, .10); border-color: rgba(248, 228, 92, .40); color: var(--cy-yellow); }
|
|
205
|
+
.dc-pre { margin: 0; padding: 14px; border-radius: 16px; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word;
|
|
206
|
+
font-family: var(--cy-mono); font-size: 11px; line-height: 1.65; color: #9ef7ff;
|
|
207
|
+
background: repeating-linear-gradient(0deg, rgba(0, 240, 255, .03) 0 1px, transparent 1px 3px), #04050d;
|
|
208
|
+
border: 1px solid var(--cy-line); box-shadow: inset 0 0 24px rgba(0, 240, 255, .06); }
|
|
209
|
+
.dc-qr-wrap { position: relative; display: inline-block; margin-top: 14px; }
|
|
210
|
+
.dc-qr { display: block; width: 168px; height: 168px; border-radius: 22px; background: #fff; padding: 10px;
|
|
211
|
+
border: 1px solid var(--cy-cyan); box-shadow: 0 0 0 4px rgba(0, 240, 255, .10), 0 0 26px -4px rgba(0, 240, 255, .8); transition: opacity .2s; }
|
|
212
|
+
.dc-qr-wrap[data-stale] .dc-qr { opacity: .15; box-shadow: none; border-color: var(--cy-faint); }
|
|
213
|
+
.dc-qr-mask { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; font-size: 12px; font-weight: 700;
|
|
214
|
+
font-family: var(--cy-mono); color: var(--cy-magenta); text-shadow: 0 0 10px rgba(255, 43, 214, .8); }
|
|
215
|
+
.dc-banner { display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: 16px; margin-bottom: 12px; font-size: 12px; line-height: 1.55;
|
|
216
|
+
background: rgba(248, 228, 92, .07); border: 1px solid rgba(248, 228, 92, .38); color: var(--cy-yellow); }
|
|
217
|
+
.dc-banner::before { content: "!"; flex: 0 0 auto; font-family: var(--cy-mono); font-weight: 800; }
|
|
218
|
+
.dc-banner[data-tone=err] { background: rgba(255, 77, 109, .08); border-color: rgba(255, 77, 109, .45); color: #ff8aa0; }
|
|
219
|
+
.dc-state-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cy-red); box-shadow: 0 0 8px var(--cy-red); flex: 0 0 auto; align-self: flex-start; margin-top: 5px; }
|
|
220
|
+
.dc-state-dot[data-ok] { background: var(--cy-green); box-shadow: 0 0 8px var(--cy-green); }
|
|
221
|
+
.dc-empty { padding: 24px 10px; text-align: center; font-size: 12px; color: var(--cy-faint); letter-spacing: .3px; }
|
|
222
|
+
.dc-toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; max-width: min(420px, calc(100vw - 48px)); padding: 12px 16px; border-radius: 18px;
|
|
223
|
+
font-size: 12px; line-height: 1.5; cursor: pointer; text-align: left; font-family: inherit; color: var(--cy-text);
|
|
224
|
+
background: rgba(14, 16, 34, .92); border: 1px solid var(--cy-line-strong); backdrop-filter: blur(16px);
|
|
225
|
+
box-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 0 22px -8px rgba(0, 240, 255, .8); }
|
|
226
|
+
.dc-toast[data-tone=err] { color: #ff9aae; border-color: rgba(255, 77, 109, .6); box-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 0 22px -8px rgba(255, 77, 109, .9); }
|
|
227
|
+
.dc-toast[data-tone=ok] { color: var(--cy-green); border-color: rgba(57, 255, 160, .5); }
|
|
228
|
+
.dc-split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr); align-items: start; }
|
|
229
|
+
@media (max-width: 860px) { .dc-split { grid-template-columns: minmax(0, 1fr); } .dc-page { padding: 18px 14px 60px; } .dc-hero { padding: 22px 18px; } }
|
|
230
|
+
@media (prefers-reduced-motion: reduce) { .dc-root *, .dc-toast { transition: none !important; } }
|
|
231
|
+
`
|
|
232
|
+
|
|
233
|
+
function Icon({ name, size = 16 }) {
|
|
234
|
+
const common = { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false', style: { display: 'block', flex: '0 0 auto' } }
|
|
235
|
+
if (name === 'leaf') return h('svg', common, h('path', { d: 'M12 3C7.6 3 5 6.1 5 10.2c0 5.3 4.2 9.3 7 10.8 2.8-1.5 7-5.5 7-10.8C19 6.1 16.4 3 12 3Z' }), h('path', { d: 'M12 7v9M12 10.2c-1.6 0-3 1-3.4 2.6M12 12.6c1.5 0 2.8.9 3.2 2.4' }))
|
|
236
|
+
if (name === 'spark') return h('svg', common, h('path', { d: 'M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9Z' }), h('path', { d: 'M18.5 16.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8Z' }))
|
|
237
|
+
if (name === 'chat') return h('svg', common, h('path', { d: 'M4 5.5h16v10H9l-4.5 3.5v-3.5H4z' }), h('path', { d: 'M8 9h8M8 12h5' }))
|
|
238
|
+
if (name === 'memory') return h('svg', common, h('path', { d: 'M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8' }), h('path', { d: 'M12 8v5l3 2M18 3v5h-5' }))
|
|
239
|
+
if (name === 'play') return h('svg', common, h('path', { d: 'M8 5.5l11 6.5-11 6.5z' }))
|
|
240
|
+
if (name === 'qr') return h('svg', common, h('path', { d: 'M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h2v2h-2zM18 14h2v2h-2zM14 18h2v2h-2zM18 18h2v2h-2z' }))
|
|
241
|
+
if (name === 'check') return h('svg', common, h('path', { d: 'M4.5 12.5l5 5 10-11' }))
|
|
242
|
+
if (name === 'refresh') return h('svg', common, h('path', { d: 'M20 11a8 8 0 1 0-2.3 5.7M20 5v6h-6' }))
|
|
243
|
+
if (name === 'save') return h('svg', common, h('path', { d: 'M5 4.5h10l4 4v11H5z' }), h('path', { d: 'M8.5 4.5v5h7v-5' }))
|
|
244
|
+
if (name === 'folder') return h('svg', common, h('path', { d: 'M3.5 7.5a2 2 0 0 1 2-2h3.2l1.8 2h8a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2z' }))
|
|
245
|
+
if (name === 'link') return h('svg', common, h('path', { d: 'M10 13a4 4 0 0 0 5.7 0l2.3-2.3a4 4 0 0 0-5.7-5.7L11 6.3M14 11a4 4 0 0 0-5.7 0L6 13.3a4 4 0 0 0 5.7 5.7l1.3-1.3' }))
|
|
246
|
+
if (name === 'copy') return h('svg', common, h('path', { d: 'M9 9h11v11H9z' }), h('path', { d: 'M5 15V4h11' }))
|
|
247
|
+
if (name === 'open') return h('svg', common, h('path', { d: 'M14 4h6v6M20 4l-9 9M18 13v6H5V6h6' }))
|
|
248
|
+
return h('svg', common, h('circle', { cx: 12, cy: 12, r: 8 }))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function Btn({ children, onClick, disabled, kind, icon, title, label }) {
|
|
252
|
+
return h('button', { type: 'button', className: 'dc-btn', 'data-kind': kind || 'default', disabled: Boolean(disabled), onClick, title, 'aria-label': label },
|
|
253
|
+
icon ? h('span', { 'aria-hidden': true }, h(Icon, { name: icon, size: 14 })) : null, children)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function Card({ title, sub, actions, children, className }) {
|
|
257
|
+
return h('section', { className: 'dc-card' + (className ? ' ' + className : ''), 'aria-label': typeof title === 'string' && title ? title : undefined },
|
|
258
|
+
title || actions ? h('div', { className: 'dc-card-head' },
|
|
259
|
+
h('div', null, h('div', { className: 'dc-card-title' }, title || ''), sub ? h('div', { className: 'dc-card-sub' }, sub) : null),
|
|
260
|
+
actions || null) : null,
|
|
261
|
+
children)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function Badge({ children, tone }) {
|
|
265
|
+
return h('span', { className: 'dc-badge', 'data-tone': tone || 'neutral' }, children)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function Metric({ value, unit, label, loading }) {
|
|
269
|
+
return h('div', null,
|
|
270
|
+
h('div', { className: 'dc-metric', 'data-loading': loading ? '' : undefined }, loading ? '…' : String(value), !loading && unit ? h('small', null, unit) : null),
|
|
271
|
+
h('div', { className: 'dc-metric-label' }, label))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function Switch({ on, onChange, disabled, label }) {
|
|
275
|
+
return h('button', {
|
|
276
|
+
className: 'dc-toggle', type: 'button', role: 'switch', 'aria-checked': on ? 'true' : 'false', 'aria-label': label,
|
|
277
|
+
disabled: Boolean(disabled), onClick: () => onChange(!on),
|
|
278
|
+
}, h('i', { 'aria-hidden': true }))
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function ToggleRow({ label, note, on, onChange, disabled }) {
|
|
282
|
+
return h('div', { className: 'dc-switch' },
|
|
283
|
+
h('div', null, h('div', { className: 'dc-switch-label' }, label), note ? h('div', { className: 'dc-switch-note' }, note) : null),
|
|
284
|
+
h('div', { className: 'dc-switch-ctl' },
|
|
285
|
+
h('span', { className: 'dc-switch-state', 'data-on': on ? '' : undefined, 'aria-hidden': true }, on ? '开' : '关'),
|
|
286
|
+
h(Switch, { on, onChange, disabled, label: typeof label === 'string' ? label : undefined })))
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 失焦才保存的输入框:只有内容真的改了才提交;没获得焦点时跟着服务端的值走,
|
|
291
|
+
* 不会把还没读到的默认值写回去。回车 = 失焦(多行输入除外)。
|
|
292
|
+
*/
|
|
293
|
+
function DraftField({ value, onCommit, normalize, multiline, disabled, className, style, ...rest }) {
|
|
294
|
+
const shown = value === undefined || value === null ? '' : String(value)
|
|
295
|
+
const [text, setText] = useState(shown)
|
|
296
|
+
const focused = useRef(false)
|
|
297
|
+
const cancelled = useRef(false)
|
|
298
|
+
useEffect(() => { if (!focused.current) setText(shown) }, [shown])
|
|
299
|
+
const commit = () => {
|
|
300
|
+
focused.current = false
|
|
301
|
+
if (cancelled.current) { cancelled.current = false; setText(shown); return }
|
|
302
|
+
const next = normalize ? normalize(text) : text
|
|
303
|
+
if (String(next) !== shown) onCommit(next)
|
|
304
|
+
setText(String(next))
|
|
305
|
+
}
|
|
306
|
+
return h(multiline ? 'textarea' : 'input', {
|
|
307
|
+
...rest,
|
|
308
|
+
className: className || (multiline ? 'dc-textarea' : 'dc-input'),
|
|
309
|
+
style,
|
|
310
|
+
disabled: Boolean(disabled),
|
|
311
|
+
value: text,
|
|
312
|
+
onFocus: () => { focused.current = true },
|
|
313
|
+
onChange: (e) => setText(e.target.value),
|
|
314
|
+
onBlur: commit,
|
|
315
|
+
onKeyDown: multiline ? undefined : (e) => {
|
|
316
|
+
if (e.key === 'Enter') e.currentTarget.blur()
|
|
317
|
+
if (e.key === 'Escape') { cancelled.current = true; e.currentTarget.blur() }
|
|
318
|
+
},
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function fmtTime(value) {
|
|
323
|
+
if (!value) return '—'
|
|
324
|
+
const d = new Date(value)
|
|
325
|
+
if (isNaN(d.getTime())) return String(value)
|
|
326
|
+
const pad = (n) => (n < 10 ? '0' + n : '' + n)
|
|
327
|
+
return (d.getMonth() + 1) + '/' + d.getDate() + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function shortPath(p) {
|
|
331
|
+
if (typeof p !== 'string' || p === '') return ''
|
|
332
|
+
const parts = p.replace(/\\/g, '/').split('/').filter(Boolean)
|
|
333
|
+
return parts.length <= 2 ? p : '…/' + parts.slice(-2).join('/')
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 百炼 Sambert 里的英文音色:拿来读中文只会回一个空 WAV
|
|
337
|
+
const ENGLISH_SAMBERT = /^sambert-(betty|beth|cally|cindy|eva|donna|brian)-v\d/i
|
|
338
|
+
|
|
339
|
+
// 语音表单里会提交的字段(和 /api/companion/tts/config 认的一致)
|
|
340
|
+
const TTS_FORM_KEYS = ['provider','baseUrl','model','voice','language','workspace','instructions','refAudio','refText','refLanguage','speed','sampleRate','timeoutSec','customBody','customAudioField','qwenModel','qwenSource','qwenDevice','qwenPort','qwenHost','qwenAutoStart','pipIndex']
|
|
341
|
+
|
|
342
|
+
function errText(error) {
|
|
343
|
+
return String((error && error.message) || error)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function samePath(a, b) {
|
|
347
|
+
const norm = (v) => String(v || '').trim().replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase()
|
|
348
|
+
return norm(a) !== '' && norm(a) === norm(b)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function useServiceList(name) {
|
|
352
|
+
const [snap, setSnap] = useState(null)
|
|
353
|
+
const source = (() => { const svc = service(name); return svc && svc.list ? svc.list : null })()
|
|
354
|
+
useEffect(() => {
|
|
355
|
+
if (!source) return undefined
|
|
356
|
+
const read = () => { try { setSnap(source.getSnapshot()) } catch { setSnap(null) } }
|
|
357
|
+
read()
|
|
358
|
+
if (typeof source.subscribe !== 'function') return undefined
|
|
359
|
+
let off = null
|
|
360
|
+
try { off = source.subscribe(read) } catch { off = null }
|
|
361
|
+
return () => { if (typeof off === 'function') { try { off() } catch { /* noop */ } } }
|
|
362
|
+
}, [source])
|
|
363
|
+
return snap
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function CompanionIcon(props) {
|
|
367
|
+
const size = props && props.size ? props.size : 20
|
|
368
|
+
const active = Boolean(props && props.active)
|
|
369
|
+
return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', style: { display: 'block', opacity: active ? 1 : 0.85 } },
|
|
370
|
+
h('path', { d: 'M12 3C7.6 3 5 6.1 5 10.2c0 5.3 4.2 9.3 7 10.8 2.8-1.5 7-5.5 7-10.8C19 6.1 16.4 3 12 3Z', fill: active ? 'currentColor' : 'none', fillOpacity: active ? 0.16 : 0 }),
|
|
371
|
+
h('path', { d: 'M12 7v9M12 10.2c-1.6 0-3 1-3.4 2.6M12 12.6c1.5 0 2.8.9 3.2 2.4' }))
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const LOCAL_STATE_TEXT = {
|
|
375
|
+
stopped: '没在跑', starting: '启动中…', loading: '加载模型中(第一次会下载,较久)…', ready: '运行中', stopping: '停止中…', error: '出错了',
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** 自带的本地 Qwen3-TTS:装环境 → 选模型 / 设备 → 启动。 */
|
|
379
|
+
function LocalQwenCard({ form, edit, local, busy, act, logOpen, setLogOpen }) {
|
|
380
|
+
const installed = Boolean(local && local.installed)
|
|
381
|
+
const inst = (local && local.install) || { state: 'idle' }
|
|
382
|
+
const srv = (local && local.server) || { state: 'stopped' }
|
|
383
|
+
const running = ['starting', 'loading', 'ready'].includes(srv.state)
|
|
384
|
+
const log = String((inst.state === 'running' || !srv.log ? inst.log : srv.log) || '').trim()
|
|
385
|
+
return h(Card, { title: '本地 Qwen3-TTS', sub: !local ? '读取中…' : (installed ? '环境已装好 · 服务' + (LOCAL_STATE_TEXT[srv.state] || srv.state) : '还没装环境') },
|
|
386
|
+
inst.state === 'running' ? h('div', { className: 'dc-banner', role: 'status' }, '正在安装:' + (inst.step || '…') + '(PyTorch 有几百 MB 到几 GB,看网速)') : null,
|
|
387
|
+
inst.state === 'error' ? h('div', { className: 'dc-banner', 'data-tone': 'err' }, '安装失败:' + (inst.step || '看下面的日志')) : null,
|
|
388
|
+
srv.state === 'error' && srv.error ? h('div', { className: 'dc-banner', 'data-tone': 'err' }, '服务:' + srv.error) : null,
|
|
389
|
+
h('div', { className: 'dc-row', style: { gap: '10px', alignItems: 'flex-start' } },
|
|
390
|
+
h('div', { style: { flex: '1 1 140px' } },
|
|
391
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-q-device' }, '设备'),
|
|
392
|
+
h('select', { id: 'dc-q-device', className: 'dc-select', value: form.qwenDevice || 'auto', onChange: (e) => edit('qwenDevice', e.target.value) },
|
|
393
|
+
[['auto', '自动(有显卡用显卡)'], ['cuda', 'NVIDIA 显卡(CUDA)'], ['mps', '苹果芯片(MPS)'], ['cpu', '只用 CPU']].map(([v, l]) => h('option', { key: v, value: v }, l)))),
|
|
394
|
+
h('div', { style: { flex: '1 1 140px' } },
|
|
395
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-q-source' }, '模型下载源'),
|
|
396
|
+
h('select', { id: 'dc-q-source', className: 'dc-select', value: form.qwenSource || 'modelscope', onChange: (e) => edit('qwenSource', e.target.value) },
|
|
397
|
+
[['modelscope', 'ModelScope(国内快)'], ['huggingface', 'Hugging Face'], ['hf-mirror', 'HF 镜像(hf-mirror.com)']].map(([v, l]) => h('option', { key: v, value: v }, l)))),
|
|
398
|
+
h('div', { style: { flex: '0 1 110px' } },
|
|
399
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-q-port' }, '端口'),
|
|
400
|
+
h('input', { id: 'dc-q-port', className: 'dc-input', type: 'number', min: 1024, max: 65535, value: String(form.qwenPort || 8077), onChange: (e) => edit('qwenPort', e.target.value) }))),
|
|
401
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-q-pip' }, 'Python 包镜像(可空;国内可填 https://pypi.tuna.tsinghua.edu.cn/simple)'),
|
|
402
|
+
h('input', { id: 'dc-q-pip', className: 'dc-input', value: form.pipIndex || '', placeholder: '留空用 PyPI 官方源', onChange: (e) => edit('pipIndex', e.target.value) }),
|
|
403
|
+
h('div', { style: { marginTop: '6px' } },
|
|
404
|
+
h(ToggleRow, { label: '对局域网开放', note: '默认只本机能用;打开后虚拟机宿主 / 别的电脑也能连(自己确认网络可信)', on: form.qwenHost === '0.0.0.0', onChange: (v) => edit('qwenHost', v ? '0.0.0.0' : '127.0.0.1') }),
|
|
405
|
+
h(ToggleRow, { label: '跟着 DSH 一起启动', note: '开着的话,DSH 一启动就在后台加载模型,QQ 语音不用等', on: form.qwenAutoStart === true, onChange: (v) => edit('qwenAutoStart', v) })),
|
|
406
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
407
|
+
h(Btn, { icon: 'save', kind: installed ? undefined : 'primary', disabled: busy['local-install'] || inst.state === 'running' || running, onClick: () => act('install') }, inst.state === 'running' ? '安装中…' : (installed ? '重装 / 更新环境' : '安装环境')),
|
|
408
|
+
running
|
|
409
|
+
? h(Btn, { icon: 'check', kind: 'danger', disabled: busy['local-stop'] || srv.state === 'stopping', onClick: () => act('stop') }, '停止')
|
|
410
|
+
: h(Btn, { icon: 'play', kind: 'primary', disabled: !installed || busy['local-start'] || inst.state === 'running', onClick: () => act('start') }, '保存并启动'),
|
|
411
|
+
log ? h(Btn, { icon: 'open', kind: 'ghost', onClick: () => setLogOpen(!logOpen) }, logOpen ? '收起日志' : '看日志') : null),
|
|
412
|
+
logOpen && log ? h('pre', { className: 'dc-pre', style: { marginTop: '10px', maxHeight: '220px' }, tabIndex: 0, 'aria-label': '本地 Qwen3-TTS 日志' }, log.slice(-6000)) : null,
|
|
413
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px' } },
|
|
414
|
+
'· 环境装在 DSH 目录的 tts-qwen3 里,不动系统 Python,也不动 B站 那个环境。', h('br'),
|
|
415
|
+
'· 没显卡建议选 0.6B;1.7B 在 CPU 上一句话可能要几十秒。苹果芯片自动用 MPS。', h('br'),
|
|
416
|
+
'· Linux + NVIDIA 想要更快,可以改用上面的「vLLM-Omni」预设,在那台机器上自己跑 vLLM。'))
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function readFileAsDataUrl(file) {
|
|
420
|
+
return new Promise((resolve, reject) => {
|
|
421
|
+
const reader = new FileReader()
|
|
422
|
+
reader.onload = () => resolve(String(reader.result || ''))
|
|
423
|
+
reader.onerror = () => reject(reader.error || new Error('读不了这个文件'))
|
|
424
|
+
reader.readAsDataURL(file)
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** 角色声音:上传一段角色的声音 → Qwen3-TTS Base 直接克隆(不用训练)。 */
|
|
429
|
+
function VoiceCloneCard({ list, current, busy, onCreate, onUse, onDelete, provider }) {
|
|
430
|
+
const [name, setName] = useState('')
|
|
431
|
+
const [refText, setRefText] = useState('')
|
|
432
|
+
const [language, setLanguage] = useState('Chinese')
|
|
433
|
+
const [file, setFile] = useState(null)
|
|
434
|
+
const [fileNote, setFileNote] = useState('')
|
|
435
|
+
const inputRef = useRef(null)
|
|
436
|
+
const pick = (f) => {
|
|
437
|
+
setFile(f || null)
|
|
438
|
+
if (!f) { setFileNote(''); return }
|
|
439
|
+
if (f.size > 20 * 1024 * 1024) { setFileNote('文件太大(' + Math.round(f.size / 1048576) + ' MB);截一段 3–30 秒的就够'); return }
|
|
440
|
+
setFileNote(f.name + ' · ' + Math.max(1, Math.round(f.size / 1024)) + ' KB')
|
|
441
|
+
if (!name) setName(String(f.name).replace(/\.[^.]+$/, '').slice(0, 40))
|
|
442
|
+
}
|
|
443
|
+
const submit = async () => {
|
|
444
|
+
if (!file || file.size > 20 * 1024 * 1024) return
|
|
445
|
+
const ok = await onCreate({ name, refText, language, file })
|
|
446
|
+
if (ok) { setFile(null); setFileNote(''); setRefText(''); setName(''); if (inputRef.current) inputRef.current.value = '' }
|
|
447
|
+
}
|
|
448
|
+
const voices = Array.isArray(list) ? list : []
|
|
449
|
+
return h(Card, { title: '角色声音(克隆)', sub: '上传一段角色的声音,用 Qwen3-TTS Base 模型直接模仿;不用训练,几秒钟就能用' },
|
|
450
|
+
h('div', { className: 'dc-note' }, '要求:一个人在说话、没有背景音乐,3–30 秒(超过 30 秒只取前 30 秒)。最好把这段话的原文也填上,像不像主要看这一步;不填也能用,但只模仿音色。'),
|
|
451
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-vc-file' }, '音频文件(wav / mp3 / m4a / ogg / flac)'),
|
|
452
|
+
h('input', { id: 'dc-vc-file', ref: inputRef, className: 'dc-input', type: 'file', accept: 'audio/*,.wav,.mp3,.m4a,.ogg,.flac,.aac', onChange: (e) => pick(e.target.files && e.target.files[0]) }),
|
|
453
|
+
fileNote ? h('div', { className: 'dc-note', style: { marginTop: '4px' } }, fileNote) : null,
|
|
454
|
+
h('div', { className: 'dc-row', style: { gap: '10px', alignItems: 'flex-start' } },
|
|
455
|
+
h('div', { style: { flex: '2 1 180px' } },
|
|
456
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-vc-name' }, '名字'),
|
|
457
|
+
h('input', { id: 'dc-vc-name', className: 'dc-input', value: name, maxLength: 40, placeholder: '例:纳西妲', onChange: (e) => setName(e.target.value) })),
|
|
458
|
+
h('div', { style: { flex: '1 1 120px' } },
|
|
459
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-vc-lang' }, '这段话的语言'),
|
|
460
|
+
h('select', { id: 'dc-vc-lang', className: 'dc-select', value: language, onChange: (e) => setLanguage(e.target.value) },
|
|
461
|
+
['Chinese', 'English', 'Japanese', 'Korean', 'Cantonese', 'Auto'].map((x) => h('option', { key: x, value: x }, x))))),
|
|
462
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-vc-text' }, '这段音频说的原话(推荐填)'),
|
|
463
|
+
h('textarea', { id: 'dc-vc-text', className: 'dc-textarea', style: { minHeight: '60px' }, value: refText, placeholder: '一字不差地写下音频里说的话', onChange: (e) => setRefText(e.target.value) }),
|
|
464
|
+
h('div', { className: 'dc-row', style: { marginTop: '10px' } },
|
|
465
|
+
h(Btn, { icon: 'save', kind: 'primary', disabled: !file || !name.trim() || busy['voice-create'] || (file && file.size > 20 * 1024 * 1024), onClick: submit }, busy['voice-create'] ? '处理中…' : '上传并制作')),
|
|
466
|
+
h('div', { className: 'dc-label' }, '已有的角色声音'),
|
|
467
|
+
voices.length ? h('div', { className: 'dc-list' }, voices.map((v) => h('div', { key: v.id, className: 'dc-item', 'data-on': current === v.id ? '' : undefined },
|
|
468
|
+
h('div', { className: 'dc-item-main' },
|
|
469
|
+
h('div', { className: 'dc-item-title' }, v.name + (current === v.id ? '(正在用)' : '')),
|
|
470
|
+
h('div', { className: 'dc-item-sub' }, (v.seconds ? v.seconds.toFixed(1) + ' 秒' : '') + (v.truncated ? '(截到 30 秒)' : '') + ' · ' + (v.refText ? '有原文' : '没填原文:只模仿音色') + ' · ' + (v.language || 'Auto'))),
|
|
471
|
+
h('div', { className: 'dc-row', style: { gap: '6px' } },
|
|
472
|
+
current === v.id ? null : h(Btn, { icon: 'check', kind: 'primary', disabled: busy['voice-use'], onClick: () => onUse(v) }, '用这个声音'),
|
|
473
|
+
h(Btn, { icon: 'refresh', kind: 'danger', label: '删除 ' + v.name, disabled: busy['voice-delete'], onClick: () => onDelete(v) }, '删除')))))
|
|
474
|
+
: h('div', { className: 'dc-note' }, '还没有。上传一段之后会出现在这里。'),
|
|
475
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px' } },
|
|
476
|
+
'· 点「用这个声音」会把模型换成同尺寸的 Base(克隆)模型' + (provider === 'qwen3-vllm' ? ';vLLM-Omni 那边也要用 Base 模型启动。' : ';本地服务要重启一次才会换上。'), h('br'),
|
|
477
|
+
'· 换好后在右边「试听」就能听效果;QQ 回复也会用这个声音。', h('br'),
|
|
478
|
+
'· 只上传你有权使用的声音;不要用来冒充真人。', h('br'),
|
|
479
|
+
'· 想要更像:可以再做「微调训练」,但要 NVIDIA 显卡和几十分钟的录音,目前没放进这个页面。'))
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** B站 页里的「QQ 分享视频」卡片:分镜插件、yt-dlp、高清登录开关、最近一张卡片。 */
|
|
483
|
+
function VideoCard({ info, busy, onLogin, onInstallYtdlp, onRefresh, biliLoggedIn }) {
|
|
484
|
+
const sb = (info && info.storyboard) || { installed: false }
|
|
485
|
+
const yt = (info && info.ytdlp) || { found: false }
|
|
486
|
+
const card = info && info.lastCard
|
|
487
|
+
const results = card && Array.isArray(card.results) ? card.results : []
|
|
488
|
+
return h(Card, { title: 'QQ 分享的视频', sub: '对方在 QQ 里分享 B站 视频,机器人用视频分镜插件去看' },
|
|
489
|
+
!info ? h('div', { className: 'dc-empty' }, '读取中…') : h('div', null,
|
|
490
|
+
!sb.installed ? h('div', { className: 'dc-banner' }, '视频分镜插件(dsh-video-storyboard)没装:机器人能拿到链接,但看不了画面。装法见「环境」页。') : null,
|
|
491
|
+
sb.installed && !yt.found ? h('div', { className: 'dc-banner' }, '还差 yt-dlp:分镜插件靠它拉 B站 视频。') : null,
|
|
492
|
+
h('div', { className: 'dc-row', style: { marginBottom: '6px' } },
|
|
493
|
+
h(Badge, { tone: sb.installed ? 'ok' : 'warn' }, sb.installed ? '分镜 v' + sb.version : '分镜未装'),
|
|
494
|
+
h(Badge, { tone: yt.found ? 'ok' : 'warn' }, yt.found ? 'yt-dlp ' + yt.version : 'yt-dlp 未装'),
|
|
495
|
+
h(Badge, { tone: info.ffmpeg ? 'ok' : 'warn' }, info.ffmpeg ? 'ffmpeg 已就绪' : 'ffmpeg 未装'),
|
|
496
|
+
!yt.found ? h(Btn, { icon: 'save', disabled: busy.ytdlp, onClick: onInstallYtdlp }, busy.ytdlp ? '安装中…' : '一键装 yt-dlp') : null),
|
|
497
|
+
h(ToggleRow, {
|
|
498
|
+
label: '用 B站 专用号的登录看高清',
|
|
499
|
+
note: info.cookiesConfigured && !info.cookiesOurs ? '你在 video.json 里自己配了 cookies,这里不改动它' : (biliLoggedIn ? '默认关:匿名最高 480P,看分镜够用。打开后会把专用号登录信息写成一份只给分镜插件用的 cookies 文件;关掉就删掉' : '要先在上面「账号」里扫码登录专用号'),
|
|
500
|
+
on: info.useBiliLogin === true,
|
|
501
|
+
disabled: busy['video-login'] || (!info.useBiliLogin && (!biliLoggedIn || (info.cookiesConfigured && !info.cookiesOurs))),
|
|
502
|
+
onChange: onLogin,
|
|
503
|
+
}),
|
|
504
|
+
h('div', { className: 'dc-label' }, '最近一张收到的卡片'),
|
|
505
|
+
results.length ? h('div', { className: 'dc-list' }, results.map((r, i) => h('div', { key: i, className: 'dc-item' },
|
|
506
|
+
h('span', { className: 'dc-state-dot', 'data-ok': r.url ? '' : undefined, role: 'img', 'aria-label': r.url ? '拿到链接' : '没有链接' }),
|
|
507
|
+
h('div', { className: 'dc-item-main' },
|
|
508
|
+
h('div', { className: 'dc-item-title', title: r.title || '' }, (r.kind === 'bili' ? '哔哩哔哩:' : '') + (r.title || r.source || '(无标题)')),
|
|
509
|
+
h('div', { className: 'dc-item-sub' }, r.url ? r.url : (r.kind === 'bili' ? '卡片里没有可用链接(会请对方直接发链接)' : '不是 B站 卡片'))))))
|
|
510
|
+
: h('div', { className: 'dc-note' }, card ? '收到过卡片,但里面没有能识别的内容' : '还没收到过。QQ 网关重启后,对方分享一个 B站 视频就会显示在这里。'),
|
|
511
|
+
h('div', { className: 'dc-row', style: { marginTop: '10px' } }, h(Btn, { icon: 'refresh', onClick: onRefresh }, '刷新')),
|
|
512
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } },
|
|
513
|
+
'· 卡片里的 b23.tv 短链会在本机解开成视频地址,只访问 B站 自己的域名。', h('br'),
|
|
514
|
+
'· 群里 QQ 只把 @机器人 的消息交给它;直接转发卡片到群里通常收不到,私聊最稳。', h('br'),
|
|
515
|
+
'· 每看一个视频会花模型 token(一张分镜图约 384 token)。')))
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function CompanionPage() {
|
|
519
|
+
const [tab, setTab] = useState('home')
|
|
520
|
+
const [busy, setBusyMap] = useState({})
|
|
521
|
+
const [toast, setToast] = useState(null)
|
|
522
|
+
const [agent, setAgent] = useState(null)
|
|
523
|
+
const [bili, setBili] = useState(null)
|
|
524
|
+
const [world, setWorld] = useState(null)
|
|
525
|
+
const [mem, setMem] = useState(null)
|
|
526
|
+
const [qqBind, setQqBind] = useState(null)
|
|
527
|
+
const [loaded, setLoaded] = useState(false)
|
|
528
|
+
const [loadErrors, setLoadErrors] = useState([])
|
|
529
|
+
const [cwd, setCwd] = useState('')
|
|
530
|
+
const [draft, setDraft] = useState(null)
|
|
531
|
+
const [dirty, setDirty] = useState(false)
|
|
532
|
+
const [createConfirm, setCreateConfirm] = useState(false)
|
|
533
|
+
const [selectedChat, setSelectedChat] = useState('')
|
|
534
|
+
const [expandedChats, setExpandedChats] = useState({})
|
|
535
|
+
const [showAllChats, setShowAllChats] = useState(false)
|
|
536
|
+
const [loginKey, setLoginKey] = useState('')
|
|
537
|
+
const [loginQr, setLoginQr] = useState('')
|
|
538
|
+
const [loginState, setLoginState] = useState('')
|
|
539
|
+
const [logoutConfirm, setLogoutConfirm] = useState(false)
|
|
540
|
+
// 文字转语音
|
|
541
|
+
const [tts, setTts] = useState(null)
|
|
542
|
+
const [ttsError, setTtsError] = useState('')
|
|
543
|
+
const [ttsForm, setTtsForm] = useState(null)
|
|
544
|
+
const [ttsKey, setTtsKey] = useState('')
|
|
545
|
+
const [voiceText, setVoiceText] = useState('')
|
|
546
|
+
const [voiceBusy, setVoiceBusy] = useState('')
|
|
547
|
+
const [voiceNote, setVoiceNote] = useState('')
|
|
548
|
+
const [playing, setPlaying] = useState(false)
|
|
549
|
+
const [ttsProbe, setTtsProbe] = useState(null)
|
|
550
|
+
const [localTts, setLocalTts] = useState(null)
|
|
551
|
+
const [localLogOpen, setLocalLogOpen] = useState(false)
|
|
552
|
+
// 视频分镜 / QQ 分享卡片
|
|
553
|
+
const [videoInfo, setVideoInfo] = useState(null)
|
|
554
|
+
const [voiceList, setVoiceList] = useState(null)
|
|
555
|
+
// 表情包(dsh-meme)
|
|
556
|
+
const [meme, setMeme] = useState(null)
|
|
557
|
+
const [memeStatus, setMemeStatus] = useState('idle')
|
|
558
|
+
const [memeBusy, setMemeBusy] = useState('')
|
|
559
|
+
const [doctor, setDoctor] = useState(null)
|
|
560
|
+
const sessionsSnap = useServiceList('sessions')
|
|
561
|
+
const workspacesSnap = useServiceList('workspaces')
|
|
562
|
+
const alive = useRef(true)
|
|
563
|
+
const draftRef = useRef({ dirty: false, text: null })
|
|
564
|
+
const audioRef = useRef(null)
|
|
565
|
+
const audioUrlRef = useRef('')
|
|
566
|
+
const toastTimer = useRef(null)
|
|
567
|
+
const busyRef = useRef({})
|
|
568
|
+
const cwdRef = useRef('')
|
|
569
|
+
const loadSeq = useRef(0)
|
|
570
|
+
const appliedSeq = useRef(0)
|
|
571
|
+
const polling = useRef(false)
|
|
572
|
+
|
|
573
|
+
cwdRef.current = cwd
|
|
574
|
+
|
|
575
|
+
const stopAudio = useCallback(() => {
|
|
576
|
+
const audio = audioRef.current
|
|
577
|
+
audioRef.current = null
|
|
578
|
+
if (audio) { try { audio.pause(); audio.removeAttribute('src'); audio.load() } catch { /* ignore */ } }
|
|
579
|
+
if (audioUrlRef.current) { try { URL.revokeObjectURL(audioUrlRef.current) } catch { /* ignore */ } audioUrlRef.current = '' }
|
|
580
|
+
}, [])
|
|
581
|
+
|
|
582
|
+
useEffect(() => () => {
|
|
583
|
+
alive.current = false
|
|
584
|
+
if (toastTimer.current) clearTimeout(toastTimer.current)
|
|
585
|
+
stopAudio()
|
|
586
|
+
}, [stopAudio])
|
|
587
|
+
|
|
588
|
+
// 同一时间只显示一条提示;新的顶掉旧的,错误多停一会儿。
|
|
589
|
+
const say = useCallback((text, tone) => {
|
|
590
|
+
if (!alive.current) return
|
|
591
|
+
if (toastTimer.current) clearTimeout(toastTimer.current)
|
|
592
|
+
setToast({ text: String(text || ''), tone: tone || '' })
|
|
593
|
+
toastTimer.current = setTimeout(() => { toastTimer.current = null; if (alive.current) setToast(null) }, tone === 'err' ? 7000 : 4200)
|
|
594
|
+
}, [])
|
|
595
|
+
|
|
596
|
+
const dismissToast = useCallback(() => {
|
|
597
|
+
if (toastTimer.current) { clearTimeout(toastTimer.current); toastTimer.current = null }
|
|
598
|
+
setToast(null)
|
|
599
|
+
}, [])
|
|
600
|
+
|
|
601
|
+
// 每个动作有自己的忙碌标记:一个动作结束不会把另一个还在跑的按钮放开;同一个动作跑着时重复点击直接忽略。
|
|
602
|
+
const runBusy = useCallback(async (key, fn) => {
|
|
603
|
+
if (busyRef.current[key]) return undefined
|
|
604
|
+
busyRef.current[key] = true
|
|
605
|
+
setBusyMap((m) => ({ ...m, [key]: true }))
|
|
606
|
+
try {
|
|
607
|
+
return await fn()
|
|
608
|
+
} finally {
|
|
609
|
+
delete busyRef.current[key]
|
|
610
|
+
if (alive.current) setBusyMap((m) => { const n = { ...m }; delete n[key]; return n })
|
|
611
|
+
}
|
|
612
|
+
}, [])
|
|
613
|
+
|
|
614
|
+
const load = useCallback(async (nextCwd) => {
|
|
615
|
+
const target = typeof nextCwd === 'string' ? nextCwd : cwdRef.current
|
|
616
|
+
const seq = ++loadSeq.current
|
|
617
|
+
const [agentRes, biliRes, worldRes, memRes, qqRes] = await Promise.allSettled([
|
|
618
|
+
get(AG + '/state' + (target ? '?path=' + encodeURIComponent(target) : '')),
|
|
619
|
+
get(BILI + '/status'),
|
|
620
|
+
get(WORLD + '/console/snapshot'),
|
|
621
|
+
get(CC + '/state'),
|
|
622
|
+
get('/qqbot/im-qqbot/bind'),
|
|
623
|
+
])
|
|
624
|
+
// 更晚发出的那次已经回来过了:这次是旧数据,丢掉,免得切项目后被旧结果盖回去。
|
|
625
|
+
if (!alive.current || seq < appliedSeq.current) return
|
|
626
|
+
appliedSeq.current = seq
|
|
627
|
+
if (agentRes.status === 'fulfilled') setAgent(agentRes.value)
|
|
628
|
+
if (biliRes.status === 'fulfilled') setBili(biliRes.value)
|
|
629
|
+
if (worldRes.status === 'fulfilled') setWorld(worldRes.value)
|
|
630
|
+
if (memRes.status === 'fulfilled') setMem(memRes.value)
|
|
631
|
+
if (qqRes.status === 'fulfilled') setQqBind(qqRes.value)
|
|
632
|
+
const failed = []
|
|
633
|
+
if (agentRes.status === 'rejected') failed.push('人格 / QQ(dsh-agent-md)')
|
|
634
|
+
if (biliRes.status === 'rejected') failed.push('B站 值班(dsh-bili-scroll)')
|
|
635
|
+
if (worldRes.status === 'rejected') failed.push('记忆(dsh-world)')
|
|
636
|
+
if (memRes.status === 'rejected') failed.push('本插件 /api/companion')
|
|
637
|
+
if (qqRes.status === 'rejected') failed.push('QQ 网关')
|
|
638
|
+
setLoadErrors((prev) => (prev.join('|') === failed.join('|') ? prev : failed))
|
|
639
|
+
setLoaded(true)
|
|
640
|
+
}, [])
|
|
641
|
+
|
|
642
|
+
const loadTts = useCallback(async () => {
|
|
643
|
+
try {
|
|
644
|
+
const d = await get(CC + '/tts')
|
|
645
|
+
if (!alive.current) return
|
|
646
|
+
if (d && d.config) { setTts(d.config); setTtsError('') }
|
|
647
|
+
} catch (error) { if (alive.current) setTtsError(errText(error)) }
|
|
648
|
+
}, [])
|
|
649
|
+
|
|
650
|
+
const loadLocalTts = useCallback(async () => {
|
|
651
|
+
try { const d = await get(CC + '/tts/local'); if (alive.current) setLocalTts(d) } catch { /* 旧宿主没有这个接口 */ }
|
|
652
|
+
}, [])
|
|
653
|
+
|
|
654
|
+
const loadVoices = useCallback(async () => {
|
|
655
|
+
try { const d = await get(CC + '/voices'); if (alive.current) setVoiceList(d) } catch { /* 旧宿主没有这个接口 */ }
|
|
656
|
+
}, [])
|
|
657
|
+
|
|
658
|
+
const loadVideo = useCallback(async () => {
|
|
659
|
+
try { const d = await get(CC + '/video'); if (alive.current) setVideoInfo(d) } catch { if (alive.current) setVideoInfo((v) => v || { error: true }) }
|
|
660
|
+
}, [])
|
|
661
|
+
|
|
662
|
+
const loadMeme = useCallback(async () => {
|
|
663
|
+
setMemeStatus((s) => (s === 'ok' ? s : 'loading'))
|
|
664
|
+
try {
|
|
665
|
+
const d = await post('/dsh-memes-api', { op: 'getMemeRoot' })
|
|
666
|
+
if (!alive.current) return
|
|
667
|
+
if (d && d.ok) { setMeme(d); setMemeStatus('ok') } else setMemeStatus('missing')
|
|
668
|
+
} catch (error) {
|
|
669
|
+
if (!alive.current) return
|
|
670
|
+
// 404 = 没装 dsh-meme;别的错误是装了但没答上
|
|
671
|
+
setMemeStatus(error && error.status === 404 ? 'missing' : 'error')
|
|
672
|
+
}
|
|
673
|
+
}, [])
|
|
674
|
+
|
|
675
|
+
const checkDoctor = useCallback(() => runBusy('doctor-check', async () => {
|
|
676
|
+
try {
|
|
677
|
+
const d = await get(CC + '/doctor')
|
|
678
|
+
if (d && alive.current) setDoctor(d)
|
|
679
|
+
} catch (error) { say('体检失败:' + errText(error), 'err') }
|
|
680
|
+
}), [runBusy, say])
|
|
681
|
+
|
|
682
|
+
const installDashscope = useCallback(() => runBusy('doctor-install', async () => {
|
|
683
|
+
try {
|
|
684
|
+
const r = await post(CC + '/doctor/install', { what: 'dashscope' })
|
|
685
|
+
if (r && r.ok) say('dashscope 装好了', 'ok')
|
|
686
|
+
else say('安装失败:' + String((r && (r.error || r.output)) || '看安装日志').slice(-400), 'err')
|
|
687
|
+
} catch (error) { say('安装失败:' + errText(error), 'err') }
|
|
688
|
+
await checkDoctor()
|
|
689
|
+
}), [runBusy, checkDoctor, say])
|
|
690
|
+
|
|
691
|
+
const patchQqbot = useCallback(() => runBusy('doctor-patch', async () => {
|
|
692
|
+
try {
|
|
693
|
+
const r = await post(CC + '/qqbot/patch', {})
|
|
694
|
+
if (r && r.ok) say(r.changed ? '补丁已写入;重启 DSH 后生效' : 'QQ 网关已经是补丁状态', 'ok')
|
|
695
|
+
else say('补丁失败:' + String((r && (r.error || r.detail)) || '看插件日志').slice(-400), 'err')
|
|
696
|
+
} catch (error) { say('补丁失败:' + errText(error), 'err') }
|
|
697
|
+
await checkDoctor()
|
|
698
|
+
}), [runBusy, checkDoctor, say])
|
|
699
|
+
|
|
700
|
+
// 切项目(以及第一次打开)时立刻拉一次
|
|
701
|
+
useEffect(() => { load(cwd) }, [cwd, load])
|
|
702
|
+
|
|
703
|
+
// 15 秒轮询;页面藏起来时不跑,切回来马上补一次。上一轮没回来就跳过这一轮。
|
|
704
|
+
useEffect(() => {
|
|
705
|
+
const poll = async () => {
|
|
706
|
+
if (document.hidden || polling.current) return
|
|
707
|
+
polling.current = true
|
|
708
|
+
try { await load() } finally { polling.current = false }
|
|
709
|
+
}
|
|
710
|
+
const timer = setInterval(poll, 15000)
|
|
711
|
+
const onVisible = () => { if (!document.hidden) poll() }
|
|
712
|
+
document.addEventListener('visibilitychange', onVisible)
|
|
713
|
+
return () => { clearInterval(timer); document.removeEventListener('visibilitychange', onVisible) }
|
|
714
|
+
}, [load])
|
|
715
|
+
|
|
716
|
+
useEffect(() => { loadTts() }, [loadTts])
|
|
717
|
+
|
|
718
|
+
// 只在这几个页签打开时才拉重数据(表情包索引、环境体检),平时不跑。
|
|
719
|
+
useEffect(() => {
|
|
720
|
+
if (tab === 'voice') { loadTts(); loadLocalTts(); loadVoices() }
|
|
721
|
+
if (tab === 'bili' || tab === 'home') loadVideo()
|
|
722
|
+
if (tab === 'meme') loadMeme()
|
|
723
|
+
if (tab === 'doctor') { checkDoctor(); loadVideo() }
|
|
724
|
+
}, [tab, loadTts, loadLocalTts, loadVoices, loadVideo, loadMeme, checkDoctor])
|
|
725
|
+
|
|
726
|
+
// 本地 Qwen3-TTS 在装 / 在启动时,语音页每 3 秒看一次进度;停下来就不再轮询。
|
|
727
|
+
const localBusy = Boolean(localTts && ((localTts.install && localTts.install.state === 'running')
|
|
728
|
+
|| (localTts.server && ['starting', 'loading', 'stopping'].includes(localTts.server.state))))
|
|
729
|
+
useEffect(() => {
|
|
730
|
+
if (tab !== 'voice' || !localBusy) return undefined
|
|
731
|
+
const timer = setInterval(() => { if (!document.hidden) loadLocalTts() }, 3000)
|
|
732
|
+
return () => clearInterval(timer)
|
|
733
|
+
}, [tab, localBusy, loadLocalTts])
|
|
734
|
+
|
|
735
|
+
// 首次拿到当前项目目录
|
|
736
|
+
useEffect(() => {
|
|
737
|
+
if (cwd !== '') return
|
|
738
|
+
const guess = (agent && agent.current && agent.current.cwd) || ''
|
|
739
|
+
if (guess !== '') { setCwd(guess); return }
|
|
740
|
+
const projects = (agent && Array.isArray(agent.workspaces)) ? agent.workspaces : []
|
|
741
|
+
if (projects.length > 0 && projects[0].cwd) setCwd(projects[0].cwd)
|
|
742
|
+
}, [agent, cwd])
|
|
743
|
+
|
|
744
|
+
// 切换项目 / 拿到项目正文时填进编辑器(没改过才填)
|
|
745
|
+
useEffect(() => {
|
|
746
|
+
if (!agent) return
|
|
747
|
+
const target = cwd !== '' ? cwd : (agent.current ? agent.current.cwd : '')
|
|
748
|
+
const row = (agent.projects || []).find((p) => samePath(p.cwd, target))
|
|
749
|
+
const content = row ? row.content : ''
|
|
750
|
+
if (!draftRef.current.dirty) { setDraft(content); draftRef.current.text = content; setDirty(false) }
|
|
751
|
+
}, [agent, cwd])
|
|
752
|
+
|
|
753
|
+
useEffect(() => {
|
|
754
|
+
if (!tts || ttsForm !== null) return
|
|
755
|
+
const form = {}
|
|
756
|
+
for (const key of TTS_FORM_KEYS) form[key] = tts[key] === undefined || tts[key] === null ? '' : tts[key]
|
|
757
|
+
form.provider = tts.provider || 'dashscope'
|
|
758
|
+
form.language = tts.language || 'Chinese'
|
|
759
|
+
setTtsForm(form)
|
|
760
|
+
}, [tts, ttsForm])
|
|
761
|
+
|
|
762
|
+
// 扫码登录轮询:上一次请求回来后再排下一次,网慢时不会叠起来。
|
|
763
|
+
useEffect(() => {
|
|
764
|
+
if (loginKey === '') return undefined
|
|
765
|
+
let stopped = false
|
|
766
|
+
let timer = null
|
|
767
|
+
const tick = async () => {
|
|
768
|
+
try {
|
|
769
|
+
const r = await post(BILI + '/login/poll', { key: loginKey })
|
|
770
|
+
if (stopped || !alive.current) return
|
|
771
|
+
if (r && r.state === 'ok') {
|
|
772
|
+
setLoginKey(''); setLoginQr(''); setLoginState('ok')
|
|
773
|
+
say('B站 登录成功', 'ok')
|
|
774
|
+
load()
|
|
775
|
+
return
|
|
776
|
+
}
|
|
777
|
+
if (r && (r.state === 'expired' || r.state === 'unknown')) {
|
|
778
|
+
setLoginKey('')
|
|
779
|
+
setLoginState(r.state === 'expired' ? 'expired' : 'error')
|
|
780
|
+
return
|
|
781
|
+
}
|
|
782
|
+
if (r && r.state) setLoginState(r.state)
|
|
783
|
+
} catch { /* 下一次再试 */ }
|
|
784
|
+
if (!stopped) timer = setTimeout(tick, 3000)
|
|
785
|
+
}
|
|
786
|
+
timer = setTimeout(tick, 3000)
|
|
787
|
+
return () => { stopped = true; if (timer) clearTimeout(timer) }
|
|
788
|
+
}, [loginKey, load, say])
|
|
789
|
+
|
|
790
|
+
const projects = useMemo(() => {
|
|
791
|
+
const list = (agent && Array.isArray(agent.workspaces)) ? agent.workspaces.slice() : []
|
|
792
|
+
const currentCwd = agent && agent.current ? agent.current.cwd : ''
|
|
793
|
+
if (currentCwd && !list.some((w) => samePath(w.cwd, currentCwd))) {
|
|
794
|
+
list.unshift({ cwd: currentCwd, displayName: (agent.current && agent.current.displayName) || shortPath(currentCwd), sources: [] })
|
|
795
|
+
}
|
|
796
|
+
return list
|
|
797
|
+
}, [agent])
|
|
798
|
+
|
|
799
|
+
const workspaceId = useMemo(() => {
|
|
800
|
+
const items = (workspacesSnap && Array.isArray(workspacesSnap.items)) ? workspacesSnap.items : []
|
|
801
|
+
const found = items.find((w) => samePath(w.path, cwd))
|
|
802
|
+
return found ? found.workspaceId : ''
|
|
803
|
+
}, [workspacesSnap, cwd])
|
|
804
|
+
|
|
805
|
+
const conversations = useMemo(() => {
|
|
806
|
+
const byId = (sessionsSnap && sessionsSnap.byId) ? sessionsSnap.byId : {}
|
|
807
|
+
const list = []
|
|
808
|
+
for (const id of Object.keys(byId)) {
|
|
809
|
+
const row = byId[id]
|
|
810
|
+
if (!row) continue
|
|
811
|
+
if (cwd !== '' && !samePath(row.cwd, cwd)) continue
|
|
812
|
+
list.push({ id, title: row.displayTitle || row.title || id, updatedAt: Number(row.updatedAt) || 0, running: row.running === true, cwd: row.cwd || '' })
|
|
813
|
+
}
|
|
814
|
+
list.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
815
|
+
return list
|
|
816
|
+
}, [sessionsSnap, cwd])
|
|
817
|
+
|
|
818
|
+
useEffect(() => {
|
|
819
|
+
if (selectedChat !== '') return
|
|
820
|
+
if (conversations.length > 0) setSelectedChat(conversations[0].id)
|
|
821
|
+
}, [conversations, selectedChat])
|
|
822
|
+
|
|
823
|
+
const copy = useCallback(async (text, what) => {
|
|
824
|
+
const value = String(text || '')
|
|
825
|
+
if (value === '') { say('没有可复制的内容', 'err'); return }
|
|
826
|
+
if (await copyText(value)) say('已复制' + (what ? what : ''), 'ok')
|
|
827
|
+
else say('复制失败;浏览器不让写剪贴板', 'err')
|
|
828
|
+
}, [say])
|
|
829
|
+
|
|
830
|
+
const changeProject = useCallback((next) => {
|
|
831
|
+
if (next === cwdRef.current) return
|
|
832
|
+
if (draftRef.current.dirty && !window.confirm('人格正文有未保存的修改,切换项目会丢掉这些修改。继续切换吗?')) return
|
|
833
|
+
setCwd(next); setDraft(null)
|
|
834
|
+
draftRef.current.dirty = false; draftRef.current.text = null
|
|
835
|
+
setDirty(false); setCreateConfirm(false)
|
|
836
|
+
setSelectedChat(''); setExpandedChats({}); setShowAllChats(false)
|
|
837
|
+
}, [])
|
|
838
|
+
|
|
839
|
+
const savePersona = useCallback(() => runBusy('save', async () => {
|
|
840
|
+
if (cwd === '' || draft === null) return
|
|
841
|
+
const sent = draft
|
|
842
|
+
try {
|
|
843
|
+
await post(AG + '/save', { scope: 'project', kind: 'stored', cwd, content: sent })
|
|
844
|
+
// 保存途中又改了的话,保留“有未保存的修改”
|
|
845
|
+
if (draftRef.current.text === sent) { draftRef.current.dirty = false; setDirty(false) }
|
|
846
|
+
say('局部人格已保存(下一个回合生效)', 'ok')
|
|
847
|
+
await load()
|
|
848
|
+
} catch (error) { say('保存失败:' + errText(error), 'err') }
|
|
849
|
+
}), [runBusy, cwd, draft, load, say])
|
|
850
|
+
|
|
851
|
+
const createPersona = useCallback((overwrite) => {
|
|
852
|
+
if (cwd === '') { say('先选一个项目', 'err'); return undefined }
|
|
853
|
+
return runBusy('create', async () => {
|
|
854
|
+
try {
|
|
855
|
+
const r = await post(AG + '/create', { scope: 'project', kind: 'stored', cwd, overwrite: overwrite === true })
|
|
856
|
+
if (r && r.created === false) {
|
|
857
|
+
setCreateConfirm(true)
|
|
858
|
+
say('已有局部人格,没有覆盖;要重建就点「覆盖为模板」', 'err')
|
|
859
|
+
} else {
|
|
860
|
+
setCreateConfirm(false)
|
|
861
|
+
draftRef.current.dirty = false
|
|
862
|
+
setDirty(false)
|
|
863
|
+
say('已按模板新建局部人格', 'ok')
|
|
864
|
+
await load()
|
|
865
|
+
}
|
|
866
|
+
} catch (error) { say('新建失败:' + errText(error), 'err') }
|
|
867
|
+
})
|
|
868
|
+
}, [runBusy, cwd, load, say])
|
|
869
|
+
|
|
870
|
+
const openPersona = useCallback(() => {
|
|
871
|
+
if (cwd === '') { say('先选一个项目', 'err'); return undefined }
|
|
872
|
+
return runBusy('open', async () => {
|
|
873
|
+
try {
|
|
874
|
+
const r = await post(AG + '/open', { scope: 'project', kind: 'stored', cwd })
|
|
875
|
+
say(r && r.opened ? '已在文件管理器中打开:' + r.opened : '已请求打开原文件', 'ok')
|
|
876
|
+
} catch (error) { say('打开失败:' + errText(error), 'err') }
|
|
877
|
+
})
|
|
878
|
+
}, [runBusy, cwd, say])
|
|
879
|
+
|
|
880
|
+
const agentConfig = useCallback(async (patch) => {
|
|
881
|
+
try { await post(AG + '/config', patch); await load() } catch (error) { say(errText(error), 'err') }
|
|
882
|
+
}, [load, say])
|
|
883
|
+
|
|
884
|
+
const newChat = useCallback(() => runBusy('chat', async () => {
|
|
885
|
+
const nav = service('uiWorkspace')
|
|
886
|
+
const workspaces = service('workspaces')
|
|
887
|
+
if (!nav || typeof nav.connectWorkspace !== 'function') { say('当前宿主不支持新建对话', 'err'); return }
|
|
888
|
+
try {
|
|
889
|
+
let id = workspaceId
|
|
890
|
+
if (!id && workspaces && typeof workspaces.create === 'function') {
|
|
891
|
+
const view = await workspaces.create({ path: cwd })
|
|
892
|
+
id = view && view.workspaceId
|
|
893
|
+
}
|
|
894
|
+
if (!id) throw new Error('拿不到工作区 id')
|
|
895
|
+
const sid = await nav.connectWorkspace(id)
|
|
896
|
+
if (nav.openSession) nav.openSession(sid)
|
|
897
|
+
if (sid) setSelectedChat(sid)
|
|
898
|
+
say('已在这个项目里新建一个对话', 'ok')
|
|
899
|
+
await load()
|
|
900
|
+
} catch (error) { say('新建失败:' + errText(error), 'err') }
|
|
901
|
+
}), [runBusy, cwd, workspaceId, load, say])
|
|
902
|
+
|
|
903
|
+
const openChat = useCallback((id) => {
|
|
904
|
+
const nav = service('uiWorkspace')
|
|
905
|
+
if (!nav || typeof nav.openSession !== 'function') { say('当前宿主不支持切换对话', 'err'); return }
|
|
906
|
+
try { nav.openSession(id); setSelectedChat(id) } catch (error) { say(errText(error), 'err') }
|
|
907
|
+
}, [say])
|
|
908
|
+
|
|
909
|
+
// 绑定 / 解绑共用一个忙碌标记:两者不会同时在路上。
|
|
910
|
+
const bindQqChat = useCallback((id) => {
|
|
911
|
+
if (!id) { say('先选一个对话', 'err'); return undefined }
|
|
912
|
+
return runBusy('qq', async () => {
|
|
913
|
+
try {
|
|
914
|
+
const r = await post(AG + '/qq/bind', { sessionId: id, cwd })
|
|
915
|
+
say(r && r.ok ? '已把这个对话接到 QQ' : ('已写入绑定;' + ((r && r.reload && r.reload.message) || '网关重载后生效')), r && r.ok ? 'ok' : 'err')
|
|
916
|
+
await load()
|
|
917
|
+
} catch (error) { say('绑定失败:' + errText(error), 'err') }
|
|
918
|
+
})
|
|
919
|
+
}, [runBusy, cwd, load, say])
|
|
920
|
+
|
|
921
|
+
const bindQq = useCallback(() => bindQqChat(selectedChat), [bindQqChat, selectedChat])
|
|
922
|
+
|
|
923
|
+
const toggleChat = useCallback((id) => {
|
|
924
|
+
setSelectedChat(id)
|
|
925
|
+
setExpandedChats((prev) => ({ ...(prev || {}), [id]: !(prev && prev[id]) }))
|
|
926
|
+
}, [])
|
|
927
|
+
|
|
928
|
+
const unbindQq = useCallback(() => runBusy('qq', async () => {
|
|
929
|
+
try { await post(AG + '/qq/unbind', {}); say('已解除 QQ 绑定', 'ok'); await load() } catch (error) { say('解绑失败:' + errText(error), 'err') }
|
|
930
|
+
}), [runBusy, load, say])
|
|
931
|
+
|
|
932
|
+
const biliPatch = useCallback(async (patch) => {
|
|
933
|
+
try { await post(BILI + '/config', patch); await load() } catch (error) { say('保存失败:' + errText(error), 'err') }
|
|
934
|
+
}, [load, say])
|
|
935
|
+
|
|
936
|
+
const biliRun = useCallback(() => runBusy('bili-run', async () => {
|
|
937
|
+
try {
|
|
938
|
+
const r = await post(BILI + '/run', {})
|
|
939
|
+
say(r && r.error ? String(r.error) : '这一轮已经开跑,进度看下面的日志', r && r.error ? 'err' : 'ok')
|
|
940
|
+
await load()
|
|
941
|
+
} catch (error) { say('跑一轮失败:' + errText(error), 'err') }
|
|
942
|
+
}), [runBusy, load, say])
|
|
943
|
+
|
|
944
|
+
const biliLogin = useCallback(() => runBusy('bili-login', async () => {
|
|
945
|
+
setLoginKey('')
|
|
946
|
+
setLoginState('starting')
|
|
947
|
+
try {
|
|
948
|
+
const r = await post(BILI + '/login/start', {})
|
|
949
|
+
if (!r || r.ok === false) throw new Error((r && r.error) || '出码失败')
|
|
950
|
+
setLoginQr(r.qr || '')
|
|
951
|
+
setLoginState('waiting')
|
|
952
|
+
setLoginKey(r.key || '')
|
|
953
|
+
say('用专用小号扫码;手机上选「记住我」', 'ok')
|
|
954
|
+
} catch (error) { setLoginState('error'); say('登录码生成失败:' + errText(error), 'err') }
|
|
955
|
+
}), [runBusy, say])
|
|
956
|
+
|
|
957
|
+
const biliLogout = useCallback(() => runBusy('logout', async () => {
|
|
958
|
+
try {
|
|
959
|
+
const r = await post(BILI + '/logout', {})
|
|
960
|
+
if (!r || r.ok === false) throw new Error((r && r.error) || '退出失败')
|
|
961
|
+
setLogoutConfirm(false)
|
|
962
|
+
setLoginQr(''); setLoginKey(''); setLoginState('')
|
|
963
|
+
say('已退出 B站 登录', 'ok')
|
|
964
|
+
await load()
|
|
965
|
+
} catch (error) { say('退出失败:' + errText(error), 'err') }
|
|
966
|
+
}), [runBusy, load, say])
|
|
967
|
+
|
|
968
|
+
const refreshQqBind = useCallback(async () => {
|
|
969
|
+
try { const r = await get('/qqbot/im-qqbot/bind'); if (alive.current) setQqBind(r) } catch { /* ignore */ }
|
|
970
|
+
}, [])
|
|
971
|
+
|
|
972
|
+
const qqBindRefresh = useCallback(() => runBusy('qq-qr', async () => {
|
|
973
|
+
try { await post('/qqbot/im-qqbot/bind/refresh', {}); await refreshQqBind() } catch (error) { say('出码失败:' + errText(error), 'err') }
|
|
974
|
+
}), [runBusy, refreshQqBind, say])
|
|
975
|
+
|
|
976
|
+
// QQ 机器人扫码时:只在「对话与 QQ」页、页面可见时每 3 秒看一次状态,扫完 / 失败就停。
|
|
977
|
+
const qqPhase = qqBind && qqBind.phase ? qqBind.phase : ''
|
|
978
|
+
useEffect(() => {
|
|
979
|
+
if (tab !== 'chat' || !(qqPhase === 'starting' || qqPhase === 'waiting' || qqPhase === 'saving')) return undefined
|
|
980
|
+
const timer = setInterval(() => { if (!document.hidden) refreshQqBind() }, 3000)
|
|
981
|
+
return () => clearInterval(timer)
|
|
982
|
+
}, [tab, qqPhase, refreshQqBind])
|
|
983
|
+
|
|
984
|
+
const saveTts = useCallback((extra) => {
|
|
985
|
+
if (!ttsForm) return undefined
|
|
986
|
+
return runBusy('tts', async () => {
|
|
987
|
+
try {
|
|
988
|
+
const body = { ...ttsForm, ...(extra || {}) }
|
|
989
|
+
if (String(ttsKey || '').trim() !== '') body.apiKey = String(ttsKey).trim()
|
|
990
|
+
const r = await post(CC + '/tts/config', body)
|
|
991
|
+
if (r && r.config && alive.current) setTts(r.config)
|
|
992
|
+
setTtsKey('')
|
|
993
|
+
say('语音设置已保存', 'ok')
|
|
994
|
+
} catch (error) { say('保存失败:' + errText(error), 'err') }
|
|
995
|
+
})
|
|
996
|
+
}, [runBusy, ttsForm, ttsKey, say])
|
|
997
|
+
|
|
998
|
+
const stopSpeaking = useCallback(() => {
|
|
999
|
+
stopAudio()
|
|
1000
|
+
setPlaying(false)
|
|
1001
|
+
setVoiceNote('已停止')
|
|
1002
|
+
}, [stopAudio])
|
|
1003
|
+
|
|
1004
|
+
const speak = useCallback(async () => {
|
|
1005
|
+
const text = String(voiceText || '').trim()
|
|
1006
|
+
if (text === '') { say('先写一段要读的文字', 'err'); return }
|
|
1007
|
+
if (voiceBusy) return
|
|
1008
|
+
setVoiceBusy('1')
|
|
1009
|
+
setVoiceNote('')
|
|
1010
|
+
stopAudio()
|
|
1011
|
+
setPlaying(false)
|
|
1012
|
+
try {
|
|
1013
|
+
const res = await fetch(CC + '/tts', {
|
|
1014
|
+
method: 'POST', credentials: 'same-origin',
|
|
1015
|
+
headers: { 'content-type': 'application/json' },
|
|
1016
|
+
body: JSON.stringify({ text }),
|
|
1017
|
+
})
|
|
1018
|
+
if (!res.ok) {
|
|
1019
|
+
let message = 'HTTP ' + res.status
|
|
1020
|
+
try { const j = await res.json(); if (j && j.error) message = j.error } catch { /* not json */ }
|
|
1021
|
+
throw new Error(message)
|
|
1022
|
+
}
|
|
1023
|
+
const blob = await res.blob()
|
|
1024
|
+
if (!alive.current) return
|
|
1025
|
+
const url = URL.createObjectURL(blob)
|
|
1026
|
+
const audio = new Audio(url)
|
|
1027
|
+
audioRef.current = audio
|
|
1028
|
+
audioUrlRef.current = url
|
|
1029
|
+
const secs = Number(res.headers.get('x-companion-tts-seconds'))
|
|
1030
|
+
const size = (secs > 0 ? secs.toFixed(1) + ' 秒 · ' : '') + Math.round(blob.size / 1024) + ' KB'
|
|
1031
|
+
audio.onended = () => { if (audioRef.current !== audio) return; stopAudio(); if (alive.current) { setPlaying(false); setVoiceNote('播完了(' + size + ')') } }
|
|
1032
|
+
audio.onerror = () => { if (audioRef.current !== audio) return; stopAudio(); if (alive.current) { setPlaying(false); setVoiceNote('浏览器播不了这段音频') } }
|
|
1033
|
+
await audio.play()
|
|
1034
|
+
if (alive.current && audioRef.current === audio) { setPlaying(true); setVoiceNote('正在播放(' + size + ')') }
|
|
1035
|
+
} catch (error) {
|
|
1036
|
+
stopAudio()
|
|
1037
|
+
setPlaying(false)
|
|
1038
|
+
setVoiceNote('')
|
|
1039
|
+
say('朗读失败:' + errText(error), 'err')
|
|
1040
|
+
} finally { if (alive.current) setVoiceBusy('') }
|
|
1041
|
+
}, [voiceText, voiceBusy, say, stopAudio])
|
|
1042
|
+
|
|
1043
|
+
const speakToQq = useCallback(async () => {
|
|
1044
|
+
const text = String(voiceText || '').trim()
|
|
1045
|
+
if (text === '') { say('先写一段要读的文字', 'err'); return }
|
|
1046
|
+
if (voiceBusy) return
|
|
1047
|
+
setVoiceBusy('qq')
|
|
1048
|
+
try {
|
|
1049
|
+
const r = await post(CC + '/tts/qq', { text })
|
|
1050
|
+
say(r && r.ok ? '已发到 QQ(' + (Number(r.seconds) > 0 ? Number(r.seconds).toFixed(1) + ' 秒,' : '') + Math.round((Number(r.bytes) || 0) / 1024) + ' KB 语音)' : '已发送', 'ok')
|
|
1051
|
+
} catch (error) { say('发到 QQ 失败:' + errText(error), 'err') } finally { if (alive.current) setVoiceBusy('') }
|
|
1052
|
+
}, [voiceText, voiceBusy, say])
|
|
1053
|
+
|
|
1054
|
+
const memeOp = useCallback(async (op, extra) => {
|
|
1055
|
+
setMemeBusy(op)
|
|
1056
|
+
try {
|
|
1057
|
+
const r = await post('/dsh-memes-api', { op, ...(extra || {}) })
|
|
1058
|
+
if (r && r.ok && alive.current) setMeme(r)
|
|
1059
|
+
say(r && r.message ? r.message : '已保存', 'ok')
|
|
1060
|
+
} catch (error) { say('表情包设置失败:' + errText(error), 'err') } finally { if (alive.current) setMemeBusy('') }
|
|
1061
|
+
}, [say])
|
|
1062
|
+
|
|
1063
|
+
const pickTtsProvider = useCallback((id) => {
|
|
1064
|
+
const preset = (tts && Array.isArray(tts.presets) ? tts.presets : []).find((x) => x.id === id)
|
|
1065
|
+
setTtsForm((form) => ({
|
|
1066
|
+
...(form || {}),
|
|
1067
|
+
provider: id,
|
|
1068
|
+
...(preset ? { baseUrl: preset.baseUrl, model: preset.model, voice: preset.voice, language: preset.language } : {}),
|
|
1069
|
+
}))
|
|
1070
|
+
}, [tts])
|
|
1071
|
+
|
|
1072
|
+
const editTts = useCallback((key, value) => setTtsForm((form) => ({ ...(form || {}), [key]: value })), [])
|
|
1073
|
+
|
|
1074
|
+
const testTts = useCallback(() => runBusy('tts-test', async () => {
|
|
1075
|
+
setTtsProbe(null)
|
|
1076
|
+
try {
|
|
1077
|
+
const r = await post(CC + '/tts/test', { provider: ttsForm && ttsForm.provider, baseUrl: ttsForm && ttsForm.baseUrl, qwenPort: ttsForm && ttsForm.qwenPort })
|
|
1078
|
+
if (alive.current) setTtsProbe(r)
|
|
1079
|
+
} catch (error) { if (alive.current) setTtsProbe({ ok: false, detail: errText(error) }) }
|
|
1080
|
+
}), [runBusy, ttsForm])
|
|
1081
|
+
|
|
1082
|
+
const localAction = useCallback((action) => runBusy('local-' + action, async () => {
|
|
1083
|
+
try {
|
|
1084
|
+
// 先把表单存了:启动 / 安装用的是保存后的模型、端口、设备
|
|
1085
|
+
if (ttsForm && (action === 'start' || action === 'install')) {
|
|
1086
|
+
const saved = await post(CC + '/tts/config', { ...ttsForm })
|
|
1087
|
+
if (saved && saved.config && alive.current) setTts(saved.config)
|
|
1088
|
+
}
|
|
1089
|
+
const r = await post(CC + '/tts/local/' + action, action === 'install' ? { device: ttsForm && ttsForm.qwenDevice, pipIndex: ttsForm && ttsForm.pipIndex } : {})
|
|
1090
|
+
if (r && r.ok === false) say(String(r.error || '操作失败'), 'err')
|
|
1091
|
+
else say(action === 'install' ? '开始安装(几分钟到几十分钟,看网速)' : action === 'start' ? '开始启动;第一次要下载模型,会比较久' : '已停止', 'ok')
|
|
1092
|
+
} catch (error) { say(errText(error), 'err') }
|
|
1093
|
+
await loadLocalTts()
|
|
1094
|
+
}), [runBusy, ttsForm, say, loadLocalTts])
|
|
1095
|
+
|
|
1096
|
+
// 保存后的 TTS 配置回来时,表单也跟着换(模型 / 声音可能被「用这个声音」改了)
|
|
1097
|
+
const adoptTts = useCallback((config) => {
|
|
1098
|
+
if (!config || !alive.current) return
|
|
1099
|
+
setTts(config)
|
|
1100
|
+
const form = {}
|
|
1101
|
+
for (const key of TTS_FORM_KEYS) form[key] = config[key] === undefined || config[key] === null ? '' : config[key]
|
|
1102
|
+
setTtsForm(form)
|
|
1103
|
+
}, [])
|
|
1104
|
+
|
|
1105
|
+
const createVoice = useCallback(({ name, refText, language, file }) => runBusy('voice-create', async () => {
|
|
1106
|
+
try {
|
|
1107
|
+
const audio = await readFileAsDataUrl(file)
|
|
1108
|
+
const r = await post(CC + '/voices', { name, refText, language, audio })
|
|
1109
|
+
if (r && alive.current) setVoiceList((v) => ({ ...(v || {}), voices: r.voices }))
|
|
1110
|
+
say('做好了:「' + (r && r.voice ? r.voice.name : name) + '」' + (r && r.voice && r.voice.truncated ? '(超过 30 秒,只取了前 30 秒)' : '') + ';点「用这个声音」启用', 'ok')
|
|
1111
|
+
return true
|
|
1112
|
+
} catch (error) { say('制作失败:' + errText(error), 'err'); return false }
|
|
1113
|
+
}), [runBusy, say])
|
|
1114
|
+
|
|
1115
|
+
const useVoice = useCallback((v) => runBusy('voice-use', async () => {
|
|
1116
|
+
try {
|
|
1117
|
+
const r = await post(CC + '/voices/use', { id: v.id })
|
|
1118
|
+
if (r && r.config) adoptTts(r.config)
|
|
1119
|
+
await loadVoices()
|
|
1120
|
+
say(r && r.restart ? '已换成「' + v.name + '」;模型换成了 Base,点「停止」再「保存并启动」生效' : '已换成「' + v.name + '」' + (r && r.model ? '(模型:' + r.model.split('/').pop() + ')' : ''), 'ok')
|
|
1121
|
+
} catch (error) { say(errText(error), 'err') }
|
|
1122
|
+
}), [runBusy, adoptTts, loadVoices, say])
|
|
1123
|
+
|
|
1124
|
+
const deleteVoice = useCallback((v) => {
|
|
1125
|
+
if (!window.confirm('删除角色声音「' + v.name + '」?上传的音频会一起删掉,不能恢复。')) return undefined
|
|
1126
|
+
return runBusy('voice-delete', async () => {
|
|
1127
|
+
try {
|
|
1128
|
+
const r = await post(CC + '/voices/delete', { id: v.id })
|
|
1129
|
+
if (r && r.config) adoptTts(r.config)
|
|
1130
|
+
if (r && alive.current) setVoiceList((x) => ({ ...(x || {}), voices: r.voices }))
|
|
1131
|
+
await loadVoices()
|
|
1132
|
+
say('已删除「' + v.name + '」', 'ok')
|
|
1133
|
+
} catch (error) { say(errText(error), 'err') }
|
|
1134
|
+
})
|
|
1135
|
+
}, [runBusy, adoptTts, loadVoices, say])
|
|
1136
|
+
|
|
1137
|
+
const setVideoLogin = useCallback((on) => runBusy('video-login', async () => {
|
|
1138
|
+
try {
|
|
1139
|
+
const r = await post(CC + '/video/bili-login', { on })
|
|
1140
|
+
say(on ? '分镜插件会用 B站 专用号的登录看高清' : '已关闭:分镜插件改回匿名(最高 480P)', 'ok')
|
|
1141
|
+
if (r && alive.current) setVideoInfo((v) => ({ ...(v || {}), ...r }))
|
|
1142
|
+
} catch (error) { say(errText(error), 'err') }
|
|
1143
|
+
await loadVideo()
|
|
1144
|
+
}), [runBusy, say, loadVideo])
|
|
1145
|
+
|
|
1146
|
+
const installYtdlp = useCallback(() => runBusy('ytdlp', async () => {
|
|
1147
|
+
try {
|
|
1148
|
+
const r = await post(CC + '/doctor/install', { what: 'yt-dlp' })
|
|
1149
|
+
if (r && r.ok) say('yt-dlp 装好了(' + (r.version || '') + ')', 'ok')
|
|
1150
|
+
else say('安装失败:' + String((r && (r.error || r.output)) || '看日志').slice(-300), 'err')
|
|
1151
|
+
} catch (error) { say('安装失败:' + errText(error), 'err') }
|
|
1152
|
+
await loadVideo()
|
|
1153
|
+
if (tab === 'doctor') await checkDoctor()
|
|
1154
|
+
}), [runBusy, say, loadVideo, checkDoctor, tab])
|
|
1155
|
+
|
|
1156
|
+
const qq = (agent && agent.qq) ? agent.qq : null
|
|
1157
|
+
const qqPeer = qq && Array.isArray(qq.peers) ? (qq.peers.find((p) => p.boundSessionId) || qq.peers[0]) : null
|
|
1158
|
+
const boundSession = qqPeer && qqPeer.boundSessionId ? qqPeer.boundSessionId : ''
|
|
1159
|
+
const boundTitle = boundSession ? (((conversations.find((c) => c.id === boundSession) || {}).title) || boundSession) : ''
|
|
1160
|
+
const selectedTitle = selectedChat ? (((conversations.find((c) => c.id === selectedChat) || {}).title) || selectedChat) : ''
|
|
1161
|
+
const memInfo = mem && mem.memory ? mem.memory : null
|
|
1162
|
+
const biliCfg = bili && bili.config ? bili.config : {}
|
|
1163
|
+
const biliReady = Boolean(bili)
|
|
1164
|
+
const loggedIn = Boolean(bili && bili.loggedIn)
|
|
1165
|
+
const customTimes = bili && Array.isArray(bili.customTimes) ? bili.customTimes : []
|
|
1166
|
+
const focusCount = bili ? Number(bili.focusCount || 0) : 0
|
|
1167
|
+
const dutyRunning = Boolean(bili && bili.dutyRunning)
|
|
1168
|
+
const worldRunning = Boolean(world && world.running)
|
|
1169
|
+
const worldMemory = world && world.memory ? world.memory : {}
|
|
1170
|
+
const logLines = String((bili && bili.logTail) || '').split('\n').filter((x) => x.trim() !== '').slice(-10)
|
|
1171
|
+
const nextLabel = !bili ? '—' : (customTimes.length ? customTimes.join('、') : (biliCfg.peakValley ? '内置谷时' : '手动'))
|
|
1172
|
+
const projectName = (projects.find((p) => samePath(p.cwd, cwd)) || {}).displayName || shortPath(cwd)
|
|
1173
|
+
const hasDraft = draft !== null
|
|
1174
|
+
const ttsOff = Boolean(ttsForm && ttsForm.provider === 'off')
|
|
1175
|
+
const ttsPreset = ttsForm && tts && Array.isArray(tts.presets) ? (tts.presets.find((p) => p.id === ttsForm.provider) || null) : null
|
|
1176
|
+
const ttsLocal = Boolean(ttsPreset && ttsPreset.group === 'local')
|
|
1177
|
+
const ttsReady = Boolean(tts && tts.enabled && ttsForm && !ttsOff && tts.provider === ttsForm.provider)
|
|
1178
|
+
const ttsPresets = tts && Array.isArray(tts.presets) ? tts.presets : []
|
|
1179
|
+
const memSessions = memInfo && Array.isArray(memInfo.sessions) ? memInfo.sessions.length : 0
|
|
1180
|
+
const qqServiceOk = Boolean(mem && mem.qqService && mem.qqService.available)
|
|
1181
|
+
const loading = !loaded
|
|
1182
|
+
|
|
1183
|
+
const statusChips = [
|
|
1184
|
+
{ label: 'B站', value: !bili ? (loading ? '读取中…' : '没连上') : (loggedIn ? '已登录' : '未登录'), ok: loggedIn },
|
|
1185
|
+
{ label: 'QQ', value: !agent ? (loading ? '读取中…' : '没连上') : (boundSession ? '已绑定' : '未绑定'), ok: Boolean(boundSession) },
|
|
1186
|
+
{ label: '记忆', value: !mem ? (loading ? '读取中…' : '没连上') : memSessions + ' 个对话', ok: Boolean(worldRunning) },
|
|
1187
|
+
{ label: '分镜', value: !videoInfo ? '—' : (videoInfo.storyboard && videoInfo.storyboard.installed ? (videoInfo.ytdlp && videoInfo.ytdlp.found ? '可看视频' : '缺 yt-dlp') : '未装'), ok: Boolean(videoInfo && videoInfo.storyboard && videoInfo.storyboard.installed && videoInfo.ytdlp && videoInfo.ytdlp.found) },
|
|
1188
|
+
{ label: '值守', value: !bili ? (loading ? '读取中…' : '没连上') : (dutyRunning ? '正在跑' : nextLabel), ok: dutyRunning || Boolean(biliCfg.peakValley) || customTimes.length > 0 },
|
|
1189
|
+
]
|
|
1190
|
+
|
|
1191
|
+
const runLabel = !biliReady ? 'B站 没连上' : (dutyRunning ? '正在跑…' : (loggedIn ? '现在跑一轮 B站' : '先登录 B站'))
|
|
1192
|
+
const canRun = biliReady && loggedIn && !dutyRunning && !busy['bili-run']
|
|
1193
|
+
|
|
1194
|
+
const tabs = [
|
|
1195
|
+
['home', '总览'], ['persona', '人格'], ['chat', '对话与 QQ'], ['memory', '记忆'], ['bili', 'B站'],
|
|
1196
|
+
['meme', '表情包'], ['voice', '语音'], ['doctor', '环境'], ['about', '关于'],
|
|
1197
|
+
]
|
|
1198
|
+
|
|
1199
|
+
// 左右方向键在页签间移动(标准 tablist 键盘行为)
|
|
1200
|
+
const onTabKey = (e) => {
|
|
1201
|
+
if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft' && e.key !== 'Home' && e.key !== 'End') return
|
|
1202
|
+
e.preventDefault()
|
|
1203
|
+
const ids = tabs.map((t) => t[0])
|
|
1204
|
+
const at = ids.indexOf(tab)
|
|
1205
|
+
const next = e.key === 'Home' ? 0 : e.key === 'End' ? ids.length - 1 : (at + (e.key === 'ArrowRight' ? 1 : -1) + ids.length) % ids.length
|
|
1206
|
+
setTab(ids[next])
|
|
1207
|
+
const el = document.getElementById('dc-tab-' + ids[next])
|
|
1208
|
+
if (el) el.focus()
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const qrStateText = loginState === 'starting' ? '正在出码…'
|
|
1212
|
+
: loginState === 'waiting' ? '等待扫码…'
|
|
1213
|
+
: loginState === 'scanned' ? '已扫,等手机确认'
|
|
1214
|
+
: loginState === 'expired' ? '码过期了,点「重新出码」'
|
|
1215
|
+
: loginState === 'error' ? '出码或查询出错了,再点一次'
|
|
1216
|
+
: ''
|
|
1217
|
+
const loginStale = loginState === 'expired' || loginState === 'error'
|
|
1218
|
+
|
|
1219
|
+
const qqBindPanel = (() => {
|
|
1220
|
+
if (!qqBind) return h('div', { className: 'dc-note', style: { marginTop: '8px' } }, loading ? '正在读取机器人绑定状态…' : '读不到 QQ 网关的绑定状态(网关没加载或没响应)。')
|
|
1221
|
+
if (qqPhase === 'waiting' && qqBind.qrSvg) {
|
|
1222
|
+
return h('div', null,
|
|
1223
|
+
h('div', { className: 'dc-note', style: { marginTop: '12px' } }, '用手机 QQ 扫码绑定机器人(扫完这里会自动更新)'),
|
|
1224
|
+
h('div', { className: 'dc-qr-wrap' }, h('img', { className: 'dc-qr', src: qqBind.qrSvg, alt: '绑定 QQ 机器人的二维码' })))
|
|
1225
|
+
}
|
|
1226
|
+
if (qqPhase === 'starting') return h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '正在生成绑定码…')
|
|
1227
|
+
if (qqPhase === 'saving') return h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '已扫码,正在保存凭据…')
|
|
1228
|
+
if (qqPhase === 'failed') return h('div', { className: 'dc-banner', 'data-tone': 'err', style: { marginTop: '10px', marginBottom: 0 } }, '绑定失败:' + String(qqBind.reason || '未知原因') + ';点右上角重新扫码。')
|
|
1229
|
+
if (qqPhase === 'bound') return h('div', { className: 'dc-note', style: { marginTop: '8px' } }, 'QQ 机器人已绑定。')
|
|
1230
|
+
return h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '需要绑定机器人时点右上角「扫码绑定机器人」。')
|
|
1231
|
+
})()
|
|
1232
|
+
|
|
1233
|
+
const loadNotice = loaded && loadErrors.length
|
|
1234
|
+
? h('div', { className: 'dc-banner', role: 'status' }, '这些接口这次没响应,页面上对应的数据可能是旧的或空的:' + loadErrors.join('、') + '。缺插件看「环境」页;刚装的需要刷新或重启 DSH。')
|
|
1235
|
+
: null
|
|
1236
|
+
|
|
1237
|
+
return h('div', { className: 'dc-root' },
|
|
1238
|
+
h('div', { className: 'dc-page' },
|
|
1239
|
+
h('div', { className: 'dc-hero' },
|
|
1240
|
+
h('div', { className: 'dc-hero-top' },
|
|
1241
|
+
h('div', { className: 'dc-avatar', 'aria-hidden': true }, h(Icon, { name: 'leaf', size: 30 })),
|
|
1242
|
+
h('div', null,
|
|
1243
|
+
h('h1', null, 'dsh-chat-comprehension'),
|
|
1244
|
+
h('p', null, '一个入口:局部人格 · QQ · 记忆 · B站 值班'))),
|
|
1245
|
+
h('div', { className: 'dc-chips', role: 'list', 'aria-label': '状态' },
|
|
1246
|
+
statusChips.map((chip) => h('span', { key: chip.label, className: 'dc-chip', role: 'listitem' },
|
|
1247
|
+
h('span', { className: 'dc-dot' + (chip.ok ? ' ok' : ''), 'aria-hidden': true }),
|
|
1248
|
+
chip.label + ':', h('b', null, chip.value)))),
|
|
1249
|
+
h('div', { className: 'dc-hero-actions' },
|
|
1250
|
+
h(Btn, { icon: 'play', disabled: !canRun, onClick: biliRun }, busy['bili-run'] ? '正在开跑…' : runLabel),
|
|
1251
|
+
h(Btn, { icon: 'link', onClick: () => setTab('chat') }, '对话与 QQ'),
|
|
1252
|
+
h(Btn, { icon: 'memory', onClick: () => setTab('memory') }, '看看记忆'))),
|
|
1253
|
+
|
|
1254
|
+
h('div', { className: 'dc-tabs', role: 'tablist', 'aria-label': '陪伴设置分页', onKeyDown: onTabKey },
|
|
1255
|
+
tabs.map(([id, label]) => h('button', {
|
|
1256
|
+
key: id, id: 'dc-tab-' + id, type: 'button', role: 'tab', className: 'dc-tab',
|
|
1257
|
+
'aria-selected': tab === id ? 'true' : 'false', 'aria-controls': 'dc-panel', tabIndex: tab === id ? 0 : -1,
|
|
1258
|
+
onClick: () => setTab(id),
|
|
1259
|
+
}, label))),
|
|
1260
|
+
|
|
1261
|
+
h('div', { id: 'dc-panel', role: 'tabpanel', 'aria-labelledby': 'dc-tab-' + tab },
|
|
1262
|
+
loadNotice,
|
|
1263
|
+
|
|
1264
|
+
tab === 'home' ? h('div', null,
|
|
1265
|
+
h('div', { className: 'dc-grid' },
|
|
1266
|
+
h(Card, null, h(Metric, { loading: !bili && loading, value: (bili && bili.pickedToday) || 0, unit: '条', label: '今天 B站 挑到' })),
|
|
1267
|
+
h(Card, null, h(Metric, { loading: !world && loading, value: (worldMemory.turns != null ? worldMemory.turns : 0), unit: '轮', label: 'QQ 专属记忆' })),
|
|
1268
|
+
h(Card, null, h(Metric, { loading: !bili && loading, value: focusCount, unit: '个', label: '关注 UP 主' })),
|
|
1269
|
+
h(Card, null, h(Metric, { loading: !bili && loading, value: nextLabel, label: '下一次值守' }))),
|
|
1270
|
+
h('div', { className: 'dc-split', style: { marginTop: '16px' } },
|
|
1271
|
+
h(Card, { title: '最近在做什么', sub: 'B站 值班日志的最后几行' },
|
|
1272
|
+
logLines.length ? h('pre', { className: 'dc-pre' }, logLines.join('\n'))
|
|
1273
|
+
: h('div', { className: 'dc-empty' }, !bili ? (loading ? '读取中…' : 'B站 值班插件没响应。') : '还没有日志。登录 B站 后跑一轮就有了。')),
|
|
1274
|
+
h(Card, { title: '今天的小结', sub: '挑到的视频会写进报告' },
|
|
1275
|
+
h('div', { className: 'dc-row', style: { marginBottom: '10px' } },
|
|
1276
|
+
h(Badge, { tone: bili && bili.ranToday > 0 ? 'ok' : 'neutral' }, (bili && bili.ranToday ? bili.ranToday : 0) + ' 轮'),
|
|
1277
|
+
h(Badge, { tone: pickedTone(bili) }, ((bili && bili.pickedToday) || 0) + ' / ' + ((biliCfg && biliCfg.perDay) ?? 5) + ' 条')),
|
|
1278
|
+
h('div', { className: 'dc-note', style: { marginBottom: '8px', wordBreak: 'break-all' } }, (bili && bili.reportPath) || '报告还没生成'),
|
|
1279
|
+
h('div', { className: 'dc-row' },
|
|
1280
|
+
h(Btn, { icon: 'copy', disabled: !bili || !bili.reportPath, onClick: () => copy(bili && bili.reportPath, '报告路径') }, '复制报告路径'),
|
|
1281
|
+
h(Btn, { icon: 'refresh', onClick: () => load() }, '刷新'))))) : null,
|
|
1282
|
+
|
|
1283
|
+
tab === 'persona' ? h('div', { className: 'dc-split' },
|
|
1284
|
+
h(Card, { title: '局部人格', sub: '只写这个项目;全局人格已删除' },
|
|
1285
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-project' }, '项目目录'),
|
|
1286
|
+
projects.length ? h('select', { id: 'dc-project', className: 'dc-select', value: cwd, onChange: (e) => changeProject(e.target.value) },
|
|
1287
|
+
projects.map((p) => h('option', { key: p.cwd, value: p.cwd }, (p.displayName || shortPath(p.cwd)) + ' — ' + p.cwd)))
|
|
1288
|
+
: h('div', { className: 'dc-empty' }, !agent ? (loading ? '读取中…' : 'dsh-agent-md 没响应,读不到工作区。') : '还没有工作区'),
|
|
1289
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '当前:' + (projectName || '未选择')),
|
|
1290
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1291
|
+
h(Btn, { icon: 'save', kind: 'primary', disabled: busy.save || !hasDraft || cwd === '', onClick: savePersona }, busy.save ? '保存中…' : (dirty ? '保存修改' : '保存')),
|
|
1292
|
+
h(Btn, { icon: 'spark', disabled: busy.create || cwd === '', onClick: () => createPersona(false) }, '按模板新建'),
|
|
1293
|
+
createConfirm ? h(Btn, { icon: 'check', kind: 'danger', disabled: busy.create, onClick: () => createPersona(true) }, '覆盖为模板') : null,
|
|
1294
|
+
createConfirm ? h(Btn, { icon: 'refresh', onClick: () => setCreateConfirm(false) }, '取消') : null,
|
|
1295
|
+
h(Btn, { icon: 'folder', disabled: busy.open || cwd === '', onClick: openPersona }, '打开原文件')),
|
|
1296
|
+
createConfirm ? h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '「覆盖为模板」会用模板替换这个项目现有的人格正文。') : null,
|
|
1297
|
+
h('div', { style: { marginTop: '16px' } },
|
|
1298
|
+
h(ToggleRow, { label: '启用局部人格', note: '关掉后这个项目就不再注入人格', disabled: !agent, on: agent ? agent.projectPersonaEnabled !== false : false, onChange: (v) => agentConfig({ projectPersonaEnabled: v }) }),
|
|
1299
|
+
h(ToggleRow, { label: '优先读项目里的 AGENT.md', note: '仓库自带的人设文件;有就优先于这里这份', disabled: !agent, on: agent ? Array.isArray(agent.localNames) && agent.localNames.length > 0 : false, onChange: (v) => agentConfig({ localNames: v ? ['AGENT.md'] : [] }) }))),
|
|
1300
|
+
h(Card, { title: '人格正文', sub: dirty ? '有未保存的修改' : '改动会在下一个回合生效' },
|
|
1301
|
+
h('textarea', { className: 'dc-textarea', value: draft === null ? '' : draft, spellCheck: false, 'aria-label': '人格正文',
|
|
1302
|
+
disabled: draft === null, placeholder: draft === null ? (loading ? '读取中…' : '先选一个项目') : '这个项目还没有局部人格;可以直接写,或点「按模板新建」',
|
|
1303
|
+
onChange: (e) => { setDraft(e.target.value); setDirty(true); draftRef.current.dirty = true; draftRef.current.text = e.target.value } }),
|
|
1304
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '字数:' + String((draft || '').length) + ' · 只影响语气与行事风格'))) : null,
|
|
1305
|
+
|
|
1306
|
+
tab === 'chat' ? h('div', { className: 'dc-list', style: { gap: '16px' } },
|
|
1307
|
+
h(Card, {
|
|
1308
|
+
title: 'QQ 绑定',
|
|
1309
|
+
sub: !agent ? (loading ? '读取中…' : 'dsh-agent-md 没响应') : (qq && qq.installed ? (qq.running ? '网关运行中' : '网关未运行') : '网关未加载'),
|
|
1310
|
+
actions: h(Btn, { icon: 'qr', disabled: busy['qq-qr'], onClick: qqBindRefresh }, busy['qq-qr'] ? '出码中…' : '扫码绑定机器人'),
|
|
1311
|
+
},
|
|
1312
|
+
h('div', { className: 'dc-row' },
|
|
1313
|
+
h(Badge, { tone: qq && qq.running ? 'ok' : 'warn' }, qq && qq.installed ? (qq.running ? '网关运行中' : '网关未运行') : '网关未加载'),
|
|
1314
|
+
h('div', { style: { flex: 1 } }),
|
|
1315
|
+
h(Btn, { icon: 'link', kind: 'primary', disabled: busy.qq || selectedChat === '', onClick: bindQq }, boundSession === selectedChat && selectedChat !== '' ? '已接到这个对话' : '把选中的对话接到 QQ'),
|
|
1316
|
+
boundSession ? h(Btn, { icon: 'link', onClick: unbindQq, disabled: busy.qq }, '解除绑定') : null),
|
|
1317
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '当前接在:' + (boundTitle || '还没接任何对话') + ';选中:' + (selectedTitle || '没选')),
|
|
1318
|
+
qqPeer ? h('div', { className: 'dc-note', style: { marginTop: '4px' } }, '账号:' + (qqPeer.scope === 'group' ? '群聊' : '私聊') + ' · ' + String(qqPeer.peerId || '').slice(-6)) : null,
|
|
1319
|
+
mem && mem.qqbotPatch ? h('div', { className: 'dc-note', style: { marginTop: '4px' } }, '网关补丁:' + (mem.qqbotPatch.patched ? '已打(' + (mem.qqbotPatch.version || '0.5.3') + ')' : (mem.qqbotPatch.found ? '未打,到「环境」页点「打 QQ 网关补丁」' : '没装 QQ 网关'))) : null,
|
|
1320
|
+
qqBindPanel),
|
|
1321
|
+
h(Card, {
|
|
1322
|
+
title: '对话',
|
|
1323
|
+
sub: '这个项目下的窗口;默认只显示最近 3 个',
|
|
1324
|
+
actions: h('div', { className: 'dc-row' },
|
|
1325
|
+
conversations.length > 3 ? h(Btn, { icon: 'refresh', onClick: () => setShowAllChats((v) => !v) }, showAllChats ? '收起' : '显示更多(+' + (conversations.length - 3) + ')') : null,
|
|
1326
|
+
h(Btn, { icon: 'spark', onClick: newChat, disabled: busy.chat || cwd === '' }, busy.chat ? '新建中…' : '新建')),
|
|
1327
|
+
},
|
|
1328
|
+
conversations.length ? h('div', { className: 'dc-list' },
|
|
1329
|
+
(showAllChats ? conversations : conversations.slice(0, 3)).map((c) => {
|
|
1330
|
+
const expanded = Boolean(expandedChats[c.id])
|
|
1331
|
+
const isBound = c.id === boundSession
|
|
1332
|
+
const stop = (e) => { if (e && e.stopPropagation) e.stopPropagation() }
|
|
1333
|
+
return h('div', { key: c.id, className: 'dc-block', 'data-on': selectedChat === c.id ? '' : undefined },
|
|
1334
|
+
h('div', {
|
|
1335
|
+
className: 'dc-block-head', role: 'button', tabIndex: 0, 'aria-expanded': expanded ? 'true' : 'false',
|
|
1336
|
+
'aria-controls': 'dc-chat-' + c.id, 'aria-label': c.title + (isBound ? '(QQ 正在用)' : '') + (expanded ? ',收起' : ',展开'),
|
|
1337
|
+
onClick: () => toggleChat(c.id),
|
|
1338
|
+
onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleChat(c.id) } },
|
|
1339
|
+
},
|
|
1340
|
+
h('span', { className: 'dc-caret', 'data-open': expanded ? '' : undefined, 'aria-hidden': true }, '▸'),
|
|
1341
|
+
h('div', { className: 'dc-item-main' },
|
|
1342
|
+
h('div', { className: 'dc-item-title', title: c.title }, c.title),
|
|
1343
|
+
h('div', { className: 'dc-item-sub' }, fmtTime(c.updatedAt) + (c.running ? ' · 运行中' : '') + (isBound ? ' · QQ 正在用' : ''))),
|
|
1344
|
+
isBound ? h(Badge, { tone: 'ok' }, 'QQ') : null),
|
|
1345
|
+
expanded ? h('div', { className: 'dc-block-body', id: 'dc-chat-' + c.id },
|
|
1346
|
+
h('div', { className: 'dc-note', style: { wordBreak: 'break-all' } }, 'ID:' + c.id),
|
|
1347
|
+
h('div', { className: 'dc-note', style: { wordBreak: 'break-all' } }, '目录:' + (c.cwd || '—')),
|
|
1348
|
+
h('div', { className: 'dc-row', style: { marginTop: '4px' } },
|
|
1349
|
+
h(Btn, { icon: 'open', onClick: (e) => { stop(e); openChat(c.id) } }, '打开'),
|
|
1350
|
+
h(Btn, { icon: 'link', kind: 'primary', disabled: busy.qq || isBound, onClick: (e) => { stop(e); bindQqChat(c.id) } }, isBound ? '已接到 QQ' : '接到 QQ'),
|
|
1351
|
+
h(Btn, { icon: 'copy', onClick: (e) => { stop(e); copy(c.id, '对话 ID') } }, '复制 ID'))) : null)
|
|
1352
|
+
}))
|
|
1353
|
+
: h('div', { className: 'dc-empty' }, !sessionsSnap ? '读取对话列表中…' : (cwd === '' ? '先在「人格」页选一个项目' : '还没有对话;点右上角「新建」')),
|
|
1354
|
+
!showAllChats && conversations.length > 3
|
|
1355
|
+
? h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '还有 ' + (conversations.length - 3) + ' 个对话没显示;点「显示更多」展开。')
|
|
1356
|
+
: null)) : null,
|
|
1357
|
+
|
|
1358
|
+
tab === 'memory' ? h('div', null,
|
|
1359
|
+
h('div', { className: 'dc-grid' },
|
|
1360
|
+
h(Card, null, h(Metric, { loading: !world && loading, value: worldMemory.turns != null ? worldMemory.turns : 0, unit: '轮', label: '已经记住的最近对话' })),
|
|
1361
|
+
h(Card, null, h(Metric, { loading: !world && loading, value: worldMemory.records != null ? worldMemory.records : 0, label: '归档消息' })),
|
|
1362
|
+
h(Card, null, h(Metric, { loading: !mem && loading, value: memSessions, unit: '个', label: '参与记忆的对话' })),
|
|
1363
|
+
h(Card, null, h(Metric, { loading: !world && loading, value: !world ? '没连上' : (worldRunning ? '运行中' : '停着'), label: '记忆引擎' }))),
|
|
1364
|
+
h('div', { className: 'dc-split', style: { marginTop: '16px' } },
|
|
1365
|
+
h(Card, { title: '记忆镜像', sub: '只给 QQ 当前对话读;你也能直接翻(只显示最后一段)' },
|
|
1366
|
+
memInfo && memInfo.mirrorInfo && memInfo.mirrorInfo.exists
|
|
1367
|
+
? h('pre', { className: 'dc-pre', style: { maxHeight: '420px' }, tabIndex: 0, 'aria-label': '记忆镜像内容' }, memInfo.mirror || '(镜像文件是空的)')
|
|
1368
|
+
: h('div', { className: 'dc-empty' }, !mem ? (loading ? '读取中…' : '读不到 /api/companion/state。') : '还没有记忆镜像。先把一个对话接到 QQ、在 QQ 里说句话。')),
|
|
1369
|
+
h(Card, { title: '规则', sub: '简单说' },
|
|
1370
|
+
h('div', { className: 'dc-note', style: { lineHeight: '1.9', whiteSpace: 'pre-line' } },
|
|
1371
|
+
'· 只有 QQ 当前绑定的那个对话会注入记忆;\n· 历史对话只作为“以前说过的话”被读,不再写入;\n· 别的对话既不会读,也不会写这份记忆;\n· 镜像文件在本机 .dsh/agents/qq-memory.md。'),
|
|
1372
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1373
|
+
h(Btn, { icon: 'copy', disabled: !(memInfo && memInfo.mirrorPath), onClick: () => copy(memInfo && memInfo.mirrorPath, '镜像文件路径') }, '复制镜像路径'),
|
|
1374
|
+
h(Btn, { icon: 'memory', onClick: () => load() }, '刷新'))))) : null,
|
|
1375
|
+
|
|
1376
|
+
tab === 'bili' ? h('div', { className: 'dc-split' },
|
|
1377
|
+
h('div', { className: 'dc-list', style: { gap: '16px' } },
|
|
1378
|
+
h(Card, { title: '账号', sub: !biliReady ? (loading ? '读取中…' : 'B站 值班插件没响应') : (loggedIn ? '已登录专用号' : '还没登录;扫码就行') },
|
|
1379
|
+
!biliReady ? h('div', { className: 'dc-empty' }, loading ? '读取中…' : '读不到 dsh-bili-scroll 的状态;看「环境」页是否装好。')
|
|
1380
|
+
: loggedIn
|
|
1381
|
+
? h('div', null,
|
|
1382
|
+
h('div', { className: 'dc-row' },
|
|
1383
|
+
h(Badge, { tone: 'ok' }, 'B站 已登录'),
|
|
1384
|
+
h('span', { className: 'dc-note' }, '关注 ' + focusCount + ' 个 UP 主'),
|
|
1385
|
+
h('div', { style: { marginLeft: 'auto' } },
|
|
1386
|
+
logoutConfirm
|
|
1387
|
+
? h('div', { className: 'dc-row' },
|
|
1388
|
+
h(Btn, { icon: 'check', kind: 'danger', disabled: busy.logout, onClick: biliLogout }, busy.logout ? '退出中…' : '确认退出'),
|
|
1389
|
+
h(Btn, { icon: 'refresh', onClick: () => setLogoutConfirm(false) }, '取消'))
|
|
1390
|
+
: h(Btn, { icon: 'open', kind: 'danger', onClick: () => setLogoutConfirm(true) }, '退出登录'))),
|
|
1391
|
+
logoutConfirm
|
|
1392
|
+
? h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '退出后这个专用号就不能再跑值班了;已生成的日报、已发出去的私信不会删。')
|
|
1393
|
+
: null)
|
|
1394
|
+
: h('div', null,
|
|
1395
|
+
h('div', { className: 'dc-note', style: { marginBottom: '10px' } }, '用给机器人单独开的小号扫;手机上确认时选「记住我」。'),
|
|
1396
|
+
h('div', { className: 'dc-row' },
|
|
1397
|
+
h(Btn, { icon: 'qr', kind: 'primary', disabled: busy['bili-login'], onClick: biliLogin }, loginQr ? '重新出码' : '扫码登录'),
|
|
1398
|
+
qrStateText ? h('span', { className: 'dc-note', role: 'status' }, qrStateText) : null),
|
|
1399
|
+
loginQr ? h('div', { className: 'dc-qr-wrap', 'data-stale': loginStale ? '' : undefined },
|
|
1400
|
+
h('img', { className: 'dc-qr', src: loginQr, alt: 'B站 登录二维码' }),
|
|
1401
|
+
loginStale ? h('div', { className: 'dc-qr-mask' }, loginState === 'expired' ? '已过期' : '出错了') : null) : null)),
|
|
1402
|
+
h(Card, { title: '什么时候跑', sub: '内置谷时 + 自定义时间点可以并存' },
|
|
1403
|
+
(biliReady && !biliCfg.peakValley && customTimes.length === 0) ? h('div', { className: 'dc-banner' }, '自动跑已关闭:现在只能手动点「现在跑一轮」') : null,
|
|
1404
|
+
h(ToggleRow, { label: '峰谷时段自动刷', note: '工作日 12–14、18:00 之后(周末也算)', disabled: !biliReady, on: Boolean(biliCfg.peakValley), onChange: (v) => biliPatch({ peakValley: v }) }),
|
|
1405
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-times' }, '自定义时间点(HH:MM,逗号或换行;回车或点别处保存)'),
|
|
1406
|
+
h(DraftField, { id: 'dc-times', disabled: !biliReady, value: customTimes.join('、'), placeholder: '例:00:30、13:00', onCommit: (v) => biliPatch({ customTimes: String(v || '') }) }),
|
|
1407
|
+
h(ToggleRow, { label: '联网校时', note: '用服务器时间校准定时器', disabled: !biliReady, on: biliCfg.timeSync !== false, onChange: (v) => biliPatch({ timeSync: v }) }),
|
|
1408
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1409
|
+
h(Btn, { icon: 'play', kind: 'primary', disabled: !canRun, onClick: biliRun }, busy['bili-run'] ? '正在开跑…' : (dutyRunning ? '正在跑…' : '现在跑一轮')),
|
|
1410
|
+
h(Btn, { icon: 'copy', disabled: !bili || !bili.reportPath, onClick: () => copy(bili && bili.reportPath, '报告路径') }, '复制报告路径'))),
|
|
1411
|
+
h(Card, { title: '关注什么', sub: '关注 UP 主 / 自己写的分区,可以只开一边,也可以都开' },
|
|
1412
|
+
h(ToggleRow, { label: '关注 UP 主(专用号的关注列表)', note: '每轮从关注列表里随机挑;不想看他们就把这个关掉', disabled: !biliReady, on: biliCfg.focusFollowings !== false, onChange: (v) => biliPatch({ focusFollowings: v }) }),
|
|
1413
|
+
h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1414
|
+
h('label', { className: 'dc-label', style: { margin: 0 }, htmlFor: 'dc-focus-limit' }, '每轮最多看'),
|
|
1415
|
+
h(DraftField, { id: 'dc-focus-limit', 'data-narrow': '', style: { width: '88px' }, type: 'number', min: 1, max: 30, disabled: !biliReady,
|
|
1416
|
+
value: String(biliCfg.focusLimit ?? 12), normalize: (v) => Math.max(1, Math.min(30, Number(v) || 12)), onCommit: (v) => biliPatch({ focusLimit: v }) }),
|
|
1417
|
+
h('span', { className: 'dc-note' }, '个 UP 主')),
|
|
1418
|
+
h(ToggleRow, { label: '按我写的分区 / 题材', note: '和上面的 UP 主互不冲突;关掉就只看 UP 主或默认来源', disabled: !biliReady, on: Boolean(biliCfg.focusTopicsEnabled), onChange: (v) => biliPatch({ focusTopicsEnabled: v }) }),
|
|
1419
|
+
h('div', { className: 'dc-note', style: { marginTop: '4px' } }, '写下你平时想看的分区 / 题材 / 会搜的词;模型会按这些去搜。点别处保存。'),
|
|
1420
|
+
h(DraftField, {
|
|
1421
|
+
multiline: true, style: { minHeight: '86px' }, disabled: !biliReady, 'aria-label': '想看的分区 / 题材',
|
|
1422
|
+
value: String(biliCfg.focusTopics || ''),
|
|
1423
|
+
placeholder: '例:科技区、AI、原神、大学生活、纪录片;也可以写具体关键词',
|
|
1424
|
+
onCommit: (v) => biliPatch({ focusTopics: String(v || '') }),
|
|
1425
|
+
}),
|
|
1426
|
+
h(ToggleRow, { label: '带 QQ 记忆摘要', note: '让这一轮知道你们最近在聊什么', disabled: !biliReady, on: biliCfg.memoryExcerpt !== false, onChange: (v) => biliPatch({ memoryExcerpt: v }) }),
|
|
1427
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } }, '语气、称呼与性格只由「人格」页决定(' + (bili && bili.personaChars ? '读到 ' + bili.personaChars + ' 字' : '没读到') + ');这一页不再单独设置,也不再往提示词里加额外要求。'),
|
|
1428
|
+
h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1429
|
+
h('label', { className: 'dc-label', style: { margin: 0 }, htmlFor: 'dc-per-day' }, '每天最多挑'),
|
|
1430
|
+
h(DraftField, { id: 'dc-per-day', 'data-narrow': '', style: { width: '88px' }, type: 'number', min: 0, disabled: !biliReady,
|
|
1431
|
+
value: String(biliCfg.perDay ?? 5), normalize: (v) => Math.max(0, Number(v) || 0), onCommit: (v) => biliPatch({ perDay: v }) }),
|
|
1432
|
+
h('span', { className: 'dc-note' }, '条'))),
|
|
1433
|
+
h(Card, { title: '私信互通', sub: '你在 B站 私信里说话,它用「人格」页的语气回你' },
|
|
1434
|
+
h(ToggleRow, { label: '收到你的私信就回', note: '只回你本人(UID ' + (biliCfg.dmUid || biliCfg.dmOwnerUid || '没填') + ');查私信是纯代码、不花 token,只有真的回复才花', disabled: !biliReady, on: biliCfg.dmWatch === true, onChange: (v) => biliPatch({ dmWatch: v }) }),
|
|
1435
|
+
h(ToggleRow, { label: '读图', note: '用 DSH 当前的主模型读图(模型需要支持图片输入);只有新消息真正读图时才花 token', disabled: !biliReady, on: biliCfg.dmReadImages !== false, onChange: (v) => biliPatch({ dmReadImages: v }) }),
|
|
1436
|
+
h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1437
|
+
h('span', { className: 'dc-note' }, '每'),
|
|
1438
|
+
h(DraftField, { 'data-narrow': '', style: { width: '80px' }, type: 'number', min: 1, disabled: !biliReady, 'aria-label': '查私信间隔(分钟)',
|
|
1439
|
+
value: String(biliCfg.dmWatchMinutes ?? 1), normalize: (v) => Math.max(1, Number(v) || 1), onCommit: (v) => biliPatch({ dmWatchMinutes: v }) }),
|
|
1440
|
+
h('span', { className: 'dc-note' }, '分钟查一次')),
|
|
1441
|
+
h('div', { className: 'dc-note', style: { marginTop: '8px' } },
|
|
1442
|
+
'语气来自「人格」页(' + (bili && bili.personaChars ? bili.personaChars + ' 字' : '没读到') + ');读图走 DSH 主模型。',
|
|
1443
|
+
h('br'), '按上面的间隔查私信是纯 B站 HTTP,不花 token;只有新消息的回复和读图才花 token。开关即时生效。')),
|
|
1444
|
+
h(Card, { title: '更多(原插件设置)', sub: '评论 / 收藏 / 转写这些默认关' },
|
|
1445
|
+
h('div', { className: 'dc-row', style: { marginBottom: '4px' } },
|
|
1446
|
+
h('label', { className: 'dc-label', style: { margin: 0 }, htmlFor: 'dc-dm-mode' }, '投递'),
|
|
1447
|
+
h('select', { id: 'dc-dm-mode', className: 'dc-select', 'data-narrow': '', style: { width: '130px' }, disabled: !biliReady, value: biliCfg.dmMode || 'only', onChange: (e) => biliPatch({ dmMode: e.target.value }) },
|
|
1448
|
+
h('option', { value: 'only' }, '只私信'),
|
|
1449
|
+
h('option', { value: 'both' }, '评论 + 私信'),
|
|
1450
|
+
h('option', { value: 'off' }, '只写报告')),
|
|
1451
|
+
h('label', { className: 'dc-note', htmlFor: 'dc-dm-uid' }, '收件人'),
|
|
1452
|
+
h(DraftField, { id: 'dc-dm-uid', 'data-narrow': '', style: { width: '120px' }, type: 'number', disabled: !biliReady,
|
|
1453
|
+
value: String(biliCfg.dmUid || 0), normalize: (v) => Number(v) || 0, onCommit: (v) => biliPatch({ dmUid: v }) })),
|
|
1454
|
+
h(ToggleRow, { label: '自动公开评论', note: '默认关;开了会真的在视频下 @ 人', disabled: !biliReady, on: Boolean(biliCfg.autoComment), onChange: (v) => biliPatch({ autoComment: v }) }),
|
|
1455
|
+
biliCfg.autoComment ? h('div', { className: 'dc-row' },
|
|
1456
|
+
h(DraftField, { placeholder: '@ 谁(昵称)', 'aria-label': '@ 谁(昵称)', value: biliCfg.mentionName || '', onCommit: (v) => biliPatch({ mentionName: v }) }),
|
|
1457
|
+
h(DraftField, { 'data-narrow': '', style: { width: '90px' }, type: 'number', min: 1, 'aria-label': '每轮评论数',
|
|
1458
|
+
value: String(biliCfg.commentPerRound ?? 1), normalize: (v) => Math.max(1, Number(v) || 1), onCommit: (v) => biliPatch({ commentPerRound: v }) })) : null,
|
|
1459
|
+
h(ToggleRow, { label: '回复别人的评论', note: '默认关;只回直接回在你那条下面的人', disabled: !biliReady, on: Boolean(biliCfg.replyToComments), onChange: (v) => biliPatch({ replyToComments: v }) }),
|
|
1460
|
+
biliCfg.replyToComments ? h('div', { className: 'dc-row' },
|
|
1461
|
+
h('span', { className: 'dc-note' }, '每轮最多回'),
|
|
1462
|
+
h(DraftField, { 'data-narrow': '', style: { width: '80px' }, type: 'number', min: 1, 'aria-label': '每轮最多回复数',
|
|
1463
|
+
value: String(biliCfg.replyPerRound ?? 1), normalize: (v) => Math.max(1, Number(v) || 1), onCommit: (v) => biliPatch({ replyPerRound: v }) }),
|
|
1464
|
+
h('span', { className: 'dc-note' }, '条(你本人不受限)')) : null,
|
|
1465
|
+
h('div', { className: 'dc-row', style: { marginTop: '6px' } },
|
|
1466
|
+
h('label', { className: 'dc-label', style: { margin: 0 }, htmlFor: 'dc-report' }, '日报'),
|
|
1467
|
+
h('select', { id: 'dc-report', className: 'dc-select', 'data-narrow': '', style: { width: '130px' }, disabled: !biliReady, value: biliCfg.reportLevel || 'full', onChange: (e) => biliPatch({ reportLevel: e.target.value }) },
|
|
1468
|
+
h('option', { value: 'full' }, '完整'),
|
|
1469
|
+
h('option', { value: 'brief' }, '薄版'),
|
|
1470
|
+
h('option', { value: 'off' }, '不写')),
|
|
1471
|
+
h('label', { className: 'dc-label', style: { margin: 0, marginLeft: '10px' }, htmlFor: 'dc-fav' }, '收藏夹 ID'),
|
|
1472
|
+
h(DraftField, { id: 'dc-fav', 'data-narrow': '', style: { width: '110px' }, type: 'number', disabled: !biliReady,
|
|
1473
|
+
value: String(biliCfg.favFolderId || 0), normalize: (v) => Number(v) || 0, onCommit: (v) => biliPatch({ favFolderId: v }) })),
|
|
1474
|
+
h(ToggleRow, { label: '无字幕时本地转写', note: '要另装 Whisper 依赖;默认关', disabled: !biliReady, on: Boolean(biliCfg.transcribe), onChange: (v) => biliPatch({ transcribe: v }) }),
|
|
1475
|
+
biliCfg.transcribe ? h(Btn, { icon: 'save', disabled: busy.asr, onClick: () => runBusy('asr', () => post(BILI + '/install-asr', {}).then(() => say('开始装转写依赖,日志里看进度', 'ok')).catch((e) => say(errText(e), 'err'))) }, '装转写依赖') : null,
|
|
1476
|
+
)),
|
|
1477
|
+
h('div', { className: 'dc-list', style: { gap: '16px' } },
|
|
1478
|
+
h(VideoCard, { info: videoInfo, busy, onLogin: setVideoLogin, onInstallYtdlp: installYtdlp, onRefresh: loadVideo, biliLoggedIn: loggedIn }),
|
|
1479
|
+
h(Card, { title: '今天', sub: '日志与报告' },
|
|
1480
|
+
h('pre', { className: 'dc-pre' }, logLines.length ? logLines.join('\n') : (!bili ? (loading ? '读取中…' : 'B站 值班插件没响应') : '还没有日志')),
|
|
1481
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px', wordBreak: 'break-all' } }, (bili && bili.reportPath) || '报告还没生成'),
|
|
1482
|
+
h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1483
|
+
h(Btn, { icon: 'refresh', onClick: () => load() }, '刷新'))))) : null,
|
|
1484
|
+
|
|
1485
|
+
tab === 'meme' ? h('div', { className: 'dc-split' },
|
|
1486
|
+
h(Card, { title: '表情包(dsh-meme)', sub: meme ? '已装 v' + (meme.pluginVersion || '?') : (memeStatus === 'missing' ? '还没装上' : memeStatus === 'error' ? '读取失败' : '读取中…') },
|
|
1487
|
+
meme ? h('div', null,
|
|
1488
|
+
meme.promptEnabled === false ? h('div', { className: 'dc-banner' }, 'AI 斗图已关闭:模型不会主动发图,手动选图还在') : null,
|
|
1489
|
+
h(ToggleRow, {
|
|
1490
|
+
label: 'AI 主动斗图',
|
|
1491
|
+
note: '关掉后模型不再主动配图/发图;手动选择器还在',
|
|
1492
|
+
on: meme.promptEnabled !== false,
|
|
1493
|
+
onChange: (v) => memeOp('setPromptEnabled', { enabled: v }),
|
|
1494
|
+
disabled: Boolean(memeBusy),
|
|
1495
|
+
}),
|
|
1496
|
+
h('div', { className: 'dc-row', style: { margin: '8px 0' } },
|
|
1497
|
+
h(Badge, { tone: qqServiceOk ? 'ok' : 'warn' }, qqServiceOk ? 'QQ 发图通道已接' : 'QQ 发图通道未接'),
|
|
1498
|
+
h(Badge, null, '发送方式:' + (meme.sendMode || 'auto')),
|
|
1499
|
+
h(Badge, null, '图库:' + ((meme.packs || []).filter((p) => p.enabled).length) + ' / ' + ((meme.packs || []).length))),
|
|
1500
|
+
(meme.packs || []).length ? h('div', { className: 'dc-list' },
|
|
1501
|
+
(meme.packs || []).map((p) => h('div', { key: p.id, className: 'dc-item', 'data-off': p.enabled ? undefined : '' },
|
|
1502
|
+
h('div', { className: 'dc-item-main' },
|
|
1503
|
+
h('div', { className: 'dc-item-title' }, p.name || p.id),
|
|
1504
|
+
h('div', { className: 'dc-item-sub' }, (p.count || 0) + ' 张' + (p.enabled ? ' · 已启用' : ' · 已关闭'))),
|
|
1505
|
+
h('div', { className: 'dc-switch-ctl' },
|
|
1506
|
+
h('span', { className: 'dc-switch-state', 'data-on': p.enabled ? '' : undefined, 'aria-hidden': true }, p.enabled ? '开' : '关'),
|
|
1507
|
+
h(Switch, { on: Boolean(p.enabled), disabled: Boolean(memeBusy), label: '图库 ' + (p.name || p.id), onChange: (v) => memeOp('setPackEnabled', { packId: p.id, enabled: v }) })))))
|
|
1508
|
+
: h('div', { className: 'dc-empty' }, '还没有图库;在图库管理里上传或导入。'),
|
|
1509
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1510
|
+
h(Btn, { icon: 'open', onClick: () => window.open('/memes-panel', '_blank', 'noopener') }, '打开图库管理'),
|
|
1511
|
+
h(Btn, { icon: 'refresh', disabled: memeStatus === 'loading', onClick: loadMeme }, '刷新')),
|
|
1512
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px' } }, '完整图库管理(上传 / 学图 / 导入导出 / 市场)在 /memes-panel;这里只放开关。'))
|
|
1513
|
+
: memeStatus === 'missing' ? h('div', null,
|
|
1514
|
+
h('div', { className: 'dc-empty' }, 'dsh-meme 还没装;在插件页装上后这里会出现开关。'),
|
|
1515
|
+
h(Btn, { icon: 'open', onClick: () => window.open('/plugins', '_blank', 'noopener') }, '打开插件页'))
|
|
1516
|
+
: memeStatus === 'error' ? h('div', null,
|
|
1517
|
+
h('div', { className: 'dc-banner', 'data-tone': 'err' }, 'dsh-meme 没答上来;稍后点「刷新」再试。'),
|
|
1518
|
+
h(Btn, { icon: 'refresh', onClick: loadMeme }, '刷新'))
|
|
1519
|
+
: h('div', { className: 'dc-empty' }, '读取中…')),
|
|
1520
|
+
h(Card, { title: '怎么用', sub: '装好之后' },
|
|
1521
|
+
h('div', { className: 'dc-note', style: { lineHeight: '1.9' } },
|
|
1522
|
+
'· 输入框旁边会多一个表情入口,手动挑图;', h('br'),
|
|
1523
|
+
'· 聊天里模型会按气氛主动配图;', h('br'),
|
|
1524
|
+
'· 关掉上面的开关,模型就不再主动斗图,图库和手动入口都还在;', h('br'),
|
|
1525
|
+
'· QQ 发图需要 companionQq 通道(这里显示「已接」就说明服务在了);', h('br'),
|
|
1526
|
+
'· 如果表情包是刚刚热装的,重启一次 DSH 后 send_meme 才会切到 QQ 原生图片;', h('br'),
|
|
1527
|
+
'· 热重载后先在 QQ 里发一句话,机器人有「最近聊天目标」才能发图。'))) : null,
|
|
1528
|
+
|
|
1529
|
+
tab === 'voice' ? h('div', { className: 'dc-split' },
|
|
1530
|
+
h('div', { className: 'dc-list', style: { gap: '16px' } },
|
|
1531
|
+
h(Card, { title: '文字转语音', sub: !tts ? (ttsError ? '读取失败' : '读取中…') : (tts.provider === 'off' ? '已停用:QQ 只发文字' : (tts.enabled ? (tts.local ? '本地服务:' + ((ttsPresets.find((p) => p.id === tts.provider) || {}).name || tts.provider) : 'Key 已保存 ' + tts.keyHint) : (tts.needsKey ? (tts.hasKey ? '模型没填:QQ 只发文字' : '还没填 API Key') : '还没填服务地址'))) },
|
|
1532
|
+
ttsError && !tts ? h('div', { className: 'dc-banner', 'data-tone': 'err' }, '读不到语音设置:' + ttsError) : null,
|
|
1533
|
+
tts && !tts.enabled ? h('div', { className: 'dc-banner' }, '语音已关闭:QQ 回复只发文字' + (tts.provider === 'off' ? '(选的是「不启用」)' : tts.needsKey ? '(Key 或模型没填全)' : '(服务地址没填)')) : null,
|
|
1534
|
+
ttsForm ? h('div', null,
|
|
1535
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-provider' }, '服务预设'),
|
|
1536
|
+
h('select', { id: 'dc-tts-provider', className: 'dc-select', value: ttsForm.provider, onChange: (e) => { setTtsProbe(null); pickTtsProvider(e.target.value) } },
|
|
1537
|
+
h('optgroup', { label: '云端(要 API Key)' }, ttsPresets.filter((p) => p.group !== 'local').map((p) => h('option', { key: p.id, value: p.id }, p.name))),
|
|
1538
|
+
h('optgroup', { label: '本地 / 自建(不用 Key)' }, ttsPresets.filter((p) => p.group === 'local').map((p) => h('option', { key: p.id, value: p.id }, p.name)))),
|
|
1539
|
+
h('div', { className: 'dc-note', style: { marginTop: '6px' } }, (ttsPreset && ttsPreset.note) || ''),
|
|
1540
|
+
h('div', { className: 'dc-note', style: { marginTop: '4px' } }, '选「不启用」、模型或地址没填:QQ 回复只发文字;合成失败(没额度 / 鉴权 / 网络 / 本地服务没开)也会自动退回文字。'),
|
|
1541
|
+
!ttsLocal && !ttsOff ? h('div', null,
|
|
1542
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-key' }, 'API Key(只存本机,不回显)'),
|
|
1543
|
+
h('div', { className: 'dc-row' },
|
|
1544
|
+
h('input', { id: 'dc-tts-key', className: 'dc-input', type: 'password', value: ttsKey, placeholder: tts && tts.hasKey ? '已保存 ' + tts.keyHint + '(留空不改)' : 'sk-…', onChange: (e) => setTtsKey(e.target.value), autoComplete: 'off' }),
|
|
1545
|
+
h(Btn, { icon: 'save', disabled: busy.tts, onClick: () => saveTts({}) }, '保存'))) : null,
|
|
1546
|
+
ttsOff ? null : ttsForm.provider === 'qwen3-local' ? null : h('div', null,
|
|
1547
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-base' }, ttsForm.provider === 'custom-http' ? '接口完整地址' : (ttsLocal ? '服务地址(虚拟机 / 另一台电脑就填它的局域网 IP)' : 'Base URL')),
|
|
1548
|
+
h('div', { className: 'dc-row' },
|
|
1549
|
+
h('input', { id: 'dc-tts-base', className: 'dc-input', value: ttsForm.baseUrl || '', placeholder: (ttsPreset && ttsPreset.baseUrl) || 'http://127.0.0.1:8000/v1', onChange: (e) => { setTtsProbe(null); editTts('baseUrl', e.target.value) } }),
|
|
1550
|
+
ttsLocal ? h(Btn, { icon: 'link', disabled: busy['tts-test'], onClick: testTts }, busy['tts-test'] ? '连接中…' : '测试连接') : null)),
|
|
1551
|
+
ttsProbe ? h('div', { className: 'dc-banner', 'data-tone': ttsProbe.ok ? undefined : 'err', style: { marginTop: '8px', marginBottom: 0, ...(ttsProbe.ok ? { color: 'var(--cy-green)', borderColor: 'rgba(57,255,160,.4)', background: 'rgba(57,255,160,.07)' } : {}) }, role: 'status' },
|
|
1552
|
+
(ttsProbe.ok ? '能连上:' : '连不上:') + String(ttsProbe.detail || '') + (ttsProbe.voices && ttsProbe.voices.length ? ';服务端声音:' + ttsProbe.voices.slice(0, 12).join('、') : '')) : null,
|
|
1553
|
+
!ttsLocal && !ttsOff && String(ttsForm.provider || '').startsWith('dashscope') ? h('div', null,
|
|
1554
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-ws' }, 'Workspace ID(可选;报 workspace 相关错误再填)'),
|
|
1555
|
+
h('input', { id: 'dc-tts-ws', className: 'dc-input', value: ttsForm.workspace || '', placeholder: '百炼业务空间 ID,留空走默认', onChange: (e) => editTts('workspace', e.target.value) })) : null,
|
|
1556
|
+
ttsOff ? null : h('div', { className: 'dc-row', style: { gap: '10px', alignItems: 'flex-start' } },
|
|
1557
|
+
ttsForm.provider === 'qwen3-local' ? h('div', { style: { flex: '2 1 240px' } },
|
|
1558
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-qmodel' }, '模型'),
|
|
1559
|
+
h('select', { id: 'dc-tts-qmodel', className: 'dc-select', value: ttsForm.qwenModel || '', onChange: (e) => editTts('qwenModel', e.target.value) },
|
|
1560
|
+
(tts && Array.isArray(tts.qwen3Models) ? tts.qwen3Models : []).map((m) => h('option', { key: m.id, value: m.id }, m.name + ' · ' + m.size))))
|
|
1561
|
+
: ['gpt-sovits', 'cosyvoice', 'fish-speech', 'custom-http'].includes(ttsForm.provider) ? null : h('div', { style: { flex: '1 1 160px' } },
|
|
1562
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-model' }, '模型'),
|
|
1563
|
+
h('input', { id: 'dc-tts-model', className: 'dc-input', list: ttsForm.provider === 'qwen3-vllm' ? 'dc-qwen-models' : undefined, value: ttsForm.model || '', placeholder: ttsLocal ? '按服务的说明填(可留空)' : '留空 = 只发文字', onChange: (e) => editTts('model', e.target.value) })),
|
|
1564
|
+
ttsForm.provider === 'gpt-sovits' ? null : h('div', { style: { flex: '1 1 160px' } },
|
|
1565
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-voice' }, ttsForm.provider === 'cosyvoice' ? '声音(spk_id)' : ttsForm.provider === 'fish-speech' ? '参考音色 ID(可空)' : '声音 / 说话人'),
|
|
1566
|
+
String(ttsForm.voice || '').startsWith('clone:')
|
|
1567
|
+
? h('div', { className: 'dc-row' },
|
|
1568
|
+
h(Badge, { tone: 'ok' }, '角色声音:' + ((((voiceList && voiceList.voices) || []).find((v) => 'clone:' + v.id === ttsForm.voice) || {}).name || '(已删除)')),
|
|
1569
|
+
h(Btn, { icon: 'refresh', kind: 'ghost', onClick: () => editTts('voice', 'Vivian') }, '换回内置音色'))
|
|
1570
|
+
: h('input', { id: 'dc-tts-voice', className: 'dc-input', list: String(ttsForm.provider).startsWith('qwen3') ? 'dc-qwen-speakers' : undefined, value: ttsForm.voice || '', onChange: (e) => editTts('voice', e.target.value) }))),
|
|
1571
|
+
h('datalist', { id: 'dc-qwen-speakers' }, (tts && Array.isArray(tts.qwen3Speakers) ? tts.qwen3Speakers : []).map((x) => h('option', { key: x, value: x }))),
|
|
1572
|
+
h('datalist', { id: 'dc-qwen-models' }, (tts && Array.isArray(tts.qwen3Models) ? tts.qwen3Models : []).map((m) => h('option', { key: m.id, value: m.id }))),
|
|
1573
|
+
!ttsLocal && !ttsOff ? h('div', { className: 'dc-note', style: { marginTop: '4px' } }, '声音栏只对 Qwen-TTS / OpenAI 有效;Sambert 的模型名就是音色,留空即可。') : null,
|
|
1574
|
+
ENGLISH_SAMBERT.test(String(ttsForm.model || '').trim())
|
|
1575
|
+
? h('div', { className: 'dc-banner', style: { marginTop: '8px' } }, '「' + String(ttsForm.model).trim() + '」是英文音色,读中文几乎没声音(QQ 里会变成 1 秒的空语音)。中文请用 sambert-zhida-v1 这类中文音色;现在这种情况会自动改发文字。')
|
|
1576
|
+
: null,
|
|
1577
|
+
ttsOff ? null : h('div', null,
|
|
1578
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-lang' }, '语言'),
|
|
1579
|
+
h('select', { id: 'dc-tts-lang', className: 'dc-select', value: ttsForm.language || 'Auto', onChange: (e) => editTts('language', e.target.value) },
|
|
1580
|
+
['Auto', 'Chinese', 'English', 'Japanese', 'Korean', 'Cantonese', 'French', 'German', 'Spanish', 'Italian', 'Portuguese', 'Russian'].map((x) => h('option', { key: x, value: x }, x)))),
|
|
1581
|
+
['qwen3-local', 'qwen3-vllm', 'openai-local'].includes(ttsForm.provider) ? h('div', null,
|
|
1582
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-inst' }, '风格 / 音色描述(CustomVoice 当语气指令;VoiceDesign 必填,写想要的音色)'),
|
|
1583
|
+
h('textarea', { id: 'dc-tts-inst', className: 'dc-textarea', style: { minHeight: '60px' }, value: ttsForm.instructions || '', placeholder: '例:用温柔、带点笑意的语气说 / 二十岁左右的女生,声音清亮', onChange: (e) => editTts('instructions', e.target.value) })) : null,
|
|
1584
|
+
['qwen3-local', 'qwen3-vllm', 'gpt-sovits'].includes(ttsForm.provider) ? h('div', { className: 'dc-row', style: { gap: '10px', alignItems: 'flex-start' } },
|
|
1585
|
+
h('div', { style: { flex: '1 1 200px' } },
|
|
1586
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-ref' }, ttsForm.provider === 'gpt-sovits' ? '参考音频(服务端机器上的路径,必填)' : '参考音频(Base 克隆模型才要:路径或网址)'),
|
|
1587
|
+
h('input', { id: 'dc-tts-ref', className: 'dc-input', value: ttsForm.refAudio || '', placeholder: ttsForm.provider === 'gpt-sovits' ? '例:D:/voices/ref.wav' : '例:/home/me/ref.wav', onChange: (e) => editTts('refAudio', e.target.value) })),
|
|
1588
|
+
h('div', { style: { flex: '1 1 200px' } },
|
|
1589
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-reftext' }, '参考文本(参考音频里说的话)'),
|
|
1590
|
+
h('input', { id: 'dc-tts-reftext', className: 'dc-input', value: ttsForm.refText || '', onChange: (e) => editTts('refText', e.target.value) }))) : null,
|
|
1591
|
+
ttsForm.provider === 'custom-http' ? h('div', null,
|
|
1592
|
+
h('label', { className: 'dc-label', htmlFor: 'dc-tts-body' }, 'JSON 请求模板(占位:{{text}} {{voice}} {{lang}} {{language}} {{instructions}} {{ref_audio}} {{ref_text}})'),
|
|
1593
|
+
h('textarea', { id: 'dc-tts-body', className: 'dc-textarea', style: { minHeight: '90px', fontFamily: 'var(--cy-mono)' }, value: ttsForm.customBody || '', placeholder: '{"text": "{{text}}", "speaker": "{{voice}}", "lang": "{{lang}}"}', onChange: (e) => editTts('customBody', e.target.value) }),
|
|
1594
|
+
h('div', { className: 'dc-row', style: { marginTop: '6px' } },
|
|
1595
|
+
h('label', { className: 'dc-note', htmlFor: 'dc-tts-field' }, '回 JSON 时的音频字段'),
|
|
1596
|
+
h('input', { id: 'dc-tts-field', className: 'dc-input', 'data-narrow': '', style: { width: '160px' }, value: ttsForm.customAudioField || '', placeholder: 'audio 或 data.audio', onChange: (e) => editTts('customAudioField', e.target.value) }))) : null,
|
|
1597
|
+
['cosyvoice', 'custom-http'].includes(ttsForm.provider) ? h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1598
|
+
h('label', { className: 'dc-note', htmlFor: 'dc-tts-rate' }, ttsForm.provider === 'cosyvoice' ? '裸 PCM 采样率' : '服务回裸 PCM 时的采样率(回 wav/mp3 选「自动」)'),
|
|
1599
|
+
h('select', { id: 'dc-tts-rate', className: 'dc-select', 'data-narrow': '', style: { width: '120px' }, value: String(ttsForm.sampleRate || 0), onChange: (e) => editTts('sampleRate', Number(e.target.value)) },
|
|
1600
|
+
[[0, ttsForm.provider === 'cosyvoice' ? '22050(默认)' : '自动'], [16000, '16000'], [22050, '22050'], [24000, '24000'], [44100, '44100'], [48000, '48000']].map(([v, l]) => h('option', { key: v, value: String(v) }, l)))) : null,
|
|
1601
|
+
ttsLocal ? h('div', { className: 'dc-row', style: { marginTop: '8px' } },
|
|
1602
|
+
h('label', { className: 'dc-note', htmlFor: 'dc-tts-timeout' }, '超时(秒;CPU 跑大模型可以调长)'),
|
|
1603
|
+
h('input', { id: 'dc-tts-timeout', className: 'dc-input', 'data-narrow': '', style: { width: '90px' }, type: 'number', min: 10, max: 900, value: String(ttsForm.timeoutSec || 180), onChange: (e) => editTts('timeoutSec', e.target.value) }),
|
|
1604
|
+
ttsForm.provider !== 'cosyvoice' && ttsForm.provider !== 'fish-speech' ? h('label', { className: 'dc-note', htmlFor: 'dc-tts-speed' }, '语速') : null,
|
|
1605
|
+
ttsForm.provider !== 'cosyvoice' && ttsForm.provider !== 'fish-speech' ? h('input', { id: 'dc-tts-speed', className: 'dc-input', 'data-narrow': '', style: { width: '80px' }, type: 'number', step: '0.1', min: 0.5, max: 2, value: String(ttsForm.speed || 1), onChange: (e) => editTts('speed', e.target.value) }) : null) : null,
|
|
1606
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1607
|
+
h(Btn, { icon: 'save', kind: 'primary', disabled: busy.tts, onClick: () => saveTts({}) }, busy.tts ? '保存中…' : '保存设置'),
|
|
1608
|
+
h(Btn, { icon: 'refresh', onClick: () => { loadTts(); loadLocalTts() } }, '刷新')))
|
|
1609
|
+
: (ttsError ? null : h('div', { className: 'dc-empty' }, '读取语音设置中…'))),
|
|
1610
|
+
ttsForm && ttsForm.provider === 'qwen3-local' ? h(LocalQwenCard, { form: ttsForm, edit: editTts, local: localTts, busy, act: localAction, logOpen: localLogOpen, setLogOpen: setLocalLogOpen }) : null,
|
|
1611
|
+
ttsForm && (ttsForm.provider === 'qwen3-local' || ttsForm.provider === 'qwen3-vllm') ? h(VoiceCloneCard, { list: voiceList && voiceList.voices, current: voiceList && voiceList.current, busy, onCreate: createVoice, onUse: useVoice, onDelete: deleteVoice, provider: ttsForm.provider }) : null),
|
|
1612
|
+
h(Card, { title: '试听', sub: '先在网页里听,确认声音再往下接' },
|
|
1613
|
+
!ttsReady && tts ? h('div', { className: 'dc-banner' }, ttsLocal ? '试听和「发到 QQ」要先填好服务地址并「保存设置」;自带 Qwen3-TTS 要先在左边启动。' : '试听和「发到 QQ」要先选一个预设、填好 Key 和模型并保存。') : null,
|
|
1614
|
+
h('textarea', { className: 'dc-textarea', style: { minHeight: '120px' }, value: voiceText, 'aria-label': '要朗读的文字', placeholder: '写一段要读的文字(Qwen-TTS 最多 600 字;Sambert 最多 1 万字;本地模型最多 2000 字)', onChange: (e) => setVoiceText(e.target.value) }),
|
|
1615
|
+
h('div', { className: 'dc-note', style: { marginTop: '4px', textAlign: 'right' } }, String(voiceText.trim().length) + ' 字'),
|
|
1616
|
+
h('div', { className: 'dc-row', style: { marginTop: '6px' } },
|
|
1617
|
+
playing
|
|
1618
|
+
? h(Btn, { icon: 'check', kind: 'primary', onClick: stopSpeaking }, '停止')
|
|
1619
|
+
: h(Btn, { icon: 'play', kind: 'primary', disabled: Boolean(voiceBusy) || !ttsReady, onClick: speak }, voiceBusy === '1' ? '生成中…' : '试听'),
|
|
1620
|
+
h(Btn, { icon: 'link', disabled: Boolean(voiceBusy) || !ttsReady, onClick: speakToQq }, voiceBusy === 'qq' ? '发送中…' : '发到 QQ'),
|
|
1621
|
+
h(Btn, { icon: 'refresh', disabled: voiceText === '', onClick: () => setVoiceText('') }, '清空')),
|
|
1622
|
+
voiceNote ? h('div', { className: 'dc-note', style: { marginTop: '8px' }, role: 'status' }, voiceNote) : null,
|
|
1623
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px' } },
|
|
1624
|
+
'· 阿里云百炼有两个预设:Qwen-TTS(qwen3-tts-flash / Cherry)和 Sambert(如 sambert-zhida-v1,模型名就是音色);Key 在百炼控制台创建。', h('br'),
|
|
1625
|
+
'· Sambert 需要先在百炼控制台把模型「开启」;工作空间报错时再填 Workspace ID。', h('br'),
|
|
1626
|
+
'· 生成后返回音频地址,宿主下载再交给浏览器播放(地址 24 小时过期,不存进对话)。', h('br'),
|
|
1627
|
+
'· QQ 回复:语音可用就发语音;没填 / 没额度 / 鉴权失败时自动发文字。ASR 或乱填模型名会报配置错误。', h('br'),
|
|
1628
|
+
'· 「发到 QQ」按钮把上面这段文字合成后直接发一条语音,用来试通道。'))) : null,
|
|
1629
|
+
|
|
1630
|
+
tab === 'doctor' ? h('div', { className: 'dc-grid two' },
|
|
1631
|
+
h(Card, {
|
|
1632
|
+
title: '环境体检',
|
|
1633
|
+
sub: doctor ? (doctor.ok ? '核心依赖齐了' : '有缺的,按下面的提示补') : (busy['doctor-check'] ? '体检中…' : '点「重新体检」'),
|
|
1634
|
+
actions: h(Btn, { icon: 'refresh', disabled: busy['doctor-check'] || busy['doctor-install'] || busy['doctor-patch'], onClick: checkDoctor }, busy['doctor-check'] ? '体检中…' : '重新体检'),
|
|
1635
|
+
},
|
|
1636
|
+
doctor ? h('div', { className: 'dc-list' },
|
|
1637
|
+
(doctor.checks || []).map((c) => h('div', { key: c.id, className: 'dc-item' },
|
|
1638
|
+
h('span', { className: 'dc-state-dot', 'data-ok': c.ok ? '' : undefined, role: 'img', 'aria-label': c.ok ? '正常' : '有问题' }),
|
|
1639
|
+
h('div', { className: 'dc-item-main' },
|
|
1640
|
+
h('div', { className: 'dc-item-title' }, c.label),
|
|
1641
|
+
h('div', { className: 'dc-item-sub' }, c.detail + (c.hint ? ' · ' + c.hint : '')),
|
|
1642
|
+
c.command ? h('code', { className: 'dc-code' }, c.command) : null))))
|
|
1643
|
+
: h('div', { className: 'dc-empty' }, busy['doctor-check'] ? '体检中…' : '还没有体检结果'),
|
|
1644
|
+
!doctor ? null : h('div', { className: 'dc-row', style: { marginTop: '12px' } },
|
|
1645
|
+
h(Btn, { icon: 'save', kind: 'primary', disabled: busy['doctor-install'] || busy['doctor-check'] || busy['doctor-patch'], onClick: installDashscope }, busy['doctor-install'] ? '安装中(最多 3 分钟)…' : '安装 dashscope'),
|
|
1646
|
+
(doctor.checks || []).some((c) => c.id === 'yt-dlp' && !c.ok) ? h(Btn, { icon: 'save', disabled: busy.ytdlp, onClick: installYtdlp }, busy.ytdlp ? '安装 yt-dlp 中…' : '安装 yt-dlp') : null,
|
|
1647
|
+
h(Btn, { icon: 'link', disabled: busy['doctor-patch'] || busy['doctor-check'], onClick: patchQqbot }, busy['doctor-patch'] ? '打补丁中…' : '打 QQ 网关补丁'),
|
|
1648
|
+
h('span', { className: 'dc-note' }, '装进上面那个 Python;打补丁只改 QQ 网关,重启后生效。'))),
|
|
1649
|
+
h(Card, { title: '引擎 / 插件', sub: '缺什么就装什么;装完刷新页面' },
|
|
1650
|
+
h('div', { className: 'dc-list' },
|
|
1651
|
+
[
|
|
1652
|
+
{ id: 'agent', label: 'dsh-agent-md · 局部人格 / QQ 绑定', ok: Boolean(agent), detail: agent ? '已加载' : '没加载', command: 'dsh plugin --profile web add dsh-agent-md' },
|
|
1653
|
+
{ id: 'bili', label: 'dsh-bili-scroll · B站 值班', ok: Boolean(bili), detail: bili ? '已加载' : '没加载', command: 'dsh plugin --profile web add dsh-bili-scroll' },
|
|
1654
|
+
{ id: 'world', label: 'dsh-world · QQ 专属记忆', ok: Boolean(world), detail: world ? '已加载' : '没加载', command: 'dsh plugin --profile web add dsh-world' },
|
|
1655
|
+
{ id: 'meme', label: 'dsh-meme · 表情包', ok: Boolean(meme), detail: meme ? 'v' + (meme.pluginVersion || '?') : (memeStatus === 'idle' || memeStatus === 'loading' ? '打开「表情包」页后检测' : '没装/没加载'), command: 'dsh plugin --profile web add dsh-meme' },
|
|
1656
|
+
{ id: 'storyboard', label: 'dsh-video-storyboard · 视频分镜(QQ 分享的 B站 视频)', ok: Boolean(videoInfo && videoInfo.storyboard && videoInfo.storyboard.installed), detail: videoInfo && videoInfo.storyboard && videoInfo.storyboard.installed ? 'v' + videoInfo.storyboard.version : (videoInfo ? '没装' : '打开「B站」页后检测'), command: 'dsh plugin --profile web add github:SAOS-3624/dsh-video-storyboard' },
|
|
1657
|
+
{ id: 'qq', label: 'QQ 网关(companionQq)', ok: qqServiceOk, detail: mem && mem.qqService ? (mem.qqService.available ? '服务已提供' : '服务没提供') : '没检测到', command: 'dsh plugin --profile web add @tencent-connect/dsh-qqbot@latest' },
|
|
1658
|
+
{ id: 'qq-patch', label: 'QQ 网关补丁(companionQq / 语音)', ok: Boolean(mem && mem.qqbotPatch && mem.qqbotPatch.patched), detail: mem && mem.qqbotPatch ? (mem.qqbotPatch.patched ? '已打(' + (mem.qqbotPatch.version || '') + ')' : (mem.qqbotPatch.found ? (mem.qqbotPatch.error || '未打') : '没装 QQ 网关')) : '等待检测', command: '' },
|
|
1659
|
+
].map((c) => h('div', { key: c.id, className: 'dc-item' },
|
|
1660
|
+
h('span', { className: 'dc-state-dot', 'data-ok': c.ok ? '' : undefined, role: 'img', 'aria-label': c.ok ? '正常' : '有问题' }),
|
|
1661
|
+
h('div', { className: 'dc-item-main' },
|
|
1662
|
+
h('div', { className: 'dc-item-title' }, c.label),
|
|
1663
|
+
h('div', { className: 'dc-item-sub' }, c.detail),
|
|
1664
|
+
c.ok ? null : h('code', { className: 'dc-code' }, c.command))))),
|
|
1665
|
+
h('div', { className: 'dc-note', style: { marginTop: '10px' } }, '这个包只是薄薄一层界面/聚合层;引擎和表情包是独立插件,按上面命令装,不会把它们的图片/代码塞进这个包里。'))) : null,
|
|
1666
|
+
|
|
1667
|
+
tab === 'about' ? h('div', { className: 'dc-grid two' },
|
|
1668
|
+
h(Card, { title: 'dsh-chat-comprehension', sub: '把几套东西收成一个入口' },
|
|
1669
|
+
h('div', { className: 'dc-note', style: { lineHeight: '1.9' } },
|
|
1670
|
+
'局部人格来自 dsh-agent-md;B站 值班来自 dsh-bili-scroll;记忆来自 dsh-world;表情包来自 dsh-meme;视频分镜来自 dsh-video-storyboard(SAOS-3624);QQ 网关来自 @tencent-connect/dsh-qqbot;本地语音用通义 Qwen3-TTS(qwen-tts);QQ 语音编码用 silk-wasm。',
|
|
1671
|
+
h('br'), '本插件只做聚合与界面,各引擎的许可与版权归各自作者所有;本插件以 MIT 发布。'),
|
|
1672
|
+
h('div', { className: 'dc-row', style: { marginTop: '12px' } }, h(Badge, null, 'v0.2.0'), h(Badge, null, 'MIT'))),
|
|
1673
|
+
h(Card, { title: '发布方式', sub: '装一次就好' },
|
|
1674
|
+
h('div', { className: 'dc-note', style: { lineHeight: '1.9' } },
|
|
1675
|
+
'发布到 npm 后:', h('br'), h('code', null, 'dsh plugin --profile web add dsh-chat-comprehension'), h('br'),
|
|
1676
|
+
'这只装这一层界面;人格、B站、记忆、表情包、视频分镜、QQ 网关这些引擎是可选的独立插件,不会自动装上,缺哪个看「环境」页的命令。', h('br'),
|
|
1677
|
+
'装好之后第一次打开这个页面时按提示扫码登录 B站、扫码绑定 QQ 机器人。'))) : null),
|
|
1678
|
+
|
|
1679
|
+
h('div', { 'aria-live': 'polite', 'aria-atomic': 'true' },
|
|
1680
|
+
toast ? h('button', { type: 'button', className: 'dc-toast', 'data-tone': toast.tone || '', title: '点一下关掉', onClick: dismissToast }, toast.text) : null)))
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
function pickedTone(bili) {
|
|
1684
|
+
const picked = bili ? Number(bili.pickedToday || 0) : 0
|
|
1685
|
+
return picked > 0 ? 'ok' : 'neutral'
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
async function copyText(text) {
|
|
1689
|
+
const value = String(text || '')
|
|
1690
|
+
try {
|
|
1691
|
+
if (navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(value); return true }
|
|
1692
|
+
} catch { /* fall through */ }
|
|
1693
|
+
try {
|
|
1694
|
+
const el = document.createElement('textarea')
|
|
1695
|
+
el.value = value
|
|
1696
|
+
el.setAttribute('readonly', '')
|
|
1697
|
+
el.style.position = 'fixed'
|
|
1698
|
+
el.style.opacity = '0'
|
|
1699
|
+
document.body.appendChild(el)
|
|
1700
|
+
el.select()
|
|
1701
|
+
const ok = document.execCommand('copy')
|
|
1702
|
+
document.body.removeChild(el)
|
|
1703
|
+
return Boolean(ok)
|
|
1704
|
+
} catch {
|
|
1705
|
+
return false
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
function apply(ctx) {
|
|
1710
|
+
CTX = ctx
|
|
1711
|
+
const style = document.createElement('style')
|
|
1712
|
+
style.setAttribute('data-plugin-css', 'dsh-chat-comprehension')
|
|
1713
|
+
style.textContent = CSS
|
|
1714
|
+
document.head.appendChild(style)
|
|
1715
|
+
ctx.effect(() => () => style.remove(), 'dsh-chat-comprehension: styles')
|
|
1716
|
+
|
|
1717
|
+
const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
|
|
1718
|
+
if (!slots) return
|
|
1719
|
+
try {
|
|
1720
|
+
slots.inject('sidebar.panellist', () => slots.register({
|
|
1721
|
+
name: 'sidebar.panellist', id: 'companion', order: 6, label: '陪伴',
|
|
1722
|
+
}, (props) => h(CompanionIcon, props)))
|
|
1723
|
+
} catch (error) { /* 老宿主没有这个槽位 */ }
|
|
1724
|
+
try {
|
|
1725
|
+
slots.inject('main', () => slots.register({ name: 'main', key: 'companion' }, () => h(CompanionPage)))
|
|
1726
|
+
} catch (error) { /* 同上 */ }
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
return { name: 'dsh-chat-comprehension', inject: ['slots'], apply }
|
|
1730
|
+
},
|
|
1731
|
+
})
|