holon-ui 0.0.1-dev.15 → 0.0.1-dev.17

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.15",
3
+ "version": "0.0.1-dev.17",
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": {
@@ -34,7 +40,13 @@
34
40
  "holon-sh": "^0.0.1-dev.23"
35
41
  },
36
42
  "peerDependencies": {
37
- "@modelcontextprotocol/ext-apps": "^2.0.0"
43
+ "@modelcontextprotocol/ext-apps": "^2.0.0",
44
+ "vite": "^8.0.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "vite": {
48
+ "optional": true
49
+ }
38
50
  },
39
51
  "devDependencies": {
40
52
  "@modelcontextprotocol/ext-apps": "^2.0.4",
@@ -42,6 +54,7 @@
42
54
  "@modelcontextprotocol/server": "2.3.1",
43
55
  "@types/node": "^22.0.0",
44
56
  "typescript": "~5.9.3",
57
+ "vite": "8.3.8",
45
58
  "zod": "4.6.6"
46
59
  }
47
60
  }
package/runtime.d.ts CHANGED
@@ -48,7 +48,7 @@ export type Page<C> =
48
48
  /** connect, narrowed by the generated #holon-ui module to the client C of the project's own app. A page tool cannot take the name of one of the app's tools. */
49
49
  export type Connect<C> = <S extends Record<string, unknown> = {}>(options?: ConnectOptions<S> & { tools?: { [K in keyof Tools<C>]?: never } }) => Promise<Page<C>>;
50
50
  /** Bind the page to its own app on the surface its build chose, and offer every tool to whichever agent is present. Most pages call the generated connect from #holon-ui. */
51
- export declare function connect<S extends Record<string, unknown> = {}, Own extends string = string>(
52
- app: { identity: Identity; /** Must include the contract of the page's own app. */ contracts: Record<string, Contract | null> & Record<NoInfer<Own>, Contract>; own: Own; /** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */ endpoint: string },
51
+ export declare function connect<S extends Record<string, unknown> = {}>(
52
+ app: { identity: Identity; contracts: Record<string, Contract | null>; own: string; /** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */ endpoint: string },
53
53
  options?: ConnectOptions<S>,
54
54
  ): Promise<Page<RuntimeClient>>;
package/runtime.web.mjs CHANGED
@@ -16,7 +16,7 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
16
16
  const { signal } = lifetime;
17
17
  const offer = tool => context.registerTool(tool, { signal }).catch(error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
18
18
  for (const [name, tool] of Object.entries(tools)) offer(pageTool(name, tool));
19
- const contracted = name => contracts[own].tools.some(tool => tool.name === name);
19
+ const contracted = name => !contracts[own] || contracts[own].tools.some(tool => tool.name === name);
20
20
  client.listTools({ signal }).then(
21
21
  ({ tools: listed }) => {
22
22
  for (const tool of listed) {
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,41 @@
1
+ import { defaultClientConditions } from "vite";
2
+
3
+ export function holon() {
4
+ return {
5
+ name: "holon",
6
+ config: () => ({
7
+ root: "ui",
8
+ base: "./",
9
+ builder: {},
10
+ build: { outDir: "../dist/web", emptyOutDir: true },
11
+ environments: {
12
+ mcp: {
13
+ consumer: "client",
14
+ resolve: { conditions: ["mcp-app", ...defaultClientConditions] },
15
+ build: {
16
+ outDir: "../dist/mcp",
17
+ copyPublicDir: false,
18
+ assetsInlineLimit: () => true,
19
+ rolldownOptions: { output: { codeSplitting: false } },
20
+ },
21
+ },
22
+ },
23
+ }),
24
+ applyToEnvironment: ({ name }) => name === "mcp",
25
+ generateBundle: {
26
+ order: "post",
27
+ handler(_, bundle) {
28
+ const { "index.html": page, ...files } = bundle;
29
+ for (const [name, file] of Object.entries(files)) {
30
+ const url = page.source.indexOf(`"./${name}"`);
31
+ 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`);
32
+ const startTag = page.source.slice(page.source.lastIndexOf("<", url), page.source.indexOf(">", url) + 1);
33
+ page.source = page.source.replace(startTag, () => file.type === "chunk"
34
+ ? `<script type="module">${file.code.replaceAll("<!--", "\\x3C!--")}`
35
+ : `<style>${file.source.replaceAll("</", "<\\/")}</style>`);
36
+ delete bundle[name];
37
+ }
38
+ },
39
+ },
40
+ };
41
+ }