view.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>E2E host capabilities</title>
  6. <style>
  7. :root {
  8. color-scheme: light dark;
  9. }
  10. body {
  11. margin: 0;
  12. padding: 16px;
  13. font:
  14. 13px/1.5 system-ui,
  15. sans-serif;
  16. color: var(--color-text-primary, #1f2328);
  17. background: var(--color-background-primary, transparent);
  18. }
  19. h1 {
  20. margin: 0 0 8px;
  21. font-size: 15px;
  22. }
  23. dl {
  24. display: grid;
  25. grid-template-columns: max-content 1fr;
  26. gap: 4px 12px;
  27. margin: 0;
  28. }
  29. dt {
  30. color: var(--color-text-secondary, #59636e);
  31. }
  32. dd {
  33. margin: 0;
  34. font-family: ui-monospace, monospace;
  35. word-break: break-all;
  36. }
  37. </style>
  38. </head>
  39. <body data-ready="0">
  40. <h1>E2E host capabilities</h1>
  41. <dl>
  42. <dt>instance</dt>
  43. <dd id="instance">loading</dd>
  44. <dt>scope</dt>
  45. <dd id="scope"></dd>
  46. </dl>
  47. <script>
  48. // 页面脚本的错误记进 DOM,E2E 失败时能直接读到原因。
  49. window.__e2eErrors = [];
  50. window.addEventListener("error", (event) => window.__e2eErrors.push(String(event.message)));
  51. window.addEventListener("unhandledrejection", (event) =>
  52. window.__e2eErrors.push(String(event.reason?.message ?? event.reason)),
  53. );
  54. </script>
  55. <script>
  56. // 页面只经 window.zcode 读写;window.zcode 是不可配置的全局属性,顶层不再声明同名变量。
  57. const host = window.zcode;
  58. const applyHostStyles = () => {
  59. const variables = host.hostContext?.styles?.variables ?? {};
  60. for (const [name, value] of Object.entries(variables)) {
  61. if (typeof value === "string") document.documentElement.style.setProperty(name, value);
  62. }
  63. document.documentElement.dataset.theme = host.theme ?? "";
  64. };
  65. host.subscribe(applyHostStyles);
  66. host.ready().then(async () => {
  67. applyHostStyles();
  68. const result = await host.callTool("describe", {});
  69. const data = result.structuredContent ?? {};
  70. document.getElementById("instance").textContent = data.instance ?? "";
  71. document.getElementById("scope").textContent = data.scope ?? "";
  72. Object.assign(document.body.dataset, {
  73. ready: "1",
  74. instance: data.instance ?? "",
  75. scope: data.scope ?? "",
  76. });
  77. });
  78. </script>
  79. </body>
  80. </html>