CMMS embedding: AI Assistant editor-buffer bridge
App.tsx gains a postMessage listener (gated on window.CMMS_SCAD_CONFIG) that answers 'cmms-ai-editor-get-buffer' with model.source and applies an 'cmms-ai-editor-apply' rewrite via model.source = new_source. Lets the CMMS AI Assistant read and rewrite the live editor buffer. Standalone use is untouched.
This commit is contained in:
parent
0e80cde156
commit
57c0672624
1 changed files with 22 additions and 0 deletions
|
|
@ -37,6 +37,28 @@ export function App({initialState, statePersister, fs}: {initialState: State, st
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// CMMS AI Assistant editor-buffer bridge (patch, not upstream). Gated on
|
||||||
|
// window.CMMS_SCAD_CONFIG so standalone use is untouched. The embedded chat
|
||||||
|
// (injected by public/vendor/openscad-playground/edit.php) postMessages the
|
||||||
|
// parent window for the current source before each turn and pushes an AI
|
||||||
|
// rewrite back the same way. No dep array: `model` is recreated every render,
|
||||||
|
// so the listener is re-bound each time to keep model.source current.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!(window as any).CMMS_SCAD_CONFIG) return;
|
||||||
|
const onMessage = (event: MessageEvent) => {
|
||||||
|
if (event.origin !== window.location.origin || !event.data || typeof event.data !== 'object') return;
|
||||||
|
const data = event.data as any;
|
||||||
|
if (data.type === 'cmms-ai-editor-get-buffer') {
|
||||||
|
const source = event.source as WindowProxy | null;
|
||||||
|
source?.postMessage({ type: 'cmms-ai-editor-buffer', buffer: model.source }, window.location.origin);
|
||||||
|
} else if (data.type === 'cmms-ai-editor-apply' && data.editor === 'scad' && typeof data.new_source === 'string') {
|
||||||
|
model.source = data.new_source;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('message', onMessage);
|
||||||
|
return () => window.removeEventListener('message', onMessage);
|
||||||
|
});
|
||||||
|
|
||||||
const zIndexOfPanelsDependingOnFocus = {
|
const zIndexOfPanelsDependingOnFocus = {
|
||||||
editor: {
|
editor: {
|
||||||
editor: 3,
|
editor: 3,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue