vite-plugin-opencode-assistant 1.0.13 → 1.0.15
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/es/client/index.js +384 -86
- package/es/core/api.d.ts +1 -0
- package/es/core/api.js +97 -15
- package/es/core/proxy-server.d.ts +5 -1
- package/es/core/proxy-server.js +75 -69
- package/es/core/service.d.ts +8 -1
- package/es/core/service.js +128 -28
- package/es/endpoints/index.js +2 -0
- package/es/endpoints/sse.js +14 -5
- package/es/endpoints/types.d.ts +7 -1
- package/es/endpoints/warmup.d.ts +3 -0
- package/es/endpoints/warmup.js +45 -0
- package/es/index.js +12 -3
- package/es/utils/system.d.ts +2 -1
- package/es/utils/system.js +11 -10
- package/lib/client/index.js +380 -85
- package/lib/client.js +2880 -2619
- package/lib/core/api.d.ts +1 -0
- package/lib/core/api.js +97 -15
- package/lib/core/proxy-server.d.ts +5 -1
- package/lib/core/proxy-server.js +75 -69
- package/lib/core/service.d.ts +8 -1
- package/lib/core/service.js +127 -28
- package/lib/endpoints/index.js +2 -0
- package/lib/endpoints/sse.js +14 -5
- package/lib/endpoints/types.d.ts +7 -1
- package/lib/endpoints/warmup.d.ts +3 -0
- package/lib/endpoints/warmup.js +68 -0
- package/lib/index.js +12 -3
- package/lib/style.css +1 -1
- package/lib/utils/system.d.ts +2 -1
- package/lib/utils/system.js +10 -5
- package/package.json +5 -5
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { createLogger } from "@vite-plugin-opencode-assistant/shared";
|
|
22
|
+
const log = createLogger("Endpoints:Warmup");
|
|
23
|
+
function setupWarmupEndpoint(server, ctx) {
|
|
24
|
+
server.middlewares.use("/__opencode_warmup__", (req, res) => __async(null, null, function* () {
|
|
25
|
+
if (req.method !== "POST") {
|
|
26
|
+
res.writeHead(405);
|
|
27
|
+
res.end("Method not allowed");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const success = yield ctx.retryWarmupChromeMcp();
|
|
32
|
+
res.setHeader("Content-Type", "application/json");
|
|
33
|
+
res.writeHead(200);
|
|
34
|
+
res.end(JSON.stringify({ success }));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
log.error("Failed to retry warmup", { error: e });
|
|
37
|
+
res.setHeader("Content-Type", "application/json");
|
|
38
|
+
res.writeHead(500);
|
|
39
|
+
res.end(JSON.stringify({ success: false, error: String(e) }));
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
setupWarmupEndpoint
|
|
45
|
+
};
|
package/es/index.js
CHANGED
|
@@ -90,6 +90,8 @@ function createOpenCodePlugin(options = {}) {
|
|
|
90
90
|
return __async(this, null, function* () {
|
|
91
91
|
var _a2, _b2;
|
|
92
92
|
const timer = log.timer("configureServer");
|
|
93
|
+
let viteOrigin = "";
|
|
94
|
+
const getViteOrigin = () => viteOrigin;
|
|
93
95
|
setupMiddlewares(server, {
|
|
94
96
|
get sessionUrl() {
|
|
95
97
|
return service.sessionUrl;
|
|
@@ -106,11 +108,18 @@ function createOpenCodePlugin(options = {}) {
|
|
|
106
108
|
set pageContext(ctx) {
|
|
107
109
|
pageContext = ctx;
|
|
108
110
|
},
|
|
111
|
+
get isServiceStarted() {
|
|
112
|
+
return service.isStarted;
|
|
113
|
+
},
|
|
114
|
+
get currentTask() {
|
|
115
|
+
return service.currentTask;
|
|
116
|
+
},
|
|
109
117
|
getSessions: () => api.getSessions(),
|
|
110
118
|
createSession: () => api.createSession(),
|
|
111
119
|
deleteSession: (id) => api.deleteSession(id),
|
|
112
120
|
resolveWidgetPath,
|
|
113
|
-
resolveWidgetStylePath
|
|
121
|
+
resolveWidgetStylePath,
|
|
122
|
+
retryWarmupChromeMcp: () => service.retryWarmupChromeMcp(getViteOrigin())
|
|
114
123
|
});
|
|
115
124
|
(_a2 = server.httpServer) == null ? void 0 : _a2.on("listening", () => __async(null, null, function* () {
|
|
116
125
|
var _a3;
|
|
@@ -131,7 +140,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
131
140
|
vitePort = server.config.server.port || 5173;
|
|
132
141
|
viteHost = typeof host === "string" && host !== "0.0.0.0" && host !== "::" && host !== "::1" ? host : "localhost";
|
|
133
142
|
}
|
|
134
|
-
|
|
143
|
+
viteOrigin = `http://${viteHost}:${vitePort}`;
|
|
135
144
|
const contextApiUrl = `http://${viteHost}:${vitePort}${CONTEXT_API_PATH}`;
|
|
136
145
|
log.debug("Vite server ready", {
|
|
137
146
|
vitePort,
|
|
@@ -170,7 +179,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
170
179
|
open: config.open,
|
|
171
180
|
autoReload: config.autoReload,
|
|
172
181
|
cwd: process.cwd(),
|
|
173
|
-
|
|
182
|
+
// 不再注入 sessionUrl,客户端完全依赖 SSE 状态同步
|
|
174
183
|
hotkey: config.hotkey
|
|
175
184
|
});
|
|
176
185
|
timer.end();
|
package/es/utils/system.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ResultPromise } from "execa";
|
|
2
|
+
export declare function waitForServer(url: string, timeout?: number, process?: ResultPromise): Promise<void>;
|
|
2
3
|
export declare function checkOpenCodeInstalled(): Promise<boolean>;
|
|
3
4
|
export declare function isPortAvailable(port: number, hostname?: string): Promise<boolean>;
|
|
4
5
|
export declare function findAvailablePort(startPort: number, hostname?: string, maxTries?: number): Promise<number>;
|
package/es/utils/system.js
CHANGED
|
@@ -21,14 +21,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
21
21
|
import { spawn } from "child_process";
|
|
22
22
|
import http from "http";
|
|
23
23
|
import net from "net";
|
|
24
|
-
import {
|
|
25
|
-
DEFAULT_HOSTNAME,
|
|
26
|
-
MAX_PORT_TRIES,
|
|
27
|
-
SERVER_CHECK_INTERVAL
|
|
28
|
-
} from "@vite-plugin-opencode-assistant/shared";
|
|
24
|
+
import { MAX_PORT_TRIES, SERVER_CHECK_INTERVAL } from "@vite-plugin-opencode-assistant/shared";
|
|
29
25
|
import { PerformanceTimer, createLogger } from "@vite-plugin-opencode-assistant/shared";
|
|
30
26
|
const log = createLogger("Utils");
|
|
31
|
-
function waitForServer(url, timeout = 1e4) {
|
|
27
|
+
function waitForServer(url, timeout = 1e4, process2) {
|
|
32
28
|
const timer = new PerformanceTimer("waitForServer", { url, timeout });
|
|
33
29
|
return new Promise((resolve, reject) => {
|
|
34
30
|
const startTime = Date.now();
|
|
@@ -36,6 +32,11 @@ function waitForServer(url, timeout = 1e4) {
|
|
|
36
32
|
const check = () => {
|
|
37
33
|
attempts++;
|
|
38
34
|
log.debug(`Checking server availability (attempt ${attempts})`, { url });
|
|
35
|
+
if ((process2 == null ? void 0 : process2.exitCode) !== null && (process2 == null ? void 0 : process2.exitCode) !== void 0) {
|
|
36
|
+
timer.end(`\u274C Process exited with code ${process2.exitCode}`);
|
|
37
|
+
reject(new Error(`Process exited with code ${process2.exitCode}`));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
39
40
|
const req = http.get(url, (res) => {
|
|
40
41
|
if (res.statusCode && res.statusCode < 500) {
|
|
41
42
|
timer.end(`\u2713 Server ready after ${attempts} attempts`);
|
|
@@ -81,8 +82,8 @@ function checkOpenCodeInstalled() {
|
|
|
81
82
|
});
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
function isPortAvailable(
|
|
85
|
-
return __async(this,
|
|
85
|
+
function isPortAvailable(port, hostname) {
|
|
86
|
+
return __async(this, null, function* () {
|
|
86
87
|
return new Promise((resolve) => {
|
|
87
88
|
const server = net.createServer();
|
|
88
89
|
server.once("error", (err) => {
|
|
@@ -98,8 +99,8 @@ function isPortAvailable(_0) {
|
|
|
98
99
|
});
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
|
-
function findAvailablePort(_0) {
|
|
102
|
-
return __async(this, arguments, function* (startPort, hostname
|
|
102
|
+
function findAvailablePort(_0, _1) {
|
|
103
|
+
return __async(this, arguments, function* (startPort, hostname, maxTries = MAX_PORT_TRIES) {
|
|
103
104
|
const timer = log.timer("findAvailablePort", { startPort, hostname, maxTries });
|
|
104
105
|
log.debug(`Looking for available port starting from ${startPort}`);
|
|
105
106
|
for (let port = startPort; port < startPort + maxTries; port++) {
|