🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"
TypeScript
feat: pipeline-style agent actions (one-click, no chat drawer)
Connora78a9788444e
diff --git a/web/src/composables/useAgentAction.ts b/web/src/composables/useAgentAction.tsnew file mode 100644index 0000000..366d765--- /dev/null+++ b/web/src/composables/useAgentAction.ts@@ -0,0 +1,83 @@+import { ref } from 'vue'+import { toast } from 'vue-sonner'+import { agentAPI } from '@/api/agent'+import type { AgentType } from '@/types/agent'++/**+ * 一键执行 Agent 操作(流水线模式,不需要用户输入)+ * 调用 agent SSE 接口,自动发送预设消息,流式接收结果+ */+export function useAgentAction() {+ const running = ref(false)+ const runningType = ref<AgentType | null>(null)+ const progress = ref('')++ async function execute(+ agentType: AgentType,+ dramaId: number,+ episodeId: number,+ message: string,+ onDone?: () => void,+ ) {+ if (running.value) {+ toast.warning('有操作正在执行中')+ return+ }++ running.value = true+ runningType.value = agentType+ progress.value = '正在处理...'++ const toastId = toast.loading(progress.value, { duration: Infinity })++ try {+ let lastContent = ''++ for await (const event of agentAPI.streamChat(agentType, {+ message,+ drama_id: dramaId,+ episode_id: episodeId,+ })) {+ switch (event.type) {+ case 'tool_call':+ progress.value = `调用 ${event.tool_name || '工具'}...`+ toast.loading(progress.value, { id: toastId })+ break+ case 'tool_result':+ progress.value = `${event.tool_name || '工具'} 完成`+ toast.loading(progress.value, { id: toastId })+ break+ case 'content':+ lastContent += event.data+ // Show first 50 chars of content as progress+ const preview = lastContent.length > 50+ ? lastContent.slice(0, 50) + '...'+ : lastContent+ progress.value = preview+ toast.loading(progress.value, { id: toastId })+ break+ case 'done':+ toast.success('操作完成', { id: toastId })+ onDone?.()+ break+ case 'error':+ toast.error(`操作失败: ${event.data}`, { id: toastId })+ break+ }+ }+ } catch (err) {+ toast.error(`连接失败: ${err instanceof Error ? err.message : '未知错误'}`, { id: toastId })+ } finally {+ running.value = false+ runningType.value = null+ progress.value = ''+ }+ }++ return {+ running,+ runningType,+ progress,+ execute,+ }+}diff --git a/web/src/views/drama/episode/EpisodeWorkbench.vue b/web/src/views/drama/episode/EpisodeWorkbench.vueindex 50d30c9..ba03046 100644--- a/web/src/views/drama/episode/EpisodeWorkbench.vue+++ b/web/src/views/drama/episode/EpisodeWorkbench.vue@@ -68,6 +68,8 @@:has-scenes="resource.hasScenes":character-count="resource.characters.length":scene-count="resource.scenes.length"+ :running="agent.running"+ :running-type="agent.runningType"@save="resource.saveScript"@upload="handleUploadScript"@rewrite="handleRewriteScript"@@ -84,6 +86,8 @@:all-selected="table.allSelected":has-selection="table.hasSelection":progress="table.progress"+ :running="agent.running"+ :running-type="agent.runningType"@toggle-select="table.toggleSelect"@toggle-select-all="table.toggleSelectAll"@clear-selection="table.clearSelection"@@ -129,6 +133,7 @@ import ResourcePanel from './workbench/ResourcePanel.vue'import ScriptTab from './workbench/ScriptTab.vue'import StoryboardTable from './workbench/StoryboardTable.vue'import { useEpisodeWorkbench } from '@/composables/useEpisodeWorkbench'+import { useAgentAction } from '@/composables/useAgentAction'import AgentDrawer from '@/components/agent/AgentDrawer.vue'import { dramaAPI } from '@/api/drama'import { characterLibraryAPI } from '@/api/character-library'@@ -146,6 +151,10 @@ const videoGen = reactive(wb.videoGen)const agentOpen = ref(false)const agentInitType = ref<AgentType | undefined>(undefined)+// 流水线操作+const agent = useAgentAction()+const episodeDbId = computed(() => Number(resource.episode?.id || 0))+const progressPct = computed(() => {const p = table.progressreturn p.total > 0 ? Math.round((p.withImage / p.total) * 100) : 0@@ -154,12 +163,6 @@ const progressPct = computed(() => {const goBack = () => router.push(`/drama/${dramaId}`)const goToCompose = () => router.push(`/drama/${dramaId}/episode/${episodeNumber}/compose`)-// --- Agent triggers: open drawer with pre-selected agent type ----function openAgent(type: AgentType) {- agentInitType.value = type- agentOpen.value = true-}-// --- Script Tab handlers ---const scriptFileInput = ref<HTMLInputElement | null>(null)@@ -179,15 +182,33 @@ const onScriptFileSelected = async (e: Event) => {} catch {toast.error('读取文件失败')}- // Reset so same file can be selected againif (scriptFileInput.value) scriptFileInput.value.value = ''}-const handleRewriteScript = () => openAgent('script_rewriter')-const handleExtract = () => openAgent('extractor')+// 流水线操作:一键执行,自动刷新数据+const handleRewriteScript = () => {+ agent.execute('script_rewriter', dramaId, episodeDbId.value,+ '请将剧本改写为格式化剧本',+ () => resource.loadData(),+ )+}-// --- Storyboard Tab handlers ----const handleBreakdown = () => openAgent('storyboard_breaker')+const handleExtract = () => {+ agent.execute('extractor', dramaId, episodeDbId.value,+ '请提取角色和场景信息',+ () => resource.loadData(),+ )+}++const handleBreakdown = () => {+ agent.execute('storyboard_breaker', dramaId, episodeDbId.value,+ '请拆解分镜并生成视频提示词',+ () => {+ resource.loadData()+ table.activeTab = 'storyboard'+ },+ )+}const handleAddStoryboard = async () => {const ep = resource.episodediff --git a/web/src/views/drama/episode/workbench/ScriptTab.vue b/web/src/views/drama/episode/workbench/ScriptTab.vueindex 683ab90..2f4569c 100644--- a/web/src/views/drama/episode/workbench/ScriptTab.vue+++ b/web/src/views/drama/episode/workbench/ScriptTab.vue@@ -9,6 +9,7 @@ import {Save,Users,MapPin,+ Loader2,} from 'lucide-vue-next'const props = defineProps<{@@ -18,6 +19,8 @@ const props = defineProps<{hasScenes: booleancharacterCount: numbersceneCount: number+ running: boolean+ runningType: string | null}>()const emit = defineEmits<{@@ -91,13 +94,21 @@ async function saveAndEmit(event: 'rewrite' | 'extract') {<Upload :size="13" />上传</Button>- <Button variant="ghost" size="sm" class="tb-btn" :disabled="!hasContent" @click="saveAndEmit('rewrite')">- <Wand2 :size="13" />- AI 改写+ <Button variant="ghost" size="sm" class="tb-btn"+ :disabled="!hasContent || running"+ @click="saveAndEmit('rewrite')"+ >+ <Loader2 v-if="runningType === 'script_rewriter'" :size="13" class="animate-spin" />+ <Wand2 v-else :size="13" />+ {{ runningType === 'script_rewriter' ? '改写中...' : 'AI 改写' }}</Button>- <Button variant="ghost" size="sm" class="tb-btn" :disabled="!hasContent" @click="saveAndEmit('extract')">- <FileText :size="13" />- 提取角色&场景+ <Button variant="ghost" size="sm" class="tb-btn"+ :disabled="!hasContent || running"+ @click="saveAndEmit('extract')"+ >+ <Loader2 v-if="runningType === 'extractor'" :size="13" class="animate-spin" />+ <FileText v-else :size="13" />+ {{ runningType === 'extractor' ? '提取中...' : '提取角色&场景' }}</Button><Button v-if="isDirty" size="sm" class="tb-btn tb-btn--save" @click="handleSave"><Save :size="13" />diff --git a/web/src/views/drama/episode/workbench/StoryboardTable.vue b/web/src/views/drama/episode/workbench/StoryboardTable.vueindex 8d8e187..4bde9ae 100644--- a/web/src/views/drama/episode/workbench/StoryboardTable.vue+++ b/web/src/views/drama/episode/workbench/StoryboardTable.vue@@ -1,7 +1,7 @@<script setup lang="ts">import { computed } from 'vue'import { Checkbox } from '@/components/ui/checkbox'-import { Wand2 } from 'lucide-vue-next'+import { Wand2, Loader2 } from 'lucide-vue-next'import { Button } from '@/components/ui/button'import type { Storyboard, Character, Scene } from '@/types/drama'import TableToolbar from './TableToolbar.vue'@@ -21,6 +21,8 @@ const props = defineProps<{generating: numbertotalDuration: number}+ running?: boolean+ runningType?: string | null}>()const emit = defineEmits<{@@ -116,9 +118,10 @@ const durationDisplay = computed(() => {<Wand2 :size="32" class="table-empty__icon" /><p class="table-empty__text">暂无分镜</p><p class="table-empty__hint">请先在「剧本」页完成改写和角色场景提取,然后拆解分镜</p>- <Button variant="outline" size="sm" @click="emit('breakdown')">- <Wand2 :size="14" />- Agent 拆解分镜+ <Button variant="outline" size="sm" :disabled="running" @click="emit('breakdown')">+ <Loader2 v-if="runningType === 'storyboard_breaker'" :size="14" class="animate-spin" />+ <Wand2 v-else :size="14" />+ {{ runningType === 'storyboard_breaker' ? '拆解中...' : 'Agent 拆解分镜' }}</Button></div></div>