@agent-smith/cli 0.0.71 → 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 (40) hide show
  1. package/dist/cmd/clicmds/aliases.js +12 -6
  2. package/dist/cmd/clicmds/base.js +13 -7
  3. package/dist/cmd/cmds.js +0 -20
  4. package/dist/cmd/lib/actions/cmd.d.ts +3 -4
  5. package/dist/cmd/lib/actions/cmd.js +48 -64
  6. package/dist/cmd/lib/actions/read.d.ts +2 -3
  7. package/dist/cmd/lib/actions/read.js +9 -14
  8. package/dist/cmd/lib/adaptaters/cmd.d.ts +1 -1
  9. package/dist/cmd/lib/adaptaters/cmd.js +7 -4
  10. package/dist/cmd/lib/mcp.d.ts +3 -3
  11. package/dist/cmd/lib/options_parsers.js +1 -1
  12. package/dist/cmd/lib/tasks/cmd.d.ts +3 -4
  13. package/dist/cmd/lib/tasks/cmd.js +98 -72
  14. package/dist/cmd/lib/tasks/read.d.ts +5 -6
  15. package/dist/cmd/lib/tasks/read.js +19 -16
  16. package/dist/cmd/lib/utils.js +3 -1
  17. package/dist/cmd/lib/workflows/cmd.js +9 -6
  18. package/dist/cmd/lib/workflows/read.d.ts +3 -4
  19. package/dist/cmd/lib/workflows/read.js +37 -15
  20. package/dist/conf.js +45 -9
  21. package/dist/const.d.ts +3 -0
  22. package/dist/const.js +24 -0
  23. package/dist/db/read.d.ts +3 -3
  24. package/dist/db/read.js +4 -4
  25. package/dist/db/schemas.js +3 -2
  26. package/dist/db/write.d.ts +4 -3
  27. package/dist/db/write.js +36 -12
  28. package/dist/index.js +2 -4
  29. package/dist/interfaces.d.ts +21 -16
  30. package/dist/main.d.ts +1 -2
  31. package/dist/main.js +1 -2
  32. package/dist/state/backends.d.ts +7 -0
  33. package/dist/state/backends.js +128 -0
  34. package/dist/utils/perf.js +1 -1
  35. package/dist/utils/user_msgs.js +5 -5
  36. package/package.json +19 -20
  37. package/dist/agent.d.ts +0 -8
  38. package/dist/agent.js +0 -24
  39. package/dist/cmd/backends.d.ts +0 -3
  40. package/dist/cmd/backends.js +0 -20
@@ -1,14 +1,14 @@
1
+ import { Task } from "@agent-smith/task";
1
2
  import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
2
- import { taskBuilder } from "../../../agent.js";
3
3
  import { readTool } from "../../../db/read.js";
4
4
  import { executeAction } from "../actions/cmd.js";
5
5
  import { McpClient } from "../mcp.js";
6
6
  import { parseTaskConfigOptions } from "../options_parsers.js";
7
7
  import { executeWorkflow } from "../workflows/cmd.js";
8
+ import { executeTask } from "./cmd.js";
8
9
  import { configureTaskModel, mergeInferParams } from "./conf.js";
9
10
  import { openTaskSpec } from "./utils.js";
