devframe 0.8.1 → 0.9.0-beta.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 (103) hide show
  1. package/dist/_shared-CttmCMBi.mjs +70 -0
  2. package/dist/_shared-DmpWW-HH.d.mts +43 -0
  3. package/dist/adapters/build.d.mts +1 -1
  4. package/dist/adapters/build.mjs +6 -5
  5. package/dist/adapters/cac.d.mts +1 -1
  6. package/dist/adapters/cac.mjs +157 -1
  7. package/dist/adapters/dev.d.mts +25 -34
  8. package/dist/adapters/dev.mjs +2 -1
  9. package/dist/adapters/embedded.d.mts +1 -1
  10. package/dist/adapters/initiate.d.mts +223 -0
  11. package/dist/adapters/initiate.mjs +2 -0
  12. package/dist/adapters/mcp.d.mts +26 -2
  13. package/dist/adapters/mcp.mjs +2 -2
  14. package/dist/cli/main.mjs +2 -2
  15. package/dist/client/index.d.mts +70 -6
  16. package/dist/client/index.mjs +743 -408
  17. package/dist/constants.d.mts +19 -6
  18. package/dist/constants.mjs +19 -6
  19. package/dist/{context-CQefP2jR.mjs → context-C33rR7n0.mjs} +1 -1
  20. package/dist/{context-DFzmxCLa.d.mts → context-CSCwoABx.d.mts} +1 -1
  21. package/dist/{host-h3-Kz7t5Xab.mjs → context-Du11TLcO.mjs} +5 -255
  22. package/dist/dev-BEveeA5H.mjs +233 -0
  23. package/dist/{devframe-qgCKL683.d.mts → devframe-Bdd9YXTy.d.mts} +88 -25
  24. package/dist/{diagnostics-B5-qHeqD.mjs → diagnostics-DLYH5oD3.mjs} +20 -0
  25. package/dist/dist-D8jAMwxU.mjs +227 -0
  26. package/dist/helpers/vite.d.mts +43 -39
  27. package/dist/helpers/vite.mjs +26 -38
  28. package/dist/host-agent-CpbAoqBx.mjs +230 -0
  29. package/dist/host-h3-CzCZwtuV.mjs +26 -0
  30. package/dist/{fetch-CK0S253E.mjs → http-DLr_cJZ7.mjs} +42 -4
  31. package/dist/{index-B7RgLw--.d.mts → index-CZRd2K1C.d.mts} +2 -2
  32. package/dist/{index-Dbw1p5ch.d.mts → index-DSCq4M4q.d.mts} +2 -31
  33. package/dist/index.d.mts +9 -4
  34. package/dist/index.mjs +8 -1
  35. package/dist/{instance-registry-D6fxYu36.mjs → instance-registry-BQqGoDO9.mjs} +9 -2
  36. package/dist/instance-shell-DBTXTSjN.d.mts +264 -0
  37. package/dist/instance-shell-KRdee1QF.mjs +485 -0
  38. package/dist/internal/index.d.mts +150 -0
  39. package/dist/internal/index.mjs +7 -0
  40. package/dist/node/auth.d.mts +2 -2
  41. package/dist/node/hub-internals.d.mts +2 -14
  42. package/dist/node/hub-internals.mjs +2 -2
  43. package/dist/node/index.d.mts +3 -267
  44. package/dist/node/index.mjs +3 -5
  45. package/dist/recipes/common-rpc-functions.d.mts +3 -3
  46. package/dist/recipes/interactive-auth.d.mts +3 -3
  47. package/dist/recipes/interactive-auth.mjs +6 -6
  48. package/dist/rolldown-runtime-JspESFgx.mjs +35 -0
  49. package/dist/rpc/dump.d.mts +77 -1
  50. package/dist/rpc/dump.mjs +1 -1
  51. package/dist/rpc/index.d.mts +2 -2
  52. package/dist/rpc/index.mjs +3 -17
  53. package/dist/rpc/transports/sse-client.d.mts +2 -0
  54. package/dist/rpc/transports/sse-client.mjs +142 -0
  55. package/dist/rpc/transports/sse-server.d.mts +61 -0
  56. package/dist/rpc/transports/sse-server.mjs +209 -0
  57. package/dist/rpc/transports/ws-bun.d.mts +35 -0
  58. package/dist/rpc/transports/ws-bun.mjs +31 -0
  59. package/dist/rpc/transports/ws-client.d.mts +1 -1
  60. package/dist/rpc/transports/ws-client.mjs +10 -18
  61. package/dist/rpc/transports/ws-server.d.mts +2 -2
  62. package/dist/rpc/transports/ws-server.mjs +2 -214
  63. package/dist/rpc-core-CGctXToO.d.mts +48 -0
  64. package/dist/rpc-core-CqcJkAu9.mjs +81 -0
  65. package/dist/{serialization-C8Mnw9hK.mjs → serialization-BHY8M5NQ.mjs} +1 -1
  66. package/dist/{shared-state-6kHolYZy.mjs → shared-state-fRRbRUtD.mjs} +1 -1
  67. package/dist/sse-client-BsIK3hMD.d.mts +37 -0
  68. package/dist/{dump-CgZShDRB.mjs → static-CvjkO8QE.mjs} +2 -265
  69. package/dist/{storage-Dzoc3NVC.mjs → storage-BcmVEJRc.mjs} +2 -2
  70. package/dist/types/index.d.mts +3 -3
  71. package/dist/types/index.mjs +1 -6
  72. package/dist/utils/events.d.mts +1 -1
  73. package/dist/utils/launch-editor.mjs +1 -25
  74. package/dist/utils/open.mjs +1 -1
  75. package/dist/utils/serve-static.mjs +1 -1
  76. package/dist/utils/shared-state.d.mts +1 -1
  77. package/dist/utils/shared-state.mjs +1 -1
  78. package/dist/utils/simple-schema.d.mts +101 -1
  79. package/dist/utils/streaming-channel.d.mts +1 -1
  80. package/dist/validation-BiuDXTKW.mjs +266 -0
  81. package/dist/wire-codec-9VhIKnyp.mjs +58 -0
  82. package/dist/{ws-client-B6Tnr0ic.d.mts → ws-client-CdNuATYa.d.mts} +6 -1
  83. package/dist/ws-server-Bk1hOG3X.mjs +267 -0
  84. package/dist/{ws-server-J-zkiOyp.d.mts → ws-server-Ces08fjP.d.mts} +102 -13
  85. package/package.json +10 -9
  86. package/skills/devframe/SKILL.md +84 -85
  87. package/dist/_shared-bWRzeSa0.mjs +0 -19
  88. package/dist/adapters/cli.d.mts +0 -11
  89. package/dist/adapters/cli.mjs +0 -6
  90. package/dist/cac-B1LM3zit.mjs +0 -157
  91. package/dist/dev-BSHFZGZr.mjs +0 -437
  92. package/dist/http-Dvgxujcu.mjs +0 -38
  93. package/dist/index-vAX6bYuc.d.mts +0 -78
  94. package/dist/recipes/open-helpers.d.mts +0 -6
  95. package/dist/recipes/open-helpers.mjs +0 -6
  96. package/dist/server-CXaDDUl0.mjs +0 -148
  97. package/dist/server-E9z4ZWbd.d.mts +0 -132
  98. package/dist/simple-schema-BDzLeJDk.d.mts +0 -102
  99. package/dist/utils/promise.d.mts +0 -8
  100. package/dist/utils/promise.mjs +0 -15
  101. package/dist/utils/scope.d.mts +0 -11
  102. package/dist/utils/scope.mjs +0 -15
  103. package/dist/{open-Deb5xmIT.mjs → open-Dz4V4irZ.mjs} +1 -1
