Files
openmotion/shared/session.ts
Tom Huang 0c3b1bcef5 Add offline project sharing and lifecycle management (#482)
* Add offline project sharing and lifecycle management

* Cover project tools in tracking and package smoke tests

* Verify tracking coverage against registered tools

* Validate pinned revisions in project archive requests

---------

Co-authored-by: pftom <pftom@pftomdeMacBook-Pro.local>
2026-11-16 23:27:37 +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', '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;
}