全能创作:定妆/台词/换款与剧情方向硬约束,资源可下载
修角色定妆修改不重出图、角色图混入商品、宠物旁白腔、换款同点复读、剧情反转方向漂移,并补会话资源下载与外观/空消息闸门。
This commit is contained in:
@@ -666,10 +666,57 @@ function planDocumentBody(payload: Record<string, unknown>): string {
|
||||
].join("\n\n");
|
||||
}
|
||||
|
||||
|
||||
function sanitizeDownloadName(name: string, fallback: string): string {
|
||||
const cleaned = String(name || "").trim().replace(/[\\/:*?"<>|]+/g, "_");
|
||||
return cleaned || fallback;
|
||||
}
|
||||
|
||||
function triggerBlobDownload(blob: Blob, filename: string) {
|
||||
const href = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = href;
|
||||
anchor.download = filename;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
window.setTimeout(() => URL.revokeObjectURL(href), 1000);
|
||||
}
|
||||
|
||||
/** 对话资源下载:文档走本地 blob;图片/视频优先 fetch blob,跨域失败则新开标签。 */
|
||||
async function downloadSessionResource(options: {
|
||||
kind: SessionAssetKind;
|
||||
title: string;
|
||||
src?: string;
|
||||
body?: string;
|
||||
}) {
|
||||
const { kind, title, src, body } = options;
|
||||
if (kind === "document") {
|
||||
const filename = sanitizeDownloadName(title, "对话资源.md");
|
||||
const safeName = filename.toLowerCase().endsWith(".md") ? filename : `${filename}.md`;
|
||||
triggerBlobDownload(new Blob([String(body || "")], { type: "text/markdown;charset=utf-8" }), safeName);
|
||||
return;
|
||||
}
|
||||
if (!src) return;
|
||||
const fallback = kind === "video" ? "生成视频.mp4" : "生成图片.png";
|
||||
const filename = sanitizeDownloadName(title, fallback);
|
||||
try {
|
||||
const response = await fetch(src, { mode: "cors" });
|
||||
if (!response.ok) throw new Error(`download failed: ${response.status}`);
|
||||
const blob = await response.blob();
|
||||
let finalName = filename;
|
||||
if (kind === "video" && !/\.\w+$/.test(finalName)) finalName = `${finalName}.mp4`;
|
||||
if (kind === "image" && !/\.\w+$/.test(finalName)) finalName = `${finalName}.png`;
|
||||
triggerBlobDownload(blob, finalName);
|
||||
} catch {
|
||||
window.open(src, "_blank", "noopener,noreferrer");
|
||||
}
|
||||
}
|
||||
|
||||
function documentDescription(title: string): string {
|
||||
if (title.includes("创作策略")) return "创作策略 · 点击查看";
|
||||
if (title.includes("视频最终方案")) return "视频方案 · 点击查看";
|
||||
return "出片指令 · 点击查看";
|
||||
if (title.includes("创作策略")) return "创作策略 · 可下载";
|
||||
if (title.includes("视频最终方案")) return "视频方案 · 可下载";
|
||||
return "出片指令 · 可下载";
|
||||
}
|
||||
|
||||
/** 从本会话已加载 messages(+pinned_refs / 会话上传)聚合聊天资产,不另打 BE。 */
|
||||
@@ -864,7 +911,22 @@ function StrategyCard({ payload }: { payload: Record<string, unknown> }) {
|
||||
<section className="omni-strategy-card">
|
||||
<header className="omni-strategy-head">
|
||||
<strong>创作策略理解</strong>
|
||||
<span>平台自动判断</span>
|
||||
<div className="omni-doc-head-actions">
|
||||
<span>平台自动判断</span>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-doc-download"
|
||||
title="下载"
|
||||
aria-label="下载创作策略"
|
||||
onClick={() => void downloadSessionResource({
|
||||
kind: "document",
|
||||
title: "创作策略摘要.md",
|
||||
body: strategyDocumentBody(payload),
|
||||
})}
|
||||
>
|
||||
<Download />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<div className="omni-strategy-grid">
|
||||
{items.map(([label, value]) => (
|
||||
@@ -935,7 +997,22 @@ function PlanCard({ payload }: { payload: Record<string, unknown> }) {
|
||||
<section className="omni-video-plan-card">
|
||||
<header className="omni-video-plan-head">
|
||||
<strong>视频最终方案</strong>
|
||||
<span>确认后进入出片参数核对</span>
|
||||
<div className="omni-doc-head-actions">
|
||||
<span>确认后进入出片参数核对</span>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-doc-download"
|
||||
title="下载"
|
||||
aria-label="下载视频最终方案"
|
||||
onClick={() => void downloadSessionResource({
|
||||
kind: "document",
|
||||
title: "视频最终方案.md",
|
||||
body: planDocumentBody(payload),
|
||||
})}
|
||||
>
|
||||
<Download />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<section className="omni-plan-section">
|
||||
<strong>卖点做减法</strong>
|
||||
@@ -1007,9 +1084,15 @@ function PromptFileCard({
|
||||
<small>已根据方案、参数和 {String(payload.ref_count ?? 0)} 组参考素材在后台整理完成</small>
|
||||
</div>
|
||||
{body ? (
|
||||
<button type="button" onClick={() => onView(title, body)}>
|
||||
查看 Prompt
|
||||
</button>
|
||||
<div className="omni-prompt-file-actions">
|
||||
<button type="button" className="is-secondary" onClick={() => void downloadSessionResource({ kind: "document", title, body })}>
|
||||
<Download />
|
||||
下载
|
||||
</button>
|
||||
<button type="button" onClick={() => onView(title, body)}>
|
||||
查看 Prompt
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
@@ -1533,9 +1616,24 @@ function ElicitCard({
|
||||
const question = message.text || fields[0]?.label || "这项你想怎么定?";
|
||||
const compactChoiceOnly = String(message.payload.topic || "") === "cast_relation";
|
||||
// 兼容多种 options 来源:单选、多选、或字段内直接携带 options
|
||||
const rawChoiceField = fields.find(
|
||||
const fieldChoice = fields.find(
|
||||
(field) => Array.isArray(field.options) && field.options.length > 0,
|
||||
);
|
||||
const replyOptions = Array.isArray(message.payload.reply_options)
|
||||
? (message.payload.reply_options as Array<{ label?: string; text?: string; value?: string }>)
|
||||
: [];
|
||||
const replyChoiceField = replyOptions.length > 0
|
||||
? {
|
||||
key: fields[0]?.key || "answer",
|
||||
label: fields[0]?.label || question,
|
||||
type: "single" as const,
|
||||
options: replyOptions.map((item, index) => ({
|
||||
value: String(item.text || item.value || item.label || `option_${index + 1}`),
|
||||
label: String(item.label || item.text || item.value || `选项 ${index + 1}`),
|
||||
})),
|
||||
}
|
||||
: null;
|
||||
const rawChoiceField = fieldChoice || replyChoiceField;
|
||||
// 如果是痛点方向追问、或文案明确提及「直接点击一个选项」,但在 fields 里未能取到 options,提供兜底选项
|
||||
const isPainPointQuestion =
|
||||
fields[0]?.key === "pain_point_direction"
|
||||
@@ -1596,7 +1694,14 @@ function ElicitCard({
|
||||
type="button"
|
||||
key={value || index}
|
||||
disabled={disabled}
|
||||
onClick={() => onSubmit({ [choiceField.key || "choice"]: value }, [])}
|
||||
onClick={() => {
|
||||
// reply_options 是快捷整句回答,走聊天正文;字段 options 仍走 elicit answers。
|
||||
if (replyChoiceField && !fieldChoice) {
|
||||
onChatAnswer(value);
|
||||
return;
|
||||
}
|
||||
onSubmit({ [choiceField.key || "choice"]: value }, []);
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
@@ -3708,7 +3813,7 @@ export function OmniSessionPage({
|
||||
<>
|
||||
<button type="button" className="omni-prompt-drawer-bg" aria-label="关闭 Prompt" onClick={() => setPromptView(null)} />
|
||||
<aside className="omni-prompt-drawer" role="dialog" aria-label={promptView.title}>
|
||||
<header>
|
||||
<header className="omni-prompt-drawer-head">
|
||||
<span className="omni-prompt-drawer-file">
|
||||
<FileText />
|
||||
</span>
|
||||
@@ -3716,6 +3821,19 @@ export function OmniSessionPage({
|
||||
<strong>{promptView.title}</strong>
|
||||
<small>{documentDescription(promptView.title)}</small>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-doc-download"
|
||||
title="下载"
|
||||
aria-label="下载文档"
|
||||
onClick={() => void downloadSessionResource({
|
||||
kind: "document",
|
||||
title: promptView.title,
|
||||
body: promptView.body,
|
||||
})}
|
||||
>
|
||||
<Download />
|
||||
</button>
|
||||
<button type="button" onClick={() => setPromptView(null)} aria-label="关闭">
|
||||
<X />
|
||||
</button>
|
||||
@@ -3924,59 +4042,91 @@ export function OmniSessionPage({
|
||||
{group.items.map((asset) => {
|
||||
if (asset.kind === "document") {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="omni-assets-card is-doc"
|
||||
key={asset.key}
|
||||
onClick={() => {
|
||||
setPromptView({
|
||||
<div className="omni-assets-card is-doc" key={asset.key}>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-assets-card-main"
|
||||
onClick={() => {
|
||||
setPromptView({
|
||||
title: asset.promptTitle || asset.title,
|
||||
body: asset.promptBody || "暂无内容",
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span className="omni-assets-thumb is-doc">
|
||||
<FileText />
|
||||
</span>
|
||||
<span className="omni-assets-meta">
|
||||
<strong>{asset.title}</strong>
|
||||
<small>{asset.documentDescription || "文档 · 点击查看"}</small>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-assets-dl"
|
||||
title="下载"
|
||||
aria-label={`下载${asset.title}`}
|
||||
onClick={() => void downloadSessionResource({
|
||||
kind: "document",
|
||||
title: asset.promptTitle || asset.title,
|
||||
body: asset.promptBody || "暂无内容",
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span className="omni-assets-thumb is-doc">
|
||||
<FileText />
|
||||
</span>
|
||||
<span className="omni-assets-meta">
|
||||
<strong>{asset.title}</strong>
|
||||
<small>{asset.documentDescription || "文档 · 点击查看"}</small>
|
||||
</span>
|
||||
</button>
|
||||
body: asset.promptBody || "",
|
||||
})}
|
||||
>
|
||||
<Download />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={`omni-assets-card is-${asset.kind}`}
|
||||
key={asset.key}
|
||||
disabled={!asset.src}
|
||||
onClick={() => {
|
||||
if (!asset.src) return;
|
||||
setAssetPreview({
|
||||
src: asset.src,
|
||||
kind: asset.kind === "video" ? "video" : "image",
|
||||
name: asset.title,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span className="omni-assets-thumb">
|
||||
{asset.thumb ? (
|
||||
<img src={asset.thumb} alt="" />
|
||||
) : (
|
||||
<i>{asset.kind === "video" ? <Play /> : <Image />}</i>
|
||||
)}
|
||||
{asset.kind === "video" ? (
|
||||
<span className="omni-assets-play" aria-hidden="true">
|
||||
<Play />
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="omni-assets-meta">
|
||||
<strong>{asset.title}</strong>
|
||||
<small>{asset.kind === "video" ? "视频" : "图片"}</small>
|
||||
</span>
|
||||
</button>
|
||||
<div className={`omni-assets-card is-${asset.kind}`} key={asset.key}>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-assets-card-main"
|
||||
disabled={!asset.src}
|
||||
onClick={() => {
|
||||
if (!asset.src) return;
|
||||
setAssetPreview({
|
||||
src: asset.src,
|
||||
kind: asset.kind === "video" ? "video" : "image",
|
||||
name: asset.title,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span className="omni-assets-thumb">
|
||||
{asset.thumb ? (
|
||||
<img src={asset.thumb} alt="" />
|
||||
) : (
|
||||
<i>{asset.kind === "video" ? <Play /> : <Image />}</i>
|
||||
)}
|
||||
{asset.kind === "video" ? (
|
||||
<span className="omni-assets-play" aria-hidden="true">
|
||||
<Play />
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="omni-assets-meta">
|
||||
<strong>{asset.title}</strong>
|
||||
<small>{asset.kind === "video" ? "视频" : "图片"}</small>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="omni-assets-dl"
|
||||
title="下载"
|
||||
aria-label={`下载${asset.title}`}
|
||||
disabled={!asset.src}
|
||||
onClick={() => {
|
||||
if (!asset.src) return;
|
||||
void downloadSessionResource({
|
||||
kind: asset.kind,
|
||||
title: asset.title,
|
||||
src: asset.src,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Download />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
@@ -4030,6 +4180,11 @@ export function OmniSessionPage({
|
||||
kind={assetPreview?.kind}
|
||||
name={assetPreview?.name}
|
||||
close={() => setAssetPreview(null)}
|
||||
onDownload={assetPreview?.src ? () => void downloadSessionResource({
|
||||
kind: assetPreview.kind === "video" ? "video" : "image",
|
||||
title: assetPreview.name || (assetPreview.kind === "video" ? "生成视频.mp4" : "生成图片.png"),
|
||||
src: assetPreview.src,
|
||||
}) : undefined}
|
||||
/>
|
||||
<AssetSelectModal
|
||||
open={sessionAssetModalOpen}
|
||||
|
||||
Reference in New Issue
Block a user