devframe 0.8.2 → 0.9.0-beta.10
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/_shared-BPmX9fqK.d.mts +41 -0
- package/dist/_shared-CbZ_yhbz.mjs +68 -0
- package/dist/adapters/build.d.mts +10 -12
- package/dist/adapters/build.mjs +26 -29
- package/dist/adapters/cac.d.mts +1 -1
- package/dist/adapters/cac.mjs +156 -1
- package/dist/adapters/dev.d.mts +38 -46
- package/dist/adapters/dev.mjs +2 -1
- package/dist/adapters/embedded.d.mts +1 -1
- package/dist/adapters/initiate.d.mts +224 -0
- package/dist/adapters/initiate.mjs +2 -0
- package/dist/adapters/mcp.d.mts +24 -7
- package/dist/adapters/mcp.mjs +2 -2
- package/dist/{agent-tool-name-C3b5vEwJ.mjs → agent-tool-name-EgfoFO8C.mjs} +0 -3
- package/dist/cli/main.d.mts +0 -2
- package/dist/cli/main.mjs +4 -8
- package/dist/client/index.d.mts +71 -7
- package/dist/client/index.mjs +720 -1540
- package/dist/constants.d.mts +28 -7
- package/dist/constants.mjs +28 -7
- package/dist/{context-DoSozfvx.d.mts → context-B3YUu_95.d.mts} +19 -1
- package/dist/{host-h3-D2hYZvDK.mjs → context-CEe4PBz1.mjs} +25 -557
- package/dist/{context-CBg8iRbQ.mjs → context-xdynGSLP.mjs} +10 -1
- package/dist/dev--rAPzbvO.mjs +239 -0
- package/dist/{devframe-mQ4qZAuo.d.mts → devframe-DJMg0WLe.d.mts} +181 -134
- package/dist/{diagnostics-hwjXp_UV.mjs → diagnostics-CD8nlgll.mjs} +1 -3
- package/dist/{diagnostics-D7wM2cwM.mjs → diagnostics-DOQPnQmX.mjs} +51 -5
- package/dist/dist-eNI9qM_I.mjs +228 -0
- package/dist/host-agent-xLCSe65D.mjs +264 -0
- package/dist/host-h3-Crkzm42q.mjs +26 -0
- package/dist/{fetch-BKaD0Vb3.mjs → http-DYpK0cUi.mjs} +42 -11
- package/dist/{index-b64Uuhy2.d.mts → index-CB-fSUyn.d.mts} +2 -2
- package/dist/{index-Dbw1p5ch.d.mts → index-tdrk1bzV.d.mts} +3 -32
- package/dist/index.d.mts +12 -5
- package/dist/index.mjs +8 -1
- package/dist/{instance-registry-BnnA2Eoh.mjs → instance-registry-WvQkt42E.mjs} +9 -8
- package/dist/instance-shell-CMFyszWJ.mjs +486 -0
- package/dist/instance-shell-CljiKq1c.d.mts +255 -0
- package/dist/internal/index.d.mts +397 -0
- package/dist/internal/index.mjs +9 -0
- package/dist/node/auth.d.mts +2 -2
- package/dist/node/auth.mjs +1 -1
- package/dist/node/hub-internals.d.mts +2 -14
- package/dist/node/hub-internals.mjs +2 -2
- package/dist/node/index.d.mts +4 -268
- package/dist/node/index.mjs +3 -5
- package/dist/nostics-CzECRXpE.mjs +59 -0
- package/dist/nostics-SPGDgHEP.d.mts +33 -0
- package/dist/recipes/common-rpc-functions.d.mts +4 -4
- package/dist/recipes/interactive-auth.d.mts +3 -3
- package/dist/recipes/interactive-auth.mjs +8 -8
- package/dist/remote-assets-Bg4gCUZ_.d.mts +123 -0
- package/dist/remote-assets-nTTxY2MU.mjs +636 -0
- package/dist/rolldown-runtime-JspESFgx.mjs +35 -0
- package/dist/rpc/dump.d.mts +77 -1
- package/dist/rpc/dump.mjs +1 -1
- package/dist/rpc/index.d.mts +3 -3
- package/dist/rpc/index.mjs +4 -18
- package/dist/rpc/transports/sse-client.d.mts +2 -0
- package/dist/rpc/transports/sse-client.mjs +142 -0
- package/dist/rpc/transports/sse-server.d.mts +61 -0
- package/dist/rpc/transports/sse-server.mjs +209 -0
- package/dist/rpc/transports/ws-bun.d.mts +35 -0
- package/dist/rpc/transports/ws-bun.mjs +31 -0
- package/dist/rpc/transports/ws-client.d.mts +1 -1
- package/dist/rpc/transports/ws-client.mjs +10 -18
- package/dist/rpc/transports/ws-server.d.mts +2 -2
- package/dist/rpc/transports/ws-server.mjs +2 -235
- package/dist/rpc-core-Cc4lucI0.d.mts +48 -0
- package/dist/rpc-core-DMTe-hLo.mjs +81 -0
- package/dist/{serialization-C8Mnw9hK.mjs → serialization-BGzEwAdr.mjs} +2 -2
- package/dist/{shared-state-6kHolYZy.mjs → shared-state-fRRbRUtD.mjs} +1 -1
- package/dist/sse-client-CFBOIaUi.d.mts +37 -0
- package/dist/state-Cc1IeSmQ.mjs +1291 -0
- package/dist/{dump-CgZShDRB.mjs → static-BPZ1_OPA.mjs} +3 -266
- package/dist/storage-CYye7P7L.mjs +137 -0
- package/dist/types/index.d.mts +6 -4
- package/dist/types/index.mjs +1 -6
- package/dist/{types-CnJSgRVa.d.mts → types-Djq7CBXh.d.mts} +0 -7
- package/dist/utils/agent-tool-name.d.mts +0 -3
- package/dist/utils/agent-tool-name.mjs +0 -3
- package/dist/utils/events.d.mts +1 -1
- package/dist/utils/get-port.d.mts +17 -0
- package/dist/utils/get-port.mjs +2 -0
- package/dist/utils/launch-editor.mjs +1 -25
- package/dist/utils/nostics.d.mts +2 -0
- package/dist/utils/nostics.mjs +2 -0
- package/dist/utils/open.d.mts +2 -10
- package/dist/utils/open.mjs +56 -1
- package/dist/utils/remote-assets.d.mts +15 -0
- package/dist/utils/remote-assets.mjs +2 -0
- package/dist/utils/serve-static.d.mts +13 -5
- package/dist/utils/serve-static.mjs +119 -9
- package/dist/utils/shared-state.d.mts +1 -1
- package/dist/utils/shared-state.mjs +1 -1
- package/dist/utils/simple-schema.d.mts +101 -1
- package/dist/utils/streaming-channel.d.mts +1 -1
- package/dist/validation-CpXFB6Dz.mjs +266 -0
- package/dist/wire-codec-0K-o5MYW.mjs +56 -0
- package/dist/{ws-client-B6Tnr0ic.d.mts → ws-client-DhjNyQo3.d.mts} +7 -2
- package/dist/ws-server-BdSLrhxE.mjs +267 -0
- package/dist/{ws-server-uKQcClcJ.d.mts → ws-server-D1d3QM9f.d.mts} +90 -9
- package/package.json +13 -12
- package/skills/devframe/SKILL.md +91 -93
- package/dist/_shared-bWRzeSa0.mjs +0 -19
- package/dist/adapters/cli.d.mts +0 -11
- package/dist/adapters/cli.mjs +0 -6
- package/dist/cac-D4_9ok0z.mjs +0 -157
- package/dist/dev-Bc49u3qg.mjs +0 -439
- package/dist/diagnostics-reporter-CsIG85Q5.mjs +0 -38
- package/dist/helpers/vite.d.mts +0 -100
- package/dist/helpers/vite.mjs +0 -105
- package/dist/http-C4T68YV6.mjs +0 -38
- package/dist/index-vAX6bYuc.d.mts +0 -78
- package/dist/open-Deb5xmIT.mjs +0 -547
- package/dist/recipes/open-helpers.d.mts +0 -6
- package/dist/recipes/open-helpers.mjs +0 -6
- package/dist/server-CD8XmBXl.mjs +0 -167
- package/dist/server-UHWae43Q.d.mts +0 -149
- package/dist/simple-schema-BDzLeJDk.d.mts +0 -102
- package/dist/state-BeUHDDjk.mjs +0 -108
- package/dist/storage-CTNVbuFB.mjs +0 -1122
- package/dist/utils/promise.d.mts +0 -8
- package/dist/utils/promise.mjs +0 -15
- package/dist/utils/scope.d.mts +0 -11
- package/dist/utils/scope.mjs +0 -15
- package/skills/devframe/templates/spa-devframe.ts +0 -38
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { DEVFRAME_CONNECTION_META_FILENAME } from "./constants.mjs";
|
|
2
|
+
import { t as diagnostics } from "./diagnostics-DOQPnQmX.mjs";
|
|
3
|
+
import { t as createHostContext } from "./context-CEe4PBz1.mjs";
|
|
4
|
+
import { t as resolveStaticAssetsSource } from "./remote-assets-nTTxY2MU.mjs";
|
|
5
|
+
import { i as resolveMcpConnectionMeta, n as resolveBasePath, r as resolveDevServerPort, t as normalizeBasePath } from "./_shared-CbZ_yhbz.mjs";
|
|
6
|
+
import { t as createH3DevframeHost } from "./host-h3-Crkzm42q.mjs";
|
|
7
|
+
import { i as normalizeHttpServerUrl, n as resolveInstanceRegister, t as createInstanceShell } from "./instance-shell-CMFyszWJ.mjs";
|
|
8
|
+
import { open } from "./utils/open.mjs";
|
|
9
|
+
import { mountStaticHandler } from "./utils/serve-static.mjs";
|
|
10
|
+
import { createServer } from "node:http";
|
|
11
|
+
import { resolve } from "pathe";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
import { joinURL, withBase } from "ufo";
|
|
14
|
+
import { H3, toNodeHandler } from "h3";
|
|
15
|
+
//#region src/adapters/initiate.ts
|
|
16
|
+
const INSTANCE_INTERNALS = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
/** @internal */
|
|
18
|
+
function getInstanceInternals(handler) {
|
|
19
|
+
return INSTANCE_INTERNALS.get(handler) ?? {};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Serve a devframe through one framework-agnostic, web-standard handler —
|
|
23
|
+
* the SPA, `__connection.json` discovery, the WebSocket RPC endpoint, the
|
|
24
|
+
* auth gate, and the optional MCP route, all under a single mount base.
|
|
25
|
+
* Mount `handler` on any framework's catch-all route (or `nodeMiddleware` on
|
|
26
|
+
* a connect stack) and the devframe is live inside that app.
|
|
27
|
+
*
|
|
28
|
+
* The factory is synchronous and kicks off initialization eagerly;
|
|
29
|
+
* `handler`/`nodeMiddleware` await readiness internally. Nothing binds a port
|
|
30
|
+
* on its own: the WebSocket resolves in precedence order — `ws.port` (pinned
|
|
31
|
+
* side-car) > `server` (shared upgrade at `<base>__ws`) > `ws.sidecar`
|
|
32
|
+
* (auto-port side-car) > the host driving upgrades itself through
|
|
33
|
+
* {@link DevframeInstance.attach} — while `ws.url`, when set, overrides the
|
|
34
|
+
* advertised* endpoint (the tunnel pattern) and on its own hands the whole
|
|
35
|
+
* transport to an external server. `__connection.json` reflects whichever
|
|
36
|
+
* combination is active.
|
|
37
|
+
*/
|
|
38
|
+
function initDevframe(def, options) {
|
|
39
|
+
const base = normalizeBasePath(options.base);
|
|
40
|
+
const distDir = options.distDir === false ? void 0 : options.distDir ?? def.cli?.distDir;
|
|
41
|
+
const app = options.app ?? new H3();
|
|
42
|
+
const shell = createInstanceShell({
|
|
43
|
+
base,
|
|
44
|
+
app,
|
|
45
|
+
host: options.host ?? def.cli?.host ?? "localhost",
|
|
46
|
+
origin: options.origin,
|
|
47
|
+
auth: options.auth !== void 0 ? options.auth : def.cli?.auth,
|
|
48
|
+
server: options.server,
|
|
49
|
+
ws: options.ws ?? def.cli?.ws,
|
|
50
|
+
sse: options.sse ?? def.cli?.sse,
|
|
51
|
+
allowedOrigins: options.allowedOrigins,
|
|
52
|
+
destroyUnmatchedUpgrades: options.destroyUnmatchedUpgrades,
|
|
53
|
+
onPeerConnect: options.onPeerConnect,
|
|
54
|
+
onPeerDisconnect: options.onPeerDisconnect,
|
|
55
|
+
register: resolveInstanceRegister(options.register, {
|
|
56
|
+
id: def.id,
|
|
57
|
+
name: def.name
|
|
58
|
+
}),
|
|
59
|
+
resolveSidecarPort: (sidecarHost) => resolveDevServerPort(def, { host: sidecarHost }),
|
|
60
|
+
onMetaUnavailable: () => {
|
|
61
|
+
throw diagnostics.DF0054({ id: def.id });
|
|
62
|
+
},
|
|
63
|
+
async init(api) {
|
|
64
|
+
const h3Host = createH3DevframeHost({
|
|
65
|
+
origin: () => api.origin() ?? "http://localhost",
|
|
66
|
+
appName: def.id,
|
|
67
|
+
mount: (mountBase, dir) => {
|
|
68
|
+
mountStaticHandler(app, mountBase, dir);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const hostImpl = options.getStorageDir ? {
|
|
72
|
+
...h3Host,
|
|
73
|
+
getStorageDir: options.getStorageDir
|
|
74
|
+
} : h3Host;
|
|
75
|
+
const context = await createHostContext({
|
|
76
|
+
cwd: process.cwd(),
|
|
77
|
+
mode: "dev",
|
|
78
|
+
host: hostImpl
|
|
79
|
+
});
|
|
80
|
+
const setupInfo = { flags: options.flags ?? {} };
|
|
81
|
+
await def.setup(context, setupInfo);
|
|
82
|
+
const mcpOption = options.mcp ?? def.cli?.mcp;
|
|
83
|
+
const mcpMeta = resolveMcpConnectionMeta(def, mcpOption);
|
|
84
|
+
let mcpDispose;
|
|
85
|
+
if (mcpMeta) {
|
|
86
|
+
const mcpConfig = mcpOption === true || mcpOption === void 0 ? {} : mcpOption;
|
|
87
|
+
const mcpPath = joinURL(base, mcpMeta.path);
|
|
88
|
+
let mountMcpHttp;
|
|
89
|
+
try {
|
|
90
|
+
({mountMcpHttp} = await import("./http-DYpK0cUi.mjs").then((n) => n.t));
|
|
91
|
+
} catch (error) {
|
|
92
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
93
|
+
throw diagnostics.DF0017({
|
|
94
|
+
transport: "http",
|
|
95
|
+
reason,
|
|
96
|
+
cause: error
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
mcpDispose = mountMcpHttp(app, context, mcpPath, {
|
|
100
|
+
serverName: `${def.id} (devframe)`,
|
|
101
|
+
serverVersion: def.version ?? "0.0.0",
|
|
102
|
+
exposeSharedState: true,
|
|
103
|
+
allowedOrigins: mcpConfig.allowedOrigins
|
|
104
|
+
}).dispose;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
context,
|
|
108
|
+
...mcpMeta ? { mcp: mcpMeta } : {},
|
|
109
|
+
...mcpDispose ? { dispose: mcpDispose } : {}
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
mount(context, meta) {
|
|
113
|
+
app.use(joinURL(base, DEVFRAME_CONNECTION_META_FILENAME), () => meta);
|
|
114
|
+
if (distDir) {
|
|
115
|
+
const source = resolveStaticAssetsSource(distDir, context.host.getStorageDir("project"));
|
|
116
|
+
mountStaticHandler(app, base, typeof source === "string" ? resolve(source) : source);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const instance = {
|
|
121
|
+
base: shell.base,
|
|
122
|
+
handler: shell.handler,
|
|
123
|
+
nodeMiddleware: shell.nodeMiddleware,
|
|
124
|
+
attach: shell.attach,
|
|
125
|
+
handleUpgrade: shell.handleUpgrade,
|
|
126
|
+
ready: shell.ready,
|
|
127
|
+
context: shell.context,
|
|
128
|
+
connectionMeta: shell.connectionMeta,
|
|
129
|
+
close: shell.close
|
|
130
|
+
};
|
|
131
|
+
INSTANCE_INTERNALS.set(instance, shell.internals);
|
|
132
|
+
return instance;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/adapters/dev.ts
|
|
136
|
+
/**
|
|
137
|
+
* Start a devframe dev server for a {@link DevframeDefinition} —
|
|
138
|
+
* h3 + WebSocket RPC + (optionally) the author's SPA mounted at the
|
|
139
|
+
* resolved base path.
|
|
140
|
+
*
|
|
141
|
+
* When `distDir` is omitted (and `def.cli?.distDir` is unset) the
|
|
142
|
+
* server runs in **bridge mode**: only `__connection.json` and the WS
|
|
143
|
+
* endpoint are mounted, with no SPA mount. The SPA is expected to be
|
|
144
|
+
* hosted elsewhere (e.g. by a parent Vite/Nuxt dev server) — see
|
|
145
|
+
* `devframeViteBridge` from `@devframes/vite`.
|
|
146
|
+
*
|
|
147
|
+
* Returns the underlying {@link StartedServer} handle so callers can
|
|
148
|
+
* close it gracefully (SIGINT, hot-reload, test teardown).
|
|
149
|
+
*
|
|
150
|
+
* Use this directly when integrating devframe into an existing CLI
|
|
151
|
+
* framework (commander, yargs, hand-rolled CAC). For the all-in-one
|
|
152
|
+
* `dev` / `build` / `mcp` shell, reach for {@link createCac} instead.
|
|
153
|
+
*/
|
|
154
|
+
async function createDevServer(def, options = {}) {
|
|
155
|
+
if (def.capabilities?.dev === false && !options.force) throw diagnostics.DF0058({ id: def.id });
|
|
156
|
+
const host = options.host ?? def.cli?.host ?? "localhost";
|
|
157
|
+
const requestedPort = options.port ?? await resolveDevServerPort(def, { host });
|
|
158
|
+
const flags = options.flags ?? {};
|
|
159
|
+
const basePath = options.basePath ? normalizeBasePath(options.basePath) : resolveBasePath(def, "standalone");
|
|
160
|
+
const app = options.app ?? new H3();
|
|
161
|
+
const server = createServer(toNodeHandler(app));
|
|
162
|
+
try {
|
|
163
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
164
|
+
const onError = (error) => rejectListen(error);
|
|
165
|
+
server.once("error", onError);
|
|
166
|
+
server.listen(requestedPort, host, () => {
|
|
167
|
+
server.removeListener("error", onError);
|
|
168
|
+
resolveListen();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw diagnostics.DF0052({
|
|
173
|
+
host,
|
|
174
|
+
port: requestedPort,
|
|
175
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
176
|
+
cause: error
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const address = server.address();
|
|
180
|
+
const port = typeof address === "object" && address ? address.port : requestedPort;
|
|
181
|
+
const origin = normalizeHttpServerUrl(host, port);
|
|
182
|
+
const devframe = initDevframe(def, {
|
|
183
|
+
base: basePath,
|
|
184
|
+
distDir: options.distDir,
|
|
185
|
+
app,
|
|
186
|
+
server,
|
|
187
|
+
host,
|
|
188
|
+
origin,
|
|
189
|
+
ws: options.ws,
|
|
190
|
+
allowedOrigins: options.allowedOrigins,
|
|
191
|
+
sse: options.sse,
|
|
192
|
+
auth: flags.auth === false ? false : options.auth,
|
|
193
|
+
mcp: options.mcp,
|
|
194
|
+
flags,
|
|
195
|
+
onPeerConnect: options.onPeerConnect,
|
|
196
|
+
onPeerDisconnect: options.onPeerDisconnect,
|
|
197
|
+
register: true,
|
|
198
|
+
destroyUnmatchedUpgrades: true
|
|
199
|
+
});
|
|
200
|
+
try {
|
|
201
|
+
await devframe.ready;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
await new Promise((resolveClose) => server.close(() => resolveClose()));
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
const internals = getInstanceInternals(devframe);
|
|
207
|
+
const transport = internals.started;
|
|
208
|
+
await options.onReady?.({
|
|
209
|
+
origin,
|
|
210
|
+
port,
|
|
211
|
+
app
|
|
212
|
+
});
|
|
213
|
+
await maybeOpenBrowser(def, flags, `${origin}${basePath}`, options.openBrowser, internals.authHandler);
|
|
214
|
+
return {
|
|
215
|
+
origin,
|
|
216
|
+
port,
|
|
217
|
+
app,
|
|
218
|
+
ws: transport.ws,
|
|
219
|
+
rpcGroup: transport.rpcGroup,
|
|
220
|
+
connectionMeta: transport.connectionMeta,
|
|
221
|
+
async close() {
|
|
222
|
+
await devframe.close();
|
|
223
|
+
await new Promise((resolveClose) => server.close(() => resolveClose()));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
async function maybeOpenBrowser(def, flags, origin, override, authHandler) {
|
|
228
|
+
const flagsOpen = flags.open;
|
|
229
|
+
const cliOpen = def.cli?.open;
|
|
230
|
+
const resolved = override ?? flagsOpen ?? cliOpen;
|
|
231
|
+
if (resolved === void 0 || resolved === false) return;
|
|
232
|
+
const target = typeof resolved === "string" ? withBase(resolved, origin) : origin;
|
|
233
|
+
const authorizedTarget = authHandler?.buildOpenUrl?.(target) ?? target;
|
|
234
|
+
try {
|
|
235
|
+
await open(authorizedTarget);
|
|
236
|
+
} catch {}
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
export { getInstanceInternals as n, initDevframe as r, createDevServer as t };
|