@@ -1,8 +1,7 @@
1
- import { DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_WS_ROUTE } from "../constants.mjs";
2
- import { t as diagnostics } from "../diagnostics-B5-qHeqD.mjs";
3
- import { n as resolveBasePath, t as normalizeBasePath } from "../_shared-bWRzeSa0.mjs";
1
+ import { t as diagnostics } from "../diagnostics-DLYH5oD3.mjs";
2
+ import { n as resolveBasePath, t as normalizeBasePath } from "../_shared-CttmCMBi.mjs";
4
3
  import { serveStaticNodeMiddleware } from "../utils/serve-static.mjs";
5
- import { n as resolveDevServerPort, r as resolveMcpConnectionMeta, t as createDevServer } from "../dev-BSHFZGZr.mjs";
4
+ import { r as initDevframe } from "../dev-BEveeA5H.mjs";
6
5
  import { resolve } from "pathe";
7
6
  //#region src/helpers/vite.ts
8
7
  /**
@@ -13,16 +12,16 @@ import { resolve } from "pathe";
13
12
  * `options.base` with SPA fallback enabled. No RPC server is started.
14
13
  *
15
14
  * - **bridge mode** (`devMiddleware: true | {…}`) — skips the static
16
- * mount; the host app owns the SPA. Devframe starts a separate
17
- * RPC + WS dev server (via {@link createDevServer} in bridge mode)
18
- * and registers Vite middleware at `<base>__connection.json` so the
19
- * host-served SPA can discover the WS endpoint via
20
- * {@link connectDevframe}.
15
+ * mount; the host app owns the SPA. Devframe serves discovery
16
+ * (`<base>__connection.json`), the WebSocket RPC upgrade
17
+ * (`<base>__ws`, shared on Vite's own HTTP server), and the optional
18
+ * MCP route through {@link initDevframe}'s node middleware, so the
19
+ * host-served SPA can discover the endpoint via {@link connectDevframe}.
21
20
  *
22
- * The side-car RPC server **gates by default** (devframe's interactive OTP
23
- * unless the definition's `cli.auth` opts out), printing its code/link banner
24
- * to stdout, so a bridged devframe isn't silently reachable by anything that
25
- * can open its socket. Pass `options.auth: false` to opt out for a single-user
21
+ * The bridge **gates by default** (devframe's interactive OTP unless the
22
+ * definition's `cli.auth` opts out), printing its code/link banner to stdout,
23
+ * so a bridged devframe isn't silently reachable by anything that can open
24
+ * its socket. Pass `options.auth: false` to opt out for a single-user
26
25
  * localhost host, or a {@link DevframeAuthHandler} for a custom scheme.
27
26
  *
28
27
  * Use bridge mode when integrating with frameworks that own the SPA
@@ -43,24 +42,26 @@ function viteDevBridge(d, options = {}) {
43
42
  };
44
43
  }
45
44
  const mw = options.devMiddleware === true ? {} : options.devMiddleware;
46
- let started;
45
+ let instance;
47
46
  return {
48
47
  name: `devframe:${d.id}`,
49
48
  apply: "serve",
50
49
  async configureServer(server) {
51
- await started?.close().catch(() => {});
52
- started = void 0;
53
- let port;
50
+ await instance?.close().catch(() => {});
51
+ instance = void 0;
54
52
  try {
55
- port = mw.port ?? await resolveDevServerPort(d, { host: mw.host });
56
- started = await createDevServer(d, {
57
- host: mw.host,
58
- port,
53
+ const created = initDevframe(d, {
54
+ base,
55
+ distDir: false,
59
56
  flags: mw.flags,
60
- openBrowser: false,
57
+ host: mw.host,
58
+ ...mw.port != null ? { ws: { port: mw.port } } : server.httpServer ? { server: server.httpServer } : { ws: { sidecar: true } },
61
59
  auth: options.auth,
62
60
  mcp: options.mcp
63
61
  });
62
+ server.middlewares.use(created.nodeMiddleware);
63
+ await created.ready;
64
+ instance = created;
64
65
  } catch (e) {
65
66
  diagnostics.DF0033({
66
67
  id: d.id,
@@ -69,26 +70,13 @@ function viteDevBridge(d, options = {}) {
69
70
  }, { method: "warn" });
70
71
  return;
71
72
  }
72
- const mcpMeta = resolveMcpConnectionMeta(d, options.mcp, port);
73
- const metaPath = `${base}${DEVFRAME_CONNECTION_META_FILENAME}`;
74
- server.middlewares.use(metaPath, (_req, res) => {
75
- res.setHeader("Content-Type", "application/json");
76
- res.end(JSON.stringify({
77
- backend: "websocket",
78
- websocket: {
79
- port,
80
- path: `/${DEVFRAME_WS_ROUTE}`
81
- },
82
- ...mcpMeta ? { mcp: mcpMeta } : {}
83
- }));
84
- });
85
73
  server.httpServer?.once("close", () => {
86
- started?.close().catch(() => {});
74
+ instance?.close().catch(() => {});
87
75
  });
88
76
  },
89
77
  async closeBundle() {
90
- await started?.close().catch(() => {});
91
- started = void 0;
78
+ await instance?.close().catch(() => {});
79
+ instance = void 0;
92
80
  }
93
81
  };
94
82
  }
@@ -0,0 +1,230 @@
1
+ import { t as diagnostics } from "./diagnostics-DLYH5oD3.mjs";
2
+ import { i as createEventEmitter } from "./storage-BcmVEJRc.mjs";
3
+ //#region src/node/agent-args.ts
4
+ /**
5
+ * Map the args payload an agent surface receives (MCP sends an object
6
+ * keyed `arg0`/`arg1`/…, matching the schema the adapter advertises) onto
7
+ * a handler's positional parameters. Shared by the agent host's RPC
8
+ * bridge and the hub's command-derived tools so the coercion cannot
9
+ * drift between them.
10
+ *
11
+ * - an array passes through as-is
12
+ * - `null`/`undefined` become a zero-argument call
13
+ * - with declared schemas, each schema reads its own `argN` key, in order
14
+ * - without schemas, `arg0`/`arg1`/… keys are collected when present
15
+ * - an empty object becomes a zero-argument call
16
+ * - anything else follows the {@link AgentArgsFallback}
17
+ *
18
+ * @experimental
19
+ */
20
+ function coerceAgentPositionalArgs(args, schemas, fallback = "wrap") {
21
+ if (Array.isArray(args)) return args;
22
+ if (args === void 0 || args === null) return [];
23
+ if (typeof args === "object") {
24
+ const obj = args;
25
+ if (schemas && schemas.length) return schemas.map((_, i) => obj[`arg${i}`]);
26
+ if ("arg0" in obj) {
27
+ const out = [];
28
+ let i = 0;
29
+ while (`arg${i}` in obj) {
30
+ out.push(obj[`arg${i}`]);
31
+ i++;
32
+ }
33
+ return out;
34
+ }
35
+ if (Object.keys(obj).length === 0) return [];
36
+ }
37
+ return fallback === "drop" ? [] : [args];
38
+ }
39
+ //#endregion
40
+ //#region src/node/host-agent.ts
41
+ /**
42
+ * Framework-neutral host aggregating the agent-exposed surface of a
43
+ * devframe. Auto-discovers RPC functions with an `agent` field from
44
+ * `ctx.rpc.definitions`, and accepts plugin-registered tools /
45
+ * resources via `registerTool` / `registerResource`.
46
+ *
47
+ * @experimental
48
+ */
49
+ var DevframeAgentHost = class {
50
+ context;
51
+ events = createEventEmitter();
52
+ tools = /* @__PURE__ */ new Map();
53
+ resources = /* @__PURE__ */ new Map();
54
+ providers = /* @__PURE__ */ new Set();
55
+ _rpcUnsubscribe;
56
+ constructor(context) {
57
+ this.context = context;
58
+ this._rpcUnsubscribe = context.rpc.onChanged(() => {
59
+ this.events.emit("agent:manifest:changed");
60
+ });
61
+ }
62
+ registerTool(input) {
63
+ this._validateToolId(input.id);
64
+ const tool = this._projectTool(input);
65
+ this.tools.set(tool.id, {
66
+ tool,
67
+ handler: input.handler
68
+ });
69
+ this.events.emit("agent:tool:registered", tool);
70
+ this.events.emit("agent:manifest:changed");
71
+ return { unregister: () => this.unregisterTool(tool.id) };
72
+ }
73
+ unregisterTool(id) {
74
+ const existed = this.tools.delete(id);
75
+ if (existed) {
76
+ this.events.emit("agent:tool:unregistered", id);
77
+ this.events.emit("agent:manifest:changed");
78
+ }
79
+ return existed;
80
+ }
81
+ registerToolProvider(provider) {
82
+ this.providers.add(provider);
83
+ this.events.emit("agent:manifest:changed");
84
+ const notifyChanged = () => {
85
+ if (this.providers.has(provider)) this.events.emit("agent:manifest:changed");
86
+ };
87
+ return {
88
+ notifyChanged,
89
+ unregister: () => {
90
+ if (this.providers.delete(provider)) this.events.emit("agent:manifest:changed");
91
+ }
92
+ };
93
+ }
94
+ registerResource(input) {
95
+ if (this.resources.has(input.id)) throw diagnostics.DF0016({ id: input.id });
96
+ const resource = {
97
+ id: input.id,
98
+ name: input.name,
99
+ description: input.description,
100
+ mimeType: input.mimeType ?? "application/json",
101
+ uri: input.uri ?? `devframe://resource/${encodeURIComponent(input.id)}`
102
+ };
103
+ this.resources.set(resource.id, {
104
+ resource,
105
+ read: input.read
106
+ });
107
+ this.events.emit("agent:resource:registered", resource);
108
+ this.events.emit("agent:manifest:changed");
109
+ return { unregister: () => this.unregisterResource(resource.id) };
110
+ }
111
+ unregisterResource(id) {
112
+ const existed = this.resources.delete(id);
113
+ if (existed) {
114
+ this.events.emit("agent:resource:unregistered", id);
115
+ this.events.emit("agent:manifest:changed");
116
+ }
117
+ return existed;
118
+ }
119
+ list() {
120
+ const rpcTools = this._collectRpcTools();
121
+ const plainTools = Array.from(this.tools.values()).map((t) => t.tool);
122
+ const resources = Array.from(this.resources.values()).map((r) => r.resource);
123
+ const seen = new Set([...rpcTools, ...plainTools].map((t) => t.id));
124
+ const providerTools = [];
125
+ for (const { tool } of this._collectProviderTools()) {
126
+ if (seen.has(tool.id)) continue;
127
+ seen.add(tool.id);
128
+ providerTools.push(tool);
129
+ }
130
+ return {
131
+ tools: [
132
+ ...rpcTools,
133
+ ...plainTools,
134
+ ...providerTools
135
+ ],
136
+ resources
137
+ };
138
+ }
139
+ getTool(id) {
140
+ const plain = this.tools.get(id);
141
+ if (plain) return plain.tool;
142
+ const rpc = this._collectRpcTools().find((t) => t.id === id);
143
+ if (rpc) return rpc;
144
+ return this._collectProviderTools().find((t) => t.tool.id === id)?.tool;
145
+ }
146
+ getResource(id) {
147
+ return this.resources.get(id)?.resource;
148
+ }
149
+ async invoke(id, args) {
150
+ const plain = this.tools.get(id);
151
+ if (plain?.handler) return await plain.handler(args);
152
+ const rpcDef = this._findRpcDefinition(id);
153
+ if (rpcDef) {
154
+ const positional = coerceAgentPositionalArgs(args, rpcDef.args, "wrap");
155
+ return await this.context.rpc.invokeLocal(id, ...positional);
156
+ }
157
+ const provided = this._collectProviderTools().find((t) => t.tool.id === id);
158
+ if (provided) return await provided.input.handler(args);
159
+ throw new Error(`[devframe/agent] tool "${id}" not found`);
160
+ }
161
+ async read(id) {
162
+ const entry = this.resources.get(id);
163
+ if (!entry) throw new Error(`[devframe/agent] resource "${id}" not found`);
164
+ return await entry.read();
165
+ }
166
+ /** @internal */
167
+ _dispose() {
168
+ this._rpcUnsubscribe?.();
169
+ this._rpcUnsubscribe = void 0;
170
+ }
171
+ _validateToolId(id) {
172
+ if (this.tools.has(id)) throw diagnostics.DF0015({ id });
173
+ if (this.context.rpc.definitions.get(id)?.agent) throw diagnostics.DF0015({ id });
174
+ }
175
+ _projectTool(input) {
176
+ if (!input.description || typeof input.description !== "string") throw diagnostics.DF0014({ name: input.id });
177
+ return {
178
+ id: input.id,
179
+ kind: "tool",
180
+ title: input.title ?? input.id,
181
+ description: input.description,
182
+ safety: input.safety ?? "action",
183
+ tags: input.tags,
184
+ args: input.args,
185
+ inputSchema: input.inputSchema,
186
+ outputSchema: input.outputSchema,
187
+ examples: input.examples
188
+ };
189
+ }
190
+ /** Query every registered provider, projecting inputs to serializable tools. */
191
+ _collectProviderTools() {
192
+ const out = [];
193
+ for (const provider of this.providers) for (const input of provider()) out.push({
194
+ input,
195
+ tool: this._projectTool(input)
196
+ });
197
+ return out;
198
+ }
199
+ _collectRpcTools() {
200
+ const out = [];
201
+ for (const [name, def] of this.context.rpc.definitions) {
202
+ const agent = def.agent;
203
+ if (!agent) continue;
204
+ if (!agent.description || typeof agent.description !== "string") throw diagnostics.DF0014({ name });
205
+ const type = def.type ?? "query";
206
+ const safety = agent.safety ?? inferSafety(type);
207
+ out.push({
208
+ id: name,
209
+ kind: "rpc",
210
+ title: agent.title ?? name,
211
+ description: agent.description,
212
+ safety,
213
+ tags: agent.tags,
214
+ rpcName: name,
215
+ examples: agent.examples
216
+ });
217
+ }
218
+ return out;
219
+ }
220
+ _findRpcDefinition(id) {
221
+ const def = this.context.rpc.definitions.get(id);
222
+ if (def?.agent) return def;
223
+ }
224
+ };
225
+ function inferSafety(type) {
226
+ if (type === "static" || type === "query") return "read";
227
+ return "action";
228
+ }
229
+ //#endregion
230
+ export { coerceAgentPositionalArgs as n, DevframeAgentHost as t };
@@ -0,0 +1,26 @@
1
+ import { join } from "pathe";
2
+ import process from "node:process";
3
+ import { homedir } from "node:os";
4
+ //#region src/node/host-h3.ts
5
+ /**
6
+ * h3-backed {@link DevframeHost} — used by the standalone CLI adapter.
7
+ */
8
+ function createH3DevframeHost(options) {
9
+ const workspaceRoot = options.workspaceRoot ?? process.cwd();
10
+ return {
11
+ mountStatic(base, distDir) {
12
+ return options.mount?.(base, distDir);
13
+ },
14
+ resolveOrigin() {
15
+ return typeof options.origin === "function" ? options.origin() : options.origin;
16
+ },
17
+ getStorageDir(scope) {
18
+ const namespace = `.${options.appName}/devframe`;
19
+ if (scope === "workspace") return join(workspaceRoot, ".devframe");
20
+ if (scope === "project") return join(workspaceRoot, "node_modules", namespace);
21
+ return join(homedir(), namespace);
22
+ }
23
+ };
24
+ }
25
+ //#endregion
26
+ export { createH3DevframeHost as t };
@@ -1,12 +1,14 @@
1
- import { isAllowedOrigin } from "./rpc/transports/ws-server.mjs";
2
- import { n as createHostContext } from "./host-h3-Kz7t5Xab.mjs";
3
- import { t as diagnostics } from "./diagnostics-B5-qHeqD.mjs";
1
+ import { n as __exportAll } from "./rolldown-runtime-JspESFgx.mjs";
2
+ import { i as isAllowedOrigin } from "./ws-server-Bk1hOG3X.mjs";
3
+ import { t as diagnostics } from "./diagnostics-DLYH5oD3.mjs";
4
+ import { t as createHostContext } from "./context-Du11TLcO.mjs";
4
5
  import { t as toAgentToolName } from "./agent-tool-name-C3b5vEwJ.mjs";
