@biunow/agent-biutalk 2.0.1 → 2.0.2

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.
@@ -106,6 +106,97 @@
106
106
  sync();
107
107
  }
108
108
 
109
+ /** 附件的角色标签:所有 Studio 共用一套名字,避免五个面板各叫各的。 */
110
+ const ROLE_LABEL = {
111
+ ref: '参考',
112
+ media: '素材',
113
+ character: '人物',
114
+ voice: '口播',
115
+ music: '配乐',
116
+ doc: '文档',
117
+ script: '文稿',
118
+ lyrics: '歌词',
119
+ subtitle: '字幕',
120
+ };
121
+
122
+ function roleLabel(role) {
123
+ return ROLE_LABEL[role] || '';
124
+ }
125
+
126
+ let openRoleMenu = null;
127
+
128
+ /** + 菜单里的二级“附件角色”菜单(参考素材 / 口播录音 / 配乐 / 文稿 …)。 */
129
+ function bindRoleMenu(anchor, items, onPick) {
130
+ if (openRoleMenu) {
131
+ openRoleMenu.close();
132
+ openRoleMenu = null;
133
+ }
134
+ if (!items || !items.length) return null;
135
+ const menu = document.createElement('div');
136
+ menu.className = 'plus-menu role-menu';
137
+ items.forEach((item) => {
138
+ const btn = document.createElement('button');
139
+ btn.type = 'button';
140
+ btn.innerHTML =
141
+ `<span class="plus-ico">${esc(item.icon || '·')}</span>` +
142
+ `<span><strong>${esc(item.label)}</strong><small>${esc(item.hint || '')}</small></span>`;
143
+ btn.addEventListener('click', (e) => {
144
+ e.preventDefault();
145
+ e.stopPropagation();
146
+ close();
147
+ onPick(item);
148
+ });
149
+ menu.appendChild(btn);
150
+ });
151
+ document.body.appendChild(menu);
152
+ const rect = anchor.getBoundingClientRect();
153
+ const width = 260;
154
+ const left = Math.min(rect.right + 8, Math.max(8, window.innerWidth - width - 8));
155
+ const top = Math.min(Math.max(8, rect.top - 6), Math.max(8, window.innerHeight - menu.offsetHeight - 8));
156
+ menu.style.position = 'fixed';
157
+ menu.style.left = `${left}px`;
158
+ menu.style.top = `${top}px`;
159
+ menu.style.width = `${width}px`;
160
+ const close = () => {
161
+ menu.remove();
162
+ document.removeEventListener('click', onDocClick);
163
+ document.removeEventListener('keydown', onKey);
164
+ openRoleMenu = null;
165
+ };
166
+ const onDocClick = () => close();
167
+ const onKey = (e) => {
168
+ if (e.key === 'Escape') close();
169
+ };
170
+ setTimeout(() => {
171
+ document.addEventListener('click', onDocClick);
172
+ document.addEventListener('keydown', onKey);
173
+ }, 0);
174
+ openRoleMenu = { close };
175
+ return openRoleMenu;
176
+ }
177
+
178
+ /** 按角色取文件:设置 accept → 弹选择框 → 回传 { role, files }。 */
179
+ function pickFilesByRole(input, role, accept, onPicked) {
180
+ if (!input) return;
181
+ if (input.__roleHandler) {
182
+ input.removeEventListener('change', input.__roleHandler);
183
+ input.__roleHandler = null;
184
+ }
185
+ if (accept) input.setAttribute('accept', accept);
186
+ else input.removeAttribute('accept');
187
+ input.dataset.role = role;
188
+ const handler = () => {
189
+ input.removeEventListener('change', handler);
190
+ input.__roleHandler = null;
191
+ const files = Array.from(input.files || []);
192
+ input.value = '';
193
+ if (files.length) onPicked(role, files);
194
+ };
195
+ input.__roleHandler = handler;
196
+ input.addEventListener('change', handler);
197
+ input.click();
198
+ }
199
+
109
200
  let filmSelectedId = '';
110
201
  let selectedJobId = '';
111
202
 
@@ -590,6 +681,10 @@
590
681
  phaseLabel,
591
682
  bindPlusMenu,
592
683
  bindCount,
684
+ bindRoleMenu,
685
+ pickFilesByRole,
686
+ roleLabel,
687
+ ROLE_LABEL,
593
688
  renderJobs,
594
689
  addChip,
595
690
  titleFromPrompt,
@@ -622,107 +717,107 @@
622
717
  studioReadyForCase = true;
623
718
  writeCasePrompt();
