@agent-smith/cli 0.0.70 → 0.0.80

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.
Files changed (43) hide show
  1. package/dist/cmd/clicmds/aliases.js +12 -6
  2. package/dist/cmd/clicmds/base.js +13 -6
  3. package/dist/cmd/clicmds/cmds.js +5 -0
  4. package/dist/cmd/cmds.js +0 -20
  5. package/dist/cmd/lib/actions/cmd.d.ts +3 -4
  6. package/dist/cmd/lib/actions/cmd.js +48 -64
  7. package/dist/cmd/lib/actions/read.d.ts +2 -3
  8. package/dist/cmd/lib/actions/read.js +9 -14
  9. package/dist/cmd/lib/adaptaters/cmd.d.ts +1 -1
  10. package/dist/cmd/lib/adaptaters/cmd.js +7 -4
  11. package/dist/cmd/lib/mcp.d.ts +3 -3
  12. package/dist/cmd/lib/options_parsers.js +1 -1
  13. package/dist/cmd/lib/tasks/cmd.d.ts +3 -4
  14. package/dist/cmd/lib/tasks/cmd.js +103 -153
  15. package/dist/cmd/lib/tasks/conf.js +14 -9
  16. package/dist/cmd/lib/tasks/read.d.ts +11 -0
  17. package/dist/cmd/lib/tasks/read.js +93 -0
  18. package/dist/cmd/lib/tools.js +2 -2
  19. package/dist/cmd/lib/utils.js +3 -1
  20. package/dist/cmd/lib/workflows/cmd.js +9 -6
  21. package/dist/cmd/lib/workflows/read.d.ts +3 -4
  22. package/dist/cmd/lib/workflows/read.js +37 -15
  23. package/dist/conf.js +49 -1
  24. package/dist/const.d.ts +3 -0
  25. package/dist/const.js +24 -0
  26. package/dist/db/read.d.ts +4 -3
  27. package/dist/db/read.js +10 -1
  28. package/dist/db/schemas.js +9 -0
  29. package/dist/db/write.d.ts +4 -2
  30. package/dist/db/write.js +38 -2
  31. package/dist/index.js +2 -2
  32. package/dist/interfaces.d.ts +23 -10
  33. package/dist/main.d.ts +3 -3
  34. package/dist/main.js +2 -2
  35. package/dist/state/backends.d.ts +7 -0
  36. package/dist/state/backends.js +128 -0
  37. package/dist/state/state.d.ts +2 -1
  38. package/dist/state/state.js +1 -1
  39. package/dist/utils/perf.js +1 -1
  40. package/dist/utils/user_msgs.js +5 -5
  41. package/package.json +19 -20
  42. package/dist/agent.d.ts +0 -7
  43. package/dist/agent.js +0 -27
@@ -13,12 +13,18 @@ function initCommandsFromAliases(program, aliases, features) {
13
13
  });
14
14
  allOptions.forEach(o => tcmd.addOption(o));
15
15
  if (features.task[alias.name]?.variables) {
16
- features.task[alias.name].variables?.optional.forEach(v => {
17
- tcmd.option(`--${v} <value>`);
18
- });
19
- features.task[alias.name].variables?.required.forEach(v => {
20
- tcmd.requiredOption(`--${v} <value>`);
21
- });
16
+ const rtv = features.task[alias.name].variables?.required;
17
+ if (rtv) {
18
+ for (const name of Object.keys(rtv)) {
19
+ tcmd.option(`--${name} <value>`);
20
+ }
21
+ }
22
+ const otv = features.task[alias.name].variables?.optional;
23
+ if (otv) {
24
+ for (const name of Object.keys(otv)) {
25
+ tcmd.option(`--${name} <value>`);
26
+ }
27
+ }
22
28
  }
23
29
  break;
24
30
  case "action":
@@ -1,5 +1,4 @@
1
1
  import YAML from 'yaml';
2
- import { initAgent, taskBuilder } from "../../agent.js";
3
2
  import { dbPath } from "../../conf.js";
4
3
  import { readFeaturePaths, readFeaturesType } from "../../db/read.js";
5
4
  import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
@@ -11,10 +10,8 @@ import { parseCommandArgs } from "../lib/options_parsers.js";
11
10
  import { deleteFileIfExists } from "../sys/delete_file.js";
12
11
  import { readTask } from "../sys/read_task.js";
13
12
  import { updateConfCmd } from "./update.js";
