@biunow/agent-biutalk 1.1.6 → 1.1.8
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/_shared/.tmp-panel-smoke/art/smoke.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/art-pipe/out/biuart-01_cave-mwq5kfpm.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/art-pipe/panel-delivery.json +7 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/film/index.html +7 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/film/main.js +68 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/film/panel-beats.json +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/CREDITS +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/build.sh +17 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/ease.js +43 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/events.json +1 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/film.js +533 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-Archivo.txt +93 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-DMSerifDisplay.txt +93 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-UnifrakturMaguntia.txt +94 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/fonts.css +3 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/index.html +6 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/lines.json +10 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/main.js +15 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/mix.py +116 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/music/score.py +168 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/music/score_meta.json +59 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/score.json +235 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/stills/styleframe.jpg +0 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/fonts.sh +17 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/subs.py +11 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/words.py +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/dur.json +10 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/words.json +213 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/words_rel.json +56 -0
- package/_shared/.tmp-panel-smoke/reel-pipe/style-ref.json +5 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/film/index.html +7 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/film/main.js +68 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/film/panel-beats.json +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/out/video.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/panel-delivery.json +8 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/CREDITS +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/build.sh +17 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/ease.js +43 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/events.json +1 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/film.js +533 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-Archivo.txt +93 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-DMSerifDisplay.txt +93 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-UnifrakturMaguntia.txt +94 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/fonts.css +3 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/index.html +6 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/lines.json +10 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/main.js +15 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/mix.py +116 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/music/score.py +168 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/music/score_meta.json +59 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/score.json +235 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/stills/styleframe.jpg +0 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/fonts.sh +17 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/subs.py +11 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/words.py +20 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/dur.json +10 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/words.json +213 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/words_rel.json +56 -0
- package/_shared/.tmp-panel-smoke/reel-pipe2/style-ref.json +5 -0
- package/_shared/.tmp-panel-smoke/remo-pipe/brief.md +2 -0
- package/_shared/.tmp-panel-smoke/remo-pipe/remo-job.json +4 -0
- package/_shared/.tmp-panel-smoke/remo-pipe2/brief.md +1 -0
- package/_shared/.tmp-panel-smoke/remo-pipe2/out/final.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/remo-pipe2/panel-delivery.json +8 -0
- package/_shared/.tmp-panel-smoke/remo-pipe2/remo-job.json +4 -0
- package/_shared/.tmp-panel-smoke/vibe-pipe-ok/ep00-demo.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/vibe-pipe-ok/out/ep00-demo.mp4 +0 -0
- package/_shared/.tmp-panel-smoke/vibe-pipe-ok/panel-delivery.json +7 -0
- package/_shared/.tmp-panel-smoke/vibe-pipe-ok/publish.json +10 -0
- package/_shared/.tmp-panel-smoke/vibe-still.jpg +0 -0
- package/_shared/.tmp-panel-smoke/vibe-still.log +6 -0
- package/_shared/.tmp-panel-smoke/vibe-still.log.err +0 -0
- package/_shared/.tmp-panel-smoke/vibe-still2.log +26 -0
- package/_shared/.tmp-panel-smoke/vibe-still2.log.err +0 -0
- package/_shared/lib/film-locate.mjs +203 -0
- package/_shared/lib/voice-catalog.mjs +127 -0
- package/_shared/scripts/apply-upload-limits.mjs +62 -0
- package/_shared/scripts/patch-film-hosts.mjs +233 -0
- package/_shared/scripts/patch-voice-options.mjs +41 -0
- package/_shared/scripts/sync-local-agents.mjs +67 -0
- package/_shared/scripts/wire-film-bridge.mjs +24 -0
- package/_shared/scripts/wire-voice-plus.mjs +68 -0
- package/_shared/studio/assert-panel-permit.mjs +67 -0
- package/_shared/studio/composer.css +559 -0
- package/_shared/studio/composer.js +728 -0
- package/_shared/studio/optimize-prompt.mjs +84 -0
- package/_shared/studio/optimize-prompt.test.mjs +47 -0
- package/_shared/studio/recipes.mjs +87 -0
- package/_shared/studio/select-menu.js +450 -0
- package/_shared/studio/to-english-prompt.mjs +165 -0
- package/_shared/studio/to-english-prompt.test.mjs +72 -0
- package/bin/server.js +52 -36
- package/data/looks.json +8 -0
- package/lib/film-bridge.mjs +1 -0
- package/lib/host.mjs +149 -264
- package/lib/voice-bridge.mjs +2 -0
- package/manifest.json +4 -3
- package/package.json +1 -1
- package/skills/biutalk/EXEC.md +69 -0
- package/skills/biutalk/SKILL.md +12 -10
- package/skills/biutalk/scripts/doctor.mjs +124 -0
- package/skills/biutalk/scripts/qc.mjs +129 -0
- package/skills/biutalk/scripts/scaffold.mjs +205 -0
- package/studio/app.js +17 -1
- package/studio/composer.css +115 -1
- package/studio/composer.js +389 -10
- package/studio/index.html +5 -1
- package/studio/optimize-prompt.mjs +84 -0
- package/studio/optimize-prompt.test.mjs +47 -0
- package/studio/recipes.mjs +1 -0
- package/studio/to-english-prompt.mjs +165 -0
- package/studio/to-english-prompt.test.mjs +72 -0
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for CreateDesk-style agent studios.
|
|
3
|
+
*/
|
|
4
|
+
(function (global) {
|
|
5
|
+
function esc(s) {
|
|
6
|
+
return String(s || '')
|
|
7
|
+
.replace(/&/g, '&')
|
|
8
|
+
.replace(/</g, '<')
|
|
9
|
+
.replace(/>/g, '>')
|
|
10
|
+
.replace(/"/g, '"');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 本地 base64 JSON 上传:按类型分档(防呆,非云端配额)
|
|
14
|
+
const MB = 1024 * 1024;
|
|
15
|
+
const MAX_DOC_UPLOAD_BYTES = 50 * MB; // 图/文/PDF
|
|
16
|
+
const MAX_AUDIO_UPLOAD_BYTES = 100 * MB; // 音频
|
|
17
|
+
const MAX_VIDEO_UPLOAD_BYTES = 200 * MB; // 视频
|
|
18
|
+
const MAX_TOTAL_UPLOAD_BYTES = 250 * MB; // 单次任务合计
|
|
19
|
+
/** @deprecated 兼容旧引用:等同图文档上限 */
|
|
20
|
+
const MAX_UPLOAD_BYTES = MAX_DOC_UPLOAD_BYTES;
|
|
21
|
+
|
|
22
|
+
function uploadKind(file) {
|
|
23
|
+
const name = String(file?.name || '');
|
|
24
|
+
const type = String(file?.type || '');
|
|
25
|
+
if (type.startsWith('video/') || /\.(mp4|mov|webm|m4v)$/i.test(name)) return 'video';
|
|
26
|
+
if (type.startsWith('audio/') || /\.(mp3|wav|m4a|aac|flac|ogg)$/i.test(name)) return 'audio';
|
|
27
|
+
return 'doc';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function uploadCap(kind) {
|
|
31
|
+
if (kind === 'video') return { bytes: MAX_VIDEO_UPLOAD_BYTES, label: '200MB', title: '视频' };
|
|
32
|
+
if (kind === 'audio') return { bytes: MAX_AUDIO_UPLOAD_BYTES, label: '100MB', title: '音频' };
|
|
33
|
+
return { bytes: MAX_DOC_UPLOAD_BYTES, label: '50MB', title: '图文/PDF' };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function api(path, opts) {
|
|
37
|
+
const res = await fetch(path, opts);
|
|
38
|
+
const data = await res.json().catch(() => ({}));
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
const raw = data.error || res.statusText || '请求失败';
|
|
41
|
+
if (res.status === 413 || /body too large|附件过大/i.test(raw)) {
|
|
42
|
+
throw new Error('附件过大:图文/PDF≤50MB,音频≤100MB,视频≤200MB,合计≤250MB');
|
|
43
|
+
}
|
|
44
|
+
throw new Error(raw);
|
|
45
|
+
}
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function uploadBlockReason(file, usedBytes) {
|
|
50
|
+
const name = file?.name || '附件';
|
|
51
|
+
const size = Number(file?.size) || 0;
|
|
52
|
+
const kind = uploadKind(file);
|
|
53
|
+
const { bytes: cap, label, title } = uploadCap(kind);
|
|
54
|
+
if (size > cap) return `${name} 超过 ${label}(${title}),请压缩后再上传`;
|
|
55
|
+
if ((Number(usedBytes) || 0) + size > MAX_TOTAL_UPLOAD_BYTES) {
|
|
56
|
+
return `附件合计超过 250MB,${name} 未加入`;
|
|
57
|
+
}
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function fileToBase64(file) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const reader = new FileReader();
|
|
64
|
+
reader.onload = () => {
|
|
65
|
+
const result = String(reader.result || '');
|
|
66
|
+
const i = result.indexOf(',');
|
|
67
|
+
resolve(i >= 0 ? result.slice(i + 1) : result);
|
|
68
|
+
};
|
|
69
|
+
reader.onerror = reject;
|
|
70
|
+
reader.readAsDataURL(file);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function phaseLabel(j) {
|
|
75
|
+
if (j.outputMp4 || j.phase === 'film') return { text: '成片就绪', cls: 'ok' };
|
|
76
|
+
if (j.status === 'failed') return { text: '失败', cls: 'bad' };
|
|
77
|
+
if (j.phase === 'dsh' || (j.kickoffOk && j.status === 'running')) return { text: 'DSH 创作中', cls: 'run' };
|
|
78
|
+
if (j.phase === 'stalled') return { text: '待确认', cls: 'warn' };
|
|
79
|
+
if (j.status === 'running') return { text: '进行中', cls: 'run' };
|
|
80
|
+
if (j.status === 'done') return { text: '完成', cls: 'ok' };
|
|
81
|
+
return { text: j.status || '排队', cls: '' };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function bindPlusMenu(btn, menu) {
|
|
85
|
+
const close = () => {
|
|
86
|
+
menu.hidden = true;
|
|
87
|
+
btn.classList.remove('on');
|
|
88
|
+
};
|
|
89
|
+
btn.addEventListener('click', (e) => {
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
const open = menu.hidden;
|
|
92
|
+
menu.hidden = !open;
|
|
93
|
+
btn.classList.toggle('on', open);
|
|
94
|
+
});
|
|
95
|
+
document.addEventListener('click', () => close());
|
|
96
|
+
menu.addEventListener('click', (e) => e.stopPropagation());
|
|
97
|
+
return { close };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function bindCount(textarea, countEl, max) {
|
|
101
|
+
const sync = () => {
|
|
102
|
+
const n = textarea.value.length;
|
|
103
|
+
countEl.textContent = `${n}/${max}`;
|
|
104
|
+
};
|
|
105
|
+
textarea.addEventListener('input', sync);
|
|
106
|
+
sync();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let filmSelectedId = '';
|
|
110
|
+
let selectedJobId = '';
|
|
111
|
+
|
|
112
|
+
function filmSrc(id) {
|
|
113
|
+
return '/api/jobs/' + encodeURIComponent(id) + '/film';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let jobDetailTimer = null;
|
|
117
|
+
|
|
118
|
+
function ensureJobDetailModal() {
|
|
119
|
+
let back = document.querySelector('.job-detail-modal');
|
|
120
|
+
if (back) return back;
|
|
121
|
+
back = document.createElement('div');
|
|
122
|
+
back.className = 'job-detail-modal film-modal';
|
|
123
|
+
back.hidden = true;
|
|
124
|
+
back.innerHTML = `
|
|
125
|
+
<div class="film-modal-card job-detail-card" role="dialog" aria-modal="true">
|
|
126
|
+
<div class="film-modal-bar">
|
|
127
|
+
<strong class="jd-title">任务详情</strong>
|
|
128
|
+
<button type="button" class="film-modal-x jd-close" aria-label="关闭">×</button>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="job-detail-body">
|
|
131
|
+
<div class="jd-badge"></div>
|
|
132
|
+
<div class="jd-msg"></div>
|
|
133
|
+
<div class="bar jd-bar"><i></i></div>
|
|
134
|
+
<div class="jd-meta muted"></div>
|
|
135
|
+
<div class="jd-follow" hidden>
|
|
136
|
+
<p class="muted jd-follow-hint">成片二次修改在 DSH 执行;这里只发起对应对话。</p>
|
|
137
|
+
<div class="jd-follow-actions"></div>
|
|
138
|
+
</div>
|
|
139
|
+
<div class="jd-actions">
|
|
140
|
+
<button type="button" class="jd-refresh">刷新</button>
|
|
141
|
+
<button type="button" class="jd-dsh" hidden>在 DSH 打开对话</button>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</div>`;
|
|
145
|
+
document.body.appendChild(back);
|
|
146
|
+
const close = () => {
|
|
147
|
+
back.hidden = true;
|
|
148
|
+
if (jobDetailTimer) {
|
|
149
|
+
clearInterval(jobDetailTimer);
|
|
150
|
+
jobDetailTimer = null;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
back.querySelector('.jd-close').addEventListener('click', close);
|
|
154
|
+
back.addEventListener('click', (e) => { if (e.target === back) close(); });
|
|
155
|
+
document.addEventListener('keydown', (e) => {
|
|
156
|
+
if (e.key === 'Escape' && !back.hidden) close();
|
|
157
|
+
});
|
|
158
|
+
return back;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const FOLLOWUP_ACTIONS = [
|
|
162
|
+
{ id: 'narration', label: '改旁白', prompt: '请基于当前成片修改旁白文案,保持画幅与风格不变。' },
|
|
163
|
+
{ id: 'voice', label: '换音色', prompt: '请按 brief.json 里的 voice / ttsVoice 重新配音并重渲染成片。' },
|
|
164
|
+
{ id: 'subtitle', label: '加字幕', prompt: '请为当前成片补齐字幕并输出新成片。' },
|
|
165
|
+
{ id: 'rerender', label: '重渲染', prompt: '请在不改创意的前提下重新渲染成片,交付新的 MP4 路径。' },
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
function openDshSession(job, followPrompt) {
|
|
169
|
+
const sessionId = String(job.dshSessionId || '').trim();
|
|
170
|
+
if (!sessionId) {
|
|
171
|
+
window.alert('还没有 DSH 会话,请等创作接通后再试');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
window.parent.postMessage({
|
|
175
|
+
source: 'bn-studio',
|
|
176
|
+
type: 'open-session',
|
|
177
|
+
sessionId,
|
|
178
|
+
...(followPrompt ? { draft: followPrompt } : {}),
|
|
179
|
+
}, '*');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function fillJobDetail(back, job) {
|
|
183
|
+
if (!back || !job) return;
|
|
184
|
+
const phase = phaseLabel(job);
|
|
185
|
+
back.querySelector('.jd-title').textContent = job.title || job.kind || '任务详情';
|
|
186
|
+
const badge = back.querySelector('.jd-badge');
|
|
187
|
+
badge.className = 'jd-badge badge ' + (phase.cls || '');
|
|
188
|
+
badge.textContent = phase.text + (job.progress != null ? ` · ${Number(job.progress) || 0}%` : '');
|
|
189
|
+
back.querySelector('.jd-msg').textContent = job.message || '暂无进度说明';
|
|
190
|
+
back.querySelector('.jd-bar i').style.width = `${Number(job.progress) || 0}%`;
|
|
191
|
+
const bits = [
|
|
192
|
+
job.screen ? `画幅 ${job.screen}` : '',
|
|
193
|
+
job.styleName || job.styleId || '',
|
|
194
|
+
job.voice && (job.voice.voiceName || job.voice.voiceId)
|
|
195
|
+
? `音色 ${job.voice.voiceName || job.voice.voiceId}`
|
|
196
|
+
: '',
|
|
197
|
+
].filter(Boolean);
|
|
198
|
+
back.querySelector('.jd-meta').textContent = bits.join(' · ');
|
|
199
|
+
const dshBtn = back.querySelector('.jd-dsh');
|
|
200
|
+
const sessionId = String(job.dshSessionId || '').trim();
|
|
201
|
+
dshBtn.hidden = !sessionId;
|
|
202
|
+
dshBtn.onclick = () => openDshSession(job);
|
|
203
|
+
const follow = back.querySelector('.jd-follow');
|
|
204
|
+
const followBox = back.querySelector('.jd-follow-actions');
|
|
205
|
+
const done = Boolean(job.outputMp4) || job.status === 'done' || job.phase === 'ready';
|
|
206
|
+
follow.hidden = !done || !sessionId;
|
|
207
|
+
followBox.innerHTML = '';
|
|
208
|
+
if (!follow.hidden) {
|
|
209
|
+
FOLLOWUP_ACTIONS.forEach((act) => {
|
|
210
|
+
const btn = document.createElement('button');
|
|
211
|
+
btn.type = 'button';
|
|
212
|
+
btn.className = 'jd-follow-btn';
|
|
213
|
+
btn.textContent = act.label;
|
|
214
|
+
btn.onclick = () => openDshSession(job, act.prompt);
|
|
215
|
+
followBox.appendChild(btn);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function openJobDetailModal(job) {
|
|
221
|
+
const back = ensureJobDetailModal();
|
|
222
|
+
fillJobDetail(back, job);
|
|
223
|
+
back.hidden = false;
|
|
224
|
+
const refresh = back.querySelector('.jd-refresh');
|
|
225
|
+
refresh.onclick = () => {
|
|
226
|
+
void api('/api/jobs/' + encodeURIComponent(job.id))
|
|
227
|
+
.then((data) => fillJobDetail(back, data.job || job))
|
|
228
|
+
.catch(() => {});
|
|
229
|
+
};
|
|
230
|
+
if (jobDetailTimer) clearInterval(jobDetailTimer);
|
|
231
|
+
if (job.status === 'running' || job.phase === 'dsh' || job.phase === 'inpanel') {
|
|
232
|
+
jobDetailTimer = setInterval(() => refresh.click(), 4000);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function ensureFilmModal() {
|
|
237
|
+
let back = document.querySelector('.film-modal');
|
|
238
|
+
if (back) return back;
|
|
239
|
+
back = document.createElement('div');
|
|
240
|
+
back.className = 'film-modal';
|
|
241
|
+
back.hidden = true;
|
|
242
|
+
back.innerHTML = `
|
|
243
|
+
<div class="film-modal-card" role="dialog" aria-modal="true">
|
|
244
|
+
<div class="film-modal-bar">
|
|
245
|
+
<strong></strong>
|
|
246
|
+
<button type="button" class="film-modal-x" aria-label="关闭">×</button>
|
|
247
|
+
</div>
|
|
248
|
+
<video controls playsinline></video>
|
|
249
|
+
</div>`;
|
|
250
|
+
document.body.appendChild(back);
|
|
251
|
+
const close = () => {
|
|
252
|
+
const video = back.querySelector('video');
|
|
253
|
+
video.pause();
|
|
254
|
+
video.removeAttribute('src');
|
|
255
|
+
video.load();
|
|
256
|
+
back.hidden = true;
|
|
257
|
+
};
|
|
258
|
+
back.querySelector('.film-modal-x').addEventListener('click', close);
|
|
259
|
+
back.addEventListener('click', (e) => {
|
|
260
|
+
if (e.target === back) close();
|
|
261
|
+
});
|
|
262
|
+
document.addEventListener('keydown', (e) => {
|
|
263
|
+
if (e.key === 'Escape' && !back.hidden) close();
|
|
264
|
+
});
|
|
265
|
+
return back;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function openFilmModal(src, title, inlineVideo) {
|
|
269
|
+
const back = ensureFilmModal();
|
|
270
|
+
const video = back.querySelector('video');
|
|
271
|
+
back.querySelector('strong').textContent = title || '成片';
|
|
272
|
+
const startAt = inlineVideo && inlineVideo.dataset.src === src ? inlineVideo.currentTime || 0 : 0;
|
|
273
|
+
if (inlineVideo) inlineVideo.pause();
|
|
274
|
+
back.hidden = false;
|
|
275
|
+
let started = false;
|
|
276
|
+
const start = () => {
|
|
277
|
+
if (started) return;
|
|
278
|
+
started = true;
|
|
279
|
+
video.removeEventListener('loadedmetadata', start);
|
|
280
|
+
if (startAt > 0) {
|
|
281
|
+
try { video.currentTime = startAt; } catch { /* 还没解析出时长 */ }
|
|
282
|
+
}
|
|
283
|
+
video.play().catch(() => {});
|
|
284
|
+
};
|
|
285
|
+
const changed = video.dataset.src !== src;
|
|
286
|
+
video.addEventListener('loadedmetadata', start);
|
|
287
|
+
if (changed) {
|
|
288
|
+
video.dataset.src = src;
|
|
289
|
+
video.src = src;
|
|
290
|
+
} else if (video.readyState >= 1) {
|
|
291
|
+
start();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function ensureFilmStage(box) {
|
|
296
|
+
const parent = box.parentElement;
|
|
297
|
+
if (!parent) return null;
|
|
298
|
+
let stage = parent.querySelector(':scope > .film-stage');
|
|
299
|
+
if (stage) return stage;
|
|
300
|
+
stage = document.createElement('div');
|
|
301
|
+
stage.className = 'film-stage';
|
|
302
|
+
stage.hidden = true;
|
|
303
|
+
stage.innerHTML = `
|
|
304
|
+
<video class="film-video" controls playsinline preload="metadata"></video>
|
|
305
|
+
<div class="film-bar">
|
|
306
|
+
<span class="film-title"></span>
|
|
307
|
+
<button type="button" class="film-pop">弹窗播放</button>
|
|
308
|
+
</div>`;
|
|
309
|
+
parent.insertBefore(stage, box);
|
|
310
|
+
stage.querySelector('.film-pop').addEventListener('click', () => {
|
|
311
|
+
const video = stage.querySelector('video');
|
|
312
|
+
if (!video.dataset.src) return;
|
|
313
|
+
openFilmModal(video.dataset.src, stage.dataset.title || '', video);
|
|
314
|
+
});
|
|
315
|
+
return stage;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function showFilm(box, job, opts) {
|
|
319
|
+
const stage = ensureFilmStage(box);
|
|
320
|
+
if (!stage) return;
|
|
321
|
+
const video = stage.querySelector('video');
|
|
322
|
+
if (!job || !job.outputMp4) {
|
|
323
|
+
stage.hidden = true;
|
|
324
|
+
if (video && !video.paused) video.pause();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
stage.hidden = false;
|
|
328
|
+
const title = job.title || job.kind || '成片';
|
|
329
|
+
stage.dataset.title = title;
|
|
330
|
+
const label = stage.querySelector('.film-title');
|
|
331
|
+
if (label) label.textContent = title;
|
|
332
|
+
const src = filmSrc(job.id);
|
|
333
|
+
const same = video.dataset.src === src;
|
|
334
|
+
if (!same) {
|
|
335
|
+
video.dataset.src = src;
|
|
336
|
+
video.src = src;
|
|
337
|
+
}
|
|
338
|
+
if (!same || (opts && opts.autoplay)) video.play().catch(() => {});
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function renderJobs(box, jobs, opts) {
|
|
342
|
+
const onDelete = opts && typeof opts.onDelete === 'function' ? opts.onDelete : null;
|
|
343
|
+
const onPick = opts && typeof opts.onPick === 'function' ? opts.onPick : null;
|
|
344
|
+
const selected = jobs.find((j) => j.id === selectedJobId) || null;
|
|
345
|
+
if (!selected) selectedJobId = '';
|
|
346
|
+
filmSelectedId = selected && selected.outputMp4 ? selected.id : '';
|
|
347
|
+
showFilm(box, selected && selected.outputMp4 ? selected : null);
|
|
348
|
+
if (!jobs.length) {
|
|
349
|
+
box.innerHTML = '<p class="muted">还没有任务</p>';
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
box.innerHTML = '';
|
|
353
|
+
jobs.forEach((j) => {
|
|
354
|
+
const phase = phaseLabel(j);
|
|
355
|
+
const sessionId = String(j.dshSessionId || '').trim();
|
|
356
|
+
const playable = Boolean(j.outputMp4);
|
|
357
|
+
const meta = [j.styleName, j.screen].filter(Boolean).join(' · ');
|
|
358
|
+
const el = document.createElement('div');
|
|
359
|
+
el.className = 'job' + (phase.cls ? ' ' + phase.cls : '') + (playable ? ' playable' : '') + (j.id === selectedJobId ? ' on' : '');
|
|
360
|
+
el.title = '把这条需求填回创作框';
|
|
361
|
+
el.innerHTML = `
|
|
362
|
+
<div class="job-top">
|
|
363
|
+
<span class="badge ${phase.cls}">${esc(phase.text)}</span>
|
|
364
|
+
${meta ? `<span class="job-chip">${esc(meta)}</span>` : ''}
|
|
365
|
+
<span class="job-actions">
|
|
366
|
+
<button type="button" class="job-open" title="查看任务进度">任务详情</button>
|
|
367
|
+
<button type="button" class="job-del" title="从列表删除" aria-label="删除">×</button>
|
|
368
|
+
</span>
|
|
369
|
+
</div>
|
|
370
|
+
<div class="t">${esc(j.title || j.kind || '未命名')}</div>
|
|
371
|
+
<div class="m">${esc(j.message || '')}</div>
|
|
372
|
+
<div class="bar"><i style="width:${Number(j.progress) || 0}%"></i></div>`;
|
|
373
|
+
const openBtn = el.querySelector('.job-open');
|
|
374
|
+
if (openBtn) {
|
|
375
|
+
openBtn.addEventListener('click', (e) => {
|
|
376
|
+
e.preventDefault();
|
|
377
|
+
e.stopPropagation();
|
|
378
|
+
openJobDetailModal(j);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
el.addEventListener('click', () => {
|
|
382
|
+
selectedJobId = j.id;
|
|
383
|
+
filmSelectedId = playable ? j.id : '';
|
|
384
|
+
box.querySelectorAll('.job.on').forEach((node) => node.classList.remove('on'));
|
|
385
|
+
el.classList.add('on');
|
|
386
|
+
showFilm(box, playable ? j : null, { autoplay: playable });
|
|
387
|
+
if (onPick) onPick(j);
|
|
388
|
+
});
|
|
389
|
+
const delBtn = el.querySelector('.job-del');
|
|
390
|
+
if (delBtn) {
|
|
391
|
+
delBtn.addEventListener('click', (e) => {
|
|
392
|
+
e.preventDefault();
|
|
393
|
+
e.stopPropagation();
|
|
394
|
+
if (!j.id) return;
|
|
395
|
+
const clearFilm = () => {
|
|
396
|
+
if (selectedJobId === j.id) selectedJobId = '';
|
|
397
|
+
if (filmSelectedId !== j.id) return;
|
|
398
|
+
filmSelectedId = '';
|
|
399
|
+
showFilm(box, null);
|
|
400
|
+
};
|
|
401
|
+
if (onDelete) {
|
|
402
|
+
clearFilm();
|
|
403
|
+
onDelete(j);
|
|
404
|
+
} else {
|
|
405
|
+
void api('/api/jobs/' + encodeURIComponent(j.id), { method: 'DELETE' })
|
|
406
|
+
.then(() => {
|
|
407
|
+
clearFilm();
|
|
408
|
+
el.remove();
|
|
409
|
+
if (!box.querySelector('.job')) box.innerHTML = '<p class="muted">还没有任务</p>';
|
|
410
|
+
})
|
|
411
|
+
.catch((err) => {
|
|
412
|
+
window.alert(err.message || '删除失败');
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
box.appendChild(el);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function addChip(container, text, cls) {
|
|
422
|
+
const c = document.createElement('span');
|
|
423
|
+
c.className = 'chip' + (cls ? ' ' + cls : '');
|
|
424
|
+
c.textContent = text;
|
|
425
|
+
container.appendChild(c);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const RECIPE_LEVEL = { off: '无', optional: '可选', required: '必须' };
|
|
429
|
+
|
|
430
|
+
function paintRecipe(state, recipe, hint, keepText) {
|
|
431
|
+
currentRecipe = recipe || null;
|
|
432
|
+
const prompt = document.getElementById('prompt');
|
|
433
|
+
let bar = document.getElementById('needBar');
|
|
434
|
+
if (!bar && prompt) {
|
|
435
|
+
bar = document.createElement('div');
|
|
436
|
+
bar.id = 'needBar';
|
|
437
|
+
bar.className = 'link-bar';
|
|
438
|
+
prompt.parentNode.insertBefore(bar, prompt);
|
|
439
|
+
}
|
|
440
|
+
if (!bar) return;
|
|
441
|
+
bar.hidden = false;
|
|
442
|
+
let hintEl = document.getElementById('needHint');
|
|
443
|
+
if (!hintEl) {
|
|
444
|
+
hintEl = document.createElement('span');
|
|
445
|
+
hintEl.id = 'needHint';
|
|
446
|
+
hintEl.className = 'muted';
|
|
447
|
+
bar.appendChild(hintEl);
|
|
448
|
+
}
|
|
449
|
+
hintEl.textContent = hint || (recipe && recipe.hint) || '';
|
|
450
|
+
let flags = document.getElementById('needFlags');
|
|
451
|
+
if (!flags) {
|
|
452
|
+
flags = document.createElement('div');
|
|
453
|
+
flags.id = 'needFlags';
|
|
454
|
+
flags.className = 'need-flags';
|
|
455
|
+
bar.appendChild(flags);
|
|
456
|
+
}
|
|
457
|
+
const narr = (recipe && recipe.narration) || 'optional';
|
|
458
|
+
const att = (recipe && recipe.attachment) || 'optional';
|
|
459
|
+
const audio = recipe && recipe.audio;
|
|
460
|
+
flags.innerHTML =
|
|
461
|
+
`<span class="need-flag ${narr}">旁白 · ${RECIPE_LEVEL[narr] || narr}</span>` +
|
|
462
|
+
`<span class="need-flag ${att}">附件 · ${RECIPE_LEVEL[att] || att}</span>` +
|
|
463
|
+
(audio ? `<span class="need-flag ${audio}">音频驱动 · ${RECIPE_LEVEL[audio] || audio}</span>` : '');
|
|
464
|
+
const text = String((recipe && recipe.prompt) || '').trim();
|
|
465
|
+
if (prompt && text && !keepText) {
|
|
466
|
+
prompt.value = text;
|
|
467
|
+
prompt.dispatchEvent(new Event('input'));
|
|
468
|
+
state.seed = text;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function titleFromPrompt(prompt, fallback) {
|
|
473
|
+
const line = String(prompt || '')
|
|
474
|
+
.trim()
|
|
475
|
+
.split(/\n/)[0]
|
|
476
|
+
.replace(/^#+\s*/, '')
|
|
477
|
+
.trim();
|
|
478
|
+
return (line || fallback || '未命名成片').slice(0, 120);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function openVoicePicker(state, onPicked) {
|
|
482
|
+
const data = await api('/api/voice-options').catch(() => null);
|
|
483
|
+
const channels = (data && data.channels) || [];
|
|
484
|
+
if (!channels.length) throw new Error('语音目录不可用,请先在面板设置里配置语音');
|
|
485
|
+
if (!global.SelectMenu || typeof global.SelectMenu.mount !== 'function') {
|
|
486
|
+
throw new Error('下拉组件未加载');
|
|
487
|
+
}
|
|
488
|
+
const back = document.createElement('div');
|
|
489
|
+
back.className = 'film-modal voice-picker-modal';
|
|
490
|
+
back.innerHTML = `
|
|
491
|
+
<div class="film-modal-card job-detail-card" role="dialog" aria-modal="true">
|
|
492
|
+
<div class="film-modal-bar">
|
|
493
|
+
<strong>选择语音</strong>
|
|
494
|
+
<button type="button" class="film-modal-x" aria-label="关闭">×</button>
|
|
495
|
+
</div>
|
|
496
|
+
<div class="job-detail-body">
|
|
497
|
+
<label class="vp-field"><span>通道</span><div class="vp-channel"></div></label>
|
|
498
|
+
<label class="vp-field"><span>音色</span><div class="vp-voice"></div></label>
|
|
499
|
+
<p class="muted vp-hint"></p>
|
|
500
|
+
<div class="jd-actions">
|
|
501
|
+
<button type="button" class="jd-refresh vp-clear">清除选择</button>
|
|
502
|
+
<button type="button" class="primary vp-ok">确定</button>
|
|
503
|
+
</div>
|
|
504
|
+
</div>
|
|
505
|
+
</div>`;
|
|
506
|
+
document.body.appendChild(back);
|
|
507
|
+
const hint = back.querySelector('.vp-hint');
|
|
508
|
+
const current = state.voice || {};
|
|
509
|
+
let channelId = current.channel || (channels.find((c) => c.enabled) || channels[0] || {}).id || '';
|
|
510
|
+
let voiceId = current.voiceId || '';
|
|
511
|
+
const channelHost = back.querySelector('.vp-channel');
|
|
512
|
+
const voiceHost = back.querySelector('.vp-voice');
|
|
513
|
+
const channelMenu = global.SelectMenu.mount(channelHost, {
|
|
514
|
+
size: 'md',
|
|
515
|
+
value: channelId,
|
|
516
|
+
options: channels.map((ch) => ({
|
|
517
|
+
value: ch.id,
|
|
518
|
+
label: ch.label + (ch.enabled ? '' : '(未配置)'),
|
|
519
|
+
})),
|
|
520
|
+
onChange: (v) => {
|
|
521
|
+
channelId = v;
|
|
522
|
+
fillVoices(true);
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
let voiceMenu = null;
|
|
526
|
+
const fillVoices = (reset) => {
|
|
527
|
+
const ch = channels.find((c) => c.id === channelId);
|
|
528
|
+
hint.textContent = (ch && ch.hint) || '';
|
|
529
|
+
const opts = (ch && ch.voices ? ch.voices : []).map((v) => ({
|
|
530
|
+
value: v.id,
|
|
531
|
+
label: v.label || v.name || v.id,
|
|
532
|
+
}));
|
|
533
|
+
if (reset || !opts.some((o) => o.value === voiceId)) {
|
|
534
|
+
voiceId = (opts.some((o) => o.value === current.voiceId) && !reset)
|
|
535
|
+
? current.voiceId
|
|
536
|
+
: (ch && ch.defaultVoiceId && opts.some((o) => o.value === ch.defaultVoiceId)
|
|
537
|
+
? ch.defaultVoiceId
|
|
538
|
+
: (opts[0] && opts[0].value) || '');
|
|
539
|
+
}
|
|
540
|
+
voiceHost.innerHTML = '';
|
|
541
|
+
voiceMenu = global.SelectMenu.mount(voiceHost, {
|
|
542
|
+
size: 'md',
|
|
543
|
+
value: voiceId,
|
|
544
|
+
options: opts.length ? opts : [{ value: '', label: '暂无音色' }],
|
|
545
|
+
onChange: (v) => { voiceId = v; },
|
|
546
|
+
});
|
|
547
|
+
channelMenu.setValue(channelId, true);
|
|
548
|
+
};
|
|
549
|
+
fillVoices(false);
|
|
550
|
+
const close = () => back.remove();
|
|
551
|
+
back.querySelector('.film-modal-x').onclick = close;
|
|
552
|
+
back.addEventListener('click', (e) => { if (e.target === back) close(); });
|
|
553
|
+
back.querySelector('.vp-clear').onclick = () => {
|
|
554
|
+
state.voice = null;
|
|
555
|
+
if (onPicked) onPicked(null);
|
|
556
|
+
close();
|
|
557
|
+
};
|
|
558
|
+
back.querySelector('.vp-ok').onclick = () => {
|
|
559
|
+
const ch = channels.find((c) => c.id === channelId);
|
|
560
|
+
const v = (ch && ch.voices || []).find((x) => x.id === voiceId);
|
|
561
|
+
if (!v) {
|
|
562
|
+
window.alert('请选择可用音色');
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
state.voice = {
|
|
566
|
+
channel: ch.id,
|
|
567
|
+
voiceId: v.id,
|
|
568
|
+
voiceName: v.name || v.label || v.id,
|
|
569
|
+
rate: ch.rate || 0,
|
|
570
|
+
provider: ch.provider || '',
|
|
571
|
+
engine: ch.engine || '',
|
|
572
|
+
};
|
|
573
|
+
if (onPicked) onPicked(state.voice);
|
|
574
|
+
close();
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
global.Composer = {
|
|
579
|
+
esc,
|
|
580
|
+
api,
|
|
581
|
+
fileToBase64,
|
|
582
|
+
uploadBlockReason,
|
|
583
|
+
MAX_UPLOAD_BYTES,
|
|
584
|
+
MAX_DOC_UPLOAD_BYTES,
|
|
585
|
+
MAX_AUDIO_UPLOAD_BYTES,
|
|
586
|
+
MAX_VIDEO_UPLOAD_BYTES,
|
|
587
|
+
MAX_TOTAL_UPLOAD_BYTES,
|
|
588
|
+
uploadKind,
|
|
589
|
+
uploadCap,
|
|
590
|
+
phaseLabel,
|
|
591
|
+
bindPlusMenu,
|
|
592
|
+
bindCount,
|
|
593
|
+
renderJobs,
|
|
594
|
+
addChip,
|
|
595
|
+
titleFromPrompt,
|
|
596
|
+
paintRecipe,
|
|
597
|
+
claimCasePrompt,
|
|
598
|
+
openJobDetailModal,
|
|
599
|
+
openVoicePicker,
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
let casePromptText = '';
|
|
603
|
+
let studioReadyForCase = false;
|
|
604
|
+
|
|
605
|
+
function writeCasePrompt() {
|
|
606
|
+
const prompt = document.getElementById('prompt');
|
|
607
|
+
const text = String(casePromptText || '').trim();
|
|
608
|
+
if (!studioReadyForCase || !prompt || !text || prompt.value === text) return;
|
|
609
|
+
prompt.value = text;
|
|
610
|
+
prompt.dispatchEvent(new Event('input'));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
window.addEventListener('message', (event) => {
|
|
614
|
+
if (event.source !== window.parent) return;
|
|
615
|
+
const data = event.data || {};
|
|
616
|
+
if (data.type !== 'bn-case-prompt') return;
|
|
617
|
+
casePromptText = String(data.prompt || '');
|
|
618
|
+
writeCasePrompt();
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
function claimCasePrompt() {
|
|
622
|
+
studioReadyForCase = true;
|
|
623
|
+
writeCasePrompt();
|
|
624
|
+
}
|
|
625
|
+
let currentRecipe = null;
|
|
626
|
+
|
|
627
|
+
let optimizeMember = false;
|
|
628
|
+
let optimizeTipTimer = 0;
|
|
629
|
+
|
|
630
|
+
function showOptimizeTip(message) {
|
|
631
|
+
const tip = document.getElementById('optimizeTip');
|
|
632
|
+
if (!tip) return;
|
|
633
|
+
tip.hidden = false;
|
|
634
|
+
tip.textContent = message;
|
|
635
|
+
window.clearTimeout(optimizeTipTimer);
|
|
636
|
+
optimizeTipTimer = window.setTimeout(() => {
|
|
637
|
+
tip.hidden = true;
|
|
638
|
+
}, 2600);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async function onOptimizePrompt() {
|
|
642
|
+
const btn = document.getElementById('optimizeBtn');
|
|
643
|
+
const prompt = document.getElementById('prompt');
|
|
644
|
+
if (!btn || !prompt) return;
|
|
645
|
+
if (!optimizeMember) {
|
|
646
|
+
showOptimizeTip('会员专属,请先开通会员');
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
if (btn.dataset.busy === '1') return;
|
|
650
|
+
btn.dataset.busy = '1';
|
|
651
|
+
const previous = btn.textContent;
|
|
652
|
+
btn.textContent = '优化中';
|
|
653
|
+
try {
|
|
654
|
+
const recipe = currentRecipe || {};
|
|
655
|
+
const data = await api('/api/optimize-prompt', {
|
|
656
|
+
method: 'POST',
|
|
657
|
+
headers: { 'content-type': 'application/json' },
|
|
658
|
+
body: JSON.stringify({
|
|
659
|
+
text: prompt.value,
|
|
660
|
+
templatePrompt: recipe.prompt || '',
|
|
661
|
+
narration: recipe.narration || '',
|
|
662
|
+
attachment: recipe.attachment || '',
|
|
663
|
+
}),
|
|
664
|
+
});
|
|
665
|
+
const next = String((data && data.prompt) || '').trim();
|
|
666
|
+
if (!next) throw new Error('没有得到可用的提示词');
|
|
667
|
+
prompt.value = next;
|
|
668
|
+
prompt.dispatchEvent(new Event('input'));
|
|
669
|
+
if (data && data.kept) showOptimizeTip('没选模板,按你写的原文出片');
|
|
670
|
+
} catch (error) {
|
|
671
|
+
const message = (error && error.message) || '无法优化提示词';
|
|
672
|
+
if (message.indexOf('会员专属') >= 0) {
|
|
673
|
+
optimizeMember = false;
|
|
674
|
+
btn.classList.add('is-locked');
|
|
675
|
+
btn.setAttribute('aria-disabled', 'true');
|
|
676
|
+
showOptimizeTip('会员专属,请先开通会员');
|
|
677
|
+
} else {
|
|
678
|
+
const err = document.getElementById('err');
|
|
679
|
+
if (err) {
|
|
680
|
+
err.hidden = false;
|
|
681
|
+
err.textContent = message;
|
|
682
|
+
} else {
|
|
683
|
+
showOptimizeTip(message);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
} finally {
|
|
687
|
+
btn.dataset.busy = '';
|
|
688
|
+
btn.textContent = previous || '优化提示词';
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function mountOptimize() {
|
|
693
|
+
const prompt = document.getElementById('prompt');
|
|
694
|
+
if (!prompt || document.getElementById('optimizeBtn')) return;
|
|
695
|
+
const stage = document.createElement('div');
|
|
696
|
+
stage.className = 'prompt-stage';
|
|
697
|
+
prompt.parentNode.insertBefore(stage, prompt);
|
|
698
|
+
stage.appendChild(prompt);
|
|
699
|
+
const btn = document.createElement('button');
|
|
700
|
+
btn.type = 'button';
|
|
701
|
+
btn.id = 'optimizeBtn';
|
|
702
|
+
btn.className = 'optimize is-locked';
|
|
703
|
+
btn.setAttribute('aria-disabled', 'true');
|
|
704
|
+
btn.textContent = '优化提示词';
|
|
705
|
+
const tip = document.createElement('div');
|
|
706
|
+
tip.id = 'optimizeTip';
|
|
707
|
+
tip.className = 'optimize-tip';
|
|
708
|
+
tip.hidden = true;
|
|
709
|
+
stage.appendChild(btn);
|
|
710
|
+
stage.appendChild(tip);
|
|
711
|
+
btn.addEventListener('click', () => {
|
|
712
|
+
void onOptimizePrompt();
|
|
713
|
+
});
|
|
714
|
+
fetch('/api/health')
|
|
715
|
+
.then((res) => res.json())
|
|
716
|
+
.then((data) => {
|
|
717
|
+
optimizeMember = !!(data && data.member === true);
|
|
718
|
+
btn.classList.toggle('is-locked', !optimizeMember);
|
|
719
|
+
btn.setAttribute('aria-disabled', optimizeMember ? 'false' : 'true');
|
|
720
|
+
})
|
|
721
|
+
.catch(() => {
|
|
722
|
+
optimizeMember = false;
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
mountOptimize();
|
|
727
|
+
|
|
728
|
+
})(window);
|