@agent-smith/cli 0.0.115 → 0.0.118
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/README.md +274 -34
- package/dist/cli.js +4 -8
- package/dist/cmd/{clicmds/aliases.d.ts → aliases.d.ts} +1 -1
- package/dist/cmd/{clicmds/aliases.js → aliases.js} +1 -26
- package/dist/cmd/{clicmds/base.js → base.js} +21 -17
- package/dist/cmd/build.d.ts +9 -0
- package/dist/cmd/build.js +59 -0
- package/dist/cmd/callbacks.d.ts +11 -0
- package/dist/cmd/callbacks.js +90 -0
- package/dist/cmd/cmds.d.ts +8 -9
- package/dist/cmd/cmds.js +134 -103
- package/dist/cmd/features.d.ts +6 -0
- package/dist/cmd/features.js +57 -0
- package/dist/cmd/{sys/read_cmds.d.ts → read_cmds.d.ts} +1 -1
- package/dist/cmd/{sys/read_cmds.js → read_cmds.js} +1 -1
- package/dist/cmd/user_cmds.d.ts +3 -0
- package/dist/cmd/user_cmds.js +23 -0
- package/dist/index.js +11 -11
- package/dist/main.d.ts +3 -38
- package/dist/main.js +3 -37
- package/dist/state.d.ts +6 -0
- package/dist/state.js +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +50 -0
- package/package.json +10 -20
- package/dist/cmd/clicmds/cmds.d.ts +0 -7
- package/dist/cmd/clicmds/cmds.js +0 -135
- package/dist/cmd/clicmds/updateconf.d.ts +0 -3
- package/dist/cmd/clicmds/updateconf.js +0 -74
- package/dist/cmd/lib/actions/cmd.d.ts +0 -6
- package/dist/cmd/lib/actions/cmd.js +0 -154
- package/dist/cmd/lib/actions/read.d.ts +0 -3
- package/dist/cmd/lib/actions/read.js +0 -17
- package/dist/cmd/lib/adaptaters/cmd.d.ts +0 -2
- package/dist/cmd/lib/adaptaters/cmd.js +0 -39
- package/dist/cmd/lib/agents/cmd.d.ts +0 -3
- package/dist/cmd/lib/agents/cmd.js +0 -11
- package/dist/cmd/lib/mcp.d.ts +0 -16
- package/dist/cmd/lib/mcp.js +0 -105
- package/dist/cmd/lib/options_parsers.d.ts +0 -7
- package/dist/cmd/lib/options_parsers.js +0 -52
- package/dist/cmd/lib/tasks/cmd.d.ts +0 -4
- package/dist/cmd/lib/tasks/cmd.js +0 -419
- package/dist/cmd/lib/tasks/conf.d.ts +0 -6
- package/dist/cmd/lib/tasks/conf.js +0 -131
- package/dist/cmd/lib/tasks/read.d.ts +0 -14
- package/dist/cmd/lib/tasks/read.js +0 -186
- package/dist/cmd/lib/tasks/utils.d.ts +0 -8
- package/dist/cmd/lib/tasks/utils.js +0 -48
- package/dist/cmd/lib/tools.d.ts +0 -15
- package/dist/cmd/lib/tools.js +0 -147
- package/dist/cmd/lib/utils.d.ts +0 -3
- package/dist/cmd/lib/utils.js +0 -54
- package/dist/cmd/lib/workflows/cmd.d.ts +0 -3
- package/dist/cmd/lib/workflows/cmd.js +0 -230
- package/dist/cmd/lib/workflows/read.d.ts +0 -6
- package/dist/cmd/lib/workflows/read.js +0 -61
- package/dist/cmd/sys/clipboard.d.ts +0 -3
- package/dist/cmd/sys/clipboard.js +0 -33
- package/dist/cmd/sys/delete_file.d.ts +0 -2
- package/dist/cmd/sys/delete_file.js +0 -10
- package/dist/cmd/sys/dirs.d.ts +0 -2
- package/dist/cmd/sys/dirs.js +0 -9
- package/dist/cmd/sys/execute.d.ts +0 -13
- package/dist/cmd/sys/execute.js +0 -48
- package/dist/cmd/sys/read.d.ts +0 -3
- package/dist/cmd/sys/read.js +0 -21
- package/dist/cmd/sys/read_conf.d.ts +0 -6
- package/dist/cmd/sys/read_conf.js +0 -12
- package/dist/cmd/sys/read_features.d.ts +0 -3
- package/dist/cmd/sys/read_features.js +0 -112
- package/dist/cmd/sys/read_task.d.ts +0 -6
- package/dist/cmd/sys/read_task.js +0 -23
- package/dist/cmd/sys/read_yml_file.d.ts +0 -5
- package/dist/cmd/sys/read_yml_file.js +0 -11
- package/dist/cmd/sys/run_python.d.ts +0 -6
- package/dist/cmd/sys/run_python.js +0 -39
- package/dist/conf.d.ts +0 -14
- package/dist/conf.js +0 -166
- package/dist/const.d.ts +0 -3
- package/dist/const.js +0 -24
- package/dist/db/db.d.ts +0 -4
- package/dist/db/db.js +0 -23
- package/dist/db/read.d.ts +0 -34
- package/dist/db/read.js +0 -128
- package/dist/db/schemas.d.ts +0 -2
- package/dist/db/schemas.js +0 -105
- package/dist/db/write.d.ts +0 -15
- package/dist/db/write.js +0 -376
- package/dist/interfaces.d.ts +0 -165
- package/dist/interfaces.js +0 -1
- package/dist/state/backends.d.ts +0 -7
- package/dist/state/backends.js +0 -159
- package/dist/state/chat.d.ts +0 -7
- package/dist/state/chat.js +0 -10
- package/dist/state/features.d.ts +0 -8
- package/dist/state/features.js +0 -35
- package/dist/state/plugins.d.ts +0 -6
- package/dist/state/plugins.js +0 -27
- package/dist/state/state.d.ts +0 -20
- package/dist/state/state.js +0 -80
- package/dist/state/tasks.d.ts +0 -6
- package/dist/state/tasks.js +0 -28
- package/dist/utils/perf.d.ts +0 -9
- package/dist/utils/perf.js +0 -63
- package/dist/utils/text.d.ts +0 -6
- package/dist/utils/text.js +0 -41
- package/dist/utils/user_msgs.d.ts +0 -5
- package/dist/utils/user_msgs.js +0 -19
- /package/dist/cmd/{clicmds/base.d.ts → base.d.ts} +0 -0
- /package/dist/{cmd/options.d.ts → options.d.ts} +0 -0
- /package/dist/{cmd/options.js → options.js} +0 -0
- /package/dist/{cmd/lib/user_msgs.d.ts → user_msgs.d.ts} +0 -0
- /package/dist/{cmd/lib/user_msgs.js → user_msgs.js} +0 -0
package/dist/utils.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import colors from "ansi-colors";
|
|
3
|
+
function parseCommandArgs(args) {
|
|
4
|
+
//discard the command (last arg)
|
|
5
|
+
args.pop();
|
|
6
|
+
//console.log("Raw command args:", args);
|
|
7
|
+
const res = {
|
|
8
|
+
args: new Array(),
|
|
9
|
+
options: {},
|
|
10
|
+
};
|
|
11
|
+
res.options = args.pop();
|
|
12
|
+
res.args = Array.isArray(args[0]) ? args[0] : args;
|
|
13
|
+
//console.log("PARSE ARGS RES", res.args);
|
|
14
|
+
//console.log("PARSE OPTS RES", res.options);
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
async function confirmToolUsage(toolCall) {
|
|
18
|
+
console.log("Tool call:", colors.bold(toolCall.name));
|
|
19
|
+
if (toolCall?.arguments) {
|
|
20
|
+
console.log("Arguments:", toolCall.arguments);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.log("No arguments");
|
|
24
|
+
}
|
|
25
|
+
return await confirm({ message: `Execute tool ${toolCall.name}?` });
|
|
26
|
+
}
|
|
27
|
+
let c = false;
|
|
28
|
+
const printToken = (t, showTokens = false, dim = false) => {
|
|
29
|
+
if (dim === true) {
|
|
30
|
+
process.stdout.write(`\x1b[2m${t}\x1b[0m`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (showTokens === true) {
|
|
34
|
+
let txt = t;
|
|
35
|
+
txt = c ? t : `\x1b[100m${t}\x1b[0m`;
|
|
36
|
+
process.stdout.write(txt);
|
|
37
|
+
c = !c;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
/*if (formatMode.value == "markdown") {
|
|
41
|
+
fullTxt += t;
|
|
42
|
+
process.stdout.write('\u001Bc\u001B[3J');
|
|
43
|
+
process.stdout.write(marked.parse(fullTxt) as string);*/
|
|
44
|
+
//} else {
|
|
45
|
+
process.stdout.write(t);
|
|
46
|
+
//}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export { parseCommandArgs, confirmToolUsage, printToken, };
|
package/package.json
CHANGED
|
@@ -1,45 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-smith/cli",
|
|
3
3
|
"description": "Agent Smith: terminal client for language model agents",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.118",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist/* && tsc",
|
|
7
7
|
"cli": "node --loader ts-node/esm bin/index.ts",
|
|
8
8
|
"watch": "tsc --noCheck -p . -w"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@agent-smith/
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"@agent-smith/tfm": "^0.3.0",
|
|
15
|
-
"@inquirer/prompts": "^8.3.2",
|
|
16
|
-
"@intrinsicai/gbnfgen": "^0.12.0",
|
|
17
|
-
"@locallm/api": "^0.8.0",
|
|
18
|
-
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
19
|
-
"@vue/reactivity": "^3.5.31",
|
|
11
|
+
"@agent-smith/core": "^0.0.1",
|
|
12
|
+
"@inquirer/prompts": "^8.4.0",
|
|
13
|
+
"@vue/reactivity": "^3.5.33",
|
|
20
14
|
"ansi-colors": "^4.1.3",
|
|
21
|
-
"better-sqlite3": "^12.8.0",
|
|
22
15
|
"clipboardy": "^5.3.1",
|
|
23
16
|
"commander": "^14.0.3",
|
|
24
17
|
"marked-terminal": "^7.3.0",
|
|
25
|
-
"modprompt": "^0.14.2",
|
|
26
18
|
"ora": "^9.3.0",
|
|
27
|
-
"python-shell": "^5.0.0",
|
|
28
19
|
"yaml": "^2.8.3"
|
|
29
20
|
},
|
|
30
21
|
"devDependencies": {
|
|
22
|
+
"@agent-smith/agent": "^0.5.0",
|
|
23
|
+
"@agent-smith/types": "^0.0.5",
|
|
31
24
|
"@cfworker/json-schema": "^4.1.1",
|
|
32
25
|
"@commander-js/extra-typings": "^14.0.0",
|
|
33
|
-
"@locallm/types": "^0.7.1",
|
|
34
26
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
35
27
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
36
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
37
28
|
"@types/marked-terminal": "^6.1.1",
|
|
38
|
-
"@types/node": "^25.5.
|
|
39
|
-
"
|
|
40
|
-
"restmix": "^0.6.1",
|
|
29
|
+
"@types/node": "^25.5.2",
|
|
30
|
+
"ts-node": "^10.9.2",
|
|
41
31
|
"tslib": "2.8.1",
|
|
42
|
-
"typescript": "^
|
|
32
|
+
"typescript": "^6.0.2"
|
|
43
33
|
},
|
|
44
34
|
"type": "module",
|
|
45
35
|
"preferGlobal": true,
|
|
@@ -61,7 +51,7 @@
|
|
|
61
51
|
},
|
|
62
52
|
"repository": {
|
|
63
53
|
"type": "git",
|
|
64
|
-
"url": "git+https://github.com/
|
|
54
|
+
"url": "git+https://github.com/lynxai-team/agent-smith.git"
|
|
65
55
|
},
|
|
66
56
|
"license": "MIT"
|
|
67
57
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { FeatureSpec } from '../../interfaces.js';
|
|
3
|
-
declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>, program: Command): Promise<Array<Command>>;
|
|
4
|
-
declare function resetDbCmd(): Promise<any>;
|
|
5
|
-
declare function processTasksCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
|
|
6
|
-
declare function processTaskCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
|
|
7
|
-
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, };
|
package/dist/cmd/clicmds/cmds.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import colors from "ansi-colors";
|
|
2
|
-
import { Option } from 'commander';
|
|
3
|
-
import path from "path";
|
|
4
|
-
import YAML from 'yaml';
|
|
5
|
-
import { dbPath } from "../../conf.js";
|
|
6
|
-
import { readFeaturesType, readTaskSetting } from "../../db/read.js";
|
|
7
|
-
import { deleteTaskSetting, upsertTaskSettings } from "../../db/write.js";
|
|
8
|
-
import { getFeatureSpec } from "../../state/features.js";
|
|
9
|
-
import { runMode } from "../../state/state.js";
|
|
10
|
-
import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from '../../state/tasks.js';
|
|
11
|
-
import { deleteFileIfExists } from "../sys/delete_file.js";
|
|
12
|
-
import { readTask } from "../sys/read_task.js";
|
|
13
|
-
import { parseCommandArgs } from "../lib/options_parsers.js";
|
|
14
|
-
import { readCmd } from "../sys/read_cmds.js";
|
|
15
|
-
import { runtimeDataError } from "../lib/user_msgs.js";
|
|
16
|
-
import { allOptions, displayOptions, inferenceOptions, ioOptions } from "../options.js";
|
|
17
|
-
async function initUserCmds(cmdFeats, program) {
|
|
18
|
-
const features = Object.values(cmdFeats);
|
|
19
|
-
const usrCmds = [];
|
|
20
|
-
for (const feat of features) {
|
|
21
|
-
//console.log("Init cmd", feat);
|
|
22
|
-
const hasVariables = feat?.variables ? true : false;
|
|
23
|
-
const vars = hasVariables ? feat.variables : {};
|
|
24
|
-
let desc = "";
|
|
25
|
-
if (hasVariables) {
|
|
26
|
-
desc = vars.description;
|
|
27
|
-
}
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
const cmd = program.command(feat.variables.name)
|
|
30
|
-
.description(desc)
|
|
31
|
-
.action(async (...args) => {
|
|
32
|
-
const ca = parseCommandArgs(args);
|
|
33
|
-
const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
|
|
34
|
-
const c = await readCmd(feat.name, cmdPath);
|
|
35
|
-
if (!c) {
|
|
36
|
-
runtimeDataError(`can not import command ${feat.name}`);
|
|
37
|
-
throw new Error();
|
|
38
|
-
}
|
|
39
|
-
await c.run(ca.args, ca.options);
|
|
40
|
-
});
|
|
41
|
-
if (hasVariables) {
|
|
42
|
-
if (vars?.options) {
|
|
43
|
-
for (const opt of vars.options) {
|
|
44
|
-
if (Array.isArray(opt)) {
|
|
45
|
-
cmd.addOption(new Option(opt[0], opt[1]));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// predefined option
|
|
49
|
-
switch (opt) {
|
|
50
|
-
case "all":
|
|
51
|
-
allOptions.forEach(o => cmd.addOption(o));
|
|
52
|
-
break;
|
|
53
|
-
case "display":
|
|
54
|
-
displayOptions.forEach(o => cmd.addOption(o));
|
|
55
|
-
break;
|
|
56
|
-
case "inference":
|
|
57
|
-
inferenceOptions.forEach(o => cmd.addOption(o));
|
|
58
|
-
break;
|
|
59
|
-
case "io":
|
|
60
|
-
ioOptions.forEach(o => cmd.addOption(o));
|
|
61
|
-
default:
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
usrCmds.push(cmd);
|
|
69
|
-
}
|
|
70
|
-
//console.log("USRCMDS", usrCmds.map(c => c.name()))
|
|
71
|
-
return usrCmds;
|
|
72
|
-
}
|
|
73
|
-
async function resetDbCmd() {
|
|
74
|
-
if (runMode.value == "cli") {
|
|
75
|
-
console.log("This command can not be run in cli mode");
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
deleteFileIfExists(dbPath);
|
|
79
|
-
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
80
|
-
}
|
|
81
|
-
async function processTasksCmd(args, options) {
|
|
82
|
-
if (options?.conf) {
|
|
83
|
-
if (!isTaskSettingsInitialized.value) {
|
|
84
|
-
initTaskSettings();
|
|
85
|
-
}
|
|
86
|
-
//console.log("PTS", tasksSettings);
|
|
87
|
-
console.log(YAML.stringify({ "tasks": tasksSettings }));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const ts = Object.keys(readFeaturesType("task")).sort();
|
|
91
|
-
console.table(ts);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async function processTaskCmd(args, options) {
|
|
95
|
-
//console.log("TASK OPTS", options);
|
|
96
|
-
if (args.length == 0) {
|
|
97
|
-
console.warn("Provide a task name");
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const { found, path } = getFeatureSpec(args[0], "task");
|
|
101
|
-
if (!found) {
|
|
102
|
-
console.warn(`Task ${args[0]} not found`);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (options?.reset) {
|
|
106
|
-
deleteTaskSetting(args[0]);
|
|
107
|
-
console.log("Task", args[0], "reset ok");
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
//console.log("RT", path)
|
|
111
|
-
const res = readTask(path);
|
|
112
|
-
if (!res.found) {
|
|
113
|
-
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
114
|
-
}
|
|
115
|
-
//const ts = JSON.parse(res.ymlTask);
|
|
116
|
-
console.log(res.ymlTask);
|
|
117
|
-
if (Object.keys(options).length > 0) {
|
|
118
|
-
upsertTaskSettings(args[0], options);
|
|
119
|
-
}
|
|
120
|
-
const s = readTaskSetting(args[0]);
|
|
121
|
-
if (s.found) {
|
|
122
|
-
const sts = s.settings;
|
|
123
|
-
delete sts.id;
|
|
124
|
-
delete sts.name;
|
|
125
|
-
const display = {};
|
|
126
|
-
for (const [k, v] of Object.entries(sts)) {
|
|
127
|
-
if (v) {
|
|
128
|
-
display[k] = v;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
console.log(colors.dim("Settings") + ":", display);
|
|
132
|
-
}
|
|
133
|
-
//console.log(JSON.stringify(ts, null, " "));
|
|
134
|
-
}
|
|
135
|
-
export { initUserCmds, processTaskCmd, processTasksCmd, resetDbCmd, };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { processConfPath } from "../../conf.js";
|
|
3
|
-
import { initDb } from "../../db/db.js";
|
|
4
|
-
import { readFeaturePaths, readFilePath } from "../../db/read.js";
|
|
5
|
-
import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
|
|
6
|
-
import { readFeaturesDirs } from "../../state/features.js";
|
|
7
|
-
import { readPluginsPaths } from "../../state/plugins.js";
|
|
8
|
-
import { dataDirPath, promptfilePath } from "../../state/state.js";
|
|
9
|
-
import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
|
|
10
|
-
import { readUserCmd } from "../sys/read_cmds.js";
|
|
11
|
-
async function getUserCmdsData(feats) {
|
|
12
|
-
for (const feat of feats.cmd) {
|
|
13
|
-
const cmdPath = path.join(feat.path, feat.name + "." + feat.ext);
|
|
14
|
-
const { found, userCmd } = await readUserCmd(feat.name, cmdPath);
|
|
15
|
-
if (found) {
|
|
16
|
-
feat.variables = {
|
|
17
|
-
description: userCmd.description,
|
|
18
|
-
name: userCmd.name,
|
|
19
|
-
};
|
|
20
|
-
if (userCmd?.options) {
|
|
21
|
-
feat.variables.options = userCmd.options;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return feats;
|
|
26
|
-
}
|
|
27
|
-
async function updateAllFeatures(paths) {
|
|
28
|
-
let feats = readFeaturesDirs(paths, true);
|
|
29
|
-
feats = await getUserCmdsData(feats);
|
|
30
|
-
updateFeatures(feats);
|
|
31
|
-
updateAliases(feats);
|
|
32
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
33
|
-
for (const el of deleted) {
|
|
34
|
-
console.log("- [feature path]", el);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function updateFeaturesCmd(options) {
|
|
38
|
-
const fp = readFeaturePaths();
|
|
39
|
-
const pp = await readPluginsPaths();
|
|
40
|
-
const paths = [...fp, ...pp];
|
|
41
|
-
updateAllFeatures(paths);
|
|
42
|
-
}
|
|
43
|
-
async function updateConfCmd(args) {
|
|
44
|
-
initDb(false, true);
|
|
45
|
-
// try to find a conf path in db
|
|
46
|
-
const { found, path } = readFilePath("conf");
|
|
47
|
-
const userProvidedConfPath = (args[0] != "conf") ? args[0] : null;
|
|
48
|
-
if (!found && !userProvidedConfPath) {
|
|
49
|
-
runtimeDataError("conf file path not found in db: please provide a conf path parameter to the command");
|
|
50
|
-
}
|
|
51
|
-
let confPath;
|
|
52
|
-
if (userProvidedConfPath) {
|
|
53
|
-
confPath = userProvidedConfPath;
|
|
54
|
-
const isu = upsertFilePath("conf", confPath);
|
|
55
|
-
if (isu) {
|
|
56
|
-
runtimeInfo("Config path", confPath, "updated");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
confPath = path;
|
|
61
|
-
}
|
|
62
|
-
const { paths, pf, dd } = await processConfPath(confPath);
|
|
63
|
-
console.log("Using", confPath, "to update features at", paths);
|
|
64
|
-
if (pf.length > 0) {
|
|
65
|
-
updatePromptfilePath(pf);
|
|
66
|
-
promptfilePath.value = pf;
|
|
67
|
-
}
|
|
68
|
-
if (dd.length > 0) {
|
|
69
|
-
updateDataDirPath(dd);
|
|
70
|
-
dataDirPath.value = dd;
|
|
71
|
-
}
|
|
72
|
-
updateAllFeatures(paths);
|
|
73
|
-
}
|
|
74
|
-
export { updateConfCmd, updateFeaturesCmd, };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { FeatureExecutor } from "../../../interfaces.js";
|
|
2
|
-
declare function executeAction(name: string, payload: any, options: Record<string, any>, quiet?: boolean): Promise<any>;
|
|
3
|
-
declare function executeActionCmd(name: string, aargs: Array<any>, quiet?: boolean): Promise<any>;
|
|
4
|
-
declare function systemAction(path: string): FeatureExecutor<Array<string>, any>;
|
|
5
|
-
declare function pythonAction(path: string): FeatureExecutor<Array<string>>;
|
|
6
|
-
export { executeAction, executeActionCmd, systemAction, pythonAction, };
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { getFeatureSpec } from '../../../state/features.js';
|
|
2
|
-
import { readYmlFile } from "../../sys/read_yml_file.js";
|
|
3
|
-
import { execute } from "../../sys/execute.js";
|
|
4
|
-
import { runPyScript } from "../../sys/run_python.js";
|
|
5
|
-
import { pyShell } from "../../../state/state.js";
|
|
6
|
-
import { createJsAction } from "./read.js";
|
|
7
|
-
import { runtimeError } from "../../../utils/user_msgs.js";
|
|
8
|
-
import { readClipboard } from "../../sys/clipboard.js";
|
|
9
|
-
import { processOutput, readPromptFile } from "../utils.js";
|
|
10
|
-
import { parseCommandArgs } from "../options_parsers.js";
|
|
11
|
-
import { pathToFileURL } from 'url';
|
|
12
|
-
import { getInputFromOptions } from '../tasks/utils.js';
|
|
13
|
-
async function executeAction(name, payload, options, quiet = false) {
|
|
14
|
-
let run;
|
|
15
|
-
//console.log("GET ACTION", name, payload);
|
|
16
|
-
const inputData = await getInputFromOptions(options);
|
|
17
|
-
if (inputData) {
|
|
18
|
-
if (Array.isArray(payload)) {
|
|
19
|
-
payload.push(inputData);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const { found, path, ext } = getFeatureSpec(name, "action");
|
|
23
|
-
if (!found) {
|
|
24
|
-
throw new Error(`Action ${name} not found at ${path}`);
|
|
25
|
-
}
|
|
26
|
-
//console.log("CREATE ACTION", name, ext, path);
|
|
27
|
-
switch (ext) {
|
|
28
|
-
case "js":
|
|
29
|
-
const url = pathToFileURL(path).href;
|
|
30
|
-
//console.log("CR JSA", url);
|
|
31
|
-
const mjsa = await import(/* @vite-ignore */ url);
|
|
32
|
-
run = createJsAction(mjsa.action);
|
|
33
|
-
//console.log("END CR JSA")
|
|
34
|
-
break;
|
|
35
|
-
case "yml":
|
|
36
|
-
run = systemAction(path);
|
|
37
|
-
break;
|
|
38
|
-
case "py":
|
|
39
|
-
run = pythonAction(path);
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
throw new Error(`Action ext ${ext} not implemented`);
|
|
43
|
-
}
|
|
44
|
-
//console.log("RUN", payload);
|
|
45
|
-
const res = await run(payload, options);
|
|
46
|
-
if (!quiet) {
|
|
47
|
-
if (res) {
|
|
48
|
-
console.log(res);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
await processOutput(res);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
54
|
-
async function executeActionCmd(name, aargs, quiet = false) {
|
|
55
|
-
//console.log("AARGs", aargs)
|
|
56
|
-
const { args, options } = parseCommandArgs(aargs);
|
|
57
|
-
//console.log("CMDA", args)
|
|
58
|
-
const params = args;
|
|
59
|
-
if (options?.clipBoardInput) {
|
|
60
|
-
params.push(await readClipboard());
|
|
61
|
-
}
|
|
62
|
-
else if (options?.inputFile) {
|
|
63
|
-
params.push(readPromptFile());
|
|
64
|
-
}
|
|
65
|
-
if (options?.debug) {
|
|
66
|
-
console.log("Action", name, "params", params);
|
|
67
|
-
}
|
|
68
|
-
return await executeAction(name, params, options, quiet);
|
|
69
|
-
}
|
|
70
|
-
function systemAction(path) {
|
|
71
|
-
const run = async (params) => {
|
|
72
|
-
//console.log("SYS ACTION PARAMS", params);
|
|
73
|
-
let runArgs = new Array();
|
|
74
|
-
// convert args for tool calls
|
|
75
|
-
if (!Array.isArray(params)) {
|
|
76
|
-
try {
|
|
77
|
-
// obviously a tool call
|
|
78
|
-
if (typeof params == "string") {
|
|
79
|
-
runArgs.push(params);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
runArgs = Object.values(params);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
throw new Error(`wrong python action args: ${e}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
runArgs = params;
|
|
91
|
-
}
|
|
92
|
-
const actionSpec = readYmlFile(path);
|
|
93
|
-
if (!actionSpec.found) {
|
|
94
|
-
runtimeError("System action yml file", path, "not found");
|
|
95
|
-
}
|
|
96
|
-
//console.log("Yml action", JSON.stringify(actionSpec.data, null, " "));
|
|
97
|
-
//console.log("Args", args)
|
|
98
|
-
if (!actionSpec.data?.args) {
|
|
99
|
-
actionSpec.data.args = [];
|
|
100
|
-
}
|
|
101
|
-
//console.log("EXEC", actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
|
|
102
|
-
const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...runArgs]);
|
|
103
|
-
return out.trim();
|
|
104
|
-
};
|
|
105
|
-
return run;
|
|
106
|
-
}
|
|
107
|
-
function pythonAction(path) {
|
|
108
|
-
const run = async (params) => {
|
|
109
|
-
//console.log("PY ACTION PARAMS", params);
|
|
110
|
-
let runArgs = new Array();
|
|
111
|
-
if (!Array.isArray(params)) {
|
|
112
|
-
try {
|
|
113
|
-
// obviously a tool call
|
|
114
|
-
if (typeof params == "string") {
|
|
115
|
-
runArgs.push(params);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
runArgs = Object.values(params);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
throw new Error(`wrong python action args: ${e}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
runArgs = params;
|
|
127
|
-
}
|
|
128
|
-
//console.log("Py action", path);
|
|
129
|
-
const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
|
|
130
|
-
/*console.log("----------------");
|
|
131
|
-
console.log("PYOUT", data);
|
|
132
|
-
console.log("----------------");*/
|
|
133
|
-
if (error) {
|
|
134
|
-
throw new Error(`python error: ${error}`);
|
|
135
|
-
}
|
|
136
|
-
let txt = data[0];
|
|
137
|
-
if (data.length > 1) {
|
|
138
|
-
txt = data.join("\n");
|
|
139
|
-
}
|
|
140
|
-
let final = txt;
|
|
141
|
-
if (txt.startsWith("{") || txt.startsWith("[")) {
|
|
142
|
-
try {
|
|
143
|
-
final = JSON.parse(txt);
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
console.warn("Can not parse json from python action", path, e);
|
|
147
|
-
//throw new Error(`python error: ${error}`)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return final;
|
|
151
|
-
};
|
|
152
|
-
return run;
|
|
153
|
-
}
|
|
154
|
-
export { executeAction, executeActionCmd, systemAction, pythonAction, };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
function createJsAction(action) {
|
|
2
|
-
const run = async (args, options) => {
|
|
3
|
-
//console.log("JS ACTION PARAMS", args);
|
|
4
|
-
try {
|
|
5
|
-
const res = await action(args, options);
|
|
6
|
-
return res;
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
9
|
-
/*if (e?.text) {
|
|
10
|
-
throw new Error(`executing action:${e.text()}. Args: ${args}`);
|
|
11
|
-
}*/
|
|
12
|
-
throw new Error(`executing action:${e}. Args: ${args}`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
return run;
|
|
16
|
-
}
|
|
17
|
-
export { createJsAction };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { getFeatureSpec } from "../../../state/features.js";
|
|
2
|
-
import { createJsAction } from "../actions/read.js";
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
import { getInputFromOptions } from "../tasks/utils.js";
|
|
5
|
-
async function executeAdaptater(name, params, options) {
|
|
6
|
-
/*if (params?.args) {
|
|
7
|
-
params = params.args;
|
|
8
|
-
}*/
|
|
9
|
-
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
10
|
-
if (!found) {
|
|
11
|
-
throw new Error(`adaptater ${name} not found`);
|
|
12
|
-
}
|
|
13
|
-
const inputData = await getInputFromOptions(options);
|
|
14
|
-
if (inputData) {
|
|
15
|
-
if (Array.isArray(params)) {
|
|
16
|
-
params.push(inputData);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
let run;
|
|
20
|
-
const url = pathToFileURL(path).href;
|
|
21
|
-
const jsa = await import(/* @vite-ignore */ url);
|
|
22
|
-
run = createJsAction(jsa.action);
|
|
23
|
-
let res;
|
|
24
|
-
try {
|
|
25
|
-
//console.log("ADAPT RUN PARAMS", params);
|
|
26
|
-
res = await run(params, options);
|
|
27
|
-
//console.log("ADAPT RES", res);
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
throw new Error(`adaptater ${name}: ${e}`);
|
|
31
|
-
}
|
|
32
|
-
if (res?.error) {
|
|
33
|
-
throw res.error;
|
|
34
|
-
}
|
|
35
|
-
//await processOutput(res);
|
|
36
|
-
//console.log("ADRES", res);
|
|
37
|
-
return res;
|
|
38
|
-
}
|
|
39
|
-
export { executeAdaptater, };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { parseCommandArgs } from "../options_parsers.js";
|
|
2
|
-
import { getTaskPrompt } from "../tasks/utils.js";
|
|
3
|
-
import { executeTask } from "../tasks/cmd.js";
|
|
4
|
-
async function executeAgentCmd(name, targs = []) {
|
|
5
|
-
const ca = parseCommandArgs(targs);
|
|
6
|
-
const prompt = await getTaskPrompt(name, ca.args, ca.options);
|
|
7
|
-
ca.options.isAgent = true;
|
|
8
|
-
const res = await executeTask(name, { prompt: prompt }, ca.options);
|
|
9
|
-
return res;
|
|
10
|
-
}
|
|
11
|
-
export { executeAgentCmd, };
|
package/dist/cmd/lib/mcp.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
-
import { ToolSpec } from "@locallm/types";
|
|
4
|
-
declare class McpClient {
|
|
5
|
-
name: string;
|
|
6
|
-
transport: StdioClientTransport;
|
|
7
|
-
client: Client;
|
|
8
|
-
authorizedTools: Array<string> | null;
|
|
9
|
-
askUserTools: Array<string> | null;
|
|
10
|
-
tools: Record<string, ToolSpec>;
|
|
11
|
-
constructor(servername: string, command: string, args: Array<string>, authorizedTools?: Array<string> | null, askUserTools?: Array<string> | null);
|
|
12
|
-
start(): Promise<void>;
|
|
13
|
-
stop(): Promise<void>;
|
|
14
|
-
extractTools(): Promise<Array<ToolSpec>>;
|
|
15
|
-
}
|
|
16
|
-
export { McpClient, };
|