@kevisual/cli 0.0.94 → 0.0.95
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/assistant-opencode.js +188 -27
- package/dist/assistant-server.js +188 -27
- package/dist/assistant.js +6 -2
- package/dist/envision.js +2 -2
- package/package.json +1 -1
|
@@ -58805,6 +58805,8 @@ var initConfig = (configRootPath) => {
|
|
|
58805
58805
|
const pageConfigPath = path.join(configDir2, "assistant-page-config.json");
|
|
58806
58806
|
const pagesDir = createDir(path.join(configDir2, "pages"));
|
|
58807
58807
|
const appsDir = createDir(path.join(configDir2, "apps"));
|
|
58808
|
+
const skillsDir = createDir(path.join(configDir2, "skills"), false);
|
|
58809
|
+
const pluginsDir = createDir(path.join(configDir2, "plugins"), false);
|
|
58808
58810
|
const appsConfigPath = path.join(configDir2, "assistant-apps-config.json");
|
|
58809
58811
|
const appPidPath = path.join(configDir2, "assistant-app.pid");
|
|
58810
58812
|
const envConfigPath = path.join(configDir2, ".env");
|
|
@@ -58816,7 +58818,9 @@ var initConfig = (configRootPath) => {
|
|
|
58816
58818
|
pagesDir,
|
|
58817
58819
|
pageConfigPath,
|
|
58818
58820
|
appPidPath,
|
|
58819
|
-
envConfigPath
|
|
58821
|
+
envConfigPath,
|
|
58822
|
+
skillsDir,
|
|
58823
|
+
pluginsDir
|
|
58820
58824
|
};
|
|
58821
58825
|
};
|
|
58822
58826
|
var assistantConfig;
|
|
@@ -68674,7 +68678,7 @@ import path6 from "node:path";
|
|
|
68674
68678
|
import fs9 from "node:fs";
|
|
68675
68679
|
|
|
68676
68680
|
// src/module/light-code/run.ts
|
|
68677
|
-
import { fork as fork3 } from "child_process";
|
|
68681
|
+
import { fork as fork3 } from "node:child_process";
|
|
68678
68682
|
import fs7 from "fs";
|
|
68679
68683
|
var fileExists = (path6) => {
|
|
68680
68684
|
try {
|
|
@@ -109702,13 +109706,13 @@ async function getPorts(options) {
|
|
|
109702
109706
|
// src/routes/opencode/module/open.ts
|
|
109703
109707
|
import os5 from "node:os";
|
|
109704
109708
|
import { execSync } from "node:child_process";
|
|
109709
|
+
var DEFAULT_PORT = 5000;
|
|
109705
109710
|
|
|
109706
109711
|
class OpencodeManager {
|
|
109707
109712
|
static instance = null;
|
|
109708
109713
|
client = null;
|
|
109709
109714
|
server = null;
|
|
109710
109715
|
isInitializing = false;
|
|
109711
|
-
currentPort = null;
|
|
109712
109716
|
url = "";
|
|
109713
109717
|
constructor() {}
|
|
109714
109718
|
static getInstance() {
|
|
@@ -109717,17 +109721,17 @@ class OpencodeManager {
|
|
|
109717
109721
|
}
|
|
109718
109722
|
return OpencodeManager.instance;
|
|
109719
109723
|
}
|
|
109720
|
-
async getClient() {
|
|
109724
|
+
async getClient(opts) {
|
|
109725
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
109721
109726
|
if (this.client) {
|
|
109722
109727
|
return this.client;
|
|
109723
109728
|
}
|
|
109724
109729
|
if (this.isInitializing) {
|
|
109725
109730
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
109726
|
-
return this.getClient();
|
|
109731
|
+
return this.getClient(opts);
|
|
109727
109732
|
}
|
|
109728
109733
|
this.isInitializing = true;
|
|
109729
109734
|
try {
|
|
109730
|
-
const port = 5000;
|
|
109731
109735
|
const currentPort = await getPorts({ port });
|
|
109732
109736
|
if (port === currentPort) {
|
|
109733
109737
|
const result = await createOpencode({
|
|
@@ -109783,13 +109787,13 @@ class OpencodeManager {
|
|
|
109783
109787
|
console.error("Failed to close OpenCode server:", error4);
|
|
109784
109788
|
}
|
|
109785
109789
|
}
|
|
109786
|
-
async close() {
|
|
109790
|
+
async close(opts) {
|
|
109787
109791
|
if (this.server) {
|
|
109788
109792
|
this.server.close();
|
|
109789
109793
|
this.server = null;
|
|
109790
109794
|
return;
|
|
109791
109795
|
}
|
|
109792
|
-
const port =
|
|
109796
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
109793
109797
|
const currentPort = await getPorts({ port });
|
|
109794
109798
|
if (port === currentPort) {
|
|
109795
109799
|
this.client = null;
|
|
@@ -109799,14 +109803,20 @@ class OpencodeManager {
|
|
|
109799
109803
|
}
|
|
109800
109804
|
this.client = null;
|
|
109801
109805
|
}
|
|
109802
|
-
async getUrl() {
|
|
109806
|
+
async getUrl(opts) {
|
|
109807
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
109803
109808
|
if (this.url) {
|
|
109804
109809
|
return this.url;
|
|
109805
109810
|
}
|
|
109806
109811
|
if (!this.url) {
|
|
109807
|
-
await this.getClient();
|
|
109812
|
+
await this.getClient(opts);
|
|
109808
109813
|
}
|
|
109809
|
-
return
|
|
109814
|
+
return `http://localhost:${port}`;
|
|
109815
|
+
}
|
|
109816
|
+
async restart(opts) {
|
|
109817
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
109818
|
+
await this.close({ port });
|
|
109819
|
+
return await this.getClient({ port });
|
|
109810
109820
|
}
|
|
109811
109821
|
}
|
|
109812
109822
|
var opencodeManager = OpencodeManager.getInstance();
|
|
@@ -109823,11 +109833,13 @@ app.route({
|
|
|
109823
109833
|
skill: "create-opencode-client",
|
|
109824
109834
|
title: "创建 OpenCode 客户端",
|
|
109825
109835
|
summary: "创建 OpenCode 客户端,如果存在则复用",
|
|
109826
|
-
args: {
|
|
109836
|
+
args: {
|
|
109837
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
109838
|
+
}
|
|
109827
109839
|
})
|
|
109828
109840
|
}
|
|
109829
109841
|
}).define(async (ctx) => {
|
|
109830
|
-
const client3 = await opencodeManager.getClient();
|
|
109842
|
+
const client3 = await opencodeManager.getClient({ port: ctx.query.port });
|
|
109831
109843
|
ctx.body = { content: `${opencodeManager.url} OpenCode 客户端已就绪` };
|
|
109832
109844
|
}).addTo(app);
|
|
109833
109845
|
app.route({
|
|
@@ -109840,14 +109852,38 @@ app.route({
|
|
|
109840
109852
|
...createSkill({
|
|
109841
109853
|
skill: "close-opencode-client",
|
|
109842
109854
|
title: "关闭 OpenCode 客户端",
|
|
109843
|
-
summary: "关闭 OpenCode
|
|
109844
|
-
args: {
|
|
109855
|
+
summary: "关闭 OpenCode 客户端, 未提供端口则关闭默认端口",
|
|
109856
|
+
args: {
|
|
109857
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
109858
|
+
}
|
|
109845
109859
|
})
|
|
109846
109860
|
}
|
|
109847
109861
|
}).define(async (ctx) => {
|
|
109848
|
-
|
|
109862
|
+
const port = ctx.query.port;
|
|
109863
|
+
await opencodeManager.close({ port });
|
|
109849
109864
|
ctx.body = { content: "OpenCode 客户端已关闭" };
|
|
109850
109865
|
}).addTo(app);
|
|
109866
|
+
app.route({
|
|
109867
|
+
path: "opencode",
|
|
109868
|
+
key: "restart",
|
|
109869
|
+
middleware: ["auth"],
|
|
109870
|
+
description: "重启 OpenCode 客户端",
|
|
109871
|
+
metadata: {
|
|
109872
|
+
tags: ["opencode"],
|
|
109873
|
+
...createSkill({
|
|
109874
|
+
skill: "restart-opencode-client",
|
|
109875
|
+
title: "重启 OpenCode 客户端",
|
|
109876
|
+
summary: "重启 OpenCode 客户端",
|
|
109877
|
+
args: {
|
|
109878
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
109879
|
+
}
|
|
109880
|
+
})
|
|
109881
|
+
}
|
|
109882
|
+
}).define(async (ctx) => {
|
|
109883
|
+
const port = ctx.query.port;
|
|
109884
|
+
const res = await opencodeManager.restart({ port });
|
|
109885
|
+
ctx.body = { content: `${opencodeManager.url} OpenCode 客户端已经重启` };
|
|
109886
|
+
}).addTo(app);
|
|
109851
109887
|
app.route({
|
|
109852
109888
|
path: "opencode",
|
|
109853
109889
|
key: "getUrl",
|
|
@@ -109859,11 +109895,13 @@ app.route({
|
|
|
109859
109895
|
skill: "get-opencode-url",
|
|
109860
109896
|
title: "获取 OpenCode 服务 URL",
|
|
109861
109897
|
summary: "获取当前 OpenCode 服务的 URL 地址",
|
|
109862
|
-
args: {
|
|
109898
|
+
args: {
|
|
109899
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
109900
|
+
}
|
|
109863
109901
|
})
|
|
109864
109902
|
}
|
|
109865
109903
|
}).define(async (ctx) => {
|
|
109866
|
-
const url4 = await opencodeManager.getUrl();
|
|
109904
|
+
const url4 = await opencodeManager.getUrl({ port: ctx.query.port });
|
|
109867
109905
|
const cnbURL = useKey("CNB_VSCODE_PROXY_URI");
|
|
109868
109906
|
let content = `本地访问地址: ${url4}`;
|
|
109869
109907
|
if (cnbURL) {
|
|
@@ -110516,6 +110554,126 @@ app.route({
|
|
|
110516
110554
|
});
|
|
110517
110555
|
}).addTo(app);
|
|
110518
110556
|
|
|
110557
|
+
// src/module/cmd/run.ts
|
|
110558
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
110559
|
+
var runCmd = (opts) => {
|
|
110560
|
+
const { cmd, cwd } = opts || {};
|
|
110561
|
+
return new Promise((resolve) => {
|
|
110562
|
+
const parts = cmd.split(" ");
|
|
110563
|
+
const command = parts[0];
|
|
110564
|
+
const args = parts.slice(1);
|
|
110565
|
+
const proc = spawn5(command, args, {
|
|
110566
|
+
cwd: cwd || process.cwd(),
|
|
110567
|
+
shell: true,
|
|
110568
|
+
env: { ...process.env, ...opts?.env }
|
|
110569
|
+
});
|
|
110570
|
+
let stdout = "";
|
|
110571
|
+
let stderr = "";
|
|
110572
|
+
let result = "";
|
|
110573
|
+
proc.stdout.on("data", (data) => {
|
|
110574
|
+
stdout += data.toString();
|
|
110575
|
+
});
|
|
110576
|
+
proc.stderr.on("data", (data) => {
|
|
110577
|
+
stderr += data.toString();
|
|
110578
|
+
});
|
|
110579
|
+
proc.on("close", (code2) => {
|
|
110580
|
+
result = stdout;
|
|
110581
|
+
if (stderr) {
|
|
110582
|
+
result += `
|
|
110583
|
+
` + stderr;
|
|
110584
|
+
}
|
|
110585
|
+
resolve({ code: code2 === 0 ? 200 : code2, data: result });
|
|
110586
|
+
});
|
|
110587
|
+
proc.on("error", (err) => {
|
|
110588
|
+
resolve({ code: 500, data: err.message });
|
|
110589
|
+
});
|
|
110590
|
+
});
|
|
110591
|
+
};
|
|
110592
|
+
|
|
110593
|
+
// src/routes/kevisual/auth.ts
|
|
110594
|
+
app.route({
|
|
110595
|
+
path: "kevisual",
|
|
110596
|
+
key: " me",
|
|
110597
|
+
description: "查看 ev cli 是否登录",
|
|
110598
|
+
middleware: ["admin-auth"],
|
|
110599
|
+
metadata: {
|
|
110600
|
+
tags: ["opencode"],
|
|
110601
|
+
...createSkill({
|
|
110602
|
+
skill: "kevisual-me",
|
|
110603
|
+
title: "查看 ev cli 是否登录",
|
|
110604
|
+
summary: "查看 ev cli 是否登录",
|
|
110605
|
+
args: {}
|
|
110606
|
+
})
|
|
110607
|
+
}
|
|
110608
|
+
}).define(async (ctx) => {
|
|
110609
|
+
const cmd = "ev me";
|
|
110610
|
+
const res = await runCmd({ cmd });
|
|
110611
|
+
if (res.code === 200) {
|
|
110612
|
+
ctx.body = { content: res.data };
|
|
110613
|
+
} else {
|
|
110614
|
+
ctx.throw(500, res.data);
|
|
110615
|
+
}
|
|
110616
|
+
}).addTo(app);
|
|
110617
|
+
app.route({
|
|
110618
|
+
path: "kevisual",
|
|
110619
|
+
key: "loginByAdmin",
|
|
110620
|
+
description: "通过当前登录用户 ev cli",
|
|
110621
|
+
middleware: ["admin-auth"],
|
|
110622
|
+
metadata: {
|
|
110623
|
+
tags: ["opencode"],
|
|
110624
|
+
...createSkill({
|
|
110625
|
+
skill: "kevisual-login-by-admin",
|
|
110626
|
+
title: "通过当前登录用户 ev cli",
|
|
110627
|
+
summary: "通过当前登录用户登录 ev cli, 直接用当前的用户的 token 直接设置 token 给 ev cli, 登录失败直接停止任务",
|
|
110628
|
+
args: {}
|
|
110629
|
+
})
|
|
110630
|
+
}
|
|
110631
|
+
}).define(async (ctx) => {
|
|
110632
|
+
const token = ctx.query?.token || useKey("KEVISUAL_TOKEN");
|
|
110633
|
+
if (!token) {
|
|
110634
|
+
ctx.throw(400, "登录的 token 不能为空,请传入 token 参数");
|
|
110635
|
+
return;
|
|
110636
|
+
}
|
|
110637
|
+
const cmd = `ev login -e `;
|
|
110638
|
+
const res = await runCmd({
|
|
110639
|
+
cmd,
|
|
110640
|
+
env: {
|
|
110641
|
+
KEVISUAL_TOKEN: token
|
|
110642
|
+
}
|
|
110643
|
+
});
|
|
110644
|
+
if (res.code === 200) {
|
|
110645
|
+
ctx.body = { content: res.data };
|
|
110646
|
+
} else {
|
|
110647
|
+
ctx.throw(500, res.data);
|
|
110648
|
+
}
|
|
110649
|
+
}).addTo(app);
|
|
110650
|
+
|
|
110651
|
+
// src/routes/kevisual/deploy.ts
|
|
110652
|
+
app.route({
|
|
110653
|
+
path: "kevisual",
|
|
110654
|
+
key: "deploy",
|
|
110655
|
+
description: "部署一个网页",
|
|
110656
|
+
middleware: ["admin-auth"],
|
|
110657
|
+
metadata: {
|
|
110658
|
+
tags: ["kevisual"],
|
|
110659
|
+
...createSkill({
|
|
110660
|
+
skill: "kevisual-deploy",
|
|
110661
|
+
title: "部署一个网页",
|
|
110662
|
+
summary: "部署一个网页到 kevisual 平台",
|
|
110663
|
+
args: {
|
|
110664
|
+
filepath: tool.schema.string().describe("要部署的网页文件路径"),
|
|
110665
|
+
appKey: tool.schema.string().optional().describe("应用的 appKey,如果不传则创建一个新的应用"),
|
|
110666
|
+
version: tool.schema.string().optional().describe("应用的版本号,默认为 1.0.0"),
|
|
110667
|
+
update: tool.schema.boolean().optional().describe("是否同时更新部署,默认为 false")
|
|
110668
|
+
}
|
|
110669
|
+
})
|
|
110670
|
+
}
|
|
110671
|
+
}).define(async (ctx) => {
|
|
110672
|
+
const { filepath, appKey, update } = ctx.query;
|
|
110673
|
+
console.log("部署网页,filepath:", filepath, "appKey:", appKey);
|
|
110674
|
+
ctx.body = { content: "部署功能正在开发中,敬请期待!" };
|
|
110675
|
+
}).addTo(app);
|
|
110676
|
+
|
|
110519
110677
|
// src/routes/index.ts
|
|
110520
110678
|
import os6 from "node:os";
|
|
110521
110679
|
|
|
@@ -111717,17 +111875,15 @@ var checkAuth = async (ctx, isAdmin = false) => {
|
|
|
111717
111875
|
}
|
|
111718
111876
|
authCache.set(token, tokenUser);
|
|
111719
111877
|
}
|
|
111720
|
-
|
|
111721
|
-
ctx.state
|
|
111722
|
-
|
|
111723
|
-
|
|
111724
|
-
|
|
111725
|
-
};
|
|
111726
|
-
}
|
|
111878
|
+
ctx.state = {
|
|
111879
|
+
...ctx.state,
|
|
111880
|
+
token,
|
|
111881
|
+
tokenUser
|
|
111882
|
+
};
|
|
111727
111883
|
const { username } = tokenUser;
|
|
111728
111884
|
if (!auth.username) {
|
|
111729
111885
|
auth.username = username;
|
|
111730
|
-
assistantConfig2.setConfig({ auth });
|
|
111886
|
+
assistantConfig2.setConfig({ auth, token });
|
|
111731
111887
|
}
|
|
111732
111888
|
if (isAdmin && auth.username) {
|
|
111733
111889
|
const admins = config4.auth?.admin || [];
|
|
@@ -111735,6 +111891,12 @@ var checkAuth = async (ctx, isAdmin = false) => {
|
|
|
111735
111891
|
const admin = auth.username;
|
|
111736
111892
|
if (admin === username) {
|
|
111737
111893
|
isCheckAdmin = true;
|
|
111894
|
+
const _token = config4.token;
|
|
111895
|
+
if (!_token) {
|
|
111896
|
+
assistantConfig2.setConfig({ token });
|
|
111897
|
+
} else if (_token && _token.startsWith("st-") && _token !== token) {
|
|
111898
|
+
assistantConfig2.setConfig({ token });
|
|
111899
|
+
}
|
|
111738
111900
|
}
|
|
111739
111901
|
if (!isCheckAdmin && admins.length > 0 && admins.includes(username)) {
|
|
111740
111902
|
isCheckAdmin = true;
|
|
@@ -111769,7 +111931,6 @@ app.route({
|
|
|
111769
111931
|
id: "admin-auth",
|
|
111770
111932
|
description: "管理员鉴权, 获取用户信息,并验证是否为管理员。"
|
|
111771
111933
|
}).define(async (ctx) => {
|
|
111772
|
-
logger.debug("query", ctx.query);
|
|
111773
111934
|
if (!ctx.query?.token && ctx.appId === app.appId) {
|
|
111774
111935
|
return;
|
|
111775
111936
|
}
|
package/dist/assistant-server.js
CHANGED
|
@@ -100480,6 +100480,8 @@ var initConfig = (configRootPath) => {
|
|
|
100480
100480
|
const pageConfigPath = path.join(configDir2, "assistant-page-config.json");
|
|
100481
100481
|
const pagesDir = createDir(path.join(configDir2, "pages"));
|
|
100482
100482
|
const appsDir = createDir(path.join(configDir2, "apps"));
|
|
100483
|
+
const skillsDir = createDir(path.join(configDir2, "skills"), false);
|
|
100484
|
+
const pluginsDir = createDir(path.join(configDir2, "plugins"), false);
|
|
100483
100485
|
const appsConfigPath = path.join(configDir2, "assistant-apps-config.json");
|
|
100484
100486
|
const appPidPath = path.join(configDir2, "assistant-app.pid");
|
|
100485
100487
|
const envConfigPath = path.join(configDir2, ".env");
|
|
@@ -100491,7 +100493,9 @@ var initConfig = (configRootPath) => {
|
|
|
100491
100493
|
pagesDir,
|
|
100492
100494
|
pageConfigPath,
|
|
100493
100495
|
appPidPath,
|
|
100494
|
-
envConfigPath
|
|
100496
|
+
envConfigPath,
|
|
100497
|
+
skillsDir,
|
|
100498
|
+
pluginsDir
|
|
100495
100499
|
};
|
|
100496
100500
|
};
|
|
100497
100501
|
var assistantConfig;
|
|
@@ -111075,7 +111079,7 @@ import path9 from "node:path";
|
|
|
111075
111079
|
import fs11 from "node:fs";
|
|
111076
111080
|
|
|
111077
111081
|
// src/module/light-code/run.ts
|
|
111078
|
-
import { fork as fork3 } from "child_process";
|
|
111082
|
+
import { fork as fork3 } from "node:child_process";
|
|
111079
111083
|
import fs9 from "fs";
|
|
111080
111084
|
var fileExists = (path9) => {
|
|
111081
111085
|
try {
|
|
@@ -137633,13 +137637,13 @@ function portNumbers(from3, to) {
|
|
|
137633
137637
|
// src/routes/opencode/module/open.ts
|
|
137634
137638
|
import os5 from "node:os";
|
|
137635
137639
|
import { execSync } from "node:child_process";
|
|
137640
|
+
var DEFAULT_PORT = 5000;
|
|
137636
137641
|
|
|
137637
137642
|
class OpencodeManager {
|
|
137638
137643
|
static instance = null;
|
|
137639
137644
|
client = null;
|
|
137640
137645
|
server = null;
|
|
137641
137646
|
isInitializing = false;
|
|
137642
|
-
currentPort = null;
|
|
137643
137647
|
url = "";
|
|
137644
137648
|
constructor() {}
|
|
137645
137649
|
static getInstance() {
|
|
@@ -137648,17 +137652,17 @@ class OpencodeManager {
|
|
|
137648
137652
|
}
|
|
137649
137653
|
return OpencodeManager.instance;
|
|
137650
137654
|
}
|
|
137651
|
-
async getClient() {
|
|
137655
|
+
async getClient(opts) {
|
|
137656
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
137652
137657
|
if (this.client) {
|
|
137653
137658
|
return this.client;
|
|
137654
137659
|
}
|
|
137655
137660
|
if (this.isInitializing) {
|
|
137656
137661
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
137657
|
-
return this.getClient();
|
|
137662
|
+
return this.getClient(opts);
|
|
137658
137663
|
}
|
|
137659
137664
|
this.isInitializing = true;
|
|
137660
137665
|
try {
|
|
137661
|
-
const port = 5000;
|
|
137662
137666
|
const currentPort = await getPorts({ port });
|
|
137663
137667
|
if (port === currentPort) {
|
|
137664
137668
|
const result = await createOpencode({
|
|
@@ -137714,13 +137718,13 @@ class OpencodeManager {
|
|
|
137714
137718
|
console.error("Failed to close OpenCode server:", error3);
|
|
137715
137719
|
}
|
|
137716
137720
|
}
|
|
137717
|
-
async close() {
|
|
137721
|
+
async close(opts) {
|
|
137718
137722
|
if (this.server) {
|
|
137719
137723
|
this.server.close();
|
|
137720
137724
|
this.server = null;
|
|
137721
137725
|
return;
|
|
137722
137726
|
}
|
|
137723
|
-
const port =
|
|
137727
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
137724
137728
|
const currentPort = await getPorts({ port });
|
|
137725
137729
|
if (port === currentPort) {
|
|
137726
137730
|
this.client = null;
|
|
@@ -137730,14 +137734,20 @@ class OpencodeManager {
|
|
|
137730
137734
|
}
|
|
137731
137735
|
this.client = null;
|
|
137732
137736
|
}
|
|
137733
|
-
async getUrl() {
|
|
137737
|
+
async getUrl(opts) {
|
|
137738
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
137734
137739
|
if (this.url) {
|
|
137735
137740
|
return this.url;
|
|
137736
137741
|
}
|
|
137737
137742
|
if (!this.url) {
|
|
137738
|
-
await this.getClient();
|
|
137743
|
+
await this.getClient(opts);
|
|
137739
137744
|
}
|
|
137740
|
-
return
|
|
137745
|
+
return `http://localhost:${port}`;
|
|
137746
|
+
}
|
|
137747
|
+
async restart(opts) {
|
|
137748
|
+
const port = opts?.port ?? DEFAULT_PORT;
|
|
137749
|
+
await this.close({ port });
|
|
137750
|
+
return await this.getClient({ port });
|
|
137741
137751
|
}
|
|
137742
137752
|
}
|
|
137743
137753
|
var opencodeManager = OpencodeManager.getInstance();
|
|
@@ -137754,11 +137764,13 @@ app.route({
|
|
|
137754
137764
|
skill: "create-opencode-client",
|
|
137755
137765
|
title: "创建 OpenCode 客户端",
|
|
137756
137766
|
summary: "创建 OpenCode 客户端,如果存在则复用",
|
|
137757
|
-
args: {
|
|
137767
|
+
args: {
|
|
137768
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
137769
|
+
}
|
|
137758
137770
|
})
|
|
137759
137771
|
}
|
|
137760
137772
|
}).define(async (ctx) => {
|
|
137761
|
-
const client3 = await opencodeManager.getClient();
|
|
137773
|
+
const client3 = await opencodeManager.getClient({ port: ctx.query.port });
|
|
137762
137774
|
ctx.body = { content: `${opencodeManager.url} OpenCode 客户端已就绪` };
|
|
137763
137775
|
}).addTo(app);
|
|
137764
137776
|
app.route({
|
|
@@ -137771,14 +137783,38 @@ app.route({
|
|
|
137771
137783
|
...createSkill({
|
|
137772
137784
|
skill: "close-opencode-client",
|
|
137773
137785
|
title: "关闭 OpenCode 客户端",
|
|
137774
|
-
summary: "关闭 OpenCode
|
|
137775
|
-
args: {
|
|
137786
|
+
summary: "关闭 OpenCode 客户端, 未提供端口则关闭默认端口",
|
|
137787
|
+
args: {
|
|
137788
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
137789
|
+
}
|
|
137776
137790
|
})
|
|
137777
137791
|
}
|
|
137778
137792
|
}).define(async (ctx) => {
|
|
137779
|
-
|
|
137793
|
+
const port = ctx.query.port;
|
|
137794
|
+
await opencodeManager.close({ port });
|
|
137780
137795
|
ctx.body = { content: "OpenCode 客户端已关闭" };
|
|
137781
137796
|
}).addTo(app);
|
|
137797
|
+
app.route({
|
|
137798
|
+
path: "opencode",
|
|
137799
|
+
key: "restart",
|
|
137800
|
+
middleware: ["auth"],
|
|
137801
|
+
description: "重启 OpenCode 客户端",
|
|
137802
|
+
metadata: {
|
|
137803
|
+
tags: ["opencode"],
|
|
137804
|
+
...createSkill({
|
|
137805
|
+
skill: "restart-opencode-client",
|
|
137806
|
+
title: "重启 OpenCode 客户端",
|
|
137807
|
+
summary: "重启 OpenCode 客户端",
|
|
137808
|
+
args: {
|
|
137809
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
137810
|
+
}
|
|
137811
|
+
})
|
|
137812
|
+
}
|
|
137813
|
+
}).define(async (ctx) => {
|
|
137814
|
+
const port = ctx.query.port;
|
|
137815
|
+
const res = await opencodeManager.restart({ port });
|
|
137816
|
+
ctx.body = { content: `${opencodeManager.url} OpenCode 客户端已经重启` };
|
|
137817
|
+
}).addTo(app);
|
|
137782
137818
|
app.route({
|
|
137783
137819
|
path: "opencode",
|
|
137784
137820
|
key: "getUrl",
|
|
@@ -137790,11 +137826,13 @@ app.route({
|
|
|
137790
137826
|
skill: "get-opencode-url",
|
|
137791
137827
|
title: "获取 OpenCode 服务 URL",
|
|
137792
137828
|
summary: "获取当前 OpenCode 服务的 URL 地址",
|
|
137793
|
-
args: {
|
|
137829
|
+
args: {
|
|
137830
|
+
port: tool.schema.number().optional().describe("OpenCode 服务端口,默认为 5000")
|
|
137831
|
+
}
|
|
137794
137832
|
})
|
|
137795
137833
|
}
|
|
137796
137834
|
}).define(async (ctx) => {
|
|
137797
|
-
const url3 = await opencodeManager.getUrl();
|
|
137835
|
+
const url3 = await opencodeManager.getUrl({ port: ctx.query.port });
|
|
137798
137836
|
const cnbURL = useKey("CNB_VSCODE_PROXY_URI");
|
|
137799
137837
|
let content = `本地访问地址: ${url3}`;
|
|
137800
137838
|
if (cnbURL) {
|
|
@@ -137896,6 +137934,126 @@ app.route({
|
|
|
137896
137934
|
});
|
|
137897
137935
|
}).addTo(app);
|
|
137898
137936
|
|
|
137937
|
+
// src/module/cmd/run.ts
|
|
137938
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
137939
|
+
var runCmd = (opts) => {
|
|
137940
|
+
const { cmd, cwd } = opts || {};
|
|
137941
|
+
return new Promise((resolve) => {
|
|
137942
|
+
const parts = cmd.split(" ");
|
|
137943
|
+
const command = parts[0];
|
|
137944
|
+
const args = parts.slice(1);
|
|
137945
|
+
const proc = spawn5(command, args, {
|
|
137946
|
+
cwd: cwd || process.cwd(),
|
|
137947
|
+
shell: true,
|
|
137948
|
+
env: { ...process.env, ...opts?.env }
|
|
137949
|
+
});
|
|
137950
|
+
let stdout = "";
|
|
137951
|
+
let stderr = "";
|
|
137952
|
+
let result = "";
|
|
137953
|
+
proc.stdout.on("data", (data) => {
|
|
137954
|
+
stdout += data.toString();
|
|
137955
|
+
});
|
|
137956
|
+
proc.stderr.on("data", (data) => {
|
|
137957
|
+
stderr += data.toString();
|
|
137958
|
+
});
|
|
137959
|
+
proc.on("close", (code2) => {
|
|
137960
|
+
result = stdout;
|
|
137961
|
+
if (stderr) {
|
|
137962
|
+
result += `
|
|
137963
|
+
` + stderr;
|
|
137964
|
+
}
|
|
137965
|
+
resolve({ code: code2 === 0 ? 200 : code2, data: result });
|
|
137966
|
+
});
|
|
137967
|
+
proc.on("error", (err) => {
|
|
137968
|
+
resolve({ code: 500, data: err.message });
|
|
137969
|
+
});
|
|
137970
|
+
});
|
|
137971
|
+
};
|
|
137972
|
+
|
|
137973
|
+
// src/routes/kevisual/auth.ts
|
|
137974
|
+
app.route({
|
|
137975
|
+
path: "kevisual",
|
|
137976
|
+
key: " me",
|
|
137977
|
+
description: "查看 ev cli 是否登录",
|
|
137978
|
+
middleware: ["admin-auth"],
|
|
137979
|
+
metadata: {
|
|
137980
|
+
tags: ["opencode"],
|
|
137981
|
+
...createSkill({
|
|
137982
|
+
skill: "kevisual-me",
|
|
137983
|
+
title: "查看 ev cli 是否登录",
|
|
137984
|
+
summary: "查看 ev cli 是否登录",
|
|
137985
|
+
args: {}
|
|
137986
|
+
})
|
|
137987
|
+
}
|
|
137988
|
+
}).define(async (ctx) => {
|
|
137989
|
+
const cmd = "ev me";
|
|
137990
|
+
const res = await runCmd({ cmd });
|
|
137991
|
+
if (res.code === 200) {
|
|
137992
|
+
ctx.body = { content: res.data };
|
|
137993
|
+
} else {
|
|
137994
|
+
ctx.throw(500, res.data);
|
|
137995
|
+
}
|
|
137996
|
+
}).addTo(app);
|
|
137997
|
+
app.route({
|
|
137998
|
+
path: "kevisual",
|
|
137999
|
+
key: "loginByAdmin",
|
|
138000
|
+
description: "通过当前登录用户 ev cli",
|
|
138001
|
+
middleware: ["admin-auth"],
|
|
138002
|
+
metadata: {
|
|
138003
|
+
tags: ["opencode"],
|
|
138004
|
+
...createSkill({
|
|
138005
|
+
skill: "kevisual-login-by-admin",
|
|
138006
|
+
title: "通过当前登录用户 ev cli",
|
|
138007
|
+
summary: "通过当前登录用户登录 ev cli, 直接用当前的用户的 token 直接设置 token 给 ev cli, 登录失败直接停止任务",
|
|
138008
|
+
args: {}
|
|
138009
|
+
})
|
|
138010
|
+
}
|
|
138011
|
+
}).define(async (ctx) => {
|
|
138012
|
+
const token = ctx.query?.token || useKey("KEVISUAL_TOKEN");
|
|
138013
|
+
if (!token) {
|
|
138014
|
+
ctx.throw(400, "登录的 token 不能为空,请传入 token 参数");
|
|
138015
|
+
return;
|
|
138016
|
+
}
|
|
138017
|
+
const cmd = `ev login -e `;
|
|
138018
|
+
const res = await runCmd({
|
|
138019
|
+
cmd,
|
|
138020
|
+
env: {
|
|
138021
|
+
KEVISUAL_TOKEN: token
|
|
138022
|
+
}
|
|
138023
|
+
});
|
|
138024
|
+
if (res.code === 200) {
|
|
138025
|
+
ctx.body = { content: res.data };
|
|
138026
|
+
} else {
|
|
138027
|
+
ctx.throw(500, res.data);
|
|
138028
|
+
}
|
|
138029
|
+
}).addTo(app);
|
|
138030
|
+
|
|
138031
|
+
// src/routes/kevisual/deploy.ts
|
|
138032
|
+
app.route({
|
|
138033
|
+
path: "kevisual",
|
|
138034
|
+
key: "deploy",
|
|
138035
|
+
description: "部署一个网页",
|
|
138036
|
+
middleware: ["admin-auth"],
|
|
138037
|
+
metadata: {
|
|
138038
|
+
tags: ["kevisual"],
|
|
138039
|
+
...createSkill({
|
|
138040
|
+
skill: "kevisual-deploy",
|
|
138041
|
+
title: "部署一个网页",
|
|
138042
|
+
summary: "部署一个网页到 kevisual 平台",
|
|
138043
|
+
args: {
|
|
138044
|
+
filepath: tool.schema.string().describe("要部署的网页文件路径"),
|
|
138045
|
+
appKey: tool.schema.string().optional().describe("应用的 appKey,如果不传则创建一个新的应用"),
|
|
138046
|
+
version: tool.schema.string().optional().describe("应用的版本号,默认为 1.0.0"),
|
|
138047
|
+
update: tool.schema.boolean().optional().describe("是否同时更新部署,默认为 false")
|
|
138048
|
+
}
|
|
138049
|
+
})
|
|
138050
|
+
}
|
|
138051
|
+
}).define(async (ctx) => {
|
|
138052
|
+
const { filepath, appKey, update } = ctx.query;
|
|
138053
|
+
console.log("部署网页,filepath:", filepath, "appKey:", appKey);
|
|
138054
|
+
ctx.body = { content: "部署功能正在开发中,敬请期待!" };
|
|
138055
|
+
}).addTo(app);
|
|
138056
|
+
|
|
137899
138057
|
// src/routes/index.ts
|
|
137900
138058
|
import os6 from "node:os";
|
|
137901
138059
|
|
|
@@ -139111,17 +139269,15 @@ var checkAuth = async (ctx, isAdmin = false) => {
|
|
|
139111
139269
|
}
|
|
139112
139270
|
authCache.set(token, tokenUser);
|
|
139113
139271
|
}
|
|
139114
|
-
|
|
139115
|
-
ctx.state
|
|
139116
|
-
|
|
139117
|
-
|
|
139118
|
-
|
|
139119
|
-
};
|
|
139120
|
-
}
|
|
139272
|
+
ctx.state = {
|
|
139273
|
+
...ctx.state,
|
|
139274
|
+
token,
|
|
139275
|
+
tokenUser
|
|
139276
|
+
};
|
|
139121
139277
|
const { username } = tokenUser;
|
|
139122
139278
|
if (!auth.username) {
|
|
139123
139279
|
auth.username = username;
|
|
139124
|
-
assistantConfig2.setConfig({ auth });
|
|
139280
|
+
assistantConfig2.setConfig({ auth, token });
|
|
139125
139281
|
}
|
|
139126
139282
|
if (isAdmin && auth.username) {
|
|
139127
139283
|
const admins = config3.auth?.admin || [];
|
|
@@ -139129,6 +139285,12 @@ var checkAuth = async (ctx, isAdmin = false) => {
|
|
|
139129
139285
|
const admin = auth.username;
|
|
139130
139286
|
if (admin === username) {
|
|
139131
139287
|
isCheckAdmin = true;
|
|
139288
|
+
const _token = config3.token;
|
|
139289
|
+
if (!_token) {
|
|
139290
|
+
assistantConfig2.setConfig({ token });
|
|
139291
|
+
} else if (_token && _token.startsWith("st-") && _token !== token) {
|
|
139292
|
+
assistantConfig2.setConfig({ token });
|
|
139293
|
+
}
|
|
139132
139294
|
}
|
|
139133
139295
|
if (!isCheckAdmin && admins.length > 0 && admins.includes(username)) {
|
|
139134
139296
|
isCheckAdmin = true;
|
|
@@ -139163,7 +139325,6 @@ app.route({
|
|
|
139163
139325
|
id: "admin-auth",
|
|
139164
139326
|
description: "管理员鉴权, 获取用户信息,并验证是否为管理员。"
|
|
139165
139327
|
}).define(async (ctx) => {
|
|
139166
|
-
logger.debug("query", ctx.query);
|
|
139167
139328
|
if (!ctx.query?.token && ctx.appId === app.appId) {
|
|
139168
139329
|
return;
|
|
139169
139330
|
}
|
package/dist/assistant.js
CHANGED
|
@@ -44057,6 +44057,8 @@ var initConfig = (configRootPath) => {
|
|
|
44057
44057
|
const pageConfigPath = path.join(configDir2, "assistant-page-config.json");
|
|
44058
44058
|
const pagesDir = createDir(path.join(configDir2, "pages"));
|
|
44059
44059
|
const appsDir = createDir(path.join(configDir2, "apps"));
|
|
44060
|
+
const skillsDir = createDir(path.join(configDir2, "skills"), false);
|
|
44061
|
+
const pluginsDir = createDir(path.join(configDir2, "plugins"), false);
|
|
44060
44062
|
const appsConfigPath = path.join(configDir2, "assistant-apps-config.json");
|
|
44061
44063
|
const appPidPath = path.join(configDir2, "assistant-app.pid");
|
|
44062
44064
|
const envConfigPath = path.join(configDir2, ".env");
|
|
@@ -44068,7 +44070,9 @@ var initConfig = (configRootPath) => {
|
|
|
44068
44070
|
pagesDir,
|
|
44069
44071
|
pageConfigPath,
|
|
44070
44072
|
appPidPath,
|
|
44071
|
-
envConfigPath
|
|
44073
|
+
envConfigPath,
|
|
44074
|
+
skillsDir,
|
|
44075
|
+
pluginsDir
|
|
44072
44076
|
};
|
|
44073
44077
|
};
|
|
44074
44078
|
var assistantConfig;
|
|
@@ -63926,7 +63930,7 @@ import path6 from "node:path";
|
|
|
63926
63930
|
import fs9 from "node:fs";
|
|
63927
63931
|
|
|
63928
63932
|
// src/module/light-code/run.ts
|
|
63929
|
-
import { fork as fork3 } from "child_process";
|
|
63933
|
+
import { fork as fork3 } from "node:child_process";
|
|
63930
63934
|
import fs7 from "fs";
|
|
63931
63935
|
var fileExists = (path6) => {
|
|
63932
63936
|
try {
|
package/dist/envision.js
CHANGED
|
@@ -22327,8 +22327,8 @@ InitEnv.init();
|
|
|
22327
22327
|
var version = useContextKey("version", () => {
|
|
22328
22328
|
let version2 = "0.0.64";
|
|
22329
22329
|
try {
|
|
22330
|
-
if ("0.0.
|
|
22331
|
-
version2 = "0.0.
|
|
22330
|
+
if ("0.0.95")
|
|
22331
|
+
version2 = "0.0.95";
|
|
22332
22332
|
} catch (e) {}
|
|
22333
22333
|
return version2;
|
|
22334
22334
|
});
|