@agent-smith/cli 0.0.8 → 0.0.10
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/agent.d.ts +2 -2
- package/dist/cmd/lib/execute_job.d.ts +1 -1
- package/dist/cmd/lib/execute_job.js +46 -15
- package/dist/cmd/lib/execute_task.js +4 -10
- package/dist/cmd/lib/utils.d.ts +5 -1
- package/dist/cmd/lib/utils.js +26 -1
- package/dist/db/db.js +4 -3
- package/dist/db/read.js +1 -1
- package/dist/index.js +0 -0
- package/package.json +6 -6
package/dist/agent.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LmTaskBuilder } from "@agent-smith/lmtask";
|
|
2
2
|
import { marked } from 'marked';
|
|
3
|
-
import { RunMode } from "./interfaces.js";
|
|
3
|
+
import { FeatureType, RunMode } from "./interfaces.js";
|
|
4
4
|
declare let brain: import("@agent-smith/brain").AgentBrain;
|
|
5
5
|
declare const modelsForExpert: Record<string, string>;
|
|
6
|
-
declare const taskBuilder: LmTaskBuilder
|
|
6
|
+
declare const taskBuilder: LmTaskBuilder<FeatureType>;
|
|
7
7
|
declare function initAgent(mode: RunMode, isVerbose?: boolean): Promise<boolean>;
|
|
8
8
|
export { brain, initAgent, marked, modelsForExpert, taskBuilder };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function executeJobCmd(name: string, args?: Array<any>): Promise<
|
|
1
|
+
declare function executeJobCmd(name: string, args?: Array<any>): Promise<Record<string, any>>;
|
|
2
2
|
declare function readJob(name: string): Promise<{
|
|
3
3
|
found: boolean;
|
|
4
4
|
data: Record<string, any>;
|
|
@@ -4,32 +4,61 @@ import { useAgentJob } from "@agent-smith/jobs";
|
|
|
4
4
|
import { brain, marked, taskBuilder } from '../../agent.js';
|
|
5
5
|
import { getFeatureSpec } from '../../state/features.js';
|
|
6
6
|
import { formatMode } from '../../state/state.js';
|
|
7
|
-
import { readTask } from './utils.js';
|
|
7
|
+
import { initTaskVars, readTask } from './utils.js';
|
|
8
8
|
async function executeJobCmd(name, args = []) {
|
|
9
9
|
const { job, found } = await _dispatchReadJob(name);
|
|
10
10
|
if (!found) {
|
|
11
11
|
console.log(`Job ${name} not found`);
|
|
12
|
-
return
|
|
12
|
+
return { error: `Job ${name} not found` };
|
|
13
13
|
}
|
|
14
14
|
await job.start();
|
|
15
15
|
let params = args;
|
|
16
16
|
let res = {};
|
|
17
17
|
brain.backendsForModelsInfo();
|
|
18
|
-
for (const name of Object.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
for (const [name, task] of Object.entries(job.tasks)) {
|
|
19
|
+
if (task.type == "task") {
|
|
20
|
+
const pr = args.shift();
|
|
21
|
+
const { conf, vars } = initTaskVars(args);
|
|
22
|
+
const { found, path } = getFeatureSpec(name, "task");
|
|
23
|
+
if (!found) {
|
|
24
|
+
return { ok: false, data: {}, error: `Task ${name} not found` };
|
|
25
|
+
}
|
|
26
|
+
const tres = readTask(path);
|
|
27
|
+
if (!tres.found) {
|
|
28
|
+
throw new Error(`Task ${name}, ${path} not found`);
|
|
29
|
+
}
|
|
30
|
+
const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
|
|
31
|
+
const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
|
|
32
|
+
if (!ex) {
|
|
33
|
+
throw new Error("No expert found for model " + taskSpec.model.name);
|
|
34
|
+
}
|
|
35
|
+
ex.checkStatus();
|
|
36
|
+
ex.backend.setOnToken((t) => {
|
|
37
|
+
process.stdout.write(t);
|
|
38
|
+
});
|
|
39
|
+
conf["expert"] = ex;
|
|
40
|
+
vars["prompt"] = pr;
|
|
41
|
+
try {
|
|
42
|
+
res = await job.runTask(name, vars, conf);
|
|
43
|
+
if ("text" in res) {
|
|
44
|
+
if (formatMode.value == "markdown") {
|
|
45
|
+
console.log("\n\n------------------\n");
|
|
46
|
+
console.log(marked.parse(res.text).trim());
|
|
47
|
+
}
|
|
25
48
|
}
|
|
26
49
|
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return { error: `Error executing task ${name}: ${err}` };
|
|
52
|
+
}
|
|
27
53
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
54
|
+
else {
|
|
55
|
+
try {
|
|
56
|
+
res = await job.runTask(name, args);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
return { error: `Error executing task ${name}: ${err}` };
|
|
60
|
+
}
|
|
31
61
|
}
|
|
32
|
-
params = res.data;
|
|
33
62
|
}
|
|
34
63
|
await job.finish(true);
|
|
35
64
|
return res;
|
|
@@ -52,7 +81,6 @@ async function _dispatchReadJob(name) {
|
|
|
52
81
|
break;
|
|
53
82
|
default:
|
|
54
83
|
throw new Error(`Job extension ${ext} not implemented`);
|
|
55
|
-
break;
|
|
56
84
|
}
|
|
57
85
|
return { found: true, job: jb };
|
|
58
86
|
}
|
|
@@ -70,7 +98,9 @@ async function _createJobFromSpec(spec) {
|
|
|
70
98
|
return { found: false, job: {} };
|
|
71
99
|
}
|
|
72
100
|
const { action } = await import(path);
|
|
73
|
-
|
|
101
|
+
const at = action;
|
|
102
|
+
at.type = "action";
|
|
103
|
+
tasks[t.name] = at;
|
|
74
104
|
}
|
|
75
105
|
else {
|
|
76
106
|
const { found, path } = getFeatureSpec(t.name, "task");
|
|
@@ -82,6 +112,7 @@ async function _createJobFromSpec(spec) {
|
|
|
82
112
|
throw new Error(`Task ${t.name}, ${path} not found`);
|
|
83
113
|
}
|
|
84
114
|
const at = taskBuilder.fromYaml(res.ymlTask);
|
|
115
|
+
at.type = "task";
|
|
85
116
|
tasks[t.name] = at;
|
|
86
117
|
}
|
|
87
118
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { brain, initAgent, taskBuilder } from "../../agent.js";
|
|
2
2
|
import { getFeatureSpec } from "../../state/features.js";
|
|
3
3
|
import { runMode } from "../../state/state.js";
|
|
4
|
-
import { readTask } from "./utils.js";
|
|
4
|
+
import { initTaskVars, readTask } from "./utils.js";
|
|
5
5
|
async function executeTaskCmd(args = [], options = {}) {
|
|
6
6
|
await initAgent(runMode.value);
|
|
7
7
|
const name = args.shift();
|
|
@@ -16,13 +16,7 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
16
16
|
const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
|
|
17
17
|
const task = taskBuilder.fromYaml(res.ymlTask);
|
|
18
18
|
const pr = args.shift();
|
|
19
|
-
const vars =
|
|
20
|
-
args.forEach((a) => {
|
|
21
|
-
if (a.includes("=")) {
|
|
22
|
-
const t = a.split("=");
|
|
23
|
-
vars[t[0]] = t[1];
|
|
24
|
-
}
|
|
25
|
-
});
|
|
19
|
+
const { conf, vars } = initTaskVars(args);
|
|
26
20
|
const ex = brain.getOrCreateExpertForModel(taskSpec.model.name, taskSpec.template.name);
|
|
27
21
|
if (!ex) {
|
|
28
22
|
throw new Error("No expert found for model " + taskSpec.model.name);
|
|
@@ -31,9 +25,9 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
31
25
|
ex.backend.setOnToken((t) => {
|
|
32
26
|
process.stdout.write(t);
|
|
33
27
|
});
|
|
34
|
-
|
|
28
|
+
conf.expert = ex;
|
|
35
29
|
console.log("Ingesting prompt ...");
|
|
36
|
-
const data = await task.run({ prompt: pr, ...vars });
|
|
30
|
+
const data = await task.run({ prompt: pr, ...vars }, conf);
|
|
37
31
|
if (data?.error) {
|
|
38
32
|
return { ok: false, data: {}, error: `Error executing task: ${data.error}` };
|
|
39
33
|
}
|
package/dist/cmd/lib/utils.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ declare function readTask(taskpath: string): {
|
|
|
6
6
|
ymlTask: string;
|
|
7
7
|
};
|
|
8
8
|
declare function readTasksDir(dir: string): Array<string>;
|
|
9
|
-
|
|
9
|
+
declare function initTaskVars(args: Array<any>): {
|
|
10
|
+
conf: Record<string, any>;
|
|
11
|
+
vars: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
|
package/dist/cmd/lib/utils.js
CHANGED
|
@@ -70,4 +70,29 @@ function readTasksDir(dir) {
|
|
|
70
70
|
});
|
|
71
71
|
return tasks;
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
function initTaskVars(args) {
|
|
74
|
+
const conf = {};
|
|
75
|
+
const vars = {};
|
|
76
|
+
args.forEach((a) => {
|
|
77
|
+
if (a.includes("=")) {
|
|
78
|
+
const t = a.split("=");
|
|
79
|
+
const k = t[0];
|
|
80
|
+
const v = t[1];
|
|
81
|
+
if (k == "m") {
|
|
82
|
+
if (v.includes("/")) {
|
|
83
|
+
const _s = v.split("/");
|
|
84
|
+
conf.model = _s[0];
|
|
85
|
+
conf.template = _s[1];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
conf.model = v;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
vars[k] = v;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return { conf, vars };
|
|
97
|
+
}
|
|
98
|
+
export { readPromptFile, processOutput, setOptions, readTask, readTasksDir, initTaskVars, };
|
package/dist/db/db.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import DatabaseConstructor from "better-sqlite3";
|
|
2
2
|
import { schemas } from "./schemas.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import path from "path";
|
|
4
|
+
const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
|
|
5
|
+
const dbPath = path.join(confDir, "config.db");
|
|
6
|
+
let db = new DatabaseConstructor(dbPath, { fileMustExist: false });
|
|
5
7
|
function initDb(isVerbose = false) {
|
|
6
|
-
db = new DatabaseConstructor(dbPath);
|
|
7
8
|
schemas.forEach((s) => {
|
|
8
9
|
db.exec(s);
|
|
9
10
|
if (isVerbose) {
|
package/dist/db/read.js
CHANGED
|
@@ -44,7 +44,7 @@ function readAliases() {
|
|
|
44
44
|
return f;
|
|
45
45
|
}
|
|
46
46
|
function readFeature(name, type) {
|
|
47
|
-
const q = `SELECT id, path, ext FROM ${type} WHERE name='${name}'`;
|
|
47
|
+
const q = `SELECT id, name, path, ext FROM ${type} WHERE name='${name}'`;
|
|
48
48
|
const stmt = db.prepare(q);
|
|
49
49
|
const result = stmt.get();
|
|
50
50
|
if (result?.id) {
|
package/dist/index.js
CHANGED
|
File without changes
|
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.10",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"watch": "tsc -p . -w"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/brain": "^0.0.
|
|
14
|
-
"@agent-smith/jobs": "^0.0.
|
|
15
|
-
"@agent-smith/lmtask": "^0.0.
|
|
13
|
+
"@agent-smith/brain": "^0.0.26",
|
|
14
|
+
"@agent-smith/jobs": "^0.0.11",
|
|
15
|
+
"@agent-smith/lmtask": "^0.0.20",
|
|
16
16
|
"@inquirer/prompts": "^6.0.1",
|
|
17
17
|
"@inquirer/select": "^3.0.1",
|
|
18
18
|
"@vue/reactivity": "^3.5.6",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"yaml": "^2.5.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@agent-smith/tmem-jobs": "^0.0.
|
|
29
|
+
"@agent-smith/tmem-jobs": "^0.0.4",
|
|
30
30
|
"@commander-js/extra-typings": "^12.1.0",
|
|
31
31
|
"@locallm/types": "^0.1.5",
|
|
32
32
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/marked-terminal": "^6.1.1",
|
|
36
36
|
"@types/node": "^22.5.5",
|
|
37
37
|
"restmix": "^0.5.0",
|
|
38
|
-
"rollup": "^4.
|
|
38
|
+
"rollup": "^4.22.2",
|
|
39
39
|
"ts-node": "^10.9.2",
|
|
40
40
|
"tslib": "2.7.0",
|
|
41
41
|
"typescript": "^5.6.2"
|