10
- import { executeTask } from "./cmd.js";
11
- async function readTask(name, payload, options) {
11
+ async function readTask(name, payload, options, agent) {
12
12
  if (options?.debug) {
13
13
  console.log("Payload:", payload);
14
14
  console.log("Task options:", options);
@@ -26,19 +26,25 @@ async function readTask(name, payload, options) {
26
26
  }
27
27
  const taskSpec = taskFileSpec;
28
28
  let vars = {};
29
- taskSpec.variables?.optional?.forEach(k => {
30
- if (k in options) {
31
- vars[k] = options[k];
29
+ if (taskSpec.variables?.optional) {
30
+ for (const k of Object.keys(taskSpec.variables.optional)) {
31
+ if (k in options) {
32
+ vars[k] = options[k];
33
+ }
32
34
  }
33
- });
34
- taskSpec.variables?.required?.forEach(k => {
35
- if (k in options) {
36
- vars[k] = options[k];
35
+ }
36
+ if (taskSpec.variables?.required) {
37
+ for (const k of Object.keys(taskSpec.variables.required)) {
38
+ if (k in options) {
39
+ vars[k] = options[k];
40
+ }
37
41
  }
38
- });
42
+ }
39
43
  const mcpServers = new Array();
40
- if (taskFileSpec?.mcp) {
44
+ if (!taskSpec?.tools) {
41
45
  taskSpec.tools = [];
46
+ }
47
+ if (taskFileSpec?.mcp) {
42
48
  for (const [servername, tool] of Object.entries(taskFileSpec.mcp)) {
43
49
  const mcp = new McpClient(servername, tool.command, tool.args, tool?.tools ?? null);
44
50
  mcpServers.push(mcp);
@@ -48,9 +54,6 @@ async function readTask(name, payload, options) {
48
54
  }
49
55
  }
50
56
  if (taskSpec.toolsList) {
51
- if (!taskSpec?.tools) {
52
- taskSpec.tools = [];
53
- }
54
57
  for (const toolName of taskSpec.toolsList) {
55
58
  const { found, tool, type } = readTool(toolName);
56
59
  if (!found) {
@@ -80,7 +83,7 @@ async function readTask(name, payload, options) {
80
83
  delete taskSpec.toolsList;
81
84
  }
82
85
  ;
83
- const task = taskBuilder.init(taskSpec);
86
+ const task = new Task(agent, taskSpec);
84
87
  if (model?.inferParams?.tsGrammar) {
85
88
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
86
89
  delete model.inferParams.tsGrammar;
@@ -1,9 +1,11 @@
1
- import { marked } from "../../agent.js";
2
1
  import { formatMode, initFilepaths, outputMode, promptfilePath } from "../../state/state.js";
3
2
  import { writeToClipboard } from "../sys/clipboard.js";
4
3
  import { readFile } from "../sys/read.js";
5
4
  import { splitThinking } from "../../utils/text.js";
6
5
  import { runtimeError } from "./user_msgs.js";
6
+ import { marked } from 'marked';
7
+ import { markedTerminal } from "marked-terminal";
8
+ marked.use(markedTerminal());
7
9
  function readPromptFile() {
8
10
  initFilepaths();
9
11
  return readFile(promptfilePath.value);
@@ -3,6 +3,7 @@ import { executeAdaptater } from "../adaptaters/cmd.js";
3
3
  import { parseCommandArgs } from "../options_parsers.js";
4
4
  import { executeTask } from "../tasks/cmd.js";
5
5
  import { readWorkflow } from "./read.js";
6
+ import colors from "ansi-colors";
6
7
  async function executeWorkflow(name, params, options) {
7
8
  const { workflow, found } = await readWorkflow(name);
8
9
  if (!found) {
@@ -15,11 +16,11 @@ async function executeWorkflow(name, params, options) {
15
16
  console.log("Running workflow", name, stepNames.length, "steps");
16
17
  }
17
18
  let i = 0;
18
- const finalTaskIndex = stepNames.length + 1;
19
+ const finalTaskIndex = stepNames.length - 1;
19
20
  let taskRes = params;
20
21
  for (const [name, step] of Object.entries(workflow)) {
21
22
  if (isDebug || isVerbose) {
22
- console.log(`${i + 1}: ${step.type} ${name}`);
23
+ console.log(i + 1, name, colors.dim(step.type));
23
24
  }
24
25
  switch (step.type) {
25
26
  case "task":
@@ -35,7 +36,7 @@ async function executeWorkflow(name, params, options) {
35
36
  try {
36
37
  const ares = await executeAction(name, taskRes, options, true);
37
38
  if (typeof ares == "string") {
38
- taskRes = { payload: ares };
39
+ taskRes = { args: ares };
39
40
  }
40
41
  else {
41
42
  taskRes = ares;
@@ -52,11 +53,14 @@ async function executeWorkflow(name, params, options) {
52
53
  try {
53
54
  const ares = await executeAdaptater(name, taskRes, options);
54
55
  if (typeof ares == "string") {
55
- taskRes = { payload: ares };
56
+ taskRes = { args: ares };
56
57
  }
57
58
  else {
58
59
  taskRes = ares;
59
60
  }
61
+ if (i == finalTaskIndex) {
62
+ console.log(taskRes);
63
+ }
60
64
  }
61
65
  catch (e) {
62
66
  throw new Error(`workflow adaptater ${i + 1}: ${e}`);
@@ -72,7 +76,6 @@ async function executeWorkflow(name, params, options) {
72
76
  }
73
77
  async function executeWorkflowCmd(name, wargs) {
74
78
  const { args, options } = parseCommandArgs(wargs);
75
- const params = { args: args };
76
- return await executeWorkflow(name, params, options);
79
+ return await executeWorkflow(name, { args: args }, options);
77
80
  }
78
81
  export { executeWorkflow, executeWorkflowCmd, };
@@ -1,7 +1,6 @@
1
- import { AgentTask } from "@agent-smith/jobs";
2
- import { FeatureType } from '../../../interfaces.js';
1
+ import { WorkflowStep } from '../../../interfaces.js';
3
2
  declare function readWorkflow(name: string): Promise<{
4
3
  found: boolean;
5
- workflow: Record<string, AgentTask<FeatureType, any, any, Record<string, any>>>;
4
+ workflow: Record<string, WorkflowStep>;
6
5
  }>;
7
- export { readWorkflow, };
6
+ export { readWorkflow };
@@ -1,6 +1,8 @@
1
- import YAML from 'yaml';
1
+ import { Agent } from '@agent-smith/agent';
2
+ import { Task } from '@agent-smith/task';
2
3
  import { default as fs } from "fs";
3
- import { taskBuilder } from '../../../agent.js';
4
+ import YAML from 'yaml';
5
+ import { backend } from '../../../state/backends.js';
4
6
  import { getFeatureSpec } from '../../../state/features.js';
5
7
  import { readTask } from "../../sys/read_task.js";
6
8
  import { pythonAction, systemAction } from '../actions/cmd.js';
@@ -26,24 +28,36 @@ async function _createWorkflowFromSpec(spec) {
26
28
  case "js":
27
29
  const { action } = await import(path);
28
30
  const at = action;
29
- at.type = "action";
30
- steps[name] = at;
31
+ const wf = {
32
+ type: "action",
33
+ run: at,
34
+ };
35
+ steps[name] = wf;
31
36
  break;
32
37
  case "mjs":
33
38
  const mjsa = await import(path);
34
39
  const act = createJsAction(mjsa.action);
35
- act.type = "action";
36
- steps[name] = act;
40
+ const wf2 = {
41
+ type: "action",
42
+ run: act,
43
+ };
44
+ steps[name] = wf2;
37
45
  break;
38
46
  case "yml":
39
47
  const _t1 = systemAction(path);
40
- _t1.type = "action";
41
- steps[name] = _t1;
48
+ const wf3 = {
49
+ type: "action",
50
+ run: _t1,
51
+ };
52
+ steps[name] = wf3;
42
53
  break;
43
54
  case "py":
44
55
  const _t = pythonAction(path);
45
- _t.type = "action";
46
- steps[name] = _t;
56
+ const wf4 = {
57
+ type: "action",
58
+ run: _t,
59
+ };
60
+ steps[name] = wf4;
47
61
  break;
48
62
  default:
49
63
  throw new Error(`Unknown feature extension ${ext}`);
@@ -56,8 +70,11 @@ async function _createWorkflowFromSpec(spec) {
56
70
  }
57
71
  const jsa = await import(path);
58
72
  const act = createJsAction(jsa.action);
59
- act.type = "adaptater";
60
- steps[name] = act;
73
+ const wf = {
74
+ type: "adaptater",
75
+ run: act,
76
+ };
77
+ steps[name] = wf;
61
78
  }
62
79
  else {
63
80
  const { found, path } = getFeatureSpec(name, "task");
@@ -68,8 +85,13 @@ async function _createWorkflowFromSpec(spec) {
68
85
  if (!res.found) {
69
86
  throw new Error(`Unable to read task ${name} ${path}`);
70
87
  }
71
- const tsk = taskBuilder.fromYaml(res.ymlTask, "task");
72
- steps[name] = tsk;
88
+ const agent = new Agent(backend.value);
89
+ const tsk = Task.fromYaml(agent, res.ymlTask);
90
+ const wf = {
91
+ type: "task",
92
+ run: tsk.run,
93
+ };
94
+ steps[name] = wf;
73
95
  }
74
96
  }
75
97
  return steps;
@@ -112,4 +134,4 @@ async function readWorkflow(name) {
112
134
  }
113
135
  return { found: true, workflow: wf };
114
136
  }
115
- export { readWorkflow, };
137
+ export { readWorkflow };
package/dist/conf.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import path from "path";
2
2
  import { readConf } from "./cmd/sys/read_conf.js";
3
- import { upsertBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
3
+ import { upsertBackends, insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
4
4
  import { buildPluginsPaths } from "./state/plugins.js";
5
5
  import { runtimeError } from "./cmd/lib/user_msgs.js";
6
+ import { localBackends } from "./const.js";
6
7
  const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
7
8
  const dbPath = path.join(confDir, "config.db");
8
9
  async function processConfPath(confPath) {
@@ -12,17 +13,52 @@ async function processConfPath(confPath) {
12
13
  }
13
14
  console.log(data);
14
15
  const allPaths = new Array();
16
+ const backends = {};
17
+ let defaultBackendName = "";
15
18
  if (data?.backends) {
16
- for (const [name, bconf] of Object.entries(data.backends)) {
17
- const bc = {
18
- name: name,
19
- type: bconf.type,
20
- uri: bconf.uri,
21
- apiKey: bconf?.apiKey,
22
- };
23
- upsertBackend(bc);
19
+ for (const [name, val] of Object.entries(data.backends)) {
20
+ switch (name) {
21
+ case "local":
22
+ const bs = val;
23
+ bs.forEach(b => {
24
+ if (!["llamacpp", "koboldcpp", "ollama"].includes(b)) {
25
+ throw new Error(`Unknow backend default value: ${b}`);
26
+ }
27
+ const lb = localBackends[b];
28
+ backends[lb.name] = lb;
29
+ });
30
+ break;
31
+ case "default":
32
+ const v1 = val;
33
+ defaultBackendName = v1;
34
+ break;
35
+ default:
36
+ const v3 = val;
37
+ let apiKey = undefined;
38
+ if (v3?.apiKey) {
39
+ apiKey = v3.apiKey;
40
+ }
41
+ const ib = {
42
+ name: name,
43
+ type: v3.type,
44
+ url: v3.url,
45
+ isDefault: false,
46
+ };
47
+ if (apiKey) {
48
+ ib.apiKey = apiKey;
49
+ }
50
+ backends[name] = ib;
51
+ break;
52
+ }
24
53
  }
25
54
  }
55
+ console.log("Default backend:", defaultBackendName);
56
+ console.dir(backends, { depth: 4 });
57
+ if (!Object.keys(backends).includes(defaultBackendName)) {
58
+ throw new Error(`Undeclared default backend: ${defaultBackendName}`);
59
+ }
60
+ backends[defaultBackendName].isDefault = true;
61
+ upsertBackends(Object.values(backends));
26
62
  if (data?.features) {
27
63
  allPaths.push(...data.features);
28
64
  const fts = new Array();
@@ -0,0 +1,3 @@
1
+ import { InferenceBackend } from "./interfaces.js";
2
+ declare const localBackends: Record<string, InferenceBackend>;
3
+ export { localBackends };
package/dist/const.js ADDED
@@ -0,0 +1,24 @@
1
+ const localBackends = {
2
+ llamacpp: {
3
+ name: "llamacpp",
4
+ type: "llamacpp",
5
+ url: "http://localhost:8080",
6
+ apiKey: "",
7
+ isDefault: false,
8
+ },
9
+ koboldcpp: {
10
+ name: "koboldcpp",
11
+ type: "koboldcpp",
12
+ url: "http://localhost:5001",
13
+ apiKey: "",
14
+ isDefault: false,
15
+ },
16
+ ollama: {
17
+ name: "ollama",
18
+ type: "ollama",
19
+ url: "http://localhost:11434",
20
+ apiKey: "",
21
+ isDefault: false,
22
+ },
23
+ };
24
+ export { localBackends };
package/dist/db/read.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ToolSpec } from "modprompt";
2
- import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType } from "../interfaces.js";
1
+ import { ToolSpec } from "@locallm/types";
2
+ import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType, InferenceBackend } from "../interfaces.js";
3
3
  declare function readFeaturePaths(): Array<string>;
4
- declare function readBackends(): Array<Record<string, string>>;
4
+ declare function readBackends(): Record<string, InferenceBackend>;
5
5
  declare function readPlugins(): Array<Record<string, string>>;
6
6
  declare function readFeaturesType(type: FeatureType): Record<string, FeatureSpec>;
7
7
  declare function readFeatures(): Record<FeatureType, Record<string, FeatureSpec>>;
package/dist/db/read.js CHANGED
@@ -9,13 +9,13 @@ function readFeaturePaths() {
9
9
  return f;
10
10
  }
11
11
  function readBackends() {
12
- const stmt = db.prepare("SELECT name, type, uri, apiKey FROM backend");
12
+ const stmt = db.prepare("SELECT name, type, url, apiKey, isdefault FROM backend");
13
13
  const data = stmt.all();
14
- let f = new Array();
14
+ const bks = {};
15
15
  data.forEach((row) => {
16
- f.push({ name: row.name, type: row.type, uri: row.uri, apiKey: row.apiKey });
16
+ bks[row.name] = { name: row.name, type: row.type, url: row.url, apiKey: row.apiKey, isDefault: row.isdefault === 1 };
17
17
  });
18
- return f;
18
+ return bks;
19
19
  }
20
20
  function readPlugins() {
21
21
  const stmt = db.prepare("SELECT name, path FROM plugin");
@@ -74,8 +74,9 @@ const model = `CREATE TABLE IF NOT EXISTS model (
74
74
  const backend = `CREATE TABLE IF NOT EXISTS backend (
75
75
  id INTEGER PRIMARY KEY AUTOINCREMENT,
76
76
  name TEXT UNIQUE NOT NULL,
77
- type TEXT NOT NULL CHECK ( type IN ('llamacpp', 'koboldcpp', 'ollama') ),
78
- uri TEXT NOT NULL,
77
+ type TEXT NOT NULL CHECK ( type IN ('llamacpp', 'koboldcpp', 'ollama', 'openai') ),
78
+ url TEXT NOT NULL,
79
+ isdefault INTEGER NOT NULL,
79
80
  apiKey TEXT
80
81
  );`;
81
82
  const schemas = [
@@ -1,7 +1,8 @@
1
- import { Features, DbModelDef, RemoteBackend } from "../interfaces.js";
1
+ import { Features, DbModelDef, InferenceBackend } from "../interfaces.js";
2
2
  declare function updatePromptfilePath(pf: string): void;
3
3
  declare function updateDataDirPath(dd: string): void;
4
- declare function upsertBackend(bdata: RemoteBackend): boolean;
4
+ declare function setDefaultBackend(name: string): void;
5
+ declare function upsertBackends(bdata: Array<InferenceBackend>): boolean;
5
6
  declare function insertFeaturesPathIfNotExists(path: string): boolean;
6
7
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
7
8
  declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
@@ -9,4 +10,4 @@ declare function updateAliases(feats: Features): void;
9
10
  declare function updateModels(models: Array<DbModelDef>): void;
10
11
  declare function updateFeatures(feats: Features): void;
11
12
  declare function upsertFilePath(name: string, newPath: string): boolean;
12
- export { updatePromptfilePath, updateDataDirPath, upsertBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
13
+ export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
package/dist/db/write.js CHANGED
@@ -13,17 +13,41 @@ function updateDataDirPath(dd) {
13
13
  const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
14
14
  stmt.run("datadir", dd);
15
15
  }
16
- function upsertBackend(bdata) {
17
- const stmt1 = db.prepare("SELECT * FROM backend WHERE name = ?");
18
- const result = stmt1.get(bdata.name);
19
- if (result?.id) {
20
- const updateStmt = db.prepare("UPDATE backend SET type = ?, uri = ?, apiKey = ? WHERE name = ?");
21
- updateStmt.run(bdata.type, bdata.uri, bdata?.apiKey ?? "NULL", bdata.name);
22
- return true;
16
+ function setDefaultBackend(name) {
17
+ const updateStmt = db.prepare("UPDATE backend SET isdefault = 0 WHERE isdefault = 1");
18
+ updateStmt.run();
19
+ const nupdStmt = db.prepare("UPDATE backend SET isdefault = 1 WHERE name = ?");
20
+ nupdStmt.run(name);
21
+ }
22
+ function upsertBackends(bdata) {
23
+ let hasUpdates = false;
24
+ const existingStmt = db.prepare("SELECT name FROM backend");
25
+ const existingBackends = existingStmt.all();
26
+ const existingNames = new Set(existingBackends.map(b => b.name));
27
+ const newNames = new Set(bdata.map(b => b.name));
28
+ const toDelete = Array.from(existingNames).filter(name => !newNames.has(name));
29
+ if (toDelete.length > 0) {
30
+ const deleteStmt = db.prepare("DELETE FROM backend WHERE name = ?");
31
+ for (const name of toDelete) {
32
+ deleteStmt.run(name);
33
+ }
34
+ hasUpdates = true;
23
35
  }
24
- const stmt = db.prepare("INSERT INTO backend (name,type,uri,apiKey) VALUES (?,?,?,?)");
25
- stmt.run(bdata.name, bdata.type, bdata.uri, bdata?.apiKey ?? "NULL");
26
- return false;
36
+ for (const backend of bdata) {
37
+ const stmt1 = db.prepare("SELECT * FROM backend WHERE name = ?");
38
+ const result = stmt1.get(backend.name);
39
+ if (result?.id) {
40
+ const updateStmt = db.prepare("UPDATE backend SET type = ?, url = ?, apiKey = ?, isdefault = ? WHERE name = ?");
41
+ updateStmt.run(backend.type, backend.url, backend?.apiKey ?? "NULL", backend.isDefault ? 1 : 0, backend.name);
42
+ hasUpdates = true;
43
+ }
44
+ else {
45
+ const stmt = db.prepare("INSERT INTO backend (name,type,url,apiKey,isdefault) VALUES (?,?,?,?,?)");
46
+ stmt.run(backend.name, backend.type, backend.url, backend?.apiKey ?? "NULL", backend.isDefault ? 1 : 0);
47
+ hasUpdates = true;
48
+ }
49
+ }
50
+ return hasUpdates;
27
51
  }
28
52
  function insertFeaturesPathIfNotExists(path) {
29
53
  const stmt1 = db.prepare("SELECT * FROM featurespath WHERE path = ?");
@@ -169,7 +193,7 @@ function updateFeatures(feats) {
169
193
  if (toolDoc.length > 0) {
170
194
  upsertTool(feat.name, "task", toolDoc);
171
195
  }
172
- if (variables.required.length > 0 || variables.optional.length > 0) {
196
+ if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
173
197
  updateVariables(feat.name, JSON.stringify(variables, null, " "));
174
198
  }
175
199
  });
@@ -206,4 +230,4 @@ function upsertFilePath(name, newPath) {
206
230
  return true;
207
231
  }
208
232
  }
209
- export { updatePromptfilePath, updateDataDirPath, upsertBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
233
+ export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { argv } from 'process';
3
- import { initAgent } from './agent.js';
4
3
  import { query } from "./cli.js";
5
4
  import { buildCmds, parseCmd } from './cmd/cmds.js';
6
5
  import { formatMode, initState, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
7
6
  import { updateConfCmd } from './cmd/clicmds/update.js';
8
- import { initRemoteBackends } from './cmd/backends.js';
7
+ import { initBackends } from './state/backends.js';
9
8
  async function main() {
10
9
  const nargs = argv.length;
11
10
  if (nargs == 2) {
@@ -18,8 +17,7 @@ async function main() {
18
17
  }
19
18
  }
20
19
  await initState();
21
- const rmbs = initRemoteBackends();
22
- await initAgent(rmbs);
20
+ await initBackends();
23
21
  const program = await buildCmds();
24
22
  program.hook('preAction', async (thisCommand, actionCommand) => {
25
23
  const options = actionCommand.opts();
@@ -1,15 +1,11 @@
1
- import { BaseLmTask, ModelSpec } from "@agent-smith/lmtask";
2
- import { InferenceParams } from "@locallm/types";
3
- interface FeatureVariables {
4
- required: Array<string>;
5
- optional: Array<string>;
6
- }
1
+ import { TaskDef, ModelSpec, TaskVariables } from "@agent-smith/task";
2
+ import { InferenceParams, LmProviderType } from "@locallm/types";
7
3
  interface FeatureSpec {
8
4
  id?: number;
9
5
  name: string;
10
6
  path: string;
11
7
  ext: FeatureExtension;
12
- variables?: FeatureVariables;
8
+ variables?: TaskVariables;
13
9
  }
14
10
  interface Features {
15
11
  task: Array<{
@@ -43,18 +39,24 @@ interface Features {
43
39
  ext: ModelFileExtension;
44
40
  }>;
45
41
  }
46
- interface RemoteBackend {
47
- name: string;
48
- type: RemoteProviderType;
49
- uri: string;
42
+ interface ConfInferenceBackend {
43
+ type: LmProviderType;
44
+ url: string;
50
45
  apiKey?: string;
51
46
  }
47
+ interface InferenceBackend extends ConfInferenceBackend {
48
+ name: string;
49
+ isDefault?: boolean;
50
+ }
51
+ interface BackendEntries {
52
+ [key: string]: ConfInferenceBackend | string | Array<"llamacpp" | "koboldcpp" | "ollama">;
53
+ }
52
54
  interface ConfigFile {
53
55
  promptfile?: string;
54
56
  datadir?: string;
55
57
  features?: Array<string>;
56
58
  plugins?: Array<string>;
57
- backends?: Array<RemoteBackend>;
59
+ backends?: BackendEntries;
58
60
  }
59
61
  interface Settings {
60
62
  name: string;
@@ -82,9 +84,8 @@ interface ModelPack {
82
84
  default: string;
83
85
  recommended?: Array<string>;
84
86
  }
85
- interface LmTaskFileSpec extends BaseLmTask {
87
+ interface LmTaskFileSpec extends TaskDef {
86
88
  ctx: number;
87
- model?: ModelSpec;
88
89
  modelpack?: ModelPack;
89
90
  mcp?: McpServerSpec;
90
91
  }
@@ -100,6 +101,10 @@ interface FinalLmTaskConfig {
100
101
  model?: ModelSpec;
101
102
  modelname?: string;
102
103
  }
104
+ interface WorkflowStep {
105
+ type: string;
106
+ run: FeatureExecutor;
107
+ }
103
108
  interface McpServerSpec {
104
109
  command: string;
105
110
  arguments: string[];
@@ -132,5 +137,5 @@ type CmdExtension = "js";
132
137
  type ModelFileExtension = "yml";
133
138
  type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
134
139
  type AliasType = "task" | "action" | "workflow";
135
- type RemoteProviderType = "llamacpp" | "koboldcpp" | "ollama";
136
- export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, RemoteBackend, RemoteProviderType, };
140
+ type FeatureExecutor<I = any, O = any> = (params: I, options: Record<string, any>) => Promise<O>;
141
+ export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, InferenceBackend, ConfInferenceBackend, FeatureExecutor, WorkflowStep, };
package/dist/main.d.ts CHANGED
@@ -3,7 +3,6 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
3
  import { executeAction } from "./cmd/lib/actions/cmd.js";
4
4
  import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { initAgent } from "./agent.js";
7
6
  import { initState, pluginDataDir } from "./state/state.js";
8
7
  import { usePerfTimer } from "./utils/perf.js";
9
8
  import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
@@ -14,4 +13,4 @@ import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/o
14
13
  import { McpClient } from "./cmd/lib/mcp.js";
15
14
  import { readTask } from "./cmd/lib/tasks/read.js";
16
15
  import { FeatureType } from "./interfaces.js";
17
- export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, FeatureType, };
16
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, FeatureType, };
package/dist/main.js CHANGED
@@ -3,7 +3,6 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
3
3
  import { executeAction } from "./cmd/lib/actions/cmd.js";
4
4
  import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
- import { initAgent } from "./agent.js";
7
6
  import { initState, pluginDataDir } from "./state/state.js";
8
7
  import { usePerfTimer } from "./utils/perf.js";
9
8
  import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
@@ -13,4 +12,4 @@ import { extractBetweenTags, splitThinking } from "./utils/text.js";
13
12
  import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
14
13
  import { McpClient } from "./cmd/lib/mcp.js";
15
14
  import { readTask } from "./cmd/lib/tasks/read.js";
16
- export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, };
15
+ export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, };
@@ -0,0 +1,7 @@
1
+ import { Lm } from "@locallm/api";
2
+ declare const backend: import("@vue/reactivity").Ref<Lm | undefined, Lm | undefined>;
3
+ declare const backends: Record<string, Lm>;
4
+ declare function initBackends(isVerbose?: boolean): Promise<void>;
5
+ declare function setBackend(name: string, isVerbose?: boolean): Promise<void>;
6
+ declare function listBackends(): Promise<void>;
7
+ export { backend, backends, initBackends, listBackends, setBackend };