Files
melMass-comfy_mtb/web/alchemy.js
T
Mel Massadian 9725ed1366 feat(web): add alchemy bridge and mtb api extensions
- register alchemy bridge extension for cross-window workflow communication
- enable loading, serialization, and queuing of workflows via postMessage api
2026-01-18 19:58:05 +00:00

48 lines
1.2 KiB
JavaScript

import { app } from "../../scripts/app.js";
app.registerExtension({
name: "PromptAlchemy.Bridge",
setup() {
// Listen for messages from parent window
window.addEventListener('message', async (event) => {
// Optionally verify origin
const { type, ...payload } = event.data || {};
switch (type) {
case 'loadWorkflow':
await app.loadGraphData(payload.workflow);
this.sendToParent({ type: 'workflowLoaded' });
break;
case 'getWorkflow':
const workflow = app.graph.serialize();
this.sendToParent({ type: 'workflow', workflow });
break;
case 'queuePrompt':
app.queuePrompt(0); // 0 = front of queue
break;
case 'getPrompt':
const prompt = await app.graphToPrompt();
this.sendToParent({ type: 'prompt', prompt });
break;
}
});
console.log("Alchemy Bridge Extension Loaded");
// Notify parent we're ready
this.sendToParent({ type: 'ready' });
},
sendToParent(data) {
if (window.parent !== window) {
window.parent.postMessage(data, '*');
}
}
});