@dudko.dev/agent-web-ui 0.0.0 → 0.0.1

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.
Files changed (273) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-4EHUITGU.js +342 -0
  10. package/dist/chunk-4EHUITGU.js.map +1 -0
  11. package/dist/chunk-7O64ZI6Z.js +125 -0
  12. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  13. package/dist/chunk-A55Q377T.js +342 -0
  14. package/dist/chunk-A55Q377T.js.map +1 -0
  15. package/dist/chunk-EL2YCROY.js +127 -0
  16. package/dist/chunk-EL2YCROY.js.map +1 -0
  17. package/dist/chunk-GB7RZJMG.js +98 -0
  18. package/dist/chunk-GB7RZJMG.js.map +1 -0
  19. package/dist/chunk-KZQB35LS.js +22 -0
  20. package/dist/chunk-KZQB35LS.js.map +1 -0
  21. package/dist/chunk-P2F2P3JC.js +400 -0
  22. package/dist/chunk-P2F2P3JC.js.map +1 -0
  23. package/dist/chunk-TPK25QGK.js +342 -0
  24. package/dist/chunk-TPK25QGK.js.map +1 -0
  25. package/dist/en-CcNUz2tN.d.cts +342 -0
  26. package/dist/en-CcNUz2tN.d.ts +342 -0
  27. package/dist/index.cjs +4143 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +919 -0
  30. package/dist/index.d.ts +919 -0
  31. package/dist/index.js +3771 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/labels-B5xpIGf_.d.cts +25 -0
  34. package/dist/labels-B5xpIGf_.d.ts +25 -0
  35. package/dist/labels-D5BrHct4.d.cts +1208 -0
  36. package/dist/labels-UuWI7wPo.d.ts +1208 -0
  37. package/dist/locales/be.cjs +794 -0
  38. package/dist/locales/be.cjs.map +1 -0
  39. package/dist/locales/be.d.cts +14 -0
  40. package/dist/locales/be.d.ts +14 -0
  41. package/dist/locales/be.js +374 -0
  42. package/dist/locales/be.js.map +1 -0
  43. package/dist/locales/bg.cjs +747 -0
  44. package/dist/locales/bg.cjs.map +1 -0
  45. package/dist/locales/bg.d.cts +14 -0
  46. package/dist/locales/bg.d.ts +14 -0
  47. package/dist/locales/bg.js +327 -0
  48. package/dist/locales/bg.js.map +1 -0
  49. package/dist/locales/ca.cjs +773 -0
  50. package/dist/locales/ca.cjs.map +1 -0
  51. package/dist/locales/ca.d.cts +14 -0
  52. package/dist/locales/ca.d.ts +14 -0
  53. package/dist/locales/ca.js +353 -0
  54. package/dist/locales/ca.js.map +1 -0
  55. package/dist/locales/cs.cjs +794 -0
  56. package/dist/locales/cs.cjs.map +1 -0
  57. package/dist/locales/cs.d.cts +14 -0
  58. package/dist/locales/cs.d.ts +14 -0
  59. package/dist/locales/cs.js +374 -0
  60. package/dist/locales/cs.js.map +1 -0
  61. package/dist/locales/da.cjs +747 -0
  62. package/dist/locales/da.cjs.map +1 -0
  63. package/dist/locales/da.d.cts +14 -0
  64. package/dist/locales/da.d.ts +14 -0
  65. package/dist/locales/da.js +327 -0
  66. package/dist/locales/da.js.map +1 -0
  67. package/dist/locales/de.cjs +756 -0
  68. package/dist/locales/de.cjs.map +1 -0
  69. package/dist/locales/de.d.cts +14 -0
  70. package/dist/locales/de.d.ts +14 -0
  71. package/dist/locales/de.js +336 -0
  72. package/dist/locales/de.js.map +1 -0
  73. package/dist/locales/el.cjs +756 -0
  74. package/dist/locales/el.cjs.map +1 -0
  75. package/dist/locales/el.d.cts +14 -0
  76. package/dist/locales/el.d.ts +14 -0
  77. package/dist/locales/el.js +336 -0
  78. package/dist/locales/el.js.map +1 -0
  79. package/dist/locales/en.cjs +753 -0
  80. package/dist/locales/en.cjs.map +1 -0
  81. package/dist/locales/en.d.cts +10 -0
  82. package/dist/locales/en.d.ts +10 -0
  83. package/dist/locales/en.js +333 -0
  84. package/dist/locales/en.js.map +1 -0
  85. package/dist/locales/es-419.cjs +778 -0
  86. package/dist/locales/es-419.cjs.map +1 -0
  87. package/dist/locales/es-419.d.cts +16 -0
  88. package/dist/locales/es-419.d.ts +16 -0
  89. package/dist/locales/es-419.js +23 -0
  90. package/dist/locales/es-419.js.map +1 -0
  91. package/dist/locales/es.cjs +769 -0
  92. package/dist/locales/es.cjs.map +1 -0
  93. package/dist/locales/es.d.cts +14 -0
  94. package/dist/locales/es.d.ts +14 -0
  95. package/dist/locales/es.js +14 -0
  96. package/dist/locales/es.js.map +1 -0
  97. package/dist/locales/fi.cjs +753 -0
  98. package/dist/locales/fi.cjs.map +1 -0
  99. package/dist/locales/fi.d.cts +14 -0
  100. package/dist/locales/fi.d.ts +14 -0
  101. package/dist/locales/fi.js +333 -0
  102. package/dist/locales/fi.js.map +1 -0
  103. package/dist/locales/fr-CA.cjs +777 -0
  104. package/dist/locales/fr-CA.cjs.map +1 -0
  105. package/dist/locales/fr-CA.d.cts +17 -0
  106. package/dist/locales/fr-CA.d.ts +17 -0
  107. package/dist/locales/fr-CA.js +22 -0
  108. package/dist/locales/fr-CA.js.map +1 -0
  109. package/dist/locales/fr.cjs +769 -0
  110. package/dist/locales/fr.cjs.map +1 -0
  111. package/dist/locales/fr.d.cts +14 -0
  112. package/dist/locales/fr.d.ts +14 -0
  113. package/dist/locales/fr.js +14 -0
  114. package/dist/locales/fr.js.map +1 -0
  115. package/dist/locales/gn.cjs +750 -0
  116. package/dist/locales/gn.cjs.map +1 -0
  117. package/dist/locales/gn.d.cts +16 -0
  118. package/dist/locales/gn.d.ts +16 -0
  119. package/dist/locales/gn.js +330 -0
  120. package/dist/locales/gn.js.map +1 -0
  121. package/dist/locales/hr.cjs +769 -0
  122. package/dist/locales/hr.cjs.map +1 -0
  123. package/dist/locales/hr.d.cts +14 -0
  124. package/dist/locales/hr.d.ts +14 -0
  125. package/dist/locales/hr.js +349 -0
  126. package/dist/locales/hr.js.map +1 -0
  127. package/dist/locales/ht.cjs +750 -0
  128. package/dist/locales/ht.cjs.map +1 -0
  129. package/dist/locales/ht.d.cts +16 -0
  130. package/dist/locales/ht.d.ts +16 -0
  131. package/dist/locales/ht.js +330 -0
  132. package/dist/locales/ht.js.map +1 -0
  133. package/dist/locales/hu.cjs +753 -0
  134. package/dist/locales/hu.cjs.map +1 -0
  135. package/dist/locales/hu.d.cts +14 -0
  136. package/dist/locales/hu.d.ts +14 -0
  137. package/dist/locales/hu.js +333 -0
  138. package/dist/locales/hu.js.map +1 -0
  139. package/dist/locales/index.cjs +537 -0
  140. package/dist/locales/index.cjs.map +1 -0
  141. package/dist/locales/index.d.cts +38 -0
  142. package/dist/locales/index.d.ts +38 -0
  143. package/dist/locales/index.js +105 -0
  144. package/dist/locales/index.js.map +1 -0
  145. package/dist/locales/it.cjs +777 -0
  146. package/dist/locales/it.cjs.map +1 -0
  147. package/dist/locales/it.d.cts +14 -0
  148. package/dist/locales/it.d.ts +14 -0
  149. package/dist/locales/it.js +357 -0
  150. package/dist/locales/it.js.map +1 -0
  151. package/dist/locales/nb.cjs +747 -0
  152. package/dist/locales/nb.cjs.map +1 -0
  153. package/dist/locales/nb.d.cts +14 -0
  154. package/dist/locales/nb.d.ts +14 -0
  155. package/dist/locales/nb.js +327 -0
  156. package/dist/locales/nb.js.map +1 -0
  157. package/dist/locales/nl.cjs +753 -0
  158. package/dist/locales/nl.cjs.map +1 -0
  159. package/dist/locales/nl.d.cts +14 -0
  160. package/dist/locales/nl.d.ts +14 -0
  161. package/dist/locales/nl.js +333 -0
  162. package/dist/locales/nl.js.map +1 -0
  163. package/dist/locales/pl.cjs +794 -0
  164. package/dist/locales/pl.cjs.map +1 -0
  165. package/dist/locales/pl.d.cts +14 -0
  166. package/dist/locales/pl.d.ts +14 -0
  167. package/dist/locales/pl.js +374 -0
  168. package/dist/locales/pl.js.map +1 -0
  169. package/dist/locales/pt-BR.cjs +773 -0
  170. package/dist/locales/pt-BR.cjs.map +1 -0
  171. package/dist/locales/pt-BR.d.cts +14 -0
  172. package/dist/locales/pt-BR.d.ts +14 -0
  173. package/dist/locales/pt-BR.js +353 -0
  174. package/dist/locales/pt-BR.js.map +1 -0
  175. package/dist/locales/pt.cjs +777 -0
  176. package/dist/locales/pt.cjs.map +1 -0
  177. package/dist/locales/pt.d.cts +14 -0
  178. package/dist/locales/pt.d.ts +14 -0
  179. package/dist/locales/pt.js +357 -0
  180. package/dist/locales/pt.js.map +1 -0
  181. package/dist/locales/qu.cjs +756 -0
  182. package/dist/locales/qu.cjs.map +1 -0
  183. package/dist/locales/qu.d.cts +16 -0
  184. package/dist/locales/qu.d.ts +16 -0
  185. package/dist/locales/qu.js +336 -0
  186. package/dist/locales/qu.js.map +1 -0
  187. package/dist/locales/ro.cjs +769 -0
  188. package/dist/locales/ro.cjs.map +1 -0
  189. package/dist/locales/ro.d.cts +14 -0
  190. package/dist/locales/ro.d.ts +14 -0
  191. package/dist/locales/ro.js +349 -0
  192. package/dist/locales/ro.js.map +1 -0
  193. package/dist/locales/ru.cjs +789 -0
  194. package/dist/locales/ru.cjs.map +1 -0
  195. package/dist/locales/ru.d.cts +14 -0
  196. package/dist/locales/ru.d.ts +14 -0
  197. package/dist/locales/ru.js +369 -0
  198. package/dist/locales/ru.js.map +1 -0
  199. package/dist/locales/sk.cjs +794 -0
  200. package/dist/locales/sk.cjs.map +1 -0
  201. package/dist/locales/sk.d.cts +14 -0
  202. package/dist/locales/sk.d.ts +14 -0
  203. package/dist/locales/sk.js +374 -0
  204. package/dist/locales/sk.js.map +1 -0
  205. package/dist/locales/sq.cjs +753 -0
  206. package/dist/locales/sq.cjs.map +1 -0
  207. package/dist/locales/sq.d.cts +14 -0
  208. package/dist/locales/sq.d.ts +14 -0
  209. package/dist/locales/sq.js +333 -0
  210. package/dist/locales/sq.js.map +1 -0
  211. package/dist/locales/sr-Latn.cjs +841 -0
  212. package/dist/locales/sr-Latn.cjs.map +1 -0
  213. package/dist/locales/sr-Latn.d.cts +17 -0
  214. package/dist/locales/sr-Latn.d.ts +17 -0
  215. package/dist/locales/sr-Latn.js +86 -0
  216. package/dist/locales/sr-Latn.js.map +1 -0
  217. package/dist/locales/sr.cjs +769 -0
  218. package/dist/locales/sr.cjs.map +1 -0
  219. package/dist/locales/sr.d.cts +14 -0
  220. package/dist/locales/sr.d.ts +14 -0
  221. package/dist/locales/sr.js +14 -0
  222. package/dist/locales/sr.js.map +1 -0
  223. package/dist/locales/sv.cjs +753 -0
  224. package/dist/locales/sv.cjs.map +1 -0
  225. package/dist/locales/sv.d.cts +14 -0
  226. package/dist/locales/sv.d.ts +14 -0
  227. package/dist/locales/sv.js +333 -0
  228. package/dist/locales/sv.js.map +1 -0
  229. package/dist/locales/tr.cjs +750 -0
  230. package/dist/locales/tr.cjs.map +1 -0
  231. package/dist/locales/tr.d.cts +14 -0
  232. package/dist/locales/tr.d.ts +14 -0
  233. package/dist/locales/tr.js +330 -0
  234. package/dist/locales/tr.js.map +1 -0
  235. package/dist/locales/uk.cjs +794 -0
  236. package/dist/locales/uk.cjs.map +1 -0
  237. package/dist/locales/uk.d.cts +14 -0
  238. package/dist/locales/uk.d.ts +14 -0
  239. package/dist/locales/uk.js +374 -0
  240. package/dist/locales/uk.js.map +1 -0
  241. package/dist/markdown.cjs +620 -0
  242. package/dist/markdown.cjs.map +1 -0
  243. package/dist/markdown.d.cts +153 -0
  244. package/dist/markdown.d.ts +153 -0
  245. package/dist/markdown.js +573 -0
  246. package/dist/markdown.js.map +1 -0
  247. package/dist/mcp-app-entry-BA-Ca39z.d.ts +1480 -0
  248. package/dist/mcp-app-entry-tybABaHg.d.cts +1480 -0
  249. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  250. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  251. package/dist/mcp-app-sandbox.cjs +323 -0
  252. package/dist/mcp-app-sandbox.cjs.map +1 -0
  253. package/dist/mcp-app-sandbox.d.cts +70 -0
  254. package/dist/mcp-app-sandbox.d.ts +70 -0
  255. package/dist/mcp-app-sandbox.js +209 -0
  256. package/dist/mcp-app-sandbox.js.map +1 -0
  257. package/dist/mcp-app.cjs +980 -0
  258. package/dist/mcp-app.cjs.map +1 -0
  259. package/dist/mcp-app.d.cts +3 -0
  260. package/dist/mcp-app.d.ts +3 -0
  261. package/dist/mcp-app.js +816 -0
  262. package/dist/mcp-app.js.map +1 -0
  263. package/dist/pipeline.cjs +845 -0
  264. package/dist/pipeline.cjs.map +1 -0
  265. package/dist/pipeline.css +1407 -0
  266. package/dist/pipeline.d.cts +348 -0
  267. package/dist/pipeline.d.ts +348 -0
  268. package/dist/pipeline.js +778 -0
  269. package/dist/pipeline.js.map +1 -0
  270. package/dist/styles.css +4109 -0
  271. package/dist/types-BmvgYUzF.d.cts +19 -0
  272. package/dist/types-Cr5gmUts.d.ts +19 -0
  273. package/package.json +155 -8
