@agent-smith/server 0.0.3 → 0.0.5
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/routes/conf.js +6 -20
- package/dist/routes/folders.d.ts +3 -0
- package/dist/routes/folders.js +28 -0
- package/dist/routes/index.js +3 -1
- package/dist/routes/plugins.d.ts +3 -0
- package/dist/routes/plugins.js +34 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +18 -0
- package/package.json +3 -3
package/dist/routes/conf.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
import { createConfigFile,
|
|
1
|
+
import { createConfigFile, updateConfCmd } from '@agent-smith/cli';
|
|
2
|
+
import { getConfig } from '../utils.js';
|
|
2
3
|
function getConfRoute(r) {
|
|
3
4
|
r.get('/conf', async (ctx, next) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
//let promptFilePath = "";
|
|
7
|
-
for (const p of fp) {
|
|
8
|
-
if (p.name == "conf") {
|
|
9
|
-
confFilePath = p.path;
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (confFilePath == "") {
|
|
5
|
+
const { found, conf } = getConfig();
|
|
6
|
+
if (!found) {
|
|
14
7
|
ctx.body = "can not find config path in db";
|
|
15
8
|
ctx.status = 400;
|
|
16
9
|
}
|
|
17
10
|
else {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ctx.status = 400;
|
|
21
|
-
ctx.body = "config file not found at " + confFilePath;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
ctx.body = data;
|
|
25
|
-
ctx.status = 200;
|
|
26
|
-
}
|
|
11
|
+
ctx.body = conf;
|
|
12
|
+
ctx.status = 200;
|
|
27
13
|
}
|
|
28
14
|
await next();
|
|
29
15
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { updateConfCmd, updateConfigFile, init } from '@agent-smith/cli';
|
|
2
|
+
import { getConfig } from '../utils.js';
|
|
3
|
+
function addFolderRoute(r) {
|
|
4
|
+
r.post('/folders/add', async (ctx, next) => {
|
|
5
|
+
const payload = ctx.request.body;
|
|
6
|
+
await init();
|
|
7
|
+
const { found, conf, path } = getConfig();
|
|
8
|
+
if (!found) {
|
|
9
|
+
throw new Error("no config file found");
|
|
10
|
+
}
|
|
11
|
+
;
|
|
12
|
+
if (!conf?.features) {
|
|
13
|
+
conf.features = [];
|
|
14
|
+
}
|
|
15
|
+
for (const p of payload) {
|
|
16
|
+
conf.features.push(p);
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
console.log("Updating config file at", path);
|
|
20
|
+
console.dir(conf, { depth: 3 });
|
|
21
|
+
updateConfigFile(conf, path);
|
|
22
|
+
console.log("Updating db features from config file");
|
|
23
|
+
await updateConfCmd([path]);
|
|
24
|
+
ctx.status = 202;
|
|
25
|
+
await next();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export { addFolderRoute, };
|
package/dist/routes/index.js
CHANGED
|
@@ -5,5 +5,7 @@ import { getAgentRoute, getAgentsRoute } from "./agents.js";
|
|
|
5
5
|
import { createConfRoute, getConfRoute } from "./conf.js";
|
|
6
6
|
import { getToolsRoute } from "./tools.js";
|
|
7
7
|
import { getStateRoute } from "./state.js";
|
|
8
|
-
|
|
8
|
+
import { installPluginRoute } from "./plugins.js";
|
|
9
|
+
import { addFolderRoute } from "./folders.js";
|
|
10
|
+
const baseRoutes = new Array(getConfRoute, getTasksRoute, getTaskRoute, getAgentRoute, getAgentsRoute, getModelsCmd, getToolsRoute, getTaskSettingsCmd, getStateRoute, createConfRoute, updateTaskSettingsCmd, installPluginRoute, addFolderRoute);
|
|
9
11
|
export { baseRoutes };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { execute, updateConfCmd, updateConfigFile, init } from '@agent-smith/cli';
|
|
2
|
+
import { getConfig } from '../utils.js';
|
|
3
|
+
function installPluginRoute(r) {
|
|
4
|
+
r.post('/plugins/install', async (ctx, next) => {
|
|
5
|
+
const payload = ctx.request.body;
|
|
6
|
+
console.log("P", payload);
|
|
7
|
+
for (const p of payload) {
|
|
8
|
+
console.log("Installing", p, "plugin");
|
|
9
|
+
const res = await execute("npm", ["i", "-g", p]);
|
|
10
|
+
console.log(p, res);
|
|
11
|
+
}
|
|
12
|
+
await init();
|
|
13
|
+
const { found, conf, path } = getConfig();
|
|
14
|
+
if (!found) {
|
|
15
|
+
throw new Error("no config file found");
|
|
16
|
+
}
|
|
17
|
+
;
|
|
18
|
+
if (!conf?.plugins) {
|
|
19
|
+
conf.plugins = [];
|
|
20
|
+
}
|
|
21
|
+
for (const p of payload) {
|
|
22
|
+
conf.plugins?.push(p);
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
console.log("Updating config file at", path);
|
|
26
|
+
console.dir(conf, { depth: 3 });
|
|
27
|
+
updateConfigFile(conf, path);
|
|
28
|
+
console.log("Updating db features from config file");
|
|
29
|
+
await updateConfCmd([path]);
|
|
30
|
+
ctx.status = 202;
|
|
31
|
+
await next();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export { installPluginRoute, };
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { db, readConf } from "@agent-smith/cli";
|
|
2
|
+
function getConfig() {
|
|
3
|
+
const fp = db.readFilePaths();
|
|
4
|
+
let confFilePath = "";
|
|
5
|
+
//let promptFilePath = "";
|
|
6
|
+
for (const p of fp) {
|
|
7
|
+
if (p.name == "conf") {
|
|
8
|
+
confFilePath = p.path;
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (confFilePath == "") {
|
|
13
|
+
return { found: false, conf: {}, path: "" };
|
|
14
|
+
}
|
|
15
|
+
const c = readConf(confFilePath);
|
|
16
|
+
return { found: c.found, conf: c.data, path: confFilePath };
|
|
17
|
+
}
|
|
18
|
+
export { getConfig, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-smith/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Agent Smith Nodejs server",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/cli": "^0.0.
|
|
13
|
+
"@agent-smith/cli": "^0.0.114",
|
|
14
14
|
"@koa/cors": "^5.0.0",
|
|
15
15
|
"@koa/router": "^15.3.0",
|
|
16
16
|
"ansi-colors": "^4.1.3",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@types/koa-route": "^3.2.9",
|
|
31
31
|
"@types/koa-static": "^4.0.4",
|
|
32
32
|
"@types/koa-websocket": "^5.0.11",
|
|
33
|
-
"@types/node": "^25.3.
|
|
33
|
+
"@types/node": "^25.3.2",
|
|
34
34
|
"ts-node": "^10.9.2",
|
|
35
35
|
"tslib": "2.8.1",
|
|
36
36
|
"typescript": "^5.9.3"
|