Files
ttstd-infinite-canvas/web/src/lib/canvas/canvas-style-execution.ts
ddCat 9148ceab66 feat(canvas): 画布工作区 - 整合侧栏与风格预设并修复提示词回填
选择性整合 #547,保留主分支节点与工具条设计。新增默认折叠的节点、资产、任务和历史面板,风格与预设保留在节点内,移除重复入口。

补齐工具权限、提示词解析、资源引用保护及数据库迁移,修复提示词清空和连续编辑后的生成配置同步。

验证:前端全量 1925 项测试、构建、类型检查及 lint 通过;后端 go test ./... 通过。真实模型、PostgreSQL 实库与登录态页面验收仍待进行。

Refs #547

Co-authored-by: bensharp <bensharp@qq.com>
2026-09-20 16:40:08 +08:00

41 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { applyStyleExecutionPlan, createStyleProfileSnapshot, parseStyleProfile, resolveStyleExecutionPlan, serializeStyleProfile, type StyleExecutionPlan, type StyleProfileSnapshot } from "@/lib/canvas/style-profile";
import { logicalModelIDForConfig, resolveModelRequestConfig, type AiConfig } from "@/stores/use-config-store";
import type { CanvasNodeData } from "@/types/canvas";
import { parseToolMentionTokens } from "@/lib/canvas/canvas-resource-references";
export type CanvasStyleExecutionRuntime = {
profile: StyleProfileSnapshot;
profileJson: string;
plan: StyleExecutionPlan;
prompt: string;
};
export function resolveCanvasStyleExecution(nodes: CanvasNodeData[], sourceNode: CanvasNodeData | undefined, prompt: string, config: AiConfig, mode: "image" | "video"): CanvasStyleExecutionRuntime | null {
if (mode === "image" && parseToolMentionTokens(prompt).some((tool) => tool.type === "style")) return null;
const styleNode = nodes.find((node) => node.metadata?.workflowKind === "styleboard");
if (!styleNode || sourceNode?.metadata?.workflowKind === "styleboard") return null;
const profile = parseStyleProfile(styleNode.metadata?.styleProfileJson) || legacyStyleNodeProfile(styleNode);
if (!profile) return null;
const requestConfig = resolveModelRequestConfig(config, config.model);
const plan = resolveStyleExecutionPlan(profile, { mode, model: requestConfig.model, interfaceType: requestConfig.interfaceType || requestConfig.apiFormat });
// 平台模型的真实供应模型由后端入队时路由,前端只能预览,最终兼容性由后端重算。
if (plan.status === "blocked" && !logicalModelIDForConfig(config)) throw new Error(`当前模型无法完整执行项目画风:${plan.warnings.join(";")}。请切换模型,或在项目设置中停用对应画风资产`);
return { profile, profileJson: serializeStyleProfile(profile), plan, prompt: applyStyleExecutionPlan(prompt, plan) };
}
function legacyStyleNodeProfile(node: CanvasNodeData) {
const prompt = String(node.metadata?.content || node.metadata?.prompt || "").trim();
const presetId = String(node.metadata?.stylePresetId || "").trim();
if (!prompt || !presetId) return null;
return createStyleProfileSnapshot({
presetId,
title: node.title.replace(/^(?:项目)?画风\s*[·::]?\s*/, "").trim() || node.title,
description: node.metadata?.workflowDescription || "历史项目画风规范",
tags: [],
prompt,
assets: [],
source: "user",
revision: 1,
});
}