@devframes/vite 0.9.9 → 0.9.11

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/dist/hub.d.mts CHANGED
@@ -58,7 +58,9 @@ interface ViteDevframeHubOptions {
58
58
  */
59
59
  auth?: InitHubOptions['auth'];
60
60
  /**
61
- * Expose the aggregate MCP endpoint at `<base>__mcp`.
61
+ * Expose the aggregate MCP endpoint at `<base>__mcp`. Defaults to `'auto'`
62
+ * (mount once any mounted devframe exposes an agent surface); `true`
63
+ * forces it on, `false` off.
62
64
  */
63
65
  mcp?: InitHubOptions['mcp'];
64
66
  /** Publish this hub in the global instance registry. Default: off. */
@@ -79,6 +81,17 @@ interface ViteDevframeHubOptions {
79
81
  * @default false
80
82
  */
81
83
  quiet?: boolean;
84
+ /**
85
+ * Also bake the hub into `vite build` output: `buildHub` writes the whole
86
+ * static hub subtree (each devframe's SPA, the RPC dump, `embedded.js`, …)
87
+ * into `<outDir><base>`, and the UI's `embedded.js` script tag is injected
88
+ * into the built HTML, so the deployed app ships working devtools against
89
+ * a `static` backend (baked reads, no live server). Off by default: a
90
+ * production bundle only carries devtools when the host opts in.
91
+ *
92
+ * @default false
93
+ */
94
+ build?: boolean;
82
95
  }
83
96
  /**
84
97
  * Mount a whole **devframes-hub** (many integrations under one namespace,
package/dist/hub.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import process from "node:process";
2
+ import { resolve } from "pathe";
2
3
  import { Server } from "node:http";
3
4
  import { DEVFRAMES_HUB_BASE, normalizeHubBase } from "@devframes/hub/constants";
4
5
  import { initHub } from "@devframes/hub/initiate";
@@ -29,14 +30,20 @@ function viteDevframeHub(options = {}) {
29
30
  let viteConfig;
30
31
  let instance;
31
32
  let embeddedSrc;
33
+ let buildUi;
32
34
  const teardown = async () => {
33
35
  const previous = instance;
34
36
  instance = void 0;
35
37
  await previous?.close().catch(() => {});
36
38
  };
39
+ const resolveUi = async () => options.ui === false ? void 0 : options.ui ?? await loadDefaultUi();
37
40
  return {
38
41
  name: "devframes:hub",
39
- apply: "serve",
42
+ /**
43
+ * Dev middleware by default; a production bundle only carries the hub
44
+ * when the host opts into the static build.
45
+ */
46
+ apply: (_, env) => env.command === "serve" || options.build === true,
40
47
  configResolved(config) {
41
48
  viteConfig = config;
42
49
  },
@@ -44,7 +51,7 @@ function viteDevframeHub(options = {}) {
44
51
  if (!options.quiet) recommendViteDevtools();
45
52
  await teardown();
46
53
  const cwd = options.cwd ?? viteConfig?.root ?? process.cwd();
47
- const ui = options.ui === false ? void 0 : options.ui ?? await loadDefaultUi();
54
+ const ui = await resolveUi();
48
55
  const devframes = attachClientScripts(options.devframes, options.clientScripts);
49
56
  const httpServer = server.httpServer instanceof Server ? server.httpServer : void 0;
50
57
  const hub = initHub({
@@ -91,6 +98,11 @@ function viteDevframeHub(options = {}) {
91
98
  teardown();
92
99
  });
93
100
  },
101
+ async buildStart() {
102
+ if (viteConfig?.command !== "build" || !options.build) return;
103
+ buildUi = await resolveUi();
104
+ embeddedSrc = buildUi?.embedded ? `${base}embedded.js` : void 0;
105
+ },
94
106
  transformIndexHtml() {
95
107
  if (!embeddedSrc) return;
96
108
  return [{
@@ -104,6 +116,24 @@ function viteDevframeHub(options = {}) {
104
116
  },
105
117
  async closeBundle() {
106
118
  await teardown();
119
+ if (viteConfig?.command !== "build" || !options.build) return;
120
+ const cwd = options.cwd ?? viteConfig.root;
121
+ const { buildHub } = await import("@devframes/hub/build");
122
+ await buildHub({
123
+ base,
124
+ cwd,
125
+ outDir: resolve(viteConfig.root, viteConfig.build.outDir, base.slice(1)),
126
+ devframes: attachClientScripts(options.devframes, options.clientScripts) ?? [],
127
+ ...buildUi ? { ui: buildUi } : {},
128
+ ...pickDefined(options, [
129
+ "renderers",
130
+ "rpcDeclarations",
131
+ "getStorageDir",
132
+ "name",
133
+ "version",
134
+ "configure"
135
+ ])
136
+ });
107
137
  }
108
138
  };
109
139
  }
package/dist/single.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { IncomingMessage, ServerResponse } from "node:http";
2
2
  import { Plugin } from "vite";
3
- import { DevframeDefinition, McpRouteOptions } from "devframe";
3
+ import { DevframeDefinition, McpSetting } from "devframe";
4
4
  import { DevframeAuthHandler } from "devframe/node/auth";
5
+ import { WsOriginRegistry } from "devframe/rpc/transports/ws-server";
5
6
  //#region src/single.d.ts
6
7
  /**
7
8
  * The slice of a Vite dev server these plugins touch, deliberately
@@ -88,9 +89,20 @@ interface DevframeViteBridgeOptions {
88
89
  * Expose the bridge's route-based MCP server (Streamable-HTTP) at
89
90
  * `<base>__mcp` (on the Vite app's own origin) and advertise it in the
90
91
  * bridge's `__connection.json`. Overrides `def.cli?.mcp`, `undefined`
91
- * falls through to it, `false` disables the route regardless.
92
+ * falls through to it, then to the `'auto'` default (mount once the agent
93
+ * surface is non-empty); `false` disables the route regardless.
92
94
  */
93
- mcp?: boolean | McpRouteOptions;
95
+ mcp?: McpSetting;
96
+ /**
97
+ * Widen the WebSocket origin check beyond devframe's loopback-only
98
+ * default. A bridge serves the tool same-origin with the host Vite app,
99
+ * so reaching it from a non-loopback origin (`vite --host`, containers,
100
+ * Codespaces, tunnels) needs the dev server's own origin allowed. Pass
101
+ * extra origins, a {@link WsOriginRegistry}, or `false` to disable the
102
+ * check (safe when the bridge's auth gate owns the trust boundary).
103
+ * Forwarded verbatim to `initDevframe`.
104
+ */
105
+ allowedOrigins?: readonly string[] | WsOriginRegistry | false;
94
106
  }
95
107
  /**
96
108
  * Bridge a devframe's RPC + WebSocket backend into an existing Vite dev
package/dist/single.mjs CHANGED
@@ -76,7 +76,8 @@ function devframeViteBridge(d, options = {}) {
76
76
  * than leaving the socket ungated. `false` opts out explicitly.
77
77
  */
78
78
  auth: options.auth,
79
- mcp: options.mcp
79
+ mcp: options.mcp,
80
+ allowedOrigins: options.allowedOrigins
80
81
  });
