@agent-smith/cli 0.0.109 → 0.0.111
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.
- package/dist/cli.js +1 -0
- package/dist/cmd/clicmds/aliases.js +12 -1
- package/dist/cmd/clicmds/base.js +3 -0
- package/dist/cmd/clicmds/cmds.js +9 -0
- package/dist/cmd/clicmds/updateconf.js +1 -0
- package/dist/cmd/cmds.js +70 -0
- package/dist/cmd/lib/actions/cmd.js +21 -1
- package/dist/cmd/lib/actions/read.js +4 -0
- package/dist/cmd/lib/adaptaters/cmd.js +8 -1
- package/dist/cmd/lib/agents/cmd.js +2 -1
- package/dist/cmd/lib/mcp.js +6 -0
- package/dist/cmd/lib/options_parsers.js +5 -0
- package/dist/cmd/lib/tasks/cmd.js +90 -4
- package/dist/cmd/lib/tasks/conf.js +35 -0
- package/dist/cmd/lib/tasks/read.js +30 -1
- package/dist/cmd/lib/tools.js +10 -4
- package/dist/cmd/lib/user_msgs.js +4 -3
- package/dist/cmd/lib/utils.js +5 -0
- package/dist/cmd/lib/workflows/cmd.js +32 -1
- package/dist/cmd/lib/workflows/read.js +5 -0
- package/dist/cmd/options.js +1 -0
- package/dist/cmd/sys/clipboard.js +25 -0
- package/dist/cmd/sys/execute.js +1 -0
- package/dist/cmd/sys/read_cmds.js +2 -2
- package/dist/cmd/sys/read_conf.js +1 -0
- package/dist/cmd/sys/read_features.js +1 -0
- package/dist/cmd/sys/run_python.js +4 -0
- package/dist/conf.d.ts +5 -1
- package/dist/conf.js +6 -2
- package/dist/db/db.js +1 -0
- package/dist/db/read.js +1 -0
- package/dist/db/write.js +32 -0
- package/dist/index.js +10 -0
- package/dist/main.d.ts +17 -2
- package/dist/main.js +16 -1
- package/dist/state/backends.js +14 -0
- package/dist/state/plugins.js +3 -0
- package/dist/state/state.js +21 -2
- package/dist/state/tasks.d.ts +2 -1
- package/dist/state/tasks.js +8 -1
- package/dist/utils/text.js +4 -0
- package/dist/utils/user_msgs.js +2 -0
- package/package.json +19 -16
|
@@ -22,6 +22,7 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
22
22
|
let i = 0;
|
|
23
23
|
const finalTaskIndex = stepNames.length - 1;
|
|
24
24
|
let taskRes = { cmdArgs: args };
|
|
25
|
+
//console.log("WPARAMS", taskRes);
|
|
25
26
|
let prevStepType = null;
|
|
26
27
|
for (const step of workflow) {
|
|
27
28
|
if (isDebug || isVerbose) {
|
|
@@ -93,6 +94,8 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
93
94
|
break;
|
|
94
95
|
case "action":
|
|
95
96
|
try {
|
|
97
|
+
//console.log("EXEC ACTION ARGS", taskRes);
|
|
98
|
+
//const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
96
99
|
let actArgs;
|
|
97
100
|
if (i == 0) {
|
|
98
101
|
actArgs = taskRes.cmdArgs;
|
|
@@ -105,12 +108,15 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
105
108
|
actArgs = taskRes;
|
|
106
109
|
}
|
|
107
110
|
const ares = await executeAction(step.name, actArgs, options, true);
|
|
111
|
+
//console.log("WF ACTION RES", typeof ares, ares);
|
|
112
|
+
//console.log("LAST ACT", i, finalTaskIndex);
|
|
108
113
|
if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
|
|
109
114
|
console.log(ares);
|
|
110
115
|
break;
|
|
111
116
|
}
|
|
112
117
|
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
113
118
|
taskRes.args = ares;
|
|
119
|
+
//console.log("ARRAY ACTION RES", taskRes)
|
|
114
120
|
}
|
|
115
121
|
else {
|
|
116
122
|
taskRes = { ...ares, ...taskRes };
|
|
@@ -119,12 +125,17 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
119
125
|
catch (e) {
|
|
120
126
|
throw new Error(`workflow action ${i + 1}: ${e}`);
|
|
121
127
|
}
|
|
128
|
+
//console.log("END ACTION", step.name)
|
|
122
129
|
break;
|
|
123
130
|
case "adaptater":
|
|
124
131
|
try {
|
|
132
|
+
//console.log("WF AD ARGS IN", taskRes);
|
|
133
|
+
//console.log("AD OPTS IN", options);
|
|
125
134
|
let actArgs;
|
|
126
135
|
if (i == 0) {
|
|
136
|
+
//console.log("TR", taskRes);
|
|
127
137
|
actArgs = taskRes.cmdArgs;
|
|
138
|
+
//console.log("ACT ARGS", actArgs);
|
|
128
139
|
const inputData = await getInputFromOptions(options);
|
|
129
140
|
if (inputData) {
|
|
130
141
|
actArgs.push(inputData);
|
|
@@ -134,16 +145,21 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
134
145
|
actArgs = taskRes;
|
|
135
146
|
}
|
|
136
147
|
const adres = await executeAdaptater(step.name, actArgs, options);
|
|
148
|
+
//console.log("WF AD FINAL RES", taskRes);
|
|
149
|
+
//console.log("LAST ACT", i, finalTaskIndex);
|
|
137
150
|
if (i == finalTaskIndex && !options?.isToolCall && !options?.quiet) {
|
|
138
151
|
console.log(adres);
|
|
139
152
|
break;
|
|
140
153
|
}
|
|
154
|
+
//console.log("WF AD RES", typeof adres, adres);
|
|
141
155
|
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
142
156
|
taskRes.args = adres;
|
|
157
|
+
//console.log("WF AD IT RES", taskRes);
|
|
143
158
|
}
|
|
144
159
|
else {
|
|
145
160
|
taskRes = { ...adres };
|
|
146
161
|
}
|
|
162
|
+
//console.log("WF ADAPT RES", typeof ares, Array.isArray(ares) ? ares.length : "NA");
|
|
147
163
|
}
|
|
148
164
|
catch (e) {
|
|
149
165
|
throw new Error(`workflow adaptater ${i + 1}: ${e}`);
|
|
@@ -156,7 +172,13 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
156
172
|
throw new Error(`Command ${step.name} not found`);
|
|
157
173
|
}
|
|
158
174
|
const url = pathToFileURL(path).href;
|
|
159
|
-
|
|
175
|
+
let jsa;
|
|
176
|
+
try {
|
|
177
|
+
jsa = await import(/* @vite-ignore */ url);
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
throw new Error(`cmd import error ${e}`);
|
|
181
|
+
}
|
|
160
182
|
if (!jsa?.runCmd) {
|
|
161
183
|
runtimeError(`workflow ${wname}: can not import the runCmd function from step ${i} for command ${step.name}: please add a runCmd function export`);
|
|
162
184
|
return;
|
|
@@ -188,12 +210,21 @@ async function executeWorkflow(wname, args, options = {}) {
|
|
|
188
210
|
throw new Error(`unknown workflow step type ${step.type} in workflow ${wname}`);
|
|
189
211
|
}
|
|
190
212
|
prevStepType = step.type;
|
|
213
|
+
//console.log("WF NODE RES", step.type, taskRes);
|
|
214
|
+
/*if (isDebug) {
|
|
215
|
+
console.log("->", params);
|
|
216
|
+
}*/
|
|
217
|
+
//console.log("WFR", taskRes)
|
|
191
218
|
++i;
|
|
192
219
|
}
|
|
220
|
+
//console.log("WF RES")
|
|
193
221
|
return taskRes;
|
|
194
222
|
}
|
|
195
223
|
async function executeWorkflowCmd(name, wargs) {
|
|
224
|
+
//console.log("WF INITIAL ARGS", typeof wargs, wargs.slice(0, -1));
|
|
196
225
|
const { args, options } = parseCommandArgs(wargs);
|
|
226
|
+
//console.log("WF ARGS", typeof args, args);
|
|
227
|
+
//console.log("WF OPTS", options);
|
|
197
228
|
return await executeWorkflow(name, args, options);
|
|
198
229
|
}
|
|
199
230
|
export { executeWorkflow, executeWorkflowCmd };
|
|
@@ -3,6 +3,7 @@ import YAML from 'yaml';
|
|
|
3
3
|
import { getFeatureSpec } from '../../../state/features.js';
|
|
4
4
|
async function _createWorkflowFromSpec(spec) {
|
|
5
5
|
const steps = [];
|
|
6
|
+
//console.log("Create WF. Steps:", spec);
|
|
6
7
|
for (const step of spec.steps) {
|
|
7
8
|
const type = Object.keys(step)[0];
|
|
8
9
|
const sval = step[type];
|
|
@@ -13,9 +14,11 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
13
14
|
};
|
|
14
15
|
steps.push(wf);
|
|
15
16
|
}
|
|
17
|
+
//console.log("STEPS", Object.keys(steps).length, steps);
|
|
16
18
|
return steps;
|
|
17
19
|
}
|
|
18
20
|
async function _readWorkflowFromDisk(name) {
|
|
21
|
+
//const fp = path.join(jobsPath, `${name}.yml`);
|
|
19
22
|
const { found, path } = getFeatureSpec(name, "workflow");
|
|
20
23
|
if (!found) {
|
|
21
24
|
return { found: false, data: {} };
|
|
@@ -37,8 +40,10 @@ async function readWorkflow(name) {
|
|
|
37
40
|
switch (ext) {
|
|
38
41
|
case "yml":
|
|
39
42
|
const { data } = await _readWorkflowFromDisk(name);
|
|
43
|
+
//console.log("WF DATA", data);
|
|
40
44
|
try {
|
|
41
45
|
const workflow = await _createWorkflowFromSpec(data);
|
|
46
|
+
//console.log("WF END", found, workflow);
|
|
42
47
|
if (!found) {
|
|
43
48
|
return { found: false, workflow: [] };
|
|
44
49
|
}
|
package/dist/cmd/options.js
CHANGED
|
@@ -4,6 +4,7 @@ const displayOptions = [
|
|
|
4
4
|
new Option("-d, --debug", "use the debug mode"),
|
|
5
5
|
];
|
|
6
6
|
const inferenceOptions = [
|
|
7
|
+
//new Option("-s, --stream", "use the stream mode"),
|
|
7
8
|
new Option("-m, --model <name>", "the model name").argParser(parseString),
|
|
8
9
|
new Option("-x, --ctx", "context window size").argParser(parseIntValue),
|
|
9
10
|
new Option("--tpl, --template <template>", "the template to use"),
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import clipboard from 'clipboardy';
|
|
2
|
+
//import { execute } from "./execute.js";
|
|
3
|
+
//const { platform } = process;
|
|
2
4
|
async function readClipboard() {
|
|
5
|
+
/*let res = "";
|
|
6
|
+
if (platform == "linux") {
|
|
7
|
+
res = await execute("xclip", ["-o", "-selection", "primary"]);
|
|
8
|
+
} else {
|
|
9
|
+
res = await clipboard.read();
|
|
10
|
+
}
|
|
11
|
+
return res*/
|
|
3
12
|
return await clipboard.read();
|
|
4
13
|
}
|
|
5
14
|
async function writeToClipboard(data) {
|
|
6
15
|
await clipboard.write(data);
|
|
7
16
|
}
|
|
17
|
+
/*import { platform } from "os";
|
|
18
|
+
|
|
19
|
+
async function getClipboard(): Promise<string> {
|
|
20
|
+
const currentPlatform = platform();
|
|
21
|
+
|
|
22
|
+
switch (currentPlatform) {
|
|
23
|
+
case 'darwin': // macOS
|
|
24
|
+
return await execute("pbpaste", []);
|
|
25
|
+
case 'win32': // Windows
|
|
26
|
+
return await execute("powershell", ["-command", "Get-Clipboard"]);
|
|
27
|
+
case 'linux': // Linux
|
|
28
|
+
return await execute("xclip", ["-o", "-selection", "clipboard"]);
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Unsupported platform: ${currentPlatform}`);
|
|
31
|
+
}
|
|
32
|
+
}*/
|
|
8
33
|
export { readClipboard, writeToClipboard, };
|
package/dist/cmd/sys/execute.js
CHANGED
|
@@ -6,6 +6,7 @@ async function execute(command, args = [], { onStdout = (data) => { }, onStderr
|
|
|
6
6
|
throw err; },
|
|
7
7
|
}) {
|
|
8
8
|
let buffer = new Array();
|
|
9
|
+
//console.log("Cmd args:", args)
|
|
9
10
|
const useShell = platform() === 'win32';
|
|
10
11
|
const child = spawn(command, args, { shell: useShell });
|
|
11
12
|
child.stdout.setEncoding('utf8');
|
|
@@ -4,7 +4,7 @@ async function readCmd(name, cmdPath) {
|
|
|
4
4
|
const url = pathToFileURL(cmdPath).href;
|
|
5
5
|
let _cmd;
|
|
6
6
|
try {
|
|
7
|
-
const mod = await import(url);
|
|
7
|
+
const mod = await import(/* @vite-ignore */ url);
|
|
8
8
|
_cmd = mod.cmd;
|
|
9
9
|
}
|
|
10
10
|
catch (e) {
|
|
@@ -19,7 +19,7 @@ async function readCmd(name, cmdPath) {
|
|
|
19
19
|
async function readUserCmd(name, cmdPath) {
|
|
20
20
|
const url = pathToFileURL(cmdPath).href;
|
|
21
21
|
try {
|
|
22
|
-
const mod = await import(url);
|
|
22
|
+
const mod = await import(/* @vite-ignore */ url);
|
|
23
23
|
const cmdMod = mod.cmd;
|
|
24
24
|
const uc = {
|
|
25
25
|
name: cmdMod.name,
|
|
@@ -4,6 +4,7 @@ function _readDir(dir, ext) {
|
|
|
4
4
|
const fileNames = new Array;
|
|
5
5
|
fs.readdirSync(dir).forEach((filename) => {
|
|
6
6
|
const filepath = path.join(dir, filename);
|
|
7
|
+
//console.log("F", filepath);
|
|
7
8
|
const isDir = fs.statSync(filepath).isDirectory();
|
|
8
9
|
if (!isDir) {
|
|
9
10
|
if (ext.includes(path.extname(filename))) {
|
|
@@ -17,16 +17,20 @@ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, onEmitLi
|
|
|
17
17
|
res.data.push(msg);
|
|
18
18
|
}
|
|
19
19
|
rsShell.on('message', function (message) {
|
|
20
|
+
//console.log("MSG", message);
|
|
20
21
|
handleLine(message);
|
|
21
22
|
});
|
|
22
23
|
rsShell.on('stderr', function (err) {
|
|
23
24
|
console.log("STDERR", err);
|
|
24
25
|
});
|
|
25
26
|
rsShell.on('pythonError', function (err) {
|
|
27
|
+
//console.log("PYERR", `${err.message}, ${err.traceback}`);
|
|
26
28
|
res.error = new Error(`${err.traceback} ${err.message}`);
|
|
27
29
|
promiseResolve(true);
|
|
28
30
|
});
|
|
29
31
|
rsShell.end(function (err, code, signal) {
|
|
32
|
+
//console.log("END", code, signal);
|
|
33
|
+
//console.log("DATA", res);
|
|
30
34
|
promiseResolve(true);
|
|
31
35
|
});
|
|
32
36
|
await promise;
|
package/dist/conf.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
declare function getConfigPath(appName: string, filename: string): {
|
|
2
|
+
confDir: string;
|
|
3
|
+
dbPath: string;
|
|
4
|
+
};
|
|
1
5
|
declare const confDir: string, dbPath: string;
|
|
2
6
|
declare function processConfPath(confPath: string): Promise<{
|
|
3
7
|
paths: Array<string>;
|
|
4
8
|
pf: string;
|
|
5
9
|
dd: string;
|
|
6
10
|
}>;
|
|
7
|
-
export { confDir, dbPath, processConfPath, };
|
|
11
|
+
export { confDir, dbPath, processConfPath, getConfigPath, };
|
package/dist/conf.js
CHANGED
|
@@ -18,7 +18,7 @@ function getConfigPath(appName, filename) {
|
|
|
18
18
|
confDir = join(homedir(), 'Library', 'Application Support', appName);
|
|
19
19
|
dbPath = join(homedir(), 'Library', 'Application Support', appName, filename);
|
|
20
20
|
}
|
|
21
|
-
else {
|
|
21
|
+
else { // Linux, BSD, etc.
|
|
22
22
|
confDir = join(homedir(), '.config', appName);
|
|
23
23
|
dbPath = join(homedir(), '.config', appName, filename);
|
|
24
24
|
}
|
|
@@ -31,7 +31,9 @@ async function processConfPath(confPath) {
|
|
|
31
31
|
if (!found) {
|
|
32
32
|
runtimeError(`Config file ${confPath} not found`);
|
|
33
33
|
}
|
|
34
|
+
//console.log(data)
|
|
34
35
|
const allPaths = new Array();
|
|
36
|
+
// backends
|
|
35
37
|
const backends = {};
|
|
36
38
|
let defaultBackendName = "";
|
|
37
39
|
if (data?.backends) {
|
|
@@ -72,11 +74,13 @@ async function processConfPath(confPath) {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
console.log("Default backend:", defaultBackendName);
|
|
77
|
+
//console.dir(backends, { depth: 4 });
|
|
75
78
|
if (!Object.keys(backends).includes(defaultBackendName)) {
|
|
76
79
|
throw new Error(`Undeclared default backend: ${defaultBackendName}`);
|
|
77
80
|
}
|
|
78
81
|
backends[defaultBackendName].isDefault = true;
|
|
79
82
|
upsertBackends(Object.values(backends));
|
|
83
|
+
// features and plugins from conf
|
|
80
84
|
if (data?.features) {
|
|
81
85
|
allPaths.push(...data.features);
|
|
82
86
|
const fts = new Array();
|
|
@@ -114,4 +118,4 @@ async function processConfPath(confPath) {
|
|
|
114
118
|
}
|
|
115
119
|
return { paths: allPaths, pf: pf, dd: dd };
|
|
116
120
|
}
|
|
117
|
-
export { confDir, dbPath, processConfPath, };
|
|
121
|
+
export { confDir, dbPath, processConfPath, getConfigPath, };
|
package/dist/db/db.js
CHANGED
|
@@ -5,6 +5,7 @@ import { confDir, dbPath } from "../conf.js";
|
|
|
5
5
|
let db;
|
|
6
6
|
const debugDb = false;
|
|
7
7
|
function initDb(isVerbose, execSchema) {
|
|
8
|
+
//console.log("DBP", dbPath);
|
|
8
9
|
if (execSchema) {
|
|
9
10
|
createDirectoryIfNotExists(confDir, true);
|
|
10
11
|
db = new DatabaseConstructor(dbPath, { fileMustExist: false, verbose: debugDb ? console.log : undefined });
|
package/dist/db/read.js
CHANGED
|
@@ -27,6 +27,7 @@ function readPlugins() {
|
|
|
27
27
|
return f;
|
|
28
28
|
}
|
|
29
29
|
function readFeaturesType(type) {
|
|
30
|
+
//console.log(`SELECT name, path, ext, variables FROM ${type}`)
|
|
30
31
|
const stmt = db.prepare(`SELECT name, path, ext, variables FROM ${type}`);
|
|
31
32
|
const data = stmt.all();
|
|
32
33
|
const res = {};
|
package/dist/db/write.js
CHANGED
|
@@ -20,10 +20,13 @@ function setDefaultBackend(name) {
|
|
|
20
20
|
}
|
|
21
21
|
function upsertBackends(bdata) {
|
|
22
22
|
let hasUpdates = false;
|
|
23
|
+
// Get all existing backend names
|
|
23
24
|
const existingStmt = db.prepare("SELECT name FROM backend");
|
|
24
25
|
const existingBackends = existingStmt.all();
|
|
25
26
|
const existingNames = new Set(existingBackends.map(b => b.name));
|
|
27
|
+
// Create a set of new backend names for comparison
|
|
26
28
|
const newNames = new Set(bdata.map(b => b.name));
|
|
29
|
+
// Delete backends that are not in the new list
|
|
27
30
|
const toDelete = Array.from(existingNames).filter(name => !newNames.has(name));
|
|
28
31
|
if (toDelete.length > 0) {
|
|
29
32
|
const deleteStmt = db.prepare("DELETE FROM backend WHERE name = ?");
|
|
@@ -32,6 +35,7 @@ function upsertBackends(bdata) {
|
|
|
32
35
|
}
|
|
33
36
|
hasUpdates = true;
|
|
34
37
|
}
|
|
38
|
+
// Upsert the new backends
|
|
35
39
|
for (const backend of bdata) {
|
|
36
40
|
const stmt1 = db.prepare("SELECT * FROM backend WHERE name = ?");
|
|
37
41
|
const result = stmt1.get(backend.name);
|
|
@@ -113,13 +117,19 @@ function upsertAndCleanFeatures(feats, type) {
|
|
|
113
117
|
const stmt = db.prepare(`SELECT name FROM ${type}`);
|
|
114
118
|
const rows = stmt.all();
|
|
115
119
|
const names = rows.map(row => row.name);
|
|
120
|
+
// cleanup removed features
|
|
116
121
|
const availableFeatsNames = feats.map((f) => f.name);
|
|
122
|
+
//console.log("NAMES", names);
|
|
123
|
+
//console.log("AVAILABLE", availableFeatsNames);
|
|
117
124
|
const newFeatures = new Array();
|
|
118
125
|
names.forEach((name) => {
|
|
126
|
+
//console.log(name, !availableFeatsNames.includes(name));
|
|
119
127
|
if (!availableFeatsNames.includes(name)) {
|
|
128
|
+
//console.log("DELETE", name);
|
|
120
129
|
const deleteStmt = db.prepare(`DELETE FROM ${type} WHERE name = ?`);
|
|
121
130
|
deleteStmt.run(name);
|
|
122
131
|
console.log("-", "[" + type + "]", name);
|
|
132
|
+
// check if the feature has a tool and delete if if so
|
|
123
133
|
const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
|
|
124
134
|
const result = stmt1.get(name);
|
|
125
135
|
if (result?.id) {
|
|
@@ -131,6 +141,7 @@ function upsertAndCleanFeatures(feats, type) {
|
|
|
131
141
|
});
|
|
132
142
|
feats.forEach((feat) => {
|
|
133
143
|
if (!names.includes(feat.name)) {
|
|
144
|
+
//console.log("ADD", type, feat);
|
|
134
145
|
if (feat?.variables) {
|
|
135
146
|
const insertStmt = db.prepare(`INSERT INTO ${type} (name, path, ext, variables) VALUES (?, ?, ?, ?)`);
|
|
136
147
|
insertStmt.run(feat.name, feat.path, feat.ext, JSON.stringify(feat.variables, null, 2));
|
|
@@ -148,15 +159,18 @@ function upsertAndCleanFeatures(feats, type) {
|
|
|
148
159
|
function updateVariables(name, variableDoc) {
|
|
149
160
|
const stmt1 = db.prepare("SELECT id FROM task WHERE name = ?");
|
|
150
161
|
const result = stmt1.get(name);
|
|
162
|
+
//console.log("UV res", result);
|
|
151
163
|
if (!result?.id) {
|
|
152
164
|
return;
|
|
153
165
|
}
|
|
154
166
|
const updateStmt = db.prepare("UPDATE task SET variables = ? WHERE id = ?");
|
|
155
167
|
updateStmt.run(variableDoc, result.id);
|
|
168
|
+
//console.log("~", "[task variables] updated for", name);
|
|
156
169
|
}
|
|
157
170
|
function updateUserCmd(feat) {
|
|
158
171
|
const stmt1 = db.prepare("SELECT id FROM cmd WHERE name = ?");
|
|
159
172
|
const result = stmt1.get(feat.name);
|
|
173
|
+
//console.log("UV res", result);
|
|
160
174
|
if (!result?.id) {
|
|
161
175
|
return;
|
|
162
176
|
}
|
|
@@ -167,38 +181,50 @@ function upsertTool(name, type, toolDoc) {
|
|
|
167
181
|
const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
|
|
168
182
|
const result = stmt1.get(name);
|
|
169
183
|
if (result?.id) {
|
|
184
|
+
// Update the existing tool
|
|
170
185
|
const updateStmt = db.prepare("UPDATE tool SET spec = ?, type = ? WHERE id = ?");
|
|
171
186
|
updateStmt.run(toolDoc, type, result.id);
|
|
187
|
+
//console.log("~", "[tool] updated from", type, ":", name);
|
|
172
188
|
}
|
|
173
189
|
else {
|
|
190
|
+
// Insert a new tool
|
|
174
191
|
const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
|
|
175
192
|
stmt.run(name, toolDoc, type);
|
|
193
|
+
//console.log("+", "[tool] added from", type, ":", name);
|
|
176
194
|
}
|
|
177
195
|
}
|
|
178
196
|
function updateFeatures(feats) {
|
|
197
|
+
//console.log("FEATS", feats);
|
|
179
198
|
upsertAndCleanFeatures(feats.agent, "agent");
|
|
180
199
|
feats.agent.forEach((feat) => {
|
|
181
200
|
const { toolDoc, variables } = extractTaskToolDocAndVariables(feat.name, feat.ext, feat.path);
|
|
201
|
+
//const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
202
|
+
//console.log(`TASK ${feat.name} TOOL DOC`, toolDoc);
|
|
182
203
|
if (toolDoc.length > 0) {
|
|
183
204
|
upsertTool(feat.name, "agent", toolDoc);
|
|
184
205
|
}
|
|
185
206
|
if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
|
|
207
|
+
//console.log("UPDATE VARS", feat.name, ":", variables)
|
|
186
208
|
updateVariables(feat.name, JSON.stringify(variables, null, " "));
|
|
187
209
|
}
|
|
188
210
|
});
|
|
189
211
|
upsertAndCleanFeatures(feats.task, "task");
|
|
190
212
|
feats.task.forEach((feat) => {
|
|
191
213
|
const { toolDoc, variables } = extractTaskToolDocAndVariables(feat.name, feat.ext, feat.path);
|
|
214
|
+
//const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
215
|
+
//console.log(`TASK ${feat.name} TOOL DOC`, toolDoc);
|
|
192
216
|
if (toolDoc.length > 0) {
|
|
193
217
|
upsertTool(feat.name, "task", toolDoc);
|
|
194
218
|
}
|
|
195
219
|
if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
|
|
220
|
+
//console.log("UPDATE VARS", feat.name, ":", variables)
|
|
196
221
|
updateVariables(feat.name, JSON.stringify(variables, null, " "));
|
|
197
222
|
}
|
|
198
223
|
});
|
|
199
224
|
upsertAndCleanFeatures(feats.action, "action");
|
|
200
225
|
feats.action.forEach((feat) => {
|
|
201
226
|
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
227
|
+
//console.log(`ACTION ${feat.name} TOOL DOC`, found, toolDoc);
|
|
202
228
|
if (found) {
|
|
203
229
|
upsertTool(feat.name, "action", toolDoc);
|
|
204
230
|
}
|
|
@@ -206,6 +232,7 @@ function updateFeatures(feats) {
|
|
|
206
232
|
upsertAndCleanFeatures(feats.workflow, "workflow");
|
|
207
233
|
feats.workflow.forEach((feat) => {
|
|
208
234
|
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
235
|
+
//console.log(`WORKFLOW ${feat.name} TOOL DOC`, toolDoc);
|
|
209
236
|
if (found) {
|
|
210
237
|
upsertTool(feat.name, "workflow", toolDoc);
|
|
211
238
|
}
|
|
@@ -218,12 +245,14 @@ function upsertFilePath(name, newPath) {
|
|
|
218
245
|
const selectStmt = db.prepare("SELECT * FROM filepath WHERE name = ?");
|
|
219
246
|
const result = selectStmt.get(name);
|
|
220
247
|
if (result?.id) {
|
|
248
|
+
// If the filepath exists, update it
|
|
221
249
|
const q = `UPDATE filepath SET path = ? WHERE name = ?`;
|
|
222
250
|
const stmt = db.prepare(q);
|
|
223
251
|
const updateResult = stmt.run(newPath, name);
|
|
224
252
|
return updateResult.changes > 0;
|
|
225
253
|
}
|
|
226
254
|
else {
|
|
255
|
+
// If the filepath does not exist, insert it
|
|
227
256
|
const insertStmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
|
|
228
257
|
insertStmt.run(name, newPath);
|
|
229
258
|
return true;
|
|
@@ -276,6 +305,7 @@ function upsertTaskSettings(taskName, settings) {
|
|
|
276
305
|
qvalues.push(settings.backend);
|
|
277
306
|
}
|
|
278
307
|
const q = `UPDATE tasksettings SET ${qparams.join(", ")} WHERE name = ?`;
|
|
308
|
+
//console.log("Q", q);
|
|
279
309
|
const stmt = db.prepare(q);
|
|
280
310
|
const updateResult = stmt.run(...qvalues, taskName);
|
|
281
311
|
return updateResult.changes > 0;
|
|
@@ -326,6 +356,8 @@ function upsertTaskSettings(taskName, settings) {
|
|
|
326
356
|
const nq = new Array("?");
|
|
327
357
|
qnames.forEach(n => nq.push("?"));
|
|
328
358
|
const q = `INSERT INTO tasksettings (name, ${qnames.join(", ")}) VALUES (${nq.join(", ")})`;
|
|
359
|
+
//console.log(q);
|
|
360
|
+
//console.log("VALs", qvalues);
|
|
329
361
|
const insertStmt = db.prepare(q);
|
|
330
362
|
insertStmt.run(taskName, ...qvalues);
|
|
331
363
|
return true;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,9 @@ import { resetDbCmd } from './cmd/clicmds/cmds.js';
|
|
|
5
5
|
import { updateConfCmd } from './cmd/clicmds/updateconf.js';
|
|
6
6
|
import { buildCmds, parseCmd } from './cmd/cmds.js';
|
|
7
7
|
import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
|
|
8
|
+
//import { usePerfTimer } from './main.js';
|
|
8
9
|
async function main() {
|
|
10
|
+
//const perf = usePerfTimer();
|
|
9
11
|
const nargs = argv.length;
|
|
10
12
|
if (nargs == 2) {
|
|
11
13
|
runMode.value = "cli";
|
|
@@ -20,10 +22,16 @@ async function main() {
|
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
25
|
+
//perf.measure("base");
|
|
23
26
|
await init();
|
|
27
|
+
//perf.measure("init");
|
|
24
28
|
const program = await buildCmds();
|
|
29
|
+
//perf.measure("buildCmds");
|
|
30
|
+
//perf.final("index start");
|
|
25
31
|
program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
26
32
|
const options = actionCommand.opts();
|
|
33
|
+
//console.log("POPTS", options)
|
|
34
|
+
//const v = options?.clipboardOutput !== undefined;
|
|
27
35
|
if (options?.chat === true) {
|
|
28
36
|
isChatMode.value = true;
|
|
29
37
|
}
|
|
@@ -46,8 +54,10 @@ async function main() {
|
|
|
46
54
|
break;
|
|
47
55
|
default:
|
|
48
56
|
await parseCmd(program);
|
|
57
|
+
//console.log("PARSE CMD END")
|
|
49
58
|
break;
|
|
50
59
|
}
|
|
60
|
+
//console.log("END");
|
|
51
61
|
}
|
|
52
62
|
(async () => {
|
|
53
63
|
await main();
|
package/dist/main.d.ts
CHANGED
|
@@ -12,5 +12,20 @@ import { extractBetweenTags, splitThinking } from "./utils/text.js";
|
|
|
12
12
|
import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
|
|
13
13
|
import { McpClient } from "./cmd/lib/mcp.js";
|
|
14
14
|
import { readTask } from "./cmd/lib/tasks/read.js";
|
|
15
|
-
import { FeatureType } from "./interfaces.js";
|
|
16
|
-
|
|
15
|
+
import { FeatureType, TaskSettings } from "./interfaces.js";
|
|
16
|
+
import { getConfigPath } from "./conf.js";
|
|
17
|
+
import { readFeaturesType, readFilePaths } from "./db/read.js";
|
|
18
|
+
import { readConf } from "./cmd/sys/read_conf.js";
|
|
19
|
+
import { backend } from "./state/backends.js";
|
|
20
|
+
import { getTaskSettings } from "./state/tasks.js";
|
|
21
|
+
import { upsertTaskSettings } from "./db/write.js";
|
|
22
|
+
declare const db: {
|
|
23
|
+
readFilePaths: typeof readFilePaths;
|
|
24
|
+
readFeaturesType: typeof readFeaturesType;
|
|
25
|
+
getTaskSettings: typeof getTaskSettings;
|
|
26
|
+
upsertTaskSettings: typeof upsertTaskSettings;
|
|
27
|
+
};
|
|
28
|
+
declare const fs: {
|
|
29
|
+
openTaskSpec: typeof openTaskSpec;
|
|
30
|
+
};
|
|
31
|
+
export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, isStateReady, backend, McpClient, readTask, FeatureType, getConfigPath, readConf, TaskSettings, db, fs, };
|
package/dist/main.js
CHANGED
|
@@ -12,4 +12,19 @@ import { extractBetweenTags, splitThinking } from "./utils/text.js";
|
|
|
12
12
|
import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
|
|
13
13
|
import { McpClient } from "./cmd/lib/mcp.js";
|
|
14
14
|
import { readTask } from "./cmd/lib/tasks/read.js";
|
|
15
|
-
|
|
15
|
+
import { getConfigPath } from "./conf.js";
|
|
16
|
+
import { readFeaturesType, readFilePaths } from "./db/read.js";
|
|
17
|
+
import { readConf } from "./cmd/sys/read_conf.js";
|
|
18
|
+
import { backend } from "./state/backends.js";
|
|
19
|
+
import { getTaskSettings } from "./state/tasks.js";
|
|
20
|
+
import { upsertTaskSettings } from "./db/write.js";
|
|
21
|
+
const db = {
|
|
22
|
+
readFilePaths,
|
|
23
|
+
readFeaturesType,
|
|
24
|
+
getTaskSettings,
|
|
25
|
+
upsertTaskSettings,
|
|
26
|
+
};
|
|
27
|
+
const fs = {
|
|
28
|
+
openTaskSpec,
|
|
29
|
+
};
|
|
30
|
+
export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, init, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, isStateReady, backend, McpClient, readTask, getConfigPath, readConf, db, fs, };
|
package/dist/state/backends.js
CHANGED
|
@@ -9,8 +9,10 @@ const backends = {};
|
|
|
9
9
|
const isBackendUp = ref(false);
|
|
10
10
|
async function initBackends() {
|
|
11
11
|
const rmb = readBackends();
|
|
12
|
+
//console.log("Backends:", rmb)
|
|
12
13
|
let defaultBackendName = null;
|
|
13
14
|
for (const bk of Object.values(rmb)) {
|
|
15
|
+
//console.log("BK", bk.name);
|
|
14
16
|
let name = bk.name;
|
|
15
17
|
let apiKey = "";
|
|
16
18
|
if (bk?.apiKey) {
|
|
@@ -39,6 +41,12 @@ async function initBackends() {
|
|
|
39
41
|
}
|
|
40
42
|
if (defaultBackendName !== null) {
|
|
41
43
|
backend.value = backends[defaultBackendName];
|
|
44
|
+
//console.log("Setting default backend", defaultBackendName, "/", backend.value.name)
|
|
45
|
+
/*isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
46
|
+
|
|
47
|
+
if (isBackendUp.value && backend.value.providerType == "ollama") {
|
|
48
|
+
await backend.value.modelsInfo();
|
|
49
|
+
}*/
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
async function setBackend(name, isVerbose = false) {
|
|
@@ -52,9 +60,11 @@ async function setBackend(name, isVerbose = false) {
|
|
|
52
60
|
isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
53
61
|
}
|
|
54
62
|
async function listBackends(printResult = true) {
|
|
63
|
+
//console.log("DEFB", backend.value?.name);
|
|
55
64
|
const allBk = new Array();
|
|
56
65
|
for (const [name, lm] of Object.entries(backends)) {
|
|
57
66
|
const bcn = name == backend.value?.name ? colors.bold(name) : name;
|
|
67
|
+
//const isUp = await probeBackend(lm, false);
|
|
58
68
|
const buf = new Array("-", bcn, colors.dim("(" + lm.providerType + ") " + lm.serverUrl));
|
|
59
69
|
const str = buf.join(" ");
|
|
60
70
|
if (printResult) {
|
|
@@ -103,6 +113,8 @@ const probeBackend = async (lm, isVerbose) => {
|
|
|
103
113
|
}
|
|
104
114
|
break;
|
|
105
115
|
case "ollama":
|
|
116
|
+
//console.warn("The Ollama provider is not yet supported");
|
|
117
|
+
//break;
|
|
106
118
|
try {
|
|
107
119
|
await lm.modelsInfo();
|
|
108
120
|
if (isVerbose) {
|
|
@@ -117,6 +129,8 @@ const probeBackend = async (lm, isVerbose) => {
|
|
|
117
129
|
}
|
|
118
130
|
break;
|
|
119
131
|
case "openai":
|
|
132
|
+
//console.warn("The Ollama provider is not yet supported");
|
|
133
|
+
//break;
|
|
120
134
|
try {
|
|
121
135
|
await lm.modelsInfo();
|
|
122
136
|
if (isVerbose) {
|
package/dist/state/plugins.js
CHANGED
|
@@ -5,12 +5,14 @@ async function buildPluginsPaths(names) {
|
|
|
5
5
|
const plugins = new Array();
|
|
6
6
|
const root = await execute("npm", ["root", "-g"]);
|
|
7
7
|
const rootPath = root.trim();
|
|
8
|
+
//console.log("PLUGINS", packs);
|
|
8
9
|
names.forEach((p) => {
|
|
9
10
|
plugins.push({
|
|
10
11
|
name: p,
|
|
11
12
|
path: path.join(rootPath, p, "dist")
|
|
12
13
|
});
|
|
13
14
|
});
|
|
15
|
+
//console.log("PLUGINS PATHS", paths);
|
|
14
16
|
return plugins;
|
|
15
17
|
}
|
|
16
18
|
async function readPluginsPaths() {
|
|
@@ -19,6 +21,7 @@ async function readPluginsPaths() {
|
|
|
19
21
|
plugins.forEach((p) => {
|
|
20
22
|
paths.push(p.path);
|
|
21
23
|
});
|
|
24
|
+
//console.log("PLUGINS PATHS", paths);
|
|
22
25
|
return paths;
|
|
23
26
|
}
|
|
24
27
|
export { buildPluginsPaths, readPluginsPaths };
|