devframe 0.0.0 → 0.1.16
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/LICENSE.md +21 -0
- package/README.md +62 -0
- package/dist/_shared-CU6dE-VX.mjs +20 -0
- package/dist/adapters/build.d.mts +37 -0
- package/dist/adapters/build.mjs +61 -0
- package/dist/adapters/cli.d.mts +35 -0
- package/dist/adapters/cli.mjs +357 -0
- package/dist/adapters/embedded.d.mts +19 -0
- package/dist/adapters/embedded.mjs +15 -0
- package/dist/adapters/kit.d.mts +23 -0
- package/dist/adapters/kit.mjs +16 -0
- package/dist/adapters/mcp.d.mts +39 -0
- package/dist/adapters/mcp.mjs +278 -0
- package/dist/adapters/vite.d.mts +32 -0
- package/dist/adapters/vite.mjs +31 -0
- package/dist/client/index.d.mts +227 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client-4WrEozlH.mjs +1561 -0
- package/dist/constants.d.mts +20 -0
- package/dist/constants.mjs +34 -0
- package/dist/context-BrePWeyd.mjs +6776 -0
- package/dist/define-Bb4zh-Dc.mjs +11 -0
- package/dist/devtool-OJ3QW0ns.d.mts +1125 -0
- package/dist/helpers/nuxt/index.d.mts +46 -0
- package/dist/helpers/nuxt/index.mjs +58 -0
- package/dist/helpers/nuxt/runtime/plugin.client.d.mts +8 -0
- package/dist/helpers/nuxt/runtime/plugin.client.mjs +12 -0
- package/dist/human-id-CHS0s28X.mjs +844 -0
- package/dist/immer-HjMAm3b6.mjs +894 -0
- package/dist/index-DvKDO5H8.d.mts +333 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +2 -0
- package/dist/main-DpINGndA.mjs +601 -0
- package/dist/node/index.d.mts +365 -0
- package/dist/node/index.mjs +69 -0
- package/dist/open-BtOOEldu.mjs +533 -0
- package/dist/recipes/open-helpers.d.mts +104 -0
- package/dist/recipes/open-helpers.mjs +69 -0
- package/dist/rpc/client.d.mts +9 -0
- package/dist/rpc/client.mjs +13 -0
- package/dist/rpc/index.d.mts +2 -0
- package/dist/rpc/index.mjs +3 -0
- package/dist/rpc/server.d.mts +8 -0
- package/dist/rpc/server.mjs +10 -0
- package/dist/rpc/transports/ws-client.d.mts +2 -0
- package/dist/rpc/transports/ws-client.mjs +43 -0
- package/dist/rpc/transports/ws-server.d.mts +2 -0
- package/dist/rpc/transports/ws-server.mjs +58 -0
- package/dist/rpc-9FNa3Inb.mjs +474 -0
- package/dist/server-DrBxa6ZV.mjs +49 -0
- package/dist/src-BoIqXRc9.mjs +85 -0
- package/dist/static-dump-CQUC1aIW.mjs +82 -0
- package/dist/transports-BPUzHhI2.mjs +15 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +6 -0
- package/dist/utils/events.d.mts +9 -0
- package/dist/utils/events.mjs +40 -0
- package/dist/utils/human-id.d.mts +10 -0
- package/dist/utils/human-id.mjs +3 -0
- package/dist/utils/nanoid.d.mts +4 -0
- package/dist/utils/nanoid.mjs +10 -0
- package/dist/utils/promise.d.mts +8 -0
- package/dist/utils/promise.mjs +15 -0
- package/dist/utils/shared-state.d.mts +2 -0
- package/dist/utils/shared-state.mjs +36 -0
- package/dist/utils/state.d.mts +49 -0
- package/dist/utils/state.mjs +26 -0
- package/dist/utils/when.d.mts +2 -0
- package/dist/utils/when.mjs +424 -0
- package/dist/when-CGLewRtm.d.mts +401 -0
- package/dist/ws-client-CklfxUHE.d.mts +17 -0
- package/dist/ws-server--IuUAaGi.d.mts +37 -0
- package/package.json +116 -8
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { r as DevtoolDefinition } from "../devtool-OJ3QW0ns.mjs";
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/node/mcp/build-server.d.ts
|
|
5
|
+
interface CreateMcpServerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Transport to use. Only `'stdio'` is implemented today; HTTP support
|
|
8
|
+
* is planned in a follow-up PR.
|
|
9
|
+
*/
|
|
10
|
+
transport?: 'stdio';
|
|
11
|
+
/**
|
|
12
|
+
* Expose shared-state keys as MCP resources.
|
|
13
|
+
* - `true` (default) — every key the host publishes
|
|
14
|
+
* - `false` — none
|
|
15
|
+
* - `(key) => boolean` — filter
|
|
16
|
+
*/
|
|
17
|
+
exposeSharedState?: boolean | ((key: string) => boolean);
|
|
18
|
+
/** Override the name reported in the MCP handshake. */
|
|
19
|
+
serverName?: string;
|
|
20
|
+
/** Override the version reported in the MCP handshake. Defaults to `definition.version ?? '0.0.0'`. */
|
|
21
|
+
serverVersion?: string;
|
|
22
|
+
/** Called once the transport is connected. */
|
|
23
|
+
onReady?: (info: {
|
|
24
|
+
transport: 'stdio';
|
|
25
|
+
}) => void;
|
|
26
|
+
}
|
|
27
|
+
interface McpServerHandle {
|
|
28
|
+
stop: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build an MCP server over the agent surface of a devtool definition.
|
|
32
|
+
* Currently supports `stdio` transport only.
|
|
33
|
+
*
|
|
34
|
+
* @experimental The agent-native surface is experimental and may change
|
|
35
|
+
* without a major version bump until it stabilizes.
|
|
36
|
+
*/
|
|
37
|
+
declare function createMcpServer(definition: DevtoolDefinition, options?: CreateMcpServerOptions): Promise<McpServerHandle>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { type CreateMcpServerOptions, type McpServerHandle, createMcpServer };
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { p as logger, t as createHostContext } from "../context-BrePWeyd.mjs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
6
|
+
//#region src/node/mcp/to-json-schema.ts
|
|
7
|
+
const FALLBACK_OBJECT_SCHEMA = Object.freeze({
|
|
8
|
+
type: "object",
|
|
9
|
+
additionalProperties: true
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Convert a valibot return schema to JSON Schema.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
function valibotReturnToJsonSchema(schema) {
|
|
16
|
+
if (!schema) return void 0;
|
|
17
|
+
try {
|
|
18
|
+
return toJsonSchema(schema);
|
|
19
|
+
} catch {
|
|
20
|
+
return FALLBACK_OBJECT_SCHEMA;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert positional RPC args schemas to a single MCP-friendly object
|
|
25
|
+
* schema. When the RPC declares `args: [v.object(...)]`, unwrap the
|
|
26
|
+
* single-object schema directly (nicer agent UX than `{ arg0: {...} }`).
|
|
27
|
+
*
|
|
28
|
+
* Returns `undefined` when there are no args (the MCP SDK treats this
|
|
29
|
+
* as `{ type: 'object', properties: {} }`).
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function valibotArgsToJsonSchema(args) {
|
|
33
|
+
if (!args || args.length === 0) return {
|
|
34
|
+
schema: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: {}
|
|
37
|
+
},
|
|
38
|
+
unwrapped: false
|
|
39
|
+
};
|
|
40
|
+
if (args.length === 1) {
|
|
41
|
+
const inner = safeToJsonSchema(args[0]);
|
|
42
|
+
if (isObjectJsonSchema(inner)) return {
|
|
43
|
+
schema: inner,
|
|
44
|
+
unwrapped: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const properties = {};
|
|
48
|
+
const required = [];
|
|
49
|
+
for (let i = 0; i < args.length; i++) {
|
|
50
|
+
const key = `arg${i}`;
|
|
51
|
+
properties[key] = safeToJsonSchema(args[i]);
|
|
52
|
+
required.push(key);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
schema: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties,
|
|
58
|
+
required,
|
|
59
|
+
additionalProperties: false
|
|
60
|
+
},
|
|
61
|
+
unwrapped: false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function safeToJsonSchema(schema) {
|
|
65
|
+
try {
|
|
66
|
+
return toJsonSchema(schema);
|
|
67
|
+
} catch {
|
|
68
|
+
return FALLBACK_OBJECT_SCHEMA;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function isObjectJsonSchema(value) {
|
|
72
|
+
return !!value && typeof value === "object" && value.type === "object";
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/node/mcp/build-server.ts
|
|
76
|
+
/**
|
|
77
|
+
* Wire an MCP {@link Server} to a devframe context. Returns the server
|
|
78
|
+
* plus a disposal function for the subscriptions it sets up. The
|
|
79
|
+
* transport is the caller's responsibility — `createMcpServer` connects
|
|
80
|
+
* stdio; tests can connect an {@link InMemoryTransport} instead.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
function buildMcpServerFromContext(ctx, options) {
|
|
85
|
+
const server = new Server({
|
|
86
|
+
name: options.serverName,
|
|
87
|
+
version: options.serverVersion
|
|
88
|
+
}, { capabilities: {
|
|
89
|
+
tools: { listChanged: true },
|
|
90
|
+
resources: { listChanged: true }
|
|
91
|
+
} });
|
|
92
|
+
registerToolHandlers(server, ctx);
|
|
93
|
+
registerResourceHandlers(server, ctx, options.exposeSharedState);
|
|
94
|
+
const notify = (method) => {
|
|
95
|
+
server.notification({ method }).catch(() => {});
|
|
96
|
+
};
|
|
97
|
+
const offManifest = ctx.agent.events.on("agent:manifest:changed", () => {
|
|
98
|
+
notify("notifications/tools/list_changed");
|
|
99
|
+
notify("notifications/resources/list_changed");
|
|
100
|
+
});
|
|
101
|
+
const offKeyAdded = ctx.rpc.sharedState.onKeyAdded(() => {
|
|
102
|
+
notify("notifications/resources/list_changed");
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
server,
|
|
106
|
+
dispose: () => {
|
|
107
|
+
offManifest();
|
|
108
|
+
offKeyAdded();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Build an MCP server over the agent surface of a devtool definition.
|
|
114
|
+
* Currently supports `stdio` transport only.
|
|
115
|
+
*
|
|
116
|
+
* @experimental The agent-native surface is experimental and may change
|
|
117
|
+
* without a major version bump until it stabilizes.
|
|
118
|
+
*/
|
|
119
|
+
async function createMcpServer(definition, options = {}) {
|
|
120
|
+
const transport = options.transport ?? "stdio";
|
|
121
|
+
if (transport !== "stdio") throw logger.DF0017({
|
|
122
|
+
transport,
|
|
123
|
+
reason: "Only stdio transport is supported in this release."
|
|
124
|
+
}).throw();
|
|
125
|
+
const ctx = await createHostContext({
|
|
126
|
+
cwd: process.cwd(),
|
|
127
|
+
mode: "dev",
|
|
128
|
+
host: {
|
|
129
|
+
mountStatic: () => {},
|
|
130
|
+
resolveOrigin: () => "mcp://devframe"
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
await definition.setup(ctx);
|
|
134
|
+
const { server, dispose } = buildMcpServerFromContext(ctx, {
|
|
135
|
+
serverName: options.serverName ?? `${definition.id} (devframe)`,
|
|
136
|
+
serverVersion: options.serverVersion ?? definition.version ?? "0.0.0",
|
|
137
|
+
exposeSharedState: options.exposeSharedState ?? true
|
|
138
|
+
});
|
|
139
|
+
const { startStdioTransport } = await import("../transports-BPUzHhI2.mjs");
|
|
140
|
+
let stop;
|
|
141
|
+
try {
|
|
142
|
+
stop = await startStdioTransport(server);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
145
|
+
throw logger.DF0017({
|
|
146
|
+
transport,
|
|
147
|
+
reason
|
|
148
|
+
}, { cause: error }).throw();
|
|
149
|
+
}
|
|
150
|
+
options.onReady?.({ transport: "stdio" });
|
|
151
|
+
return { async stop() {
|
|
152
|
+
dispose();
|
|
153
|
+
await stop();
|
|
154
|
+
} };
|
|
155
|
+
}
|
|
156
|
+
function registerToolHandlers(server, ctx) {
|
|
157
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
158
|
+
return { tools: ctx.agent.list().tools.map((tool) => projectTool(tool, ctx)) };
|
|
159
|
+
});
|
|
160
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
161
|
+
const { name, arguments: args } = request.params;
|
|
162
|
+
try {
|
|
163
|
+
return { content: [{
|
|
164
|
+
type: "text",
|
|
165
|
+
text: stringify(await ctx.agent.invoke(name, args ?? {}))
|
|
166
|
+
}] };
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return {
|
|
169
|
+
isError: true,
|
|
170
|
+
content: [{
|
|
171
|
+
type: "text",
|
|
172
|
+
text: `Error invoking "${name}": ${error instanceof Error ? error.message : String(error)}`
|
|
173
|
+
}]
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function registerResourceHandlers(server, ctx, exposeSharedState) {
|
|
179
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
180
|
+
const resources = ctx.agent.list().resources.map((resource) => ({
|
|
181
|
+
uri: resource.uri,
|
|
182
|
+
name: resource.name,
|
|
183
|
+
description: resource.description,
|
|
184
|
+
mimeType: resource.mimeType
|
|
185
|
+
}));
|
|
186
|
+
if (exposeSharedState !== false) {
|
|
187
|
+
const filter = typeof exposeSharedState === "function" ? exposeSharedState : () => true;
|
|
188
|
+
for (const key of ctx.rpc.sharedState.keys()) {
|
|
189
|
+
if (!filter(key)) continue;
|
|
190
|
+
resources.push({
|
|
191
|
+
uri: `devframe://state/${encodeURIComponent(key)}`,
|
|
192
|
+
name: key,
|
|
193
|
+
description: `Shared state: ${key}`,
|
|
194
|
+
mimeType: "application/json"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { resources };
|
|
199
|
+
});
|
|
200
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
201
|
+
const { uri } = request.params;
|
|
202
|
+
const parsed = parseResourceUri(uri);
|
|
203
|
+
if (parsed.kind === "resource") {
|
|
204
|
+
const content = await ctx.agent.read(parsed.id);
|
|
205
|
+
return { contents: [{
|
|
206
|
+
uri,
|
|
207
|
+
mimeType: content.mimeType ?? "application/json",
|
|
208
|
+
text: content.text ?? stringify(content.json)
|
|
209
|
+
}] };
|
|
210
|
+
}
|
|
211
|
+
if (parsed.kind === "state") return { contents: [{
|
|
212
|
+
uri,
|
|
213
|
+
mimeType: "application/json",
|
|
214
|
+
text: stringify((await ctx.rpc.sharedState.get(parsed.key)).value())
|
|
215
|
+
}] };
|
|
216
|
+
throw new Error(`[devframe/mcp] unknown resource URI "${uri}"`);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function projectTool(tool, ctx) {
|
|
220
|
+
const inputSchema = tool.inputSchema ?? computeInputSchema(tool, ctx);
|
|
221
|
+
const outputSchema = tool.outputSchema ?? computeOutputSchema(tool, ctx);
|
|
222
|
+
return {
|
|
223
|
+
name: tool.id,
|
|
224
|
+
title: tool.title,
|
|
225
|
+
description: tool.description,
|
|
226
|
+
inputSchema,
|
|
227
|
+
...outputSchema ? { outputSchema } : {},
|
|
228
|
+
annotations: {
|
|
229
|
+
title: tool.title,
|
|
230
|
+
readOnlyHint: tool.safety === "read",
|
|
231
|
+
destructiveHint: tool.safety === "destructive"
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function computeInputSchema(tool, ctx) {
|
|
236
|
+
if (tool.kind !== "rpc" || !tool.rpcName) return {
|
|
237
|
+
type: "object",
|
|
238
|
+
properties: {}
|
|
239
|
+
};
|
|
240
|
+
const def = ctx.rpc.definitions.get(tool.rpcName);
|
|
241
|
+
if (!def) return {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {}
|
|
244
|
+
};
|
|
245
|
+
const args = def.args;
|
|
246
|
+
return valibotArgsToJsonSchema(args).schema;
|
|
247
|
+
}
|
|
248
|
+
function computeOutputSchema(tool, ctx) {
|
|
249
|
+
if (tool.kind !== "rpc" || !tool.rpcName) return void 0;
|
|
250
|
+
const def = ctx.rpc.definitions.get(tool.rpcName);
|
|
251
|
+
if (!def) return void 0;
|
|
252
|
+
return valibotReturnToJsonSchema(def.returns);
|
|
253
|
+
}
|
|
254
|
+
function parseResourceUri(uri) {
|
|
255
|
+
const match = uri.match(/^devframe:\/\/(resource|state)\/(.+)$/);
|
|
256
|
+
if (!match) return { kind: "unknown" };
|
|
257
|
+
const [, kind, rest] = match;
|
|
258
|
+
const decoded = decodeURIComponent(rest);
|
|
259
|
+
if (kind === "resource") return {
|
|
260
|
+
kind: "resource",
|
|
261
|
+
id: decoded
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
kind: "state",
|
|
265
|
+
key: decoded
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function stringify(value) {
|
|
269
|
+
if (value === void 0) return "undefined";
|
|
270
|
+
if (typeof value === "string") return value;
|
|
271
|
+
try {
|
|
272
|
+
return JSON.stringify(value, null, 2);
|
|
273
|
+
} catch {
|
|
274
|
+
return String(value);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
export { createMcpServer };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { r as DevtoolDefinition } from "../devtool-OJ3QW0ns.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/adapters/vite.d.ts
|
|
4
|
+
interface CreateVitePluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Mount base. Defaults to `def.basePath ?? '/.<id>/'` for this hosted
|
|
7
|
+
* adapter — the devtool shares the origin with the host Vite app.
|
|
8
|
+
*/
|
|
9
|
+
base?: string;
|
|
10
|
+
}
|
|
11
|
+
interface DevframeVitePlugin {
|
|
12
|
+
name: string;
|
|
13
|
+
apply: 'serve';
|
|
14
|
+
configureServer: (server: {
|
|
15
|
+
middlewares: {
|
|
16
|
+
use: (path: string, handler: any) => void;
|
|
17
|
+
};
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Plain Vite plugin — mounts a devframe devtool's SPA into a user's
|
|
22
|
+
* Vite dev server at `options.base` (default: `def.basePath ?? '/.<id>/'`).
|
|
23
|
+
* Use this for tools that want the Vite dev experience without
|
|
24
|
+
* pulling the full Vite DevTools Kit.
|
|
25
|
+
*
|
|
26
|
+
* Note: this does not yet spin up the RPC WS server — for the full
|
|
27
|
+
* RPC path, use `createKitPlugin` alongside `@vitejs/devtools`, or the
|
|
28
|
+
* standalone `createCli`.
|
|
29
|
+
*/
|
|
30
|
+
declare function createVitePlugin(d: DevtoolDefinition, options?: CreateVitePluginOptions): DevframeVitePlugin;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CreateVitePluginOptions, DevframeVitePlugin, createVitePlugin };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as resolveBasePath } from "../_shared-CU6dE-VX.mjs";
|
|
2
|
+
import { resolve } from "pathe";
|
|
3
|
+
import sirv from "sirv";
|
|
4
|
+
//#region src/adapters/vite.ts
|
|
5
|
+
/**
|
|
6
|
+
* Plain Vite plugin — mounts a devframe devtool's SPA into a user's
|
|
7
|
+
* Vite dev server at `options.base` (default: `def.basePath ?? '/.<id>/'`).
|
|
8
|
+
* Use this for tools that want the Vite dev experience without
|
|
9
|
+
* pulling the full Vite DevTools Kit.
|
|
10
|
+
*
|
|
11
|
+
* Note: this does not yet spin up the RPC WS server — for the full
|
|
12
|
+
* RPC path, use `createKitPlugin` alongside `@vitejs/devtools`, or the
|
|
13
|
+
* standalone `createCli`.
|
|
14
|
+
*/
|
|
15
|
+
function createVitePlugin(d, options = {}) {
|
|
16
|
+
const base = options.base ?? resolveBasePath(d, "hosted");
|
|
17
|
+
const distDir = d.cli?.distDir;
|
|
18
|
+
return {
|
|
19
|
+
name: `devframe:${d.id}`,
|
|
20
|
+
apply: "serve",
|
|
21
|
+
configureServer(server) {
|
|
22
|
+
if (!distDir) return;
|
|
23
|
+
server.middlewares.use(base, sirv(resolve(distDir), {
|
|
24
|
+
dev: true,
|
|
25
|
+
single: true
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createVitePlugin };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { H as DevToolsRpcClientFunctions, St as DevToolsCommandEntry, U as DevToolsRpcServerFunctions, V as DevToolsDocksUserSettings, bt as DevToolsClientCommand, ct as DevToolsDockUserEntry, l as ConnectionMeta, nt as DevToolsDockEntriesGrouped, rt as DevToolsDockEntry, v as RpcSharedStateHost, w as SharedState, wt as DevToolsCommandKeybinding, zt as EventEmitter } from "../devtool-OJ3QW0ns.mjs";
|
|
2
|
+
import { F as RpcCacheManager, I as RpcCacheOptions, M as RpcFunctionsCollector } from "../index-DvKDO5H8.mjs";
|
|
3
|
+
import { t as WhenContext } from "../when-CGLewRtm.mjs";
|
|
4
|
+
import { t as WsRpcChannelOptions } from "../ws-client-CklfxUHE.mjs";
|
|
5
|
+
import { BirpcOptions, BirpcReturn } from "birpc";
|
|
6
|
+
|
|
7
|
+
//#region src/client/rpc.d.ts
|
|
8
|
+
interface DevToolsRpcClientOptions {
|
|
9
|
+
connectionMeta?: ConnectionMeta;
|
|
10
|
+
baseURL?: string | string[];
|
|
11
|
+
/**
|
|
12
|
+
* The auth token to use for the client
|
|
13
|
+
*/
|
|
14
|
+
authToken?: string;
|
|
15
|
+
wsOptions?: Partial<WsRpcChannelOptions>;
|
|
16
|
+
rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions, boolean>>;
|
|
17
|
+
cacheOptions?: boolean | Partial<RpcCacheOptions>;
|
|
18
|
+
}
|
|
19
|
+
type DevToolsRpcClientCall = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$call'];
|
|
20
|
+
type DevToolsRpcClientCallEvent = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callEvent'];
|
|
21
|
+
type DevToolsRpcClientCallOptional = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callOptional'];
|
|
22
|
+
interface DevToolsRpcClient {
|
|
23
|
+
/**
|
|
24
|
+
* The events of the client
|
|
25
|
+
*/
|
|
26
|
+
events: EventEmitter<RpcClientEvents>;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the client is trusted
|
|
29
|
+
*/
|
|
30
|
+
readonly isTrusted: boolean | null;
|
|
31
|
+
/**
|
|
32
|
+
* The connection meta
|
|
33
|
+
*/
|
|
34
|
+
readonly connectionMeta: ConnectionMeta;
|
|
35
|
+
/**
|
|
36
|
+
* Return a promise that resolves when the client is trusted
|
|
37
|
+
*
|
|
38
|
+
* Rejects with an error if the timeout is reached
|
|
39
|
+
*
|
|
40
|
+
* @param timeout - The timeout in milliseconds, default to 60 seconds
|
|
41
|
+
*/
|
|
42
|
+
ensureTrusted: (timeout?: number) => Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Request trust from the server
|
|
45
|
+
*/
|
|
46
|
+
requestTrust: () => Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Request trust from the server using a specific auth token.
|
|
49
|
+
* Updates the stored token and re-requests trust without reloading the page.
|
|
50
|
+
*/
|
|
51
|
+
requestTrustWithToken: (token: string) => Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Call a RPC function on the server
|
|
54
|
+
*/
|
|
55
|
+
call: DevToolsRpcClientCall;
|
|
56
|
+
/**
|
|
57
|
+
* Call a RPC event on the server, and does not expect a response
|
|
58
|
+
*/
|
|
59
|
+
callEvent: DevToolsRpcClientCallEvent;
|
|
60
|
+
/**
|
|
61
|
+
* Call a RPC optional function on the server
|
|
62
|
+
*/
|
|
63
|
+
callOptional: DevToolsRpcClientCallOptional;
|
|
64
|
+
/**
|
|
65
|
+
* The client RPC host
|
|
66
|
+
*/
|
|
67
|
+
client: DevToolsClientRpcHost;
|
|
68
|
+
/**
|
|
69
|
+
* The shared state host
|
|
70
|
+
*/
|
|
71
|
+
sharedState: RpcSharedStateHost;
|
|
72
|
+
/**
|
|
73
|
+
* The RPC cache manager
|
|
74
|
+
*/
|
|
75
|
+
cacheManager: RpcCacheManager;
|
|
76
|
+
}
|
|
77
|
+
interface DevToolsRpcClientMode {
|
|
78
|
+
readonly isTrusted: boolean;
|
|
79
|
+
ensureTrusted: DevToolsRpcClient['ensureTrusted'];
|
|
80
|
+
requestTrust: DevToolsRpcClient['requestTrust'];
|
|
81
|
+
requestTrustWithToken: DevToolsRpcClient['requestTrustWithToken'];
|
|
82
|
+
call: DevToolsRpcClient['call'];
|
|
83
|
+
callEvent: DevToolsRpcClient['callEvent'];
|
|
84
|
+
callOptional: DevToolsRpcClient['callOptional'];
|
|
85
|
+
}
|
|
86
|
+
declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<DevToolsRpcClient>;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/client/docks.d.ts
|
|
89
|
+
interface DockPanelStorage {
|
|
90
|
+
mode: 'float' | 'edge';
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
top: number;
|
|
94
|
+
left: number;
|
|
95
|
+
position: 'left' | 'right' | 'bottom' | 'top';
|
|
96
|
+
open: boolean;
|
|
97
|
+
inactiveTimeout: number;
|
|
98
|
+
}
|
|
99
|
+
type DockClientType = 'embedded' | 'standalone';
|
|
100
|
+
interface DevToolsRpcContext {
|
|
101
|
+
/**
|
|
102
|
+
* The RPC client to interact with the server
|
|
103
|
+
*/
|
|
104
|
+
readonly rpc: DevToolsRpcClient;
|
|
105
|
+
}
|
|
106
|
+
interface DocksContext extends DevToolsRpcContext {
|
|
107
|
+
/**
|
|
108
|
+
* Type of the client environment
|
|
109
|
+
*
|
|
110
|
+
* 'embedded' - running inside an embedded floating panel
|
|
111
|
+
* 'standalone' - running inside a standalone window (no user app)
|
|
112
|
+
*/
|
|
113
|
+
readonly clientType: 'embedded' | 'standalone';
|
|
114
|
+
/**
|
|
115
|
+
* The panel context
|
|
116
|
+
*/
|
|
117
|
+
readonly panel: DocksPanelContext;
|
|
118
|
+
/**
|
|
119
|
+
* The docks entries context
|
|
120
|
+
*/
|
|
121
|
+
readonly docks: DocksEntriesContext;
|
|
122
|
+
/**
|
|
123
|
+
* The commands context for command palette and shortcuts
|
|
124
|
+
*/
|
|
125
|
+
readonly commands: CommandsContext;
|
|
126
|
+
/**
|
|
127
|
+
* The when-clause context for conditional visibility
|
|
128
|
+
*/
|
|
129
|
+
readonly when: WhenClauseContext;
|
|
130
|
+
}
|
|
131
|
+
interface WhenClauseContext {
|
|
132
|
+
/**
|
|
133
|
+
* Get the current when-clause context snapshot.
|
|
134
|
+
* Returns a reactive object with built-in variables and any custom plugin variables.
|
|
135
|
+
*/
|
|
136
|
+
readonly context: WhenContext;
|
|
137
|
+
}
|
|
138
|
+
type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsRpcContext>;
|
|
139
|
+
type DevToolsClientContext = DocksContext;
|
|
140
|
+
interface DocksPanelContext {
|
|
141
|
+
store: DockPanelStorage;
|
|
142
|
+
isDragging: boolean;
|
|
143
|
+
isResizing: boolean;
|
|
144
|
+
readonly isVertical: boolean;
|
|
145
|
+
}
|
|
146
|
+
interface DocksEntriesContext {
|
|
147
|
+
selectedId: string | null;
|
|
148
|
+
readonly selected: DevToolsDockEntry | null;
|
|
149
|
+
entries: DevToolsDockEntry[];
|
|
150
|
+
entryToStateMap: Map<string, DockEntryState>;
|
|
151
|
+
groupedEntries: DevToolsDockEntriesGrouped;
|
|
152
|
+
settings: SharedState<DevToolsDocksUserSettings>;
|
|
153
|
+
/**
|
|
154
|
+
* Get the state of a dock entry by its ID
|
|
155
|
+
*/
|
|
156
|
+
getStateById: (id: string) => DockEntryState | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Switch to the selected dock entry, pass `null` to clear the selection
|
|
159
|
+
*
|
|
160
|
+
* @returns Whether the selection was changed successfully
|
|
161
|
+
*/
|
|
162
|
+
switchEntry: (id?: string | null) => Promise<boolean>;
|
|
163
|
+
/**
|
|
164
|
+
* Toggle the selected dock entry
|
|
165
|
+
*
|
|
166
|
+
* @returns Whether the selection was changed successfully
|
|
167
|
+
*/
|
|
168
|
+
toggleEntry: (id: string) => Promise<boolean>;
|
|
169
|
+
}
|
|
170
|
+
interface DockEntryState {
|
|
171
|
+
entryMeta: DevToolsDockEntry;
|
|
172
|
+
readonly isActive: boolean;
|
|
173
|
+
domElements: {
|
|
174
|
+
iframe?: HTMLIFrameElement | null;
|
|
175
|
+
panel?: HTMLDivElement | null;
|
|
176
|
+
};
|
|
177
|
+
events: EventEmitter<DockEntryStateEvents>;
|
|
178
|
+
}
|
|
179
|
+
interface DockEntryStateEvents {
|
|
180
|
+
'entry:activated': () => void;
|
|
181
|
+
'entry:deactivated': () => void;
|
|
182
|
+
'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
|
|
183
|
+
'dom:panel:mounted': (panel: HTMLDivElement) => void;
|
|
184
|
+
'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
|
|
185
|
+
}
|
|
186
|
+
interface RpcClientEvents {
|
|
187
|
+
'rpc:is-trusted:updated': (isTrusted: boolean) => void;
|
|
188
|
+
}
|
|
189
|
+
interface CommandsContext {
|
|
190
|
+
/**
|
|
191
|
+
* All commands (server + client)
|
|
192
|
+
*/
|
|
193
|
+
readonly commands: DevToolsCommandEntry[];
|
|
194
|
+
/**
|
|
195
|
+
* Palette-visible commands only (filtered by `showInPalette !== false`)
|
|
196
|
+
*/
|
|
197
|
+
readonly paletteCommands: DevToolsCommandEntry[];
|
|
198
|
+
/**
|
|
199
|
+
* Register client-side command(s). Returns cleanup function.
|
|
200
|
+
*/
|
|
201
|
+
register: (cmd: DevToolsClientCommand | DevToolsClientCommand[]) => () => void;
|
|
202
|
+
/**
|
|
203
|
+
* Execute a command by ID. Delegates to RPC for server commands.
|
|
204
|
+
*/
|
|
205
|
+
execute: (id: string, ...args: any[]) => Promise<unknown>;
|
|
206
|
+
/**
|
|
207
|
+
* Get effective keybindings for a command (defaults merged with overrides)
|
|
208
|
+
*/
|
|
209
|
+
getKeybindings: (id: string) => DevToolsCommandKeybinding[];
|
|
210
|
+
/**
|
|
211
|
+
* User settings store (persisted, includes command shortcuts)
|
|
212
|
+
*/
|
|
213
|
+
settings: SharedState<DevToolsDocksUserSettings>;
|
|
214
|
+
/**
|
|
215
|
+
* Whether the command palette is open
|
|
216
|
+
*/
|
|
217
|
+
paletteOpen: boolean;
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/client/context.d.ts
|
|
221
|
+
declare const CLIENT_CONTEXT_KEY = "__VITE_DEVTOOLS_CLIENT_CONTEXT__";
|
|
222
|
+
/**
|
|
223
|
+
* Get the global DevTools client context, or `undefined` if not yet initialized.
|
|
224
|
+
*/
|
|
225
|
+
declare function getDevToolsClientContext(): DevToolsClientContext | undefined;
|
|
226
|
+
//#endregion
|
|
227
|
+
export { CLIENT_CONTEXT_KEY, CommandsContext, DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientCall, DevToolsRpcClientCallEvent, DevToolsRpcClientCallOptional, DevToolsRpcClientMode, DevToolsRpcClientOptions, DevToolsRpcContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, RpcClientEvents, WhenClauseContext, getDevToolsRpcClient as connectDevtool, getDevToolsRpcClient, getDevToolsClientContext };
|