@lalalic/markcut 3.2.40 → 3.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/mcp/bridge.mjs +58 -14
- package/src/mcp/compile-operation.mjs +3 -3
- package/src/mcp/compile-worker.mjs +3 -2
- package/src/mcp/remotion-app.bundle.js +297 -297
- package/src/mcp/review-delivery.mjs +47 -0
- package/src/mcp/server.mjs +5 -3
- package/src/player/SharedPlayer.tsx +4 -0
- package/src/types/Scene.tsx +2 -1
- package/src/types/remotion-folder-name.ts +19 -0
- package/tests/mcp-preview-bridge.test.ts +58 -1
- package/tests/mcp-preview-delivery.test.ts +33 -0
- package/tests/remotion-folder-name.test.ts +25 -0
package/package.json
CHANGED
package/src/mcp/bridge.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function buildPreviewBridgeScript() {
|
|
2
2
|
return `
|
|
3
3
|
const feedback=document.getElementById('feedback'),status=document.getElementById('status'),pathLabel=document.getElementById('path-label');
|
|
4
|
-
let nextId=0,identity=null,busy=false,expectedPath=null,activePath=null,activeRelay=null,submittedRevision=null;
|
|
4
|
+
let nextId=0,identity=null,busy=false,expectedPath=null,activePath=null,activeRelay=null,activeReview={delivery:"text"},expectedDelivery="text",submittedRevision=null,submission=null;
|
|
5
5
|
const comments=[];
|
|
6
6
|
let currentScene={sceneId:null,sceneName:null,sceneStart:0,timeSeconds:0},selectedId=null,nextCommentId=0;
|
|
7
7
|
const mode=document.getElementById('comment-mode');
|
|
@@ -93,6 +93,8 @@ async function loadRemoteScenes(path){
|
|
|
93
93
|
const response=await fetch(url+'?try='+attempt,{cache:'no-store'});
|
|
94
94
|
if(response.ok){const data=await response.json();
|
|
95
95
|
if(data.requestedPath===path && (data.compiledUrl||data.compiled) && generation===fallbackGeneration){
|
|
96
|
+
// Public path cache contains media only, never a caller's private
|
|
97
|
+
// eventTemplate. Event delivery cannot be reconstructed from it.
|
|
96
98
|
if(window.__markcutRevision?.requestedPath===path)return;
|
|
97
99
|
resultsByPath.set(path,data);renderRevision(data);return;
|
|
98
100
|
}
|
|
@@ -110,12 +112,15 @@ function applyToolInput(params){
|
|
|
110
112
|
const input=params?.arguments||params?.input||params?.toolInput||params||{};
|
|
111
113
|
if(typeof input.path!=='string')return;
|
|
112
114
|
expectedPath=input.path;
|
|
115
|
+
expectedDelivery=input.review?.delivery==='event'?'event':'text';
|
|
116
|
+
// The selection has no authority to change delivery; only the compiled
|
|
117
|
+
// operation result supplies the provider-bound review configuration.
|
|
113
118
|
loadRemoteScenes(expectedPath);
|
|
114
119
|
showVideoName(expectedPath);
|
|
115
120
|
const cached=resultsByPath.get(expectedPath);
|
|
116
121
|
if(cached){if(cached.operationUrl)trackOperation(cached);else renderRevision(cached);return;}
|
|
117
122
|
if(window.__markcutRevision?.path!==expectedPath && window.__markcutRevision?.requestedPath!==expectedPath){
|
|
118
|
-
identity=null;
|
|
123
|
+
identity=null;activeReview={delivery:"text"};
|
|
119
124
|
window.__markcutRevision=null;
|
|
120
125
|
window.dispatchEvent(new CustomEvent('markcut:revision',{detail:null}));
|
|
121
126
|
pathLabel.textContent=expectedPath;
|
|
@@ -123,6 +128,25 @@ function applyToolInput(params){
|
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
let operationGeneration=0;
|
|
131
|
+
function eventEnvelope(template,review){
|
|
132
|
+
if(!template || template.type!=='markcut.review.submitted' || !template.source || !template.data ||
|
|
133
|
+
Object.prototype.hasOwnProperty.call(template.data,'review'))throw new Error('Invalid bound review event template');
|
|
134
|
+
return {type:template.type,source:template.source,data:{...template.data,review}};
|
|
135
|
+
}
|
|
136
|
+
async function sendReviewEvent(result){
|
|
137
|
+
const event=eventEnvelope(activeReview.eventTemplate,result);
|
|
138
|
+
// MCP Apps tools/call is host-mediated; an unavailable or unauthorized Events
|
|
139
|
+
// provider MUST fail, never be substituted with ui/message.
|
|
140
|
+
const response=await request('tools/call',{name:'events',arguments:{command:'publish',args:event}});
|
|
141
|
+
if(response?.isError)throw new Error(response.content?.[0]?.text||'Events MCP rejected review');
|
|
142
|
+
let receipt=response?.structuredContent||response;
|
|
143
|
+
if(!receipt?.published && response?.content?.[0]?.text){
|
|
144
|
+
try{receipt=JSON.parse(response.content[0].text);}catch{}
|
|
145
|
+
}
|
|
146
|
+
if(!receipt?.published && receipt?.result?.published)receipt=receipt.result;
|
|
147
|
+
if(receipt?.published!==true)throw new Error('Events MCP did not acknowledge publish');
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
126
150
|
async function sendDecisionMessage(result){
|
|
127
151
|
for(let attempt=0;attempt<3;attempt++){
|
|
128
152
|
try{await request('ui/message',{role:'user',content:[{type:'text',text:JSON.stringify(result)}]});return true;}catch(e){if(attempt===2){status.textContent='Could not send review to this conversation: '+String(e.message||e);return false;}await new Promise(resolve=>setTimeout(resolve,250*(attempt+1)));}
|
|
@@ -144,7 +168,8 @@ async function trackOperation(data){
|
|
|
144
168
|
if(!response.ok)throw new Error('HTTP '+response.status);
|
|
145
169
|
const progress=await response.json();
|
|
146
170
|
if(generation!==operationGeneration)return;
|
|
147
|
-
if(progress.state==='ready'&&progress.result){renderRevision({...progress.result,requestedPath:data.requestedPath||data.path,
|
|
171
|
+
if(progress.state==='ready'&&progress.result){renderRevision({...progress.result,requestedPath:data.requestedPath||data.path,
|
|
172
|
+
requestId:progress.result.requestId||data.requestId,review:progress.result.review||data.review,relay:data.relay});return;}
|
|
148
173
|
if(progress.state==='failed'){reviewReadonly(true,'Compilation failed: '+progress.error);return;}
|
|
149
174
|
const elapsed=Math.round((Date.now()-(progress.startedAt||Date.now()))/1000);
|
|
150
175
|
status.textContent='Compiling · '+(progress.stage||'working')+' · '+elapsed+'s';
|
|
@@ -170,7 +195,7 @@ async function currentRevisionMatches(path,hash){
|
|
|
170
195
|
const response=await fetch(__MARKCUT_ORIGIN__+'/files/_neoy/markcut/revisions/'+key+'.json?t='+Date.now(),{cache:'no-store'});
|
|
171
196
|
if(!response.ok)throw new Error('Latest preview status unavailable');
|
|
172
197
|
const latest=await response.json();
|
|
173
|
-
return latest.contentHash===hash;
|
|
198
|
+
return latest.contentHash===hash && (!latest.requestId || !identity?.requestId || latest.requestId===identity.requestId);
|
|
174
199
|
}
|
|
175
200
|
function reviewReadonly(readonly,message){
|
|
176
201
|
document.getElementById('approve').disabled=readonly;
|
|
@@ -182,10 +207,11 @@ async function renderRevision(data){
|
|
|
182
207
|
if(identity?.revisionId&&identity.revisionId!==data.revisionId)clearComments();
|
|
183
208
|
if(data.path){pathLabel.textContent=data.path;showVideoName(data.path,data.title||data.videoTitle);}
|
|
184
209
|
if(!data.compiled&&!data.compiledUrl){status.textContent='Compiled scenes unavailable';return;}
|
|
185
|
-
identity={previewId:data.id,revisionId:data.revisionId,contentHash:data.contentHash};
|
|
210
|
+
identity={requestId:data.requestId||data.operationId||data.revisionId,previewId:data.id,revisionId:data.revisionId,contentHash:data.contentHash};
|
|
211
|
+
activeReview=data.review||{delivery:'text'};
|
|
186
212
|
activePath=data.requestedPath||data.path||expectedPath||null;
|
|
187
213
|
activeRelay=data.relay||null;
|
|
188
|
-
if(submittedRevision!==data.revisionId){busy=false;submittedRevision=null;}
|
|
214
|
+
if(submittedRevision!==data.revisionId){busy=false;submittedRevision=null;submission=null;}
|
|
189
215
|
reviewReadonly(true,'Loading static compiled scenes…');
|
|
190
216
|
try{
|
|
191
217
|
let compiled=data.compiled;
|
|
@@ -202,10 +228,17 @@ async function renderRevision(data){
|
|
|
202
228
|
window.__markcutRevision={...data,compiled};
|
|
203
229
|
window.dispatchEvent(new CustomEvent('markcut:revision',{detail:window.__markcutRevision}));
|
|
204
230
|
status.textContent='';
|
|
205
|
-
if(!data.compiledUrl){
|
|
231
|
+
if(!data.compiledUrl){
|
|
232
|
+
reviewReadonly(expectedDelivery==='event' && activeReview.delivery!=='event',
|
|
233
|
+
'Event review configuration unavailable; await an authenticated Provider result.');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
206
236
|
const same=await currentRevisionMatches(activePath,identity.contentHash);
|
|
207
237
|
if(generation!==renderGeneration)return;
|
|
208
|
-
|
|
238
|
+
const unboundEvent=expectedDelivery==='event' && activeReview.delivery!=='event';
|
|
239
|
+
reviewReadonly(!same||unboundEvent,unboundEvent?
|
|
240
|
+
'Event review configuration unavailable; cannot submit from shared media cache.':
|
|
241
|
+
(same?'':'Historical Preview · Read-only'));
|
|
209
242
|
}catch(e){
|
|
210
243
|
if(generation!==renderGeneration)return;
|
|
211
244
|
reviewReadonly(true,'Preview unavailable or review state unverified: '+String(e));
|
|
@@ -228,6 +261,9 @@ async function initialize(){
|
|
|
228
261
|
}
|
|
229
262
|
async function submit(decision){
|
|
230
263
|
if(busy)return;
|
|
264
|
+
if(document.getElementById(decision==='approved'?'approve':'changes').disabled){
|
|
265
|
+
status.textContent='Review disabled for this revision or delivery configuration.';return;
|
|
266
|
+
}
|
|
231
267
|
if(feedback.value.trim()&&(selectedId===null||comments.find(x=>x.id===selectedId)?.text!==feedback.value.trim())){status.textContent='Add or remove the current comment before submitting.';return;}
|
|
232
268
|
const preparedComments=allComments();
|
|
233
269
|
if(decision==='changes_requested'&&!preparedComments.length){status.textContent='Feedback is required.';return;}
|
|
@@ -237,22 +273,30 @@ async function submit(decision){
|
|
|
237
273
|
try{if(!await currentRevisionMatches(activePath,identity.contentHash)){reviewReadonly(true,'Historical Preview · Read-only');return;}}
|
|
238
274
|
catch(e){reviewReadonly(true,'Cannot verify latest preview: '+String(e));return;}
|
|
239
275
|
}
|
|
240
|
-
const result={...identity,decision
|
|
276
|
+
const result={...identity,decision,comments:preparedComments.map(item=>({
|
|
277
|
+
sceneId:item.playbackContext?.sceneId||null,timeSeconds:Number(item.playbackContext?.timeSeconds)||0,
|
|
278
|
+
text:item.text,scope:item.scope,playbackContext:item.playbackContext
|
|
279
|
+
}))};
|
|
280
|
+
// Retain the same submission key across retries, including lost ACKs.
|
|
281
|
+
const signature=JSON.stringify({result,delivery:activeReview.delivery});
|
|
282
|
+
if(!submission || submission.signature!==signature)submission={signature,key:crypto.randomUUID()};
|
|
283
|
+
result.idempotencyKey=submission.key;
|
|
241
284
|
if(activePath)result.path=activePath;
|
|
242
285
|
if(activeRelay)result.relay=activeRelay;
|
|
243
286
|
if(decision==='changes_requested'){
|
|
244
|
-
result.comments=preparedComments;
|
|
245
287
|
result.feedback=preparedComments.length===1?preparedComments[0].text:preparedComments.map((item,index)=>String(index+1)+'. ['+sceneKey(item.playbackContext)+' @ '+(item.playbackContext.timeSeconds??0)+'s] '+item.text).join('\\n');
|
|
246
288
|
if(window.__markcutPlaybackContext)result.playbackContext=window.__markcutPlaybackContext;
|
|
247
289
|
}
|
|
248
|
-
busy=true;status.textContent='Sending review to this conversation…';
|
|
290
|
+
busy=true;status.textContent=activeReview.delivery==='event'?'Publishing review event…':'Sending review to this conversation…';
|
|
249
291
|
const submittedId=result.revisionId;
|
|
250
292
|
try{
|
|
251
|
-
const delivered=await sendDecisionMessage(result);
|
|
293
|
+
const delivered=activeReview.delivery==='event' ? await sendReviewEvent(result) : await sendDecisionMessage(result);
|
|
252
294
|
if(!delivered){busy=false;return;}
|
|
253
|
-
if(identity?.revisionId===submittedId){submittedRevision=submittedId;status.textContent=
|
|
295
|
+
if(identity?.revisionId===submittedId){submittedRevision=submittedId;status.textContent=activeReview.delivery==='event'
|
|
296
|
+
? 'Review event submitted (transport accepted; awaiting consumer).'
|
|
297
|
+
: (decision==='approved'?'Review sent.':'Feedback sent. Waiting for the updated preview.');}
|
|
254
298
|
}
|
|
255
|
-
catch(e){busy=false;status.textContent=e.message||'Unable to submit review';}
|
|
299
|
+
catch(e){busy=false;status.textContent='Review not submitted: '+(e.message||'Unable to submit review');}
|
|
256
300
|
}
|
|
257
301
|
document.getElementById('approve').onclick=()=>submit('approved');
|
|
258
302
|
document.getElementById('changes').onclick=()=>submit('changes_requested');
|
|
@@ -27,7 +27,7 @@ export function writeOperation(id,data){
|
|
|
27
27
|
writeFileSync(temp,JSON.stringify(data),{mode:0o644});
|
|
28
28
|
renameSync(temp,join(folder,id+".json"));
|
|
29
29
|
}
|
|
30
|
-
export function startCompileOperation(path,relay){
|
|
30
|
+
export function startCompileOperation(path,relay,review={delivery:"text"}){
|
|
31
31
|
const valid=validateMarkdownPath(resolvePreviewPath(path));
|
|
32
32
|
if(!statSync(valid).isFile())throw new Error("Preview source must be a Markdown file");
|
|
33
33
|
const input=fingerprintInputs(valid);
|
|
@@ -36,7 +36,7 @@ export function startCompileOperation(path,relay){
|
|
|
36
36
|
const id=randomUUID(),startedAt=Date.now();
|
|
37
37
|
writeOperation(id,{id,state:"compiling",stage:"queued",startedAt,requestedPath:path});
|
|
38
38
|
const worker=fileURLToPath(new URL("./compile-worker.mjs",import.meta.url));
|
|
39
|
-
const child=spawn(process.execPath,[worker,id,valid,path,JSON.stringify(relay||null),sourceHash],{detached:true,stdio:"ignore"});
|
|
39
|
+
const child=spawn(process.execPath,[worker,id,valid,path,JSON.stringify(relay||null),sourceHash,JSON.stringify(review)],{detached:true,stdio:"ignore"});
|
|
40
40
|
child.on("error",e=>{
|
|
41
41
|
writeOperation(id,{id,state:"failed",stage:"failed",startedAt,requestedPath:path,error:e.message});
|
|
42
42
|
});
|
|
@@ -50,5 +50,5 @@ export function startCompileOperation(path,relay){
|
|
|
50
50
|
}catch{}
|
|
51
51
|
});
|
|
52
52
|
child.unref();
|
|
53
|
-
return {operationId:id,operationUrl:publicOrigin()+"/files/_neoy/markcut/operations/"+id+".json",path:valid,requestedPath:path,state:"compiling"};
|
|
53
|
+
return {operationId:id,operationUrl:publicOrigin()+"/files/_neoy/markcut/operations/"+id+".json",path:valid,requestedPath:path,state:"compiling",requestId:id,review};
|
|
54
54
|
}
|
|
@@ -3,8 +3,9 @@ import {ensureVideoPreview} from "./preview.mjs";
|
|
|
3
3
|
import {publishPreviewRevision} from "./remote-assets.mjs";
|
|
4
4
|
import {writeOperation} from "./compile-operation.mjs";
|
|
5
5
|
import {fingerprintInputs} from "./source-fingerprint.mjs";
|
|
6
|
-
const [id,path,requestedPath,relayText,sourceHash]=process.argv.slice(2);
|
|
6
|
+
const [id,path,requestedPath,relayText,sourceHash,reviewText]=process.argv.slice(2);
|
|
7
7
|
const startedAt=Date.now();
|
|
8
|
+
const review=JSON.parse(reviewText||'{"delivery":"text"}');
|
|
8
9
|
function update(stage){writeOperation(id,{id,state:"compiling",stage,startedAt,updatedAt:Date.now(),requestedPath});}
|
|
9
10
|
try{
|
|
10
11
|
update("resolving-and-compiling");
|
|
@@ -14,7 +15,7 @@ try{
|
|
|
14
15
|
const result=await ensureVideoPreview(path,{onProgress:update});
|
|
15
16
|
update("publishing");
|
|
16
17
|
publishPreviewRevision(requestedPath,{...result,requestedPath});
|
|
17
|
-
writeOperation(id,{id,state:"ready",stage:"complete",startedAt,updatedAt:Date.now(),requestedPath,result:{...result,requestedPath,relay:JSON.parse(relayText)}});
|
|
18
|
+
writeOperation(id,{id,state:"ready",stage:"complete",startedAt,updatedAt:Date.now(),requestedPath,result:{...result,requestedPath,requestId:id,review,relay:JSON.parse(relayText)}});
|
|
18
19
|
}catch(e){
|
|
19
20
|
writeOperation(id,{id,state:"failed",stage:"failed",startedAt,updatedAt:Date.now(),requestedPath,error:e?.message||String(e)});
|
|
20
21
|
process.exitCode=1;
|