@agent-smith/server 0.0.5 → 0.0.6

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.
@@ -4,7 +4,8 @@ function getAgentsRoute(r) {
4
4
  const agents = db.readFeaturesType("agent");
5
5
  ctx.body = agents;
6
6
  ctx.status = 200;
7
- await next();
7
+ //console.log("AGENTS", ctx.status);
8
+ //await next()
8
9
  });
9
10
  }
10
11
  function getAgentRoute(r) {
@@ -13,7 +14,7 @@ function getAgentRoute(r) {
13
14
  const taskSpec = fs.openTaskSpec(ctx.params.id, true);
14
15
  ctx.body = taskSpec.taskFileSpec;
15
16
  ctx.status = 200;
16
- await next();
17
+ //await next()
17
18
  });
18
19
  }
19
20
  export { getAgentRoute, getAgentsRoute, };
@@ -11,7 +11,6 @@ function getConfRoute(r) {
11
11
  ctx.body = conf;
12
12
  ctx.status = 200;
13
13
  }
14
- await next();
15
14
  });
16
15
  }
17
16
  function createConfRoute(r) {
@@ -30,7 +29,6 @@ function createConfRoute(r) {
30
29
  ctx.status = 201;
31
30
  await updateConfCmd([cfp]);
32
31
  }
33
- await next();
34
32
  });
35
33
  }
36
34
  export { createConfRoute, getConfRoute };
@@ -22,7 +22,6 @@ function addFolderRoute(r) {
22
22
  console.log("Updating db features from config file");
23
23
  await updateConfCmd([path]);
24
24
  ctx.status = 202;
25
- await next();
26
25
  });
27
26
  }
28
27
  export { addFolderRoute, };
@@ -8,7 +8,6 @@ function getModelsCmd(r) {
8
8
  catch (e) {
9
9
  ctx.body = "error reading the models";
10
10
  ctx.status = 502;
11
- await next();
12
11
  return;
13
12
  }
14
13
  const ms = {};
@@ -32,7 +31,6 @@ function getModelsCmd(r) {
32
31
  });
33
32
  ctx.body = ms;
34
33
  ctx.status = 200;
35
- await next();
36
34
  });
37
35
  }
38
36
  export { getModelsCmd, };
@@ -28,7 +28,6 @@ function installPluginRoute(r) {
28
28
  console.log("Updating db features from config file");
29
29
  await updateConfCmd([path]);
30
30
  ctx.status = 202;
31
- await next();
32
31
  });
33
32
  }
34
33
  export { installPluginRoute, };
@@ -2,9 +2,10 @@ import { getConfigPath, init } from '@agent-smith/cli';
2
2
  import fs from "node:fs";
3
3
  function getStateRoute(r) {
4
4
  r.get('/state', async (ctx, next) => {
5
- console.log("STATE ROUTE");
5
+ //console.log('STATE URL --> ' + ctx.request.url);
6
+ //console.log("STATE ROUTE");
6
7
  const { confDir, dbPath } = getConfigPath("agent-smith", "config.db");
7
- console.log("conf paths", confDir, dbPath);
8
+ //console.log("conf paths", confDir, dbPath);
8
9
  if (!fs.existsSync(dbPath)) {
9
10
  ctx.body = "no db found at " + dbPath;
10
11
  ctx.status = 202;
@@ -13,7 +14,8 @@ function getStateRoute(r) {
13
14
  ctx.status = 200;
14
15
  await init();
15
16
  }
16
- await next();
17
+ //console.log("STATE", ctx.status)
18
+ //return next()
17
19
  });
18
20
  }
19
21
  export { getStateRoute, };
@@ -4,7 +4,6 @@ function getTaskSettingsCmd(r) {
4
4
  const ts = db.getTaskSettings();
5
5
  ctx.body = ts;
6
6
  ctx.status = 200;
7
- await next();
8
7
  });
9
8
  }