5
6
  import { randomUUID } from "node:crypto";
6
7
  import { Diagnostic } from "nostics";
7
8
  import { join } from "pathe";
8
9
  import process from "node:process";
9
10
  import { homedir } from "node:os";
11
+ import { defineHandler } from "h3";
10
12
  import { Server, WebStandardStreamableHTTPServerTransport, isInitializeRequest } from "@modelcontextprotocol/server";
11
13
  //#region src/adapters/mcp/stringify.ts
12
14
  /**
@@ -531,4 +533,40 @@ function createMcpFetchHandler(ctx, options) {
531
533
  };
532
534
  }
533
535
  //#endregion
534
- export { createMcpServer as n, createMcpFetchHandler as t };
536
+ //#region src/adapters/mcp/http.ts
537
+ var http_exports = /* @__PURE__ */ __exportAll({ mountMcpHttp: () => mountMcpHttp });
538
+ /**
539
+ * Mount an MCP Streamable-HTTP endpoint on an h3 app at `path` — the h3
540
+ * binding over {@link createMcpFetchHandler}, which owns the sessions, the
541
+ * origin gate, and the transport plumbing.
542
+ *
543
+ * The handler is web-standard — it takes the h3 event's web `Request` and
544
+ * returns a web `Response` (an SSE `ReadableStream` body for the
545
+ * server→client stream). We copy that response onto `event.res` and return
546
+ * its body rather than returning the `Response` object directly, so a
547
+ * legitimate MCP 404 (unknown session) isn't swallowed by h3's
548
+ * "Response-with-404 falls through to the next handler" rule (which would
549
+ * otherwise hand the request to the SPA static catch-all).
550
+ *
551
+ * @experimental
552
+ */
553
+ function mountMcpHttp(app, ctx, path, options) {
554
+ const handler = createMcpFetchHandler(ctx, options);
555
+ app.use(path, defineHandler(async (event) => respond(event, await handler.fetch(event.req))));
556
+ return { dispose: handler.dispose };
557
+ }
558
+ /**
559
+ * Copy a web `Response` from the MCP transport onto the h3 event's response
560
+ * and return its body. Returning the body (a `ReadableStream` or `null`)
561
+ * rather than the `Response` object avoids h3's 404-fall-through behavior.
562
+ */
563
+ function respond(event, response) {
564
+ event.res.status = response.status;
565
+ event.res.statusText = response.statusText;
566
+ response.headers.forEach((value, key) => {
567
+ event.res.headers.set(key, value);
568
+ });
569
+ return response.body ?? "";
570
+ }
571
+ //#endregion
572
+ export { createMcpServer as i, mountMcpHttp as n, createMcpFetchHandler as r, http_exports as t };
@@ -1,5 +1,5 @@
1
- import { W as DevframeNodeRpcSession, b as DevframeNodeContext, ht as SharedState } from "./devframe-qgCKL683.mjs";
2
- import { n as InternalAnonymousAuthStorage } from "./context-DFzmxCLa.mjs";
1
+ import { G as DevframeNodeRpcSession, gt as SharedState, x as DevframeNodeContext } from "./devframe-Bdd9YXTy.mjs";
2
+ import { n as InternalAnonymousAuthStorage } from "./context-CSCwoABx.mjs";
3
3
  //#region src/node/auth/revoke.d.ts
