@agent-smith/cli 0.0.44 → 0.0.45

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 (38) hide show
  1. package/dist/cmd/clicmds/cmds.js +10 -5
  2. package/dist/cmd/lib/actions/cmd.js +3 -1
  3. package/dist/cmd/lib/models.d.ts +2 -0
  4. package/dist/cmd/lib/models.js +35 -0
  5. package/dist/cmd/lib/tasks/cmd.d.ts +2 -2
  6. package/dist/cmd/lib/tasks/cmd.js +33 -64
  7. package/dist/cmd/lib/tasks/conf.d.ts +7 -0
  8. package/dist/cmd/lib/tasks/conf.js +144 -0
  9. package/dist/cmd/lib/utils.d.ts +1 -12
  10. package/dist/cmd/lib/utils.js +5 -167
  11. package/dist/cmd/sys/dirs.d.ts +2 -0
  12. package/dist/cmd/sys/dirs.js +9 -0
  13. package/dist/cmd/sys/read_cmds.js +3 -0
  14. package/dist/cmd/sys/read_features.js +2 -2
  15. package/dist/cmd/sys/read_modelfile.d.ts +8 -0
  16. package/dist/cmd/sys/{read_models.js → read_modelfile.js} +3 -3
  17. package/dist/conf.d.ts +1 -0
  18. package/dist/conf.js +6 -2
  19. package/dist/db/read.d.ts +12 -3
  20. package/dist/db/read.js +39 -9
  21. package/dist/db/schemas.js +8 -1
  22. package/dist/db/write.d.ts +4 -2
  23. package/dist/db/write.js +31 -2
  24. package/dist/interfaces.d.ts +41 -6
  25. package/dist/main.d.ts +6 -2
  26. package/dist/main.js +5 -2
  27. package/dist/primitives/args.d.ts +5 -0
  28. package/dist/primitives/args.js +40 -0
  29. package/dist/primitives/perf.d.ts +7 -0
  30. package/dist/primitives/perf.js +38 -0
  31. package/dist/state/chat.d.ts +2 -0
  32. package/dist/state/features.js +2 -2
  33. package/dist/state/state.d.ts +3 -1
  34. package/dist/state/state.js +29 -3
  35. package/package.json +10 -11
  36. package/dist/cmd/sys/read_models.d.ts +0 -7
  37. /package/dist/cmd/sys/{reset.d.ts → delete_file.d.ts} +0 -0
  38. /package/dist/cmd/sys/{reset.js → delete_file.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  import YAML from 'yaml';
2
- import { formatMode, isChatMode, promptfilePath, runMode } from "../../state/state.js";
2
+ import { dataDirPath, formatMode, isChatMode, promptfilePath, runMode } from "../../state/state.js";
3
3
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
4
4
  import { readAliases, readFeatures } from "../../db/read.js";
5
- import { cleanupFeaturePaths, updateAliases, updateFeatures, updatePromptfilePath } from "../../db/write.js";
5
+ import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath } from "../../db/write.js";
6
6
  import { processConfPath } from "../../conf.js";
7
7
  import { executeActionCmd } from "../lib/actions/cmd.js";
8
8
  import { initAgent, marked, taskBuilder } from "../../agent.js";
@@ -10,7 +10,7 @@ import { executeTaskCmd } from "../lib/tasks/cmd.js";
10
10
  import { readCmds } from "../sys/read_cmds.js";
11
11
  import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
12
12
  import { readTask } from "../sys/read_task.js";
13
- import { deleteFileIfExists } from "../sys/reset.js";
13
+ import { deleteFileIfExists } from "../sys/delete_file.js";
14
14
  import { dbPath } from "../../db/db.js";
15
15
  let cmds = {
16
16
  exit: {
@@ -82,11 +82,15 @@ async function _updateConfCmd(args = [], options) {
82
82
  console.warn("Provide a config.yml file path");
83
83
  return;
84
84
  }
85
- const { paths, pf } = await processConfPath(args[0]);
85
+ const { paths, pf, dd } = await processConfPath(args[0]);
86
86
  if (pf.length > 0) {
87
87
  updatePromptfilePath(pf);
88
88
  promptfilePath.value = pf;
89
89
  }
90
+ if (dd.length > 0) {
91
+ updateDataDirPath(dd);
92
+ dataDirPath.value = dd;
93
+ }
90
94
  const feats = readFeaturesDirs(paths);
91
95
  updateFeatures(feats);
92
96
  updateAliases(feats);
@@ -147,6 +151,7 @@ async function _readTaskCmd(args = [], options) {
147
151
  console.log(YAML.stringify(ts));
148
152
  }
149
153
  async function _listTasksCmd(args = [], options) {
150
- Object.keys(readFeatures().task).forEach((t) => console.log("-", t));
154
+ const ts = Object.keys(readFeatures().task).sort();
155
+ console.table(ts);
151
156
  }
152
157
  export { cmds, initCmds, pingCmd, initAliases };
@@ -80,7 +80,9 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
80
80
  throw res.error;
81
81
  }
82
82
  if (!quiet) {
83
- console.log(res);
83
+ if (res) {
84
+ console.log(res);
85
+ }
84
86
  }
85
87
  await processOutput(res);
86
88
  return res;
@@ -0,0 +1,2 @@
1
+ declare function updateModels(): void;
2
+ export { updateModels, };
@@ -0,0 +1,35 @@
1
+ import path from "path";
2
+ import { readModelfiles } from "../../db/read.js";
3
+ import { readModelsFile } from "../sys/read_modelfile.js";
4
+ import { upsertModels } from "../../db/write.js";
5
+ function updateModels() {
6
+ const mfs = readModelfiles();
7
+ const modelNames = new Array();
8
+ const modelDefs = new Array();
9
+ mfs.forEach((mf) => {
10
+ const filePath = path.join(mf.path + "/" + mf.name + "." + mf.ext);
11
+ const { models, ctx, max_tokens, found } = readModelsFile(filePath);
12
+ if (!found) {
13
+ throw new Error(`model file ${filePath} not found`);
14
+ }
15
+ for (const [name, m] of (Object.entries(models))) {
16
+ if (modelNames.includes(m.name)) {
17
+ console.log("🔴 [models] error: duplicate model name", m.name, "found in", filePath);
18
+ continue;
19
+ }
20
+ if (!m?.ctx) {
21
+ m.ctx = ctx;
22
+ }
23
+ if (!m?.inferParams) {
24
+ m.inferParams = {};
25
+ }
26
+ if (!m?.inferParams?.max_tokens) {
27
+ m.inferParams.max_tokens = max_tokens;
28
+ }
29
+ const md = { name: m.name, shortname: name, data: m };
30
+ modelDefs.push(md);
31
+ }
32
+ upsertModels(modelDefs);
33
+ });
34
+ }
35
+ export { updateModels, };
@@ -1,3 +1,3 @@
1
- import { LmTaskOutput } from "../../../../../lmtask/dist/main.js";
2
- declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<LmTaskOutput>;
1
+ import { LmTaskOutput } from "@agent-smith/lmtask";
2
+ declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: Record<string, any>): Promise<LmTaskOutput>;
3
3
  export { executeTaskCmd };
