@agent-smith/cli 0.0.95 → 0.0.96

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.
@@ -1,38 +1,28 @@
1
- import YAML from 'yaml';
2
- import { dbPath } from "../../conf.js";
3
- import { readFeaturePaths, readFeaturesType } from "../../db/read.js";
4
- import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
5
- import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
6
- import { readPluginsPaths } from "../../state/plugins.js";
7
- import { runMode } from "../../state/state.js";
8
- import { showModelsCmd } from "../lib/models.js";
1
+ import { Option } from "commander";
2
+ import { listBackends, setBackend } from "../../state/backends.js";
9
3
  import { parseCommandArgs } from "../lib/options_parsers.js";
10
- import { deleteFileIfExists } from "../sys/delete_file.js";
11
- import { readTask } from "../sys/read_task.js";
4
+ import { processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd } from "./cmds.js";
12
5
  import { updateConfCmd } from "./update.js";
13
- import { listBackends, setBackend } from "../../state/backends.js";
6
+ import { inferenceOptions } from "../options.js";
14
7
  function initBaseCommands(program) {
15
8
  program.command("exit")
16
9
  .description("exit the cli")
17
10
  .action(() => process.exit(0));
18
- program.command("tasks")
11
+ const tasksCmd = program.command("tasks")
19
12
  .description("list all the tasks")
20
13
  .action(async (...args) => {
21
- const ts = Object.keys(readFeaturesType("task")).sort();
22
- console.table(ts);
23
- });
24
- program.command("task <task>")
25
- .description("read a task")
26
- .action(async (...args) => {
27
14
  const ca = parseCommandArgs(args);
28
- await _readTaskCmd(ca.args);
15
+ await processTasksCmd(ca.args, ca.options);
29
16
  });
30
- program.command("models [filters...]")
31
- .description("list the available models")
17
+ tasksCmd.addOption(new Option("-c, --conf", "output the tasks config"));
18
+ const taskCmd = program.command("task <task>")
19
+ .description("read a task")
32
20
  .action(async (...args) => {
33
21
  const ca = parseCommandArgs(args);
34
- await showModelsCmd(ca.args);
22
+ await processTaskCmd(ca.args, ca.options);
35
23
  });
24
+ inferenceOptions.forEach(o => taskCmd.addOption(o));
25
+ taskCmd.addOption(new Option("--reset", "reset the task config to the original"));
36
26
  program.command("backend <name>")
37
27
  .description("set the default backend")
38
28
  .action(async (...args) => {
@@ -47,7 +37,7 @@ function initBaseCommands(program) {
47
37
  program.command("update")
48
38
  .description("update the available features: run this after adding a new feature")
49
39
  .action(async (...args) => {
50
- await _updateFeatures();
40
+ await updateFeaturesCmd();
51
41
  });
52
42
  program.command("conf <path>")
53
43
  .description("process config file")
@@ -58,44 +48,8 @@ function initBaseCommands(program) {
58
48
  program.command("reset")
59
49
  .description("reset the config database")
60
50
  .action(async (...args) => {
61
- await _resetDbCmd();
51
+ await resetDbCmd();
62
52
  });
63
53
  return program;
64
54
  }
65
- async function _resetDbCmd() {
66
- if (runMode.value == "cli") {
67
- console.log("This command can not be run in cli mode");
68
- return;
69
- }
70
- deleteFileIfExists(dbPath);
71
- console.log("Config database reset ok. Run the conf command to recreate it");
72
- }
73
- async function _updateFeatures() {
74
- const fp = readFeaturePaths();
75
- const pp = await readPluginsPaths();
76
- const paths = [...fp, ...pp];
77
- const feats = readFeaturesDirs(paths);
78
- updateFeatures(feats);
79
- updateAliases(feats);
80
- const deleted = cleanupFeaturePaths(paths);
81
- for (const el of deleted) {
82
- console.log("- [feature path]", el);
83
- }
84
- }
85
- async function _readTaskCmd(args) {
86
- if (args.length == 0) {
87
- console.warn("Provide a task name");
88
- return;
89
- }
90
- const { found, path } = getFeatureSpec(args[0], "task");
91
- if (!found) {
92
- console.warn(`FeatureType ${args[0]} not found`);
93
- return;
94
- }
95
- const res = readTask(path);
96
- if (!res.found) {
97
- throw new Error(`Task ${args[0]}, ${path} not found`);
98
- }
99
- console.log(YAML.stringify(res.ymlTask));
100
- }
101
55
  export { initBaseCommands };
@@ -1,4 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import { FeatureSpec } from '../../interfaces.js';
3
3
  declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>): Promise<Array<Command>>;
4
- export { initUserCmds };
4
+ declare function resetDbCmd(): Promise<any>;
5
+ declare function updateFeaturesCmd(): Promise<any>;
6
+ declare function processTasksCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
7
+ declare function processTaskCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
8
+ export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
@@ -1,4 +1,15 @@
1
1
  import { readCmds } from "../sys/read_cmds.js";
2
+ import YAML from 'yaml';
3
+ import colors from "ansi-colors";
4
+ import { dbPath } from "../../conf.js";
5
+ import { readFeaturePaths, readFeaturesType, readTaskSetting } from "../../db/read.js";
6
+ import { cleanupFeaturePaths, deleteTaskSetting, updateAliases, updateFeatures, upsertTaskSettings } from "../../db/write.js";
7
+ import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
8
+ import { readPluginsPaths } from "../../state/plugins.js";
9
+ import { runMode } from "../../state/state.js";
10
+ import { deleteFileIfExists } from "../sys/delete_file.js";
11
+ import { readTask } from "../sys/read_task.js";
12
+ import { isTaskSettingsInitialized, initTaskSettings, tasksSettings } from '../../state/tasks.js';
2
13
  async function initUserCmds(cmdFeats) {
3
14
  const paths = new Set();
4
15
  const cmds = new Array();
@@ -12,4 +23,73 @@ async function initUserCmds(cmdFeats) {
12
23
  }
13
24
  return cmds;
14
25
  }
15
- export { initUserCmds };
26
+ async function resetDbCmd() {
27
+ if (runMode.value == "cli") {
28
+ console.log("This command can not be run in cli mode");
29
+ return;
30
+ }
31
+ deleteFileIfExists(dbPath);
32
+ console.log("Config database reset ok. Run the conf command to recreate it");
33
+ }
34
+ async function updateFeaturesCmd() {
35
+ const fp = readFeaturePaths();
36
+ const pp = await readPluginsPaths();
37
+ const paths = [...fp, ...pp];
38
+ const feats = readFeaturesDirs(paths);
39
+ updateFeatures(feats);
40
+ updateAliases(feats);
41
+ const deleted = cleanupFeaturePaths(paths);
42
+ for (const el of deleted) {
43
+ console.log("- [feature path]", el);
44
+ }
45
+ }
46
+ async function processTasksCmd(args, options) {
47
+ if (options?.conf) {
48
+ if (!isTaskSettingsInitialized.value) {
49
+ initTaskSettings();
50
+ }
51
+ console.log(YAML.stringify({ "tasks": tasksSettings }));
52
+ }
53
+ else {
54
+ const ts = Object.keys(readFeaturesType("task")).sort();
55
+ console.table(ts);
56
+ }
57
+ }
58
+ async function processTaskCmd(args, options) {
59
+ if (args.length == 0) {
60
+ console.warn("Provide a task name");
61
+ return;
62
+ }
63
+ const { found, path } = getFeatureSpec(args[0], "task");
64
+ if (!found) {
65
+ console.warn(`Task ${args[0]} not found`);
66
+ return;
67
+ }
68
+ if (options?.reset) {
69
+ deleteTaskSetting(args[0]);
70
+ console.log("Task", args[0], "reset ok");
71
+ return;
72
+ }
73
+ const res = readTask(path);
74
+ if (!res.found) {
75
+ throw new Error(`Task ${args[0]}, ${path} not found`);
76
+ }
77
+ console.log(res.ymlTask);
78
+ if (Object.keys(options).length > 0) {
79
+ upsertTaskSettings(args[0], options);
80
+ }
81
+ const s = readTaskSetting(args[0]);
82
+ if (s.found) {
83
+ const sts = s.settings;
84
+ delete sts.id;
85
+ delete sts.name;
86
+ const display = {};
87
+ for (const [k, v] of Object.entries(sts)) {
88
+ if (v) {
89
+ display[k] = v;
90
+ }
91
+ }
92
+ console.log(colors.dim("Settings") + ":", display);
93
+ }
94
+ }
95
+ export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
@@ -4,7 +4,6 @@ import { readFilePath } from "../../db/read.js";
4
4
  import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
5
5
  import { readFeaturesDirs } from "../../state/features.js";
6
6
  import { dataDirPath, promptfilePath } from "../../state/state.js";
7
- import { updateAllModels } from '../lib/models.js';
8
7
  import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
9
8
  async function updateConfCmd(args) {
10
9
  initDb(false, true);
@@ -37,7 +36,6 @@ async function updateConfCmd(args) {
37
36
  const feats = readFeaturesDirs(paths);
38
37
  updateFeatures(feats);
39
38
  updateAliases(feats);
40
- updateAllModels();
41
39
  const deleted = cleanupFeaturePaths(paths);
42
40
  for (const el of deleted) {
43
41
  console.log("- [feature path]", el);
@@ -5,7 +5,7 @@ function createJsAction(action) {
5
5
  return res;
6
6
  }
7
7
  catch (e) {
8
- throw new Error(`executing action:${e}`);
8
+ throw new Error(`executing action:${e}. Args: ${args}`);
9
9
  }
10
10
  };
11
11
  return run;
@@ -13,7 +13,16 @@ 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
15
  import { backend, backends, listBackends } from "../../../state/backends.js";
16
+ import { isTaskSettingsInitialized, initTaskSettings, tasksSettings } from "../../../state/tasks.js";
16
17
  async function executeTask(name, payload, options, quiet) {
18
+ if (!isTaskSettingsInitialized.value) {
19
+ initTaskSettings();
20
+ }
21
+ const hasSettings = Object.keys(tasksSettings).includes(name);
22
+ let settings = {};
23
+ if (hasSettings) {
24
+ settings = tasksSettings[name];
25
+ }
17
26
  if (options?.backend) {
18
27
  if (options.backend in backends) {
19
28
  agent.lm = backends[options.backend];
@@ -23,10 +32,45 @@ async function executeTask(name, payload, options, quiet) {
23
32
  runtimeDataError(`The backend ${options.backend} is not registered in config. Available backends:\n`, bks);
24
33
  }
25
34
  }
35
+ else if (settings?.backend) {
36
+ agent.lm = backends[settings.backend];
37
+ }
26
38
  if (options?.debug || options?.backend) {
27
39
  console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
28
40
  }
29
41
  const { task, model, conf, vars, mcpServers } = await readTask(name, payload, options, agent);
42
+ if (hasSettings) {
43
+ if (!model?.inferParams) {
44
+ model.inferParams = {};
45
+ }
46
+ if (settings?.model && !conf?.model?.name) {
47
+ model.name = settings.model;
48
+ }
49
+ if (settings?.template && !conf?.model?.template) {
50
+ model.template = settings.template;
51
+ }
52
+ if (settings?.ctx && !conf?.model?.ctx) {
53
+ model.ctx = settings.ctx;
54
+ }
55
+ if (settings?.max_tokens && !conf?.inferParams?.max_tokens) {
56
+ model.inferParams.max_tokens = settings.max_tokens;
57
+ }
58
+ if (settings?.top_k && !conf?.inferParams?.top_k) {
59
+ model.inferParams.top_k = settings.top_k;
60
+ }
61
+ if (settings?.top_p && !conf?.inferParams?.top_p) {
62
+ model.inferParams.top_p = settings.top_p;
63
+ }
64
+ if (settings?.min_p && !conf?.inferParams?.min_p) {
65
+ model.inferParams.min_p = settings.min_p;
66
+ }
67
+ if (settings?.temperature && !conf?.inferParams?.temperature) {
68
+ model.inferParams.temperature = settings.temperature;
69
+ }
70
+ if (settings?.repeat_penalty && !conf?.inferParams?.repeat_penalty) {
71
+ model.inferParams.repeat_penalty = settings.repeat_penalty;
72
+ }
73
+ }
30
74
  if (model?.inferParams?.tsGrammar) {
31
75
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
32
76
  delete model.inferParams.tsGrammar;
@@ -22,7 +22,6 @@ function readFeaturesDir(dir) {
22
22
  cmd: [],
23
23
  workflow: [],
24
24
  adaptater: [],
25
- modelfile: []
26
25
  };
27
26
  let dirpath = path.join(dir, "tasks");
28
27
  if (fs.existsSync(dirpath)) {
@@ -94,20 +93,6 @@ function readFeaturesDir(dir) {
94
93
  });
95
94
  });
96
95
  }
97
- dirpath = path.join(dir, "models");
98
- if (fs.existsSync(dirpath)) {
99
- const data = _readDir(dirpath, [".yml"]);
100
- data.forEach((filename) => {
101
- const parts = filename.split(".");
102
- const ext = parts.pop();
103
- const name = parts.join("");
104
- feats.modelfile.push({
105
- name: name,
106
- path: path.join(dirpath),
107
- ext: ext,
108
- });
109
- });
110
- }
111
96
  return feats;
112
97
  }
113
98
  export { readFeaturesDir };
package/dist/conf.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { readConf } from "./cmd/sys/read_conf.js";
2
- import { upsertBackends, insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
2
+ import { upsertBackends, insertFeaturesPathIfNotExists, insertPluginIfNotExists, upsertTaskSettings, deleteTaskSettings } from "./db/write.js";
3
3
  import { buildPluginsPaths } from "./state/plugins.js";
4
4
  import { runtimeError } from "./cmd/lib/user_msgs.js";
5
5
  import { localBackends } from "./const.js";
6
6
  import { homedir } from 'os';
7
7
  import { join } from 'path';
8
8
  import { createDirectoryIfNotExists } from "./cmd/sys/dirs.js";
9
+ import { initTaskSettings, tasksSettings } from "./state/tasks.js";
9
10
  function getConfigPath(appName, filename) {
10
11
  let confDir;
11
12
  let dbPath;
@@ -93,6 +94,16 @@ async function processConfPath(confPath) {
93
94
  insertPluginIfNotExists(_pl.name, _pl.path);
94
95
  });
95
96
  }
97
+ if (data?.tasks) {
98
+ initTaskSettings();
99
+ const okTasks = new Array();
100
+ for (const [name, settings] of Object.entries(data.tasks)) {
101
+ upsertTaskSettings(name, settings);
102
+ okTasks.push(name);
103
+ }
104
+ const toDel = Object.keys(tasksSettings).filter(t => !okTasks.includes(t));
105
+ deleteTaskSettings(toDel);
106
+ }
96
107
  let pf = "";
97
108
  if (data?.promptfile) {
98
109
  pf = data.promptfile;
package/dist/db/read.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ToolSpec } from "@locallm/types";
2
- import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType, InferenceBackend } from "../interfaces.js";
2
+ import { AliasType, FeatureSpec, FeatureType, ToolType, InferenceBackend } from "../interfaces.js";
3
3
  declare function readFeaturePaths(): Array<string>;
4
4
  declare function readBackends(): Record<string, InferenceBackend>;
5
5
  declare function readPlugins(): Array<Record<string, string>>;
@@ -26,10 +26,9 @@ declare function readFilePath(name: string): {
26
26
  found: boolean;
27
27
  path: string;
28
28
  };
29
- declare function readModelfiles(): Array<Record<string, string>>;
30
- declare function readModels(): Array<DbModelDef>;
31
- declare function readModel(shortname: string): {
29
+ declare function readTaskSettings(): Array<Record<string, any>>;
30
+ declare function readTaskSetting(name: string): {
32
31
  found: boolean;
33
- modelData: Record<string, any>;
32
+ settings: Record<string, string>;
34
33
  };
35
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, readBackends, };
34
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readFeaturesType, readBackends, readTaskSettings, readTaskSetting, };
package/dist/db/read.js CHANGED
@@ -43,14 +43,13 @@ function readFeaturesType(type) {
43
43
  }
44
44
  function readFeatures() {
45
45
  const feats = {
46
- task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {}, modelfile: {}
46
+ task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {}
47
47
  };
48
48
  feats.task = readFeaturesType("task");
49
49
  feats.action = readFeaturesType("action");
50
50
  feats.cmd = readFeaturesType("cmd");
51
51
  feats.workflow = readFeaturesType("workflow");
52
52
  feats.adaptater = readFeaturesType("adaptater");
53
- feats.modelfile = readFeaturesType("modelfile");
54
53
  return feats;
55
54
  }
56
55
  function readAliases() {
@@ -110,38 +109,18 @@ function readFilePath(name) {
110
109
  }
111
110
  return { found: false, path: "" };
112
111
  }
113
- function readModelfiles() {
114
- const stmt = db.prepare("SELECT name, path, ext FROM modelfile");
115
- const data = stmt.all();
116
- let f = new Array();
117
- data.forEach((row) => {
118
- f.push(row);
119
- });
120
- return f;
121
- }
122
- function readModels() {
123
- const stmt = db.prepare("SELECT name, shortname, data FROM model");
124
- const data = stmt.all();
125
- let f = new Array();
126
- data.forEach((row) => {
127
- const ips = JSON.parse(row.data);
128
- const mod = {
129
- name: row.name,
130
- shortname: row.shortname,
131
- data: ips,
132
- };
133
- f.push(mod);
134
- });
135
- return f;
112
+ function readTaskSettings() {
113
+ const stmt1 = db.prepare("SELECT * FROM tasksettings ORDER BY name");
114
+ const data = stmt1.all();
115
+ return data;
136
116
  }
137
- function readModel(shortname) {
138
- const q = `SELECT id, data FROM model WHERE shortname='${shortname}'`;
117
+ function readTaskSetting(name) {
118
+ const q = "SELECT * FROM tasksettings WHERE name= ?";
139
119
  const stmt = db.prepare(q);
140
- const result = stmt.get();
120
+ const result = stmt.get(name);
141
121
  if (result?.id) {
142
- const data = JSON.parse(result.data);
143
- return { found: true, modelData: data };
122
+ return { found: true, settings: result };
144
123
  }
145
- return { found: false, modelData: {} };
124
+ return { found: false, settings: {} };
146
125
  }
147
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, readBackends, };
126
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readFeaturesType, readBackends, readTaskSettings, readTaskSetting, };
@@ -58,19 +58,6 @@ const alias = `CREATE TABLE IF NOT EXISTS aliases (
58
58
  name TEXT UNIQUE NOT NULL,
59
59
  type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
60
60
  );`;
61
- const modelfile = `CREATE TABLE IF NOT EXISTS modelfile (
62
- id INTEGER PRIMARY KEY AUTOINCREMENT,
63
- name TEXT UNIQUE NOT NULL,
64
- path TEXT NOT NULL,
65
- variables TEXT,
66
- ext TEXT NOT NULL CHECK ( ext IN ('yml') )
67
- );`;
68
- const model = `CREATE TABLE IF NOT EXISTS model (
69
- id INTEGER PRIMARY KEY AUTOINCREMENT,
70
- name TEXT NOT NULL,
71
- shortname TEXT UNIQUE NOT NULL,
72
- data TEXT NOT NULL
73
- );`;
74
61
  const backend = `CREATE TABLE IF NOT EXISTS backend (
75
62
  id INTEGER PRIMARY KEY AUTOINCREMENT,
76
63
  name TEXT UNIQUE NOT NULL,
@@ -79,6 +66,20 @@ const backend = `CREATE TABLE IF NOT EXISTS backend (
79
66
  isdefault INTEGER NOT NULL,
80
67
  apiKey TEXT
81
68
  );`;
69
+ const tasksSettings = `CREATE TABLE IF NOT EXISTS tasksettings (
70
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
71
+ name TEXT UNIQUE NOT NULL,
72
+ model TEXT,
73
+ template TEXT,
74
+ ctx INTEGER,
75
+ maxtokens INTEGER
76
+ topk INTEGER,
77
+ topp REAL,
78
+ minp REAL,
79
+ temperature REAL,
80
+ repeat REAL,
81
+ backend TEXT
82
+ );`;
82
83
  const schemas = [
83
84
  filepath,
84
85
  featurespath,
@@ -89,9 +90,8 @@ const schemas = [
89
90
  cmd,
90
91
  plugin,
91
92
  alias,
92
- model,
93
- modelfile,
94
93
  adaptater,
95
94
  backend,
95
+ tasksSettings,
96
96
  ];
97
97
  export { schemas };
@@ -1,4 +1,4 @@
1
- import { Features, DbModelDef, InferenceBackend } from "../interfaces.js";
1
+ import { Features, InferenceBackend, TaskSettings } from "../interfaces.js";
2
2
  declare function updatePromptfilePath(pf: string): void;
3
3
  declare function updateDataDirPath(dd: string): void;
4
4
  declare function setDefaultBackend(name: string): void;
@@ -7,7 +7,9 @@ declare function insertFeaturesPathIfNotExists(path: string): boolean;
7
7
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
8
8
  declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
9
9
  declare function updateAliases(feats: Features): void;
10
- declare function updateModels(models: Array<DbModelDef>): void;
11
10
  declare function updateFeatures(feats: Features): void;
12
11
  declare function upsertFilePath(name: string, newPath: string): boolean;
13
- export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
12
+ declare function upsertTaskSettings(taskName: string, settings: TaskSettings): boolean;
13
+ declare function deleteTaskSettings(settings: Array<string>): void;
14
+ declare function deleteTaskSetting(name: string): void;
15
+ export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertFilePath, upsertTaskSettings, deleteTaskSettings, deleteTaskSetting, };
package/dist/db/write.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { extractTaskToolDocAndVariables, extractToolDoc } from "../cmd/lib/tools.js";
2
2
  import { db } from "./db.js";
3
- import { readModels } from "./read.js";
4
3
  function updatePromptfilePath(pf) {
5
4
  const deleteStmt = db.prepare("DELETE FROM filepath WHERE name = ?");
6
5
  deleteStmt.run("promptfile");
@@ -145,7 +144,6 @@ function updateVariables(name, variableDoc) {
145
144
  }
146
145
  const updateStmt = db.prepare("UPDATE task SET variables = ? WHERE id = ?");
147
146
  updateStmt.run(variableDoc, result.id);
148
- console.log("~", "[task variables] updated for", name);
149
147
  }
150
148
  function upsertTool(name, type, toolDoc) {
151
149
  const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
@@ -153,39 +151,12 @@ function upsertTool(name, type, toolDoc) {
153
151
  if (result?.id) {
154
152
  const updateStmt = db.prepare("UPDATE tool SET spec = ?, type = ? WHERE id = ?");
155
153
  updateStmt.run(toolDoc, type, result.id);
156
- console.log("~", "[tool] updated from", type, ":", name);
157
154
  }
158
155
  else {
159
156
  const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
160
157
  stmt.run(name, toolDoc, type);
161
- console.log("+", "[tool] added from", type, ":", name);
162
158
  }
163
159
  }
164
- function updateModels(models) {
165
- const allDbModels = readModels();
166
- const existingModelShortNames = allDbModels.map(row => row.shortname);
167
- const newModelShortNames = models.filter(m => !existingModelShortNames.includes(m.shortname)).map(m => m.shortname);
168
- const mm = models.map(m => m.shortname);
169
- const modelsToDelete = existingModelShortNames.filter(name => !mm.includes(name));
170
- db.transaction(() => {
171
- for (const model of models) {
172
- if (!existingModelShortNames.includes(model.shortname)) {
173
- const insertStmt = db.prepare("INSERT INTO model (name, shortname, data) VALUES (?, ?, ?)");
174
- insertStmt.run(model.name, model.shortname, JSON.stringify(model.data));
175
- console.log("+", "[model]", model.name);
176
- }
177
- else {
178
- const updateStmt = db.prepare("UPDATE model SET name = ?, data = ? WHERE shortname = ?");
179
- updateStmt.run(model.name, JSON.stringify(model.data), model.shortname);
180
- }
181
- }
182
- for (const name of modelsToDelete) {
183
- const deleteStmt = db.prepare("DELETE FROM model WHERE shortname = ?");
184
- deleteStmt.run(name);
185
- console.log("-", "[model]", name);
186
- }
187
- })();
188
- }
189
160
  function updateFeatures(feats) {
190
161
  upsertAndCleanFeatures(feats.task, "task");
191
162
  feats.task.forEach((feat) => {
@@ -213,7 +184,6 @@ function updateFeatures(feats) {
213
184
  });
214
185
  upsertAndCleanFeatures(feats.adaptater, "adaptater");
215
186
  upsertAndCleanFeatures(feats.cmd, "cmd");
216
- upsertAndCleanFeatures(feats.modelfile, "modelfile");
217
187
  }
218
188
  function upsertFilePath(name, newPath) {
219
189
  const selectStmt = db.prepare("SELECT * FROM filepath WHERE name = ?");
@@ -230,4 +200,117 @@ function upsertFilePath(name, newPath) {
230
200
  return true;
231
201
  }
232
202
  }
233
- export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
203
+ function upsertTaskSettings(taskName, settings) {
204
+ const selectStmt = db.prepare("SELECT * FROM tasksettings WHERE name = ?");
205
+ const result = selectStmt.get(taskName);
206
+ if (result?.id) {
207
+ const qparams = new Array();
208
+ const qvalues = new Array();
209
+ if (settings?.model) {
210
+ qparams.push("model = ?");
211
+ qvalues.push(settings.model);
212
+ }
213
+ if (settings?.template) {
214
+ qparams.push("template = ?");
215
+ qvalues.push(settings.template);
216
+ }
217
+ if (settings?.ctx) {
218
+ qparams.push("ctx = ?");
219
+ qvalues.push(settings.ctx);
220
+ }
221
+ if (settings?.max_tokens) {
222
+ qparams.push("maxtokens = ?");
223
+ qvalues.push(settings.max_tokens);
224
+ }
225
+ if (settings?.top_k) {
226
+ qparams.push("topk = ?");
227
+ qvalues.push(settings.top_k);
228
+ }
229
+ if (settings?.top_p) {
230
+ qparams.push("topp = ?");
231
+ qvalues.push(settings.top_p);
232
+ }
233
+ if (settings?.min_p) {
234
+ qparams.push("minp = ?");
235
+ qvalues.push(settings.min_p);
236
+ }
237
+ if (settings?.temperature) {
238
+ qparams.push("temperature = ?");
239
+ qvalues.push(settings.temperature);
240
+ }
241
+ if (settings?.repeat_penalty) {
242
+ qparams.push("repeat = ?");
243
+ qvalues.push(settings.repeat_penalty);
244
+ }
245
+ if (settings?.backend) {
246
+ qparams.push("backend = ?");
247
+ qvalues.push(settings.backend);
248
+ }
249
+ const q = `UPDATE tasksettings SET ${qparams.join(", ")} WHERE name = ?`;
250
+ const stmt = db.prepare(q);
251
+ const updateResult = stmt.run(...qvalues, taskName);
252
+ return updateResult.changes > 0;
253
+ }
254
+ else {
255
+ const qnames = new Array();
256
+ const qvalues = new Array();
257
+ if (settings?.model) {
258
+ qnames.push("model");
259
+ qvalues.push(settings.model);
260
+ }
261
+ if (settings?.template) {
262
+ qnames.push("template");
263
+ qvalues.push(settings.template);
264
+ }
265
+ if (settings?.ctx) {
266
+ qnames.push("ctx");
267
+ qvalues.push(settings.ctx);
268
+ }
269
+ if (settings?.max_tokens) {
270
+ qnames.push("maxtokens");
271
+ qvalues.push(settings.max_tokens);
272
+ }
273
+ if (settings?.top_k) {
274
+ qnames.push("topk");
275
+ qvalues.push(settings.top_k);
276
+ }
277
+ if (settings?.top_p) {
278
+ qnames.push("topp");
279
+ qvalues.push(settings.top_p);
280
+ }
281
+ if (settings?.min_p) {
282
+ qnames.push("minp");
283
+ qvalues.push(settings.min_p);
284
+ }
285
+ if (settings?.temperature) {
286
+ qnames.push("temperature");
287
+ qvalues.push(settings.temperature);
288
+ }
289
+ if (settings?.repeat_penalty) {
290
+ qnames.push("repeat");
291
+ qvalues.push(settings.repeat_penalty);
292
+ }
293
+ if (settings?.backend) {
294
+ qnames.push("backend");
295
+ qvalues.push(settings.backend);
296
+ }
297
+ const nq = new Array("?");
298
+ qnames.forEach(n => nq.push("?"));
299
+ const q = `INSERT INTO tasksettings (name, ${qnames.join(", ")}) VALUES (${nq.join(", ")})`;
300
+ console.log(q);
301
+ const insertStmt = db.prepare(q);
302
+ insertStmt.run(taskName, ...qvalues);
303
+ return true;
304
+ }
305
+ }
306
+ function deleteTaskSettings(settings) {
307
+ settings.forEach(s => {
308
+ const deleteStmt = db.prepare("DELETE FROM tasksettings WHERE name = ?");
309
+ deleteStmt.run(s);
310
+ });
311
+ }
312
+ function deleteTaskSetting(name) {
313
+ const deleteStmt = db.prepare("DELETE FROM tasksettings WHERE name = ?");
314
+ deleteStmt.run(name);
315
+ }
316
+ export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertFilePath, upsertTaskSettings, deleteTaskSettings, deleteTaskSetting, };
@@ -33,11 +33,6 @@ interface Features {
33
33
  path: string;
34
34
  ext: AdaptaterExtension;
35
35
  }>;
36
- modelfile: Array<{
37
- name: string;
38
- path: string;
39
- ext: ModelFileExtension;
40
- }>;
41
36
  }
42
37
  interface ConfInferenceBackend {
43
38
  type: LmProviderType;
@@ -57,6 +52,7 @@ interface ConfigFile {
57
52
  features?: Array<string>;
58
53
  plugins?: Array<string>;
59
54
  backends?: BackendEntries;
55
+ tasks?: Record<string, TaskSettings>;
60
56
  }
61
57
  interface Settings {
62
58
  name: string;
@@ -122,20 +118,31 @@ interface McpServerTool {
122
118
  required: string[];
123
119
  };
124
120
  }
121
+ interface TaskSettings {
122
+ model?: string;
123
+ template?: string;
124
+ ctx?: number;
125
+ max_tokens?: number;
126
+ top_k?: number;
127
+ top_p?: number;
128
+ min_p?: number;
129
+ temperature?: number;
130
+ repeat_penalty?: number;
131
+ backend?: string;
132
+ }
125
133
  type InputMode = "manual" | "promptfile" | "clipboard";
126
134
  type OutputMode = "txt" | "clipboard";
127
135
  type RunMode = "cli" | "cmd";
128
136
  type FormatMode = "text" | "markdown";
129
137
  type VerbosityMode = "quiet" | "verbose" | "debug";
130
- type FeatureType = "task" | "action" | "cmd" | "workflow" | "adaptater" | "modelfile";
138
+ type FeatureType = "task" | "action" | "cmd" | "workflow" | "adaptater";
131
139
  type ToolType = "task" | "action" | "cmd" | "workflow";
132
140
  type ActionExtension = "js" | "mjs" | "py" | "yml";
133
141
  type TaskExtension = "yml";
134
142
  type AdaptaterExtension = "js";
135
143
  type WorkflowExtension = "yml";
136
144
  type CmdExtension = "js";
137
- type ModelFileExtension = "yml";
138
- type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
145
+ type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension;
139
146
  type AliasType = "task" | "action" | "workflow";
140
147
  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, };
148
+ export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, InferenceBackend, ConfInferenceBackend, FeatureExecutor, WorkflowStep, TaskSettings, };
@@ -8,7 +8,6 @@ function readFeaturesDirs(featuresPaths) {
8
8
  cmd: [],
9
9
  workflow: [],
10
10
  adaptater: [],
11
- modelfile: [],
12
11
  };
13
12
  featuresPaths.forEach((dir) => {
14
13
  const _f = readFeaturesDir(dir);
@@ -17,7 +16,6 @@ function readFeaturesDirs(featuresPaths) {
17
16
  _f.cmd.forEach((item) => feats.cmd.push(item));
18
17
  _f.workflow.forEach((item) => feats.workflow.push(item));
19
18
  _f.adaptater.forEach((item) => feats.adaptater.push(item));
20
- _f.modelfile.forEach((item) => feats.modelfile.push(item));
21
19
  });
22
20
  return feats;
23
21
  }
@@ -0,0 +1,5 @@
1
+ import { TaskSettings } from "../interfaces.js";
2
+ declare const tasksSettings: Record<string, TaskSettings>;
3
+ declare const isTaskSettingsInitialized: import("@vue/reactivity").Ref<boolean, boolean>;
4
+ declare function initTaskSettings(): void;
5
+ export { tasksSettings, initTaskSettings, isTaskSettingsInitialized, };
@@ -0,0 +1,21 @@
1
+ import { ref } from "@vue/reactivity";
2
+ import { readTaskSettings } from "../db/read.js";
3
+ const tasksSettings = {};
4
+ const isTaskSettingsInitialized = ref(false);
5
+ function initTaskSettings() {
6
+ const data = readTaskSettings();
7
+ data.forEach(row => {
8
+ const name = row.name;
9
+ delete row.name;
10
+ delete row.id;
11
+ const vals = {};
12
+ for (const [k, v] of Object.entries(row)) {
13
+ if (v !== null) {
14
+ vals[k] = v;
15
+ }
16
+ }
17
+ tasksSettings[name] = vals;
18
+ });
19
+ isTaskSettingsInitialized.value = true;
20
+ }
21
+ export { tasksSettings, initTaskSettings, isTaskSettingsInitialized, };
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.95",
5
+ "version": "0.0.96",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,17 +10,17 @@
10
10
  "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/agent": "^0.1.4",
14
- "@agent-smith/task": "^0.1.6",
13
+ "@agent-smith/agent": "^0.1.5",
14
+ "@agent-smith/task": "^0.1.7",
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.1",
18
+ "@locallm/api": "^0.7.2",
19
19
  "@modelcontextprotocol/sdk": "^1.24.3",
20
20
  "@vue/reactivity": "^3.5.25",
21
21
  "ansi-colors": "^4.1.3",
22
22
  "better-sqlite3": "^12.5.0",
23
- "clipboardy": "^5.0.1",
23
+ "clipboardy": "^5.0.2",
24
24
  "commander": "^14.0.2",
25
25
  "marked-terminal": "^7.3.0",
26
26
  "modprompt": "^0.12.6",
@@ -32,12 +32,12 @@
32
32
  "@agent-smith/tmem-jobs": "^0.0.4",
33
33
  "@cfworker/json-schema": "^4.1.1",
34
34
  "@commander-js/extra-typings": "^14.0.0",
35
- "@locallm/types": "^0.6.2",
35
+ "@locallm/types": "^0.6.4",
36
36
  "@rollup/plugin-node-resolve": "^16.0.3",
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.2",
40
+ "@types/node": "^25.0.2",
41
41
  "openai": "^6.10.0",
42
42
  "restmix": "^0.6.1",
43
43
  "rollup": "^4.53.3",
@@ -64,4 +64,4 @@
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
66
66
  "license": "MIT"
67
- }
67
+ }
@@ -1,3 +0,0 @@
1
- declare function showModelsCmd(args: Array<string>): Promise<void>;
2
- declare function updateAllModels(): void;
3
- export { updateAllModels, showModelsCmd, };
@@ -1,53 +0,0 @@
1
- import path from "path";
2
- import { readModelfiles, readModels } from "../../db/read.js";
3
- import { readModelsFile } from "../sys/read_modelfile.js";
4
- import { updateModels as dbUpdateModels } from "../../db/write.js";
5
- import color from "ansi-colors";
6
- async function showModelsCmd(args) {
7
- let models = readModels();
8
- models.sort((a, b) => a.name.localeCompare(b.name));
9
- let foundModels = new Array();
10
- if (args.length > 0) {
11
- args.forEach((a) => {
12
- const fm = models.filter((m) => m.shortname.includes(a) || m.name.includes(a));
13
- foundModels.push(...fm);
14
- });
15
- }
16
- else {
17
- foundModels = models;
18
- }
19
- foundModels.forEach((model) => {
20
- const ips = model.data.inferParams;
21
- const mt = ips.max_tokens;
22
- delete ips.max_tokens;
23
- const vip = Object.keys(ips).length > 0 ? JSON.stringify(ips) : "";
24
- const m = `- ${color.yellow(model.shortname)}: ${color.bold(model.data.name)} - ${model.data.ctx} ctx / ${mt} max tokens ${vip}`;
25
- console.log(m);
26
- });
27
- }
28
- function updateAllModels() {
29
- const mfs = readModelfiles();
30
- const modelDefs = new Array();
31
- mfs.forEach((mf) => {
32
- const filePath = path.join(mf.path + "/" + mf.name + "." + mf.ext);
33
- const { models, ctx, max_tokens, found } = readModelsFile(filePath);
34
- if (!found) {
35
- throw new Error(`model file ${filePath} not found`);
36
- }
37
- for (const [name, m] of (Object.entries(models))) {
38
- if (!m?.ctx) {
39
- m.ctx = ctx;
40
- }
41
- if (!m?.inferParams) {
42
- m.inferParams = {};
43
- }
44
- if (!m?.inferParams?.max_tokens) {
45
- m.inferParams.max_tokens = max_tokens;
46
- }
47
- const md = { name: m.name, shortname: name, data: m };
48
- modelDefs.push(md);
49
- }
50
- });
51
- dbUpdateModels(modelDefs);
52
- }
53
- export { updateAllModels, showModelsCmd, };
@@ -1,8 +0,0 @@
1
- import { ModelSpec } from "../../interfaces.js";
2
- declare function readModelsFile(fp: string): {
3
- found: boolean;
4
- ctx: number;
5
- max_tokens: number;
6
- models: Record<string, ModelSpec>;
7
- };
8
- export { readModelsFile, };
@@ -1,21 +0,0 @@
1
- import { default as fs } from "fs";
2
- import YAML from 'yaml';
3
- function readModelsFile(fp) {
4
- if (!fs.existsSync(fp)) {
5
- return { models: {}, ctx: 0, max_tokens: 0, found: false };
6
- }
7
- const data = fs.readFileSync(fp, 'utf8');
8
- const m = YAML.parse(data);
9
- if (!m?.ctx) {
10
- throw new Error(`provide a ctx param in models file`);
11
- }
12
- if (!m?.max_tokens) {
13
- throw new Error(`provide a max_tokens param in models file`);
14
- }
15
- const ctx = m.ctx;
16
- const max_tokens = m.max_tokens;
17
- delete m.ctx;
18
- delete m.max_tokens;
19
- return { models: m, ctx: ctx, max_tokens: max_tokens, found: true };
20
- }
21
- export { readModelsFile, };