4
4
  /**
5
5
  * Flip `isTrusted` to false on any live WS clients connected with `token`
@@ -1,5 +1,4 @@
1
1
  import { C as RpcFunctionType, S as RpcFunctionSetupResult, T as RpcReturnSchema, _ as RpcFunctionDefinition, i as RpcArgsSchema, v as RpcFunctionDefinitionAny, w as RpcFunctionsCollector } from "./types-CnJSgRVa.mjs";
2
- import { a as getDefinitionsWithDumps$1, c as StaticRpcDumpManifest$1, d as StaticRpcDumpManifestValue$1, f as StaticRpcDumpSerialization$1, i as dumpFunctions$1, l as StaticRpcDumpManifestQueryEntry$1, n as serializeDumpError$1, o as StaticRpcDumpCollection$1, p as collectStaticRpcDump$1, r as createClientFromDump$1, s as StaticRpcDumpFile$1, t as reviveDumpError$1, u as StaticRpcDumpManifestStaticEntry$1 } from "./index-vAX6bYuc.mjs";
3
2
  //#region src/rpc/cache.d.ts
4
3
  interface RpcCacheOptions {
5
4
  functions: string[];
@@ -54,7 +53,7 @@ declare function getRpcHandler<NAME extends string, TYPE extends RpcFunctionType
54
53
  //#endregion
55
54
  //#region src/rpc/serialization.d.ts
56
55
  /**
57
- * Wire format used by the WS RPC transport.
56
+ * Wire format used by the live RPC transports (WebSocket and SSE).
58
57
  *
59
58
  * - **JSON (default, unprefixed):** payload is plain JSON text. Used when
60
59
  * the dispatched method is declared `jsonSerializable: true`. Encoded
@@ -133,32 +132,4 @@ declare function validateDefinitions(definitions: readonly RpcFunctionDefinition
133
132
  */
