export type SessionMessage = { id: string; role: 'user' | 'assistant'; content: string; createdAt: number }; /** Compatibility name for existing project conversation readers. */ export type ProjectMessage = SessionMessage; export type ProjectConversation = { projectId: string; messages: ProjectMessage[] }; export function validateInstruction(value: unknown): string { if (typeof value !== 'string' || !value.trim() || value.trim().length > 8000 || /[\x00-\x08\x0b\x0c\x0e-\x1f]/.test(value)) { throw new Error('创作需求需要 1–8000 个字符'); } return value.trim(); } function originInstallGuide(url: string): string | null { try { const parsed = new URL(url); if (parsed.protocol === 'https:' || parsed.protocol === 'http:') { return `${parsed.origin}/install.md`; } } catch { // Ignore non-URL strings. } return null; } /** A handoff to an external Agent, never a claim that a task has been executed. */ export function projectInstruction(url: string, content: string) { const guide = originInstallGuide(url); const setupLine = guide ? `如当前尚未接入该环境的 OpenMotion 云端 MCP,或仍连接着旧版 local stdio MCP / 本地插件,请先按 ${guide} 移除旧本地配置并完成云端接入与 OAuth 授权(保留本地工程文件,不要执行新建模板引导,完成后直接继续本项目)。\n` : ''; return `请打开这个 OpenMotion 工程:${url}\n${setupLine}先调用 openmotion_get_project,确认 projectId 与链接一致,读取该工程的 conversation,再继续制作。\n\n${content}`; } export function sessionInstruction(url: string, sessionId: string, content: string) { const guide = originInstallGuide(url); const setupLine = guide ? `如当前尚未接入该环境的 OpenMotion 云端 MCP,或仍连接着旧版 local stdio MCP / 本地插件,请先按 ${guide} 移除旧本地配置并完成云端接入与 OAuth 授权(保留本地工程文件,不要执行新建模板引导,完成后直接继续本会话)。\n` : ''; return `继续这个 OpenMotion 会话:${url}\n${setupLine}先调用 openmotion_get_session(sessionId: ${sessionId}),读取模式、需求和 artifacts,按返回的 skill 与 templateId 制作。若没有产物,先用 openmotion_create_artifact 在这个会话中创建。操作前调用 openmotion_get_project,确认 projectId 与链接或所选产物一致;如不一致,用最新 revision 调用 openmotion_open_artifact 切到本会话对应的产物后再读取。不要覆盖其他会话的工程。\n\n${content}`; }