@agent-smith/cli 0.0.57 → 0.0.59
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/lib/actions/cmd.js +8 -4
- package/dist/cmd/lib/tasks/cmd.js +12 -18
- package/dist/cmd/lib/tasks/conf.js +2 -2
- package/dist/cmd/lib/tasks/utils.d.ts +3 -0
- package/dist/cmd/lib/tasks/utils.js +16 -0
- package/dist/cmd/lib/tools.js +26 -2
- package/dist/cmd/lib/workflows/cmd.js +27 -6
- package/dist/cmd/sys/read_yml_file.d.ts +5 -0
- package/dist/cmd/sys/{read_yml_action.js → read_yml_file.js} +2 -2
- package/dist/db/write.js +21 -11
- package/dist/main.d.ts +2 -1
- package/dist/main.js +2 -1
- package/dist/primitives/args.d.ts +1 -1
- package/dist/primitives/args.js +7 -5
- package/package.json +5 -5
- package/dist/cmd/sys/read_yml_action.d.ts +0 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAgentTask } from "@agent-smith/jobs";
|
|
2
2
|
import { getFeatureSpec } from '../../../state/features.js';
|
|
3
|
-
import {
|
|
3
|
+
import { readYmlFile } from "../../sys/read_yml_file.js";
|
|
4
4
|
import { execute } from "../../sys/execute.js";
|
|
5
5
|
import { runPyScript } from "../../sys/run_python.js";
|
|
6
6
|
import { pyShell } from "../../../state/state.js";
|
|
@@ -10,7 +10,7 @@ function systemAction(path) {
|
|
|
10
10
|
id: "system_action",
|
|
11
11
|
title: "",
|
|
12
12
|
run: async (args) => {
|
|
13
|
-
const actionSpec =
|
|
13
|
+
const actionSpec = readYmlFile(path);
|
|
14
14
|
if (!actionSpec.data?.args) {
|
|
15
15
|
actionSpec.data.args = [];
|
|
16
16
|
}
|
|
@@ -29,13 +29,17 @@ function pythonAction(path) {
|
|
|
29
29
|
if (error) {
|
|
30
30
|
throw new Error(`python error: ${error}`);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
let txt = data[0];
|
|
33
|
+
if (data.length > 1) {
|
|
34
|
+
txt = data.join("\n");
|
|
35
|
+
}
|
|
33
36
|
let final = txt;
|
|
34
37
|
if (txt.startsWith("{") || txt.startsWith("[")) {
|
|
35
38
|
try {
|
|
36
39
|
final = JSON.parse(txt);
|
|
37
40
|
}
|
|
38
|
-
catch (e) {
|
|
41
|
+
catch (e) {
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
44
|
return final;
|
|
41
45
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
|
|
2
|
-
import YAML from 'yaml';
|
|
3
2
|
import { brain, initAgent, taskBuilder } from "../../../agent.js";
|
|
4
3
|
import { readTool } from "../../../db/read.js";
|
|
5
|
-
import {
|
|
4
|
+
import { parseArgs } from "../../../primitives/args.js";
|
|
6
5
|
import { isChatMode, isDebug, isShowTokens, isVerbose } from "../../../state/state.js";
|
|
7
|
-
import { readTask } from "../../sys/read_task.js";
|
|
8
6
|
import { executeActionCmd, } from "../actions/cmd.js";
|
|
9
7
|
import { formatStats, parseInputOptions } from "../utils.js";
|
|
10
8
|
import { executeWorkflowCmd } from "../workflows/cmd.js";
|
|
11
9
|
import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
12
|
-
import {
|
|
10
|
+
import { openTaskSpec } from "./utils.js";
|
|
13
11
|
async function executeTaskCmd(args = [], options = {}) {
|
|
14
12
|
await initAgent();
|
|
15
13
|
if (isDebug.value) {
|
|
@@ -45,15 +43,7 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
45
43
|
name = args.name;
|
|
46
44
|
pr = args.prompt;
|
|
47
45
|
}
|
|
48
|
-
const
|
|
49
|
-
if (!found) {
|
|
50
|
-
throw new Error(`Task ${name} not found`);
|
|
51
|
-
}
|
|
52
|
-
const res = readTask(path);
|
|
53
|
-
if (!res.found) {
|
|
54
|
-
throw new Error(`Task ${name}, ${path} not found`);
|
|
55
|
-
}
|
|
56
|
-
const taskFileSpec = YAML.parse(res.ymlTask);
|
|
46
|
+
const taskFileSpec = openTaskSpec(name);
|
|
57
47
|
const { conf, vars } = parseArgs(args);
|
|
58
48
|
conf.inferParams = mergeInferParams(conf.inferParams, taskFileSpec.inferParams ?? {});
|
|
59
49
|
const model = configureTaskModel(conf, taskFileSpec);
|
|
@@ -68,15 +58,19 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
68
58
|
const lmTool = {
|
|
69
59
|
...tool,
|
|
70
60
|
execute: async (args) => {
|
|
61
|
+
const normalizedArgs = Array.isArray(args) ? [toolName, ...args] : {
|
|
62
|
+
name: toolName,
|
|
63
|
+
...args,
|
|
64
|
+
};
|
|
71
65
|
switch (type) {
|
|
72
66
|
case "action":
|
|
73
|
-
const res = await executeActionCmd(
|
|
67
|
+
const res = await executeActionCmd(normalizedArgs, options, true);
|
|
74
68
|
return res;
|
|
75
69
|
case "task":
|
|
76
|
-
const tres = await executeTaskCmd(
|
|
77
|
-
return tres;
|
|
70
|
+
const tres = await executeTaskCmd(normalizedArgs, options);
|
|
71
|
+
return tres.answer.text;
|
|
78
72
|
case "workflow":
|
|
79
|
-
const wres = await executeWorkflowCmd(toolName,
|
|
73
|
+
const wres = await executeWorkflowCmd(toolName, normalizedArgs, options);
|
|
80
74
|
return wres;
|
|
81
75
|
default:
|
|
82
76
|
throw new Error(`unknown tool execution function type: ${type} for ${toolName}`);
|
|
@@ -134,7 +128,7 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
134
128
|
console.log();
|
|
135
129
|
}
|
|
136
130
|
catch (err) {
|
|
137
|
-
throw new Error(`
|
|
131
|
+
throw new Error(`executing task: ${name} (${err})`);
|
|
138
132
|
}
|
|
139
133
|
if (isChatMode.value) {
|
|
140
134
|
if (brain.ex.name != ex.name) {
|
|
@@ -18,8 +18,8 @@ function configureTaskModel(itConf, taskSpec) {
|
|
|
18
18
|
found = true;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
if (!taskSpec?.modelpack) {
|
|
22
|
-
throw new Error(
|
|
21
|
+
if (!taskSpec?.modelpack?.default) {
|
|
22
|
+
throw new Error(`provide a default model or a use a modelpack in the ${taskSpec.name} task yaml file`);
|
|
23
23
|
}
|
|
24
24
|
modelName = taskSpec.modelpack.default;
|
|
25
25
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
import { readTask } from "../../../cmd/sys/read_task.js";
|
|
3
|
+
import { getFeatureSpec } from "../../../state/features.js";
|
|
4
|
+
function openTaskSpec(name) {
|
|
5
|
+
const { found, path } = getFeatureSpec(name, "task");
|
|
6
|
+
if (!found) {
|
|
7
|
+
throw new Error(`Task ${name} not found`);
|
|
8
|
+
}
|
|
9
|
+
const res = readTask(path);
|
|
10
|
+
if (!res.found) {
|
|
11
|
+
throw new Error(`Task ${name}, ${path} not found`);
|
|
12
|
+
}
|
|
13
|
+
const taskFileSpec = YAML.parse(res.ymlTask);
|
|
14
|
+
return taskFileSpec;
|
|
15
|
+
}
|
|
16
|
+
export { openTaskSpec, };
|
package/dist/cmd/lib/tools.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import YAML from 'yaml';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
+
import { readYmlFile } from '../sys/read_yml_file.js';
|
|
3
4
|
function _extractToolDoc(filePath, startComment, endComment) {
|
|
4
5
|
try {
|
|
5
6
|
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
@@ -36,6 +37,17 @@ function _extractPyToolDoc(filePath) {
|
|
|
36
37
|
function _extractJsToolDoc(filePath) {
|
|
37
38
|
return _extractToolDoc(filePath, '/*', '*/');
|
|
38
39
|
}
|
|
40
|
+
function _extractYamlToolDoc(filePath, name) {
|
|
41
|
+
const { data, found } = readYmlFile(filePath);
|
|
42
|
+
if (!found) {
|
|
43
|
+
return { found: false, tspec: {} };
|
|
44
|
+
}
|
|
45
|
+
if (!data.tool) {
|
|
46
|
+
return { found: false, tspec: {} };
|
|
47
|
+
}
|
|
48
|
+
data.tool.name = name;
|
|
49
|
+
return { found: true, tspec: data.tool };
|
|
50
|
+
}
|
|
39
51
|
function _parseToolDoc(rawTxt, name) {
|
|
40
52
|
try {
|
|
41
53
|
const res = YAML.parse(rawTxt);
|
|
@@ -49,7 +61,8 @@ function _parseToolDoc(rawTxt, name) {
|
|
|
49
61
|
function extractToolDoc(name, ext, dirPath) {
|
|
50
62
|
let spec;
|
|
51
63
|
let found = false;
|
|
52
|
-
let doc;
|
|
64
|
+
let doc = "";
|
|
65
|
+
let docts = null;
|
|
53
66
|
switch (ext) {
|
|
54
67
|
case "py":
|
|
55
68
|
let res = _extractPyToolDoc(dirPath + "/" + name + "." + ext);
|
|
@@ -61,11 +74,22 @@ function extractToolDoc(name, ext, dirPath) {
|
|
|
61
74
|
found = res2.found;
|
|
62
75
|
doc = res2.doc;
|
|
63
76
|
break;
|
|
77
|
+
case "yml":
|
|
78
|
+
let res3 = _extractYamlToolDoc(dirPath + "/" + name + "." + ext, name);
|
|
79
|
+
found = res3.found;
|
|
80
|
+
docts = res3.tspec;
|
|
81
|
+
break;
|
|
64
82
|
default:
|
|
65
83
|
return { found: false, toolDoc: "" };
|
|
66
84
|
}
|
|
67
85
|
if (found) {
|
|
68
|
-
|
|
86
|
+
let ts;
|
|
87
|
+
if (docts) {
|
|
88
|
+
ts = docts;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
ts = _parseToolDoc(doc, name);
|
|
92
|
+
}
|
|
69
93
|
spec = JSON.stringify(ts, null, " ");
|
|
70
94
|
}
|
|
71
95
|
else {
|
|
@@ -20,11 +20,22 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
|
20
20
|
if (isDebug.value || isVerbose.value) {
|
|
21
21
|
console.log(`${i + 1}: ${step.type} ${name}`);
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
let pval = new Array();
|
|
24
|
+
if (i == 0) {
|
|
25
|
+
pval = [name, ...args];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (Array.isArray(params)) {
|
|
29
|
+
pval = [name, ...params];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
pval = { name: name, ...params };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
switch (step.type) {
|
|
25
36
|
case "task":
|
|
26
37
|
try {
|
|
27
|
-
const tr = await executeTaskCmd(
|
|
38
|
+
const tr = await executeTaskCmd(pval, options);
|
|
28
39
|
taskRes = tr;
|
|
29
40
|
}
|
|
30
41
|
catch (e) {
|
|
@@ -33,8 +44,13 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
|
33
44
|
break;
|
|
34
45
|
case "action":
|
|
35
46
|
try {
|
|
36
|
-
const ares = await executeActionCmd(
|
|
37
|
-
|
|
47
|
+
const ares = await executeActionCmd(pval, options, true);
|
|
48
|
+
if (typeof ares == "string") {
|
|
49
|
+
taskRes = [ares];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
taskRes = ares;
|
|
53
|
+
}
|
|
38
54
|
if (i == finalTaskIndex) {
|
|
39
55
|
console.log(taskRes);
|
|
40
56
|
}
|
|
@@ -45,8 +61,13 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
|
45
61
|
break;
|
|
46
62
|
case "adaptater":
|
|
47
63
|
try {
|
|
48
|
-
const ares = await executeAdaptaterCmd(
|
|
49
|
-
|
|
64
|
+
const ares = await executeAdaptaterCmd(pval, options);
|
|
65
|
+
if (typeof ares == "string") {
|
|
66
|
+
taskRes = [ares];
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
taskRes = ares;
|
|
70
|
+
}
|
|
50
71
|
}
|
|
51
72
|
catch (e) {
|
|
52
73
|
throw new Error(`workflow adaptater ${i + 1}: ${e}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as fs } from "fs";
|
|
2
2
|
import YAML from 'yaml';
|
|
3
|
-
function
|
|
3
|
+
function readYmlFile(path) {
|
|
4
4
|
if (!fs.existsSync(path)) {
|
|
5
5
|
return { data: {}, found: false };
|
|
6
6
|
}
|
|
@@ -8,4 +8,4 @@ function readYmlAction(path) {
|
|
|
8
8
|
const data = YAML.parse(file);
|
|
9
9
|
return { data: data, found: true };
|
|
10
10
|
}
|
|
11
|
-
export {
|
|
11
|
+
export { readYmlFile };
|
package/dist/db/write.js
CHANGED
|
@@ -134,19 +134,29 @@ function upsertModels(models) {
|
|
|
134
134
|
})();
|
|
135
135
|
}
|
|
136
136
|
function updateFeatures(feats) {
|
|
137
|
-
upsertAndCleanFeatures(feats.task, "task");
|
|
137
|
+
const newTasks = upsertAndCleanFeatures(feats.task, "task");
|
|
138
|
+
newTasks.forEach((feat) => {
|
|
139
|
+
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
140
|
+
if (found) {
|
|
141
|
+
upsertTool(feat.name, "task", toolDoc);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
138
144
|
const newActions = upsertAndCleanFeatures(feats.action, "action");
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
newActions.forEach((feat) => {
|
|
146
|
+
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
147
|
+
if (found) {
|
|
148
|
+
upsertTool(feat.name, "action", toolDoc);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const newWorkflows = upsertAndCleanFeatures(feats.workflow, "workflow");
|
|
152
|
+
newWorkflows.forEach((feat) => {
|
|
153
|
+
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
154
|
+
if (found) {
|
|
155
|
+
upsertTool(feat.name, "workflow", toolDoc);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
149
158
|
upsertAndCleanFeatures(feats.adaptater, "adaptater");
|
|
159
|
+
upsertAndCleanFeatures(feats.cmd, "cmd");
|
|
150
160
|
upsertAndCleanFeatures(feats.modelfile, "modelfile");
|
|
151
161
|
}
|
|
152
162
|
export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, upsertModels, };
|
package/dist/main.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ import { usePerfTimer } from "./primitives/perf.js";
|
|
|
10
10
|
import { parseArgs } from "./primitives/args.js";
|
|
11
11
|
import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
|
|
12
12
|
import { extractToolDoc } from "./cmd/lib/tools.js";
|
|
13
|
-
|
|
13
|
+
import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
|
|
14
|
+
export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, LmTaskConf, openTaskSpec, };
|
package/dist/main.js
CHANGED
|
@@ -9,4 +9,5 @@ import { initState, pluginDataDir } from "./state/state.js";
|
|
|
9
9
|
import { usePerfTimer } from "./primitives/perf.js";
|
|
10
10
|
import { parseArgs } from "./primitives/args.js";
|
|
11
11
|
import { extractToolDoc } from "./cmd/lib/tools.js";
|
|
12
|
-
|
|
12
|
+
import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
|
|
13
|
+
export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, initState, pluginDataDir, usePerfTimer, parseArgs, extractToolDoc, openTaskSpec, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LmTaskConfig } from "../interfaces.js";
|
|
2
|
-
declare function parseArgs(params: Record<string, any> | Array<any
|
|
2
|
+
declare function parseArgs(params: Record<string, any> | Array<any>, checkPrompt?: boolean): {
|
|
3
3
|
conf: LmTaskConfig;
|
|
4
4
|
vars: Record<string, any>;
|
|
5
5
|
args: Array<string>;
|
package/dist/primitives/args.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
function parseArgs(params) {
|
|
1
|
+
function parseArgs(params, checkPrompt = false) {
|
|
2
2
|
switch (Array.isArray(params)) {
|
|
3
3
|
case true:
|
|
4
4
|
return parseArrayArgs(params);
|
|
5
5
|
default:
|
|
6
|
-
return { ...parseObjectArgs(params), args: [] };
|
|
6
|
+
return { ...parseObjectArgs(params, checkPrompt), args: [] };
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function parseObjectArgs(params) {
|
|
9
|
+
function parseObjectArgs(params, checkPrompt) {
|
|
10
10
|
const conf = { inferParams: {}, modelname: "", templateName: "" };
|
|
11
|
-
if (
|
|
12
|
-
|
|
11
|
+
if (checkPrompt) {
|
|
12
|
+
if (!params?.prompt) {
|
|
13
|
+
throw new Error(`args parsing error: provide a prompt`);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
if (params?.images) {
|
|
15
17
|
conf.inferParams.images = params.images;
|
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.59",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@agent-smith/brain": "^0.0.42",
|
|
14
14
|
"@agent-smith/jobs": "^0.0.14",
|
|
15
|
-
"@agent-smith/lmtask": "^0.0.
|
|
15
|
+
"@agent-smith/lmtask": "^0.0.39",
|
|
16
16
|
"@agent-smith/tfm": "^0.1.2",
|
|
17
17
|
"@inquirer/prompts": "^7.5.0",
|
|
18
18
|
"@inquirer/select": "^4.2.0",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"clipboardy": "^4.0.0",
|
|
24
24
|
"commander": "^13.1.0",
|
|
25
25
|
"marked-terminal": "^7.3.0",
|
|
26
|
-
"modprompt": "^0.11.
|
|
26
|
+
"modprompt": "^0.11.2",
|
|
27
27
|
"python-shell": "^5.0.0",
|
|
28
28
|
"yaml": "^2.7.1"
|
|
29
29
|
},
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
36
36
|
"@types/better-sqlite3": "^7.6.13",
|
|
37
37
|
"@types/marked-terminal": "^6.1.1",
|
|
38
|
-
"@types/node": "^22.15.
|
|
38
|
+
"@types/node": "^22.15.12",
|
|
39
39
|
"restmix": "^0.5.0",
|
|
40
|
-
"rollup": "^4.40.
|
|
40
|
+
"rollup": "^4.40.2",
|
|
41
41
|
"ts-node": "^10.9.2",
|
|
42
42
|
"tslib": "2.8.1",
|
|
43
43
|
"typescript": "^5.8.3"
|