unplugin-devpilot 0.0.1 → 0.0.3
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/README.md +105 -0
- package/dist/farm.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{src-42lrzRI8.mjs → src-Bm2tOOQC.mjs} +224 -42
- package/dist/vite.mjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# unplugin-devpilot
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![Unit Test][unit-test-src]][unit-test-href]
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -D unplugin-devpilot
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
<details>
|
|
14
|
+
<summary>Vite</summary><br>
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// vite.config.ts
|
|
18
|
+
import Devpilot from 'unplugin-devpilot/vite';
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [Devpilot()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
<br></details>
|
|
26
|
+
|
|
27
|
+
<details>
|
|
28
|
+
<summary>Webpack</summary><br>
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
// webpack.config.js
|
|
32
|
+
import Devpilot from 'unplugin-devpilot/webpack';
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
/* ... */
|
|
36
|
+
plugins: [Devpilot()],
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
<br></details>
|
|
41
|
+
|
|
42
|
+
<details>
|
|
43
|
+
<summary>Rspack</summary><br>
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// rspack.config.js
|
|
47
|
+
import Devpilot from 'unplugin-devpilot/rspack';
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
/* ... */
|
|
51
|
+
plugins: [Devpilot()],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
<br></details>
|
|
56
|
+
|
|
57
|
+
## Client Import
|
|
58
|
+
|
|
59
|
+
Add this import to your project entry point to enable the devpilot client:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// main.ts or main.js (entry point)
|
|
63
|
+
import 'virtual:devpilot-client';
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This import activates the WebSocket connection to the development server and initializes all registered plugins on the client side.
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
You can customize the plugin behavior by passing options:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// vite.config.ts
|
|
74
|
+
import Devpilot from 'unplugin-devpilot/vite';
|
|
75
|
+
|
|
76
|
+
export default defineConfig({
|
|
77
|
+
plugins: [
|
|
78
|
+
Devpilot({
|
|
79
|
+
wsPort: 3100, // Optional: Specify WebSocket port (will be randomly allocated if not specified)
|
|
80
|
+
mcpPort: 3101, // Optional: Specify MCP server port (will use random port if specified port is occupied)
|
|
81
|
+
plugins: [], // Optional: Array of DevpilotPlugin instances
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Port Allocation Strategy
|
|
88
|
+
|
|
89
|
+
- **wsPort**: When provided, the specified port is used if available; otherwise, a random available port is allocated. When not provided, a random available port is automatically allocated
|
|
90
|
+
- **mcpPort**: When not provided, defaults to 3101. If the port is already in use, an error will be thrown
|
|
91
|
+
|
|
92
|
+
This ensures your MCP server runs on a predictable port. If the default port is occupied, you'll need to specify a different port or free up the occupied port.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
[MIT](./LICENSE) License © 2025-PRESENT [Huali](https://github.com/zcf0508)
|
|
97
|
+
|
|
98
|
+
<!-- Badges -->
|
|
99
|
+
|
|
100
|
+
[npm-version-src]: https://img.shields.io/npm/v/unplugin-devpilot.svg
|
|
101
|
+
[npm-version-href]: https://npmjs.com/package/unplugin-devpilot
|
|
102
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-devpilot
|
|
103
|
+
[npm-downloads-href]: https://www.npmcharts.com/compare/unplugin-devpilot?interval=30
|
|
104
|
+
[unit-test-src]: https://github.com/zcf0508/unplugin-devpilot/actions/workflows/unit-test.yml/badge.svg
|
|
105
|
+
[unit-test-href]: https://github.com/zcf0508/unplugin-devpilot/actions/workflows/unit-test.yml
|
package/dist/farm.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as unpluginDevpilot, r as clientManager, t as src_default } from "./src-
|
|
1
|
+
import { n as unpluginDevpilot, r as clientManager, t as src_default } from "./src-Bm2tOOQC.mjs";
|
|
2
2
|
import { n as defineMcpToolRegister, t as resolveClientModule } from "./plugin-BPkoZQbf.mjs";
|
|
3
3
|
|
|
4
4
|
export { clientManager, src_default as default, defineMcpToolRegister, resolveClientModule, unpluginDevpilot };
|
package/dist/rspack.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import process$1 from "node:process";
|
|
2
3
|
import { createUnplugin } from "unplugin";
|
|
3
4
|
import { createServer } from "node:http";
|
|
4
5
|
import { Http2ServerRequest } from "http2";
|
|
5
6
|
import { Readable } from "stream";
|
|
6
7
|
import crypto$1 from "crypto";
|
|
8
|
+
import { createServer as createServer$1 } from "node:net";
|
|
9
|
+
import { networkInterfaces } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { exec } from "node:child_process";
|
|
7
12
|
|
|
8
13
|
//#region rolldown:runtime
|
|
9
14
|
var __create = Object.create;
|
|
@@ -6406,7 +6411,7 @@ function initializeContext(params) {
|
|
|
6406
6411
|
external: params?.external ?? void 0
|
|
6407
6412
|
};
|
|
6408
6413
|
}
|
|
6409
|
-
function process$
|
|
6414
|
+
function process$2(schema, ctx, _params = {
|
|
6410
6415
|
path: [],
|
|
6411
6416
|
schemaPath: []
|
|
6412
6417
|
}) {
|
|
@@ -6443,7 +6448,7 @@ function process$1(schema, ctx, _params = {
|
|
|
6443
6448
|
const parent = schema._zod.parent;
|
|
6444
6449
|
if (parent) {
|
|
6445
6450
|
if (!result.ref) result.ref = parent;
|
|
6446
|
-
process$
|
|
6451
|
+
process$2(parent, ctx, params);
|
|
6447
6452
|
ctx.seen.get(parent).isParent = true;
|
|
6448
6453
|
}
|
|
6449
6454
|
}
|
|
@@ -6655,7 +6660,7 @@ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
|
6655
6660
|
...params,
|
|
6656
6661
|
processors
|
|
6657
6662
|
});
|
|
6658
|
-
process$
|
|
6663
|
+
process$2(schema, ctx);
|
|
6659
6664
|
extractDefs(ctx, schema);
|
|
6660
6665
|
return finalize(ctx, schema);
|
|
6661
6666
|
};
|
|
@@ -6667,7 +6672,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
6667
6672
|
io,
|
|
6668
6673
|
processors
|
|
6669
6674
|
});
|
|
6670
|
-
process$
|
|
6675
|
+
process$2(schema, ctx);
|
|
6671
6676
|
extractDefs(ctx, schema);
|
|
6672
6677
|
return finalize(ctx, schema);
|
|
6673
6678
|
};
|
|
@@ -6839,7 +6844,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
|
|
|
6839
6844
|
if (typeof minimum === "number") json.minItems = minimum;
|
|
6840
6845
|
if (typeof maximum === "number") json.maxItems = maximum;
|
|
6841
6846
|
json.type = "array";
|
|
6842
|
-
json.items = process$
|
|
6847
|
+
json.items = process$2(def.element, ctx, {
|
|
6843
6848
|
...params,
|
|
6844
6849
|
path: [...params.path, "items"]
|
|
6845
6850
|
});
|
|
@@ -6850,7 +6855,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
6850
6855
|
json.type = "object";
|
|
6851
6856
|
json.properties = {};
|
|
6852
6857
|
const shape = def.shape;
|
|
6853
|
-
for (const key in shape) json.properties[key] = process$
|
|
6858
|
+
for (const key in shape) json.properties[key] = process$2(shape[key], ctx, {
|
|
6854
6859
|
...params,
|
|
6855
6860
|
path: [
|
|
6856
6861
|
...params.path,
|
|
@@ -6868,7 +6873,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
6868
6873
|
if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
|
|
6869
6874
|
else if (!def.catchall) {
|
|
6870
6875
|
if (ctx.io === "output") json.additionalProperties = false;
|
|
6871
|
-
} else if (def.catchall) json.additionalProperties = process$
|
|
6876
|
+
} else if (def.catchall) json.additionalProperties = process$2(def.catchall, ctx, {
|
|
6872
6877
|
...params,
|
|
6873
6878
|
path: [...params.path, "additionalProperties"]
|
|
6874
6879
|
});
|
|
@@ -6876,7 +6881,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
6876
6881
|
const unionProcessor = (schema, ctx, json, params) => {
|
|
6877
6882
|
const def = schema._zod.def;
|
|
6878
6883
|
const isExclusive = def.inclusive === false;
|
|
6879
|
-
const options = def.options.map((x, i) => process$
|
|
6884
|
+
const options = def.options.map((x, i) => process$2(x, ctx, {
|
|
6880
6885
|
...params,
|
|
6881
6886
|
path: [
|
|
6882
6887
|
...params.path,
|
|
@@ -6889,7 +6894,7 @@ const unionProcessor = (schema, ctx, json, params) => {
|
|
|
6889
6894
|
};
|
|
6890
6895
|
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
6891
6896
|
const def = schema._zod.def;
|
|
6892
|
-
const a = process$
|
|
6897
|
+
const a = process$2(def.left, ctx, {
|
|
6893
6898
|
...params,
|
|
6894
6899
|
path: [
|
|
6895
6900
|
...params.path,
|
|
@@ -6897,7 +6902,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
6897
6902
|
0
|
|
6898
6903
|
]
|
|
6899
6904
|
});
|
|
6900
|
-
const b = process$
|
|
6905
|
+
const b = process$2(def.right, ctx, {
|
|
6901
6906
|
...params,
|
|
6902
6907
|
path: [
|
|
6903
6908
|
...params.path,
|
|
@@ -6914,7 +6919,7 @@ const tupleProcessor = (schema, ctx, _json, params) => {
|
|
|
6914
6919
|
json.type = "array";
|
|
6915
6920
|
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
6916
6921
|
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
6917
|
-
const prefixItems = def.items.map((x, i) => process$
|
|
6922
|
+
const prefixItems = def.items.map((x, i) => process$2(x, ctx, {
|
|
6918
6923
|
...params,
|
|
6919
6924
|
path: [
|
|
6920
6925
|
...params.path,
|
|
@@ -6922,7 +6927,7 @@ const tupleProcessor = (schema, ctx, _json, params) => {
|
|
|
6922
6927
|
i
|
|
6923
6928
|
]
|
|
6924
6929
|
}));
|
|
6925
|
-
const rest = def.rest ? process$
|
|
6930
|
+
const rest = def.rest ? process$2(def.rest, ctx, {
|
|
6926
6931
|
...params,
|
|
6927
6932
|
path: [
|
|
6928
6933
|
...params.path,
|
|
@@ -6953,7 +6958,7 @@ const recordProcessor = (schema, ctx, _json, params) => {
|
|
|
6953
6958
|
const keyType = def.keyType;
|
|
6954
6959
|
const patterns = keyType._zod.bag?.patterns;
|
|
6955
6960
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
6956
|
-
const valueSchema = process$
|
|
6961
|
+
const valueSchema = process$2(def.valueType, ctx, {
|
|
6957
6962
|
...params,
|
|
6958
6963
|
path: [
|
|
6959
6964
|
...params.path,
|
|
@@ -6964,11 +6969,11 @@ const recordProcessor = (schema, ctx, _json, params) => {
|
|
|
6964
6969
|
json.patternProperties = {};
|
|
6965
6970
|
for (const pattern of patterns) json.patternProperties[pattern.source] = valueSchema;
|
|
6966
6971
|
} else {
|
|
6967
|
-
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process$
|
|
6972
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process$2(def.keyType, ctx, {
|
|
6968
6973
|
...params,
|
|
6969
6974
|
path: [...params.path, "propertyNames"]
|
|
6970
6975
|
});
|
|
6971
|
-
json.additionalProperties = process$
|
|
6976
|
+
json.additionalProperties = process$2(def.valueType, ctx, {
|
|
6972
6977
|
...params,
|
|
6973
6978
|
path: [...params.path, "additionalProperties"]
|
|
6974
6979
|
});
|
|
@@ -6981,7 +6986,7 @@ const recordProcessor = (schema, ctx, _json, params) => {
|
|
|
6981
6986
|
};
|
|
6982
6987
|
const nullableProcessor = (schema, ctx, json, params) => {
|
|
6983
6988
|
const def = schema._zod.def;
|
|
6984
|
-
const inner = process$
|
|
6989
|
+
const inner = process$2(def.innerType, ctx, params);
|
|
6985
6990
|
const seen = ctx.seen.get(schema);
|
|
6986
6991
|
if (ctx.target === "openapi-3.0") {
|
|
6987
6992
|
seen.ref = def.innerType;
|
|
@@ -6990,27 +6995,27 @@ const nullableProcessor = (schema, ctx, json, params) => {
|
|
|
6990
6995
|
};
|
|
6991
6996
|
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
6992
6997
|
const def = schema._zod.def;
|
|
6993
|
-
process$
|
|
6998
|
+
process$2(def.innerType, ctx, params);
|
|
6994
6999
|
const seen = ctx.seen.get(schema);
|
|
6995
7000
|
seen.ref = def.innerType;
|
|
6996
7001
|
};
|
|
6997
7002
|
const defaultProcessor = (schema, ctx, json, params) => {
|
|
6998
7003
|
const def = schema._zod.def;
|
|
6999
|
-
process$
|
|
7004
|
+
process$2(def.innerType, ctx, params);
|
|
7000
7005
|
const seen = ctx.seen.get(schema);
|
|
7001
7006
|
seen.ref = def.innerType;
|
|
7002
7007
|
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
7003
7008
|
};
|
|
7004
7009
|
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
7005
7010
|
const def = schema._zod.def;
|
|
7006
|
-
process$
|
|
7011
|
+
process$2(def.innerType, ctx, params);
|
|
7007
7012
|
const seen = ctx.seen.get(schema);
|
|
7008
7013
|
seen.ref = def.innerType;
|
|
7009
7014
|
if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
7010
7015
|
};
|
|
7011
7016
|
const catchProcessor = (schema, ctx, json, params) => {
|
|
7012
7017
|
const def = schema._zod.def;
|
|
7013
|
-
process$
|
|
7018
|
+
process$2(def.innerType, ctx, params);
|
|
7014
7019
|
const seen = ctx.seen.get(schema);
|
|
7015
7020
|
seen.ref = def.innerType;
|
|
7016
7021
|
let catchValue;
|
|
@@ -7024,32 +7029,32 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
7024
7029
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
7025
7030
|
const def = schema._zod.def;
|
|
7026
7031
|
const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
7027
|
-
process$
|
|
7032
|
+
process$2(innerType, ctx, params);
|
|
7028
7033
|
const seen = ctx.seen.get(schema);
|
|
7029
7034
|
seen.ref = innerType;
|
|
7030
7035
|
};
|
|
7031
7036
|
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
7032
7037
|
const def = schema._zod.def;
|
|
7033
|
-
process$
|
|
7038
|
+
process$2(def.innerType, ctx, params);
|
|
7034
7039
|
const seen = ctx.seen.get(schema);
|
|
7035
7040
|
seen.ref = def.innerType;
|
|
7036
7041
|
json.readOnly = true;
|
|
7037
7042
|
};
|
|
7038
7043
|
const promiseProcessor = (schema, ctx, _json, params) => {
|
|
7039
7044
|
const def = schema._zod.def;
|
|
7040
|
-
process$
|
|
7045
|
+
process$2(def.innerType, ctx, params);
|
|
7041
7046
|
const seen = ctx.seen.get(schema);
|
|
7042
7047
|
seen.ref = def.innerType;
|
|
7043
7048
|
};
|
|
7044
7049
|
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
7045
7050
|
const def = schema._zod.def;
|
|
7046
|
-
process$
|
|
7051
|
+
process$2(def.innerType, ctx, params);
|
|
7047
7052
|
const seen = ctx.seen.get(schema);
|
|
7048
7053
|
seen.ref = def.innerType;
|
|
7049
7054
|
};
|
|
7050
7055
|
const lazyProcessor = (schema, ctx, _json, params) => {
|
|
7051
7056
|
const innerType = schema._zod.innerType;
|
|
7052
|
-
process$
|
|
7057
|
+
process$2(innerType, ctx, params);
|
|
7053
7058
|
const seen = ctx.seen.get(schema);
|
|
7054
7059
|
seen.ref = innerType;
|
|
7055
7060
|
};
|
|
@@ -7104,7 +7109,7 @@ function toJSONSchema(input, params) {
|
|
|
7104
7109
|
const defs = {};
|
|
7105
7110
|
for (const entry of registry._idmap.entries()) {
|
|
7106
7111
|
const [_, schema] = entry;
|
|
7107
|
-
process$
|
|
7112
|
+
process$2(schema, ctx);
|
|
7108
7113
|
}
|
|
7109
7114
|
const schemas = {};
|
|
7110
7115
|
ctx.external = {
|
|
@@ -7124,7 +7129,7 @@ function toJSONSchema(input, params) {
|
|
|
7124
7129
|
...params,
|
|
7125
7130
|
processors: allProcessors
|
|
7126
7131
|
});
|
|
7127
|
-
process$
|
|
7132
|
+
process$2(input, ctx);
|
|
7128
7133
|
extractDefs(ctx, input);
|
|
7129
7134
|
return finalize(ctx, input);
|
|
7130
7135
|
}
|
|
@@ -19792,7 +19797,7 @@ var StreamableHTTPServerTransport = class {
|
|
|
19792
19797
|
|
|
19793
19798
|
//#endregion
|
|
19794
19799
|
//#region package.json
|
|
19795
|
-
var version = "0.0.
|
|
19800
|
+
var version = "0.0.3";
|
|
19796
19801
|
|
|
19797
19802
|
//#endregion
|
|
19798
19803
|
//#region ../../node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/compat/util/uniqueId.mjs
|
|
@@ -20195,16 +20200,184 @@ function stopMcpServer() {
|
|
|
20195
20200
|
}
|
|
20196
20201
|
}
|
|
20197
20202
|
|
|
20203
|
+
//#endregion
|
|
20204
|
+
//#region ../../node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
|
|
20205
|
+
const unsafePorts = /* @__PURE__ */ new Set([
|
|
20206
|
+
1,
|
|
20207
|
+
7,
|
|
20208
|
+
9,
|
|
20209
|
+
11,
|
|
20210
|
+
13,
|
|
20211
|
+
15,
|
|
20212
|
+
17,
|
|
20213
|
+
19,
|
|
20214
|
+
20,
|
|
20215
|
+
21,
|
|
20216
|
+
22,
|
|
20217
|
+
23,
|
|
20218
|
+
25,
|
|
20219
|
+
37,
|
|
20220
|
+
42,
|
|
20221
|
+
43,
|
|
20222
|
+
53,
|
|
20223
|
+
69,
|
|
20224
|
+
77,
|
|
20225
|
+
79,
|
|
20226
|
+
87,
|
|
20227
|
+
95,
|
|
20228
|
+
101,
|
|
20229
|
+
102,
|
|
20230
|
+
103,
|
|
20231
|
+
104,
|
|
20232
|
+
109,
|
|
20233
|
+
110,
|
|
20234
|
+
111,
|
|
20235
|
+
113,
|
|
20236
|
+
115,
|
|
20237
|
+
117,
|
|
20238
|
+
119,
|
|
20239
|
+
123,
|
|
20240
|
+
135,
|
|
20241
|
+
137,
|
|
20242
|
+
139,
|
|
20243
|
+
143,
|
|
20244
|
+
161,
|
|
20245
|
+
179,
|
|
20246
|
+
389,
|
|
20247
|
+
427,
|
|
20248
|
+
465,
|
|
20249
|
+
512,
|
|
20250
|
+
513,
|
|
20251
|
+
514,
|
|
20252
|
+
515,
|
|
20253
|
+
526,
|
|
20254
|
+
530,
|
|
20255
|
+
531,
|
|
20256
|
+
532,
|
|
20257
|
+
540,
|
|
20258
|
+
548,
|
|
20259
|
+
554,
|
|
20260
|
+
556,
|
|
20261
|
+
563,
|
|
20262
|
+
587,
|
|
20263
|
+
601,
|
|
20264
|
+
636,
|
|
20265
|
+
989,
|
|
20266
|
+
990,
|
|
20267
|
+
993,
|
|
20268
|
+
995,
|
|
20269
|
+
1719,
|
|
20270
|
+
1720,
|
|
20271
|
+
1723,
|
|
20272
|
+
2049,
|
|
20273
|
+
3659,
|
|
20274
|
+
4045,
|
|
20275
|
+
5060,
|
|
20276
|
+
5061,
|
|
20277
|
+
6e3,
|
|
20278
|
+
6566,
|
|
20279
|
+
6665,
|
|
20280
|
+
6666,
|
|
20281
|
+
6667,
|
|
20282
|
+
6668,
|
|
20283
|
+
6669,
|
|
20284
|
+
6697,
|
|
20285
|
+
10080
|
|
20286
|
+
]);
|
|
20287
|
+
function isUnsafePort(port) {
|
|
20288
|
+
return unsafePorts.has(port);
|
|
20289
|
+
}
|
|
20290
|
+
function isSafePort(port) {
|
|
20291
|
+
return !isUnsafePort(port);
|
|
20292
|
+
}
|
|
20293
|
+
var GetPortError = class extends Error {
|
|
20294
|
+
constructor(message, opts) {
|
|
20295
|
+
super(message, opts);
|
|
20296
|
+
this.message = message;
|
|
20297
|
+
}
|
|
20298
|
+
name = "GetPortError";
|
|
20299
|
+
};
|
|
20300
|
+
function _log(verbose, message) {
|
|
20301
|
+
if (verbose) console.log(`[get-port] ${message}`);
|
|
20302
|
+
}
|
|
20303
|
+
function _tryPort(port, host) {
|
|
20304
|
+
return new Promise((resolve) => {
|
|
20305
|
+
const server = createServer$1();
|
|
20306
|
+
server.unref();
|
|
20307
|
+
server.on("error", () => {
|
|
20308
|
+
resolve(false);
|
|
20309
|
+
});
|
|
20310
|
+
server.listen({
|
|
20311
|
+
port,
|
|
20312
|
+
host
|
|
20313
|
+
}, () => {
|
|
20314
|
+
const { port: port2 } = server.address();
|
|
20315
|
+
server.close(() => {
|
|
20316
|
+
resolve(isSafePort(port2) && port2);
|
|
20317
|
+
});
|
|
20318
|
+
});
|
|
20319
|
+
});
|
|
20320
|
+
}
|
|
20321
|
+
function _getLocalHosts(additional) {
|
|
20322
|
+
const hosts = new Set(additional);
|
|
20323
|
+
for (const _interface of Object.values(networkInterfaces())) for (const config of _interface || []) if (config.address && !config.internal && !config.address.startsWith("fe80::") && !config.address.startsWith("169.254")) hosts.add(config.address);
|
|
20324
|
+
return [...hosts];
|
|
20325
|
+
}
|
|
20326
|
+
function _fmtOnHost(hostname) {
|
|
20327
|
+
return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
|
|
20328
|
+
}
|
|
20329
|
+
async function getRandomPort(host) {
|
|
20330
|
+
const port = await checkPort(0, host);
|
|
20331
|
+
if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
|
|
20332
|
+
return port;
|
|
20333
|
+
}
|
|
20334
|
+
async function checkPort(port, host = process.env.HOST, verbose) {
|
|
20335
|
+
if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
|
|
20336
|
+
if (!Array.isArray(host)) return _tryPort(port, host);
|
|
20337
|
+
for (const _host of host) {
|
|
20338
|
+
const _port = await _tryPort(port, _host);
|
|
20339
|
+
if (_port === false) {
|
|
20340
|
+
if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
|
|
20341
|
+
return false;
|
|
20342
|
+
}
|
|
20343
|
+
if (port === 0 && _port !== 0) port = _port;
|
|
20344
|
+
}
|
|
20345
|
+
return port;
|
|
20346
|
+
}
|
|
20347
|
+
|
|
20198
20348
|
//#endregion
|
|
20199
20349
|
//#region src/core/options.ts
|
|
20200
|
-
function resolveOptions(options) {
|
|
20350
|
+
async function resolveOptions(options) {
|
|
20351
|
+
let wsPort;
|
|
20352
|
+
if (options.wsPort !== void 0) if (await checkPort(options.wsPort) === false) wsPort = options.wsPort;
|
|
20353
|
+
else wsPort = await getRandomPort();
|
|
20354
|
+
else wsPort = await getRandomPort();
|
|
20355
|
+
const preferredMcpPort = options.mcpPort || 3101;
|
|
20356
|
+
if (await checkPort(preferredMcpPort) === false) throw new Error(`MCP port ${preferredMcpPort} is already in use. Please specify a different port or free up the port.`);
|
|
20201
20357
|
return {
|
|
20202
|
-
wsPort
|
|
20203
|
-
mcpPort:
|
|
20358
|
+
wsPort,
|
|
20359
|
+
mcpPort: preferredMcpPort,
|
|
20204
20360
|
plugins: options.plugins || []
|
|
20205
20361
|
};
|
|
20206
20362
|
}
|
|
20207
20363
|
|
|
20364
|
+
//#endregion
|
|
20365
|
+
//#region src/core/utils.ts
|
|
20366
|
+
/**
|
|
20367
|
+
* npx free-port :port
|
|
20368
|
+
*/
|
|
20369
|
+
async function killPort(port) {
|
|
20370
|
+
return new Promise((resolve, reject) => {
|
|
20371
|
+
exec(`npx -y @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
|
|
20372
|
+
if (err) reject(err);
|
|
20373
|
+
else {
|
|
20374
|
+
console.log(stdout);
|
|
20375
|
+
resolve();
|
|
20376
|
+
}
|
|
20377
|
+
});
|
|
20378
|
+
});
|
|
20379
|
+
}
|
|
20380
|
+
|
|
20208
20381
|
//#endregion
|
|
20209
20382
|
//#region ../../node_modules/.pnpm/birpc@4.0.0/node_modules/birpc/dist/index.mjs
|
|
20210
20383
|
const TYPE_REQUEST = "q";
|
|
@@ -24005,7 +24178,8 @@ function getPluginClientModules(plugins, options) {
|
|
|
24005
24178
|
return typeof p.clientModule === "function" ? p.clientModule(ctx) : p.clientModule;
|
|
24006
24179
|
});
|
|
24007
24180
|
}
|
|
24008
|
-
function generateVirtualClientModule(options) {
|
|
24181
|
+
function generateVirtualClientModule(options, isDev) {
|
|
24182
|
+
if (!isDev) return "";
|
|
24009
24183
|
const pluginModules = getPluginClientModules(options.plugins, options);
|
|
24010
24184
|
const importStatements = pluginModules.map((mod, index) => `import { rpcHandlers as handlers_${index} } from '${mod}';`).join("\n");
|
|
24011
24185
|
const handlerCollection = pluginModules.map((_, index) => ` ...handlers_${index},`).join("\n");
|
|
@@ -24023,22 +24197,29 @@ ${handlerCollection}
|
|
|
24023
24197
|
`;
|
|
24024
24198
|
}
|
|
24025
24199
|
const unpluginDevpilot = createUnplugin((rawOptions = {}) => {
|
|
24026
|
-
|
|
24200
|
+
let options = null;
|
|
24027
24201
|
let serversStarted = false;
|
|
24028
24202
|
const name = "unplugin-devpilot";
|
|
24203
|
+
async function ensureOptionsResolved() {
|
|
24204
|
+
if (!options) options = await resolveOptions(rawOptions);
|
|
24205
|
+
return options;
|
|
24206
|
+
}
|
|
24029
24207
|
async function startServers() {
|
|
24030
24208
|
if (serversStarted) return;
|
|
24031
24209
|
serversStarted = true;
|
|
24032
|
-
|
|
24033
|
-
|
|
24034
|
-
|
|
24035
|
-
|
|
24210
|
+
const resolvedOptions = await ensureOptionsResolved();
|
|
24211
|
+
registerPluginServerMethods(resolvedOptions.plugins);
|
|
24212
|
+
registerPluginMcpRegisterMethods(resolvedOptions.plugins);
|
|
24213
|
+
startWebSocketServer(resolvedOptions.wsPort);
|
|
24214
|
+
await startMcpServer(resolvedOptions.mcpPort);
|
|
24036
24215
|
}
|
|
24037
|
-
function stopServers() {
|
|
24216
|
+
async function stopServers() {
|
|
24038
24217
|
if (!serversStarted) return;
|
|
24218
|
+
const resolvedOptions = await ensureOptionsResolved();
|
|
24039
24219
|
serversStarted = false;
|
|
24040
24220
|
stopWebSocketServer();
|
|
24041
24221
|
stopMcpServer();
|
|
24222
|
+
await killPort(resolvedOptions.mcpPort);
|
|
24042
24223
|
}
|
|
24043
24224
|
return {
|
|
24044
24225
|
name,
|
|
@@ -24049,17 +24230,18 @@ const unpluginDevpilot = createUnplugin((rawOptions = {}) => {
|
|
|
24049
24230
|
loadInclude(id) {
|
|
24050
24231
|
return id === RESOLVED_VIRTUAL_MODULE_ID;
|
|
24051
24232
|
},
|
|
24052
|
-
load(id) {
|
|
24053
|
-
if (id === RESOLVED_VIRTUAL_MODULE_ID) return generateVirtualClientModule(
|
|
24233
|
+
async load(id) {
|
|
24234
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) return generateVirtualClientModule(await ensureOptionsResolved(), process$1.env.NODE_ENV !== "production");
|
|
24054
24235
|
},
|
|
24055
24236
|
buildStart() {
|
|
24056
|
-
|
|
24237
|
+
if (process$1.env.NODE_ENV === "production") return;
|
|
24238
|
+
return startServers();
|
|
24057
24239
|
},
|
|
24058
24240
|
buildEnd() {
|
|
24059
24241
|
stopServers();
|
|
24060
24242
|
},
|
|
24061
24243
|
vite: { configureServer() {
|
|
24062
|
-
startServers();
|
|
24244
|
+
return startServers();
|
|
24063
24245
|
} },
|
|
24064
24246
|
webpack(compiler) {
|
|
24065
24247
|
compiler.hooks.watchRun.tapPromise(name, async () => {
|
package/dist/vite.mjs
CHANGED
package/dist/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-devpilot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "Description.",
|
|
6
6
|
"author": "zcf0508 <zcf0508@live.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@types/ws": "^8.18.1",
|
|
61
61
|
"birpc": "^4.0.0",
|
|
62
62
|
"es-toolkit": "^1.44.0",
|
|
63
|
+
"get-port-please": "^3.2.0",
|
|
63
64
|
"hookable": "^6.0.1",
|
|
64
65
|
"mitt": "^3.0.1",
|
|
65
66
|
"ws": "^8.19.0",
|