Open source CapCut alternative.
TypeScript
feat(site): package the ChatGPT plugin with skills
David Lee242db723935
diff --git a/site/package.json b/site/package.jsonindex 3ff22e88..ecb8e35d 100644--- a/site/package.json+++ b/site/package.json@@ -49,6 +49,7 @@"eval:cut-export": "bun run scripts/eval-cut-export.ts","eval:cut-export-memory": "bun run scripts/eval-cut-export-memory.ts","chatgpt:build": "bun run scripts/build-chatgpt-widget.ts",+ "chatgpt:plugin": "bun run scripts/build-chatgpt-plugin.ts","predev": "npm run chatgpt:build","prebuild": "npm run chatgpt:build","eval:chatgpt-widget": "bun run scripts/eval-chatgpt-widget.ts"diff --git a/site/scripts/build-chatgpt-plugin.ts b/site/scripts/build-chatgpt-plugin.tsnew file mode 100644index 00000000..11e85f4a--- /dev/null+++ b/site/scripts/build-chatgpt-plugin.ts@@ -0,0 +1,29 @@+import { copyFile, mkdir, rm, writeFile } from "node:fs/promises";+import path from "node:path";+import { pluginFiles } from "../src/clients/chatgpt/plugin";++// The ZIP the OpenAI portal imports as a new draft of the Donkey Cut plugin.+// bun run scripts/build-chatgpt-plugin.ts --demo <reviewer-accessible video URL>+const demo = process.argv[process.argv.indexOf("--demo") + 1];+if (!process.argv.includes("--demo") || !demo?.startsWith("https://")) {+ throw new Error("Pass --demo <https URL of the demo recording>; review requires one.");+}+const root = path.resolve(import.meta.dir, "..");+const outdir = path.join(root, "dist/chatgpt-plugin");+const zipPath = path.join(root, "dist/donkey-cut-chatgpt-plugin.zip");+await rm(outdir, { recursive: true, force: true });+await rm(zipPath, { force: true });++// Write every file, then zip the folder's contents so the manifest sits at the root.+for (const file of pluginFiles(demo)) {+ const target = path.join(outdir, file.path);+ await mkdir(path.dirname(target), { recursive: true });+ if ("from" in file) {+ await copyFile(path.join(root, file.from), target);+ continue;+ }+ await writeFile(target, file.text);+}+const zip = Bun.spawnSync(["zip", "-qrX", zipPath, "."], { cwd: outdir });+if (zip.exitCode !== 0) throw new Error(`zip failed: ${zip.stderr.toString()}`);+console.log(`ChatGPT plugin: ${zipPath}`);diff --git a/site/src/clients/chatgpt/plugin.test.ts b/site/src/clients/chatgpt/plugin.test.tsnew file mode 100644index 00000000..d8be2b92--- /dev/null+++ b/site/src/clients/chatgpt/plugin.test.ts@@ -0,0 +1,65 @@+import { expect, test } from "bun:test";+import { existsSync } from "node:fs";+import path from "node:path";+import { pluginFiles } from "./plugin";++const DEMO = "https://example.com/demo.mp4";+const files = pluginFiles(DEMO);+const json = (name: string) => {+ const file = files.find((f) => f.path === name);+ if (!file || !("text" in file)) throw new Error(`missing ${name}`);+ return JSON.parse(file.text);+};++// The portal's limits for an initial MCP review, checked before an upload.+test("the manifest fits the portal's listing and review limits", () => {+ const openai = json("plugin.json").extensions["com.openai"];+ const ui = openai.interface;+ expect(ui.displayName.length).toBeLessThanOrEqual(30);+ expect(ui.shortDescription.length).toBeLessThanOrEqual(30);+ expect(ui.longDescription.length).toBeLessThanOrEqual(4000);+ expect(ui.developerName.length).toBeLessThanOrEqual(80);+ for (const key of ["websiteURL", "supportURL", "privacyPolicyURL", "termsOfServiceURL"]) {+ expect(ui[key].startsWith("https://")).toBe(true);+ }+ expect(ui.defaultPrompt.length).toBeLessThanOrEqual(3);+ expect(new Set(ui.defaultPrompt).size).toBe(ui.defaultPrompt.length);+ for (const prompt of ui.defaultPrompt) {+ expect(prompt.length).toBeLessThanOrEqual(128);+ expect(prompt).not.toContain("@");+ }+ expect(openai.review.demo_recording_url).toBe(DEMO);+ expect(openai.review.test_cases.positive).toHaveLength(5);+ expect(openai.review.test_cases.negative).toHaveLength(3);+ for (const c of openai.review.test_cases.positive) {+ expect(c.tools_triggered.length).toBeGreaterThan(0);+ expect(c.expected_behavior.length).toBeGreaterThan(0);+ }+});++test("every path the manifest names ships in the package, and no secret does", () => {+ const openai = json("plugin.json").extensions["com.openai"];+ const paths = new Set(files.map((f) => `./${f.path}`));+ for (const ref of [openai.onboardingSkill, openai.interface.logo, openai.interface.composerIcon]) {+ expect(paths.has(ref)).toBe(true);+ }+ for (const file of files) {+ if ("from" in file) expect(existsSync(path.resolve(process.cwd(), file.from))).toBe(true);+ }+ const text = files.map((f) => ("text" in f ? f.text : "")).join("\n");+ expect(text).not.toMatch(/clientSecret|test_credentials|reviewer_instructions|\.app\.json/);+ expect(Object.keys(json("mcp.json").mcpServers)).toHaveLength(1);+});++test("each skill has the frontmatter ChatGPT reads to pick it", () => {+ const skills = files.filter((f) => f.path.startsWith("skills/"));+ expect(skills.length).toBeGreaterThan(10);+ for (const skill of skills) {+ if (!("text" in skill)) throw new Error(skill.path);+ const name = skill.path.split("/")[1];+ expect(skill.text.startsWith(`---\nname: ${name}\ndescription: "`)).toBe(true);+ const description = JSON.parse(skill.text.split("\n")[2].slice("description: ".length));+ expect(description.length).toBeGreaterThan(40);+ expect(skill.text.split("---\n")[2].trim().length).toBeGreaterThan(100);+ }+});diff --git a/site/src/clients/chatgpt/plugin.ts b/site/src/clients/chatgpt/plugin.tsnew file mode 100644index 00000000..2a432ed1--- /dev/null+++ b/site/src/clients/chatgpt/plugin.ts@@ -0,0 +1,130 @@+// The ChatGPT plugin package: the manifest, the MCP connection and the+// guides as skills, in the Agent Plugins layout OpenAI's portal imports from a+// ZIP. Tools come from the MCP server; this package carries the listing, the+// review cases and the skills.+import { SETTINGS } from "@/lib/config/registry";+import { CLIENT_ID, MCP_PATH, SCOPES } from "@/clients/chatgpt/server/config";+import { pluginSkills } from "@/clients/chatgpt/server/guidance";++/** The package name the portal gave the listing; uploads update it. */+const PACKAGE_NAME = "app-6ab37f0e13e88191a96ea418d230fe55";+const SERVER_NAME = "donkey-cut";+const LOGO_SOURCE = "public/chatgpt-app-icon.png";+const LOGO = "./assets/logo.png";++const LONG_DESCRIPTION = `Donkey Cut is an open-source video editor.++Import footage, trim and arrange clips, add captions and titles, and preview your edits.++Open existing projects or start a new video, undo changes as you work, and export the finished result when you're ready.++Open Donkey Cut from the sidebar or beside a conversation to pick a project, or @-mention a project in the composer to work on it.`;++// Prompts the reviewer runs. Each names the tools ChatGPT should reach for.+const POSITIVE = [+ {+ description: "Lists the account's cloud projects and opens the picker.",+ prompt: "Show me my Donkey Cut projects.",+ tools_triggered: ["list_projects"],+ expected_behavior: "Lists the connected account's cloud projects with their names, most recent first.",+ },+ {+ description: "Creates a vertical project and opens it in the editor card.",+ prompt: "Start a new vertical Donkey Cut video called Weekend recap.",+ tools_triggered: ["create_project", "open_project"],+ expected_behavior: "Creates a 9:16 project named Weekend recap and shows the Donkey Cut editor in the card.",+ },+ {+ description: "Edits the open project with individual editing tools.",+ prompt: "In Donkey Cut, make my newest project square and add a title that says HELLO.",+ tools_triggered: ["list_projects", "open_project", "set_aspect", "add_title"],+ expected_behavior: "Opens the project, sets the aspect to 1:1 and adds a HELLO title; the card shows both changes.",+ },+ {+ description: "Steps the card's undo history.",+ prompt: "Undo that last Donkey Cut edit.",+ tools_triggered: ["undo"],+ expected_behavior: "Reverts the most recent edit in the open project and says what changed.",+ },+ {+ description: "Exports the finished video for download.",+ prompt: "Export my Donkey Cut project as a video file.",+ tools_triggered: ["export_video", "get_export_status"],+ expected_behavior: "Starts an export, reports progress, and returns a download link when it finishes.",+ },+];+const NEGATIVE = [+ { description: "General knowledge with no video editing.", prompt: "What is the capital of Australia?" },+ { description: "A writing task with no project or footage.", prompt: "Write a short poem about autumn leaves." },+ { description: "Arithmetic the model answers itself.", prompt: "What is 18 percent of 240?" },+];++type PluginFile = { path: string; text: string } | { path: string; from: string };++/** Every file in the package, with the logo copied from the site's assets.+ * The demo recording is the reviewer's video of the plugin at work. */+export function pluginFiles(demoRecordingUrl: string): PluginFile[] {+ const issuer = SETTINGS.chatgptApp.default.issuer;+ const skills = pluginSkills();+ const plugin = {+ $schema: "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",+ name: PACKAGE_NAME,+ version: "1.1.0",+ description: "Create and edit videos in Donkey Cut from ChatGPT.",+ author: { name: "HEY SALESMAN INC", url: issuer },+ homepage: issuer,+ repository: "https://github.com/DonkeyCut/Donkey",+ license: "Apache-2.0",+ extensions: {+ "com.openai": {+ onboardingSkill: "./skills/setup/SKILL.md",+ interface: {+ displayName: "Donkey Cut",+ shortDescription: "Create and edit videos",+ longDescription: LONG_DESCRIPTION,+ developerName: "HEY SALESMAN INC",+ category: "Creativity",+ websiteURL: issuer,+ supportURL: "https://discord.gg/Xv6qGax7sT",+ privacyPolicyURL: `${issuer}/privacy`,+ termsOfServiceURL: `${issuer}/terms`,+ defaultPrompt: [+ "Open my latest Donkey Cut project",+ "Start a vertical video for TikTok in Donkey Cut",+ "Add captions to my Donkey Cut project",+ ],+ logo: LOGO,+ composerIcon: LOGO,+ },+ review: {+ demo_recording_url: demoRecordingUrl,+ test_cases: { positive: POSITIVE, negative: NEGATIVE },+ },+ },+ },+ };+ const mcp = {+ $schema: "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",+ mcpServers: {+ [SERVER_NAME]: {+ type: "streamable-http",+ url: `${issuer}${MCP_PATH}`,+ extensions: {+ "com.openai": {+ auth: { type: "oauth", client: { mode: "provided", clientId: CLIENT_ID, tokenEndpointAuthMethod: "none" }, defaultScopes: [...SCOPES] },+ },+ },+ },+ },+ };+ return [+ { path: "plugin.json", text: `${JSON.stringify(plugin, null, 2)}\n` },+ { path: "mcp.json", text: `${JSON.stringify(mcp, null, 2)}\n` },+ { path: "assets/logo.png", from: LOGO_SOURCE },+ // JSON strings are valid YAML scalars, so descriptions with colons stay intact.+ ...skills.map((skill) => ({+ path: `skills/${skill.name}/SKILL.md`,+ text: `---\nname: ${skill.name}\ndescription: ${JSON.stringify(skill.description)}\n---\n\n${skill.body.trim()}\n`,+ })),+ ];+}diff --git a/site/src/clients/chatgpt/server/guidance.ts b/site/src/clients/chatgpt/server/guidance.tsindex e97597c1..e0cb076d 100644--- a/site/src/clients/chatgpt/server/guidance.ts+++ b/site/src/clients/chatgpt/server/guidance.ts@@ -90,8 +90,47 @@ set_publish edits the project's caption, tags, sound title and handle. These fieexport_video renders the saved cloud project with one of these presets: ${DOC_EXPORT_PRESETS.join(", ")}. Read its tool description for the preset choices. loudness masters the mix to a LUFS target for its destination, and stems adds a zip of one WAV per lane for mixing elsewhere. A returned export job is completed through get_export_status, and the card offers the finished download. render_preview and get_preview_status provide a playable preview for review. Only report a preview or export as ready when its result confirms completion.`,};+// What each guide is for, as the plugin's skill description: ChatGPT reads+// it to decide when to load the guide.+const DESCRIPTIONS: Record<string, string> = {+ "color-grading": "Grade and match color in Donkey Cut: exposure, contrast, curves, wheels, hue bands, LUTs and presets. Use when the user asks to change the look or color of footage.",+ "replicating-a-video": "Recreate the structure and style of a reference video with the user's own footage in Donkey Cut. Use when the user shares a video to copy.",+ "transitions-and-fades": "Add transitions between clips and fade clips in and out in Donkey Cut. Use when the user asks for smoother cuts, fades or transition effects.",+ "text-videos": "Build Donkey Cut videos driven by on-screen text: lyric videos, kinetic typography, quotes and timed captions. Use when text is the main visual.",+ "text-creativity": "Choose fonts, colors, layout and motion for on-screen text in Donkey Cut. Use when the user wants titles or captions to look designed.",+ "editing-taste": "Pacing, hooks and structure for short social videos in Donkey Cut. Use when the user asks to make an edit better, tighter or more engaging.",+ "talking-head-videos": "Edit talking-head footage in Donkey Cut: cut pauses and filler, add captions, punch-ins and b-roll. Use for vlogs, interviews and direct-to-camera videos.",+ "editor-overview": "How Donkey Cut works inside ChatGPT: cloud projects, the editor card, shared undo history, and which tools read or edit. Use at the start of any Donkey Cut editing session.",+ "timeline-editing": "Place, trim, split, move, retime and delete clips on the Donkey Cut timeline. Use when the user asks to cut, reorder, speed up or rearrange footage.",+ "watching-and-cutting": "Watch and listen to footage, measure silence, beats and levels, and cut by content in Donkey Cut. Use before content-based edits such as removing pauses, picking highlights or cutting to music.",+ "background-removal": "Remove or replace the background behind a person or subject in a Donkey Cut clip. Use when the user asks for a cutout or a background swap.",+ "graphics": "Add and animate titles, shapes, stickers, masks and effects in Donkey Cut. Use when the user asks for on-screen text, graphics, motion or layered composites.",+ "audio-and-subtitles": "Mix audio, level and duck tracks, and create, style, translate or correct subtitles in Donkey Cut. Use for sound, music, voiceover and caption requests.",+ "ai-generation": "Find stock media and generate images, voiceover, music and stickers in Donkey Cut with the account's credits. Use when the user needs media the project does not have.",+ "media-and-library": "Import, organize, convert and delete Donkey Cut project media and Library assets. Use when the user manages files, folders, notes or templates.",+ "replicating-a-project": "Reuse another Donkey Cut project's edit, media or template in this one. Use when the user points at an existing project or share link to copy.",+ "publish-and-export": "Export the finished Donkey Cut video and set its publish caption and tags. Use when the user wants a file to download or post.",+};++/** The plugin's setup skill: ChatGPT runs it once the plugin is installed. */+const ONBOARDING_SKILL = {+ name: "setup",+ description: "Set up Donkey Cut after installing the plugin: confirm the connected account, then open or create the first cloud project. Use right after installation or when the user asks how to start with Donkey Cut.",+ body: `# Getting started with Donkey Cut+1. Call account_status. Tell the user their plan, AI credit balance and cloud storage in one line. Editing, previews and exports are free; hosted AI generation spends credits.+2. Call list_projects. When projects exist, name the three most recent and ask which to open. When there are none, ask what the video is for and its shape (9:16 for TikTok, Reels and Shorts, 16:9 for YouTube, 1:1 square), then call create_project.+3. Call open_project for the chosen project. The editor card holds the timeline, media panel and preview; keep it open while editing.+4. Ask the user to attach footage or paste a link, and bring it in with import_media.+Projects saved on a Mac or in a browser reach ChatGPT once the user saves them to the cloud in Donkey Cut. Ask before creating a project the user did not request.`,+};+export const SKILL_INDEX = Object.keys(SKILLS);+/** Every guide as a plugin skill, the setup skill first. */+export function pluginSkills(): { name: string; description: string; body: string }[] {+ return [ONBOARDING_SKILL, ...SKILL_INDEX.map((name) => ({ name, description: DESCRIPTIONS[name], body: SKILLS[name] }))];+}+export function readSkill(name: string): string | undefined {return Object.hasOwn(SKILLS, name) ? SKILLS[name] : undefined;}