10
9
  function updateTaskSettingsCmd(r) {
@@ -17,7 +16,6 @@ function updateTaskSettingsCmd(r) {
17
16
  db.getTaskSettings(true);
18
17
  ctx.body = ts;
19
18
  ctx.status = 200;
20
- await next();
21
19
  });
22
20
  }
23
21
  export { getTaskSettingsCmd, updateTaskSettingsCmd, };
@@ -4,7 +4,6 @@ function getTasksRoute(r) {
4
4
  const tasks = db.readFeaturesType("task");
5
5
  ctx.body = tasks;
6
6
  ctx.status = 200;
7
- await next();
8
7
  });
9
8
  }
10
9
  function getTaskRoute(r) {
@@ -13,7 +12,6 @@ function getTaskRoute(r) {
13
12
  const taskSpec = fs.openTaskSpec(ctx.params.id);
14
13
  ctx.body = taskSpec.taskFileSpec;
15
14
  ctx.status = 200;
16
- await next();
17
15
  });
18
16
  }
19
17
  function saveTasksRoute(r) {
@@ -21,7 +19,6 @@ function saveTasksRoute(r) {
21
19
  //const payload = ctx.request.body;
22
20
  ctx.body = "ok";
23
21
  ctx.status = 200;
24
- await next();
25
22
  });
26
23
  }
27
24
  export { getTasksRoute, getTaskRoute, };
@@ -24,7 +24,6 @@ function getToolsRoute(r) {
24
24
  ctx.body = tools;
25
25
  ctx.status = 200;
26
26
  }
27
- await next();
28
27
  });
29
28
  }
30
29
  export { getToolsRoute, };
@@ -21,17 +21,18 @@ if (argv.length > 2) {
21
21
  }*/
22
22
  const logger = async (ctx, next) => {
23
23
  const start = Date.now();
24
+ //console.log('LOGGER BEFORE URL --> ' + ctx.request.url);
24
25
  await next();
25
26
  const duration = Date.now() - start;
26
27
  console.log(`${ctx.method} ${ctx.url} - ${ctx.status} - ${duration}ms`);
28
+ //console.log('LOGGER AFTER URL --> ' + ctx.request.url);
27
29
  };
28
30
  const app = websockify(new Koa());
29
31
  app.use(bodyParser());
30
- app.use(logger);
31
32
  app.use(cors({
32
33
  credentials: true
33
34
  }));
34
- app.ws.use(function (ctx, next) {
35
+ app.ws.use((ctx, next) => {
35
36
  return next();
36
37
  });
37
38
  function createAwaiter() {
@@ -48,9 +49,6 @@ function createAwaiter() {
48
49
  };
49
50
  }
50
51
  function runserver(routes, staticDir) {
51
- if (staticDir) {
52
- app.use(serve(staticDir));
53
- }
54
52
  const router = useRouter(routes);
55
53
  const sendTokensInterval = 100;
56
54
  const confirmToolCalls = {};
@@ -326,17 +324,22 @@ function runserver(routes, staticDir) {
326
324
  abort = new AbortController();
327
325
  });
328
326
  }));
327
+ if (staticDir) {
328
+ app.use(serve(staticDir));
329
+ }
330
+ app.use(logger);
329
331
  app.use(router.routes()).use(router.allowedMethods());
330
332
  // 404 middleware - runs after router
331
- /*app.use((ctx) => {
332
- if (!ctx.matched || ctx.matched.length === 0) {
333
- ctx.status = 404;
334
- ctx.body = {
335
- error: 'Not Found',
336
- path: ctx.path
337
- };
338
- }
339
- });*/
333
+ app.use((ctx) => {
334
+ if (!ctx.matched || ctx.matched.length === 0) {
335
+ ctx.status = 404;
336
+ //console.log("404 ROUTE", ctx);
337
+ ctx.body = {
338
+ error: 'Not Found',
339
+ path: ctx.path
340
+ };
341
+ }
342
+ });
340
343
  app.listen(5184, () => {
341
344
  console.log('Please open url localhost:5184 in a browser');
342
345
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-smith/server",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Agent Smith Nodejs server",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",