@agent-smith/cli 0.0.91 → 0.0.93
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/cmd/cmds.js +19 -0
- package/dist/cmd/lib/actions/cmd.js +3 -1
- package/dist/cmd/lib/adaptaters/cmd.js +3 -1
- package/dist/cmd/lib/tasks/cmd.js +26 -6
- package/dist/cmd/lib/tasks/conf.js +14 -12
- package/dist/cmd/lib/tasks/read.js +1 -1
- package/dist/cmd/lib/workflows/cmd.js +4 -2
- package/dist/cmd/lib/workflows/read.js +7 -3
- package/dist/cmd/sys/read_cmds.js +3 -1
- package/dist/index.js +2 -4
- package/dist/state/backends.js +2 -2
- package/dist/state/state.d.ts +3 -1
- package/dist/state/state.js +10 -2
- package/package.json +9 -9
package/dist/cmd/cmds.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
import { toRaw } from "@vue/reactivity";
|
|
1
3
|
import { Command } from "commander";
|
|
4
|
+
import { query } from "../cli.js";
|
|
2
5
|
import { readAliases, readFeatures } from "../db/read.js";
|
|
6
|
+
import { chatInferenceParams } from "../state/chat.js";
|
|
7
|
+
import { agent, isChatMode, runMode } from "../state/state.js";
|
|
3
8
|
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
4
9
|
import { initBaseCommands } from "./clicmds/base.js";
|
|
5
10
|
import { initUserCmds } from "./clicmds/cmds.js";
|
|
6
11
|
const program = new Command();
|
|
7
12
|
async function chat(program) {
|
|
13
|
+
const data = { message: '>', default: "" };
|
|
14
|
+
const prompt = await input(data);
|
|
15
|
+
if (prompt == "/q") {
|
|
16
|
+
isChatMode.value = false;
|
|
17
|
+
if (runMode.value == "cmd") {
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await query(program);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
await agent.lm.infer(prompt, toRaw(chatInferenceParams));
|
|
25
|
+
console.log();
|
|
26
|
+
await chat(program);
|
|
8
27
|
}
|
|
9
28
|
async function buildCmds() {
|
|
10
29
|
initBaseCommands(program);
|
|
@@ -8,6 +8,7 @@ import { runtimeError } from "../../../utils/user_msgs.js";
|
|
|
8
8
|
import { readClipboard } from "../../sys/clipboard.js";
|
|
9
9
|
import { processOutput, readPromptFile } from "../utils.js";
|
|
10
10
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
11
|
+
import { pathToFileURL } from 'url';
|
|
11
12
|
async function executeAction(name, payload, options, quiet = false) {
|
|
12
13
|
let run;
|
|
13
14
|
const { found, path, ext } = getFeatureSpec(name, "action");
|
|
@@ -16,7 +17,8 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
16
17
|
}
|
|
17
18
|
switch (ext) {
|
|
18
19
|
case "js":
|
|
19
|
-
const
|
|
20
|
+
const url = pathToFileURL(path).href;
|
|
21
|
+
const mjsa = await import(url);
|
|
20
22
|
run = createJsAction(mjsa.action);
|
|
21
23
|
break;
|
|
22
24
|
case "yml":
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { getFeatureSpec } from "../../../state/features.js";
|
|
2
2
|
import { createJsAction } from "../actions/read.js";
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
3
4
|
async function executeAdaptater(name, params, options) {
|
|
4
5
|
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
5
6
|
if (!found) {
|
|
6
7
|
throw new Error(`adaptater ${name} not found`);
|
|
7
8
|
}
|
|
8
9
|
let run;
|
|
9
|
-
const
|
|
10
|
+
const url = pathToFileURL(path).href;
|
|
11
|
+
const jsa = await import(url);
|
|
10
12
|
run = createJsAction(jsa.action);
|
|
11
13
|
let res;
|
|
12
14
|
try {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Agent } from "@agent-smith/agent";
|
|
2
1
|
import { input } from "@inquirer/prompts";
|
|
3
2
|
import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
|
|
4
3
|
import { default as color, default as colors } from "ansi-colors";
|
|
@@ -7,15 +6,13 @@ import ora from 'ora';
|
|
|
7
6
|
import { query } from "../../../cli.js";
|
|
8
7
|
import { readClipboard } from "../../../cmd/sys/clipboard.js";
|
|
9
8
|
import { usePerfTimer } from "../../../main.js";
|
|
10
|
-
import {
|
|
11
|
-
import { isChatMode, runMode } from "../../../state/state.js";
|
|
9
|
+
import { isChatMode, runMode, agent } from "../../../state/state.js";
|
|
12
10
|
import { program } from "../../cmds.js";
|
|
13
11
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
14
|
-
import { runtimeDataError, runtimeWarning } from "../user_msgs.js";
|
|
12
|
+
import { runtimeDataError, runtimeError, runtimeWarning } from "../user_msgs.js";
|
|
15
13
|
import { formatStats, processOutput, readPromptFile } from "../utils.js";
|
|
16
14
|
import { readTask } from "./read.js";
|
|
17
15
|
async function executeTask(name, payload, options, quiet) {
|
|
18
|
-
const agent = new Agent(backend.value);
|
|
19
16
|
if (options?.debug) {
|
|
20
17
|
console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
|
|
21
18
|
}
|
|
@@ -144,7 +141,30 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
144
141
|
...conf,
|
|
145
142
|
};
|
|
146
143
|
let out;
|
|
147
|
-
|
|
144
|
+
try {
|
|
145
|
+
out = await task.run({ prompt: payload.prompt, ...vars }, tconf);
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
const errMsg = `${e}`;
|
|
149
|
+
if (errMsg.includes("502 Bad Gateway")) {
|
|
150
|
+
runtimeError("The server answered with a 502 Bad Gateway error. It might be down or misconfigured. Check your inference server.");
|
|
151
|
+
if (options?.debug) {
|
|
152
|
+
throw new Error(errMsg);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
else if (errMsg.includes("404 Not Found")) {
|
|
157
|
+
runtimeError("The server answered with a 404 Not Found error. That usually mean that the model you are requesting does not exist on the server.");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
else if (errMsg.includes("fetch failed")) {
|
|
161
|
+
runtimeError("The server is not responding. Check if your inference backend is running.");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new Error(errMsg);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
148
168
|
if (!out.answer.text.endsWith("\n")) {
|
|
149
169
|
console.log();
|
|
150
170
|
}
|
|
@@ -17,22 +17,24 @@ function configureTaskModel(itConf, taskSpec) {
|
|
|
17
17
|
model.template = itConf.templateName;
|
|
18
18
|
foundTemplate = true;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
21
|
-
if (itConf?.model?.name
|
|
22
|
-
|
|
20
|
+
if (!foundTemplate) {
|
|
21
|
+
if (itConf?.model?.name) {
|
|
22
|
+
if (itConf?.model?.name != taskSpec.model.name) {
|
|
23
|
+
const gt = guessTemplate(itConf.model.name);
|
|
24
|
+
model.template = gt;
|
|
25
|
+
foundTemplate = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (taskSpec?.model?.template) {
|
|
29
|
+
model.template = taskSpec.model.template;
|
|
30
|
+
foundTemplate = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const gt = guessTemplate(taskSpec.model.name);
|
|
23
34
|
model.template = gt;
|
|
24
35
|
foundTemplate = true;
|
|
25
36
|
}
|
|
26
37
|
}
|
|
27
|
-
else if (taskSpec?.model?.template) {
|
|
28
|
-
model.template = taskSpec.model.template;
|
|
29
|
-
foundTemplate = true;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const gt = guessTemplate(taskSpec.model.name);
|
|
33
|
-
model.template = gt;
|
|
34
|
-
foundTemplate = true;
|
|
35
|
-
}
|
|
36
38
|
if (itConf?.model?.name) {
|
|
37
39
|
if (taskSpec?.models && Object.keys(taskSpec.models).includes(itConf.model.name)) {
|
|
38
40
|
for (const [k, v] of Object.entries(taskSpec.models)) {
|
|
@@ -18,7 +18,7 @@ async function readTask(name, payload, options, agent) {
|
|
|
18
18
|
const opts = payload?.inferParams ? { ...options, ...payload.inferParams } : options;
|
|
19
19
|
const conf = parseTaskConfigOptions(opts);
|
|
20
20
|
if (options?.debug) {
|
|
21
|
-
console.log("conf:", conf);
|
|
21
|
+
console.log("Task conf:", conf);
|
|
22
22
|
conf.debug = true;
|
|
23
23
|
}
|
|
24
24
|
conf.inferParams = mergeInferParams(conf.inferParams, taskFileSpec.inferParams ?? {});
|
|
@@ -34,7 +34,8 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
34
34
|
break;
|
|
35
35
|
case "action":
|
|
36
36
|
try {
|
|
37
|
-
const
|
|
37
|
+
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
38
|
+
const ares = await executeAction(name, actArgs, options, true);
|
|
38
39
|
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
39
40
|
taskRes.args = ares;
|
|
40
41
|
}
|
|
@@ -51,7 +52,8 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
51
52
|
break;
|
|
52
53
|
case "adaptater":
|
|
53
54
|
try {
|
|
54
|
-
const
|
|
55
|
+
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
56
|
+
const adres = await executeAdaptater(name, actArgs, options);
|
|
55
57
|
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
56
58
|
taskRes.args = adres;
|
|
57
59
|
}
|
|
@@ -7,6 +7,7 @@ import { getFeatureSpec } from '../../../state/features.js';
|
|
|
7
7
|
import { readTask } from "../../sys/read_task.js";
|
|
8
8
|
import { pythonAction, systemAction } from '../actions/cmd.js';
|
|
9
9
|
import { createJsAction } from '../actions/read.js';
|
|
10
|
+
import { pathToFileURL } from 'url';
|
|
10
11
|
async function _createWorkflowFromSpec(spec) {
|
|
11
12
|
const steps = {};
|
|
12
13
|
for (const step of spec.steps) {
|
|
@@ -26,7 +27,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
26
27
|
}
|
|
27
28
|
switch (ext) {
|
|
28
29
|
case "js":
|
|
29
|
-
const
|
|
30
|
+
const url = pathToFileURL(path).href;
|
|
31
|
+
const { action } = await import(url);
|
|
30
32
|
const at = action;
|
|
31
33
|
const wf = {
|
|
32
34
|
type: "action",
|
|
@@ -35,7 +37,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
35
37
|
steps[name] = wf;
|
|
36
38
|
break;
|
|
37
39
|
case "mjs":
|
|
38
|
-
const
|
|
40
|
+
const url2 = pathToFileURL(path).href;
|
|
41
|
+
const mjsa = await import(url2);
|
|
39
42
|
const act = createJsAction(mjsa.action);
|
|
40
43
|
const wf2 = {
|
|
41
44
|
type: "action",
|
|
@@ -68,7 +71,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
68
71
|
if (!found) {
|
|
69
72
|
throw new Error(`Adaptater ${name} not found`);
|
|
70
73
|
}
|
|
71
|
-
const
|
|
74
|
+
const url = pathToFileURL(path).href;
|
|
75
|
+
const jsa = await import(url);
|
|
72
76
|
const act = createJsAction(jsa.action);
|
|
73
77
|
const wf = {
|
|
74
78
|
type: "adaptater",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { default as fs } from "fs";
|
|
2
2
|
import { default as path } from "path";
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
3
4
|
function _readCmdsDir(dir) {
|
|
4
5
|
const fileNames = new Array;
|
|
5
6
|
fs.readdirSync(dir).forEach((filename) => {
|
|
@@ -18,7 +19,8 @@ async function readCmds(dir) {
|
|
|
18
19
|
const cmds = new Array();
|
|
19
20
|
const fileNames = _readCmdsDir(dir);
|
|
20
21
|
for (const name of fileNames) {
|
|
21
|
-
const
|
|
22
|
+
const url = pathToFileURL(path.join(dir, name + ".js")).href;
|
|
23
|
+
const { cmd } = await import(url);
|
|
22
24
|
if (!cmd) {
|
|
23
25
|
throw new Error(`command ${name} not found in ${dir}`);
|
|
24
26
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { argv } from 'process';
|
|
3
3
|
import { query } from "./cli.js";
|
|
4
4
|
import { buildCmds, parseCmd } from './cmd/cmds.js';
|
|
5
|
-
import { formatMode,
|
|
5
|
+
import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
|
|
6
6
|
import { updateConfCmd } from './cmd/clicmds/update.js';
|
|
7
|
-
import { initBackends } from './state/backends.js';
|
|
8
7
|
async function main() {
|
|
9
8
|
const nargs = argv.length;
|
|
10
9
|
if (nargs == 2) {
|
|
@@ -16,8 +15,7 @@ async function main() {
|
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
await
|
|
20
|
-
await initBackends();
|
|
18
|
+
await init();
|
|
21
19
|
const program = await buildCmds();
|
|
22
20
|
program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
23
21
|
const options = actionCommand.opts();
|
package/dist/state/backends.js
CHANGED
|
@@ -55,8 +55,8 @@ const probeBackend = async (lm, isVerbose) => {
|
|
|
55
55
|
switch (lm.providerType) {
|
|
56
56
|
case "llamacpp":
|
|
57
57
|
try {
|
|
58
|
-
const info = await lm.info();
|
|
59
58
|
if (isVerbose) {
|
|
59
|
+
const info = await lm.modelInfo();
|
|
60
60
|
console.log(`Provider ${lm.name} up`, info);
|
|
61
61
|
}
|
|
62
62
|
isUp = true;
|
|
@@ -69,9 +69,9 @@ const probeBackend = async (lm, isVerbose) => {
|
|
|
69
69
|
break;
|
|
70
70
|
case "koboldcpp":
|
|
71
71
|
try {
|
|
72
|
-
const info = await lm.info();
|
|
73
72
|
if (lm.model.name.length > 0) {
|
|
74
73
|
if (isVerbose) {
|
|
74
|
+
const info = await lm.modelInfo();
|
|
75
75
|
console.log(`Provider ${lm.name} up`, info);
|
|
76
76
|
}
|
|
77
77
|
isUp = true;
|
package/dist/state/state.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PythonShell } from 'python-shell';
|
|
2
2
|
import { InputMode, RunMode, FormatMode, OutputMode } from "../interfaces.js";
|
|
3
|
+
import { Agent } from "@agent-smith/agent";
|
|
3
4
|
declare let pyShell: PythonShell;
|
|
4
5
|
declare const inputMode: import("@vue/reactivity").Ref<InputMode, InputMode>;
|
|
5
6
|
declare const outputMode: import("@vue/reactivity").Ref<OutputMode, OutputMode>;
|
|
@@ -9,6 +10,7 @@ declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
|
9
10
|
declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
|
|
10
11
|
declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
|
|
11
12
|
declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
13
|
+
declare let agent: Agent;
|
|
12
14
|
declare const lastCmd: {
|
|
13
15
|
name: string;
|
|
14
16
|
args: Array<string>;
|
|
@@ -17,4 +19,4 @@ declare function initFilepaths(): void;
|
|
|
17
19
|
declare function init(): Promise<void>;
|
|
18
20
|
declare function initState(): Promise<void>;
|
|
19
21
|
declare function pluginDataDir(pluginName: string): string;
|
|
20
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, };
|
|
22
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, agent, };
|
package/dist/state/state.js
CHANGED
|
@@ -3,7 +3,9 @@ import { initDb } from "../db/db.js";
|
|
|
3
3
|
import { readFilePaths } from "../db/read.js";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
|
|
6
|
-
import { initBackends } from "./backends.js";
|
|
6
|
+
import { backend, initBackends } from "./backends.js";
|
|
7
|
+
import { Agent } from "@agent-smith/agent";
|
|
8
|
+
import { runtimeDataError } from "../utils/user_msgs.js";
|
|
7
9
|
let pyShell;
|
|
8
10
|
const inputMode = ref("manual");
|
|
9
11
|
const outputMode = ref("txt");
|
|
@@ -13,6 +15,7 @@ const isChatMode = ref(false);
|
|
|
13
15
|
const promptfilePath = ref("");
|
|
14
16
|
const dataDirPath = ref("");
|
|
15
17
|
const isStateReady = ref(false);
|
|
18
|
+
let agent;
|
|
16
19
|
const lastCmd = reactive({
|
|
17
20
|
name: "",
|
|
18
21
|
args: [],
|
|
@@ -32,6 +35,11 @@ function initFilepaths() {
|
|
|
32
35
|
async function init() {
|
|
33
36
|
await initState();
|
|
34
37
|
await initBackends();
|
|
38
|
+
if (!backend.value) {
|
|
39
|
+
runtimeDataError("No backend found, can not initialize agent");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
agent = new Agent(backend.value);
|
|
35
43
|
}
|
|
36
44
|
async function initState() {
|
|
37
45
|
if (isStateReady.value) {
|
|
@@ -53,4 +61,4 @@ function pluginDataDir(pluginName) {
|
|
|
53
61
|
createDirectoryIfNotExists(pluginDatapath);
|
|
54
62
|
return pluginDatapath;
|
|
55
63
|
}
|
|
56
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, };
|
|
64
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, agent, };
|
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.
|
|
5
|
+
"version": "0.0.93",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"watch": "tsc --noCheck -p . -w"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/agent": "^0.1.
|
|
14
|
-
"@agent-smith/task": "^0.1.
|
|
13
|
+
"@agent-smith/agent": "^0.1.4",
|
|
14
|
+
"@agent-smith/task": "^0.1.5",
|
|
15
15
|
"@agent-smith/tfm": "^0.2.0",
|
|
16
16
|
"@inquirer/prompts": "^7.10.1",
|
|
17
17
|
"@intrinsicai/gbnfgen": "0.12.0",
|
|
18
|
-
"@locallm/api": "^0.
|
|
19
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
20
|
-
"@vue/reactivity": "^3.5.
|
|
18
|
+
"@locallm/api": "^0.7.0",
|
|
19
|
+
"@modelcontextprotocol/sdk": "^1.23.0",
|
|
20
|
+
"@vue/reactivity": "^3.5.25",
|
|
21
21
|
"ansi-colors": "^4.1.3",
|
|
22
|
-
"better-sqlite3": "^12.4.
|
|
22
|
+
"better-sqlite3": "^12.4.6",
|
|
23
23
|
"clipboardy": "^5.0.1",
|
|
24
24
|
"commander": "^14.0.2",
|
|
25
25
|
"marked-terminal": "^7.3.0",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@agent-smith/tmem-jobs": "^0.0.4",
|
|
33
33
|
"@cfworker/json-schema": "^4.1.1",
|
|
34
34
|
"@commander-js/extra-typings": "^14.0.0",
|
|
35
|
-
"@locallm/types": "^0.
|
|
35
|
+
"@locallm/types": "^0.6.2",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
37
37
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
38
38
|
"@types/better-sqlite3": "^7.6.13",
|
|
39
39
|
"@types/marked-terminal": "^6.1.1",
|
|
40
40
|
"@types/node": "^24.10.1",
|
|
41
|
-
"restmix": "^0.
|
|
41
|
+
"restmix": "^0.6.1",
|
|
42
42
|
"rollup": "^4.53.3",
|
|
43
43
|
"ts-node": "^10.9.2",
|
|
44
44
|
"tslib": "2.8.1",
|