holon-ui 0.0.1-dev.16 → 0.0.1-dev.18

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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Typed MCP clients for browser pages. One `connect()` serves a page as an MCP App
8
8
 
9
9
  ```sh
10
10
  npm install holon-ui
11
- npm install -D holon-types typescript
11
+ npm install -D holon-types typescript vite
12
12
  ```
13
13
 
14
14
  ## Create an app
@@ -96,19 +96,18 @@ Host-only features are on `app.view`, the ext-apps `App`:
96
96
  if (app.view) app.view.onhostcontextchanged = ({ theme }) => { if (theme) document.documentElement.style.colorScheme = theme; };
97
97
  ```
98
98
 
99
- ## Building the view
99
+ ## Building the page
100
100
 
101
- A view is its own build. Set the `mcp-app` condition in it, and `holon-ui` calls through the host there and over HTTP everywhere else:
101
+ `holon-ui/vite` builds `ui/index.html` twice in one `vite build`: the web page into `dist/web`, and the view into `dist/mcp/index.html`, one self-contained file in which `holon-ui` calls through the host:
102
102
 
103
103
  ```ts
104
- import { defaultClientConditions, defineConfig } from "vite";
104
+ import { defineConfig } from "vite";
105
+ import { holon } from "holon-ui/vite";
105
106
 
106
- export default defineConfig(({ mode }) => ({
107
- resolve: { conditions: mode === "mcp" ? ["mcp-app", ...defaultClientConditions] : undefined },
108
- }));
107
+ export default defineConfig({ plugins: [holon()] });
109
108
  ```
110
109
 
111
- `create-holon-app` sets this up.
110
+ `create-holon-app` sets this up. With another bundler, build the view with the `mcp-app` export condition.
112
111
 
113
112
  ## Community
114
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "holon-ui",
3
- "version": "0.0.1-dev.16",
3
+ "version": "0.0.1-dev.18",
4
4
  "description": "Typed MCP clients for browser pages: one connect() for MCP Apps views and WebMCP pages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,12 +17,18 @@
17
17
  "types": "./runtime.d.ts",
18
18
  "mcp-app": "./runtime.host.mjs",
19
19
  "default": "./runtime.web.mjs"
20
+ },
21
+ "./vite": {
22
+ "types": "./vite.d.ts",
23
+ "default": "./vite.mjs"
20
24
  }
21
25
  },
22
26
  "files": [
23
27
  "runtime.d.ts",
24
28
  "runtime.host.mjs",
25
29
  "runtime.web.mjs",
30
+ "vite.d.ts",
31
+ "vite.mjs",
26
32
  "README.md"
27
33
  ],
28
34
  "scripts": {
@@ -42,6 +48,7 @@
42
48
  "@modelcontextprotocol/server": "2.3.1",
43
49
  "@types/node": "^22.0.0",
44
50
  "typescript": "~5.9.3",
51
+ "vite": "8.3.8",
45
52
  "zod": "4.6.6"
46
53
  }
47
54
  }
package/vite.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ /** Builds the page in ui/index.html twice in one vite build: the web page into dist/web, and into dist/mcp the MCP Apps view, one self-contained HTML file whose holon-ui calls its app through the host. A view that would need a file beside it fails the build. */
4
+ export declare function holon(): Plugin;
package/vite.mjs ADDED
@@ -0,0 +1,39 @@
1
+ export function holon() {
2
+ return {
3
+ name: "holon",
4
+ config: () => ({
5
+ root: "ui",
6
+ base: "./",
7
+ builder: {},
8
+ build: { outDir: "../dist/web", emptyOutDir: true },
9
+ environments: {
10
+ mcp: {
11
+ consumer: "client",
12
+ build: {
13
+ outDir: "../dist/mcp",
14
+ copyPublicDir: false,
15
+ assetsInlineLimit: () => true,
16
+ rolldownOptions: { output: { codeSplitting: false } },
17
+ },
18
+ },
19
+ },
20
+ }),
21
+ applyToEnvironment: ({ name }) => name === "mcp",
22
+ resolveId: { order: "pre", handler: id => (id === "holon-ui/runtime" ? `${import.meta.dirname}/runtime.host.mjs` : null) },
23
+ generateBundle: {
24
+ order: "post",
25
+ handler(_, bundle) {
26
+ const { "index.html": page, ...files } = bundle;
27
+ for (const [name, file] of Object.entries(files)) {
28
+ const url = page.source.indexOf(`"./${name}"`);
29
+ if (url < 0) this.error(`holon-ui/vite cannot inline ${name} into the view, which a host loads as one HTML file; import a worker with ?worker&inline`);
30
+ const startTag = page.source.slice(page.source.lastIndexOf("<", url), page.source.indexOf(">", url) + 1);
31
+ page.source = page.source.replace(startTag, () => file.type === "chunk"
32
+ ? `<script type="module">${file.code.replaceAll("<!--", "\\x3C!--")}`
33
+ : `<style>${file.source.replaceAll("</", "<\\/")}</style>`);
34
+ delete bundle[name];
35
+ }
36
+ },
37
+ },
38
+ };
39
+ }