@lalalic/markcut 3.2.40 → 3.2.41
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/review-delivery.mjs +47 -0
- package/src/mcp/server.mjs +5 -3
- package/tests/mcp-preview-bridge.test.ts +58 -1
- package/tests/mcp-preview-delivery.test.ts +33 -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;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Provider-side validation: the UI cannot invent an event destination or a Relay terminal event.
|
|
2
|
+
const ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
3
|
+
const SOURCE = /^job\/[A-Za-z0-9_-]+\/task\/[A-Za-z0-9_-]+\/execution\/[A-Za-z0-9_-]+$/;
|
|
4
|
+
const RECORD = value => value && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
function copyData(value) {
|
|
6
|
+
if (!RECORD(value)) throw new Error("eventTemplate.data must be an object");
|
|
7
|
+
// No executable values or reserved overrides can be shipped in a template.
|
|
8
|
+
const encoded=JSON.stringify(value);
|
|
9
|
+
if (!encoded || encoded.length > 12000) throw new Error("Invalid eventTemplate.data");
|
|
10
|
+
const clean=JSON.parse(encoded);
|
|
11
|
+
const walk=(node)=>{
|
|
12
|
+
if (!node || typeof node !== "object") return;
|
|
13
|
+
for (const [key, val] of Object.entries(node)) {
|
|
14
|
+
if (["__proto__", "constructor", "prototype"].includes(key)) throw new Error("Unsafe eventTemplate data");
|
|
15
|
+
walk(val);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
walk(clean);
|
|
19
|
+
if (Object.hasOwn(clean,"review")) throw new Error("data.review is reserved for the human result");
|
|
20
|
+
return clean;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeReviewConfig(value) {
|
|
23
|
+
if (value === undefined) return {delivery:"text"};
|
|
24
|
+
if (!RECORD(value) || !["text","event"].includes(value.delivery ?? "text")) throw new Error("Unsupported review delivery");
|
|
25
|
+
if (value.delivery !== "event") {
|
|
26
|
+
if (value.eventTemplate !== undefined) throw new Error("eventTemplate requires event delivery");
|
|
27
|
+
return {delivery:"text"};
|
|
28
|
+
}
|
|
29
|
+
const template=value.eventTemplate;
|
|
30
|
+
if (!RECORD(template) || template.type!=="markcut.review.submitted"
|
|
31
|
+
|| typeof template.source!=="string" || !SOURCE.test(template.source)
|
|
32
|
+
|| !RECORD(template.data)) throw new Error("Invalid review event template");
|
|
33
|
+
if (Object.keys(template).some(key=>!["type","source","data"].includes(key))) throw new Error("Unexpected eventTemplate fields");
|
|
34
|
+
return {delivery:"event",eventTemplate:{
|
|
35
|
+
type:template.type,source:template.source,data:copyData(template.data),
|
|
36
|
+
}};
|
|
37
|
+
}
|
|
38
|
+
export function eventForReview(config,review) {
|
|
39
|
+
const {eventTemplate:template}=normalizeReviewConfig(config);
|
|
40
|
+
if (!template) throw new Error("Event mode required");
|
|
41
|
+
if (!RECORD(review) || !ID.test(review.requestId || "") || !ID.test(review.revisionId || "")
|
|
42
|
+
|| !/^[a-f0-9]{64}$/.test(review.contentHash || "")
|
|
43
|
+
|| !["approved","changes_requested"].includes(review.decision)
|
|
44
|
+
|| !ID.test(review.idempotencyKey || "") || !Array.isArray(review.comments))
|
|
45
|
+
throw new Error("Invalid review result");
|
|
46
|
+
return {type:template.type,source:template.source,data:{...template.data,review:structuredClone(review)}};
|
|
47
|
+
}
|
package/src/mcp/server.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { McpServer } from "@modelcontextprotocol/server";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
4
4
|
import { registerAppResource, registerAppTool } from "@modelcontextprotocol/ext-apps/server";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import {normalizeReviewConfig} from "./review-delivery.mjs";
|
|
6
7
|
import {publishPreviewRevision,publishPlayerBundle,publicOrigin} from "./remote-assets.mjs";
|
|
7
8
|
import {fileURLToPath} from "node:url";
|
|
8
9
|
import {startCompileOperation} from "./compile-operation.mjs";
|
|
@@ -46,18 +47,19 @@ registerAppTool(
|
|
|
46
47
|
server,
|
|
47
48
|
TOOL_NAME,
|
|
48
49
|
{
|
|
49
|
-
description: "Compile and publish an immutable Markcut preview revision for this ChatGPT conversation.
|
|
50
|
+
description: "Compile and publish an immutable Markcut preview revision for this ChatGPT conversation. Review delivery defaults to ui/message, or submits an authorized caller-bound event when explicitly configured. Approval applies only to the exact contentHash shown.",
|
|
50
51
|
inputSchema: z.object({
|
|
51
52
|
path: z.string().describe("Absolute .md path or NeoY HTTPS mounted file URL"),
|
|
53
|
+
review: z.object({delivery:z.enum(["text","event"]).optional(),eventTemplate:z.object({type:z.string(),source:z.string(),data:z.record(z.string(),z.unknown())}).optional()}).optional(),
|
|
52
54
|
relay: z.object({jobId:z.string(),taskId:z.union([z.string(),z.number()]),executionId:z.string().optional()}).optional().describe("Optional Agents Relay task correlation. No Relay dependency for standalone ChatGPT/Work reviews."),
|
|
53
55
|
}),
|
|
54
56
|
_meta: {
|
|
55
57
|
ui: { resourceUri: RESOURCE_URI },
|
|
56
58
|
},
|
|
57
59
|
},
|
|
58
|
-
async ({ path, relay }) => {
|
|
60
|
+
async ({ path, relay, review }) => {
|
|
59
61
|
try {
|
|
60
|
-
const operation=startCompileOperation(path,relay);
|
|
62
|
+
const operation=startCompileOperation(path,relay,normalizeReviewConfig(review));
|
|
61
63
|
const payload={...operation,...(relay ? {relay} : {})};
|
|
62
64
|
return {
|
|
63
65
|
content: [{ type: "text", text: `Compilation started: ${operation.path}` }],
|
|
@@ -43,6 +43,20 @@ describe('MCP Remotion bridge',()=>{
|
|
|
43
43
|
expect(h.events.at(-1)?.detail?.revisionId).toBe('remote-r1');
|
|
44
44
|
expect(h.nodes.status.textContent).toBe('');
|
|
45
45
|
});
|
|
46
|
+
it("never reconstructs event destinations from another caller's path cache",async()=>{
|
|
47
|
+
const path='/shared-video.md';
|
|
48
|
+
const remote={id:'shared',revisionId:'rev1',contentHash:'a'.repeat(64),requestedPath:path,
|
|
49
|
+
compiled:{children:[{name:'Shared'}]}};
|
|
50
|
+
const h=harness(remote);
|
|
51
|
+
h.dispatch({method:'ui/notifications/tool-input',params:{arguments:{path,
|
|
52
|
+
review:{delivery:'event',eventTemplate:{type:'markcut.review.submitted',
|
|
53
|
+
source:'job/a/task/b/execution/c',data:{correlation:{secret:'other'}}}}}}});
|
|
54
|
+
for(let i=0;i<20&&!h.events.some(e=>e.detail?.revisionId==='rev1');i++)await nextTick();
|
|
55
|
+
expect(h.events.some(e=>e.detail?.revisionId==='rev1')).toBe(true);
|
|
56
|
+
expect(h.nodes.approve.disabled).toBe(true);
|
|
57
|
+
h.nodes.approve.onclick?.();
|
|
58
|
+
expect(h.messages.filter(m=>m.method==='tools/call'||m.method==='ui/message')).toHaveLength(0);
|
|
59
|
+
});
|
|
46
60
|
it('initializes, delivers compiled scenes and sends review directly to the caller',async()=>{
|
|
47
61
|
const h=harness();
|
|
48
62
|
expect(h.messages[0]).toMatchObject({id:1,method:'ui/initialize'});
|
|
@@ -59,7 +73,8 @@ describe('MCP Remotion bridge',()=>{
|
|
|
59
73
|
expect(h.messages.filter(m=>m.method==='tools/call')).toHaveLength(0);
|
|
60
74
|
await nextTick();
|
|
61
75
|
const notification=h.messages.find(m=>m.method==='ui/message');
|
|
62
|
-
expect(JSON.parse(notification.params.content[0].text)).
|
|
76
|
+
expect(JSON.parse(notification.params.content[0].text)).toMatchObject({requestId:'rev1',previewId:'one',revisionId:'rev1',contentHash:'a'.repeat(64),path:'/tmp/a.md',decision:'approved',comments:[]});
|
|
77
|
+
expect(JSON.parse(notification.params.content[0].text).idempotencyKey).toMatch(/^[a-f0-9-]{36}$/);
|
|
63
78
|
h.respond(notification.id);
|
|
64
79
|
await nextTick();
|
|
65
80
|
expect(h.nodes.status.textContent).toBe('Review sent.');
|
|
@@ -344,3 +359,45 @@ describe('async compilation UI transition',()=>{
|
|
|
344
359
|
expect(h.nodes.status.textContent).toContain('TTS unavailable');
|
|
345
360
|
});
|
|
346
361
|
});
|
|
362
|
+
|
|
363
|
+
describe('Review event delivery',()=>{
|
|
364
|
+
const template={type:'markcut.review.submitted',
|
|
365
|
+
source:'job/551/task/producer/execution/e1',data:{correlation:{jobId:'551'},purpose:'video'}};
|
|
366
|
+
const media={id:'video1',requestId:'d9b2006a-0618-45aa-a3d8-31363fa629ca',revisionId:'rv1',
|
|
367
|
+
contentHash:'a'.repeat(64),path:'/tmp/video.md',compiled:{children:[]},review:{delivery:'event',eventTemplate:template}};
|
|
368
|
+
it('does not publish until explicit Submit, preserves fixed envelope and scoped comments',async()=>{
|
|
369
|
+
const h=harness(undefined,undefined, m=> m.method==='tools/call'?{published:true,event:{event_id:'ack'}}:undefined);
|
|
370
|
+
h.result(media);h.scene({sceneId:'intro',timeSeconds:2.25,sceneStart:0});
|
|
371
|
+
h.nodes.feedback.value='Trim opening';h.nodes['save-spot'].onclick?.();
|
|
372
|
+
expect(h.messages.filter(m=>m.method==='tools/call')).toHaveLength(0);
|
|
373
|
+
h.nodes.changes.onclick?.();await nextTick();
|
|
374
|
+
const calls=h.messages.filter(m=>m.method==='tools/call');
|
|
375
|
+
expect(calls).toHaveLength(1);
|
|
376
|
+
expect(calls[0]).toMatchObject({params:{name:'events',arguments:{command:'publish',
|
|
377
|
+
args:{type:template.type,source:template.source,data:{correlation:template.data.correlation,purpose:'video',
|
|
378
|
+
review:{requestId:media.requestId,revisionId:media.revisionId,contentHash:media.contentHash,
|
|
379
|
+
decision:'changes_requested',comments:[{sceneId:'intro',timeSeconds:2.25,text:'Trim opening'}]}}}}}});
|
|
380
|
+
expect(h.messages.filter(m=>m.method==='ui/message')).toHaveLength(0);
|
|
381
|
+
expect(h.nodes.status.textContent).toContain('submitted');
|
|
382
|
+
});
|
|
383
|
+
it('fails visibly without host Events access and reuses the idempotency key on retry',async()=>{
|
|
384
|
+
const h=harness(undefined,undefined,m=>m.method==='tools/call'?{rpcError:{message:'Host denies cross-server tool'}}:undefined);
|
|
385
|
+
h.result(media);h.nodes.approve.onclick?.();await nextTick();await nextTick();
|
|
386
|
+
expect(h.nodes.status.textContent).toContain('Review not submitted');
|
|
387
|
+
h.nodes.approve.onclick?.();await nextTick();await nextTick();
|
|
388
|
+
const calls=h.messages.filter(m=>m.method==='tools/call');
|
|
389
|
+
expect(calls).toHaveLength(2);
|
|
390
|
+
expect(calls[0].params.arguments.args.data.review.idempotencyKey)
|
|
391
|
+
.toBe(calls[1].params.arguments.args.data.review.idempotencyKey);
|
|
392
|
+
expect(h.messages.filter(m=>m.method==='ui/message')).toHaveLength(0);
|
|
393
|
+
});
|
|
394
|
+
it('rejects non-acknowledging host and prevents a second submit after acceptance',async()=>{
|
|
395
|
+
let accepted=false;
|
|
396
|
+
const h=harness(undefined,undefined,m=>m.method==='tools/call'?{published:accepted}:undefined);
|
|
397
|
+
h.result(media);h.nodes.approve.onclick?.();await nextTick();await nextTick();
|
|
398
|
+
expect(h.nodes.status.textContent).toContain('not submitted');
|
|
399
|
+
accepted=true;h.nodes.approve.onclick?.();await nextTick();await nextTick();
|
|
400
|
+
h.nodes.approve.onclick?.();
|
|
401
|
+
expect(h.messages.filter(m=>m.method==='tools/call')).toHaveLength(2);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {describe,it,expect} from 'vitest';
|
|
2
|
+
import {normalizeReviewConfig,eventForReview} from '../src/mcp/review-delivery.mjs';
|
|
3
|
+
|
|
4
|
+
const template={type:'markcut.review.submitted',source:'job/j1/task/t1/execution/e1',data:{job:'j1',meta:{source:'ok'}}};
|
|
5
|
+
const review={requestId:'r1',previewId:'p1',revisionId:'rev1',contentHash:'a'.repeat(64),
|
|
6
|
+
decision:'changes_requested',comments:[{sceneId:'intro',timeSeconds:3.2,text:'Shorter intro'}],idempotencyKey:'key1'};
|
|
7
|
+
|
|
8
|
+
describe('Provider-bound preview delivery',()=>{
|
|
9
|
+
it('defaults to text and disallows a third delivery mode',()=>{
|
|
10
|
+
expect(normalizeReviewConfig(undefined)).toEqual({delivery:'text'});
|
|
11
|
+
expect(normalizeReviewConfig({delivery:'text'})).toEqual({delivery:'text'});
|
|
12
|
+
expect(()=>normalizeReviewConfig({delivery:'callback'})).toThrow();
|
|
13
|
+
expect(()=>normalizeReviewConfig({delivery:'event'})).toThrow();
|
|
14
|
+
});
|
|
15
|
+
it('rejects terminal event spoofing, arbitrary source and reserved data overrides',()=>{
|
|
16
|
+
expect(()=>normalizeReviewConfig({delivery:'event',eventTemplate:{...template,type:'task.completed'}})).toThrow();
|
|
17
|
+
expect(()=>normalizeReviewConfig({delivery:'event',eventTemplate:{...template,source:'job/a/task/b/execution/e/forged'}})).toThrow();
|
|
18
|
+
expect(()=>normalizeReviewConfig({delivery:'event',eventTemplate:{...template,data:{review:{decision:'approved'}}}})).toThrow();
|
|
19
|
+
});
|
|
20
|
+
it('retains caller-owned envelope and only fills data.review',()=>{
|
|
21
|
+
const config=normalizeReviewConfig({delivery:'event',eventTemplate:template});
|
|
22
|
+
template.data.meta.source='changed after validation';
|
|
23
|
+
const event=eventForReview(config,review);
|
|
24
|
+
expect(event).toMatchObject({type:'markcut.review.submitted',source:template.source,
|
|
25
|
+
data:{job:'j1',meta:{source:'ok'},review}});
|
|
26
|
+
expect(event.data.review.idempotencyKey).toBe('key1');
|
|
27
|
+
});
|
|
28
|
+
it('refuses malformed review identity or decision',()=>{
|
|
29
|
+
const config=normalizeReviewConfig({delivery:'event',eventTemplate:template});
|
|
30
|
+
expect(()=>eventForReview(config,{...review,contentHash:'bogus'})).toThrow();
|
|
31
|
+
expect(()=>eventForReview(config,{...review,decision:'task.completed'})).toThrow();
|
|
32
|
+
});
|
|
33
|
+
});
|