@@ -0,0 +1,816 @@
1
+ import {
2
+ cspMetaTag,
3
+ escapeAttribute,
4
+ withPolicyFirst
5
+ } from "./chunk-EL2YCROY.js";
6
+ import {
7
+ MCP_APP_POLICY_MAX_ORIGINS,
8
+ MCP_APP_POLICY_TOKEN_MAX_CHARS,
9
+ MCP_APP_SANDBOX_PROXY_READY,
10
+ MCP_APP_SANDBOX_RESOURCE_READY,
11
+ MCP_APP_SCHEME_PARAM,
12
+ isMcpAppSandboxMessage,
13
+ mcpAppColorScheme,
14
+ mcpAppPolicy,
15
+ mcpAppPolicyOfToken,
16
+ mcpAppPolicyOrigin,
17
+ mcpAppPolicyToken
18
+ } from "./chunk-GB7RZJMG.js";
19
+
20
+ // src/mcp-app.ts
21
+ import { mcpAppOrigin } from "@dudko.dev/agent-web";
22
+ var MCP_APP_PROTOCOL_VERSION = "2026-01-26";
23
+ var APP_DEFAULT_HEIGHT = 360;
24
+ var APP_MIN_HEIGHT = 120;
25
+ var APP_MAX_HEIGHT = 800;
26
+ var APP_HEIGHT_SCREENS = 3;
27
+ var APP_HEIGHT_CEILING = 6e3;
28
+ var appHeightCap = (viewHeight) => {
29
+ if (typeof viewHeight !== "number" || !Number.isFinite(viewHeight) || viewHeight <= 0) {
30
+ return APP_MAX_HEIGHT;
31
+ }
32
+ const screens = Math.floor(viewHeight * APP_HEIGHT_SCREENS / 100) * 100;
33
+ return Math.min(APP_HEIGHT_CEILING, Math.max(APP_MAX_HEIGHT, screens));
34
+ };
35
+ var nextAppHeightCap = (current, viewHeight) => {
36
+ const now = appHeightCap(viewHeight);
37
+ return Number.isFinite(current) && current > now ? Math.min(APP_HEIGHT_CEILING, current) : now;
38
+ };
39
+ var MCP_APP_MAX_IN_FLIGHT = 3;
40
+ var MCP_APP_MAX_MESSAGE_CHARS = 4e3;
41
+ var MCP_APP_MAX_URL_CHARS = 2048;
42
+ var MCP_APP_MAX_ARGS_CHARS = 64e3;
43
+ var clampAppHeight = (height, max = APP_MAX_HEIGHT) => Math.min(
44
+ Math.max(
45
+ APP_MIN_HEIGHT,
46
+ Math.min(APP_HEIGHT_CEILING, Number.isFinite(max) ? max : APP_MAX_HEIGHT)
47
+ ),
48
+ Math.max(APP_MIN_HEIGHT, Math.round(Number.isFinite(height) ? height : APP_DEFAULT_HEIGHT))
49
+ );
50
+ var origins = (list) => {
51
+ const out = [];
52
+ for (const entry of list ?? []) {
53
+ const origin = mcpAppOrigin(entry);
54
+ if (origin && !out.includes(origin)) out.push(origin);
55
+ }
56
+ return out;
57
+ };
58
+ var mcpAppCsp = (csp) => mcpAppPolicy({ connect: origins(csp?.connectDomains), resources: origins(csp?.resourceDomains) });
59
+ var grantedAppCsp = (csp) => ({
60
+ connectDomains: origins(csp?.connectDomains),
61
+ resourceDomains: origins(csp?.resourceDomains)
62
+ });
63
+ var MCP_APP_RELAY = "(function(){var f=document.getElementById('app');function reserved(d){return !!d&&typeof d.method==='string'&&d.method.indexOf('ui/notifications/sandbox-')===0}addEventListener('message',function(e){var w=f&&f.contentWindow;if(!w||reserved(e.data))return;if(e.source===w){parent.postMessage(e.data,'*')}else if(e.source===parent){w.postMessage(e.data,'*')}})})()";
64
+ var schemeMeta = (scheme) => scheme ? `<meta name="color-scheme" content="${scheme}">` : "";
65
+ var schemeCss = (scheme) => scheme ? `:root{color-scheme:${scheme}}` : "";
66
+ var schemeOfFrame = (scheme) => scheme ? `;color-scheme:${scheme}` : "";
67
+ var buildMcpAppDocument = (html, csp, scheme) => {
68
+ const policy = mcpAppCsp(csp);
69
+ const s = mcpAppColorScheme(scheme);
70
+ return `<!doctype html><html><head><meta http-equiv="Content-Security-Policy" content="${escapeAttribute(policy)}">` + schemeMeta(s) + `<style>${schemeCss(s)}html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%${schemeOfFrame(s)}}</style></head><body><iframe id="app" sandbox="allow-scripts" referrerpolicy="no-referrer" srcdoc="${escapeAttribute(withPolicyFirst(html, policy))}"></iframe><script>${MCP_APP_RELAY}</script></body></html>`;
71
+ };
72
+ var appLinkOf = (value) => {
73
+ if (typeof value !== "string" || value.length > MCP_APP_MAX_URL_CHARS) return void 0;
74
+ let url;
75
+ try {
76
+ url = new URL(value);
77
+ } catch {
78
+ return void 0;
79
+ }
80
+ if (url.protocol !== "https:" && url.protocol !== "http:") return void 0;
81
+ if (url.username || url.password || !url.hostname) return void 0;
82
+ const scheme = `${url.protocol}//`;
83
+ return {
84
+ href: url.href,
85
+ scheme,
86
+ host: url.host,
87
+ rest: url.href.slice(scheme.length + url.host.length)
88
+ };
89
+ };
90
+ var HIDDEN = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f​-‏‪-‮⁦-⁩]/g;
91
+ var appMessageTextOf = (content) => {
92
+ const blocks = Array.isArray(content) ? content : content === void 0 ? [] : [content];
93
+ if (blocks.length === 0 || blocks.length > 20) return void 0;
94
+ const texts = [];
95
+ for (const block of blocks) {
96
+ if (!isObject(block) || block.type !== "text" || typeof block.text !== "string") {
97
+ return void 0;
98
+ }
99
+ texts.push(block.text);
100
+ }
101
+ const text = texts.join("\n\n").replace(HIDDEN, "").trim();
102
+ return text && text.length <= MCP_APP_MAX_MESSAGE_CHARS ? text : void 0;
103
+ };
104
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
105
+ var MCP_APP_REQUESTS = [
106
+ "ui/initialize",
107
+ "ping",
108
+ "tools/call",
109
+ "ui/open-link",
110
+ "ui/message",
111
+ "ui/request-display-mode"
112
+ ];
113
+ var MCP_APP_OPTIONAL_REQUESTS = ["ui/download-file", "sampling/createMessage"];
114
+ var MCP_APP_NOTIFICATIONS = [
115
+ "ui/notifications/initialized",
116
+ "ui/notifications/size-changed"
117
+ ];
118
+ var McpAppRpcError = class extends Error {
119
+ constructor(code, message) {
120
+ super(message);
121
+ this.code = code;
122
+ this.name = "McpAppRpcError";
123
+ }
124
+ code;
125
+ };
126
+ var METHOD_NOT_FOUND = -32601;
127
+ var INVALID_PARAMS = -32602;
128
+ var INVALID_REQUEST = -32600;
129
+ var MCP_APP_REFUSED = -32e3;
130
+ var MCP_APP_DISPLAY_MODES = ["inline", "fullscreen", "pip"];
131
+ var validId = (id) => typeof id === "string" && id.length > 0 && id.length <= 100 || typeof id === "number" && Number.isFinite(id);
132
+ var McpAppBridge = class {
133
+ o;
134
+ initializeSeen = false;
135
+ delivered = false;
136
+ inFlight = 0;
137
+ closed = false;
138
+ seq = 0;
139
+ // The display modes the app declared at `ui/initialize` (undefined: none declared).
140
+ appModes;
141
+ constructor(options) {
142
+ this.o = options;
143
+ }
144
+ /** The app said it is ready, and was given the tool's input and result. */
145
+ get initialized() {
146
+ return this.delivered;
147
+ }
148
+ /** Stop answering: the frame is gone or was reloaded. */
149
+ close() {
150
+ this.closed = true;
151
+ }
152
+ /** Tell the app it is being torn down (not waited for: the frame goes anyway). */
153
+ teardown(reason) {
154
+ if (!this.delivered || this.closed) return;
155
+ this.seq += 1;
156
+ this.send({
157
+ jsonrpc: "2.0",
158
+ id: `host-teardown-${this.seq}`,
159
+ method: "ui/resource-teardown",
160
+ params: { reason }
161
+ });
162
+ }
163
+ /** The display modes the app declared at `ui/initialize` (undefined: none, or not yet). */
164
+ get appDisplayModes() {
165
+ return this.appModes ? [...this.appModes] : void 0;
166
+ }
167
+ /** How the app is shown now (`hostContext.displayMode`). */
168
+ get displayMode() {
169
+ const mode = this.o.hostContext.displayMode;
170
+ return MCP_APP_DISPLAY_MODES.includes(mode) ? mode : "inline";
171
+ }
172
+ /** Tell an initialized app that part of the host context changed (the theme). */
173
+ updateContext(patch) {
174
+ Object.assign(this.o.hostContext, patch);
175
+ if (this.delivered && !this.closed) {
176
+ this.send({ jsonrpc: "2.0", method: "ui/notifications/host-context-changed", params: patch });
177
+ }
178
+ }
179
+ /** One message from the app's frame. */
180
+ receive(data) {
181
+ if (this.closed || !isObject(data) || data.jsonrpc !== "2.0") return;
182
+ const method = data.method;
183
+ const id = data.id;
184
+ if (method === void 0) return;
185
+ if (typeof method !== "string" || method.length === 0 || method.length > 100) {
186
+ if (validId(id)) this.error(id, INVALID_REQUEST, "Invalid request");
187
+ return;
188
+ }
189
+ if (id === void 0) {
190
+ this.notification(method, data.params);
191
+ return;
192
+ }
193
+ if (!validId(id)) return;
194
+ if (data.params !== void 0 && !isObject(data.params)) {
195
+ this.error(id, INVALID_PARAMS, "params must be an object");
196
+ return;
197
+ }
198
+ void this.request(id, method, data.params ?? {});
199
+ }
200
+ send(message) {
201
+ if (!this.closed) this.o.post(message);
202
+ }
203
+ error(id, code, message) {
204
+ this.send({ jsonrpc: "2.0", id, error: { code, message } });
205
+ }
206
+ notification(method, params) {
207
+ const p = isObject(params) ? params : {};
208
+ if (method === "ui/notifications/initialized") {
209
+ if (!this.initializeSeen || this.delivered) return;
210
+ this.delivered = true;
211
+ this.send({
212
+ jsonrpc: "2.0",
213
+ method: "ui/notifications/tool-input",
214
+ params: { arguments: this.o.toolInput }
215
+ });
216
+ this.send(
217
+ this.o.toolResult === void 0 ? {
218
+ jsonrpc: "2.0",
219
+ method: "ui/notifications/tool-cancelled",
220
+ params: { reason: this.o.cancelledReason ?? "no result" }
221
+ } : { jsonrpc: "2.0", method: "ui/notifications/tool-result", params: this.o.toolResult }
222
+ );
223
+ return;
224
+ }
225
+ if (method === "ui/notifications/size-changed") {
226
+ if (typeof p.height === "number" && Number.isFinite(p.height) && p.height > 0) {
227
+ this.o.handlers.resize(p.height);
228
+ }
229
+ }
230
+ }
231
+ async request(id, method, params) {
232
+ const h = this.o.handlers;
233
+ const offered = MCP_APP_REQUESTS.includes(method) || method === "ui/download-file" && typeof h.downloadFile === "function" || method === "sampling/createMessage" && typeof h.sample === "function";
234
+ if (!offered) {
235
+ this.error(id, METHOD_NOT_FOUND, `Method not found: ${method.slice(0, 60)}`);
236
+ return;
237
+ }
238
+ if (method === "ping") {
239
+ this.send({ jsonrpc: "2.0", id, result: {} });
240
+ return;
241
+ }
242
+ if (method === "ui/initialize") {
243
+ this.initializeSeen = true;
244
+ const caps = isObject(params.appCapabilities) ? params.appCapabilities : {};
245
+ this.appModes = Array.isArray(caps.availableDisplayModes) ? caps.availableDisplayModes.filter(
246
+ (m) => MCP_APP_DISPLAY_MODES.includes(m)
247
+ ) : void 0;
248
+ this.send({
249
+ jsonrpc: "2.0",
250
+ id,
251
+ result: {
252
+ protocolVersion: MCP_APP_PROTOCOL_VERSION,
253
+ hostInfo: this.o.hostInfo,
254
+ hostCapabilities: this.o.hostCapabilities,
255
+ hostContext: this.o.hostContext
256
+ }
257
+ });
258
+ return;
259
+ }
260
+ if (!this.initializeSeen) {
261
+ this.error(id, MCP_APP_REFUSED, "The app is not initialized (send ui/initialize first)");
262
+ return;
263
+ }
264
+ if (method === "ui/request-display-mode") {
265
+ const requested = params.mode;
266
+ if (!MCP_APP_DISPLAY_MODES.includes(requested)) {
267
+ this.error(id, INVALID_PARAMS, 'mode must be "inline", "fullscreen" or "pip"');
268
+ return;
269
+ }
270
+ const current = this.displayMode;
271
+ const host = Array.isArray(this.o.hostContext.availableDisplayModes) ? this.o.hostContext.availableDisplayModes : ["inline"];
272
+ let mode = current;
273
+ if (h.displayMode && appDisplayModeAllowed({
274
+ requested,
275
+ current,
276
+ host,
277
+ app: this.appModes
278
+ })) {
279
+ try {
280
+ const next = await h.displayMode(requested);
281
+ mode = MCP_APP_DISPLAY_MODES.includes(next) ? next : current;
282
+ } catch {
283
+ mode = this.displayMode;
284
+ }
285
+ }
286
+ this.send({ jsonrpc: "2.0", id, result: { mode } });
287
+ return;
288
+ }
289
+ let run;
290
+ if (method === "tools/call") {
291
+ const name = params.name;
292
+ const args = params.arguments === void 0 ? {} : params.arguments;
293
+ if (typeof name !== "string" || name.length === 0 || name.length > 128) {
294
+ this.error(id, INVALID_PARAMS, "tools/call needs the name of a tool");
295
+ return;
296
+ }
297
+ if (!isObject(args)) {
298
+ this.error(id, INVALID_PARAMS, "tools/call arguments must be an object");
299
+ return;
300
+ }
301
+ let size = Infinity;
302
+ try {
303
+ size = JSON.stringify(args).length;
304
+ } catch {
305
+ }
306
+ if (size > MCP_APP_MAX_ARGS_CHARS) {
307
+ this.error(id, INVALID_PARAMS, "tools/call arguments are too large");
308
+ return;
309
+ }
310
+ run = () => this.o.handlers.callTool(name, args);
311
+ } else if (method === "ui/download-file") {
312
+ const file = appDownloadOf(params);
313
+ if (typeof file === "string") {
314
+ this.error(id, INVALID_PARAMS, file);
315
+ return;
316
+ }
317
+ const save = h.downloadFile;
318
+ run = async () => await save(file) ? {} : { isError: true };
319
+ } else if (method === "sampling/createMessage") {
320
+ const sample = h.sample;
321
+ run = () => sample(params);
322
+ } else if (method === "ui/open-link") {
323
+ const link = appLinkOf(params.url);
324
+ if (!link) {
325
+ this.error(id, INVALID_PARAMS, "Invalid URL: only http(s) links without credentials");
326
+ return;
327
+ }
328
+ run = async () => {
329
+ if (!await this.o.handlers.openLink(link)) {
330
+ throw new McpAppRpcError(MCP_APP_REFUSED, "Link opening denied by user");
331
+ }
332
+ return {};
333
+ };
334
+ } else {
335
+ const text = params.role === "user" ? appMessageTextOf(params.content) : void 0;
336
+ if (text === void 0) {
337
+ this.error(
338
+ id,
339
+ INVALID_PARAMS,
340
+ "Invalid message format: one user text, not empty, not too long"
341
+ );
342
+ return;
343
+ }
344
+ run = async () => {
345
+ if (!await this.o.handlers.message(text)) {
346
+ throw new McpAppRpcError(MCP_APP_REFUSED, "Message sending denied");
347
+ }
348
+ return {};
349
+ };
350
+ }
351
+ const cap = this.o.maxInFlight ?? MCP_APP_MAX_IN_FLIGHT;
352
+ if (this.inFlight >= cap) {
353
+ this.error(id, MCP_APP_REFUSED, "Too many requests of this app are waiting");
354
+ return;
355
+ }
356
+ this.inFlight += 1;
357
+ try {
358
+ const result = await run();
359
+ this.send({ jsonrpc: "2.0", id, result });
360
+ } catch (err) {
361
+ const code = err instanceof McpAppRpcError ? err.code : MCP_APP_REFUSED;
362
+ const message = (err instanceof Error ? err.message : String(err)).slice(0, 300);
363
+ this.error(id, code, message);
364
+ } finally {
365
+ this.inFlight -= 1;
366
+ }
367
+ }
368
+ };
369
+ var mcpAppHostCapabilities = (csp, features = {}) => ({
370
+ openLinks: {},
371
+ serverTools: {},
372
+ message: { text: {} },
373
+ ...features.downloadFile ? { downloadFile: {} } : {},
374
+ ...features.sampling ? { sampling: {} } : {},
375
+ // What the frame grants: the declared origins it kept; no permission at all.
376
+ sandbox: { permissions: {}, csp: grantedAppCsp(csp) }
377
+ });
378
+ var appDisplayModeAllowed = (o) => o.requested === o.current || o.requested === "inline" || o.host.includes(o.requested) && (o.app?.includes(o.requested) ?? false);
379
+ var appGestureOf = (o) => o.focused && o.activation !== false;
380
+ var MCP_APP_MAX_DOWNLOAD_BYTES = 20 * 1024 * 1024;
381
+ var MCP_APP_MAX_FILE_NAME_CHARS = 100;
382
+ var MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS = [
383
+ "exe",
384
+ "com",
385
+ "bat",
386
+ "cmd",
387
+ "scr",
388
+ "pif",
389
+ "msi",
390
+ "msp",
391
+ "mst",
392
+ "msc",
393
+ "cpl",
394
+ "dll",
395
+ "sys",
396
+ "ps1",
397
+ "psm1",
398
+ "psd1",
399
+ "vbs",
400
+ "vbe",
401
+ "js",
402
+ "jse",
403
+ "mjs",
404
+ "cjs",
405
+ "wsf",
406
+ "wsh",
407
+ "ws",
408
+ "hta",
409
+ "jar",
410
+ "jnlp",
411
+ "lnk",
412
+ "reg",
413
+ "inf",
414
+ "scf",
415
+ "url",
416
+ "website",
417
+ "application",
418
+ "gadget",
419
+ "sh",
420
+ "bash",
421
+ "zsh",
422
+ "csh",
423
+ "ksh",
424
+ "command",
425
+ "tool",
426
+ "app",
427
+ "pkg",
428
+ "mpkg",
429
+ "dmg",
430
+ "deb",
431
+ "rpm",
432
+ "apk",
433
+ "xapk",
434
+ "appimage",
435
+ "run",
436
+ "bin",
437
+ "elf",
438
+ "out",
439
+ "py",
440
+ "pyw",
441
+ "pyz",
442
+ "pl",
443
+ "rb",
444
+ "php",
445
+ "html",
446
+ "htm",
447
+ "xhtml",
448
+ "xht",
449
+ "shtml",
450
+ "mht",
451
+ "mhtml",
452
+ "svg",
453
+ "svgz",
454
+ "xml",
455
+ "xsl",
456
+ "xslt",
457
+ "webloc",
458
+ "desktop",
459
+ "iso",
460
+ "img",
461
+ "vhd",
462
+ "vhdx",
463
+ "library-ms",
464
+ "settingcontent-ms"
465
+ ];
466
+ var MCP_APP_REFUSED_DOWNLOAD_TYPES = [
467
+ "text/html",
468
+ "application/xhtml+xml",
469
+ "image/svg+xml",
470
+ "application/xml",
471
+ "text/xml",
472
+ "text/javascript",
473
+ "application/javascript",
474
+ "application/ecmascript",
475
+ "application/x-javascript",
476
+ "application/x-msdownload",
477
+ "application/x-msdos-program",
478
+ "application/x-msi",
479
+ "application/x-ms-installer",
480
+ "application/vnd.microsoft.portable-executable",
481
+ "application/x-executable",
482
+ "application/x-elf",
483
+ "application/x-sh",
484
+ "application/x-shellscript",
485
+ "application/x-csh",
486
+ "application/java-archive",
487
+ "application/x-java-jnlp-file",
488
+ "application/hta",
489
+ "application/x-apple-diskimage",
490
+ "application/vnd.android.package-archive",
491
+ "application/x-python-code",
492
+ "text/x-python",
493
+ "application/x-httpd-php"
494
+ ];
495
+ var MIME = /^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;
496
+ var appMimeTypeOf = (value) => {
497
+ if (typeof value !== "string") return void 0;
498
+ const type = value.split(";")[0].trim().toLowerCase();
499
+ return MIME.test(type) ? type : void 0;
500
+ };
501
+ var RESERVED_NAME = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
502
+ var appFileNameOf = (value) => {
503
+ let name = typeof value === "string" ? value.slice(0, 2048) : "";
504
+ name = name.replace(/[?#].*$/s, "");
505
+ name = name.split(/[\\/]/).pop() ?? "";
506
+ try {
507
+ name = decodeURIComponent(name);
508
+ } catch {
509
+ }
510
+ name = (name.split(/[\\/]/).pop() ?? "").replace(HIDDEN, "").replace(/[<>:"|?*\u0000-\u001f\u007f]/g, "_").replace(/\s+/g, " ").replace(/^[.\s]+/, "").replace(/[.\s]+$/, "");
511
+ if (RESERVED_NAME.test(name)) name = `_${name}`;
512
+ if (name.length > MCP_APP_MAX_FILE_NAME_CHARS) {
513
+ const dot = name.lastIndexOf(".");
514
+ const ext = dot > 0 && name.length - dot <= 16 ? name.slice(dot) : "";
515
+ name = name.slice(0, MCP_APP_MAX_FILE_NAME_CHARS - ext.length).replace(/[.\s]+$/, "") + ext;
516
+ }
517
+ return name || "download";
518
+ };
519
+ var appFileExtensionOf = (name) => {
520
+ const dot = name.lastIndexOf(".");
521
+ return dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
522
+ };
523
+ var appDownloadRefusal = (name, mimeType) => {
524
+ const ext = appFileExtensionOf(name);
525
+ if (MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS.includes(ext)) return `“.${ext}” files are not saved`;
526
+ const type = appMimeTypeOf(mimeType);
527
+ if (type && (MCP_APP_REFUSED_DOWNLOAD_TYPES.includes(type) || type.endsWith("+xml"))) {
528
+ return `${type} files are not saved`;
529
+ }
530
+ return void 0;
531
+ };
532
+ var URI_LINE = /^[^\u0000-\u001f\u007f\s]{1,2048}$/;
533
+ var bytesOfBase64 = (blob, maxBytes) => {
534
+ if (blob.length > Math.ceil(maxBytes * 4 / 3) + 4)
535
+ return `the file is larger than ${maxBytes} bytes`;
536
+ if (!/^[A-Za-z0-9+/\s]*={0,2}\s*$/.test(blob)) return "blob must be base64";
537
+ try {
538
+ const binary = atob(blob.replace(/\s+/g, ""));
539
+ const bytes = new Uint8Array(binary.length);
540
+ for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
541
+ return bytes;
542
+ } catch {
543
+ return "blob must be base64";
544
+ }
545
+ };
546
+ var appDownloadOf = (params, maxBytes = MCP_APP_MAX_DOWNLOAD_BYTES) => {
547
+ const contents = isObject(params) ? params.contents : void 0;
548
+ if (!Array.isArray(contents) || contents.length === 0) return "contents must list the file";
549
+ if (contents.length > 1) return "One file per request";
550
+ const item = contents[0];
551
+ if (!isObject(item)) return "Invalid content";
552
+ if (item.type === "resource") {
553
+ const r = item.resource;
554
+ if (!isObject(r) || typeof r.uri !== "string" || !URI_LINE.test(r.uri)) {
555
+ return "Invalid content: resource.uri names the file";
556
+ }
557
+ const name = appFileNameOf(r.uri);
558
+ const mimeType = appMimeTypeOf(r.mimeType);
559
+ const refused = appDownloadRefusal(name, mimeType);
560
+ if (refused) return `Policy violation: ${refused}`;
561
+ let bytes;
562
+ if (typeof r.text === "string") {
563
+ bytes = r.text.length > maxBytes ? `the file is larger than ${maxBytes} bytes` : new TextEncoder().encode(r.text);
564
+ } else if (typeof r.blob === "string") {
565
+ bytes = bytesOfBase64(r.blob, maxBytes);
566
+ } else {
567
+ return "Invalid content: text or blob";
568
+ }
569
+ if (typeof bytes === "string") return `Invalid content: ${bytes}`;
570
+ if (bytes.length > maxBytes) return `Invalid content: the file is larger than ${maxBytes} bytes`;
571
+ return { kind: "embedded", name, ...mimeType ? { mimeType } : {}, bytes };
572
+ }
573
+ if (item.type === "resource_link") {
574
+ if (typeof item.uri !== "string" || !URI_LINE.test(item.uri)) {
575
+ return "Invalid content: a resource_link needs a URI";
576
+ }
577
+ const fromUri = appFileNameOf(item.uri);
578
+ const name = fromUri !== "download" || typeof item.name !== "string" ? fromUri : appFileNameOf(item.name);
579
+ const mimeType = appMimeTypeOf(item.mimeType);
580
+ const refused = appDownloadRefusal(name, mimeType);
581
+ if (refused) return `Policy violation: ${refused}`;
582
+ return { kind: "link", uri: item.uri, name, ...mimeType ? { mimeType } : {} };
583
+ }
584
+ return "Invalid content: a resource or a resource_link";
585
+ };
586
+ var resolveAppDownload = async (file, server, read, signal, maxBytes = MCP_APP_MAX_DOWNLOAD_BYTES) => {
587
+ if (file.kind === "embedded") {
588
+ return {
589
+ name: file.name,
590
+ ...file.mimeType ? { mimeType: file.mimeType } : {},
591
+ bytes: file.bytes,
592
+ source: "embedded"
593
+ };
594
+ }
595
+ if (!read) throw new McpAppRpcError(MCP_APP_REFUSED, "This host cannot read a linked file");
596
+ let got;
597
+ try {
598
+ got = await read(server, file.uri, { ...signal ? { signal } : {}, maxBytes });
599
+ } catch (err) {
600
+ const why = err instanceof Error ? err.message : String(err);
601
+ throw new McpAppRpcError(MCP_APP_REFUSED, `Invalid content: ${why.slice(0, 200)}`);
602
+ }
603
+ if (!(got?.bytes instanceof Uint8Array)) {
604
+ throw new McpAppRpcError(MCP_APP_REFUSED, "Invalid content: no bytes");
605
+ }
606
+ if (got.bytes.length > maxBytes) {
607
+ throw new McpAppRpcError(INVALID_PARAMS, `Invalid content: larger than ${maxBytes} bytes`);
608
+ }
609
+ const mimeType = appMimeTypeOf(got.mimeType) ?? file.mimeType;
610
+ const refused = appDownloadRefusal(file.name, mimeType);
611
+ if (refused) throw new McpAppRpcError(INVALID_PARAMS, `Policy violation: ${refused}`);
612
+ return { name: file.name, ...mimeType ? { mimeType } : {}, bytes: got.bytes, source: "link" };
613
+ };
614
+ var appSamplingErrorOf = (err) => {
615
+ if (err instanceof McpAppRpcError) return err;
616
+ const rpc = err?.rpcCode;
617
+ const message = (err instanceof Error ? err.message : String(err)).slice(0, 300);
618
+ return err instanceof Error && err.name === "AppSamplingError" && typeof rpc === "number" ? new McpAppRpcError(rpc, message) : new McpAppRpcError(MCP_APP_REFUSED, message);
619
+ };
620
+ var saveAppFile = (file, env) => {
621
+ const blob = new Blob([file.bytes], { type: "application/octet-stream" });
622
+ const url = env.URL.createObjectURL(blob);
623
+ const a = env.document.createElement("a");
624
+ a.href = url;
625
+ a.download = appFileNameOf(file.name);
626
+ a.rel = "noopener";
627
+ a.style.display = "none";
628
+ env.document.body.append(a);
629
+ a.click();
630
+ a.remove();
631
+ env.setTimeout(() => env.URL.revokeObjectURL(url), 6e4);
632
+ };
633
+ var MCP_APP_SANDBOX_SERVER = "{server}";
634
+ var MCP_APP_SANDBOX_TIMEOUT_MS = 5e3;
635
+ var MCP_APP_SANDBOX_GRACE_MS = 1e3;
636
+ var MCP_APP_SANDBOX_FRAME_TOKENS = "allow-scripts allow-same-origin";
637
+ var DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
638
+ var LOOPBACK_HOSTS = ["localhost", "127.0.0.1"];
639
+ var SAFE_PATH = /^\/[A-Za-z0-9\-._~/%]*$/;
640
+ var no = (reason) => ({ ok: false, reason });
641
+ var mcpAppSandboxTarget = (options, server, pageOrigin) => {
642
+ const template = options?.url;
643
+ if (typeof template !== "string" || template.length === 0 || template.length > 2048) {
644
+ return no("invalid");
645
+ }
646
+ const parts = template.split(MCP_APP_SANDBOX_SERVER);
647
+ if (parts.length > 2) return no("invalid");
648
+ let raw = template;
649
+ if (parts.length === 2) {
650
+ const authority = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)/i.exec(template)?.[1] ?? "";
651
+ if (!authority.replace(/:\d*$/, "").includes(MCP_APP_SANDBOX_SERVER)) return no("invalid");
652
+ if (typeof server !== "string" || !DNS_LABEL.test(server)) return no("server-name");
653
+ raw = template.replace(MCP_APP_SANDBOX_SERVER, server);
654
+ }
655
+ if (/[?#\s]/.test(raw)) return no("invalid");
656
+ let url;
657
+ try {
658
+ url = new URL(raw);
659
+ } catch {
660
+ return no("invalid");
661
+ }
662
+ const loopback = LOOPBACK_HOSTS.includes(url.hostname);
663
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) return no("insecure");
664
+ if (url.username || url.password || !url.hostname) return no("invalid");
665
+ if (!url.hostname.split(".").every((label) => DNS_LABEL.test(label))) {
666
+ return no(parts.length === 2 ? "server-name" : "invalid");
667
+ }
668
+ if (!SAFE_PATH.test(url.pathname)) return no("invalid");
669
+ if (!pageOrigin || pageOrigin === "null") return no("no-page-origin");
670
+ if (url.origin === pageOrigin) return no("same-origin");
671
+ return { ok: true, origin: url.origin, base: `${url.origin}${url.pathname.replace(/\/+$/, "")}` };
672
+ };
673
+ var mcpAppSandboxProxyUrl = (base, csp) => {
674
+ const granted = grantedAppCsp(csp);
675
+ const token = mcpAppPolicyToken({
676
+ connect: granted.connectDomains,
677
+ resources: granted.resourceDomains
678
+ });
679
+ return token ? `${base}/${token}` : void 0;
680
+ };
681
+ var PROXY_URL = /^https?:\/\/[A-Za-z0-9.-]+(?::\d{1,5})?\/[A-Za-z0-9\-._~/%]*$/;
682
+ var mcpAppSandboxShellCsp = (proxyUrl) => [
683
+ "default-src 'none'",
684
+ "script-src 'none'",
685
+ "style-src 'unsafe-inline'",
686
+ `frame-src ${proxyUrl}`,
687
+ "child-src 'none'",
688
+ "worker-src 'none'",
689
+ "object-src 'none'",
690
+ "form-action 'none'",
691
+ "base-uri 'none'"
692
+ ].join("; ");
693
+ var buildMcpAppSandboxShell = (proxyUrl, scheme) => {
694
+ if (!PROXY_URL.test(proxyUrl)) throw new Error("not a sandbox proxy URL");
695
+ const s = mcpAppColorScheme(scheme);
696
+ const src = s ? `${proxyUrl}?${MCP_APP_SCHEME_PARAM}=${s}` : proxyUrl;
697
+ return "<!doctype html><html><head>" + cspMetaTag(mcpAppSandboxShellCsp(proxyUrl)) + schemeMeta(s) + `<style>${schemeCss(s)}html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%${schemeOfFrame(s)}}</style></head><body><iframe id="proxy" sandbox="${MCP_APP_SANDBOX_FRAME_TOKENS}" referrerpolicy="no-referrer" src="${escapeAttribute(src)}"></iframe></body></html>`;
698
+ };
699
+ var McpAppSandboxLink = class {
700
+ o;
701
+ state = "waiting";
702
+ constructor(options) {
703
+ this.o = options;
704
+ }
705
+ /** The proxy answered and was given the app. */
706
+ get ready() {
707
+ return this.state === "loaded";
708
+ }
709
+ /** The proxy page was loaded a second time: the app must be stopped. */
710
+ get broken() {
711
+ return this.state === "broken";
712
+ }
713
+ /** Whether a message event is the proxy's: its window, and the sandbox origin. */
714
+ accepts(event, proxy) {
715
+ return proxy !== null && proxy !== void 0 && event.source === proxy && event.origin === this.o.origin;
716
+ }
717
+ receive(event, proxy) {
718
+ if (this.state === "broken" || this.state === "closed" || !this.accepts(event, proxy)) {
719
+ return "drop";
720
+ }
721
+ const data = event.data;
722
+ if (isMcpAppSandboxMessage(data)) {
723
+ const d = data;
724
+ if (d.jsonrpc !== "2.0" || d.method !== MCP_APP_SANDBOX_PROXY_READY) return "drop";
725
+ if (this.state === "loaded") {
726
+ this.state = "broken";
727
+ return "broken";
728
+ }
729
+ this.state = "loaded";
730
+ const granted = grantedAppCsp(this.o.csp);
731
+ this.o.post(
732
+ {
733
+ jsonrpc: "2.0",
734
+ method: MCP_APP_SANDBOX_RESOURCE_READY,
735
+ params: { html: this.o.html, csp: granted }
736
+ },
737
+ this.o.origin
738
+ );
739
+ return "ready";
740
+ }
741
+ return this.state === "loaded" ? "app" : "drop";
742
+ }
743
+ /** Send a message to the app, through the proxy, to the sandbox origin. Nothing once broken. */
744
+ post(message) {
745
+ if (this.state === "loaded") this.o.post(message, this.o.origin);
746
+ }
747
+ close() {
748
+ if (this.state !== "broken") this.state = "closed";
749
+ }
750
+ };
751
+ var isApprovalOfApp = (approval, app) => approval.status === "pending" && approval.app !== void 0 && (approval.app.frame !== void 0 ? approval.app.frame === app.id : approval.app.server === app.server && approval.app.resourceUri === app.resourceUri);
752
+ export {
753
+ APP_DEFAULT_HEIGHT,
754
+ APP_HEIGHT_CEILING,
755
+ APP_HEIGHT_SCREENS,
756
+ APP_MAX_HEIGHT,
757
+ APP_MIN_HEIGHT,
758
+ MCP_APP_DISPLAY_MODES,
759
+ MCP_APP_MAX_ARGS_CHARS,
760
+ MCP_APP_MAX_DOWNLOAD_BYTES,
761
+ MCP_APP_MAX_FILE_NAME_CHARS,
762
+ MCP_APP_MAX_IN_FLIGHT,
763
+ MCP_APP_MAX_MESSAGE_CHARS,
764
+ MCP_APP_MAX_URL_CHARS,
765
+ MCP_APP_NOTIFICATIONS,
766
+ MCP_APP_OPTIONAL_REQUESTS,
767
+ MCP_APP_POLICY_MAX_ORIGINS,
768
+ MCP_APP_POLICY_TOKEN_MAX_CHARS,
769
+ MCP_APP_PROTOCOL_VERSION,
770
+ MCP_APP_REFUSED,
771
+ MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS,
772
+ MCP_APP_REFUSED_DOWNLOAD_TYPES,
773
+ MCP_APP_RELAY,
774
+ MCP_APP_REQUESTS,
775
+ MCP_APP_SANDBOX_FRAME_TOKENS,
776
+ MCP_APP_SANDBOX_GRACE_MS,
777
+ MCP_APP_SANDBOX_PROXY_READY,
778
+ MCP_APP_SANDBOX_RESOURCE_READY,
779
+ MCP_APP_SANDBOX_SERVER,
780
+ MCP_APP_SANDBOX_TIMEOUT_MS,
781
+ MCP_APP_SCHEME_PARAM,
782
+ McpAppBridge,
783
+ McpAppRpcError,
784
+ McpAppSandboxLink,
785
+ appDisplayModeAllowed,
786
+ appDownloadOf,
787
+ appDownloadRefusal,
788
+ appFileExtensionOf,
789
+ appFileNameOf,
790
+ appGestureOf,
791
+ appHeightCap,
792
+ appLinkOf,
793
+ appMessageTextOf,
794
+ appMimeTypeOf,
795
+ appSamplingErrorOf,
796
+ buildMcpAppDocument,
797
+ buildMcpAppSandboxShell,
798
+ clampAppHeight,
799
+ grantedAppCsp,
800
+ isApprovalOfApp,
801
+ isMcpAppSandboxMessage,
802
+ mcpAppColorScheme,
803
+ mcpAppCsp,
804
+ mcpAppHostCapabilities,
805
+ mcpAppPolicy,
806
+ mcpAppPolicyOfToken,
807
+ mcpAppPolicyOrigin,
808
+ mcpAppPolicyToken,
809
+ mcpAppSandboxProxyUrl,
810
+ mcpAppSandboxShellCsp,
811
+ mcpAppSandboxTarget,
812
+ nextAppHeightCap,
813
+ resolveAppDownload,
814
+ saveAppFile
815
+ };
816
+ //# sourceMappingURL=mcp-app.js.map