@copilotkit/mcp-apps-renderer 1.81.0 → 1.82.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.d.mts","names":[],"sources":["../src/sandbox.ts"],"mappings":";;AAwBA;;;;;iBAAgB,mBAAA,CAAoB,uBAAA;;;;;;;;;;;;;;;;iBAmBpB,gBAAA,CAAiB,eAAA"}
1
+ {"version":3,"file":"sandbox.d.mts","names":[],"sources":["../src/sandbox.ts"],"mappings":";;AAwBA;;;;;iBAAgB,mBAAA,CAAoB,uBAAA;;;;;;;;;;;;;;;;iBA4BpB,gBAAA,CAAiB,eAAA"}
package/dist/sandbox.mjs CHANGED
@@ -25,6 +25,13 @@ function ɵmcpAppSandboxFlags(allowSameOriginFallback = false) {
25
25
  return allowSameOriginFallback ? SAME_ORIGIN_SANDBOX_FLAGS : SANDBOX_FLAGS;
26
26
  }
27
27
  /**
28
+ * A CSP host source: optional scheme, host (a leading `*.` allowed), optional
29
+ * port and path. The domains come from the MCP server, so anything else (a
30
+ * space, quote, `;`, `,`, `&` or `<`) could end the policy or the `<meta>` tag
31
+ * early. The path allows CSP's own path characters, such as `+` and `@`.
32
+ */
33
+ const CSP_HOST_SOURCE = /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:\*\.)?[a-z0-9-]+(?:\.[a-z0-9-]+)*(?::(?:\d+|\*))?(?:\/[\w.~%/!$()*+=:@-]*)?$/i;
34
+ /**
28
35
  * Build the sandbox-proxy HTML document loaded into the outer iframe.
29
36
  *
30
37
  * The proxy relays postMessage between the host and the inner sandboxed widget
@@ -42,7 +49,8 @@ function ɵmcpAppSandboxFlags(allowSameOriginFallback = false) {
42
49
  function buildSandboxHTML(extraCspDomains) {
43
50
  const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
44
51
  const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
45
- const extra = extraCspDomains?.length ? " " + extraCspDomains.join(" ") : "";
52
+ const domains = (extraCspDomains ?? []).filter((domain) => typeof domain === "string" && CSP_HOST_SOURCE.test(domain));
53
+ const extra = domains.length ? " " + domains.join(" ") : "";
46
54
  return `<!doctype html>
47
55
  <html>
48
56
  <head>
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.mjs","names":[],"sources":["../src/sandbox.ts"],"sourcesContent":["/**\n * Sandbox flags for both the proxy frame and the widget frame.\n *\n * SEP-1865 grants `allow-same-origin` only together with a Sandbox that has a\n * different origin from the Host. The proxy is loaded via `srcdoc`, which\n * inherits the host origin, so granting `allow-same-origin` here would give\n * the widget the host's cookies, storage and DOM. Without it the widget gets\n * an opaque origin and the postMessage relay still works.\n */\nconst SANDBOX_FLAGS = \"allow-scripts allow-forms\";\n\n/**\n * The flags used before the safe default, kept only for\n * `allowSameOriginFallback`. Unsafe with a `srcdoc` proxy: the widget runs\n * with the host origin.\n */\nconst SAME_ORIGIN_SANDBOX_FLAGS = \"allow-scripts allow-same-origin allow-forms\";\n\n/**\n * The `sandbox` attribute for the proxy and widget frames.\n *\n * @param allowSameOriginFallback Restore `allow-same-origin`. Unsafe: the\n * widget then runs with the host's origin. See `McpAppSessionOptions`.\n */\nexport function ɵmcpAppSandboxFlags(allowSameOriginFallback = false): string {\n return allowSameOriginFallback ? SAME_ORIGIN_SANDBOX_FLAGS : SANDBOX_FLAGS;\n}\n\n/**\n * Build the sandbox-proxy HTML document loaded into the outer iframe.\n *\n * The proxy relays postMessage between the host and the inner sandboxed widget\n * and announces `ui/notifications/sandbox-proxy-ready` once ready. The host\n * sets the widget frame's sandbox flags in `sandbox-resource-ready`; the\n * template default is the safe one. Messages from the widget whose method\n * starts with `ui/notifications/sandbox-` are reserved for the proxy (spec\n * item 6) and are not relayed, so a widget cannot forge the handshake. `extraCspDomains`\n * (from the resource's `_meta.ui.csp`) are appended to the `script-src`/`frame-src`\n * CSP directives so a widget can load its own approved origins.\n *\n * @param extraCspDomains Optional additional origins allowed by the sandbox CSP.\n * @returns The complete sandbox-proxy HTML document as a string.\n */\nexport function buildSandboxHTML(extraCspDomains?: string[]): string {\n const baseScriptSrc =\n \"'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*\";\n const baseFrameSrc = \"* blob: data: http://localhost:* https://localhost:*\";\n const extra = extraCspDomains?.length ? \" \" + extraCspDomains.join(\" \") : \"\";\n const scriptSrc = baseScriptSrc + extra;\n const frameSrc = baseFrameSrc + extra;\n\n return `<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\" />\n<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${scriptSrc}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${frameSrc}; base-uri 'self';\" />\n<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>\n</head>\n<body>\n<script>\nif(window.self===window.top){throw new Error(\"This file must be used in an iframe.\")}\nconst inner=document.createElement(\"iframe\");\ninner.style=\"width:100%;height:100%;border:none;\";\ninner.setAttribute(\"sandbox\",\"${SANDBOX_FLAGS}\");\ndocument.body.appendChild(inner);\nwindow.addEventListener(\"message\",async(event)=>{\nif(event.source===window.parent){\nif(event.data&&event.data.method===\"ui/notifications/sandbox-resource-ready\"){\nconst{html,sandbox}=event.data.params;\nif(typeof sandbox===\"string\")inner.setAttribute(\"sandbox\",sandbox);\nif(typeof html===\"string\")inner.srcdoc=html;\n}else if(inner&&inner.contentWindow){\ninner.contentWindow.postMessage(event.data,\"*\");\n}\n}else if(event.source===inner.contentWindow){\nif(event.data&&typeof event.data.method===\"string\"&&event.data.method.startsWith(\"ui/notifications/sandbox-\"))return;\nwindow.parent.postMessage(event.data,\"*\");\n}\n});\nwindow.parent.postMessage({jsonrpc:\"2.0\",method:\"ui/notifications/sandbox-proxy-ready\",params:{}},\"*\");\n</script>\n</body>\n</html>`;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,gBAAgB;;;;;;AAOtB,MAAM,4BAA4B;;;;;;;AAQlC,SAAgB,oBAAoB,0BAA0B,OAAe;AAC3E,QAAO,0BAA0B,4BAA4B;;;;;;;;;;;;;;;;;AAkB/D,SAAgB,iBAAiB,iBAAoC;CACnE,MAAM,gBACJ;CACF,MAAM,eAAe;CACrB,MAAM,QAAQ,iBAAiB,SAAS,MAAM,gBAAgB,KAAK,IAAI,GAAG;AAI1E,QAAO;;;;6KAHW,gBAAgB,MAOmJ,sEANpK,eAAe,MAMoO;;;;;;;;gCAQtO,cAAc"}
1
+ {"version":3,"file":"sandbox.mjs","names":[],"sources":["../src/sandbox.ts"],"sourcesContent":["/**\n * Sandbox flags for both the proxy frame and the widget frame.\n *\n * SEP-1865 grants `allow-same-origin` only together with a Sandbox that has a\n * different origin from the Host. The proxy is loaded via `srcdoc`, which\n * inherits the host origin, so granting `allow-same-origin` here would give\n * the widget the host's cookies, storage and DOM. Without it the widget gets\n * an opaque origin and the postMessage relay still works.\n */\nconst SANDBOX_FLAGS = \"allow-scripts allow-forms\";\n\n/**\n * The flags used before the safe default, kept only for\n * `allowSameOriginFallback`. Unsafe with a `srcdoc` proxy: the widget runs\n * with the host origin.\n */\nconst SAME_ORIGIN_SANDBOX_FLAGS = \"allow-scripts allow-same-origin allow-forms\";\n\n/**\n * The `sandbox` attribute for the proxy and widget frames.\n *\n * @param allowSameOriginFallback Restore `allow-same-origin`. Unsafe: the\n * widget then runs with the host's origin. See `McpAppSessionOptions`.\n */\nexport function ɵmcpAppSandboxFlags(allowSameOriginFallback = false): string {\n return allowSameOriginFallback ? SAME_ORIGIN_SANDBOX_FLAGS : SANDBOX_FLAGS;\n}\n\n/**\n * A CSP host source: optional scheme, host (a leading `*.` allowed), optional\n * port and path. The domains come from the MCP server, so anything else (a\n * space, quote, `;`, `,`, `&` or `<`) could end the policy or the `<meta>` tag\n * early. The path allows CSP's own path characters, such as `+` and `@`.\n */\nconst CSP_HOST_SOURCE =\n /^(?:[a-z][a-z0-9+.-]*:\\/\\/)?(?:\\*\\.)?[a-z0-9-]+(?:\\.[a-z0-9-]+)*(?::(?:\\d+|\\*))?(?:\\/[\\w.~%/!$()*+=:@-]*)?$/i;\n\n/**\n * Build the sandbox-proxy HTML document loaded into the outer iframe.\n *\n * The proxy relays postMessage between the host and the inner sandboxed widget\n * and announces `ui/notifications/sandbox-proxy-ready` once ready. The host\n * sets the widget frame's sandbox flags in `sandbox-resource-ready`; the\n * template default is the safe one. Messages from the widget whose method\n * starts with `ui/notifications/sandbox-` are reserved for the proxy (spec\n * item 6) and are not relayed, so a widget cannot forge the handshake. `extraCspDomains`\n * (from the resource's `_meta.ui.csp`) are appended to the `script-src`/`frame-src`\n * CSP directives so a widget can load its own approved origins.\n *\n * @param extraCspDomains Optional additional origins allowed by the sandbox CSP.\n * @returns The complete sandbox-proxy HTML document as a string.\n */\nexport function buildSandboxHTML(extraCspDomains?: string[]): string {\n const baseScriptSrc =\n \"'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*\";\n const baseFrameSrc = \"* blob: data: http://localhost:* https://localhost:*\";\n const domains = (extraCspDomains ?? []).filter(\n (domain) => typeof domain === \"string\" && CSP_HOST_SOURCE.test(domain),\n );\n const extra = domains.length ? \" \" + domains.join(\" \") : \"\";\n const scriptSrc = baseScriptSrc + extra;\n const frameSrc = baseFrameSrc + extra;\n\n return `<!doctype html>\n<html>\n<head>\n<meta charset=\"utf-8\" />\n<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${scriptSrc}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${frameSrc}; base-uri 'self';\" />\n<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>\n</head>\n<body>\n<script>\nif(window.self===window.top){throw new Error(\"This file must be used in an iframe.\")}\nconst inner=document.createElement(\"iframe\");\ninner.style=\"width:100%;height:100%;border:none;\";\ninner.setAttribute(\"sandbox\",\"${SANDBOX_FLAGS}\");\ndocument.body.appendChild(inner);\nwindow.addEventListener(\"message\",async(event)=>{\nif(event.source===window.parent){\nif(event.data&&event.data.method===\"ui/notifications/sandbox-resource-ready\"){\nconst{html,sandbox}=event.data.params;\nif(typeof sandbox===\"string\")inner.setAttribute(\"sandbox\",sandbox);\nif(typeof html===\"string\")inner.srcdoc=html;\n}else if(inner&&inner.contentWindow){\ninner.contentWindow.postMessage(event.data,\"*\");\n}\n}else if(event.source===inner.contentWindow){\nif(event.data&&typeof event.data.method===\"string\"&&event.data.method.startsWith(\"ui/notifications/sandbox-\"))return;\nwindow.parent.postMessage(event.data,\"*\");\n}\n});\nwindow.parent.postMessage({jsonrpc:\"2.0\",method:\"ui/notifications/sandbox-proxy-ready\",params:{}},\"*\");\n</script>\n</body>\n</html>`;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAM,gBAAgB;;;;;;AAOtB,MAAM,4BAA4B;;;;;;;AAQlC,SAAgB,oBAAoB,0BAA0B,OAAe;AAC3E,QAAO,0BAA0B,4BAA4B;;;;;;;;AAS/D,MAAM,kBACJ;;;;;;;;;;;;;;;;AAiBF,SAAgB,iBAAiB,iBAAoC;CACnE,MAAM,gBACJ;CACF,MAAM,eAAe;CACrB,MAAM,WAAW,mBAAmB,EAAE,EAAE,QACrC,WAAW,OAAO,WAAW,YAAY,gBAAgB,KAAK,OAAO,CACvE;CACD,MAAM,QAAQ,QAAQ,SAAS,MAAM,QAAQ,KAAK,IAAI,GAAG;AAIzD,QAAO;;;;6KAHW,gBAAgB,MAOmJ,sEANpK,eAAe,MAMoO;;;;;;;;gCAQtO,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/mcp-apps-renderer",
3
- "version": "1.81.0",
3
+ "version": "1.82.0",
4
4
  "private": false,
5
5
  "description": "Framework-agnostic MCP Apps host for CopilotKit - the app<->host protocol (ext-apps AppBridge), sandbox proxy, and shared renderer consumed by the React, Vue, and Angular frontends",
6
6
  "keywords": [
@@ -50,7 +50,7 @@
50
50
  "dependencies": {
51
51
  "@modelcontextprotocol/ext-apps": "^1.7.5",
52
52
  "@modelcontextprotocol/sdk": "^1.29.0",
53
- "@copilotkit/shared": "1.81.0"
53
+ "@copilotkit/shared": "1.82.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@ag-ui/client": ">=0.0.59",