fe02999904
前端统一现有资源编辑入口,按图片、视频、音频、文本、Agent 回执和版本分流。 Tauri 增加来源复核、稳定幂等、远端轮询、非破坏性派生与恢复账本。 服务端补齐资源编辑队列身份、视频音频幂等键和裁剪后的稳定完成结果。 同步共享合同、产品技术文档与定向回归测试。
280 lines
8.2 KiB
TypeScript
280 lines
8.2 KiB
TypeScript
import type {
|
|
GameCreationAppManifest,
|
|
GameIterationVersion,
|
|
ProjectResourceCanvasSection,
|
|
} from '../../../../../packages/shared/src/contracts/gameCreationApp';
|
|
|
|
export type ProjectResourceCategory = ProjectResourceCanvasSection;
|
|
|
|
export type ProjectAttachmentResult = {
|
|
fileName: string;
|
|
mediaType: string;
|
|
localPath?: string;
|
|
status: 'imported' | 'failed';
|
|
error?: string;
|
|
};
|
|
|
|
export type ProjectAgentResultSummary = {
|
|
agentId: string;
|
|
runId: string;
|
|
label: string;
|
|
title: string;
|
|
content: string;
|
|
updatedAt: number;
|
|
};
|
|
|
|
export type ProjectVersionResourceSummary = GameIterationVersion & {
|
|
label: string;
|
|
childVersionIds: string[];
|
|
};
|
|
|
|
export type ProjectResource = {
|
|
id: string;
|
|
category: ProjectResourceCategory;
|
|
subtype: string;
|
|
label: string;
|
|
path: string;
|
|
mediaType: string;
|
|
sourceLabel: string;
|
|
taskTitle: string | null;
|
|
manifestAssetId: string | null;
|
|
producerTaskId: string | null;
|
|
externalResourceId: string | null;
|
|
referenceResourceIds: string[];
|
|
dependencies: string[];
|
|
dependencyDepth: number;
|
|
content?: string;
|
|
version?: ProjectVersionResourceSummary;
|
|
};
|
|
|
|
const documentExtension =
|
|
/\.(md|markdown|mdx|txt|json|ya?ml|toml|html?|css|scss|less|m?[jt]sx?|cjs|rs|py|go|java|kt|kts|c|cc|cpp|h|hpp|cs|swift|php|rb|lua|sh|bash|zsh|sql|graphql|gql|xml|csv|ini|conf|vue|svelte)$/iu;
|
|
const artExtension = /\.(png|jpe?g|webp|gif|svg|avif|bmp|mp4|webm|mov)$/iu;
|
|
const audioExtension = /\.(mp3|wav|ogg|m4a|aac|flac|opus)$/iu;
|
|
const artKind =
|
|
/(?:^|[-_])(art|animation|character|icon|image|scene|sprite|spritesheet|ui|video)(?:$|[-_])/iu;
|
|
const audioKind = /(?:^|[-_])(audio|bgm|music|sfx|sound|voice)(?:$|[-_])/iu;
|
|
|
|
function fileName(path: string) {
|
|
return path.split(/[\\/]/u).filter(Boolean).pop() || path;
|
|
}
|
|
|
|
export function classifyProjectedResource(input: {
|
|
path: string;
|
|
mediaType: string;
|
|
kind?: string;
|
|
}): Exclude<ProjectResourceCategory, 'version'> | null {
|
|
const normalizedPath = input.path.trim().toLowerCase();
|
|
const normalizedMediaType = input.mediaType.trim().toLowerCase();
|
|
const normalizedKind = input.kind?.trim().toLowerCase() ?? '';
|
|
|
|
if (
|
|
normalizedMediaType.startsWith('audio/') ||
|
|
audioExtension.test(normalizedPath) ||
|
|
audioKind.test(normalizedKind)
|
|
) {
|
|
return 'audio';
|
|
}
|
|
if (
|
|
normalizedMediaType.startsWith('image/') ||
|
|
normalizedMediaType.startsWith('video/') ||
|
|
artExtension.test(normalizedPath) ||
|
|
artKind.test(normalizedKind)
|
|
) {
|
|
return 'art';
|
|
}
|
|
if (
|
|
normalizedMediaType.includes('json') ||
|
|
normalizedMediaType.includes('yaml') ||
|
|
normalizedMediaType.startsWith('text/') ||
|
|
documentExtension.test(normalizedPath)
|
|
) {
|
|
return 'document';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function resourcePriority(resource: ProjectResource) {
|
|
if (resource.manifestAssetId) {
|
|
return 4;
|
|
}
|
|
if (resource.id.startsWith('attachment:')) {
|
|
return 3;
|
|
}
|
|
if (resource.id.startsWith('task:')) {
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
export function projectResourcesFromReadModels(
|
|
manifest: GameCreationAppManifest,
|
|
attachments: ProjectAttachmentResult[],
|
|
agentResults: ProjectAgentResultSummary[],
|
|
) {
|
|
const taskById = new Map(manifest.tasks.map((task) => [task.id, task]));
|
|
const resources: ProjectResource[] = [];
|
|
|
|
for (const task of manifest.tasks) {
|
|
if (task.status !== 'completed') {
|
|
continue;
|
|
}
|
|
for (const path of task.artifacts) {
|
|
const category = classifyProjectedResource({ path, mediaType: '' });
|
|
if (!category) {
|
|
continue;
|
|
}
|
|
resources.push({
|
|
id: `task:${task.id}:${path}`,
|
|
category,
|
|
subtype: 'task-artifact',
|
|
label: fileName(path),
|
|
path,
|
|
mediaType: category === 'document' ? '项目文档' : '美术产物',
|
|
sourceLabel: '任务产物',
|
|
taskTitle: task.title,
|
|
manifestAssetId: null,
|
|
producerTaskId: task.id,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: task.dependencies,
|
|
dependencyDepth: 0,
|
|
});
|
|
}
|
|
}
|
|
|
|
for (const asset of manifest.assets) {
|
|
const category = classifyProjectedResource({
|
|
path: asset.localPath,
|
|
mediaType: asset.mediaType,
|
|
kind: asset.kind,
|
|
});
|
|
if (!category) {
|
|
continue;
|
|
}
|
|
const isPendingUiPrototype =
|
|
asset.kind === 'ui-prototype' &&
|
|
taskById.get('design-foundation')?.status !== 'completed';
|
|
resources.push({
|
|
id: `asset:${asset.id}`,
|
|
category,
|
|
subtype: asset.kind,
|
|
label: `${fileName(asset.localPath)}${
|
|
isPendingUiPrototype ? '(待视觉验收)' : ''
|
|
}`,
|
|
path: asset.localPath,
|
|
mediaType: asset.mediaType,
|
|
sourceLabel:
|
|
isPendingUiPrototype && asset.source.kind === 'canvas'
|
|
? '画板 · 候选界面图'
|
|
: asset.source.kind === 'canvas'
|
|
? '画板'
|
|
: asset.source.kind === 'generated'
|
|
? 'Agent 生成'
|
|
: '用户上传',
|
|
taskTitle: null,
|
|
manifestAssetId: asset.id,
|
|
producerTaskId: null,
|
|
externalResourceId: asset.source.resourceId ?? null,
|
|
referenceResourceIds: asset.source.referenceResourceIds ?? [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
});
|
|
}
|
|
|
|
for (const attachment of attachments) {
|
|
if (attachment.status !== 'imported' || !attachment.localPath) {
|
|
continue;
|
|
}
|
|
const category = classifyProjectedResource({
|
|
path: attachment.localPath,
|
|
mediaType: attachment.mediaType,
|
|
});
|
|
if (!category) {
|
|
continue;
|
|
}
|
|
resources.push({
|
|
id: `attachment:${attachment.localPath}`,
|
|
category,
|
|
subtype: 'attachment',
|
|
label: attachment.fileName,
|
|
path: attachment.localPath,
|
|
mediaType: attachment.mediaType || '未知媒体类型',
|
|
sourceLabel: '用户上传',
|
|
taskTitle: null,
|
|
manifestAssetId: null,
|
|
producerTaskId: null,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
});
|
|
}
|
|
|
|
for (const result of agentResults) {
|
|
resources.push({
|
|
id: `agent-result:${result.agentId}:${result.runId}`,
|
|
category: 'document',
|
|
subtype: 'agent-result',
|
|
label: result.title,
|
|
path: `专业 Agent 文本回执 · ${result.label}`,
|
|
mediaType: 'Agent 历史文本回执',
|
|
sourceLabel: `历史成果 · ${result.label}`,
|
|
taskTitle: null,
|
|
manifestAssetId: null,
|
|
producerTaskId: taskById.has(result.agentId) ? result.agentId : null,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
content: result.content,
|
|
});
|
|
}
|
|
|
|
const childVersionIdsByParent = new Map<string, string[]>();
|
|
for (const version of manifest.versions ?? []) {
|
|
if (!version.parentVersionId) {
|
|
continue;
|
|
}
|
|
const children = childVersionIdsByParent.get(version.parentVersionId) ?? [];
|
|
children.push(version.versionId);
|
|
childVersionIdsByParent.set(version.parentVersionId, children);
|
|
}
|
|
for (const [index, manifestVersion] of (manifest.versions ?? []).entries()) {
|
|
const version: ProjectVersionResourceSummary = {
|
|
...manifestVersion,
|
|
label: `版本 ${index + 1}`,
|
|
childVersionIds:
|
|
childVersionIdsByParent.get(manifestVersion.versionId) ?? [],
|
|
};
|
|
resources.push({
|
|
id: `version:${version.versionId}`,
|
|
category: 'version',
|
|
subtype: 'project-version',
|
|
label: version.label,
|
|
path: `项目版本 · ${version.versionId}`,
|
|
mediaType: '正式项目版本',
|
|
sourceLabel: version.parentVersionId
|
|
? `项目修订 ${version.projectRevision} · 父版本 ${version.parentVersionId}`
|
|
: `项目修订 ${version.projectRevision} · 初始版本`,
|
|
taskTitle: null,
|
|
manifestAssetId: null,
|
|
producerTaskId: null,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
version,
|
|
});
|
|
}
|
|
|
|
const uniqueByPath = new Map<string, ProjectResource>();
|
|
for (const resource of resources) {
|
|
const existing = uniqueByPath.get(resource.path);
|
|
if (!existing || resourcePriority(resource) > resourcePriority(existing)) {
|
|
uniqueByPath.set(resource.path, resource);
|
|
}
|
|
}
|
|
return Array.from(uniqueByPath.values());
|
|
}
|