Files
openmotion/shared/session.ts
Tom Huang 942457a98e Connect Explore, media scenes and studios in the creative workspace (#637)
* Connect Explore, media scenes and studios in the creative workspace

* Keep the related template preview open while retrying playback

* Exercise the project MCP entry in the review handoff browser test

* Ship the Studio soundtrack and complete navigation translations

* Localize Studio entry points and searchable destination names

---------

Co-authored-by: pftom <26423749+pftom@users.noreply.github.com>
2026-11-19 14:25:19 +08:00

28 lines
2.0 KiB
TypeScript

import type { ProjectMessage } from './conversation.ts';
/** Mode selects production tools; artifact kind selects its viewer. Neither depends on an Agent host. */
export const creationModes = [{ id: 'motion', title: 'OpenMotion', skill: 'openmotion-production', artifactKind: 'motion-project', templateCategories: ['builtin', 'featured', 'ads', 'motion', 'script', 'short-form', 'all'] }] as const;
export const artifactViewers = { 'motion-project': { id: 'motion', title: 'OpenMotion', scheme: 'motion', embeddable: true } } as const;
export type ArtifactKind = keyof typeof artifactViewers;
export type CreationMode = typeof creationModes[number]['id'];
export type ArtifactIdentity = { id: string; title: string; templateId?: string };
export type MotionArtifact = ArtifactIdentity & { kind: 'motion-project'; projectId: string };
// Extend this discriminated union when an additional viewer/resource type is implemented.
export type SessionArtifact = MotionArtifact;
export type CreativeSession = { id: string; title: string; mode: CreationMode; artifacts: SessionArtifact[]; activeArtifactId?: string; createdAt?: number; openedAt?: number; templateId?: string };
export type SessionDetail = CreativeSession & { messages: ProjectMessage[] };
/** Hide a session with only trashed projects without dropping drafts or saved ownership. */
export function availableSession<T extends CreativeSession>(session: T, trashed: ReadonlySet<string>): T | undefined {
const artifacts = session.artifacts.filter(artifact => !trashed.has(artifact.projectId));
if (artifacts.length === session.artifacts.length) return session;
if (!artifacts.length) return undefined;
const activeArtifactId = artifacts.find(artifact => artifact.id === session.activeArtifactId)?.id ?? artifacts[0].id;
return { ...session, artifacts, activeArtifactId };
}
export function creationMode(value: unknown) {
const mode = creationModes.find(item => item.id === value);
if (!mode) throw new Error('当前仅支持 OpenMotion 模式');
return mode;
}