@agent-smith/server 0.0.6 → 0.0.7

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.
@@ -0,0 +1,4 @@
1
+ import type Router from "@koa/router";
2
+ declare function getOrCreateAppConfigFileRoute(r: Router): void;
3
+ declare function updateAppConfigFileRoute(r: Router): void;
4
+ export { getOrCreateAppConfigFileRoute, updateAppConfigFileRoute, };
@@ -0,0 +1,40 @@
1
+ import { getConfigPath } from "@agent-smith/cli";
2
+ import fs, { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import yaml from "yaml";
5
+ function getOrCreateAppConfigFile(appName) {
6
+ const { confDir } = getConfigPath("agent-smith/" + appName, "config.db");
7
+ if (!fs.existsSync(confDir)) {
8
+ fs.mkdirSync(confDir);
9
+ }
10
+ const fp = path.join(confDir, "config.yml");
11
+ let fc = "";
12
+ if (!existsSync(fp)) {
13
+ fs.writeFileSync(fp, "");
14
+ return {};
15
+ }
16
+ else {
17
+ fc = fs.readFileSync(fp, { encoding: "utf-8" });
18
+ return yaml.parse(fc);
19
+ }
20
+ }
21
+ function updateAppConfigFile(appName, content) {
22
+ const { confDir } = getConfigPath("agent-smith/" + appName, "config.db");
23
+ const fp = path.join(confDir, "config.yml");
24
+ const txt = yaml.stringify(content);
25
+ fs.writeFileSync(fp, txt, { encoding: "utf-8" });
26
+ }
27
+ function getOrCreateAppConfigFileRoute(r) {
28
+ r.get('/app/:name/conf', async (ctx, next) => {
29
+ ctx.body = getOrCreateAppConfigFile(ctx.params.name);
30
+ ctx.status = 200;
31
+ });
32
+ }
33
+ function updateAppConfigFileRoute(r) {
34
+ r.post('/app/:name/update', async (ctx, next) => {
35
+ const payload = ctx.request.body;
36
+ updateAppConfigFile(ctx.params.name, payload);
37
+ ctx.status = 200;
38
+ });
39
+ }
40
+ export { getOrCreateAppConfigFileRoute, updateAppConfigFileRoute, };
@@ -0,0 +1,4 @@
1
+ import type Router from '@koa/router';
2
+ declare function getBackendsRoute(r: Router): void;
3
+ declare function setBackendRoute(r: Router): void;
4
+ export { getBackendsRoute, setBackendRoute, };
@@ -0,0 +1,24 @@
1
+ import { db, setBackend } from '@agent-smith/cli';
2
+ function getBackendsRoute(r) {
3
+ r.get('/backends', async (ctx, next) => {
4
+ const backends = db.readBackends();
5
+ ctx.body = backends;
6
+ ctx.status = 200;
7
+ });
8
+ }
9
+ function setBackendRoute(r) {
10
+ r.get('/backend/:name', async (ctx, next) => {
11
+ const name = ctx.params.name;
12
+ console.log("Loading backend", name);
13
+ const ok = await setBackend(name, true);
14
+ if (!ok) {
15
+ ctx.status = 400;
16
+ ctx.body = "backend not found";
17
+ }
18
+ else {
19
+ ctx.body = ok;
20
+ ctx.status = 200;
21
+ }
22
+ });
23
+ }
24
+ export { getBackendsRoute, setBackendRoute, };
@@ -17,7 +17,7 @@ function createConfRoute(r) {
17
17
  r.get('/conf/create', async (ctx, next) => {
18
18
  let cfp = null;
19
19
  try {
20
- cfp = createConfigFile();
20
+ cfp = createConfigFile(undefined, ["llamacpp"]);
21
21
  }
22
22
  catch (e) {
23
23
  console.error("500", e);
@@ -7,5 +7,8 @@ import { getToolsRoute } from "./tools.js";
7
7
  import { getStateRoute } from "./state.js";
8
8
  import { installPluginRoute } from "./plugins.js";
9
9
  import { addFolderRoute } from "./folders.js";
10
- const baseRoutes = new Array(getConfRoute, getTasksRoute, getTaskRoute, getAgentRoute, getAgentsRoute, getModelsCmd, getToolsRoute, getTaskSettingsCmd, getStateRoute, createConfRoute, updateTaskSettingsCmd, installPluginRoute, addFolderRoute);
10
+ import { getWorkflowRoute, getWorkflowsRoute } from "./workflows.js";
11
+ import { getBackendsRoute, setBackendRoute } from "./backends.js";
12
+ import { getOrCreateAppConfigFileRoute, updateAppConfigFileRoute } from "./apps.js";
13
+ const baseRoutes = new Array(getConfRoute, getTasksRoute, getTaskRoute, getAgentRoute, getAgentsRoute, getModelsCmd, getToolsRoute, getTaskSettingsCmd, getStateRoute, createConfRoute, updateTaskSettingsCmd, installPluginRoute, addFolderRoute, getWorkflowRoute, getWorkflowsRoute, getBackendsRoute, setBackendRoute, getOrCreateAppConfigFileRoute, updateAppConfigFileRoute);
11
14
  export { baseRoutes };
@@ -1,5 +1,6 @@
1
1
  import { getConfigPath, init } from '@agent-smith/cli';
2
2
  import fs from "node:fs";
3
+ import { getConfig } from '../utils.js';
3
4
  function getStateRoute(r) {
4
5
  r.get('/state', async (ctx, next) => {
5
6
  //console.log('STATE URL --> ' + ctx.request.url);
@@ -11,8 +12,16 @@ function getStateRoute(r) {
11
12
  ctx.status = 202;
12
13
  }
13
14
  else {
14
- ctx.status = 200;
15
15
  await init();
16
+ const { found, conf } = getConfig();
17
+ if (!found) {
18
+ ctx.body = "can not find config path in db";
19
+ ctx.status = 400;
20
+ }
21
+ else {
22
+ ctx.body = conf;
23
+ ctx.status = 200;
24
+ }
16
25
  }
17
26
  //console.log("STATE", ctx.status)
18
27
  //return next()
@@ -0,0 +1,4 @@
1
+ import type Router from '@koa/router';
2
+ declare function getWorkflowsRoute(r: Router): void;
3
+ declare function getWorkflowRoute(r: Router): void;
4
+ export { getWorkflowRoute, getWorkflowsRoute, };
@@ -0,0 +1,23 @@
1
+ import { db, fs } from '@agent-smith/cli';
2
+ function getWorkflowsRoute(r) {
3
+ r.get('/workflows', async (ctx, next) => {
4
+ const w = db.readFeaturesType("workflow");
5
+ ctx.body = w;
6
+ ctx.status = 200;
7
+ });
8
+ }
9
+ function getWorkflowRoute(r) {
10
+ r.get('/workflow/:id', async (ctx, next) => {
11
+ //console.log(ctx.params.id)
12
+ const { found, workflow } = await fs.readWorkflow(ctx.params.id);
13
+ if (!found) {
14
+ ctx.body = "workflow not found";
15
+ ctx.status = 400;
16
+ }
17
+ else {
18
+ ctx.body = workflow;
19
+ ctx.status = 200;
20
+ }
21
+ });
22
+ }
23
+ export { getWorkflowRoute, getWorkflowsRoute, };
@@ -60,6 +60,7 @@ function runserver(routes, staticDir) {
60
60
  if (!msg?.options) {
61
61
  msg.options = {};
62
62
  }
63
+ msg.options.nocli = true;
63
64
  //console.log("ABO", abort);
64
65
  msg.options.abort = abort;
65
66
  //console.log(msg)
@@ -169,7 +170,7 @@ function runserver(routes, staticDir) {
169
170
  else if (msg.feature == "agent") {
170
171
  msg.options.onToolsTurnStart = (tcs) => {
171
172
  const rsm = {
172
- type: "finalresult",
173
+ type: "toolsturnstart",
173
174
  msg: JSON.stringify(tcs),
174
175
  };
175
176
  ctx.websocket.send(JSON.stringify(rsm));
@@ -233,6 +234,7 @@ function runserver(routes, staticDir) {
233
234
  type: "toolcallend",
234
235
  msg: `${id}<|xtool_call_id|>` + toolResData,
235
236
  };
237
+ //console.log("TOOL CALL END", toolResData);
236
238
  ctx.websocket.send(JSON.stringify(rsm));
237
239
  };
238
240
  msg.options.confirmToolUsage = async (tc) => {
@@ -251,26 +253,28 @@ function runserver(routes, staticDir) {
251
253
  };
252
254
  msg.options.isAgent = true;
253
255
  try {
254
- let buf = "";
256
+ //let buf = "";
255
257
  msg.options.onToken = (t) => {
256
- buf += t;
257
- process.stdout.write(t);
258
- };
259
- const it = setInterval(() => {
260
- if (buf == "") {
261
- return;
262
- }
263
- ;
264
- const rsm = {
258
+ const rsm2 = {
265
259
  type: "token",
266
- msg: buf,
260
+ msg: t,
267
261
  };
268
- ctx.websocket.send(JSON.stringify(rsm));
269
- buf = "";
270
- }, sendTokensInterval);
262
+ ctx.websocket.send(JSON.stringify(rsm2));
263
+ //buf += t;
264
+ process.stdout.write(t);
265
+ };
266
+ /*const it = setInterval(() => {
267
+ if (buf == "") { return };
268
+ const rsm: WsRawServerMsg = {
269
+ type: "token",
270
+ msg: buf,
271
+ }
272
+ ctx.websocket.send(JSON.stringify(rsm));
273
+ buf = "";
274
+ }, sendTokensInterval);*/
271
275
  const res = await executeTask(msg.command, msg.payload, msg.options);
272
276
  //setTimeout(() => {
273
- clearInterval(it);
277
+ //clearInterval(it);
274
278
  //}, sendTokensInterval);
275
279
  const ht = JSON.stringify(res.template.history.pop());
276
280
  //console.log("FINAL MSG", ht)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-smith/server",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Agent Smith Nodejs server",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -10,27 +10,28 @@
10
10
  },
11
11
  "type": "module",
12
12
  "dependencies": {
13
- "@agent-smith/cli": "^0.0.114",
13
+ "@agent-smith/cli": "^0.0.115",
14
14
  "@koa/cors": "^5.0.0",
15
- "@koa/router": "^15.3.0",
15
+ "@koa/router": "^15.4.0",
16
16
  "ansi-colors": "^4.1.3",
17
- "koa": "^3.1.2",
17
+ "koa": "^3.2.0",
18
18
  "koa-bodyparser": "^4.4.1",
19
19
  "koa-route": "^4.0.1",
20
20
  "koa-static": "^5.0.0",
21
- "koa-websocket": "^7.0.0"
21
+ "koa-websocket": "^7.0.0",
22
+ "yaml": "^2.8.3"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@agent-smith/types": "^0.0.3",
25
26
  "@locallm/types": "^0.7.1",
26
27
  "@types/better-sqlite3": "^7.6.13",
27
- "@types/koa": "^3.0.1",
28
+ "@types/koa": "^3.0.2",
28
29
  "@types/koa__cors": "^5.0.1",
29
30
  "@types/koa-bodyparser": "^4.3.13",
30
31
  "@types/koa-route": "^3.2.9",
31
32
  "@types/koa-static": "^4.0.4",
32
33
  "@types/koa-websocket": "^5.0.11",
33
- "@types/node": "^25.3.2",
34
+ "@types/node": "^25.5.0",
34
35
  "ts-node": "^10.9.2",
35
36
  "tslib": "2.8.1",
36
37
  "typescript": "^5.9.3"