134
133
  declare function validateDefinition(definition: RpcFunctionDefinitionAny): void;
135
134
  //#endregion
136
- //#region src/rpc/index.d.ts
137
- /** @deprecated Import from `devframe/rpc/dump` instead. */
138
- declare const collectStaticRpcDump: typeof collectStaticRpcDump$1;
139
- /** @deprecated Import from `devframe/rpc/dump` instead. */
140
- declare const createClientFromDump: typeof createClientFromDump$1;
141
- /** @deprecated Import from `devframe/rpc/dump` instead. */
142
- declare const dumpFunctions: typeof dumpFunctions$1;
143
- /** @deprecated Import from `devframe/rpc/dump` instead. */
144
- declare const getDefinitionsWithDumps: typeof getDefinitionsWithDumps$1;
145
- /** @deprecated Import from `devframe/rpc/dump` instead. */
146
- declare const reviveDumpError: typeof reviveDumpError$1;
147
- /** @deprecated Import from `devframe/rpc/dump` instead. */
148
- declare const serializeDumpError: typeof serializeDumpError$1;
149
- /** @deprecated Import from `devframe/rpc/dump` instead. */
150
- type StaticRpcDumpCollection = StaticRpcDumpCollection$1;
151
- /** @deprecated Import from `devframe/rpc/dump` instead. */
152
- type StaticRpcDumpFile = StaticRpcDumpFile$1;
153
- /** @deprecated Import from `devframe/rpc/dump` instead. */
154
- type StaticRpcDumpManifest = StaticRpcDumpManifest$1;
155
- /** @deprecated Import from `devframe/rpc/dump` instead. */
156
- type StaticRpcDumpManifestQueryEntry = StaticRpcDumpManifestQueryEntry$1;
157
- /** @deprecated Import from `devframe/rpc/dump` instead. */
158
- type StaticRpcDumpManifestStaticEntry = StaticRpcDumpManifestStaticEntry$1;
159
- /** @deprecated Import from `devframe/rpc/dump` instead. */
160
- type StaticRpcDumpManifestValue = StaticRpcDumpManifestValue$1;
161
- /** @deprecated Import from `devframe/rpc/dump` instead. */
162
- type StaticRpcDumpSerialization = StaticRpcDumpSerialization$1;
163
- //#endregion
164
- export { defineRpcFunction as C, RpcCacheOptions as E, createDefineWrapperWithContext as S, RpcCacheManager as T, validateRpcReturn as _, StaticRpcDumpManifestStaticEntry as a, getRpcHandler as b, collectStaticRpcDump as c, getDefinitionsWithDumps as d, reviveDumpError as f, validateRpcArgs as g, validateDefinitions as h, StaticRpcDumpManifestQueryEntry as i, createClientFromDump as l, validateDefinition as m, StaticRpcDumpFile as n, StaticRpcDumpManifestValue as o, serializeDumpError as p, StaticRpcDumpManifest as r, StaticRpcDumpSerialization as s, StaticRpcDumpCollection as t, dumpFunctions as u, STRUCTURED_CLONE_PREFIX as v, RpcFunctionsCollectorBase as w, getRpcResolvedSetupResult as x, strictJsonStringify as y };
135
+ export { STRUCTURED_CLONE_PREFIX as a, getRpcResolvedSetupResult as c, RpcFunctionsCollectorBase as d, RpcCacheManager as f, validateRpcReturn as i, createDefineWrapperWithContext as l, validateDefinitions as n, strictJsonStringify as o, RpcCacheOptions as p, validateRpcArgs as r, getRpcHandler as s, validateDefinition as t, defineRpcFunction as u };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,13 @@
1
- import { $ as DevframeRpcServerFunctions, A as DevframeSettingsStore, At as DevframeAgentHostEvents, B as DevframeDefineDiagnosticsOptions, C as DevframeServicesHost, Ct as AgentResourceContent, D as DevframeScopedStreamingHost, Dt as AgentToolProvider, E as DevframeScopedNodeRpc, Et as AgentToolInput, F as ScopedSharedStates, G as RpcBroadcastOptions, H as DevframeDiagnosticsHost, I as SettingsForNamespace, J as RpcSharedStateHost, K as RpcFunctionsHost, L as DevframeViewHost, M as ScopedClientFunctions, Mt as EventUnsubscribe, N as ScopedRpcFn, Nt as EventsMap, O as DevframeSettings, Ot as AgentToolProviderHandle, P as ScopedServerFunctions, Q as DevframeRpcClientFunctions, R as DevframeHost, S as DevframeServiceOf, St as AgentResource, T as DevframeScopedNodeContext, Tt as AgentTool, U as DevframeDiagnosticsLogger, V as DevframeDiagnosticsDefinition, W as DevframeNodeRpcSession, X as RpcStreamingChannelOptions, Y as RpcStreamingChannel, Z as RpcStreamingHost, _ as ConnectionMeta, a as DevframeDockDefaults, b as DevframeNodeContext, bt as AgentHandle, c as DevframeSetupInfo, d as McpRouteOptions, et as DevframeRpcSharedStates, f as defineDevframe, g as Thenable, h as PartialWithoutId, i as DevframeDeploymentKind, j as ScopedBroadcastOptions, jt as EventEmitter, k as DevframeSettingsRegistry, kt as DevframeAgentHost, l as DevframeSpaOptions, m as EntriesToObject, n as DevframeCliOptions, o as DevframeDuplicationStrategy, q as RpcSharedStateGetOptions, r as DevframeDefinition, s as DevframeRuntime, t as DevframeBrowserContext, u as DevframeWsOptions, v as ConnectionMetaWebsocket, w as DevframeServicesRegistry, wt as AgentResourceInput, x as DevframeServiceId, xt as AgentManifest, y as DevframeCapabilities, z as DevframeStorageScope } from "./devframe-qgCKL683.mjs";
1
+ import { $ as DevframeRpcClientFunctions, A as DevframeSettingsRegistry, At as DevframeAgentHost, B as DevframeStorageScope, C as DevframeServiceOf, Ct as AgentResource, D as DevframeScopedNodeRpc, Dt as AgentToolInput, E as DevframeScopedNodeContext, Et as AgentTool, F as ScopedServerFunctions, G as DevframeNodeRpcSession, H as DevframeDiagnosticsDefinition, I as ScopedSharedStates, J as RpcSharedStateGetOptions, K as RpcBroadcastOptions, L as SettingsForNamespace, M as ScopedBroadcastOptions, Mt as EventEmitter, N as ScopedClientFunctions, Nt as EventUnsubscribe, O as DevframeScopedStreamingHost, Ot as AgentToolProvider, P as ScopedRpcFn, Pt as EventsMap, Q as RpcStreamingHost, R as DevframeViewHost, S as DevframeServiceId, St as AgentManifest, T as DevframeServicesRegistry, Tt as AgentResourceInput, U as DevframeDiagnosticsHost, V as DevframeDefineDiagnosticsOptions, W as DevframeDiagnosticsLogger, X as RpcStreamingChannel, Y as RpcSharedStateHost, Z as RpcStreamingChannelOptions, _ as ConnectionMeta, a as DevframeDockDefaults, b as DevframeCapabilities, c as DevframeSetupInfo, d as DevframeWsOptions, et as DevframeRpcServerFunctions, f as McpRouteOptions, g as Thenable, h as PartialWithoutId, i as DevframeDeploymentKind, j as DevframeSettingsStore, jt as DevframeAgentHostEvents, k as DevframeSettings, kt as AgentToolProviderHandle, l as DevframeSpaOptions, m as EntriesToObject, n as DevframeCliOptions, o as DevframeDuplicationStrategy, q as RpcFunctionsHost, r as DevframeDefinition, s as DevframeRuntime, t as DevframeBrowserContext, tt as DevframeRpcSharedStates, u as DevframeSseOptions, v as ConnectionMetaSse, w as DevframeServicesHost, wt as AgentResourceContent, x as DevframeNodeContext, xt as AgentHandle, y as ConnectionMetaWebsocket, z as DevframeHost } from "./devframe-Bdd9YXTy.mjs";
2
+ import "./index-DSCq4M4q.mjs";
2
3
  import { C as RpcFunctionType, T as RpcReturnSchema, _ as RpcFunctionDefinition, g as RpcFunctionAgentOptions, i as RpcArgsSchema } from "./types-CnJSgRVa.mjs";