81
82
  server.middlewares.use(created.nodeMiddleware);
82
83
  await created.ready;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@devframes/vite",
3
3
  "type": "module",
4
- "version": "0.9.9",
4
+ "version": "0.9.11",
5
5
  "description": "Vite plugin for mounting a devframe inside any Vite-based host (Astro, SolidStart, Nuxt, plain Vite apps).",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -30,9 +30,9 @@
30
30
  "dist"
31
31
  ],
32
32
  "peerDependencies": {
33
- "@devframes/hub": "0.9.9",
34
- "@devframes/hub-ui": "0.9.9",
35
- "devframe": "0.9.9",
33
+ "@devframes/hub": "0.9.11",
34
+ "@devframes/hub-ui": "0.9.11",
35
+ "devframe": "0.9.11",
36
36
  "vite": "^7.0.0 || ^8.0.0"
37
37
  },
38
38
  "peerDependenciesMeta": {
@@ -50,15 +50,17 @@
50
50
  "pathe": "^2.0.3"
51
51
  },
52
52
  "devDependencies": {
53
- "@devframes/hub": "0.9.9",
54
- "@devframes/hub-ui": "0.9.9",
53
+ "@devframes/hub": "0.9.11",
54
+ "@devframes/hub-ui": "0.9.11",
55
55
  "@modelcontextprotocol/client": "^2.0.0",
56
56
  "@types/node": "^26.4.0",
57
- "devframe": "0.9.9",
57
+ "@types/ws": "^8.18.1",
58
+ "devframe": "0.9.11",
58
59
  "get-port-please": "^3.2.0",
59
60
  "tsdown": "^0.22.14",
60
61
  "vite": "^8.2.2",
61
- "vitest": "^4.1.11"
62
+ "vitest": "^4.1.11",
63
+ "ws": "^8.21.3"
62
64
  },
63
65
  "scripts": {
64
66
  "build": "tsdown",