devframe 0.8.2 → 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 +20 -42
  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-CBg8iRbQ.mjs → context-C33rR7n0.mjs} +1 -1
  20. package/dist/{context-DoSozfvx.d.mts → context-CSCwoABx.d.mts} +1 -1
  21. package/dist/{host-h3-D2hYZvDK.mjs → context-Du11TLcO.mjs} +5 -255
  22. package/dist/dev-BEveeA5H.mjs +233 -0
  23. package/dist/{devframe-mQ4qZAuo.d.mts → devframe-Bdd9YXTy.d.mts} +88 -25
  24. package/dist/{diagnostics-D7wM2cwM.mjs → diagnostics-DLYH5oD3.mjs} +16 -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-BKaD0Vb3.mjs → http-DLr_cJZ7.mjs} +42 -4
  31. package/dist/{index-b64Uuhy2.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-BnnA2Eoh.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 -235
  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-CTNVbuFB.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-uKQcClcJ.d.mts → ws-server-Ces08fjP.d.mts} +89 -8
  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-D4_9ok0z.mjs +0 -157
  91. package/dist/dev-Bc49u3qg.mjs +0 -439
  92. package/dist/http-C4T68YV6.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-CD8XmBXl.mjs +0 -167
  97. package/dist/server-UHWae43Q.d.mts +0 -149
  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,14 +1,62 @@
1
1
  import { v as RpcFunctionDefinitionAny } from "./types-CnJSgRVa.mjs";
2
- import { Peer } from "crossws";
3
2
  import { BirpcGroup, ChannelOptions } from "birpc";
3
+ import { Hooks, Peer } from "crossws";
4
4
  import { NodeAdapter } from "crossws/adapters/node";
5
- import { Server } from "node:http";
5
+ import { Buffer } from "node:buffer";
6
+ import { IncomingMessage, Server } from "node:http";
6
7
  import { Server as Server$1, ServerOptions } from "node:https";
7
8
  import { AddressInfo } from "node:net";
