Open source CapCut alternative.
TypeScript
feat(chatgpt): edit, import, undo and export projects through MCP
David Le19916cbe1e21
diff --git a/site/package-lock.json b/site/package-lock.jsonindex 6afad1d3..caac2ac1 100644--- a/site/package-lock.json+++ b/site/package-lock.json@@ -33,8 +33,10 @@"@mdxeditor/editor": "^4.2.4","@mediabunny/server": "^1.55.1","@mediapipe/tasks-vision": "^1.0.1",+ "@modelcontextprotocol/client": "^2.0.0",+ "@modelcontextprotocol/core": "^2.0.0","@modelcontextprotocol/ext-apps": "^2.0.0",- "@modelcontextprotocol/sdk": "^1.30.0",+ "@modelcontextprotocol/server": "^2.0.0","@next/mdx": "^16.3.4","@posthog/react": "^1.10.3","@prisma/adapter-pg": "^7.8.0",@@ -4669,7 +4671,6 @@"resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.0.0.tgz","integrity": "sha512-8f1OghQ2rjzIOfqgUCP+8GiUWqRs89njoWLNqAe8kWmDePv3s1fZXseej+QXemssEuuOvLLmLO/kqM3IQHtISw==","license": "MIT",- "peer": true,"dependencies": {"@modelcontextprotocol/core": "2.0.0","cross-spawn": "^7.0.5",@@ -4688,7 +4689,6 @@"resolved": "https://registry.npmjs.org/@modelcontextprotocol/core/-/core-2.0.0.tgz","integrity": "sha512-pJCEwGG7Lfr/+PQp9ZTwKXNeO5wzbfKL7H3MYpCorM4oFBoQrdjnBgEoqG+RjhsvS1FKrDbKux+M1HhlnGWqcA==","license": "MIT",- "peer": true,"dependencies": {"zod": "^4.2.0"},@@ -4792,6 +4792,19 @@"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==","license": "MIT"},+ "node_modules/@modelcontextprotocol/server": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/@modelcontextprotocol/server/-/server-2.0.0.tgz",+ "integrity": "sha512-YhHWdHfpFMQfd0prsEnxKeS3Qz3ytIGmsS0sth4KDjnacIT7hxk6hXHkJ9KysxlkvTM+WZAtQbbcUhdoP4Hvtw==",+ "license": "MIT",+ "dependencies": {+ "@modelcontextprotocol/core": "2.0.0",+ "zod": "^4.2.0"+ },+ "engines": {+ "node": ">=20"+ }+ },"node_modules/@mswjs/interceptors": {"version": "0.41.9","resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.41.9.tgz",diff --git a/site/package.json b/site/package.jsonindex 9040af98..f7884f83 100644--- a/site/package.json+++ b/site/package.json@@ -22,6 +22,7 @@"worker:build": "bun build --target=node --minify --external=pg-native --external=skia-canvas --external=mediabunny --external=@mediabunny/server --external=node-web-audio-api --loader .css:text src/cut/worker/main.ts --outfile dist/cut-worker/main.js","bench:watch": "bun run scripts/bench-watch.ts","eval:cut-chat": "bun run scripts/eval-cut-chat.ts",+ "eval:chatgpt-workflow": "bun run scripts/eval-chatgpt-workflow.ts","eval:cut-headless": "bun run scripts/eval-cut-headless.ts","email:dev": "email dev --dir src/emails --port 3001","test": "bun test src packages/effects-kit/src packages/abexp/src scripts/lib/cut-eval",@@ -52,6 +53,7 @@"@better-auth/kysely-adapter": "1.6.11","@better-auth/utils": "0.4.0","@donkeycut/abexp": "*",+ "@donkeycut/artifact-player": "*","@donkeycut/effects-kit": "*","@earendil-works/pi-agent-core": "0.84.1","@earendil-works/pi-ai": "0.84.1",@@ -62,8 +64,10 @@"@mdxeditor/editor": "^4.2.4","@mediabunny/server": "^1.55.1","@mediapipe/tasks-vision": "^1.0.1",+ "@modelcontextprotocol/client": "^2.0.0",+ "@modelcontextprotocol/core": "^2.0.0","@modelcontextprotocol/ext-apps": "^2.0.0",- "@modelcontextprotocol/sdk": "^1.30.0",+ "@modelcontextprotocol/server": "^2.0.0","@next/mdx": "^16.3.4","@posthog/react": "^1.10.3","@prisma/adapter-pg": "^7.8.0",@@ -107,8 +111,7 @@"tailwind-merge": "^3.6.0","tw-animate-css": "^1.4.0","zod": "^4.4.3",- "zustand": "^5.0.5",- "@donkeycut/artifact-player": "*"+ "zustand": "^5.0.5"},"devDependencies": {"@cloudflare/containers": "^0.3.7",diff --git a/site/public/chatgpt-app-icon.png b/site/public/chatgpt-app-icon.pngnew file mode 100644index 00000000..5568fec4Binary files /dev/null and b/site/public/chatgpt-app-icon.png differdiff --git a/site/public/chatgpt-app-icon.svg b/site/public/chatgpt-app-icon.svgnew file mode 100644index 00000000..203e6878--- /dev/null+++ b/site/public/chatgpt-app-icon.svg@@ -0,0 +1,8 @@+<svg width="256" height="256" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">+<rect width="1024" height="1024" fill="#ffffff"/>+<g transform="translate(221.43 162.00) scale(2.2013)">+<path d="M57.2844 0.297878C55.9944 0.874583 54.325 3.19656 53.0957 6.12561C52.3065 7.99232 52.352 7.93161 51.5932 8.17443C50.5157 8.53867 49.7113 9.47961 49.2712 10.8758C48.9222 11.9989 48.4062 14.3057 48.133 16.0207C48.0419 16.567 47.9509 16.7643 47.7839 16.7188C47.6625 16.6884 47.4652 16.6429 47.3286 16.5974C47.0403 16.5215 46.7216 18.2516 45.902 24.4436C45.5985 26.6593 44.9156 31.5765 44.3844 35.3858C42.7453 46.8895 42.4873 49.7579 42.4873 56.5266C42.4873 64.6611 43.1703 71.4298 44.6272 77.7888C45.4619 81.4007 45.6896 82.2962 46.2208 84.0718C48.74 92.4492 52.3369 100.72 56.48 107.61C61.0633 115.244 66.1171 120.601 72.5367 124.623C77.0745 127.461 80.6864 130.739 82.8111 133.972C84.1922 136.066 84.8448 137.493 85.376 139.602C85.8161 141.317 85.8313 141.94 85.4518 142.744C84.8751 143.973 83.3727 144.929 81.0355 145.521C80.4133 145.688 79.8821 145.885 79.8669 145.961C79.7759 146.219 81.4756 147.949 82.4469 148.587C83.4789 149.255 85.0117 149.801 86.3321 149.938C86.924 149.998 87.1971 150.104 87.2275 150.256C87.2427 150.393 86.8784 150.894 86.3928 151.379C84.8144 152.988 82.7049 153.686 79.8062 153.565C77.8181 153.489 77.8333 153.458 78.7894 155.31C79.9124 157.465 81.8854 159.241 83.8887 159.908C84.4502 160.106 84.9207 160.349 84.951 160.47C85.0117 160.743 83.5093 162.655 82.7656 163.247C81.3694 164.355 79.275 165.281 78.1672 165.281C77.3628 165.281 77.5753 165.767 78.9563 167.148C80.2463 168.438 81.6577 169.318 82.9781 169.667C83.3271 169.773 83.6155 169.94 83.6155 170.061C83.6155 170.168 83.2209 170.608 82.7504 171.018C81.9157 171.761 81.8854 171.792 82.1434 172.08C82.6138 172.611 82.4773 173.233 81.7336 173.84C80.9444 174.493 80.6561 174.508 79.9731 174.007C79.3661 173.567 79.1992 173.552 78.5617 173.886C77.6056 174.372 75.9969 174.69 74.4034 174.69C72.5367 174.69 72.5671 174.645 73.4776 176.42C74.7221 178.788 77.0137 180.639 79.2902 181.095C79.791 181.201 80.2463 181.353 80.2919 181.413C80.3526 181.489 80.3374 181.778 80.2615 182.036C80.2008 182.294 79.958 183.523 79.7455 184.783C78.3948 192.69 76.7102 198.062 75.0408 199.777C73.083 201.795 69.0158 202.099 65.6314 200.49C65.1002 200.232 64.5994 200.035 64.5084 200.035C64.2352 200.035 64.3111 201.613 64.6601 203.085C64.8422 203.875 65.2672 205.028 65.6921 205.878C66.1019 206.667 66.3751 207.365 66.3144 207.396C66.1171 207.517 63.6281 206.743 62.7024 206.272C61.7007 205.772 59.6215 204.254 58.969 203.541C58.711 203.283 58.4378 203.07 58.3467 203.07C58.2253 203.07 58.0887 203.601 57.9673 204.436C57.7093 206.257 57.8459 209.293 58.2557 210.856C58.6047 212.206 59.5305 214.24 60.259 215.302C61.5186 217.154 63.8558 219.157 65.5859 219.901C66.2537 220.189 66.5724 220.462 66.4206 220.614C66.3447 220.69 65.7832 220.599 63.5826 220.189C60.9571 219.704 58.544 218.611 56.5559 217.002C55.964 216.532 55.8578 216.759 56.0096 218.171C56.5407 222.936 59.3635 226.897 63.4308 228.582C63.8861 228.764 64.3262 228.976 64.4021 229.052C64.8119 229.401 61.9587 231.496 60.3804 232.042C59.1511 232.452 58.4378 232.437 57.163 231.981C55.7667 231.496 54.6285 230.798 53.4751 229.735C52.9439 229.25 52.4583 228.885 52.3824 228.931C52.1396 229.067 52.0333 231.314 52.2003 232.573C52.2761 233.241 52.3065 233.833 52.2306 233.909C52.0789 234.061 50.03 233.545 48.8463 233.044C47.8295 232.604 45.8262 231.526 44.8852 230.889C44.0505 230.327 43.9443 230.494 44.0505 232.194C44.2782 235.973 46.2359 239.463 49.4989 241.922C50.9862 243.045 51.8816 243.515 53.5661 244.062C54.2794 244.289 54.8561 244.563 54.8561 244.669C54.8561 244.881 53.1867 245.473 51.6539 245.792C48.0571 246.536 45.0522 246.141 41.7589 244.487C40.9545 244.077 40.2412 243.804 40.1805 243.864C39.9832 244.062 40.4385 246.141 40.9394 247.416C41.7437 249.495 43.2613 251.407 45.1281 252.682C45.4619 252.91 46.3118 253.395 47.0099 253.76C47.6929 254.124 48.2544 254.473 48.2544 254.549C48.2544 254.746 45.4316 256.795 44.0809 257.584C42.9882 258.206 41.0001 259.011 39.1485 259.557C38.7691 259.663 38.4656 259.815 38.4656 259.906C38.4656 260.452 42.5481 262.698 43.5649 262.714C43.6863 262.714 43.9139 262.805 44.0505 262.911C44.2933 263.078 44.263 263.23 43.6408 264.838C42.6846 267.388 40.6965 271.698 39.2396 274.415C35.142 282.064 30.1641 288.483 22.7428 295.722C18.2809 300.078 14.1226 303.493 6.71649 308.911C4.56144 310.504 2.16356 312.25 1.38956 312.826C0.0236811 313.843 -0.35573 314.298 0.342386 314.101C0.888738 313.949 7.18696 312.69 9.4179 312.28C31.7728 308.182 57.254 307.105 86.4231 309.002C91.0975 309.32 93.723 309.503 96.5155 309.761C97.3957 309.836 98.9589 309.973 100.006 310.064C106.319 310.626 114.272 311.506 120.798 312.356L124.364 312.826L124.698 312.401C124.88 312.158 126.003 310.702 127.187 309.154C130.754 304.54 134.29 301.186 137.34 299.577C140.982 297.635 145.171 297.134 148.54 298.211C151.758 299.258 153.761 300.336 155.248 301.854C156.462 303.068 158.223 304.145 159.027 304.145C159.649 304.145 159.923 304.418 160.454 305.663C161.805 308.729 164.445 311.825 167.42 313.828C171.548 316.62 177.558 317.683 182.991 316.59C186.709 315.846 189.547 314.587 195.375 311.066C201.4 307.439 203.813 306.209 212.767 302.248C219.308 299.365 221.873 297.862 224.514 295.343C226.836 293.142 228.338 290.684 229.112 287.815C229.461 286.541 229.522 286.009 229.507 284.264C229.507 281.957 229.355 280.971 228.672 278.922C227.534 275.477 225.485 272.427 222.313 269.422L221.129 268.299L221.812 266.842C222.434 265.521 224.271 261.196 225.212 258.889C225.409 258.419 225.637 257.994 225.728 257.963C225.834 257.918 226.456 258.237 227.109 258.646C230.478 260.741 232.709 261.53 235.304 261.545C239.614 261.575 243.029 259.436 245.093 255.414C246.322 253.031 246.959 250.83 247.369 247.613C247.885 243.606 248.234 242.741 250.192 240.556C251.103 239.539 251.664 238.75 252.089 237.87C252.423 237.202 252.802 236.595 252.924 236.549C253.06 236.504 253.592 236.458 254.123 236.458C256.718 236.458 259.829 235.108 261.316 233.317C261.999 232.513 262.925 230.494 263.153 229.371C263.426 228.005 263.274 225.015 262.849 223.558C262.409 222.086 261.013 218.99 260.117 217.503C259.237 216.046 259.055 215.53 259.07 214.468C259.085 212.586 259.389 211.539 260.391 210.021C262.455 206.88 263.153 204.755 263.153 201.553C263.153 197.561 261.407 195.027 258.691 195.027C258.175 195.027 257.371 195.087 256.9 195.178C255.914 195.33 254.821 195.118 253.698 194.556C253 194.192 251.634 192.856 250.966 191.885C250.374 191.035 249.464 188.88 248.507 186.073C246.944 181.535 246.292 180.093 244.744 177.832C243.621 176.178 242.968 175.616 241.147 174.721C239.811 174.053 239.705 173.962 239.584 173.446C239.447 172.884 239.174 172.596 237.414 171.124C236.336 170.228 235.395 168.164 233.71 162.944C232.936 160.516 232.542 159.65 231.722 158.421C230.098 155.993 228.52 154.718 226.38 154.096C225.712 153.899 224.832 153.519 224.422 153.261C224.013 152.988 222.844 152.381 221.827 151.926L219.976 151.076L219.794 149.27C219.429 145.476 218.2 142.607 215.939 140.179C214.391 138.525 212.949 137.569 210.946 136.901C210.141 136.643 209.398 136.552 207 136.461C202.159 136.248 201.127 135.823 197.515 132.515C195.951 131.088 195.102 130.633 192.582 129.905C190.67 129.358 188.561 128.357 186.997 127.249C186.436 126.839 184.994 125.549 183.78 124.38C179.91 120.601 178.863 120.177 172.716 119.752C168.057 119.433 165.143 118.325 162.229 115.791C159.437 113.332 158.329 112.649 155.916 111.814C153.609 111.01 152.972 110.631 151.287 109.037C149.345 107.201 148.555 106.806 146.749 106.73C146.036 106.7 144.701 106.776 143.775 106.912C141.787 107.186 141.149 107.11 138.706 106.32C134.821 105.076 132.726 105.288 128.507 107.398C127.612 107.838 126.61 108.384 126.261 108.597C125.927 108.809 125.502 108.976 125.305 108.976C124.926 108.976 122.24 107.535 120.783 106.533C119.371 105.577 117.671 103.892 116.837 102.617C116.427 101.98 115.425 100.174 114.621 98.5805C112.952 95.272 110.979 91.918 109.689 90.2031C108.156 88.1694 106.244 86.1358 101.524 81.5222C93.981 74.1616 91.4465 70.9745 88.4113 65.0557C87.1364 62.5668 86.499 60.7304 86.0589 58.1353C85.7098 56.1623 85.1787 54.4777 84.5716 53.4457C84.3591 53.0663 83.5548 52.1254 82.8263 51.3514L81.4604 49.9552L81.339 47.709C81.1114 44.0515 80.5499 42.6401 78.5314 40.6065C77.5146 39.5897 77.1352 39.0888 76.6647 38.072C75.4354 35.5224 73.5232 29.558 71.7931 22.9563C69.7746 15.2922 68.0748 10.0563 66.6482 7.21833C65.1002 4.12234 62.7479 1.40574 60.775 0.464797C59.6215 -0.0815551 58.2708 -0.157415 57.2844 0.297878ZM131.573 117.915C135.64 118.613 140.239 120.632 142.439 122.665C143.502 123.637 144.412 125.018 145.262 126.915C146.173 128.964 146.567 129.54 148.206 131.346C148.905 132.105 149.481 132.788 149.481 132.864C149.481 132.925 149.254 133.304 148.965 133.699C148.07 134.943 146.856 136.931 146.067 138.479C145.217 140.164 145.323 140.088 143.335 140.376C142.667 140.483 141.377 140.756 140.451 141.014C135.822 142.228 133.349 143.837 128.022 149.027C126.261 150.742 124.334 152.533 123.757 153.003C120.434 155.674 116.837 157.495 110.554 159.666C107.7 160.652 105.014 161.806 100.871 163.824C99.0499 164.704 97.5323 165.433 97.5019 165.433C97.3046 165.433 97.5171 164.856 98.3973 162.913C100.37 158.603 101.493 155.356 101.903 152.76C102.085 151.698 102.116 150.12 102.085 145.931C102.055 139.83 102.146 138.859 103.117 135.323C104.665 129.692 108.034 124.881 112.527 121.907C115.805 119.736 119.386 118.34 123.302 117.688C125.017 117.399 129.327 117.521 131.573 117.915ZM212.281 153.428C214.345 153.883 216.242 154.566 218.23 155.568C220.477 156.706 221.903 157.708 223.724 159.484C225.955 161.654 227.018 163.323 228.11 166.374C228.915 168.605 229.416 169.561 230.736 171.306C231.904 172.854 234.181 175.161 235.577 176.178C236.002 176.511 237.292 177.301 238.415 177.953C241.435 179.699 242.862 180.67 243.605 181.505C244.577 182.597 245.639 184.479 246.565 186.786C248.553 191.749 249.858 193.904 251.831 195.467C253.774 197.015 255.261 197.379 257.765 196.939L259.131 196.696L259.617 197.242C260.33 198.047 260.391 198.608 259.905 199.944C258.964 202.524 256.384 205.18 254.821 205.195C254.411 205.195 253.273 204.649 252.256 203.95C251.861 203.692 250.526 202.478 249.297 201.264C246.808 198.806 246.823 198.821 246.201 200.05C245.229 201.978 245.366 205.787 246.489 208.003C247.142 209.308 248.158 210.689 248.993 211.402C250.541 212.738 252.681 213.466 254.047 213.117C254.791 212.935 254.851 213.011 255.185 214.316C255.428 215.272 255.428 215.348 255.17 215.834C254.988 216.152 254.866 216.835 254.806 217.64C254.73 218.839 254.669 218.99 254.092 219.855C253.743 220.356 253.045 221.161 252.529 221.631C251.649 222.451 249.782 223.558 249.281 223.558C249.13 223.558 248.993 223.316 248.887 222.906C248.052 219.43 246.671 216.35 243.879 211.721C240.494 206.075 239.766 204.74 238.81 202.433C237.247 198.608 235.881 192.856 235.608 188.804C235.562 188.015 235.486 187.256 235.456 187.135C235.41 187.014 235.441 186.816 235.516 186.695C235.623 186.528 235.866 186.528 237.064 186.74C239.538 187.15 241.799 187.439 241.891 187.347C242.027 187.211 240.373 185.739 239.174 184.934C237.929 184.1 235.122 182.688 232.269 181.444C229.947 180.427 229.006 180.063 224.453 178.484C222.571 177.832 220.461 177.073 219.748 176.815C218.352 176.314 217.578 176.284 216.713 176.739C216.106 177.058 215.863 177.589 215.666 178.97C215.453 180.548 215.013 181.611 214.103 182.825C212.16 185.435 203.889 192.796 199.943 195.436C197.439 197.121 194.798 198.32 192.051 199.048C189.972 199.61 187.179 199.64 185.374 199.14C182.49 198.335 179.121 196.256 175.463 193.008C174.173 191.855 174.128 191.976 174.902 194.374C176.404 198.927 179.804 202.812 184.235 205.043C187.164 206.515 189.046 207.001 192.355 207.122C196.225 207.274 200.58 206.272 204.906 204.224C206.165 203.632 206.347 203.692 205.74 204.497C204.89 205.62 202.326 209.976 201.43 211.797C199.882 214.969 199.366 216.972 199.351 219.992C199.336 222.117 199.488 222.951 200.186 224.666C200.884 226.412 201.552 227.368 203.221 229.052C204.83 230.661 204.83 230.661 207.47 231.966C210.232 233.317 211.325 234.106 212.145 235.29C212.858 236.352 212.995 236.944 212.767 238.158L212.57 239.205L213.055 240.177C213.662 241.36 213.617 241.74 212.752 242.559C211.614 243.637 210.445 243.546 207.334 242.134C206.105 241.588 204.632 240.966 204.041 240.753C203.464 240.541 202.538 240.146 201.992 239.873C201.005 239.372 200.444 239.038 194.783 235.548C192.097 233.894 186.572 230.6 184.463 229.401C184.053 229.174 181.686 227.777 179.227 226.305C167.556 219.37 162.821 216.759 160.408 215.97C158.42 215.302 156.129 215.409 154.034 216.259C152.319 216.957 151.363 217.609 149.876 219.081C146.309 222.602 144.336 227.064 143.304 233.954C142.895 236.716 142.94 243.576 143.395 247.461C144.458 256.719 146.583 265.005 149.421 271.137C151.029 274.582 153.791 279.028 154.231 278.861C154.717 278.679 156.235 275.28 156.978 272.715C157.176 272.017 157.403 271.425 157.479 271.41C157.555 271.379 157.995 272.169 158.45 273.14C159.589 275.644 162.321 280.364 163.793 282.428C167.283 287.284 171.275 291.245 176.222 294.751C177.831 295.904 178.15 296.178 177.983 296.345C177.345 296.967 167.465 301.869 166.843 301.869C166.312 301.869 164.87 300.806 162.654 298.773C161.516 297.726 160.53 296.861 160.484 296.861C160.165 296.861 160.955 299.759 161.865 301.914C162.427 303.265 162.396 303.386 161.501 303.386C160.196 303.386 157.889 302.112 156.569 300.64C155.339 299.289 154.778 298.044 153.579 294.129C152.987 292.171 152.259 289.773 151.955 288.817C150.422 283.763 148.829 280.151 144.989 272.958C143.016 269.27 141.119 265.081 140.208 262.41C139.161 259.375 138.129 255.824 137.704 253.835C137.507 252.925 137.173 251.407 136.961 250.497C136.46 248.311 135.595 243.303 135.261 240.632C134.897 237.673 134.897 231.921 135.261 229.401C136.005 224.393 137.674 219.734 140.133 215.849C141.483 213.709 142.652 212.328 144.716 210.4C147.797 207.502 148.768 205.893 149.132 203.025C149.466 200.293 150.073 198.745 151.53 196.848C152.866 195.103 154.338 193.873 158.041 191.339C160.469 189.669 163.231 186.407 164.506 183.705C165.963 180.594 166.858 178.909 167.526 178.029C168.998 176.087 175.22 170.168 179.379 166.783C189.061 158.907 197.651 154.217 204.283 153.216C206.363 152.912 210.43 153.003 212.281 153.428ZM61.2454 206.971C63.2487 208.321 65.8742 209.277 68.2873 209.52C69.122 209.611 69.3496 209.702 69.8808 210.173C70.2299 210.476 70.7003 210.886 70.928 211.083C71.4743 211.539 71.3074 211.751 70.0629 212.161C68.6819 212.631 67.058 212.722 65.8742 212.419C63.2487 211.751 61.7766 210.537 60.5473 208.048C60.1375 207.183 59.7885 206.439 59.7885 206.379C59.7885 206.106 60.2741 206.303 61.2454 206.971ZM62.4444 221.221C65.0699 221.95 64.8726 221.874 64.6905 222.056C64.5842 222.162 63.9165 222.208 62.7934 222.162C61.4124 222.117 60.9267 222.026 60.2741 221.752C59.4394 221.373 58.4226 220.371 58.4226 219.901C58.4226 219.673 58.5744 219.719 59.4546 220.159C60.0161 220.432 61.3668 220.918 62.4444 221.221ZM185.495 237.323C186.436 237.794 187.513 238.78 187.893 239.524C188.075 239.888 188.181 240.404 188.181 240.996C188.181 241.74 188.09 242.058 187.65 242.863C187.346 243.379 186.269 245.534 185.237 247.628C184.19 249.707 183.249 251.513 183.112 251.62C182.915 251.787 182.702 251.696 181.731 251.043C179.986 249.859 179.925 249.965 181.23 251.893C184.827 257.235 188.894 261.53 194.024 265.445C196.103 267.024 196.483 267.464 197.302 269.179C198.41 271.516 198.198 272.912 196.559 273.823C195.451 274.46 194.403 274.445 192.84 273.792C190.503 272.821 189.198 271.713 187.407 269.194C186.815 268.39 186.269 267.722 186.163 267.707C186.056 267.707 185.131 267.707 184.099 267.722C182.384 267.737 182.156 267.707 181.443 267.358C180.32 266.811 178.286 265.142 177.482 264.125C176.404 262.759 175.919 261.166 176.389 260.543C176.571 260.285 176.617 260.285 177.284 260.543C177.679 260.68 178.043 260.756 178.089 260.71C178.15 260.665 177.937 260.285 177.618 259.876C176.996 259.071 175.782 256.628 175.312 255.201C175.145 254.7 174.826 253.532 174.598 252.621C174.386 251.696 174.037 250.709 173.839 250.39C173.339 249.632 172.094 249.055 170.956 249.055C169.833 249.055 169.605 248.918 169.241 247.962C169.074 247.522 168.588 246.262 168.163 245.17C167.389 243.166 167.192 242.104 167.587 241.816C167.678 241.74 168.573 241.421 169.575 241.102C171.7 240.404 172.216 240.435 173.855 241.239C175.205 241.892 176.48 243.212 176.92 244.38C177.087 244.821 177.284 245.2 177.376 245.23C177.467 245.261 178.119 244.092 178.817 242.65C180.805 238.583 181.67 237.415 183.021 236.99C183.841 236.747 184.524 236.838 185.495 237.323ZM163.99 241.618L166.084 243.728L166.433 245.291C166.615 246.141 166.919 247.249 167.086 247.765C167.238 248.266 167.541 249.313 167.754 250.102C168.194 251.771 168.376 252.014 168.968 251.787C170.045 251.377 171.548 251.832 172.109 252.743C172.701 253.714 173.187 255.581 173.217 256.962C173.232 258.115 173.187 258.373 172.792 259.193L172.352 260.118L173.081 261.302C174.492 263.579 175.949 265.385 178.225 267.646C181.352 270.772 182.687 271.804 186.739 274.248C194.98 279.226 203.236 281.563 209.732 280.774C213.966 280.258 217.335 278.285 218.686 275.568C218.959 275.007 219.262 274.551 219.354 274.551C219.46 274.551 219.778 275.007 220.052 275.568C220.492 276.448 220.568 276.767 220.583 277.662C220.583 279.074 220.158 279.924 218.762 281.305C216.637 283.429 213.162 284.689 208.563 285.023C206.681 285.144 203.358 285.038 201.885 284.795C195.845 283.779 190.655 282.064 185.859 279.468C180.441 276.524 176.693 273.519 173.141 269.239C168.922 264.155 165.69 258.358 163.61 252.166C162.32 248.281 161.759 245.549 161.638 242.301C161.531 239.691 161.546 239.494 161.759 239.494C161.835 239.494 162.836 240.45 163.99 241.618ZM195.299 241.709C196.316 242.225 198.152 243.925 198.516 244.73C198.698 245.109 198.805 245.701 198.805 246.278C198.805 247.158 198.714 247.416 197.302 250.375C192.992 259.451 192.855 259.678 191.672 259.678C190.989 259.678 190.306 259.253 188.014 257.387C185.677 255.49 184.903 254.685 184.706 253.987C184.326 252.576 184.357 252.47 186.937 248.129C189.638 243.561 190.367 242.529 191.338 241.967C192.886 241.057 193.827 240.996 195.299 241.709ZM206.211 247.401C208.032 248.235 209.428 250.041 209.428 251.589C209.428 252.348 208.366 255.08 206.438 259.284C203.585 265.506 203.525 265.612 202.326 265.87C201.278 266.113 200.732 265.916 197.515 264.171C195.223 262.926 194.813 262.562 194.57 261.682C194.252 260.574 194.358 259.86 194.935 259.056C195.223 258.646 196.528 256.415 197.833 254.093C201.172 248.175 201.582 247.643 203.282 247.052C204.223 246.718 204.921 246.809 206.211 247.401ZM216.227 253.016C217.881 253.835 218.595 255.05 218.58 257.022C218.564 258.115 218.458 258.586 217.472 261.575C215.347 268.025 214.679 269.3 213.253 269.68C211.947 270.044 206.787 268.708 205.938 267.798C205.649 267.494 205.558 267.191 205.513 266.432C205.452 265.506 205.482 265.385 206.059 264.429C206.393 263.852 207.106 262.501 207.653 261.424C208.7 259.314 210.824 255.399 211.462 254.382C212.615 252.576 214.345 252.075 216.227 253.016Z" fill="#051020"/>+<path d="M125.639 125.291C119.872 126.126 113.528 130.406 109.765 135.991C108.019 138.571 106.896 141.575 106.365 145.096C106.061 147.1 106.046 147.479 106.198 149.315C106.471 152.533 107.018 153.337 108.93 153.322C110.554 153.322 112.253 152.654 114.727 151.046C116.123 150.15 117.14 149.3 119.508 147.085C123.56 143.29 127.991 139.967 131.543 138.039C136.02 135.626 136.338 135.384 137.128 133.836C137.674 132.758 137.598 131.544 136.93 130.724C136.384 130.026 135.838 129.753 134.927 129.662C133.425 129.51 132.954 129.192 132.241 127.78C131.467 126.232 130.435 125.549 128.386 125.215C127.248 125.048 127.339 125.033 125.639 125.291ZM123.317 130.284C125.852 130.74 128.234 132.242 129.676 134.321L130.071 134.898L129.706 135.49C129.494 135.808 129.251 136.324 129.145 136.628C129.054 136.947 128.917 137.205 128.841 137.205C128.781 137.205 128.523 136.886 128.295 136.476C127.627 135.323 126.368 133.684 125.609 133.001C123.241 130.831 119.766 130.573 116.048 132.303C114.287 133.137 114.242 132.652 116.002 131.68C117.201 131.013 118.476 130.573 119.887 130.315C121.405 130.041 121.86 130.026 123.317 130.284ZM123.605 134.776C125.062 135.156 126.732 135.9 127.187 136.385C127.627 136.856 127.415 136.84 126.049 136.309C124.304 135.611 123.241 135.384 121.663 135.384C119.66 135.384 117.869 135.96 116.199 137.159C115.274 137.812 115.091 137.69 115.881 136.962C117.11 135.808 118.536 135.05 120.115 134.701C121.405 134.412 122.255 134.427 123.605 134.776ZM120.449 138.419C121.754 139.208 121.784 141.181 120.525 142.137C119.902 142.607 118.521 142.562 117.99 142.061C117.125 141.257 116.928 140.285 117.444 139.329C118.036 138.191 119.417 137.781 120.449 138.419ZM112.527 143.928C112.527 145.779 112.527 145.81 113.088 146.933C113.422 147.601 113.589 148.117 113.513 148.192C113.346 148.359 111.449 147.919 111.13 147.646C110.963 147.509 110.933 147.282 110.994 146.751C111.191 145.248 112.223 142.061 112.496 142.061C112.527 142.061 112.542 142.896 112.527 143.928Z" fill="#051020"/>+<path d="M183.567 176.754C180.745 177.316 179.197 178.151 178.605 179.471C178.225 180.29 178.256 180.989 178.696 181.945C179.728 184.145 182.414 186.634 185.54 188.228C187.984 189.487 190.139 190.019 192.734 190.019C197.181 190.019 202.037 187.848 205.649 184.252C207.258 182.658 208.199 181.353 208.851 179.85C209.565 178.151 209.307 177.149 208.047 176.815C207.121 176.557 205.664 176.845 200.246 178.333C196.483 179.365 195.83 179.471 193.872 179.456C191.823 179.441 190.67 179.152 189.517 178.378C189.168 178.135 188.561 177.726 188.181 177.468C187.377 176.906 186.087 176.512 185.237 176.527C184.888 176.527 184.144 176.633 183.567 176.754Z" fill="#051020"/>+</g>+</svg>diff --git a/site/scripts/eval-chatgpt-widget.ts b/site/scripts/eval-chatgpt-widget.tsindex 1dfdc158..7fd0c129 100644--- a/site/scripts/eval-chatgpt-widget.ts+++ b/site/scripts/eval-chatgpt-widget.ts@@ -22,7 +22,7 @@ const frame = document.querySelector('iframe');const project = {id:'project',name:'Launch film',revision:'cloud:2',url:'https://donkeycut.com/app/p/project'};let count = 0, renewals = 0;window.calls = []; window.links = [];-const view = (selected, preview = null) => ({view:selected?'project':'projects',projects:selected?[]:[project],nextCursor:null,project:selected?project:null,preview,canRender:true});+const view = (selected, preview = null) => ({view:selected?'project':'projects',projects:selected?[]:[project],nextCursor:null,project:selected?project:null,preview,canRender:true,canEdit:false,export:null,job:null,results:[],changed:false,history:null,account:null});const result = (data, playback = null) => ({content:[{type:'text',text:'Preview'}],structuredContent:data,_meta:{playback,pollMs:1000}});const reply = (id, result) => frame.contentWindow.postMessage({jsonrpc:'2.0',id,result},'*');window.addEventListener('message', ({source,data}) => {diff --git a/site/scripts/eval-chatgpt-workflow.ts b/site/scripts/eval-chatgpt-workflow.tsnew file mode 100644index 00000000..71ce36d1--- /dev/null+++ b/site/scripts/eval-chatgpt-workflow.ts@@ -0,0 +1,180 @@+#!/usr/bin/env bun+/**+ * The ChatGPT editing workflow, end to end: drive the MCP server in process+ * as the dev-bypass account and walk the milestone — create a project, import+ * footage, inspect it, make a vertical cut, preview, undo, redo, export — and+ * assert every step landed in the stored document and the export downloads.+ *+ * Run with the site dev server up and a local worker running:+ * bun run scripts/eval-chatgpt-workflow.ts [--base http://localhost:3000] [--keep]+ * (worker: `npm run worker:build && node dist/cut-worker/main.js` from site/;+ * .env supplies DATABASE_URL and the R2 credentials for both)+ */++import { Client, InMemoryTransport } from "@modelcontextprotocol/client";+import { SETTINGS } from "../src/lib/config/registry";+import { createChatgptServer, SERVER_INSTRUCTIONS } from "../src/clients/chatgpt/server/mcp";+import type { ProjectView } from "../src/clients/chatgpt/contracts";+import { deleteProjectCascade } from "../src/cut/server/cloud/projects";+import { prisma } from "../src/lib/prisma";++const arg = (name: string): string | undefined => {+ const i = process.argv.indexOf(`--${name}`);+ return i >= 0 ? process.argv[i + 1] : undefined;+};+const base = arg("base") ?? "http://localhost:3000";+const keep = process.argv.includes("--keep");+// The user the dev bypass header resolves to (src/lib/donkey-api-auth.ts).+const USER_ID = "donkey-dev-auth-bypass";+const FOOTAGE = `${base}/cut-starter/media/ai-watercolor-and-loose-black-ink-sketch-il.mp4`;++const fail = (msg: string): never => {+ process.exitCode = 1;+ throw new Error(`FAIL ${msg}`);+};+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));++const config = SETTINGS.chatgptApp.schema.parse({ ...SETTINGS.chatgptApp.default, enabled: true, commandWaitMs: 120_000 });+const server = createChatgptServer(+ { userId: USER_ID, scopes: ["projects:read", "previews:render", "projects:write"] },+ config+);+const client = new Client({ name: "eval", version: "1" });+const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();+await server.connect(serverTransport);+await client.connect(clientTransport);++type Called = { view: ProjectView; text: string; images: number; isError?: boolean };+async function call(name: string, args: Record<string, unknown> = {}): Promise<Called> {+ const result = await client.callTool({ name, arguments: args });+ const content = (result.content ?? []) as { type: string; text?: string }[];+ const text = content.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");+ if (result.isError) fail(`${name}: ${text}`);+ return { view: result.structuredContent as ProjectView, text, images: content.filter((c) => c.type === "image").length };+}++/** Poll a job the call handed back until it settles. */+async function settle(first: Called, tool: "get_job_status" | "get_export_status", label: string): Promise<Called> {+ let current = first;+ const deadline = Date.now() + 10 * 60_000;+ for (;;) {+ const job = tool === "get_export_status" ? current.view.export : current.view.job;+ if (!job || (job.status !== "queued" && job.status !== "running")) return current;+ if (Date.now() > deadline) fail(`${label} did not settle in 10 minutes — is the worker running?`);+ console.log(` ${label}: ${job.status} ${Math.round(job.progress * 100)}%`);+ await sleep(2000);+ current = await call(tool, { jobId: job.id });+ }+}++const doc = async (projectId: string) => {+ const row = await prisma.cutProject.findFirst({ where: { id: projectId, userId: USER_ID }, select: { doc: true, version: true } });+ if (!row) fail("project row is gone");+ return { ...(row!.doc as { aspect?: string; clips?: { id: string; in: number; out: number }[]; overlays?: { text?: string }[]; assets?: { id: string }[] }), version: row!.version };+};++let projectId: string | null = null;+try {+ // Instructions and catalog: what ChatGPT reads first.+ if (!SERVER_INSTRUCTIONS.includes("github.com/DonkeyCut/Donkey")) fail("server instructions do not link the repository");+ const index = await call("list_commands");+ const names = (index.view as unknown as { commands: { name: string }[] }).commands.map((c) => c.name);+ for (const need of ["set_aspect", "add_clip", "trim_clip", "add_title", "subtitles_generate", "set_framing"])+ if (!names.includes(need)) fail(`list_commands misses ${need}`);+ console.log(`catalog: ${names.length} commands`);++ const created = await call("create_project", { name: `chatgpt-workflow-${Date.now()}`, aspect: "16:9" });+ projectId = created.view.project?.id ?? fail("create_project returned no project");+ console.log(`created ${projectId}`);++ const imported = await settle(await call("import_media", { projectId, urls: [FOOTAGE] }), "get_job_status", "import");+ const importAssets = imported.view.results.flatMap((r) => ((r.output as { assets?: { assetId: string; name: string; duration: number }[] })?.assets ?? []));+ if (!importAssets.length) fail(`import landed no asset: ${imported.text}`);+ const asset = importAssets[0];+ console.log(`imported asset ${asset.assetId} "${asset.name}" (${asset.duration}s)`);+ if (imported.view.history?.undo !== `Imported ${asset.name}`) fail(`import is not on the undo history: ${JSON.stringify(imported.view.history)}`);++ const inspected = await call("inspect_project", { projectId });+ const state = inspected.view.results[0]?.output as { media?: unknown[] } | undefined;+ if (!state || !Array.isArray(state.media) || state.media.length !== 1) fail(`inspect_project state has no media list: ${inspected.text.slice(0, 200)}`);+ console.log("inspected: state carries the footage");++ const before = await doc(projectId);+ const placed = await settle(+ await call("edit_project", {+ projectId,+ label: "Vertical frame with the footage",+ commands: [+ { name: "set_aspect", input: { aspect: "9:16" } },+ { name: "add_clip", input: { asset_id: asset.assetId } },+ ],+ }),+ "get_job_status",+ "edit"+ );+ if (placed.view.results.some((r) => !r.ok)) fail(`the first batch failed: ${placed.text}`);+ const clipId = (placed.view.results[1].output as { id?: string })?.id ?? fail("add_clip returned no clip id");+ const after = await doc(projectId);+ if (after.aspect !== "9:16") fail(`aspect did not save: ${after.aspect}`);+ if (!(after.clips?.length === 1)) fail(`clip did not save: ${JSON.stringify(after.clips)}`);+ if (after.version <= before.version) fail("the edit did not bump the version");+ if (placed.view.history?.undo !== "Vertical frame with the footage") fail(`history missing the step: ${JSON.stringify(placed.view.history)}`);++ // A batch stops at its first failure and reports how far it got.+ const broken = await settle(+ await call("edit_project", {+ projectId,+ commands: [{ name: "trim_clip", input: { clipId: "no-such-clip", out: 1 } }, { name: "set_background", input: { color: "#ff0000" } }],+ }),+ "get_job_status",+ "broken edit"+ );+ if (broken.view.results.length !== 1 || broken.view.results[0].ok || broken.view.changed) fail(`a failed batch should stop and save nothing: ${broken.text}`);++ const finished = await settle(+ await call("edit_project", {+ projectId,+ label: "Trim and title",+ commands: [+ { name: "trim_clip", input: { clipId, in: 0, out: Math.min(3, asset.duration) } },+ { name: "add_title", input: { text: "MADE IN CHATGPT", start: 0, end: 2 } },+ { name: "capture_frame", input: { t: 0.5 } },+ ],+ }),+ "get_job_status",+ "edit 2"+ );+ if (finished.view.results.some((r) => !r.ok)) fail(`second batch failed: ${finished.text}`);+ if (finished.images < 1) fail("capture_frame returned no image block");+ const titled = await doc(projectId);+ if (!(titled.overlays ?? []).some((o) => o.text === "MADE IN CHATGPT")) fail("the title did not save");+ if (!(titled.clips![0].out - titled.clips![0].in <= 3.001)) fail("the trim did not save");+ console.log("edited: aspect, clip, trim, title and a captured frame");++ const undone = await call("undo", { projectId });+ const reverted = await doc(projectId);+ if ((reverted.overlays ?? []).some((o) => o.text === "MADE IN CHATGPT")) fail("undo left the title in place");+ if (undone.view.history?.redo !== "Trim and title") fail(`redo not offered: ${JSON.stringify(undone.view.history)}`);+ const redone = await call("redo", { projectId });+ const restored = await doc(projectId);+ if (!(restored.overlays ?? []).some((o) => o.text === "MADE IN CHATGPT")) fail("redo did not bring the title back");+ if (redone.view.history?.undo !== "Trim and title") fail(`undo not offered after redo: ${JSON.stringify(redone.view.history)}`);+ console.log("undo and redo walk the history");++ const previewed = await call("render_preview", { projectId });+ if (!previewed.view.preview) fail("render_preview queued nothing");+ console.log(`preview ${previewed.view.preview.status}`);++ const exported = await settle(await call("export_video", { projectId, preset: "light" }), "get_export_status", "export");+ if (exported.view.export?.status !== "done") fail(`export ended ${exported.view.export?.status}: ${exported.view.export?.error ?? exported.text}`);+ const meta = (await client.callTool({ name: "get_export_status", arguments: { jobId: exported.view.export.id } }))._meta as { download?: { url: string; name: string } };+ if (!meta.download?.url) fail("no download in the export result metadata");+ const head = await fetch(meta.download.url, { method: "HEAD" });+ if (!head.ok) fail(`the export download answered ${head.status}`);+ console.log(`PASS exported ${meta.download.name} (${head.headers.get("content-length")} bytes)`);+} finally {+ await client.close().catch(() => {});+ await server.close().catch(() => {});+ if (projectId && !keep) await deleteProjectCascade(USER_ID, projectId).catch((e) => console.error("cleanup failed:", e));+ await prisma.$disconnect().catch(() => {});+}diff --git a/site/src/app/api/chatgpt/mcp/route.ts b/site/src/app/api/chatgpt/mcp/route.tsindex 8475f407..9f50f44a 100644--- a/site/src/app/api/chatgpt/mcp/route.ts+++ b/site/src/app/api/chatgpt/mcp/route.ts@@ -1,4 +1,6 @@export { mcpEndpoint as POST } from "@/clients/chatgpt/server/mcp";+// An edit call waits on the worker for up to chatgptApp.commandWaitMs.+export const maxDuration = 300;// The stateless transport has no event stream or session to terminate.export function GET() { return new Response(null, { status: 405, headers: { Allow: "POST" } }); }export const DELETE = GET;diff --git a/site/src/clients/chatgpt/contracts.ts b/site/src/clients/chatgpt/contracts.tsindex e6a5bca3..8ad3a26a 100644--- a/site/src/clients/chatgpt/contracts.ts+++ b/site/src/clients/chatgpt/contracts.ts@@ -2,11 +2,25 @@ import { z } from "zod";export const WIDGET_URI = "ui://donkey/project-preview-v1.html";export const projectSchema = z.object({ id: z.string(), name: z.string(), url: z.url(), revision: z.string() });-export const previewSchema = z.object({ id: z.string(), status: z.enum(["queued", "running", "done", "error", "expired"]), progress: z.number(), revision: z.string().nullable(), error: z.string().optional() });+export const jobStatusSchema = z.enum(["queued", "running", "done", "error", "expired"]);+export const previewSchema = z.object({ id: z.string(), status: jobStatusSchema, progress: z.number(), revision: z.string().nullable(), error: z.string().optional() });+/** A finished export downloads from the widget; the model gets the project link. */+export const exportSchema = z.object({ id: z.string(), status: jobStatusSchema, progress: z.number(), name: z.string().nullable(), error: z.string().optional() });+/** Any queued work the caller may poll with get_job_status. */+export const jobSchema = z.object({ id: z.string(), kind: z.string(), status: jobStatusSchema, progress: z.number(), error: z.string().optional() });+/** One command's outcome inside a batch. */+export const outcomeSchema = z.object({ name: z.string(), ok: z.boolean(), output: z.unknown().optional(), error: z.string().optional() });+/** What undo and redo would each revert, by the step's label. */+export const historySchema = z.object({ undo: z.string().nullable(), redo: z.string().nullable() });+export const accountSchema = z.object({ credits: z.string(), storageBytes: z.number(), storageQuotaBytes: z.number().nullable(), plan: z.string() });export const viewSchema = z.object({view: z.enum(["projects", "project"]), projects: z.array(projectSchema), nextCursor: z.string().nullable(),- project: projectSchema.nullable(), preview: previewSchema.nullable(), canRender: z.boolean(),+ project: projectSchema.nullable(), preview: previewSchema.nullable(), canRender: z.boolean(), canEdit: z.boolean(),+ export: exportSchema.nullable(), job: jobSchema.nullable(), results: z.array(outcomeSchema), changed: z.boolean(),+ history: historySchema.nullable(), account: accountSchema.nullable(),});export const playbackSchema = z.object({ url: z.url(), expiresAt: z.number() });+export const downloadSchema = z.object({ url: z.url(), expiresAt: z.number(), name: z.string() });export type ProjectView = z.infer<typeof viewSchema>;export type Playback = z.infer<typeof playbackSchema>;+export type Download = z.infer<typeof downloadSchema>;diff --git a/site/src/clients/chatgpt/server/catalog.ts b/site/src/clients/chatgpt/server/catalog.tsnew file mode 100644index 00000000..26e68972--- /dev/null+++ b/site/src/clients/chatgpt/server/catalog.ts@@ -0,0 +1,78 @@+import type { AiToolDef } from "@/cut/lib/aiToolDef";+import { AI_SKILL_INDEX, AI_SKILLS, PROJECT_TOOLS } from "@/cut/server/ai/catalog";++// The editing commands ChatGPT can run, drawn from the editor's own tool+// catalog so a command the assistant gains is a command ChatGPT gains. A few+// are left out because ChatGPT reaches the same thing through a first-class+// tool of its own, or because the command needs a page or a running chat.++const HIDDEN = new Set([+ // First-class ChatGPT tools cover these.+ "get_state",+ "undo",+ "redo",+ "render_preview",+ "import_url",+ // Page-local: the editor's clipboard and playback.+ "copy_selection",+ "paste_selection",+ // Long generations settle after the batch ends, so nothing would place them.+ "generate_video",+ "generate_character_video",+ "generate_scene",+ "approve_scene",+ "cancel_scene",+ "regenerate_shot",+ "recut_scene",+ "restyle_scene",+ "wait_for_renders",+]);++export const COMMANDS: AiToolDef[] = PROJECT_TOOLS.filter((tool) => !HIDDEN.has(tool.name));+export const COMMAND_NAMES = COMMANDS.map((tool) => tool.name);++/** What a batch may name: the catalog, plus the state read inspect_project+ * runs by default. */+const KNOWN_COMMANDS = new Set([...COMMAND_NAMES, "get_state"]);+export const unknownCommandNames = (names: string[]): string[] => names.filter((name) => !KNOWN_COMMANDS.has(name));++/** Commands whose output matters and whose effect is on the caller's eyes:+ * a read runs without saving the document. */+export const READ_COMMANDS = new Set([+ "watch_video",+ "capture_frame",+ "listen_audio",+ "detect_silence",+ "detect_beats",+ "measure_level",+ "read_color_stats",+ "stock_search",+ "list_voices",+ "library_list",+ "notes_list",+ "read_project",+]);++/** The first sentence of a description, as the index shows it. */+function summary(description: string): string {+ const first = description.replace(/\s+/g, " ").match(/^(.*?[.!?])(\s|$)/)?.[1] ?? description;+ return first.length > 180 ? `${first.slice(0, 177)}…` : first;+}++export function commandIndex(): { name: string; summary: string; reads?: true }[] {+ return COMMANDS.map((tool) => ({+ name: tool.name,+ summary: summary(tool.description),+ ...(READ_COMMANDS.has(tool.name) ? { reads: true as const } : {}),+ }));+}++export function describeCommands(names: string[]): { found: AiToolDef[]; unknown: string[] } {+ const wanted = new Set(names);+ const found = COMMANDS.filter((tool) => wanted.has(tool.name));+ const known = new Set(found.map((tool) => tool.name));+ return { found, unknown: names.filter((name) => !known.has(name)) };+}++export const SKILL_INDEX = AI_SKILL_INDEX;+export const readSkill = (name: string): string | undefined => AI_SKILLS[name];diff --git a/site/src/clients/chatgpt/server/config.ts b/site/src/clients/chatgpt/server/config.tsindex fc35f5b2..fbdf8446 100644--- a/site/src/clients/chatgpt/server/config.ts+++ b/site/src/clients/chatgpt/server/config.ts@@ -2,7 +2,7 @@ import { prisma } from "@/lib/prisma";import { resolveSettings } from "@/lib/config/resolve";export const CLIENT_ID = "donkey-chatgpt";-export const SCOPES = ["projects:read", "previews:render"] as const;+export const SCOPES = ["projects:read", "previews:render", "projects:write"] as const;export const MCP_PATH = "/api/chatgpt/mcp";export const OAUTH_PATH = "/api/chatgpt/oauth";export const RESOURCE_METADATA_PATH =diff --git a/site/src/clients/chatgpt/server/mcp.test.ts b/site/src/clients/chatgpt/server/mcp.test.tsindex 48a771ad..8927b6e6 100644--- a/site/src/clients/chatgpt/server/mcp.test.ts+++ b/site/src/clients/chatgpt/server/mcp.test.ts@@ -1,11 +1,13 @@import { describe, expect, test } from "bun:test";-import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";-import { Client } from "@modelcontextprotocol/sdk/client/index.js";-import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";+import { Client, InMemoryTransport } from "@modelcontextprotocol/client";import { SETTINGS } from "@/lib/config/registry";-import { createChatgptServer } from "@/clients/chatgpt/server/mcp";+import {+ chatgptHttpHandler,+ createChatgptServer,+} from "@/clients/chatgpt/server/mcp";import { WIDGET_URI } from "@/clients/chatgpt/contracts";-import type { ProjectResult } from "@/clients/chatgpt/server/projects";+import type { projectTools, ProjectResult } from "@/clients/chatgpt/server/projects";+import { unknownCommandNames } from "@/clients/chatgpt/server/catalog";const config = SETTINGS.chatgptApp.schema.parse({...SETTINGS.chatgptApp.default,@@ -30,23 +32,47 @@ const data: ProjectResult = {revision: "cloud:2",},canRender: true,+ canEdit: true,+ export: null,+ job: null,+ results: [],+ changed: false,+ history: null,+ account: null,},playback: {url: "https://media.donkeycut.com/object?private=token",expiresAt: Date.now() + 3600000,},};+type Projects = ReturnType<typeof projectTools>;+/** Every project tool answers with `data` unless overridden. */+const fakeProjects = (overrides: Partial<Projects> = {}): Projects => {+ const answer = async () => data;+ return {+ list: answer,+ status: answer,+ render: answer,+ create: answer,+ inspect: answer,+ edit: answer,+ importMedia: answer,+ undo: answer,+ redo: answer,+ exportVideo: answer,+ exportStatus: answer,+ jobStatus: answer,+ account: answer,+ ...overrides,+ };+};describe("ChatGPT MCP protocol", () => {test("tools validate inputs, expose their safety annotations, and keep signed URLs out of model content", async () => {const server = createChatgptServer({ userId: "owner", scopes: ["projects:read", "previews:render"] },config,- {- list: async () => data,- status: async () => data,- render: async () => data,- },+ fakeProjects(),);const client = new Client({ name: "test", version: "1" });const [serverTransport, clientTransport] =@@ -55,7 +81,35 @@ describe("ChatGPT MCP protocol", () => {await client.connect(clientTransport);try {const { tools } = await client.listTools();- expect(tools).toHaveLength(4);+ expect(tools.map((tool) => tool.name).sort()).toEqual(+ [+ "account_status",+ "create_project",+ "describe_commands",+ "edit_project",+ "export_video",+ "get_export_status",+ "get_job_status",+ "get_preview_status",+ "import_media",+ "inspect_project",+ "list_commands",+ "list_projects",+ "list_skills",+ "open_project",+ "read_skill",+ "redo",+ "render_preview",+ "undo",+ ],+ );+ expect(tools.find((tool) => tool.name === "import_media")?._meta).toMatchObject({+ "openai/fileParams": ["files"],+ });+ expect(tools.find((tool) => tool.name === "edit_project")?.annotations).toMatchObject({+ readOnlyHint: false,+ destructiveHint: false,+ });expect(tools.find((tool) => tool.name === "render_preview")?.annotations,).toMatchObject({@@ -98,13 +152,14 @@ test("render scope requests a reconnect through the MCP authentication challengeconst server = createChatgptServer({ userId: "owner", scopes: ["projects:read"] },config,- {- list: async () => data,- status: async () => data,+ fakeProjects({render: async () => {throw new Error("must not render without scope");},- },+ edit: async () => {+ throw new Error("must not edit without scope");+ },+ }),);const client = new Client({ name: "test", version: "1" });const [serverTransport, clientTransport] =@@ -118,13 +173,123 @@ test("render scope requests a reconnect through the MCP authentication challenge});expect(result.isError).toBe(true);expect(JSON.stringify(result._meta)).toContain("insufficient_scope");+ const edit = await client.callTool({+ name: "edit_project",+ arguments: { projectId: "project", commands: [{ name: "set_aspect", input: { aspect: "9:16" } }] },+ });+ expect(edit.isError).toBe(true);+ expect(JSON.stringify(edit._meta)).toContain("projects:write");} finally {await client.close();await server.close();}});-test("stateless HTTP initializes and serves independent tool requests", async () => {+const projects = fakeProjects();+const http = async (+ message: Record<string, unknown>,+ headers: Record<string, string> = {},+) => {+ const handler = chatgptHttpHandler(+ { userId: "owner", scopes: ["projects:read"] },+ config,+ projects,+ );+ try {+ return await handler.fetch(+ new Request(`${config.issuer}/api/chatgpt/mcp`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ Accept: "application/json, text/event-stream",+ ...headers,+ },+ body: JSON.stringify(message),+ }),+ );+ } finally {+ await handler.close();+ }+};+/** Legacy stateless serving answers over SSE; the final event carries the response. */+const readBody = async (response: Response) => {+ const text = await response.text();+ if (!response.headers.get("content-type")?.includes("text/event-stream")) {+ return JSON.parse(text);+ }+ const events = text+ .split("\n")+ .filter((line) => line.startsWith("data:"))+ .map((line) => JSON.parse(line.slice(5)));+ return events.at(-1);+};+type RpcBody = {+ id?: unknown;+ result: {+ structuredContent?: unknown;+ resources?: { uri: string; mimeType?: string }[];+ contents?: { uri: string; mimeType?: string; text?: string }[];+ };+};+const expectServed = async (body: RpcBody, method: string) => {+ if (method === "tools/call") {+ expect(body.result.structuredContent).toEqual(data.view);+ }+ if (method === "resources/list") {+ expect(+ body.result.resources?.some(+ (resource) =>+ resource.uri === WIDGET_URI &&+ resource.mimeType === "text/html;profile=mcp-app",+ ),+ ).toBe(true);+ }+ if (method === "resources/read") {+ expect(body.result.contents).toHaveLength(1);+ expect(body.result.contents?.[0]).toMatchObject({+ uri: WIDGET_URI,+ mimeType: "text/html;profile=mcp-app",+ });+ expect(body.result.contents?.[0].text).toContain("<!doctype html>");+ expect(body.result.contents?.[0].text).toContain(+ `${config.issuer}/clients/chatgpt/`,+ );+ }+};++test("protocol 2026-07-28 requests are served without a handshake", async () => {+ const meta = {+ "io.modelcontextprotocol/protocolVersion": "2026-07-28",+ "io.modelcontextprotocol/clientInfo": { name: "chatgpt", version: "1" },+ "io.modelcontextprotocol/clientCapabilities": {},+ };+ for (const [method, params, name] of [+ ["tools/list", {}, undefined],+ [+ "tools/call",+ { name: "open_project", arguments: { projectId: "project" } },+ "open_project",+ ],+ ["resources/list", {}, undefined],+ ["resources/read", { uri: WIDGET_URI }, WIDGET_URI],+ ] as const) {+ const response = await http(+ { jsonrpc: "2.0", id: 1, method, params: { ...params, _meta: meta } },+ {+ "MCP-Protocol-Version": "2026-07-28",+ "Mcp-Method": method,+ ...(name ? { "Mcp-Name": name } : {}),+ },+ );+ expect(response.status).toBe(200);+ expect(response.headers.get("content-type")).toContain("application/json");+ const body = await readBody(response);+ expect(body.id).toBe(1);+ await expectServed(body, method);+ }+});++test("2025-era clients still initialize and read tools and widget resources statelessly", async () => {for (const message of [{jsonrpc: "2.0",@@ -142,40 +307,93 @@ test("stateless HTTP initializes and serves independent tool requests", async ()method: "tools/call",params: { name: "open_project", arguments: { projectId: "project" } },},+ { jsonrpc: "2.0", id: 3, method: "resources/list", params: {} },+ {+ jsonrpc: "2.0",+ id: 4,+ method: "resources/read",+ params: { uri: WIDGET_URI },+ },]) {- const server = createChatgptServer(- { userId: "owner", scopes: ["projects:read"] },- config,- {- list: async () => data,- status: async () => data,- render: async () => data,+ const response = await http(message, {+ "MCP-Protocol-Version": "2025-11-25",+ });+ expect(response.status).toBe(200);+ const body = await readBody(response);+ expect(body.id).toBe(message.id);+ await expectServed(body, message.method);+ }+});++test("edit results reach the model as text and structure, and captured frames become image blocks", async () => {+ const frame = "data:image/jpeg;base64,/9j/4AAQ";+ const edited: ProjectResult = {+ ...data,+ view: {+ ...data.view,+ changed: true,+ history: { undo: "Vertical cut", redo: null },+ results: [+ { name: "set_aspect", ok: true, output: { aspect: "9:16" } },+ { name: "capture_frame", ok: true, output: { image: frame, at: 1.5 } },+ ],+ },+ playback: null,+ };+ let received: unknown = null;+ const server = createChatgptServer(+ { userId: "owner", scopes: ["projects:read", "projects:write"] },+ config,+ fakeProjects({+ edit: async (_projectId, commands, label) => {+ received = { commands, label };+ return edited;+ },+ }),+ );+ const client = new Client({ name: "test", version: "1" });+ const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();+ await server.connect(serverTransport);+ await client.connect(clientTransport);+ try {+ const result = await client.callTool({+ name: "edit_project",+ arguments: {+ projectId: "project",+ label: "Vertical cut",+ commands: [{ name: "set_aspect", input: { aspect: "9:16" } }, { name: "capture_frame" }],},- );- const transport = new WebStandardStreamableHTTPServerTransport({- sessionIdGenerator: undefined,- enableJsonResponse: true,});- await server.connect(transport);- try {- const response = await transport.handleRequest(- new Request(`${config.issuer}/api/chatgpt/mcp`, {- method: "POST",- headers: {- "Content-Type": "application/json",- Accept: "application/json, text/event-stream",- },- body: JSON.stringify(message),- }),- );- expect(response.status).toBe(200);- const body = await response.json();- expect(body.id).toBe(message.id);- if (message.method === "tools/call") {- expect(body.result.structuredContent).toEqual(data.view);- }- } finally {- await server.close();- }+ expect(received).toEqual({+ commands: [+ { name: "set_aspect", input: { aspect: "9:16" } },+ { name: "capture_frame", input: {} },+ ],+ label: "Vertical cut",+ });+ const content = result.content as { type: string; text?: string; data?: string; mimeType?: string }[];+ expect(content[0].text).toContain("2 commands ran; the project was saved");+ expect(content[0].text).toContain("Undo would revert: Vertical cut");+ expect(content[0].text).not.toContain("base64");+ expect(content[1]).toMatchObject({ type: "image", mimeType: "image/jpeg", data: "/9j/4AAQ" });+ expect(JSON.stringify(result.structuredContent)).not.toContain("base64");++ const index = await client.callTool({ name: "list_commands", arguments: {} });+ const commands = (index.structuredContent as { commands: { name: string; reads?: true }[] }).commands;+ expect(commands.some((c) => c.name === "set_aspect")).toBe(true);+ expect(commands.find((c) => c.name === "watch_video")?.reads).toBe(true);+ expect(commands.some((c) => c.name === "get_state" || c.name === "undo" || c.name === "import_url")).toBe(false);+ // inspect_project's default read passes the batch guard while staying out of the listing.+ expect(unknownCommandNames(["get_state", "set_aspect", "nope"])).toEqual(["nope"]);++ const described = await client.callTool({ name: "describe_commands", arguments: { names: ["trim_clip", "nope"] } });+ expect(described.structuredContent).toMatchObject({ unknown: ["nope"] });+ expect((described.structuredContent as { commands: { name: string; inputSchema: object }[] }).commands[0].name).toBe("trim_clip");++ const skill = await client.callTool({ name: "read_skill", arguments: { name: "timeline-editing" } });+ expect((skill.content as { text: string }[])[0].text).toContain("# Timeline editing");+ } finally {+ await client.close();+ await server.close();}});diff --git a/site/src/clients/chatgpt/server/mcp.ts b/site/src/clients/chatgpt/server/mcp.tsindex 0af1577f..8013ae8e 100644--- a/site/src/clients/chatgpt/server/mcp.ts+++ b/site/src/clients/chatgpt/server/mcp.ts@@ -1,5 +1,4 @@-import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";-import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";+import { createMcpHandler, McpServer } from "@modelcontextprotocol/server";import { z } from "zod";import {checkInMemoryRateLimit,@@ -10,6 +9,15 @@ import {WIDGET_URI,type ProjectView,} from "@/clients/chatgpt/contracts";+import {+ commandIndex,+ COMMAND_NAMES,+ describeCommands,+ readSkill,+ SKILL_INDEX,+} from "@/clients/chatgpt/server/catalog";+import { MAX_COMMANDS_PER_BATCH } from "@/cut/server/cloud/commands";+import { DOC_EXPORT_PRESETS } from "@/cut/lib/exportPresets";import {chatgptConfig,RESOURCE_METADATA_PATH,@@ -30,6 +38,57 @@ const readOnlyAnnotations = {openWorldHint: false,idempotentHint: true,};+const editAnnotations = {+ readOnlyHint: false,+ destructiveHint: false,+ openWorldHint: false,+ idempotentHint: false,+};++export const REPOSITORY_URL = "https://github.com/DonkeyCut/Donkey";++/** What ChatGPT reads before it picks a tool. The first 512 characters carry+ * the weight, so the economics and the workflow come first. */+export const SERVER_INSTRUCTIONS = [+ `Donkey Cut is an open-source video editor (Apache 2.0, ${REPOSITORY_URL}). Edit the connected account's cloud projects: import footage, inspect it, cut it, caption it, preview, undo, export.`,+ "Editing, previews and exports are free. Hosted AI (voiceover, music, images, caption rewriting, transcription past the monthly allowance) spends the account's credits. Imports and exports use the account's cloud storage.",+ "Workflow: list_projects or create_project → import_media → inspect_project → list_commands once, describe_commands for the ones you need → edit_project (batches, one undo step each) → render_preview → undo/redo → export_video.",+ "Times are seconds; ids come from inspect_project. A batch stops at its first failed command. A tool that answers with a job still running is finished by get_job_status.",+].join("\n");++const commandSchema = z.object({+ name: z.string().min(1).max(64).describe(`A command from list_commands: one of ${COMMAND_NAMES.join(", ")}`),+ input: z.record(z.string(), z.unknown()).optional().describe("The command's input, per describe_commands"),+});+/** A file ChatGPT attaches to a call (openai/fileParams). */+const fileSchema = z.object({+ download_url: z.url(),+ file_id: z.string(),+ mime_type: z.string().optional(),+ file_name: z.string().optional(),+});++type MediaBlock = { type: "image" | "audio"; data: string; mimeType: string };++/** Data-URL images and audio in a command's output become MCP image and+ * audio blocks, so base64 never lands in the text the model reads. */+function liftMedia(view: ProjectView): MediaBlock[] {+ const blocks: MediaBlock[] = [];+ const lift = (value: unknown): unknown => {+ const match = typeof value === "string" ? value.match(/^data:((image|audio)\/[a-z0-9.+-]+);base64,([\s\S]+)$/) : null;+ if (!match) return value;+ blocks.push({ type: match[2] as "image" | "audio", data: match[3], mimeType: match[1] });+ return `(${match[2]} ${blocks.length} attached)`;+ };+ for (const result of view.results) {+ const out = result.output as { image?: unknown; images?: unknown[]; audio?: unknown } | null;+ if (!out || typeof out !== "object") continue;+ if ("image" in out) out.image = lift(out.image);+ if (Array.isArray(out.images)) out.images = out.images.map(lift);+ if ("audio" in out) out.audio = lift(out.audio);+ }+ return blocks;+}type Identity = { userId: string; scopes: string[] };export function createChatgptServer(@@ -37,7 +96,10 @@ export function createChatgptServer(config: ChatgptConfig,projects = projectTools(identity, config),) {- const server = new McpServer({ name: "donkey-cut", version: "1.0.0" });+ const server = new McpServer(+ { name: "donkey-cut", title: "Donkey Cut", version: "1.1.0" },+ { instructions: SERVER_INSTRUCTIONS },+ );const readMetadata = {securitySchemes: [{ type: "oauth2", scopes: ["projects:read"] }],};@@ -46,14 +108,34 @@ export function createChatgptServer({ type: "oauth2", scopes: ["projects:read", "previews:render"] },],};+ const editMetadata = {+ securitySchemes: [+ { type: "oauth2", scopes: ["projects:read", "projects:write"] },+ ],+ };+ const status = (invoking: string, invoked: string) => ({+ "openai/toolInvocation/invoking": invoking,+ "openai/toolInvocation/invoked": invoked,+ });+ const scopeChallenge = (scope: string, text: string) => ({+ isError: true,+ content: [{ type: "text" as const, text }],+ _meta: {+ "mcp/www_authenticate": [+ `Bearer error="insufficient_scope", resource_metadata="${config.issuer}${RESOURCE_METADATA_PATH}", scope="projects:read previews:render projects:write"`,+ ],+ requiredScope: scope,+ },+ });const runTool = async (run: () => Promise<ProjectResult>) => {try {- const { view, playback } = await run();+ const { view, playback, download } = await run();+ const media = liftMedia(view);const text = describeProjectView(view);return {- content: [{ type: "text" as const, text }],+ content: [{ type: "text" as const, text }, ...media],structuredContent: view,- _meta: { playback, pollMs: config.pollMs },+ _meta: { playback, download: download ?? null, pollMs: config.pollMs },};} catch (error) {if (!(error instanceof ProjectToolError)) {@@ -79,7 +161,7 @@ export function createChatgptServer(title: "List Donkey Cut cloud projects",description:"List the connected user's saved cloud projects. Browser and Mac projects become available after being saved to the cloud. Follow nextCursor for more results.",- inputSchema: { cursor: idSchema.optional() },+ inputSchema: z.object({ cursor: idSchema.optional() }),outputSchema: viewSchema,annotations: readOnlyAnnotations,_meta: readMetadata,@@ -93,7 +175,7 @@ export function createChatgptServer(title: "Open a Donkey Cut preview",description:"Show a selected cloud project and its latest available preview. The preview can be from an earlier edit; render_preview renders the current saved revision. With no projectId, show the project picker.",- inputSchema: { projectId: idSchema.optional() },+ inputSchema: z.object({ projectId: idSchema.optional() }),outputSchema: viewSchema,annotations: readOnlyAnnotations,_meta: { ...readMetadata, ui: { resourceUri: WIDGET_URI } },@@ -108,27 +190,14 @@ export function createChatgptServer(title: "Render a Donkey Cut preview",description:"Render the current saved cloud project into a playable preview. Returns a job immediately; use get_preview_status to check it. Reuses a render of the same saved revision. Consumes no AI credits. Does not edit the project.",- inputSchema: { projectId: idSchema },+ inputSchema: z.object({ projectId: idSchema }),outputSchema: viewSchema,annotations: { ...readOnlyAnnotations, readOnlyHint: false },_meta: renderMetadata,},({ projectId }) => {if (!identity.scopes.includes("previews:render")) {- return {- isError: true,- content: [- {- type: "text",- text: "Reconnect Donkey Cut to allow preview rendering.",- },- ],- _meta: {- "mcp/www_authenticate": [- `Bearer error="insufficient_scope", resource_metadata="${config.issuer}${RESOURCE_METADATA_PATH}", scope="projects:read previews:render"`,- ],- },- };+ return scopeChallenge("previews:render", "Reconnect Donkey Cut to allow preview rendering.");}return runTool(() => projects.render(projectId));},@@ -140,7 +209,7 @@ export function createChatgptServer(title: "Check a Donkey Cut preview",description:"Read render progress or renew the playback URL of an existing preview. Returns expired when the preview needs rendering again.",- inputSchema: { projectId: idSchema, jobId: idSchema },+ inputSchema: z.object({ projectId: idSchema, jobId: idSchema }),outputSchema: viewSchema,annotations: readOnlyAnnotations,_meta: readMetadata,@@ -148,6 +217,244 @@ export function createChatgptServer(({ projectId, jobId }) => runTool(() => projects.status(projectId, jobId)),);+ const editing = <T,>(run: () => Promise<T>) =>+ identity.scopes.includes("projects:write")+ ? run()+ : Promise.resolve(scopeChallenge("projects:write", "Reconnect Donkey Cut to allow editing."));++ server.registerTool(+ "create_project",+ {+ title: "Create a Donkey Cut project",+ description:+ "Create an empty cloud project. aspect is the output frame as \"W:H\" — 9:16 for TikTok, Reels and Shorts, 16:9 for YouTube, 1:1 square (default 9:16). Free.",+ inputSchema: z.object({ name: z.string().min(1).max(120), aspect: z.string().max(16).optional() }),+ outputSchema: viewSchema,+ annotations: editAnnotations,+ _meta: { ...editMetadata, ...status("Creating the project", "Project created") },+ },+ ({ name, aspect }) => editing(() => runTool(() => projects.create(name, aspect))),+ );++ server.registerTool(+ "import_media",+ {+ title: "Import footage into a project",+ description:+ "Bring footage into a cloud project: files the user attached to the chat (files), or links (urls) — TikTok, YouTube, Instagram, an X post, a web page, or a direct video/audio/image link. Every file lands as a project asset with an assetId for edit_project's add_clip. Free; the bytes use the account's cloud storage. A long download can outlast this call — then the answer carries a job to finish with get_job_status. audio_only keeps just the soundtrack of a link.",+ inputSchema: z.object({+ projectId: idSchema,+ files: z.array(fileSchema).max(10).optional().describe("Files attached in ChatGPT"),+ urls: z.array(z.url()).max(10).optional().describe("Links to import"),+ audio_only: z.boolean().optional(),+ }),+ outputSchema: viewSchema,+ annotations: { ...editAnnotations, openWorldHint: true },+ _meta: { ...editMetadata, "openai/fileParams": ["files"], ...status("Importing footage", "Footage imported") },+ },+ ({ projectId, files, urls, audio_only }) =>+ editing(() =>+ runTool(() => {+ const items = [+ ...(files ?? []).map((f) => ({ url: f.download_url, ...(f.file_name ? { name: f.file_name } : {}) })),+ ...(urls ?? []).map((url) => ({ url })),+ ];+ if (!items.length) throw new ProjectToolError("Attach files or pass urls.");+ return projects.importMedia(projectId, items, audio_only === true);+ }),+ ),+ );++ server.registerTool(+ "inspect_project",+ {+ title: "Inspect a project",+ description:+ "Read a project's full editor state — media assets with ids, durations, transcripts and notes; the video tracks with clip ids, trims and gaps; soundtrack, titles, captions, aspect. Call it before editing and after an edit_project you want to verify. Pass commands to run read-only inspection commands instead (watch_video for contact sheets of the footage, capture_frame for the composited picture at a time, detect_silence, listen_audio, detect_beats — list_commands marks them reads). Free.",+ inputSchema: z.object({+ projectId: idSchema,+ commands: z.array(commandSchema).max(MAX_COMMANDS_PER_BATCH).optional(),+ }),+ outputSchema: viewSchema,+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Reading the project", "Project read") },+ },+ ({ projectId, commands }) => runTool(() => projects.inspect(projectId, commands?.map((c) => ({ name: c.name, input: c.input ?? {} })))),+ );++ server.registerTool(+ "list_commands",+ {+ title: "List editing commands",+ description:+ "The catalog of editing commands edit_project runs, one line each. Call it once per conversation, then describe_commands for the input schemas of the ones you will use.",+ inputSchema: z.object({}),+ outputSchema: z.object({ commands: z.array(z.object({ name: z.string(), summary: z.string(), reads: z.literal(true).optional() })) }),+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Listing commands", "Commands listed") },+ },+ () => {+ const commands = commandIndex();+ return {+ content: [{ type: "text" as const, text: commands.map((c) => `${c.name}${c.reads ? " (read)" : ""}: ${c.summary}`).join("\n") }],+ structuredContent: { commands },+ };+ },+ );++ server.registerTool(+ "describe_commands",+ {+ title: "Describe editing commands",+ description: "Full descriptions and JSON input schemas for named commands from list_commands.",+ inputSchema: z.object({ names: z.array(z.string().min(1).max(64)).min(1).max(20) }),+ outputSchema: z.object({+ commands: z.array(z.object({ name: z.string(), description: z.string(), inputSchema: z.record(z.string(), z.unknown()) })),+ unknown: z.array(z.string()),+ }),+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Describing commands", "Commands described") },+ },+ ({ names }) => {+ const { found, unknown } = describeCommands(names);+ const commands = found.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));+ return {+ content: [{ type: "text" as const, text: JSON.stringify({ commands, unknown }) }],+ structuredContent: { commands, unknown },+ };+ },+ );++ server.registerTool(+ "list_skills",+ {+ title: "List editing guides",+ description: "The editor's own guides — timeline editing, watching and cutting by content, captions, transitions, graphics, audio, export. Read one with read_skill before working in an unfamiliar area.",+ inputSchema: z.object({}),+ outputSchema: z.object({ skills: z.array(z.string()) }),+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Listing guides", "Guides listed") },+ },+ () => ({+ content: [{ type: "text" as const, text: SKILL_INDEX.join("\n") }],+ structuredContent: { skills: SKILL_INDEX },+ }),+ );++ server.registerTool(+ "read_skill",+ {+ title: "Read an editing guide",+ description: "Read one guide from list_skills.",+ inputSchema: z.object({ name: z.string().min(1).max(64) }),+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Reading the guide", "Guide read") },+ },+ ({ name }) => {+ const doc = readSkill(name);+ if (!doc) return { isError: true, content: [{ type: "text" as const, text: `No such guide. Available: ${SKILL_INDEX.join(", ")}` }] };+ return { content: [{ type: "text" as const, text: doc }] };+ },+ );++ server.registerTool(+ "edit_project",+ {+ title: "Edit a project",+ description:+ "Run editing commands on a cloud project, in order, as one undo step. Commands come from list_commands with inputs per describe_commands; ids and times come from inspect_project. The batch stops at the first command that fails and reports every outcome. label names the step for undo. Editing is free; commands that generate media (voiceover_generate, generate_music, generate_image, captions_generate) spend the account's credits. The result's history says what undo would revert.",+ inputSchema: z.object({+ projectId: idSchema,+ commands: z.array(commandSchema).min(1).max(MAX_COMMANDS_PER_BATCH),+ label: z.string().max(80).optional().describe("What this step does, e.g. \"Cut to 30s and add captions\""),+ }),+ outputSchema: viewSchema,+ annotations: editAnnotations,+ _meta: { ...editMetadata, ...status("Editing the project", "Project edited") },+ },+ ({ projectId, commands, label }) =>+ editing(() => runTool(() => projects.edit(projectId, commands.map((c) => ({ name: c.name, input: c.input ?? {} })), label))),+ );++ server.registerTool(+ "undo",+ {+ title: "Undo the last edit",+ description: "Revert the last edit_project or import_media step on a project. Steps saved from the Donkey Cut editor itself are not on this history.",+ inputSchema: z.object({ projectId: idSchema }),+ outputSchema: viewSchema,+ annotations: editAnnotations,+ _meta: { ...editMetadata, ...status("Undoing", "Undone") },+ },+ ({ projectId }) => editing(() => runTool(() => projects.undo(projectId))),+ );++ server.registerTool(+ "redo",+ {+ title: "Redo an undone edit",+ description: "Re-apply the step the last undo reverted.",+ inputSchema: z.object({ projectId: idSchema }),+ outputSchema: viewSchema,+ annotations: editAnnotations,+ _meta: { ...editMetadata, ...status("Redoing", "Redone") },+ },+ ({ projectId }) => editing(() => runTool(() => projects.redo(projectId))),+ );++ server.registerTool(+ "export_video",+ {+ title: "Export a project",+ description:+ `Render the saved project to an MP4 the user downloads from the Donkey Cut card. preset: ${DOC_EXPORT_PRESETS.join(" | ")} (original matches the footage; tiktok is best quality 1080p; fast is a smaller 1080p; light is a 720p draft). Free; the file counts against the account's cloud storage and is listed in the project's Media panel. A render can outlast this call — finish it with get_export_status.`,+ inputSchema: z.object({ projectId: idSchema, preset: z.enum(DOC_EXPORT_PRESETS).optional() }),+ outputSchema: viewSchema,+ annotations: editAnnotations,+ _meta: { ...editMetadata, ...status("Exporting the video", "Export started") },+ },+ ({ projectId, preset }) => editing(() => runTool(() => projects.exportVideo(projectId, preset ?? "original"))),+ );++ server.registerTool(+ "get_export_status",+ {+ title: "Check an export",+ description: "Read an export's progress; when it is done the Donkey Cut card offers the download.",+ inputSchema: z.object({ jobId: idSchema }),+ outputSchema: viewSchema,+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Checking the export", "Export checked") },+ },+ ({ jobId }) => runTool(() => projects.exportStatus(jobId)),+ );++ server.registerTool(+ "get_job_status",+ {+ title: "Check a job",+ description: "Finish a call that answered with a running job (an import, an edit batch, an export): read its progress and, once done, its results.",+ inputSchema: z.object({ jobId: idSchema }),+ outputSchema: viewSchema,+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Checking the job", "Job checked") },+ },+ ({ jobId }) => runTool(() => projects.jobStatus(jobId)),+ );++ server.registerTool(+ "account_status",+ {+ title: "Account credits and storage",+ description: "The connected account's AI credit balance, cloud storage used against its allowance, and plan. Editing, previews and exports never spend credits.",+ inputSchema: z.object({}),+ outputSchema: viewSchema,+ annotations: readOnlyAnnotations,+ _meta: { ...readMetadata, ...status("Reading the account", "Account read") },+ },+ () => runTool(() => projects.account()),+ );+server.registerResource("project-preview",WIDGET_URI,@@ -168,7 +475,7 @@ export function createChatgptServer(},},"openai/widgetDescription":- "Donkey Cut cloud project picker and video preview with render progress and an Open in Donkey Cut link.",+ "Donkey Cut cloud project picker and video preview with render progress, export download, and an Open in Donkey Cut link.",},},],@@ -178,9 +485,14 @@ export function createChatgptServer(}function describeProjectView(view: ProjectView): string {+ if (view.account) {+ const { credits, storageBytes, storageQuotaBytes, plan } = view.account;+ const storage = storageQuotaBytes === null ? `${mb(storageBytes)} MB used` : `${mb(storageBytes)} of ${mb(storageQuotaBytes)} MB used`;+ return `Plan: ${plan}. AI credits: $${credits}. Cloud storage: ${storage}. Editing, previews and exports spend no credits.`;+ }if (view.view === "projects") {if (!view.projects.length) {- return "No cloud projects yet. Open Donkey Cut to save a project to the cloud.";+ return "No cloud projects yet. Create one with create_project, or open Donkey Cut to save a project to the cloud.";}return view.projects.map((project) => `${project.name}: ${project.id} (${project.url})`)@@ -188,12 +500,42 @@ function describeProjectView(view: ProjectView): string {}const project = view.project!;- const previewStatus = view.preview- ? `preview ${view.preview.status}`- : "no preview yet";- return `${project.name}: ${previewStatus}. Open in Donkey Cut: ${project.url}`;+ const lines: string[] = [];+ if (view.job && view.job.status !== "done") {+ lines.push(+ view.job.status === "error"+ ? `Job ${view.job.id} (${view.job.kind}) failed: ${view.job.error ?? "unknown error"}.`+ : `Job ${view.job.id} (${view.job.kind}) is ${view.job.status} at ${Math.round(view.job.progress * 100)}%. Call get_job_status with this id to finish.`,+ );+ }+ if (view.results.length) {+ const failed = view.results.filter((r) => !r.ok);+ lines.push(+ `${view.results.length} command${view.results.length === 1 ? "" : "s"} ran${failed.length ? `, ${failed.length} failed` : ""}${view.changed ? "; the project was saved" : "; nothing changed"}.`,+ );+ lines.push(JSON.stringify(view.results));+ }+ if (view.export) {+ const { status, progress, name, error } = view.export;+ lines.push(+ status === "done"+ ? `Export ${name ?? ""} is ready: the Donkey Cut card has the Download button, and the file is in the project's Media panel.`+ : status === "error" || status === "expired"+ ? `Export ${name ?? ""} ${status}: ${error ?? ""}`+ : `Export ${name ?? ""} is ${status} at ${Math.round(progress * 100)}%. Call get_export_status with job id ${view.export.id}.`,+ );+ }+ if (view.preview || !lines.length) {+ lines.push(`${project.name} (${project.revision}): ${view.preview ? `preview ${view.preview.status}` : "no preview yet"}.`);+ }+ if (view.history?.undo) lines.push(`Undo would revert: ${view.history.undo}.`);+ if (view.history?.redo) lines.push(`Redo would re-apply: ${view.history.redo}.`);+ lines.push(`Open in Donkey Cut: ${project.url}`);+ return lines.join("\n");}+const mb = (bytes: number) => Math.round(bytes / 1024 ** 2);+/** POST /api/chatgpt/mcp: this protocol accepts scoped OAuth access tokens. */export async function mcpEndpoint(request: Request) {const config = await chatgptConfig();@@ -215,7 +557,7 @@ export async function mcpEndpoint(request: Request) {return new Response(null, {status: identity ? 403 : 401,headers: {- "WWW-Authenticate": `Bearer resource_metadata="${config.issuer}${RESOURCE_METADATA_PATH}", scope="projects:read previews:render"`,+ "WWW-Authenticate": `Bearer resource_metadata="${config.issuer}${RESOURCE_METADATA_PATH}", scope="projects:read previews:render projects:write"`,"Cache-Control": "no-store",},});@@ -230,15 +572,10 @@ export async function mcpEndpoint(request: Request) {return rateLimitResponse(rateLimit.retryAfterSeconds);}- const server = createChatgptServer(identity, config);- const transport = new WebStandardStreamableHTTPServerTransport({- sessionIdGenerator: undefined,- enableJsonResponse: true,- });+ const handler = chatgptHttpHandler(identity, config);try {- await server.connect(transport);- const response = await transport.handleRequest(request);- // Materialize the JSON response before closing this stateless request's transport.+ const response = await handler.fetch(request);+ // Materialize the body before closing the per-request handler.const body = await response.arrayBuffer();return new Response(body.byteLength ? body : null, {status: response.status,@@ -248,6 +585,25 @@ export async function mcpEndpoint(request: Request) {},});} finally {- await server.close();+ await handler.close();}}++/**+ * Serves protocol 2026-07-28 requests directly and answers 2025-era clients+ * through the stateless initialize path, so a ChatGPT connection works+ * whichever revision it sends. Every request gets a fresh server.+ */+export function chatgptHttpHandler(+ identity: Identity,+ config: ChatgptConfig,+ projects?: ReturnType<typeof projectTools>,+) {+ return createMcpHandler(+ () => createChatgptServer(identity, config, projects),+ {+ onerror: (error) =>+ console.warn("[chatgpt] mcp request rejected", error.message),+ },+ );+}diff --git a/site/src/clients/chatgpt/server/oauthRoutes.ts b/site/src/clients/chatgpt/server/oauthRoutes.tsindex e457791f..8f873fa0 100644--- a/site/src/clients/chatgpt/server/oauthRoutes.ts+++ b/site/src/clients/chatgpt/server/oauthRoutes.ts@@ -323,10 +323,8 @@ function consentCookie(value: string, maxAgeSeconds: number) {}function consentPage(nonce: string, authorization: Authorization) {- const canRender = authorization.scope.split(" ").includes("previews:render");- const renderPermission = canRender- ? " It can also render previews of your saved edits."- : "";+ const scopes = authorization.scope.split(" ");+ const access = scopes.includes("projects:write") ? "view and edit" : "view";const escapedNonce = nonce.replace(/[&<>"']/g,(character) =>@@ -343,20 +341,22 @@ function consentPage(nonce: string, authorization: Authorization) {<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">- <title>Connect Donkey Cut to ChatGPT</title>+ <title>Connect to ChatGPT</title><style>body { font: 17px system-ui; max-width: 460px; margin: 12vh auto; padding: 24px; color: #202020; background: #faf9f7; }- h1 { font-size: 30px; }- p { line-height: 1.6; }+ .app { display: flex; align-items: center; gap: 12px; font-weight: 600; margin-bottom: 28px; }+ .app img { width: 44px; height: 44px; }+ h1 { font-size: 30px; margin: 0 0 12px; }+ p { line-height: 1.6; margin: 0 0 24px; }button { font: inherit; padding: 12px 20px; border-radius: 10px; border: 1px solid #ccc; cursor: pointer; }button[value=allow] { background: #202020; color: white; }form { display: flex; gap: 12px; }</style></head><body>- <h1>Connect Donkey Cut to ChatGPT</h1>- <p>ChatGPT can read your cloud project names and play their previews.${renderPermission}</p>- <p>Preview rendering uses no AI credits. Your existing storage allowance applies to retained media.</p>+ <div class="app"><img src="/donkey-logo.svg" alt="">Donkey Cut</div>+ <h1>Connect to ChatGPT</h1>+ <p>ChatGPT can ${access} your projects.</p><form method="post" action="${OAUTH_PATH}/authorize"><input type="hidden" name="nonce" value="${escapedNonce}"><button name="decision" value="allow">Connect</button>@@ -369,6 +369,7 @@ function consentPage(nonce: string, authorization: Authorization) {const callbackOrigin = new URL(authorization.redirect_uri).origin;const contentSecurityPolicy = ["default-src 'none'",+ "img-src 'self'","style-src 'unsafe-inline'",`form-action 'self' ${callbackOrigin}`,"frame-ancestors 'none'",diff --git a/site/src/clients/chatgpt/server/projects.test.ts b/site/src/clients/chatgpt/server/projects.test.tsindex 6ede4709..af7cfead 100644--- a/site/src/clients/chatgpt/server/projects.test.ts+++ b/site/src/clients/chatgpt/server/projects.test.ts@@ -4,7 +4,7 @@ import { SETTINGS } from "@/lib/config/registry";import { projectTools } from "@/clients/chatgpt/server/projects";const config = SETTINGS.chatgptApp.schema.parse(SETTINGS.chatgptApp.default);-function createTestContext() {+function createTestContext(scopes: string[] = ["projects:read"]) {const project = { id: "mine", userId: "owner", name: "My video", version: 4 };const jobs = mock(async (args: unknown) => {void args;@@ -34,7 +34,7 @@ function createTestContext() {return {db,tools: projectTools(- { userId: "owner", scopes: ["projects:read"] },+ { userId: "owner", scopes },config,db as unknown as typeof prisma,),@@ -51,9 +51,18 @@ describe("ChatGPT cloud projects", () => {expect(db.cutRenderJob.findFirst).not.toHaveBeenCalled();expect(db.cutProject.findMany).not.toHaveBeenCalled();});- test("read scope cannot enqueue renders", async () => {+ test("read scope cannot enqueue renders or edits", async () => {const { tools } = createTestContext();await expect(tools.render("mine")).rejects.toThrow("permission");+ await expect(tools.edit("mine", [{ name: "set_aspect", input: { aspect: "9:16" } }])).rejects.toThrow("permission");+ await expect(tools.undo("mine")).rejects.toThrow("permission");+ await expect(tools.exportVideo("mine", "original")).rejects.toThrow("permission");+ });+ test("a batch names only catalog commands, and inspection stays read-only", async () => {+ const { tools } = createTestContext(["projects:read", "projects:write"]);+ await expect(tools.edit("mine", [{ name: "not_a_command", input: {} }])).rejects.toThrow("Unknown command: not_a_command");+ await expect(tools.edit("foreign", [{ name: "set_aspect", input: {} }])).rejects.toThrow("Project not found");+ await expect(tools.inspect("mine", [{ name: "set_aspect", input: { aspect: "9:16" } }])).rejects.toThrow("reads only");});test("status is constrained to the owner, selected project, and preview kind", async () => {const { tools, db } = createTestContext();diff --git a/site/src/clients/chatgpt/server/projects.ts b/site/src/clients/chatgpt/server/projects.tsindex b8428835..fa748496 100644--- a/site/src/clients/chatgpt/server/projects.ts+++ b/site/src/clients/chatgpt/server/projects.ts@@ -1,13 +1,43 @@+import type { Prisma } from "@/generated/prisma/client";import { prisma } from "@/lib/prisma";+import { getCreditBalance } from "@/lib/credits/inference";+import { getActiveProSubscription } from "@/lib/billing/pro-subscription";+import { isDonkeySuperUser } from "@/lib/donkey-api-auth";+import { normalizeAspect, type ProjectDoc } from "@/cut/lib/types";+import { queueCommands, waitForJob, type CommandCall, type CommandJobResult, type JobRow } from "@/cut/server/cloud/commands";+import { historyState, HistoryError, restoreCheckpoint } from "@/cut/server/cloud/history";+import { queueDocExport, queueImportUrl } from "@/cut/server/cloud/jobs";+import { cutLimitsFor } from "@/cut/server/cloud/limits";import { previewFromDoc } from "@/cut/server/cloud/previewJobs";import { mediaObjectUrl, mediaUrlLifetime } from "@/cut/server/cloud/mediaCdn";+import { usageBytes } from "@/cut/server/cloud/usage";import { wakeRenderWorker } from "@/cut/server/cloud/wake";-import type { Playback, ProjectView } from "@/clients/chatgpt/contracts";+import type { ImportUrlResult } from "@/cut/worker/importUrlJob";+import type { Download, Playback, ProjectView } from "@/clients/chatgpt/contracts";import type { ChatgptConfig } from "@/clients/chatgpt/server/config";+import { READ_COMMANDS, unknownCommandNames } from "@/clients/chatgpt/server/catalog";type Identity = { userId: string; scopes: string[] };export class ProjectToolError extends Error {}-export type ProjectResult = { view: ProjectView; playback: Playback | null };+export type ProjectResult = { view: ProjectView; playback: Playback | null; download?: Download | null };++/** A queue helper's refusal, read out of its Response as a message. */+async function refusal(res: Response): Promise<never> {+ const body = (await res.json().catch(() => ({}))) as { error?: string; bytes?: number; quotaBytes?: number };+ if (body.error === "storage_quota_exceeded")+ throw new ProjectToolError(+ `The account's cloud storage is full (${mb(body.bytes ?? 0)} of ${mb(body.quotaBytes ?? 0)} MB). Delete media or exports in Donkey Cut, or upgrade the plan.`+ );+ throw new ProjectToolError(body.error ?? "Donkey Cut refused the request.");+}++const mb = (bytes: number) => Math.round(bytes / 1024 ** 2);++const jobStatus = (row: Pick<JobRow, "state">): "queued" | "running" | "done" | "error" =>+ row.state === "queued" || row.state === "running" || row.state === "done" ? row.state : "error";++const jobError = (row: Pick<JobRow, "state" | "error">) =>+ row.state === "canceled" ? "The job was canceled." : row.error ?? undefined;export function projectTools(identity: Identity,@@ -15,6 +45,7 @@ export function projectTools(db = prisma,) {const canRender = identity.scopes.includes("previews:render");+ const canEdit = identity.scopes.includes("projects:write");const projectSummary = (row: {id: string;name: string;@@ -32,6 +63,13 @@ export function projectTools(project: null,preview: null,canRender,+ canEdit,+ export: null,+ job: null,+ results: [],+ changed: false,+ history: null,+ account: null,});async function getOwnedProject(projectId: string) {@@ -47,6 +85,22 @@ export function projectTools(return projectSummary(row);}+ /** The project view with its undo state, as every edit tool answers. */+ async function projectView(projectId: string): Promise<ProjectView> {+ const project = await getOwnedProject(projectId);+ const version = Number(project.revision.slice("cloud:".length));+ return {+ ...emptyProjectView(),+ view: "project",+ project,+ history: await historyState(db, identity.userId, projectId, version),+ };+ }++ function requireEdit() {+ if (!canEdit) throw new ProjectToolError("Reconnect Donkey Cut with editing permission.");+ }+async function getPreviewStatus(projectId: string,jobId?: string,@@ -83,10 +137,7 @@ export function projectTools(wakeRenderWorker();}- const status =- job.state === "queued" || job.state === "running" || job.state === "done"- ? job.state- : "error";+ const status = jobStatus(job);view.preview = {id: job.id,status,@@ -126,6 +177,78 @@ export function projectTools(};}+ /** An export job as the widget and the model see it. */+ async function exportView(row: JobRow): Promise<ProjectResult> {+ if (!row.projectId) throw new ProjectToolError("Export not found.");+ const view = await projectView(row.projectId);+ const status = jobStatus(row);+ view.export = { id: row.id, status, progress: Math.max(0, Math.min(1, row.progress)), name: row.outName, ...(jobError(row) ? { error: jobError(row) } : {}) };+ if (status !== "done" || !row.outputKey) {+ if (status === "queued" || status === "running") wakeRenderWorker();+ return { view, playback: null, download: null };+ }+ const media = await db.cutMediaObject.findFirst({+ where: { r2Key: row.outputKey, userId: identity.userId, kind: "export", uploadState: "complete" },+ select: { r2Key: true },+ });+ if (!media) {+ view.export.status = "expired";+ view.export.error = "The export file was deleted. Export again.";+ return { view, playback: null, download: null };+ }+ return {+ view,+ playback: null,+ download: {+ url: mediaObjectUrl(media.r2Key, row.outName ? { downloadName: row.outName } : undefined),+ expiresAt: Date.now() + mediaUrlLifetime() * 1000,+ name: row.outName ?? "export.mp4",+ },+ };+ }++ /** A commands or import job as a result: settled rows carry their+ * outcomes; a row still running carries the job for a later poll. */+ async function jobView(row: JobRow): Promise<ProjectResult> {+ if (row.kind === "export") return exportView(row);+ if (row.kind === "preview" && row.projectId) return getPreviewStatus(row.projectId, row.id);+ if (!row.projectId) throw new ProjectToolError("Job not found.");+ const view = await projectView(row.projectId);+ const status = jobStatus(row);+ view.job = { id: row.id, kind: row.kind, status, progress: Math.max(0, Math.min(1, row.progress)), ...(jobError(row) ? { error: jobError(row) } : {}) };+ if (status === "queued" || status === "running") wakeRenderWorker();+ if (status !== "done") return { view, playback: null };+ if (row.kind === "commands") {+ const result = row.result as CommandJobResult | null;+ view.results = result?.results ?? [];+ view.changed = result?.changed ?? false;+ } else if (row.kind === "import_url") {+ const result = row.result as ImportUrlResult | null;+ view.results = [{ name: "import_media", ok: true, output: { assets: result?.assets ?? [], ...(result?.text ? { sourceText: result.text } : {}) } }];+ view.changed = (result?.assets?.length ?? 0) > 0;+ }+ return { view, playback: null };+ }++ async function ownedJob(jobId: string): Promise<JobRow> {+ const row = await db.cutRenderJob.findFirst({ where: { id: jobId, userId: identity.userId } });+ if (!row) throw new ProjectToolError("Job not found.");+ return row;+ }++ /** Queue a batch and wait on it within the call's budget. */+ async function runBatch(projectId: string, commands: CommandCall[], opts: { readOnly?: boolean; label?: string }): Promise<ProjectResult> {+ await getOwnedProject(projectId);+ const unknown = unknownCommandNames(commands.map((c) => c.name));+ if (unknown.length)+ throw new ProjectToolError(`Unknown command${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}. Call list_commands for the catalog.`);+ const queued = await queueCommands(identity.userId, projectId, { commands, ...opts });+ if (queued instanceof Response) return refusal(queued);+ const row = await waitForJob(identity.userId, queued.id, config.commandWaitMs);+ if (!row) throw new ProjectToolError("The job disappeared. Try again.");+ return jobView(row);+ }+return {async list(cursor?: string): Promise<ProjectResult> {// A cursor names an account-owned row, so a foreign id cannot influence pagination.@@ -163,5 +286,149 @@ export function projectTools(}return getPreviewStatus(projectId, job.id);},++ async create(name: string, aspect?: string): Promise<ProjectResult> {+ requireEdit();+ const frame = aspect ? normalizeAspect(aspect) : null;+ if (aspect && !frame) throw new ProjectToolError('aspect must be "W:H", like "9:16" or "16:9".');+ const now = Date.now();+ const doc: ProjectDoc = {+ version: 1,+ name: name.trim() || "Untitled",+ createdAt: now,+ updatedAt: now,+ assets: [],+ clips: [],+ audioClips: [],+ overlays: [],+ ...(frame ? { aspect: frame } : {}),+ };+ const row = await db.cutProject.create({+ data: { userId: identity.userId, name: doc.name, doc: doc as unknown as Prisma.InputJsonValue },+ select: { id: true, name: true, version: true },+ });+ return { view: { ...emptyProjectView(), view: "project", project: projectSummary(row), history: { undo: null, redo: null } }, playback: null };+ },++ async inspect(projectId: string, commands?: CommandCall[]): Promise<ProjectResult> {+ const calls = commands?.length ? commands : [{ name: "get_state", input: {} }];+ const writes = calls.filter((c) => c.name !== "get_state" && !READ_COMMANDS.has(c.name)).map((c) => c.name);+ if (writes.length)+ throw new ProjectToolError(`inspect_project runs reads only; ${writes.join(", ")} edit the project — send them through edit_project.`);+ return runBatch(projectId, calls, { readOnly: true });+ },++ async edit(projectId: string, commands: CommandCall[], label?: string): Promise<ProjectResult> {+ requireEdit();+ return runBatch(projectId, commands, { label });+ },++ async importMedia(projectId: string, items: { url: string; name?: string }[], audioOnly: boolean): Promise<ProjectResult> {+ requireEdit();+ await getOwnedProject(projectId);+ const ids: string[] = [];+ for (const item of items) {+ const queued = await queueImportUrl(identity.userId, projectId, {+ url: item.url,+ audio: audioOnly,+ adopt: item.name ? { name: item.name } : {},+ });+ if (queued instanceof Response) {+ if (ids.length === 0) return refusal(queued);+ break;+ }+ ids.push(queued.id);+ }+ const deadline = Date.now() + config.commandWaitMs;+ const rows: JobRow[] = [];+ for (const id of ids) {+ const row = await waitForJob(identity.userId, id, Math.max(0, deadline - Date.now()));+ if (row) rows.push(row);+ }+ const view = await projectView(projectId);+ const pending = rows.filter((r) => r.state === "queued" || r.state === "running");+ for (const row of rows) {+ const status = jobStatus(row);+ if (status === "done") {+ const result = row.result as ImportUrlResult | null;+ view.results.push({ name: "import_media", ok: true, output: { jobId: row.id, assets: result?.assets ?? [], ...(result?.text ? { sourceText: result.text } : {}) } });+ view.changed ||= (result?.assets?.length ?? 0) > 0;+ } else if (status === "error") {+ view.results.push({ name: "import_media", ok: false, error: jobError(row) ?? "The import failed." });+ }+ }+ // Every unfinished import names its job, so none is lost once the call+ // returns; the first one is the job the view carries.+ for (const row of pending)+ view.results.push({ name: "import_media", ok: true, output: { jobId: row.id, status: jobStatus(row) } });+ if (pending.length) {+ const row = pending[0];+ view.job = { id: row.id, kind: row.kind, status: jobStatus(row), progress: row.progress };+ }+ if (ids.length < items.length)+ view.results.push({ name: "import_media", ok: false, error: `${items.length - ids.length} item(s) were not queued: the account's job cap was reached.` });+ return { view, playback: null };+ },++ async undo(projectId: string): Promise<ProjectResult> {+ requireEdit();+ await getOwnedProject(projectId);+ const step = await restoreCheckpoint(db, identity.userId, projectId, "undo").catch((e) => {+ throw e instanceof HistoryError ? new ProjectToolError(e.message) : e;+ });+ const view = await projectView(projectId);+ view.changed = true;+ view.results = [{ name: "undo", ok: true, output: { undone: step.label } }];+ return { view, playback: null };+ },++ async redo(projectId: string): Promise<ProjectResult> {+ requireEdit();+ await getOwnedProject(projectId);+ const step = await restoreCheckpoint(db, identity.userId, projectId, "redo").catch((e) => {+ throw e instanceof HistoryError ? new ProjectToolError(e.message) : e;+ });+ const view = await projectView(projectId);+ view.changed = true;+ view.results = [{ name: "redo", ok: true, output: { redone: step.label } }];+ return { view, playback: null };+ },++ async exportVideo(projectId: string, preset: string): Promise<ProjectResult> {+ requireEdit();+ const queued = await queueDocExport(identity.userId, projectId, preset);+ if (queued instanceof Response) return refusal(queued);+ const row = await waitForJob(identity.userId, queued.id, config.commandWaitMs);+ if (!row) throw new ProjectToolError("The export disappeared. Try again.");+ return exportView(row);+ },++ async exportStatus(jobId: string): Promise<ProjectResult> {+ const row = await ownedJob(jobId);+ if (row.kind !== "export") throw new ProjectToolError("That job is not an export.");+ return exportView(row);+ },++ async jobStatus(jobId: string): Promise<ProjectResult> {+ return jobView(await ownedJob(jobId));+ },++ async account(): Promise<ProjectResult> {+ const [credits, bytes, limits, superUser, pro] = await Promise.all([+ getCreditBalance(identity.userId),+ usageBytes(identity.userId),+ cutLimitsFor(identity.userId),+ isDonkeySuperUser(identity.userId),+ getActiveProSubscription(identity.userId),+ ]);+ const view = emptyProjectView();+ view.account = {+ credits: credits.balance,+ storageBytes: bytes,+ storageQuotaBytes: limits.storageBytes,+ plan: superUser ? "unlimited" : pro ? "pro" : "free",+ };+ return { view, playback: null };+ },};}diff --git a/site/src/clients/chatgpt/ui/PreviewApp.tsx b/site/src/clients/chatgpt/ui/PreviewApp.tsxindex 91ad3dd5..38466aab 100644--- a/site/src/clients/chatgpt/ui/PreviewApp.tsx+++ b/site/src/clients/chatgpt/ui/PreviewApp.tsx@@ -3,10 +3,12 @@ import { useProjectApp } from "./useProjectApp";import "./preview.css";export function PreviewApp() {- const { ready, view, playback, error, busy, visible, run, playbackFailed, openDonkey } = useProjectApp();+ const { ready, view, playback, download, error, busy, visible, run, playbackFailed, openDonkey, openDownload } = useProjectApp();const project = view?.project;const preview = view?.preview;const rendering = preview?.status === "queued" || preview?.status === "running";+ const exp = view?.export;+ const exporting = exp?.status === "queued" || exp?.status === "running";return <main aria-busy={busy}><header><span className="brand">Donkey Cut</span><span>Cloud projects</span></header>{error && <p role="alert" className="error">{error}</p>}@@ -29,9 +31,17 @@ export function PreviewApp() {{preview?.status === "expired" && <p>This preview has expired. Render it again to watch.</p>}{preview?.status === "error" && <p role="alert">{preview.error}</p>}{preview?.status === "done" && preview.revision !== project.revision && <p className="muted">This preview may be from an earlier edit.</p>}+ {exporting && <div role="status"><p>{exp.status === "queued" ? "Waiting to export…" : `Exporting ${exp.name ?? "video"}… ${Math.round(exp.progress * 100)}%`}</p><progress max={1} value={exp.progress} /></div>}+ {exp?.status === "done" && !download && <p className="muted">Export {exp.name ?? ""} finished. Renewing the download link…</p>}+ {(exp?.status === "error" || exp?.status === "expired") && <p role="alert">{exp.error ?? "The export did not finish."}</p>}+ {view.history?.undo && <p className="muted">Last step: {view.history.undo}</p>}<nav>{view.canRender && <button className="primary" disabled={busy || rendering || !ready} onClick={() => void run("render_preview", { projectId: project.id })}>Render preview</button>}- <button disabled={!ready} onClick={() => void openDonkey()}>Open in Donkey Cut ↗</button>+ {download && <button className="primary" disabled={!ready} onClick={() => openDownload()}>Download {download.name}</button>}+ {view.canEdit && <button disabled={busy || exporting || !ready} onClick={() => void run("export_video", { projectId: project.id })}>Export video</button>}+ {view.canEdit && view.history?.undo && <button disabled={busy || !ready} onClick={() => void run("undo", { projectId: project.id })}>Undo</button>}+ {view.canEdit && view.history?.redo && <button disabled={busy || !ready} onClick={() => void run("redo", { projectId: project.id })}>Redo</button>}+ <button disabled={!ready} onClick={() => openDonkey()}>Open in Donkey Cut ↗</button><button disabled={busy || !ready} onClick={() => void run("list_projects", {})}>Projects</button>{error && <button disabled={busy || !ready} onClick={() => void run("open_project", { projectId: project.id })}>Try again</button>}</nav>diff --git a/site/src/clients/chatgpt/ui/useProjectApp.ts b/site/src/clients/chatgpt/ui/useProjectApp.tsindex 05744a16..0278c6d2 100644--- a/site/src/clients/chatgpt/ui/useProjectApp.ts+++ b/site/src/clients/chatgpt/ui/useProjectApp.ts@@ -1,6 +1,6 @@import { useCallback, useEffect, useRef, useState } from "react";import { App } from "@modelcontextprotocol/ext-apps";-import { playbackSchema, viewSchema, type Playback, type ProjectView } from "../contracts";+import { downloadSchema, playbackSchema, viewSchema, type Download, type Playback, type ProjectView } from "../contracts";type ToolResult = { isError?: boolean; structuredContent?: unknown; _meta?: Record<string, unknown>; content?: unknown[] };@@ -11,6 +11,7 @@ export function useProjectApp() {const [ready, setReady] = useState(false);const [view, setView] = useState<ProjectView | null>(null);const [playback, setPlayback] = useState<Playback | null>(null);+ const [download, setDownload] = useState<Download | null>(null);const [error, setError] = useState<string | null>(null);const [busy, setBusy] = useState(false);const [visible, setVisible] = useState(!document.hidden);@@ -22,10 +23,12 @@ export function useProjectApp() {const parsed = viewSchema.safeParse(result.structuredContent);if (!parsed.success) throw new Error("The preview response could not be read.");const media = playbackSchema.safeParse(result._meta?.playback);+ const file = downloadSchema.safeParse(result._meta?.download);const interval = result._meta?.pollMs;if (typeof interval === "number" && interval >= 1000 && interval <= 30000) setPollMs(interval);setView(parsed.data);setPlayback(media.success ? media.data : null);+ setDownload(file.success ? file.data : null);setError(null);}, []);@@ -81,6 +84,19 @@ export function useProjectApp() {return () => window.clearTimeout(timeout);}, [ready, visible, busy, error, projectId, jobId, status, playback, pollMs, run, view]);+ // An export in flight polls the same way; a finished one renews its+ // download link before it expires.+ const exportId = view?.export?.id;+ const exportStatus = view?.export?.status;+ useEffect(() => {+ if (!ready || !visible || busy || error || !exportId) return;+ const waiting = exportStatus === "queued" || exportStatus === "running";+ if (!waiting && !download) return;+ const delay = waiting ? pollMs : Math.max(1000, download!.expiresAt - Date.now() - 60000);+ const timeout = window.setTimeout(() => { void run("get_export_status", { jobId: exportId }, false); }, delay);+ return () => window.clearTimeout(timeout);+ }, [ready, visible, busy, error, exportId, exportStatus, download, pollMs, run, view]);+const playbackFailed = useCallback(() => {if (!projectId || !jobId) return;if (recoveries.current++ >= 1) { setError("Video could not load. Try opening the project again."); return; }@@ -88,10 +104,12 @@ export function useProjectApp() {void run("get_preview_status", { projectId, jobId }, false);}, [projectId, jobId, run]);- const openDonkey = async () => {- if (!view?.project || !appRef.current) return;- try { const result = await appRef.current.openLink({ url: view.project.url }); if (result.isError) setError("Could not open Donkey Cut."); }- catch { setError("Could not open Donkey Cut."); }+ const openLink = async (url: string, failure: string) => {+ if (!appRef.current) return;+ try { const result = await appRef.current.openLink({ url }); if (result.isError) setError(failure); }+ catch { setError(failure); }};- return { ready, view, playback, error, busy, visible, run, playbackFailed, openDonkey };+ const openDonkey = () => { if (view?.project) void openLink(view.project.url, "Could not open Donkey Cut."); };+ const openDownload = () => { if (download) void openLink(download.url, "Could not open the download."); };+ return { ready, view, playback, download, error, busy, visible, run, playbackFailed, openDonkey, openDownload };}