13
+ import { listBackends, setBackend } from "../../state/backends.js";
14
14
  function initBaseCommands(program) {
15
- program.command("ping")
16
- .description("ping inference servers")
17
- .action(async (...args) => { console.log("Found working inference server(s):", await initAgent()); });
18
15
  program.command("exit")
19
16
  .description("exit the cli")
20
17
  .action(() => process.exit(0));
@@ -36,6 +33,17 @@ function initBaseCommands(program) {
36
33
  const ca = parseCommandArgs(args);
37
34
  await showModelsCmd(ca.args);
38
35
  });
36
+ program.command("backend <name>")
37
+ .description("set the default backend")
38
+ .action(async (...args) => {
39
+ const ca = parseCommandArgs(args);
40
+ await setBackend(ca.args[0]);
41
+ });
42
+ program.command("backends")
43
+ .description("list the available backends")
44
+ .action(async (...args) => {
45
+ await listBackends();
46
+ });
39
47
  program.command("update")
40
48
  .description("update the available features: run this after adding a new feature")
41
49
  .action(async (...args) => {
@@ -88,7 +96,6 @@ async function _readTaskCmd(args) {
88
96
  if (!res.found) {
89
97
  throw new Error(`Task ${args[0]}, ${path} not found`);
90
98
  }
91
- const ts = taskBuilder.readFromYaml(res.ymlTask);
92
- console.log(YAML.stringify(ts));
99
+ console.log(YAML.stringify(res.ymlTask));
93
100
  }
94
101
  export { initBaseCommands };
@@ -1,9 +1,14 @@
1
1
  import { readCmds } from "../sys/read_cmds.js";
2
2
  async function initUserCmds(cmdFeats) {
3
+ const paths = new Set();
3
4
  const cmds = new Array();
4
5
  for (const feat of Object.values(cmdFeats)) {
6
+ if (paths.has(feat.path)) {
7
+ continue;
8
+ }
5
9
  const c = await readCmds(`${feat.path}`);
6
10
  cmds.push(...c);
11
+ paths.add(feat.path);
7
12
  }
8
13
  return cmds;
9
14
  }
package/dist/cmd/cmds.js CHANGED
@@ -1,30 +1,10 @@
1
- import { input } from "@inquirer/prompts";
2
- import { toRaw } from "@vue/reactivity";
3
1
  import { Command } from "commander";
4
- import { brain } from "../agent.js";
5
- import { query } from "../cli.js";
6
2
  import { readAliases, readFeatures } from "../db/read.js";
7
- import { chatInferenceParams } from "../state/chat.js";
8
- import { isChatMode, runMode } from "../state/state.js";
9
3
  import { initCommandsFromAliases } from "./clicmds/aliases.js";
10
4
  import { initBaseCommands } from "./clicmds/base.js";
11
5
  import { initUserCmds } from "./clicmds/cmds.js";
12
6
  const program = new Command();
13
7
  async function chat(program) {
14
- const data = { message: '>', default: "" };
15
- const prompt = await input(data);
16
- if (prompt == "/q") {
17
- isChatMode.value = false;
18
- if (runMode.value == "cmd") {
19
- process.exit(0);
20
- }
21
- else {
22
- await query(program);
23
- }
24
- }
25
- await brain.ex.think(prompt, toRaw(chatInferenceParams));
26
- console.log();
27
- await chat(program);
28
8
  }
29
9
  async function buildCmds() {
30
10
  initBaseCommands(program);
@@ -1,7 +1,6 @@
1
- import { AgentTask } from "@agent-smith/jobs";
2
- import { FeatureType } from "../../../interfaces.js";
1
+ import { FeatureExecutor } from "../../../interfaces.js";
3
2
  declare function executeAction(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean): Promise<any>;
4
3
  declare function executeActionCmd(name: string, aargs: Array<any>, quiet?: boolean): Promise<any>;
5
- declare function systemAction(path: string): AgentTask<FeatureType, Array<string>, any>;
6
- declare function pythonAction(path: string): AgentTask<FeatureType, Array<string>>;
4
+ declare function systemAction(path: string): FeatureExecutor<Array<string>, any>;
5
+ declare function pythonAction(path: string): FeatureExecutor<Array<string>>;
7
6
  export { executeAction, executeActionCmd, systemAction, pythonAction, };
@@ -1,4 +1,3 @@
1
- import { useAgentTask } from "@agent-smith/jobs";
2
1
  import { getFeatureSpec } from '../../../state/features.js';
3
2
  import { readYmlFile } from "../../sys/read_yml_file.js";
4
3
  import { execute } from "../../sys/execute.js";
@@ -10,7 +9,7 @@ import { readClipboard } from "../../sys/clipboard.js";
10
9
  import { processOutput, readPromptFile } from "../utils.js";
11
10
  import { parseCommandArgs } from "../options_parsers.js";
12
11
  async function executeAction(name, payload, options, quiet = false) {
13
- let act;
12
+ let run;
14
13
  const { found, path, ext } = getFeatureSpec(name, "action");
15
14
  if (!found) {
16
15
  throw new Error(`Action ${name} not found at ${path}`);
@@ -18,18 +17,22 @@ async function executeAction(name, payload, options, quiet = false) {
18
17
  switch (ext) {
19
18
  case "js":
20
19
  const mjsa = await import(path);
21
- act = createJsAction(mjsa.action);
20
+ run = createJsAction(mjsa.action);
22
21
  break;
23
22
  case "yml":
24
- act = systemAction(path);
23
+ run = systemAction(path);
25
24
  break;
26
25
  case "py":
27
- act = pythonAction(path);
26
+ run = pythonAction(path);
28
27
  break;
29
28
  default:
30
29
  throw new Error(`Action ext ${ext} not implemented`);
31
30
  }
32
- const res = await act.run(payload, options);
31
+ let _pl = payload;
32
+ if (payload?.args) {
33
+ _pl = payload.args;
34
+ }
35
+ const res = await run(_pl, options);
33
36
  if (!quiet) {
34
37
  if (res) {
35
38
  console.log(res);
@@ -53,71 +56,52 @@ async function executeActionCmd(name, aargs, quiet = false) {
53
56
  return await executeAction(name, params, options, quiet);
54
57
  }
55
58
  function systemAction(path) {
56
- const action = useAgentTask({
57
- id: "system_action",
58
- title: "",
59
- run: async (params) => {
60
- let runArgs = new Array();
61
- if (params?.args) {
62
- runArgs = params.args;
63
- }
64
- else {
65
- try {
66
- runArgs = Object.values(params);
67
- }
68
- catch (e) {
69
- throw new Error(`wrong system action args: ${e}`);
70
- }
71
- }
72
- const actionSpec = readYmlFile(path);
73
- if (!actionSpec.found) {
74
- runtimeError("System action yml file", path, "not found");
75
- }
76
- if (!actionSpec.data?.args) {
77
- actionSpec.data.args = [];
78
- }
79
- const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
80
- return out.trim();
59
+ const run = async (params) => {
60
+ let runArgs = params;
61
+ const actionSpec = readYmlFile(path);
62
+ if (!actionSpec.found) {
63
+ runtimeError("System action yml file", path, "not found");
64
+ }
65
+ if (!actionSpec.data?.args) {
66
+ actionSpec.data.args = [];
81
67
  }
82
- });
83
- return action;
68
+ const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
69
+ return out.trim();
70
+ };
71
+ return run;
84
72
  }
85
73
  function pythonAction(path) {
86
- const action = useAgentTask({
87
- id: "python_action",
88
- title: "",
89
- run: async (params) => {
90
- let runArgs = new Array();
91
- if (params?.args) {
92
- runArgs = params.args;
93
- }
94
- else {
95
- try {
96
- runArgs = Object.values(params);
97
- }
98
- catch (e) {
99
- throw new Error(`wrong python action args: ${e}`);
100
- }
74
+ const run = async (params) => {
75
+ let runArgs = new Array();
76
+ if (params?.args) {
77
+ runArgs = params.args;
78
+ }
79
+ else {
80
+ try {
81
+ runArgs = Object.values(params);
101
82
  }
102
- const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
103
- if (error) {
104
- throw new Error(`python error: ${error}`);
83
+ catch (e) {
84
+ throw new Error(`wrong python action args: ${e}`);
105
85
  }
106
- let txt = data[0];
107
- if (data.length > 1) {
108
- txt = data.join("\n");
86
+ }
87
+ const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
88
+ if (error) {
89
+ throw new Error(`python error: ${error}`);
90
+ }
91
+ let txt = data[0];
92
+ if (data.length > 1) {
93
+ txt = data.join("\n");
94
+ }
95
+ let final = txt;
96
+ if (txt.startsWith("{") || txt.startsWith("[")) {
97
+ try {
98
+ final = JSON.parse(txt);
109
99
  }
110
- let final = txt;
111
- if (txt.startsWith("{") || txt.startsWith("[")) {
112
- try {
113
- final = JSON.parse(txt);
114
- }
115
- catch (e) {
116
- }
100
+ catch (e) {
117
101
  }
118
- return final;
119
102
  }
120
- });
121
- return action;
103
+ return final;
104
+ };
105
+ return run;
122
106
  }
123
107
  export { executeAction, executeActionCmd, systemAction, pythonAction, };
@@ -1,4 +1,3 @@
1
- import { FeatureType } from "../../../interfaces.js";
2
- import { AgentTask } from "@agent-smith/jobs";
3
- declare function createJsAction(action: CallableFunction): AgentTask<FeatureType, any, any>;
1
+ import { FeatureExecutor } from "../../../interfaces.js";
2
+ declare function createJsAction(action: CallableFunction): FeatureExecutor;
4
3
  export { createJsAction };
@@ -1,18 +1,13 @@
1
- import { useAgentTask } from "@agent-smith/jobs";
2
1
  function createJsAction(action) {
3
- const task = useAgentTask({
4
- id: "",
5
- title: "",
6
- run: async (args, options) => {
7
- try {
8
- const res = await action(args, options);
9
- return res;
10
- }
11
- catch (e) {
12
- throw new Error(`executing action:${e}`);
13
- }
2
+ const run = async (args, options) => {
3
+ try {
4
+ const res = await action(args, options);
5
+ return res;
14
6
  }
15
- });
16
- return task;
7
+ catch (e) {
8
+ throw new Error(`executing action:${e}`);
9
+ }
10
+ };
11
+ return run;
17
12
  }
18
13
  export { createJsAction };
@@ -1,2 +1,2 @@
1
- declare function executeAdaptater(name: string, argsOrParams: Record<string, any> | Array<any>, options: Record<string, any>): Promise<any>;
1
+ declare function executeAdaptater(name: string, params: any, options: Record<string, any>): Promise<any>;
2
2
  export { executeAdaptater, };
@@ -1,16 +1,19 @@
1
1
  import { getFeatureSpec } from "../../../state/features.js";
2
2
  import { createJsAction } from "../actions/read.js";
3
- async function executeAdaptater(name, argsOrParams, options) {
3
+ async function executeAdaptater(name, params, options) {
4
+ if (params?.args) {
5
+ params = params.args;
6
+ }
4
7
  const { found, path } = getFeatureSpec(name, "adaptater");
5
8
  if (!found) {
6
9
  throw new Error(`adaptater ${name} not found`);
7
10
  }
8
- let act;
11
+ let run;
9
12
  const jsa = await import(path);
10
- act = createJsAction(jsa.action);
13
+ run = createJsAction(jsa.action);
11
14
  let res;
12
15
  try {
13
- res = await act.run(argsOrParams, options);
16
+ res = await run(params, options);
14
17
  }
15
18
  catch (e) {
16
19
  throw new Error(`adaptater ${name}: ${e}`);
@@ -1,15 +1,15 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
- import { LmTaskToolSpec } from "@agent-smith/lmtask/dist/interfaces.js";
3
+ import { ToolSpec } from "@locallm/types/dist/tools";
4
4
  declare class McpClient {
5
5
  name: string;
6
6
  transport: StdioClientTransport;
7
7
  client: Client;
8
8
  authorizedTools: Array<string> | null;
9
- tools: Record<string, LmTaskToolSpec>;
9
+ tools: Record<string, ToolSpec>;
10
10
  constructor(servername: string, command: string, args: Array<string>, authorizedTools?: Array<string> | null);
11
11
  start(): Promise<void>;
12
12
  stop(): Promise<void>;
13
- extractTools(): Promise<Array<LmTaskToolSpec>>;
13
+ extractTools(): Promise<Array<ToolSpec>>;
14
14
  }
15
15
  export { McpClient, };
@@ -1,9 +1,9 @@
1
1
  function parseCommandArgs(args) {
2
+ args.pop();
2
3
  const res = {
3
4
  args: new Array(),
4
5
  options: {},
5
6
  };
6
- args.pop();
7
7
  res.options = args.pop();
8
8
  res.args = Array.isArray(args[0]) ? args[0] : args;
9
9
  return res;
@@ -1,5 +1,4 @@
1
- import { LmTaskOutput } from "@agent-smith/lmtask";
2
- import { LmExpert } from "@agent-smith/brain";
3
- declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean, expert?: LmExpert): Promise<LmTaskOutput>;
4
- declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<LmTaskOutput>;
1
+ import { TaskOutput } from "@agent-smith/task";
2
+ declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean): Promise<TaskOutput>;
3
+ declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<TaskOutput>;
5
4
  export { executeTask, executeTaskCmd };