3
- import "./index-Dbw1p5ch.mjs";
4
- import { n as DevframeNodeRpcSessionMeta } from "./ws-server-J-zkiOyp.mjs";
4
+ import { d as DevframeRpcConnection, f as DevframeRpcConnectionRequest, p as DevframeRpcTransportKind, u as DevframeNodeRpcSessionMeta } from "./ws-server-Ces08fjP.mjs";
5
5
  //#region src/define.d.ts
6
6
  declare const defineRpcFunction: <NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void, const AS extends RpcArgsSchema | undefined = undefined, const RS extends RpcReturnSchema | undefined = undefined>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS, DevframeNodeContext>) => RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS, DevframeNodeContext>;
7
+ /**
8
+ * Identity helper that types a devframe definition — the primary authoring
9
+ * entry point. Import it from the package root: `import { defineDevframe } from 'devframe'`.
10
+ */
11
+ declare function defineDevframe(d: DevframeDefinition): DevframeDefinition;
7
12
  //#endregion
8
- export { type AgentHandle, type AgentManifest, type AgentResource, type AgentResourceContent, type AgentResourceInput, type AgentTool, type AgentToolInput, type AgentToolProvider, type AgentToolProviderHandle, type ConnectionMeta, type ConnectionMetaWebsocket, type DevframeAgentHost, type DevframeAgentHostEvents, type DevframeBrowserContext, type DevframeCapabilities, type DevframeCliOptions, type DevframeDefineDiagnosticsOptions, type DevframeDefinition, type DevframeDeploymentKind, type DevframeDiagnosticsDefinition, type DevframeDiagnosticsHost, type DevframeDiagnosticsLogger, type DevframeDockDefaults, type DevframeDuplicationStrategy, type DevframeHost, type DevframeNodeContext, type DevframeNodeRpcSession, type DevframeNodeRpcSessionMeta, type DevframeRpcClientFunctions, type DevframeRpcServerFunctions, type DevframeRpcSharedStates, type DevframeRuntime, type DevframeScopedNodeContext, type DevframeScopedNodeRpc, type DevframeScopedStreamingHost, type DevframeServiceId, type DevframeServiceOf, type DevframeServicesHost, type DevframeServicesRegistry, type DevframeSettings, type DevframeSettingsRegistry, type DevframeSettingsStore, type DevframeSetupInfo, type DevframeSpaOptions, type DevframeStorageScope, type DevframeViewHost, type DevframeWsOptions, type EntriesToObject, type EventEmitter, type EventUnsubscribe, type EventsMap, type McpRouteOptions, type PartialWithoutId, type RpcBroadcastOptions, type RpcFunctionAgentOptions, type RpcFunctionsHost, type RpcSharedStateGetOptions, type RpcSharedStateHost, type RpcStreamingChannel, type RpcStreamingChannelOptions, type RpcStreamingHost, type ScopedBroadcastOptions, type ScopedClientFunctions, type ScopedRpcFn, type ScopedServerFunctions, type ScopedSharedStates, type SettingsForNamespace, type Thenable, type defineDevframe, defineRpcFunction };
13
+ export { type AgentHandle, type AgentManifest, type AgentResource, type AgentResourceContent, type AgentResourceInput, type AgentTool, type AgentToolInput, type AgentToolProvider, type AgentToolProviderHandle, type ConnectionMeta, type ConnectionMetaSse, type ConnectionMetaWebsocket, type DevframeAgentHost, type DevframeAgentHostEvents, type DevframeBrowserContext, type DevframeCapabilities, type DevframeCliOptions, type DevframeDefineDiagnosticsOptions, type DevframeDefinition, type DevframeDeploymentKind, type DevframeDiagnosticsDefinition, type DevframeDiagnosticsHost, type DevframeDiagnosticsLogger, type DevframeDockDefaults, type DevframeDuplicationStrategy, type DevframeHost, type DevframeNodeContext, type DevframeNodeRpcSession, type DevframeNodeRpcSessionMeta, type DevframeRpcClientFunctions, type DevframeRpcConnection, type DevframeRpcConnectionRequest, type DevframeRpcServerFunctions, type DevframeRpcSharedStates, type DevframeRpcTransportKind, type DevframeRuntime, type DevframeScopedNodeContext, type DevframeScopedNodeRpc, type DevframeScopedStreamingHost, type DevframeServiceId, type DevframeServiceOf, type DevframeServicesHost, type DevframeServicesRegistry, type DevframeSettings, type DevframeSettingsRegistry, type DevframeSettingsStore, type DevframeSetupInfo, type DevframeSpaOptions, type DevframeSseOptions, type DevframeStorageScope, type DevframeViewHost, type DevframeWsOptions, type EntriesToObject, type EventEmitter, type EventUnsubscribe, type EventsMap, type McpRouteOptions, type PartialWithoutId, type RpcBroadcastOptions, type RpcFunctionAgentOptions, type RpcFunctionsHost, type RpcSharedStateGetOptions, type RpcSharedStateHost, type RpcStreamingChannel, type RpcStreamingChannelOptions, type RpcStreamingHost, type ScopedBroadcastOptions, type ScopedClientFunctions, type ScopedRpcFn, type ScopedServerFunctions, type ScopedSharedStates, type SettingsForNamespace, type Thenable, defineDevframe, defineRpcFunction };
package/dist/index.mjs CHANGED
@@ -1,5 +1,12 @@
1
1
  import { t as createDefineWrapperWithContext } from "./define-BLWPsH6y.mjs";
