@agent-smith/cli 0.0.93 → 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.
@@ -12,8 +12,18 @@ import { parseCommandArgs } from "../options_parsers.js";
12
12
  import { runtimeDataError, runtimeError, runtimeWarning } from "../user_msgs.js";
13
13
  import { formatStats, processOutput, readPromptFile } from "../utils.js";
14
14
  import { readTask } from "./read.js";
15
+ import { backend, backends, listBackends } from "../../../state/backends.js";
15
16
  async function executeTask(name, payload, options, quiet) {
16
- if (options?.debug) {
17
+ if (options?.backend) {
18
+ if (options.backend in backends) {
19
+ agent.lm = backends[options.backend];
20
+ }
21
+ else {
22
+ const bks = await listBackends(false);
23
+ runtimeDataError(`The backend ${options.backend} is not registered in config. Available backends:\n`, bks);
24
+ }
25
+ }
26
+ if (options?.debug || options?.backend) {
17
27
  console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
18
28
  }
19
29
  const { task, model, conf, vars, mcpServers } = await readTask(name, payload, options, agent);
@@ -21,10 +31,6 @@ async function executeTask(name, payload, options, quiet) {
21
31
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
22
32
  delete model.inferParams.tsGrammar;
23
33
  }
24
- if (options?.debug) {
25
- console.log("Task model:", model);
26
- console.log("Task vars:", vars);
27
- }
28
34
  let c = false;
29
35
  const useTemplates = agent.lm.providerType !== "openai";
30
36
  let hasThink = false;
@@ -33,6 +39,10 @@ async function executeTask(name, payload, options, quiet) {
33
39
  tpl = new PromptTemplate(model.template ?? "none");
34
40
  hasThink = tpl.tags?.think ? true : false;
35
41
  }
42
+ if (options?.debug) {
43
+ console.log("Task model:", model);
44
+ console.log("Task vars:", vars);
45
+ }
36
46
  const printToken = (t) => {
37
47
  if (options?.tokens === true) {
38
48
  let txt = t;
@@ -197,6 +207,9 @@ async function executeTask(name, payload, options, quiet) {
197
207
  runtimeWarning("Error formating stats:", `${e}`);
198
208
  }
199
209
  }
210
+ if (options?.backend) {
211
+ agent.lm = backend.value;
212
+ }
200
213
  return out;
201
214
  }
202
215
  async function executeTaskCmd(name, targs = []) {
@@ -19,11 +19,9 @@ function configureTaskModel(itConf, taskSpec) {
19
19
  }
20
20
  if (!foundTemplate) {
21
21
  if (itConf?.model?.name) {
22
- if (itConf?.model?.name != taskSpec.model.name) {
23
- const gt = guessTemplate(itConf.model.name);
24
- model.template = gt;
25
- foundTemplate = true;
26
- }
22
+ const gt = guessTemplate(itConf.model.name);
23
+ model.template = gt;
24
+ foundTemplate = true;
27
25
  }
28
26
  else if (taskSpec?.model?.template) {
29
27
  model.template = taskSpec.model.template;
@@ -13,6 +13,7 @@ const inferenceOptions = [
13
13
  new Option("--mp, --min_p <number>", "the minimum probability for a token to be considered, relative to the probability of the most likely token").argParser(parseFloatValue),
14
14
  new Option("-t, --temperature <number>", "adjusts randomness in sampling; higher values mean more randomness").argParser(parseFloatValue),
15
15
  new Option("-r, --repeat_penalty <number>", "adjusts penalty for repeated tokens").argParser(parseFloatValue),
16
+ new Option("-b, --backend <name>", "use a given backend. It must be registered in config").argParser(parseString),
16
17
  ];
17
18
  const ioOptions = [
18
19
  new Option("--if, --input-file", "use promptfile input mode"),
@@ -1,5 +1,5 @@
1
- import { TaskDef, ModelSpec, TaskVariables } from "@agent-smith/task";
2
- import { InferenceParams, LmProviderType } from "@locallm/types";
1
+ import type { TaskDef, ModelSpec, TaskVariables } from "@agent-smith/task";
2
+ import type { InferenceParams, LmProviderType } from "@locallm/types";
3
3
  interface FeatureSpec {
4
4
  id?: number;
5
5
  name: string;
@@ -86,7 +86,6 @@ interface ModelPack {
86
86
  }
87
87
  interface LmTaskFileSpec extends TaskDef {
88
88
  ctx: number;
89
- modelpack?: ModelPack;
90
89
  mcp?: McpServerSpec;
91
90
  }
92
91
  interface BaseLmTaskConfig {
@@ -1,7 +1,7 @@
1
1
  import { Lm } from "@locallm/api";
2
2
  declare const backend: import("@vue/reactivity").Ref<Lm | undefined, Lm | undefined>;
3
3
  declare const backends: Record<string, Lm>;
4
- declare function initBackends(isVerbose?: boolean): Promise<void>;
4
+ declare function initBackends(): Promise<void>;
5
5
  declare function setBackend(name: string, isVerbose?: boolean): Promise<void>;
6
- declare function listBackends(): Promise<void>;
6
+ declare function listBackends(printResult?: boolean): Promise<string>;
7
7
  export { backend, backends, initBackends, listBackends, setBackend };
@@ -1,36 +1,44 @@
1
1
  import { Lm } from "@locallm/api";
2
- import { reactive, ref } from "@vue/reactivity";
2
+ import { ref } from "@vue/reactivity";
3
3
  import colors from "ansi-colors";
4
4
  import { readBackends } from "../db/read.js";
5
5
  import { setDefaultBackend } from "../db/write.js";
6
6
  import { runtimeDataError } from "../utils/user_msgs.js";
7
7
  const backend = ref();
8
- const backends = reactive({});
8
+ const backends = {};
9
9
  const isBackendUp = ref(false);
10
- async function initBackends(isVerbose = false) {
10
+ async function initBackends() {
11
11
  const rmb = readBackends();
12
12
  let defaultBackendName = null;
13
13
  for (const bk of Object.values(rmb)) {
14
+ let name = bk.name;
15
+ let apiKey = "";
16
+ if (bk?.apiKey) {
17
+ if (bk.apiKey == "$OPENROUTER_API_KEY") {
18
+ const apk = process.env.OPENROUTER_API_KEY;
19
+ if (apk === undefined) {
20
+ runtimeDataError("No $OPENROUTER_API_KEY environment variable found, required for ", name);
21
+ return;
22
+ }
23
+ apiKey = apk;
24
+ }
25
+ else {
26
+ apiKey = bk.apiKey;
27
+ }
28
+ }
29
+ ;
14
30
  const lm = new Lm({
15
31
  providerType: bk.type,
16
32
  serverUrl: bk.url,
33
+ apiKey: apiKey.length > 0 ? apiKey : undefined,
17
34
  });
18
- lm.name = bk.name;
19
- if (bk?.apiKey) {
20
- lm.apiKey = bk.apiKey;
21
- }
22
- ;
23
- backends[bk.name] = lm;
35
+ backends[name] = lm;
24
36
  if (bk.isDefault) {
25
37
  defaultBackendName = bk.name;
26
38
  }
27
39
  }
28
40
  if (defaultBackendName !== null) {
29
41
  backend.value = backends[defaultBackendName];
30
- isBackendUp.value = await probeBackend(backend.value, isVerbose);
31
- if (isBackendUp.value && backend.value.providerType == "ollama") {
32
- await backend.value.modelsInfo();
33
- }
34
42
  }
35
43
  }
36
44
  async function setBackend(name, isVerbose = false) {
@@ -43,12 +51,18 @@ async function setBackend(name, isVerbose = false) {
43
51
  console.log("Default backend set to", name);
44
52
  isBackendUp.value = await probeBackend(backend.value, isVerbose);
45
53
  }
46
- async function listBackends() {
54
+ async function listBackends(printResult = true) {
55
+ const allBk = new Array();
47
56
  for (const [name, lm] of Object.entries(backends)) {
48
57
  const bcn = name == backend.value?.name ? colors.bold(name) : name;
49
58
  const buf = new Array("-", bcn, colors.dim("(" + lm.providerType + ") " + lm.serverUrl));
50
- console.log(buf.join(" "));
59
+ const str = buf.join(" ");
60
+ if (printResult) {
61
+ console.log(str);
62
+ }
63
+ allBk.push(str);
51
64
  }
65
+ return allBk.join(" ");
52
66
  }
53
67
  const probeBackend = async (lm, isVerbose) => {
54
68
  let isUp = false;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@agent-smith/cli",
3
3
  "description": "Agent Smith: terminal client for language model agents",
4
4
  "repository": "https://github.com/synw/agent-smith",
5
- "version": "0.0.93",
5
+ "version": "0.0.95",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -11,22 +11,22 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@agent-smith/agent": "^0.1.4",
14
- "@agent-smith/task": "^0.1.5",
14
+ "@agent-smith/task": "^0.1.6",
15
15
  "@agent-smith/tfm": "^0.2.0",
16
16
  "@inquirer/prompts": "^7.10.1",
17
17
  "@intrinsicai/gbnfgen": "0.12.0",
18
- "@locallm/api": "^0.7.0",
19
- "@modelcontextprotocol/sdk": "^1.23.0",
18
+ "@locallm/api": "^0.7.1",
19
+ "@modelcontextprotocol/sdk": "^1.24.3",
20
20
  "@vue/reactivity": "^3.5.25",
21
21
  "ansi-colors": "^4.1.3",
22
- "better-sqlite3": "^12.4.6",
22
+ "better-sqlite3": "^12.5.0",
23
23
  "clipboardy": "^5.0.1",
24
24
  "commander": "^14.0.2",
25
25
  "marked-terminal": "^7.3.0",
26
- "modprompt": "^0.12.5",
26
+ "modprompt": "^0.12.6",
27
27
  "ora": "^9.0.0",
28
28
  "python-shell": "^5.0.0",
29
- "yaml": "^2.8.1"
29
+ "yaml": "^2.8.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@agent-smith/tmem-jobs": "^0.0.4",
@@ -37,7 +37,8 @@
37
37
  "@rollup/plugin-typescript": "^12.3.0",
38
38
  "@types/better-sqlite3": "^7.6.13",
39
39
  "@types/marked-terminal": "^6.1.1",
40
- "@types/node": "^24.10.1",
40
+ "@types/node": "^24.10.2",
41
+ "openai": "^6.10.0",
41
42
  "restmix": "^0.6.1",
42
43
  "rollup": "^4.53.3",
43
44
  "ts-node": "^10.9.2",
@@ -63,4 +64,4 @@
63
64
  "registry": "https://registry.npmjs.org/"
64
65
  },
65
66
  "license": "MIT"
66
- }
67
+ }