@@ -1,13 +1,14 @@
1
+ import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
2
+ import YAML from 'yaml';
1
3
  import { brain, initAgent, taskBuilder } from "../../../agent.js";
2
4
  import { getFeatureSpec } from "../../../state/features.js";
3
5
  import { isChatMode, isDebug, isShowTokens, isVerbose } from "../../../state/state.js";
4
- import { formatStats, initTaskConf, initTaskParams, initTaskVars, parseInputOptions } from "../utils.js";
6
+ import { formatStats, parseInputOptions } from "../utils.js";
5
7
  import { readTask } from "../../sys/read_task.js";
6
- import { readFeature, readTool } from "../../../db/read.js";
7
- import { LmTaskBuilder } from "../../../../../lmtask/dist/main.js";
8
+ import { readTool } from "../../../db/read.js";
8
9
  import { executeActionCmd, } from "../actions/cmd.js";
9
10
  import { executeWorkflowCmd } from "../workflows/cmd.js";
10
- import { readModelsFile } from "../../../cmd/sys/read_models.js";
11
+ import { configureTask, parseTaskVars } from "./conf.js";
11
12
  async function executeTaskCmd(args = [], options = {}) {
12
13
  await initAgent();
13
14
  if (isDebug.value) {
@@ -53,48 +54,20 @@ async function executeTaskCmd(args = [], options = {}) {
53
54
  if (!res.found) {
54
55
  throw new Error(`Task ${name}, ${path} not found`);
55
56
  }
56
- const taskRawSpec = taskBuilder.readSpecFromYaml(res.ymlTask);
57
- let taskSpec;
58
- let defaultCtx;
59
- if (taskRawSpec?.modelset) {
60
- const modelsFeat = readFeature(taskRawSpec.modelset.name, "modelset");
61
- if (!modelsFeat.found) {
62
- throw new Error(`modelset feature ${taskRawSpec.modelset.name} not found in conf db`);
63
- }
64
- const { found, ctx, max_tokens, models } = readModelsFile(modelsFeat.feature.path + "/" + modelsFeat.feature.name + "." + modelsFeat.feature.ext);
65
- if (!found) {
66
- throw new Error(`modelset ${taskRawSpec.modelset.name} not found`);
67
- }
68
- defaultCtx = ctx;
69
- for (const [k, v] of Object.entries(models)) {
70
- if (!v?.ctx) {
71
- v.ctx = ctx;
72
- models[k] = v;
73
- }
74
- }
75
- taskRawSpec.model = models[taskRawSpec.modelset.default];
76
- if (!taskRawSpec.model) {
77
- throw new Error(`model ${taskRawSpec.modelset.default} not found`);
78
- }
79
- if (!taskRawSpec.model?.ctx) {
80
- taskRawSpec.model.ctx = ctx;
81
- }
82
- if (!taskRawSpec?.inferParams?.max_tokens) {
83
- if (!taskRawSpec?.inferParams) {
84
- taskRawSpec.inferParams = {};
85
- }
86
- taskRawSpec.inferParams.max_tokens = max_tokens;
87
- }
88
- taskRawSpec.models = models;
89
- taskSpec = LmTaskBuilder.fromRawSpec(taskRawSpec);
57
+ const taskFileSpec = YAML.parse(res.ymlTask);
58
+ let conf = {};
59
+ let vars = {};
60
+ if (!isWorkflow) {
61
+ const tv = parseTaskVars(args, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
62
+ vars = tv.vars;
63
+ conf = configureTask(tv.conf, taskFileSpec);
90
64
  }
91
65
  else {
92
- taskSpec = taskRawSpec;
93
- if (!taskSpec.model?.ctx) {
94
- throw new Error(`provide a ctx parameter in the task default model`);
95
- }
96
- defaultCtx = taskSpec.model.ctx;
66
+ const tv = parseTaskVars({ name: name, prompt: pr, ...args }, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
67
+ vars = tv.vars;
68
+ conf = configureTask(tv.conf, taskFileSpec);
97
69
  }
70
+ const taskSpec = taskFileSpec;
98
71
  if (taskSpec.toolsList) {
99
72
  taskSpec.tools = [];
100
73
  for (const toolName of taskSpec.toolsList) {
@@ -127,19 +100,10 @@ async function executeTaskCmd(args = [], options = {}) {
127
100
  }
128
101
  ;
129
102
  const task = taskBuilder.init(taskSpec);
130
- let conf = {};
131
- let vars = {};
132
- if (!isWorkflow) {
133
- const tv = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
134
- conf = tv.conf;
135
- vars = tv.vars;
103
+ if (conf?.inferParams?.tsGrammar) {
104
+ conf.inferParams.grammar = serializeGrammar(await compile(conf.inferParams.tsGrammar, "Grammar"));
105
+ delete conf.inferParams.tsGrammar;
136
106
  }
137
- else {
138
- const tv = initTaskParams({ name: name, prompt: pr, ...args }, taskSpec?.inferParams ? taskSpec.inferParams : {});
139
- conf = tv.conf;
140
- vars = tv.vars;
141
- }
142
- conf = initTaskConf(conf, taskSpec, defaultCtx);
143
107
  if (isDebug.value) {
144
108
  console.log("Task conf:", conf);
145
109
  console.log("Task vars:", vars);
@@ -151,15 +115,20 @@ async function executeTaskCmd(args = [], options = {}) {
151
115
  ex.checkStatus();
152
116
  let i = 0;
153
117
  let c = false;
154
- ex.backend.setOnToken((t) => {
155
- let txt = t;
156
- if (isShowTokens.value) {
157
- txt = c ? t : `\x1b[100m${t}\x1b[0m`;
158
- }
159
- process.stdout.write(txt);
160
- ++i;
161
- c = !c;
162
- });
118
+ if (options?.onToken) {
119
+ ex.backend.setOnToken(options.onToken);
120
+ }
121
+ else {
122
+ ex.backend.setOnToken((t) => {
123
+ let txt = t;
124
+ if (isShowTokens.value) {
125
+ txt = c ? t : `\x1b[100m${t}\x1b[0m`;
126
+ }
127
+ process.stdout.write(txt);
128
+ ++i;
129
+ c = !c;
130
+ });
131
+ }
163
132
  conf.expert = ex;
164
133
  if (isDebug.value || isVerbose.value) {
165
134
  conf.debug = true;
@@ -0,0 +1,7 @@
1
+ import { LmTaskConfig, FinalLmTaskConfig, LmTaskFileSpec } from "../../../interfaces.js";
2
+ declare function configureTask(itConf: LmTaskConfig, taskSpec: LmTaskFileSpec): FinalLmTaskConfig;
3
+ declare function parseTaskVars(params: Array<any> | Record<string, any>, inferParams: Record<string, any>): {
4
+ conf: LmTaskConfig;
5
+ vars: Record<string, any>;
6
+ };
7
+ export { parseTaskVars, configureTask, };
@@ -0,0 +1,144 @@
1
+ import { readModel } from "../../../db/read.js";
2
+ function configureTask(itConf, taskSpec) {
3
+ const _conf = {};
4
+ let modelName = "";
5
+ let templateName = "";
6
+ let ip = itConf.inferParams;
7
+ let isModelFromTaskFile = false;
8
+ let model = {};
9
+ let found = false;
10
+ if (itConf?.templateName) {
11
+ templateName = itConf.templateName;
12
+ }
13
+ if (!itConf?.modelname) {
14
+ if (taskSpec?.model?.name) {
15
+ model = taskSpec.model;
16
+ isModelFromTaskFile = true;
17
+ found = true;
18
+ }
19
+ else {
20
+ if (!taskSpec?.modelpack) {
21
+ throw new Error("provide a default model or a use a modelpack in the task definition");
22
+ }
23
+ modelName = taskSpec.modelpack.default;
24
+ }
25
+ }
26
+ else {
27
+ modelName = itConf.modelname;
28
+ }
29
+ if (!found) {
30
+ if (modelName.length == 0) {
31
+ throw new Error("no model name defined");
32
+ }
33
+ if (taskSpec?.models) {
34
+ for (const [k, v] of Object.entries(taskSpec.models)) {
35
+ if (modelName == k) {
36
+ model = v;
37
+ if (v?.inferParams) {
38
+ const tip = v.inferParams;
39
+ for (const [k, v] of Object.entries(tip)) {
40
+ ip[k] = v;
41
+ }
42
+ }
43
+ if (v?.system) {
44
+ model.system = v.system;
45
+ }
46
+ if (v.assistant) {
47
+ model.assistant = v.assistant;
48
+ }
49
+ isModelFromTaskFile = true;
50
+ found = true;
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ if (!found) {
56
+ const m = readModel(modelName);
57
+ if (m.found) {
58
+ model = m.modelData;
59
+ found = true;
60
+ }
61
+ }
62
+ }
63
+ if (found) {
64
+ model.inferParams = ip;
65
+ if (!model?.ctx || !isModelFromTaskFile) {
66
+ model.ctx = taskSpec.ctx;
67
+ }
68
+ _conf.model = model;
69
+ _conf.model.inferParams = ip;
70
+ if (templateName.length > 0) {
71
+ _conf.model.template = templateName;
72
+ }
73
+ }
74
+ else {
75
+ _conf.modelname = modelName;
76
+ }
77
+ return _conf;
78
+ }
79
+ function parseTaskVars(params, inferParams) {
80
+ switch (Array.isArray(params)) {
81
+ case true:
82
+ return _initTaskVars(params, inferParams);
83
+ default:
84
+ return _initTaskParams(params, inferParams);
85
+ }
86
+ }
87
+ function _initTaskParams(params, inferParams) {
88
+ const conf = { inferParams: inferParams, modelname: "", templateName: "" };
89
+ if (!params?.prompt) {
90
+ throw new Error(`Error initializing task params: provide a prompt`);
91
+ }
92
+ if (params?.images) {
93
+ conf.inferParams.images = params.images;
94
+ delete params.images;
95
+ }
96
+ if (params?.model) {
97
+ conf.modelname = params.model;
98
+ delete params.model;
99
+ }
100
+ if (params?.template) {
101
+ conf.templateName = params.template;
102
+ delete params.template;
103
+ }
104
+ const res = { conf: conf, vars: params };
105
+ return res;
106
+ }
107
+ function _initTaskVars(args, inferParams) {
108
+ const conf = { inferParams: inferParams, modelname: "", templateName: "" };
109
+ const vars = {};
110
+ args.forEach((a) => {
111
+ if (a.includes("=")) {
112
+ const delimiter = "=";
113
+ const [k, v] = a.split(delimiter, 2);
114
+ if (v === undefined) {
115
+ throw new Error(`invalid parameter ${a}`);
116
+ }
117
+ switch (k) {
118
+ case "m":
119
+ if (v.includes("/")) {
120
+ const _s = v.split("/");
121
+ conf.modelname = _s[0];
122
+ conf.templateName = _s[1];
123
+ }
124
+ else {
125
+ conf.modelname = v;
126
+ }
127
+ break;
128
+ case "ip":
129
+ v.split(",").forEach((p) => {
130
+ const s = p.split(":");
131
+ const cip = conf.inferParams;
132
+ cip[s[0]] = parseFloat(s[1]);
133
+ conf.inferParams = cip;
134
+ });
135
+ break;
136
+ default:
137
+ vars[k] = v;
138
+ break;
139
+ }
140
+ }
141
+ });
142
+ return { conf, vars };
143
+ }
144
+ export { parseTaskVars, configureTask, };
@@ -1,18 +1,7 @@
1
- import { LmTask } from "@agent-smith/lmtask";
2
1
  import { InferenceStats } from "@locallm/types/dist/interfaces.js";
3
2
  declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
4
3
  declare function readPromptFile(): string;
5
4
  declare function processOutput(res: any): Promise<void>;
6
- declare function initTaskConf(conf: Record<string, any>, taskSpec: LmTask, defaultCtx: number): Record<string, any>;
7
- declare function initTaskParams(params: Record<string, any>, inferParams: Record<string, any>): {
8
- conf: Record<string, any>;
9
- vars: Record<string, any>;
10
- };
11
- declare function initActionVars(args: Array<any>): Record<string, any>;
12
- declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>): {
13
- conf: Record<string, any>;
14
- vars: Record<string, any>;
15
- };
16
5
  declare function parseInputOptions(options: any): Promise<string | null>;
17
6
  declare function formatStats(stats: InferenceStats): string;
18
- export { initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
7
+ export { parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
@@ -34,9 +34,12 @@ async function processOutput(res) {
34
34
  }
35
35
  let data = "";
36
36
  if (typeof res == "object") {
37
- if (res?.answer && res?.stats) {
37
+ if (res?.answer?.text) {
38
38
  data = res.answer.text;
39
39
  }
40
+ else {
41
+ data = JSON.stringify(res);
42
+ }
40
43
  }
41
44
  else {
42
45
  data = res;
@@ -48,171 +51,6 @@ async function processOutput(res) {
48
51
  await writeToClipboard(data);
49
52
  }
50
53
  }
51
- function initTaskConf(conf, taskSpec, defaultCtx) {
52
- const _conf = conf;
53
- let m = taskSpec.model.name;
54
- let t = taskSpec.model.template;
55
- let c = taskSpec.model?.ctx ?? defaultCtx;
56
- let ip = conf.inferParams;
57
- let system = taskSpec.model?.system;
58
- let assistant = taskSpec.model?.assistant;
59
- if (conf?.model) {
60
- m = conf.model;
61
- if (conf?.template) {
62
- t = conf.template;
63
- }
64
- else {
65
- const gt = tfm.guess(m);
66
- if (gt == "none") {
67
- throw new Error(`Unable to guess the template for ${m}: please provide a template name"`);
68
- }
69
- t = gt;
70
- }
71
- }
72
- else {
73
- if (conf?.size) {
74
- if (!taskSpec?.models) {
75
- throw new Error(`Model ${conf.size} not found in task`);
76
- }
77
- if (!Object.keys(taskSpec.models).includes(conf.size)) {
78
- throw new Error(`Model ${conf.size} not found in task`);
79
- }
80
- m = taskSpec.models[conf.size].name;
81
- t = taskSpec.models[conf.size].template;
82
- c = taskSpec.models[conf.size]?.ctx ?? defaultCtx;
83
- if (taskSpec.models[conf.size]?.inferParams) {
84
- const tip = taskSpec.models[conf.size].inferParams;
85
- for (const [k, v] of Object.entries(tip)) {
86
- ip[k] = v;
87
- }
88
- }
89
- system = taskSpec.models[conf.size]?.system;
90
- assistant = taskSpec.models[conf.size]?.assistant;
91
- }
92
- }
93
- _conf.model = {
94
- name: m,
95
- template: t,
96
- ctx: c,
97
- };
98
- if (system) {
99
- _conf.model.system = system;
100
- }
101
- if (assistant) {
102
- _conf.model.assistant = assistant;
103
- }
104
- _conf.inferParams = ip;
105
- if (_conf?.template) {
106
- delete conf.template;
107
- }
108
- return _conf;
109
- }
110
- function initTaskParams(params, inferParams) {
111
- const conf = { inferParams: inferParams };
112
- if (!params?.prompt) {
113
- throw new Error(`Error initializing task params: provide a prompt`);
114
- }
115
- if (params?.images) {
116
- conf.inferParams.images = params.images;
117
- delete params.images;
118
- }
119
- if (params?.size) {
120
- conf.size = params.size;
121
- delete params.size;
122
- }
123
- if (params?.model) {
124
- conf.model = params.model;
125
- delete params.model;
126
- }
127
- if (params?.template) {
128
- conf.template = params.template;
129
- delete params.template;
130
- }
131
- const res = { conf: conf, vars: params };
132
- return res;
133
- }
134
- function initActionVars(args) {
135
- const vars = {};
136
- args.forEach((a) => {
137
- if (a.includes("=")) {
138
- const t = a.split("=");
139
- const k = t[0];
140
- const v = t[1];
141
- switch (k) {
142
- case "m":
143
- if (v.includes("/")) {
144
- const _s = v.split("/");
145
- vars.model = _s[0];
146
- vars.template = _s[1];
147
- }
148
- else {
149
- vars.model = v;
150
- }
151
- break;
152
- case "ip":
153
- v.split(",").forEach((p) => {
154
- const s = p.split(":");
155
- vars["inferParams"][s[0]] = parseFloat(s[1]);
156
- });
157
- break;
158
- case "s":
159
- vars.size = v;
160
- break;
161
- default:
162
- vars[k] = v;
163
- break;
164
- }
165
- }
166
- });
167
- return { vars };
168
- }
169
- function initTaskVars(args, inferParams) {
170
- const conf = { inferParams: inferParams };
171
- const vars = {};
172
- args.forEach((a) => {
173
- if (a.includes("=")) {
174
- const delimiter = "=";
175
- const firstDelimiterIndex = a.indexOf(delimiter);
176
- let t = new Array();
177
- if (firstDelimiterIndex !== -1) {
178
- t = [
179
- a.slice(0, firstDelimiterIndex),
180
- a.slice(firstDelimiterIndex + 1)
181
- ];
182
- }
183
- else {
184
- t = [a];
185
- }
186
- const k = t[0];
187
- const v = t[1];
188
- switch (k) {
189
- case "m":
190
- if (v.includes("/")) {
191
- const _s = v.split("/");
192
- conf.model = _s[0];
193
- conf.template = _s[1];
194
- }
195
- else {
196
- conf.model = v;
197
- }
198
- break;
199
- case "ip":
200
- v.split(",").forEach((p) => {
201
- const s = p.split(":");
202
- conf["inferParams"][s[0]] = parseFloat(s[1]);
203
- });
204
- break;
205
- case "s":
206
- conf.size = v;
207
- break;
208
- default:
209
- vars[k] = v;
210
- break;
211
- }
212
- }
213
- });
214
- return { conf, vars };
215
- }
216
54
  async function parseInputOptions(options) {
217
55
  let out = null;
218
56
  if (options?.Ic == true || inputMode.value == "clipboard") {
@@ -231,4 +69,4 @@ function formatStats(stats) {
231
69
  buf.push(`${stats.inferenceTimeSeconds}s inference)`);
232
70
  return buf.join(" ");
233
71
  }
234
- export { initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
72
+ export { parseInputOptions, processOutput, readPromptFile, setOptions, formatStats, };
@@ -0,0 +1,2 @@
1
+ declare function createDirectoryIfNotExists(dirPath: string, recursive?: boolean): void;
2
+ export { createDirectoryIfNotExists };
@@ -0,0 +1,9 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ function createDirectoryIfNotExists(dirPath, recursive = false) {
4
+ const resolvedDirPath = path.resolve(dirPath);
5
+ if (!fs.existsSync(resolvedDirPath)) {
6
+ fs.mkdirSync(resolvedDirPath, { recursive: recursive });
7
+ }
8
+ }
9
+ export { createDirectoryIfNotExists };
@@ -19,6 +19,9 @@ async function readCmds(dir) {
19
19
  const fileNames = _readCmdsDir(dir);
20
20
  for (const name of fileNames) {
21
21
  const { cmd } = await import(path.join(dir, name + ".js"));
22
+ if (!cmd) {
23
+ throw new Error(`command ${name} not found in ${dir}`);
24
+ }
22
25
  cmds[name] = cmd;
23
26
  }
24
27
  return cmds;
@@ -22,7 +22,7 @@ function readFeaturesDir(dir) {
22
22
  cmd: [],
23
23
  workflow: [],
24
24
  adaptater: [],
25
- modelset: []
25
+ modelfile: []
26
26
  };
27
27
  let dirpath = path.join(dir, "tasks");
28
28
  if (fs.existsSync(dirpath)) {
@@ -101,7 +101,7 @@ function readFeaturesDir(dir) {
101
101
  const parts = filename.split(".");
102
102
  const ext = parts.pop();
103
103
  const name = parts.join("");
104
- feats.modelset.push({
104
+ feats.modelfile.push({
105
105
  name: name,
106
106
  path: path.join(dirpath),
107
107
  ext: ext,
@@ -0,0 +1,8 @@
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,10 +1,10 @@
1
1
  import { default as fs } from "fs";
2
2
  import YAML from 'yaml';
3
- function readModelsFile(dir) {
4
- if (!fs.existsSync(dir)) {
3
+ function readModelsFile(fp) {
4
+ if (!fs.existsSync(fp)) {
5
5
  return { models: {}, ctx: 0, max_tokens: 0, found: false };
6
6
  }
7
- const data = fs.readFileSync(dir, 'utf8');
7
+ const data = fs.readFileSync(fp, 'utf8');
8
8
  const m = YAML.parse(data);
9
9
  if (!m?.ctx) {
10
10
  throw new Error(`provide a ctx param in models file`);
package/dist/conf.d.ts CHANGED
@@ -4,5 +4,6 @@ declare function createConfDirIfNotExists(): boolean;
4
4
  declare function processConfPath(confPath: string): Promise<{
5
5
  paths: Array<string>;
6
6
  pf: string;
7
+ dd: string;
7
8
  }>;
8
9
  export { confDir, dbPath, createConfDirIfNotExists, processConfPath, };
package/dist/conf.js CHANGED
@@ -36,9 +36,13 @@ async function processConfPath(confPath) {
36
36
  });
37
37
  }
38
38
  let pf = "";
39
- if (data.promptfile) {
39
+ if (data?.promptfile) {
40
40
  pf = data.promptfile;
41
41
  }
42
- return { paths: allPaths, pf: pf };
42
+ let dd = "";
43
+ if (data?.datadir) {
44
+ dd = data.datadir;
45
+ }
46
+ return { paths: allPaths, pf: pf, dd: dd };
43
47
  }
44
48
  export { confDir, dbPath, createConfDirIfNotExists, processConfPath, };
package/dist/db/read.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ToolSpec } from "modprompt";
2
- import { AliasType, FeatureSpec, FeatureType, ToolType } from "../interfaces.js";
2
+ import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType } from "../interfaces.js";
3
3
  declare function readFeaturePaths(): Array<string>;
4
4
  declare function readPlugins(): Array<Record<string, string>>;
5
5
  declare function readFeatures(): Record<FeatureType, Record<string, string>>;
@@ -16,5 +16,14 @@ declare function readTool(name: string): {
16
16
  tool: ToolSpec;
17
17
  type: ToolType;
18
18
  };
19
- declare function readPromptFilePath(): string;
20
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFilePath, readTool, };
19
+ declare function readFilePaths(): Array<{
20
+ name: string;
21
+ path: string;
22
+ }>;
23
+ declare function readModelfiles(): Array<Record<string, string>>;
24
+ declare function readModels(): Array<DbModelDef>;
25
+ declare function readModel(shortname: string): {
26
+ found: boolean;
27
+ modelData: Record<string, any>;
28
+ };
29
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePaths, readTool, readModels, readModelfiles, readModel, };
package/dist/db/read.js CHANGED
@@ -27,13 +27,15 @@ function _readFeaturesType(type) {
27
27
  return f;
28
28
  }
29
29
  function readFeatures() {
30
- const feats = { task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {}, modelset: {} };
30
+ const feats = {
31
+ task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {}, modelfile: {}
32
+ };
31
33
  feats.task = _readFeaturesType("task");
32
34
  feats.action = _readFeaturesType("action");
33
35
  feats.cmd = _readFeaturesType("cmd");
34
36
  feats.workflow = _readFeaturesType("workflow");
35
37
  feats.adaptater = _readFeaturesType("adaptater");
36
- feats.modelset = _readFeaturesType("modelset");
38
+ feats.modelfile = _readFeaturesType("modelfile");
37
39
  return feats;
38
40
  }
39
41
  function readAliases() {
@@ -76,13 +78,41 @@ function readTool(name) {
76
78
  }
77
79
  return { found: false, tool: {}, type: "action" };
78
80
  }
79
- function readPromptFilePath() {
80
- const stmt1 = db.prepare("SELECT * FROM filepath WHERE name = ?");
81
- const result = stmt1.get("promptfile");
82
- let res = "";
81
+ function readFilePaths() {
82
+ const stmt1 = db.prepare("SELECT name, path FROM filepath");
83
+ const data = stmt1.all();
84
+ let f = new Array();
85
+ data.forEach((row) => {
86
+ f.push({ name: row.name, path: row.path });
87
+ });
88
+ return f;
89
+ }
90
+ function readModelfiles() {
91
+ const stmt = db.prepare("SELECT name, path, ext FROM modelfile");
92
+ const data = stmt.all();
93
+ let f = new Array();
94
+ data.forEach((row) => {
95
+ f.push(row);
96
+ });
97
+ return f;
98
+ }
99
+ function readModels() {
100
+ const stmt = db.prepare("SELECT name, shortname, data FROM model");
101
+ const data = stmt.all();
102
+ let f = new Array();
103
+ data.forEach((row) => {
104
+ f.push(row);
105
+ });
106
+ return f;
107
+ }
108
+ function readModel(shortname) {
109
+ const q = `SELECT id, data FROM model WHERE shortname='${shortname}'`;
110
+ const stmt = db.prepare(q);
111
+ const result = stmt.get();
83
112
  if (result?.id) {
84
- res = result.path;
113
+ const data = JSON.parse(result.data);
114
+ return { found: true, modelData: data };
85
115
  }
86
- return res;
116
+ return { found: false, modelData: {} };
87
117
  }
88
- export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFilePath, readTool, };
118
+ export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePaths, readTool, readModels, readModelfiles, readModel, };
@@ -53,12 +53,18 @@ const alias = `CREATE TABLE IF NOT EXISTS aliases (
53
53
  name TEXT UNIQUE NOT NULL,
54
54
  type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
55
55
  );`;
56
- const model = `CREATE TABLE IF NOT EXISTS modelset (
56
+ const modelfile = `CREATE TABLE IF NOT EXISTS modelfile (
57
57
  id INTEGER PRIMARY KEY AUTOINCREMENT,
58
58
  name TEXT UNIQUE NOT NULL,
59
59
  path TEXT NOT NULL,
60
60
  ext TEXT NOT NULL CHECK ( ext IN ('yml') )
61
61
  );`;
62
+ const model = `CREATE TABLE IF NOT EXISTS model (
63
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
64
+ name TEXT UNIQUE NOT NULL,
65
+ shortname TEXT UNIQUE NOT NULL,
66
+ data TEXT NOT NULL
67
+ );`;
62
68
  const schemas = [
63
69
  filepath,
64
70
  featurespath,
@@ -70,6 +76,7 @@ const schemas = [
70
76
  plugin,
71
77
  alias,
72
78
  model,
79
+ modelfile,
73
80
  adaptater,
74
81
  ];
75
82
  export { schemas };
@@ -1,8 +1,10 @@
1
- import { Features } from "../interfaces.js";
1
+ import { Features, DbModelDef } from "../interfaces.js";
2
2
  declare function updatePromptfilePath(pf: string): void;
3
+ declare function updateDataDirPath(dd: string): void;
3
4
  declare function insertFeaturesPathIfNotExists(path: string): boolean;
4
5
  declare function insertPluginIfNotExists(n: string, p: string): boolean;
5
6
  declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
6
7
  declare function updateAliases(feats: Features): void;
8
+ declare function upsertModels(models: Array<DbModelDef>): void;
7
9
  declare function updateFeatures(feats: Features): void;
8
- export { updatePromptfilePath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
10
+ export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertModels, };
package/dist/db/write.js CHANGED
@@ -6,6 +6,12 @@ function updatePromptfilePath(pf) {
6
6
  const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
7
7
  stmt.run("promptfile", pf);
8
8
  }
9
+ function updateDataDirPath(dd) {
10
+ const deleteStmt = db.prepare("DELETE FROM filepath WHERE name = ?");
11
+ deleteStmt.run("datadir");
12
+ const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
13
+ stmt.run("datadir", dd);
14
+ }
9
15
  function insertFeaturesPathIfNotExists(path) {
10
16
  const stmt1 = db.prepare("SELECT * FROM featurespath WHERE path = ?");
11
17
  const result = stmt1.get(path);
@@ -104,6 +110,29 @@ function upsertTool(name, type, toolDoc) {
104
110
  stmt.run(name, toolDoc, type);
105
111
  console.log("+", "[tool] from", type, ":", name);
106
112
  }
113
+ function upsertModels(models) {
114
+ const stmt1 = db.prepare("SELECT shortname FROM model");
115
+ const rows = stmt1.all();
116
+ const existingModelShortNames = rows.map(row => row.shortname);
117
+ const stmt = db.prepare(`INSERT INTO model (name, shortname, data) VALUES (?,?,?)`);
118
+ existingModelShortNames.forEach((name) => {
119
+ if (!existingModelShortNames.includes(name)) {
120
+ const deleteStmt = db.prepare("DELETE FROM model WHERE name = ?");
121
+ deleteStmt.run(name);
122
+ console.log("-", "[model]", name);
123
+ }
124
+ });
125
+ db.transaction(() => {
126
+ for (const model of models) {
127
+ const stmt1 = db.prepare("SELECT * FROM model WHERE shortname = ?");
128
+ const result = stmt1.get(model.shortname);
129
+ if (result?.id) {
130
+ continue;
131
+ }
132
+ stmt.run(model.name, model.shortname, JSON.stringify(model.data));
133
+ }
134
+ })();
135
+ }
107
136
  function updateFeatures(feats) {
108
137
  upsertAndCleanFeatures(feats.task, "task");
109
138
  const newActions = upsertAndCleanFeatures(feats.action, "action");
@@ -118,6 +147,6 @@ function updateFeatures(feats) {
118
147
  upsertAndCleanFeatures(feats.cmd, "cmd");
119
148
  upsertAndCleanFeatures(feats.workflow, "workflow");
120
149
  upsertAndCleanFeatures(feats.adaptater, "adaptater");
121
- upsertAndCleanFeatures(feats.modelset, "modelset");
150
+ upsertAndCleanFeatures(feats.modelfile, "modelfile");
122
151
  }
123
- export { updatePromptfilePath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
152
+ export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertModels, };
@@ -1,9 +1,12 @@
1
+ import { BaseLmTask, ModelSpec } from "@agent-smith/lmtask";
2
+ import { InferenceParams } from "@locallm/types";
1
3
  interface Cmd {
2
4
  cmd: CmdExecutor;
3
5
  description: string;
4
6
  args?: string;
5
7
  }
6
8
  interface FeatureSpec {
9
+ id?: number;
7
10
  name: string;
8
11
  path: string;
9
12
  ext: FeatureExtension;
@@ -34,14 +37,15 @@ interface Features {
34
37
  path: string;
35
38
  ext: AdaptaterExtension;
36
39
  }>;
37
- modelset: Array<{
40
+ modelfile: Array<{
38
41
  name: string;
39
42
  path: string;
40
- ext: ModelsetExtension;
43
+ ext: ModelFileExtension;
41
44
  }>;
42
45
  }
43
46
  interface ConfigFile {
44
47
  promptfile?: string;
48
+ datadir?: string;
45
49
  features?: Array<string>;
46
50
  plugins?: Array<string>;
47
51
  }
@@ -56,19 +60,50 @@ interface Settings {
56
60
  isverbose: boolean;
57
61
  promptfile: string;
58
62
  }
63
+ interface DbModelDef {
64
+ id?: number;
65
+ name: string;
66
+ shortname: string;
67
+ data: Record<string, any>;
68
+ }
69
+ interface ModelfileSpec {
70
+ ctx: number;
71
+ max_tokens: number;
72
+ models: Array<ModelSpec>;
73
+ }
74
+ interface ModelPack {
75
+ default: string;
76
+ recommended?: Array<string>;
77
+ }
78
+ interface LmTaskFileSpec extends BaseLmTask {
79
+ ctx: number;
80
+ model?: ModelSpec;
81
+ modelpack?: ModelPack;
82
+ }
83
+ interface BaseLmTaskConfig {
84
+ templateName: string;
85
+ inferParams: InferenceParams;
86
+ }
87
+ interface LmTaskConfig extends BaseLmTaskConfig {
88
+ modelname?: string;
89
+ }
90
+ interface FinalLmTaskConfig {
91
+ model?: ModelSpec;
92
+ modelname?: string;
93
+ }
59
94
  type CmdExecutor = (args: Array<string>, options: any) => Promise<any>;
60
95
  type InputMode = "manual" | "promptfile" | "clipboard";
61
96
  type OutputMode = "txt" | "clipboard";
62
97
  type RunMode = "cli" | "cmd";
63
98
  type FormatMode = "text" | "markdown";
64
- type FeatureType = "task" | "action" | "cmd" | "workflow" | "adaptater" | "modelset";
99
+ type FeatureType = "task" | "action" | "cmd" | "workflow" | "adaptater" | "modelfile";
65
100
  type ToolType = "task" | "action" | "cmd" | "workflow";
66
101
  type ActionExtension = "js" | "mjs" | "py" | "yml";
67
102
  type TaskExtension = "yml";
68
103
  type AdaptaterExtension = "js";
69
104
  type WorkflowExtension = "yml";
70
105
  type CmdExtension = "js";
71
- type ModelsetExtension = "yml";
72
- type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension;
106
+ type ModelFileExtension = "yml";
107
+ type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
73
108
  type AliasType = "task" | "action" | "workflow";
74
- export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelsetExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, };
109
+ export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, };
package/dist/main.d.ts CHANGED
@@ -5,5 +5,9 @@ import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
6
  import { pingCmd } from "./cmd/clicmds/cmds.js";
7
7
  import { initAgent } from "./agent.js";
8
- import { initState } from "./state/state.js";
9
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, };
8
+ import { initState, pluginDataDir } from "./state/state.js";
9
+ import { usePerfTimer } from "./primitives/perf.js";
10
+ import { parseInferenceArgs } from "./primitives/args.js";
11
+ import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
12
+ import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
13
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseInferenceArgs, parseTaskVars, LmTaskConf, };
package/dist/main.js CHANGED
@@ -5,5 +5,8 @@ import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
5
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
6
6
  import { pingCmd } from "./cmd/clicmds/cmds.js";
7
7
  import { initAgent } from "./agent.js";
8
- import { initState } from "./state/state.js";
9
- export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, };
8
+ import { initState, pluginDataDir } from "./state/state.js";
9
+ import { usePerfTimer } from "./primitives/perf.js";
10
+ import { parseInferenceArgs } from "./primitives/args.js";
11
+ import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
12
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseInferenceArgs, parseTaskVars, };
@@ -0,0 +1,5 @@
1
+ declare function parseInferenceArgs(args: Array<string>): {
2
+ inferenceVars: Record<string, any>;
3
+ currentArgs: Array<string>;
4
+ };
5
+ export { parseInferenceArgs, };
@@ -0,0 +1,40 @@
1
+ function parseInferenceArgs(args) {
2
+ const vars = {};
3
+ const nargs = new Array();
4
+ args.forEach((a) => {
5
+ if (a.includes("=")) {
6
+ const t = a.split("=");
7
+ const k = t[0];
8
+ const v = t[1];
9
+ switch (k) {
10
+ case "m":
11
+ if (v.includes("/")) {
12
+ const _s = v.split("/");
13
+ vars.model = _s[0];
14
+ vars.template = _s[1];
15
+ }
16
+ else {
17
+ vars.model = v;
18
+ }
19
+ break;
20
+ case "ip":
21
+ v.split(",").forEach((p) => {
22
+ const s = p.split(":");
23
+ vars["inferParams"][s[0]] = parseFloat(s[1]);
24
+ });
25
+ break;
26
+ case "s":
27
+ vars.size = v;
28
+ break;
29
+ default:
30
+ vars[k] = v;
31
+ break;
32
+ }
33
+ }
34
+ else {
35
+ nargs.push(a);
36
+ }
37
+ });
38
+ return { inferenceVars: vars, currentArgs: nargs };
39
+ }
40
+ export { parseInferenceArgs, };
@@ -0,0 +1,7 @@
1
+ declare const usePerfTimer: (startTimer?: boolean) => {
2
+ start: () => number;
3
+ time: () => string | number;
4
+ timeRaw: () => string | number;
5
+ printTime: () => void;
6
+ };
7
+ export { usePerfTimer };
@@ -0,0 +1,38 @@
1
+ const usePerfTimer = (startTimer = true) => {
2
+ let _startTime;
3
+ if (startTimer) {
4
+ _startTime = performance.now();
5
+ }
6
+ const start = () => _startTime = performance.now();
7
+ const _end = (raw) => {
8
+ if (!_startTime) {
9
+ throw new Error("the timer has not started, can not end it");
10
+ }
11
+ const endTime = performance.now();
12
+ const duration = endTime - _startTime;
13
+ if (raw) {
14
+ return duration;
15
+ }
16
+ const humanizedTime = _formatDuration(duration);
17
+ return humanizedTime;
18
+ };
19
+ const time = () => _end(false);
20
+ const printTime = () => console.log(_end(false));
21
+ const timeRaw = () => _end(true);
22
+ const _formatDuration = (ms) => {
23
+ const seconds = Math.floor(ms / 1000);
24
+ const minutes = Math.floor(seconds / 60);
25
+ if (ms < 1000)
26
+ return `${ms.toFixed(2)}ms`;
27
+ if (seconds < 60)
28
+ return `${seconds.toFixed(2)}s`;
29
+ return `${minutes}m ${seconds % 60}s`;
30
+ };
31
+ return {
32
+ start,
33
+ time,
34
+ timeRaw,
35
+ printTime,
36
+ };
37
+ };
38
+ export { usePerfTimer };
@@ -19,6 +19,8 @@ declare const chatInferenceParams: {
19
19
  tfs?: number | undefined;
20
20
  stop?: Array<string> | undefined;
21
21
  grammar?: string | undefined;
22
+ tsGrammar?: string | undefined;
23
+ schema?: Record<string, any> | undefined;
22
24
  images?: Array<string> | undefined;
23
25
  extra?: Record<string, any> | undefined;
24
26
  };
@@ -8,7 +8,7 @@ function readFeaturesDirs(featuresPaths) {
8
8
  cmd: [],
9
9
  workflow: [],
10
10
  adaptater: [],
11
- modelset: [],
11
+ modelfile: [],
12
12
  };
13
13
  featuresPaths.forEach((dir) => {
14
14
  const _f = readFeaturesDir(dir);
@@ -17,7 +17,7 @@ function readFeaturesDirs(featuresPaths) {
17
17
  _f.cmd.forEach((item) => feats.cmd.push(item));
18
18
  _f.workflow.forEach((item) => feats.workflow.push(item));
19
19
  _f.adaptater.forEach((item) => feats.adaptater.push(item));
20
- _f.modelset.forEach((item) => feats.modelset.push(item));
20
+ _f.modelfile.forEach((item) => feats.modelfile.push(item));
21
21
  });
22
22
  return feats;
23
23
  }
@@ -10,10 +10,12 @@ declare const isDebug: import("@vue/reactivity").Ref<boolean, boolean>;
10
10
  declare const isVerbose: import("@vue/reactivity").Ref<boolean, boolean>;
11
11
  declare const isShowTokens: import("@vue/reactivity").Ref<boolean, boolean>;
12
12
  declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
13
+ declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
13
14
  declare const lastCmd: {
14
15
  name: string;
15
16
  args: Array<string>;
16
17
  };
17
18
  declare function initFeatures(): Promise<void>;
18
19
  declare function initState(): Promise<void>;
19
- export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, initState, initFeatures, pyShell, };
20
+ declare function pluginDataDir(pluginName: string): string;
21
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFeatures, pyShell, };
@@ -1,10 +1,13 @@
1
1
  import { reactive, ref } from "@vue/reactivity";
2
2
  import { createConfDirIfNotExists, confDir } from "../conf.js";
3
3
  import { initDb } from "../db/db.js";
4
- import { readFeaturePaths, readPromptFilePath } from "../db/read.js";
4
+ import { readFeaturePaths, readFilePaths } from "../db/read.js";
5
5
  import { updateAliases, updateFeatures } from "../db/write.js";
6
6
  import { readFeaturesDirs } from "./features.js";
7
7
  import { readPluginsPaths } from "./plugins.js";
8
+ import path from "path";
9
+ import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
10
+ import { updateModels } from "../cmd/lib/models.js";
8
11
  let pyShell;
9
12
  const inputMode = ref("manual");
10
13
  const outputMode = ref("txt");
@@ -15,6 +18,7 @@ const isDebug = ref(false);
15
18
  const isVerbose = ref(false);
16
19
  const isShowTokens = ref(false);
17
20
  const promptfilePath = ref("");
21
+ const dataDirPath = ref("");
18
22
  const isStateReady = ref(false);
19
23
  const lastCmd = reactive({
20
24
  name: "",
@@ -34,7 +38,17 @@ async function initFeatures() {
34
38
  const feats = readFeaturesDirs(p);
35
39
  updateFeatures(feats);
36
40
  updateAliases(feats);
37
- promptfilePath.value = readPromptFilePath();
41
+ updateModels();
42
+ const filePaths = readFilePaths();
43
+ for (const fp of filePaths) {
44
+ switch (fp.name) {
45
+ case "promptfile":
46
+ promptfilePath.value = fp.path;
47
+ break;
48
+ case "datadir":
49
+ dataDirPath.value = fp.path;
50
+ }
51
+ }
38
52
  }
39
53
  async function initState() {
40
54
  if (isStateReady.value) {
@@ -44,4 +58,16 @@ async function initState() {
44
58
  await initFeatures();
45
59
  isStateReady.value = true;
46
60
  }
47
- export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, initState, initFeatures, pyShell, };
61
+ function _getDataDirPath() {
62
+ if (dataDirPath.value.length == 0) {
63
+ throw new Error("datadir path is not configured: update your config file with 'datadir' and run conf");
64
+ }
65
+ return dataDirPath.value;
66
+ }
67
+ function pluginDataDir(pluginName) {
68
+ const dd = _getDataDirPath();
69
+ const pluginDatapath = path.join(dd, pluginName);
70
+ createDirectoryIfNotExists(pluginDatapath);
71
+ return pluginDatapath;
72
+ }
73
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFeatures, pyShell, };
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.44",
5
+ "version": "0.0.45",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc",
@@ -10,12 +10,11 @@
10
10
  "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.41",
13
+ "@agent-smith/brain": "^0.0.42",
14
14
  "@agent-smith/jobs": "^0.0.14",
15
- "@agent-smith/lmtask": "^0.0.35",
16
- "@agent-smith/tfm": "^0.1.2",
17
- "@inquirer/prompts": "^7.4.0",
18
- "@inquirer/select": "^4.1.0",
15
+ "@agent-smith/lmtask": "^0.0.37",
16
+ "@inquirer/prompts": "^7.4.1",
17
+ "@inquirer/select": "^4.1.1",
19
18
  "@vue/reactivity": "^3.5.13",
20
19
  "@wllama/wllama": "^2.3.0",
21
20
  "better-sqlite3": "^11.9.1",
@@ -29,17 +28,17 @@
29
28
  "devDependencies": {
30
29
  "@agent-smith/tmem-jobs": "^0.0.4",
31
30
  "@commander-js/extra-typings": "^13.1.0",
32
- "@locallm/types": "^0.1.6",
31
+ "@locallm/types": "^0.1.9",
33
32
  "@rollup/plugin-node-resolve": "^16.0.1",
34
33
  "@rollup/plugin-typescript": "^12.1.2",
35
- "@types/better-sqlite3": "^7.6.12",
34
+ "@types/better-sqlite3": "^7.6.13",
36
35
  "@types/marked-terminal": "^6.1.1",
37
- "@types/node": "^22.13.14",
36
+ "@types/node": "^22.14.0",
38
37
  "restmix": "^0.5.0",
39
- "rollup": "^4.38.0",
38
+ "rollup": "^4.39.0",
40
39
  "ts-node": "^10.9.2",
41
40
  "tslib": "2.8.1",
42
- "typescript": "^5.8.2"
41
+ "typescript": "^5.8.3"
43
42
  },
44
43
  "type": "module",
45
44
  "preferGlobal": true,
@@ -1,7 +0,0 @@
1
- declare function readModelsFile(dir: string): {
2
- found: boolean;
3
- ctx: number;
4
- max_tokens: number;
5
- models: Record<string, any>;
6
- };
7
- export { readModelsFile, };
File without changes
File without changes