2
2
  //#region src/define.ts
3
3
  const defineRpcFunction = createDefineWrapperWithContext();
4
+ /**
5
+ * Identity helper that types a devframe definition — the primary authoring
6
+ * entry point. Import it from the package root: `import { defineDevframe } from 'devframe'`.
7
+ */
8
+ function defineDevframe(d) {
9
+ return d;
10
+ }
4
11
  //#endregion
5
- export { defineRpcFunction };
12
+ export { defineDevframe, defineRpcFunction };
@@ -1,9 +1,16 @@
1
- import { t as diagnostics } from "./diagnostics-B5-qHeqD.mjs";
1
+ import { n as __exportAll } from "./rolldown-runtime-JspESFgx.mjs";
2
+ import { t as diagnostics } from "./diagnostics-DLYH5oD3.mjs";
2
3
  import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { join } from "pathe";
4
5
  import process from "node:process";
5
6
  import { homedir } from "node:os";
6
7
  //#region src/node/instance-registry.ts
8
+ var instance_registry_exports = /* @__PURE__ */ __exportAll({
9
+ listLiveDevframeInstances: () => listLiveDevframeInstances,
10
+ probeDevframeOrigin: () => probeDevframeOrigin,
11
+ readDevframeInstances: () => readDevframeInstances,
12
+ registerDevframeInstance: () => registerDevframeInstance
13
+ });
7
14
  /** Environment variable overriding the registry directory (tests, CI). */
8
15
  const DEVFRAME_INSTANCES_DIR_ENV = "DEVFRAME_INSTANCES_DIR";
9
16
  /** Environment variable disabling instance registration entirely. */
@@ -187,4 +194,4 @@ async function listLiveDevframeInstances(options = {}) {
187
194
  };
188
195
  }
189
196
  //#endregion
190
- export { probeDevframeOrigin as n, registerDevframeInstance as r, listLiveDevframeInstances as t };
197
+ export { registerDevframeInstance as i, listLiveDevframeInstances as n, probeDevframeOrigin as r, instance_registry_exports as t };