624
719
  }
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
-
720
+ let currentRecipe = null;
721
+
722
+ let optimizeMember = false;
723
+ let optimizeTipTimer = 0;
724
+
725
+ function showOptimizeTip(message) {
726
+ const tip = document.getElementById('optimizeTip');
727
+ if (!tip) return;
728
+ tip.hidden = false;
729
+ tip.textContent = message;
730
+ window.clearTimeout(optimizeTipTimer);
731
+ optimizeTipTimer = window.setTimeout(() => {
732
+ tip.hidden = true;
733
+ }, 2600);
734
+ }
735
+
736
+ async function onOptimizePrompt() {
737
+ const btn = document.getElementById('optimizeBtn');
738
+ const prompt = document.getElementById('prompt');
739
+ if (!btn || !prompt) return;
740
+ if (!optimizeMember) {
741
+ showOptimizeTip('会员专属,请先开通会员');
742
+ return;
743
+ }
744
+ if (btn.dataset.busy === '1') return;
745
+ btn.dataset.busy = '1';
746
+ const previous = btn.textContent;
747
+ btn.textContent = '优化中';
748
+ try {
749
+ const recipe = currentRecipe || {};
750
+ const data = await api('/api/optimize-prompt', {
751
+ method: 'POST',
752
+ headers: { 'content-type': 'application/json' },
753
+ body: JSON.stringify({
754
+ text: prompt.value,
755
+ templatePrompt: recipe.prompt || '',
756
+ narration: recipe.narration || '',
757
+ attachment: recipe.attachment || '',
758
+ }),
759
+ });
760
+ const next = String((data && data.prompt) || '').trim();
761
+ if (!next) throw new Error('没有得到可用的提示词');
762
+ prompt.value = next;
763
+ prompt.dispatchEvent(new Event('input'));
764
+ if (data && data.kept) showOptimizeTip('没选模板,按你写的原文出片');
765
+ } catch (error) {
766
+ const message = (error && error.message) || '无法优化提示词';
767
+ if (message.indexOf('会员专属') >= 0) {
768
+ optimizeMember = false;
769
+ btn.classList.add('is-locked');
770
+ btn.setAttribute('aria-disabled', 'true');
771
+ showOptimizeTip('会员专属,请先开通会员');
772
+ } else {
773
+ const err = document.getElementById('err');
774
+ if (err) {
775
+ err.hidden = false;
776
+ err.textContent = message;
777
+ } else {
778
+ showOptimizeTip(message);
779
+ }
780
+ }
781
+ } finally {
782
+ btn.dataset.busy = '';
783
+ btn.textContent = previous || '优化提示词';
784
+ }
785
+ }
786
+
787
+ function mountOptimize() {
788
+ const prompt = document.getElementById('prompt');
789
+ if (!prompt || document.getElementById('optimizeBtn')) return;
790
+ const stage = document.createElement('div');
791
+ stage.className = 'prompt-stage';
792
+ prompt.parentNode.insertBefore(stage, prompt);
793
+ stage.appendChild(prompt);
794
+ const btn = document.createElement('button');
795
+ btn.type = 'button';
796
+ btn.id = 'optimizeBtn';
797
+ btn.className = 'optimize is-locked';
798
+ btn.setAttribute('aria-disabled', 'true');
799
+ btn.textContent = '优化提示词';
800
+ const tip = document.createElement('div');
801
+ tip.id = 'optimizeTip';
802
+ tip.className = 'optimize-tip';
803
+ tip.hidden = true;
804
+ stage.appendChild(btn);
805
+ stage.appendChild(tip);
806
+ btn.addEventListener('click', () => {
807
+ void onOptimizePrompt();
808
+ });
809
+ fetch('/api/health')
810
+ .then((res) => res.json())
811
+ .then((data) => {
812
+ optimizeMember = !!(data && data.member === true);
813
+ btn.classList.toggle('is-locked', !optimizeMember);
814
+ btn.setAttribute('aria-disabled', optimizeMember ? 'false' : 'true');
815
+ })
816
+ .catch(() => {
817
+ optimizeMember = false;
818
+ });
819
+ }
820
+
821
+ mountOptimize();
822
+
728
823
  })(window);
package/studio/index.html CHANGED
@@ -45,13 +45,13 @@
45
45
  <div class="plus-menu" id="plusMenu" hidden>
46
46
  <button type="button" id="uploadBtn">
47
47
  <span class="plus-ico">↑</span>
48
- <span><strong>上传附件</strong><small>图片 / 视频 / 音频 / 文档</small></span>
48
+ <span><strong>上传素材</strong><small id="uploadHint">图片 / 视频 / 文档 / 口播 / 配乐</small></span>
49
49
  </button>
50
- <button type="button" id="voiceBtn">
50
+ <button type="button" id="voiceBtn">
51
51
  <span class="plus-ico">♪</span>
52
52
  <span><strong>选择语音</strong><small>免费 / API / 复刻音色</small></span>
53
53
  </button>
54
- <button type="button" id="paceToggle">
54
+ <button type="button" id="paceToggle">
55
55
  <span class="plus-ico">⏱</span>
56
56
  <span><strong>节奏</strong><small id="paceHint">1.0×</small></span>
57
57
  </button>
@@ -69,7 +69,7 @@
69
69
  <div class="assets" id="assets" hidden>
70
70
  <span class="assets-label">素材</span>
71
71
  </div>
72
- <input id="files" class="file-hidden" type="file" multiple accept="audio/*,video/*,image/*,.pdf,.md,.txt,.doc,.docx" />
72
+ <input id="files" class="file-hidden" type="file" multiple />
73
73
  <p class="err" id="err" hidden></p>
74
74
  </section>
75
75