-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathrenderer.ts
More file actions
65 lines (62 loc) · 1.89 KB
/
Copy pathrenderer.ts
File metadata and controls
65 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// OpenGenerativeUI document assembly for the MCP server.
// Design-system CSS is single-sourced from @repo/design-system.
import { THEME_CSS, SVG_CLASSES_CSS, FORM_STYLES_CSS } from "@repo/design-system";
const BRIDGE_JS = `
window.sendPrompt = function(text) {
window.parent.postMessage({ type: 'send-prompt', text: text }, '*');
};
window.openLink = function(url) {
window.parent.postMessage({ type: 'open-link', url: url }, '*');
};
document.addEventListener('click', function(e) {
var a = e.target.closest('a[href]');
if (a && a.href.startsWith('http')) {
e.preventDefault();
window.parent.postMessage({ type: 'open-link', url: a.href }, '*');
}
});
function reportHeight() {
var content = document.getElementById('content');
var h = content ? content.offsetHeight : document.documentElement.scrollHeight;
window.parent.postMessage({ type: 'widget-resize', height: h }, '*');
}
var ro = new ResizeObserver(reportHeight);
ro.observe(document.getElementById('content') || document.body);
window.addEventListener('load', reportHeight);
var _resizeInterval = setInterval(reportHeight, 200);
setTimeout(function() { clearInterval(_resizeInterval); }, 15000);
`;
export function assembleDocument(html: string): string {
return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'unsafe-inline' 'unsafe-eval'
https://cdnjs.cloudflare.com
https://esm.sh
https://cdn.jsdelivr.net
https://unpkg.com;
style-src 'unsafe-inline';
img-src 'self' data: blob:;
font-src 'self' data:;
connect-src 'self';
">
<style>
${THEME_CSS}
${SVG_CLASSES_CSS}
${FORM_STYLES_CSS}
</style>
</head>
<body>
<div id="content">
${html}
</div>
<script>
${BRIDGE_JS}
</script>
</body>
</html>`;
}