8
- //#region src/rpc/transports/ws-server.d.ts
9
+ import { Duplex } from "node:stream";
10
+ //#region src/rpc/transports/session.d.ts
11
+ /**
12
+ * Which wire transport produced an RPC connection. Every transport speaks
13
+ * the same birpc channel protocol; the kind only matters to code that needs
14
+ * transport-specific behavior (e.g. reaching the WS escape hatch on
15
+ * {@link DevframeRpcConnection.peer}).
16
+ */
17
+ type DevframeRpcTransportKind = 'websocket' | 'sse';
18
+ /**
19
+ * Structural view of the connect-time HTTP request behind an RPC connection
20
+ * — the WS upgrade request, or the request opening an SSE stream. Shaped to
21
+ * match both the web `Request` a crossws peer exposes and a plain
22
+ * `node:http` request wrapper, so auth hooks can read the bearer-token
23
+ * query param and the `Origin` header without caring which transport (or
24
+ * runtime) produced the connection.
25
+ */
26
+ interface DevframeRpcConnectionRequest {
27
+ /** Request URL (may be path-only, e.g. `/__ws?devframe_auth_token=…`). */
28
+ url?: string;
29
+ /** Header lookup, `Headers`-style. */
30
+ headers?: {
31
+ get: (name: string) => string | null | undefined;
32
+ };
33
+ }
34
+ /**
35
+ * A live RPC connection, independent of the transport that carries it. One
36
+ * exists per connected client; transport bindings construct it alongside the
37
+ * session meta and hand both to the connect/disconnect hooks
38
+ * (`onPeerConnect` / `onPeerDisconnect`, {@link DevframeAuthHandler.onConnect}).
39
+ */
40
+ interface DevframeRpcConnection {
41
+ /** Session id — the same value as the session meta's `id`. */
42
+ id: number;
43
+ /** The transport carrying this connection. */
44
+ transport: DevframeRpcTransportKind;
45
+ /** The connect-time HTTP request (upgrade request / stream request). */
46
+ request?: DevframeRpcConnectionRequest;
47
+ /** Send a raw wire frame to this client. Prefer the birpc channel. */
48
+ send?: (data: string) => void;
49
+ /** Terminate the connection from the server side. */
50
+ close?: (code?: number, reason?: string) => void;
51
+ /**
52
+ * The crossws peer backing a `websocket` connection — the WS-specific
53
+ * escape hatch (pub/sub, raw socket access). Absent on other transports.
54
+ */
55
+ peer?: Peer;
56
+ }
9
57
  interface DevframeNodeRpcSessionMeta {
10
58
  id: number;
11
- /** The crossws peer backing this session's socket. */
59
+ /** The crossws peer backing this session's socket (WS transport only). */
12
60
  peer?: Peer;
13
61
  clientAuthToken?: string;
14
62
  isTrusted?: boolean;
@@ -26,6 +74,8 @@ interface DevframeNodeRpcSessionMeta {
26
74
  */
27
75
  uploadingStreams?: Set<string>;
28
76
  }
77
+ //#endregion
78
+ //#region src/rpc/transports/ws-server.d.ts
29
79
  interface WsRpcTransportOptions {
30
80
  /**
31
81
  * Attach to an existing HTTP(S) server, sharing its port. Combine with
@@ -43,12 +93,20 @@ interface WsRpcTransportOptions {
43
93
  /** Host for the standalone WebSocket server. Defaults to `localhost`. */
44
94
  host?: string;
45
95
  /**
46
- * Restrict the WS endpoint to a single upgrade route (e.g. `/__devframe_ws`). When
96
+ * Restrict the WS endpoint to a single upgrade route (e.g. `/__ws`). When
47
97
  * sharing a `server`, non-matching upgrade requests are left untouched for
48
98
  * other listeners to handle, so devframe's socket can sit alongside
49
99
  * framework sockets (Vite HMR, etc.).
50
100
  */
51
101
  path?: string;
102
+ /**
103
+ * Create the adapter without binding it to anything: no server is created,
104
+ * no port is bound, no `upgrade` listener is installed. The caller drives
105
+ * the socket itself through {@link WsRpcTransport.handleUpgrade} (from its
106
+ * own `upgrade` listener) or {@link WsRpcTransport.attach} (to bind a
107
+ * server later). Takes precedence over `server` / `port` / `https`.
108
+ */
109
+ unbound?: boolean;
52
110
  /**
53
111
  * Destroy upgrade requests that don't match `path` instead of leaving them
54
112
  * for other listeners. Enable this when devframe owns the shared server
@@ -76,8 +134,8 @@ interface WsRpcTransportOptions {
76
134
  * loses dev-time validation for `jsonSerializable: true` declarations.
77
135
  */
78
136
  definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, 'jsonSerializable'>>;
79
- onConnected?: (peer: Peer, meta: DevframeNodeRpcSessionMeta) => void;
80
- onDisconnected?: (peer: Peer, meta: DevframeNodeRpcSessionMeta) => void;
137
+ onConnected?: (connection: DevframeRpcConnection, meta: DevframeNodeRpcSessionMeta) => void;
138
+ onDisconnected?: (connection: DevframeRpcConnection, meta: DevframeNodeRpcSessionMeta) => void;
81
139
  /** Override the default per-call serializer. Most callers should leave this unset. */
82
140
  serialize?: ChannelOptions['serialize'];
83
141
  /** Override the default per-call deserializer. Most callers should leave this unset. */
@@ -114,6 +172,20 @@ interface WsRpcTransport {
114
172
  ready: Promise<void>;
115
173
  /** Returns the bound address, or `null` when the server is not listening. */
116
174
  address: () => AddressInfo | string | null;
175
+ /**
176
+ * Complete a `node:http` `upgrade` event on this transport, applying the
177
+ * same `path` filter and origin gate the transport's own listener uses.
178
+ * Wire it into a host server directly — `server.on('upgrade',
179
+ * transport.handleUpgrade)` — or call it from an existing listener.
180
+ */
181
+ handleUpgrade: (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
182
+ /**
183
+ * Route a server's `upgrade` events to this transport, returning a detach
184
+ * function. Use it to bind an `unbound` transport once the host server
185
+ * exists; {@link WsRpcTransport.close} detaches every server attached this
186
+ * way (without closing them — the caller owns their lifecycle).
187
+ */
188
+ attach: (server: Server | Server$1) => () => void;
117
189
  /** Remove the upgrade listener from a shared `server` (a no-op otherwise). */
118
190
  detach: () => void;
119
191
  /**
@@ -132,6 +204,15 @@ declare function isLoopbackHostname(hostname: string): boolean;
132
204
  * browser — is rejected.
133
205
  */
134
206
  declare function isAllowedOrigin(origin: string | undefined, allowedOrigins: readonly string[]): boolean;
207
+ /**
208
+ * The per-peer lifecycle hooks driving a devframe RPC WebSocket, shaped for
209
+ * any [crossws](https://crossws.h3.dev) adapter. {@link attachWsRpcTransport}
210
+ * feeds them to the Node adapter; runtime-specific attachments (e.g. Bun's
211
+ * fetch-upgrade adapter) reuse the same hooks so every transport speaks the
212
+ * identical wire protocol — one birpc channel per peer, per-method
213
+ * `jsonSerializable` dispatch between strict JSON and structured-clone.
214
+ */
215
+ declare function createWsRpcPeerHooks<ClientFunctions extends object, ServerFunctions extends object>(rpcGroup: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: Pick<WsRpcTransportOptions, 'onConnected' | 'onDisconnected' | 'definitions' | 'serialize' | 'deserialize'>): Partial<Hooks>;
135
216
  /**
136
217
  * Attach a WebSocket transport to an existing RPC group, powered by
137
218
  * [crossws](https://crossws.h3.dev). Either attach to an existing HTTP(S)
@@ -144,4 +225,4 @@ declare function isAllowedOrigin(origin: string | undefined, allowedOrigins: rea
144
225
  */
145
226
  declare function attachWsRpcTransport<ClientFunctions extends object, ServerFunctions extends object>(rpcGroup: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: WsRpcTransportOptions): WsRpcTransport;
146
227
  //#endregion
147
- export { WsRpcTransportOptions as a, isAllowedOrigin as c, WsRpcTransport as i, isLoopbackHostname as l, DevframeNodeRpcSessionMeta as n, attachWsRpcTransport as o, WsOriginRegistry as r, createWsOriginRegistry as s, CreateWsOriginRegistryOptions as t };
228
+ export { attachWsRpcTransport as a, isAllowedOrigin as c, DevframeRpcConnection as d, DevframeRpcConnectionRequest as f, WsRpcTransportOptions as i, isLoopbackHostname as l, WsOriginRegistry as n, createWsOriginRegistry as o, DevframeRpcTransportKind as p, WsRpcTransport as r, createWsRpcPeerHooks as s, CreateWsOriginRegistryOptions as t, DevframeNodeRpcSessionMeta as u };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "devframe",
3
3
  "type": "module",
4
- "version": "0.8.2",
5
- "description": "Framework for building generic devframes",
4
+ "version": "0.9.0-beta.1",
5
+ "description": "Framework for building one portable devtool integration that runs in any viewer.",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/devframes/devframe#readme",
@@ -22,23 +22,26 @@
22
22
  ".": "./dist/index.mjs",
23
23
  "./adapters/build": "./dist/adapters/build.mjs",
24
24
  "./adapters/cac": "./dist/adapters/cac.mjs",
25
- "./adapters/cli": "./dist/adapters/cli.mjs",
26
25
  "./adapters/dev": "./dist/adapters/dev.mjs",
27
26
  "./adapters/embedded": "./dist/adapters/embedded.mjs",
28
27
  "./adapters/mcp": "./dist/adapters/mcp.mjs",
29
28
  "./client": "./dist/client/index.mjs",
30
29
  "./constants": "./dist/constants.mjs",
31
30
  "./helpers/vite": "./dist/helpers/vite.mjs",
31
+ "./initiate": "./dist/adapters/initiate.mjs",
32
+ "./internal": "./dist/internal/index.mjs",
32
33
  "./node": "./dist/node/index.mjs",
33
34
  "./node/auth": "./dist/node/auth.mjs",
34
35
  "./node/hub-internals": "./dist/node/hub-internals.mjs",
35
36
  "./recipes/common-rpc-functions": "./dist/recipes/common-rpc-functions.mjs",
36
37
  "./recipes/interactive-auth": "./dist/recipes/interactive-auth.mjs",
37
- "./recipes/open-helpers": "./dist/recipes/open-helpers.mjs",
38
38
  "./rpc": "./dist/rpc/index.mjs",
39
39
  "./rpc/client": "./dist/rpc/client.mjs",
40
40
  "./rpc/dump": "./dist/rpc/dump.mjs",
41
41
  "./rpc/server": "./dist/rpc/server.mjs",
42
+ "./rpc/transports/sse-client": "./dist/rpc/transports/sse-client.mjs",
43
+ "./rpc/transports/sse-server": "./dist/rpc/transports/sse-server.mjs",
44
+ "./rpc/transports/ws-bun": "./dist/rpc/transports/ws-bun.mjs",
42
45
  "./rpc/transports/ws-client": "./dist/rpc/transports/ws-client.mjs",
43
46
  "./rpc/transports/ws-server": "./dist/rpc/transports/ws-server.mjs",
44
47
  "./types": "./dist/types/index.mjs",
@@ -50,9 +53,7 @@
50
53
  "./utils/launch-editor": "./dist/utils/launch-editor.mjs",
51
54
  "./utils/nanoid": "./dist/utils/nanoid.mjs",
52
55
  "./utils/open": "./dist/utils/open.mjs",
53
- "./utils/promise": "./dist/utils/promise.mjs",
54
56
  "./utils/simple-schema": "./dist/utils/simple-schema.mjs",
55
- "./utils/scope": "./dist/utils/scope.mjs",
56
57
  "./utils/serve-static": "./dist/utils/serve-static.mjs",
57
58
  "./utils/shared-state": "./dist/utils/shared-state.mjs",
58
59
  "./utils/streaming-channel": "./dist/utils/streaming-channel.mjs",
@@ -87,7 +88,7 @@
87
88
  },
88
89
  "dependencies": {
89
90
  "@standard-schema/spec": "^1.1.0",
90
- "birpc": "^4.0.0",
91
+ "birpc": "^4.1.0",
91
92
  "crossws": "^0.4.10",
92
93
  "destr": "^2.0.5",
93
94
  "h3": "^2.0.1-rc.26",
@@ -101,7 +102,7 @@
101
102
  "@modelcontextprotocol/server": "^2.0.0",
102
103
  "cac": "^7.0.0",
103
104
  "get-port-please": "^3.2.0",
104
- "immer": "^11.1.15",
105
+ "immer": "^11.1.16",
105
106
  "launch-editor": "^2.14.1",
106
107
  "mlly": "^1.8.2",
107
108
  "obug": "^2.1.4",
@@ -115,7 +116,7 @@
115
116
  "ua-parser-modern": "^0.1.1",
116
117
  "valibot": "^1.4.2",
117
118
  "whenexpr": "^0.1.2",
118
- "ws": "^8.21.2"
119
+ "ws": "^8.21.3"
119
120
  },
120
121
  "scripts": {
121
122
  "build": "tsdown",