@agent-smith/cli 0.0.56 → 0.0.58
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 +9 -6
- package/dist/cmd/lib/tasks/cmd.js +20 -35
- package/dist/cmd/lib/tasks/conf.d.ts +3 -5
- package/dist/cmd/lib/tasks/conf.js +8 -84
- 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/utils.d.ts +2 -2
- package/dist/cmd/lib/utils.js +2 -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 -2
- package/dist/main.js +2 -2
- package/dist/primitives/args.d.ts +3 -1
- package/dist/primitives/args.js +51 -8
- package/dist/state/state.d.ts +1 -2
- package/dist/state/state.js +1 -1
- package/package.json +1 -1
- package/dist/cmd/sys/read_yml_action.d.ts +0 -5
|
@@ -1,16 +1,16 @@
|
|
|
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
|
-
import {
|
|
6
|
+
import { pyShell } from "../../../state/state.js";
|
|
7
7
|
import { createJsAction } from "./read.js";
|
|
8
8
|
function systemAction(path) {
|
|
9
9
|
const action = useAgentTask({
|
|
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
|
}
|
|
@@ -43,7 +47,6 @@ function pythonAction(path) {
|
|
|
43
47
|
return action;
|
|
44
48
|
}
|
|
45
49
|
async function executeActionCmd(args = [], options = {}, quiet = false) {
|
|
46
|
-
while (!isStateReady.value) { }
|
|
47
50
|
const isWorkflow = !Array.isArray(args);
|
|
48
51
|
let name;
|
|
49
52
|
if (!isWorkflow) {
|
|
@@ -1,14 +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
|
-
import { configureTaskModel,
|
|
9
|
+
import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
10
|
+
import { openTaskSpec } from "./utils.js";
|
|
12
11
|
async function executeTaskCmd(args = [], options = {}) {
|
|
13
12
|
await initAgent();
|
|
14
13
|
if (isDebug.value) {
|
|
@@ -42,31 +41,12 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
42
41
|
throw new Error("Provide a task prompt param");
|
|
43
42
|
}
|
|
44
43
|
name = args.name;
|
|
45
|
-
delete args.name;
|
|
46
44
|
pr = args.prompt;
|
|
47
|
-
delete args.prompt;
|
|
48
|
-
}
|
|
49
|
-
const { found, path } = getFeatureSpec(name, "task");
|
|
50
|
-
if (!found) {
|
|
51
|
-
throw new Error(`Task ${name} not found`);
|
|
52
|
-
}
|
|
53
|
-
const res = readTask(path);
|
|
54
|
-
if (!res.found) {
|
|
55
|
-
throw new Error(`Task ${name}, ${path} not found`);
|
|
56
|
-
}
|
|
57
|
-
const taskFileSpec = YAML.parse(res.ymlTask);
|
|
58
|
-
let model;
|
|
59
|
-
let vars = {};
|
|
60
|
-
if (!isWorkflow) {
|
|
61
|
-
const tv = parseTaskVars(args, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
|
|
62
|
-
vars = tv.vars;
|
|
63
|
-
model = configureTaskModel(tv.conf, taskFileSpec);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const tv = parseTaskVars({ name: name, prompt: pr, ...args }, taskFileSpec?.inferParams ? taskFileSpec.inferParams : {});
|
|
67
|
-
vars = tv.vars;
|
|
68
|
-
model = configureTaskModel(tv.conf, taskFileSpec);
|
|
69
45
|
}
|
|
46
|
+
const taskFileSpec = openTaskSpec(name);
|
|
47
|
+
const { conf, vars } = parseArgs(args);
|
|
48
|
+
conf.inferParams = mergeInferParams(conf.inferParams, taskFileSpec.inferParams ?? {});
|
|
49
|
+
const model = configureTaskModel(conf, taskFileSpec);
|
|
70
50
|
const taskSpec = taskFileSpec;
|
|
71
51
|
if (taskSpec.toolsList) {
|
|
72
52
|
taskSpec.tools = [];
|
|
@@ -78,15 +58,19 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
78
58
|
const lmTool = {
|
|
79
59
|
...tool,
|
|
80
60
|
execute: async (args) => {
|
|
61
|
+
const normalizedArgs = Array.isArray(args) ? [toolName, ...args] : {
|
|
62
|
+
name: toolName,
|
|
63
|
+
...args,
|
|
64
|
+
};
|
|
81
65
|
switch (type) {
|
|
82
66
|
case "action":
|
|
83
|
-
const res = await executeActionCmd(
|
|
67
|
+
const res = await executeActionCmd(normalizedArgs, options, true);
|
|
84
68
|
return res;
|
|
85
69
|
case "task":
|
|
86
|
-
const tres = await executeTaskCmd(
|
|
87
|
-
return tres;
|
|
70
|
+
const tres = await executeTaskCmd(normalizedArgs, options);
|
|
71
|
+
return tres.answer.text;
|
|
88
72
|
case "workflow":
|
|
89
|
-
const wres = await executeWorkflowCmd(toolName,
|
|
73
|
+
const wres = await executeWorkflowCmd(toolName, normalizedArgs, options);
|
|
90
74
|
return wres;
|
|
91
75
|
default:
|
|
92
76
|
throw new Error(`unknown tool execution function type: ${type} for ${toolName}`);
|
|
@@ -128,18 +112,19 @@ async function executeTaskCmd(args = [], options = {}) {
|
|
|
128
112
|
c = !c;
|
|
129
113
|
});
|
|
130
114
|
}
|
|
131
|
-
const
|
|
115
|
+
const tconf = {
|
|
132
116
|
expert: ex,
|
|
133
117
|
model: model,
|
|
134
118
|
debug: isDebug.value,
|
|
119
|
+
...conf,
|
|
135
120
|
};
|
|
136
|
-
|
|
121
|
+
tconf.expert = ex;
|
|
137
122
|
if (isDebug.value || isVerbose.value) {
|
|
138
|
-
|
|
123
|
+
tconf.debug = true;
|
|
139
124
|
}
|
|
140
125
|
let out;
|
|
141
126
|
try {
|
|
142
|
-
out = await task.run({ prompt: pr, ...vars },
|
|
127
|
+
out = await task.run({ prompt: pr, ...vars }, tconf);
|
|
143
128
|
console.log();
|
|
144
129
|
}
|
|
145
130
|
catch (err) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { InferenceParams } from "@locallm/types";
|
|
1
2
|
import { LmTaskConfig, LmTaskFileSpec, ModelSpec } from "../../../interfaces.js";
|
|
2
3
|
declare function configureTaskModel(itConf: LmTaskConfig, taskSpec: LmTaskFileSpec): ModelSpec;
|
|
3
|
-
declare function
|
|
4
|
-
|
|
5
|
-
vars: Record<string, any>;
|
|
6
|
-
};
|
|
7
|
-
export { parseTaskVars, configureTaskModel, };
|
|
4
|
+
declare function mergeInferParams(userInferParams: Record<string, any>, taskInferParams: InferenceParams): InferenceParams;
|
|
5
|
+
export { mergeInferParams, configureTaskModel, };
|
|
@@ -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
|
}
|
|
@@ -83,87 +83,11 @@ function configureTaskModel(itConf, taskSpec) {
|
|
|
83
83
|
}
|
|
84
84
|
return model;
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
default:
|
|
91
|
-
return _initTaskParams(params, inferParams);
|
|
86
|
+
function mergeInferParams(userInferParams, taskInferParams) {
|
|
87
|
+
const ip = taskInferParams;
|
|
88
|
+
for (const [k, v] of Object.entries(userInferParams)) {
|
|
89
|
+
ip[k] = v;
|
|
92
90
|
}
|
|
91
|
+
return ip;
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
const conf = { inferParams: inferParams, modelname: "", templateName: "" };
|
|
96
|
-
if (!params?.prompt) {
|
|
97
|
-
throw new Error(`Error initializing task params: provide a prompt`);
|
|
98
|
-
}
|
|
99
|
-
if (params?.images) {
|
|
100
|
-
conf.inferParams.images = params.images;
|
|
101
|
-
delete params.images;
|
|
102
|
-
}
|
|
103
|
-
if (params?.modelname) {
|
|
104
|
-
conf.modelname = params.modelname;
|
|
105
|
-
delete params.modelname;
|
|
106
|
-
}
|
|
107
|
-
if (params?.template) {
|
|
108
|
-
conf.templateName = params.templateName;
|
|
109
|
-
delete params.templateName;
|
|
110
|
-
}
|
|
111
|
-
if (params?.m) {
|
|
112
|
-
if (params.m.includes("/")) {
|
|
113
|
-
const _s = params.m.split("/");
|
|
114
|
-
conf.modelname = _s[0];
|
|
115
|
-
conf.templateName = _s[1];
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
conf.modelname = params.m;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const ip = conf.inferParams;
|
|
122
|
-
if (params?.inferParams) {
|
|
123
|
-
for (const [k, v] of Object.entries(params.inferParams)) {
|
|
124
|
-
ip[k] = v;
|
|
125
|
-
}
|
|
126
|
-
conf.inferParams = ip;
|
|
127
|
-
delete params.inferParams;
|
|
128
|
-
}
|
|
129
|
-
const res = { conf: conf, vars: params };
|
|
130
|
-
return res;
|
|
131
|
-
}
|
|
132
|
-
function _initTaskVars(args, inferParams) {
|
|
133
|
-
const conf = { inferParams: inferParams, modelname: "", templateName: "" };
|
|
134
|
-
const vars = {};
|
|
135
|
-
args.forEach((a) => {
|
|
136
|
-
if (a.includes("=")) {
|
|
137
|
-
const delimiter = "=";
|
|
138
|
-
const [k, v] = a.split(delimiter, 2);
|
|
139
|
-
if (v === undefined) {
|
|
140
|
-
throw new Error(`invalid parameter ${a}`);
|
|
141
|
-
}
|
|
142
|
-
switch (k) {
|
|
143
|
-
case "m":
|
|
144
|
-
if (v.includes("/")) {
|
|
145
|
-
const _s = v.split("/");
|
|
146
|
-
conf.modelname = _s[0];
|
|
147
|
-
conf.templateName = _s[1];
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
conf.modelname = v;
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
case "ip":
|
|
154
|
-
v.split(",").forEach((p) => {
|
|
155
|
-
const s = p.split(":");
|
|
156
|
-
const cip = conf.inferParams;
|
|
157
|
-
cip[s[0]] = parseFloat(s[1]);
|
|
158
|
-
conf.inferParams = cip;
|
|
159
|
-
});
|
|
160
|
-
break;
|
|
161
|
-
default:
|
|
162
|
-
vars[k] = v;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return { conf, vars };
|
|
168
|
-
}
|
|
169
|
-
export { parseTaskVars, configureTaskModel, };
|
|
93
|
+
export { mergeInferParams, configureTaskModel, };
|
|
@@ -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 {
|
package/dist/cmd/lib/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InferenceStats } from "@locallm/types
|
|
1
|
+
import { InferenceStats } from "@locallm/types";
|
|
2
2
|
declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
|
|
3
3
|
declare function readPromptFile(): string;
|
|
4
4
|
declare function processOutput(res: any): Promise<void>;
|
|
5
5
|
declare function parseInputOptions(options: any): Promise<string | null>;
|
|
6
6
|
declare function formatStats(stats: InferenceStats): string;
|
|
7
|
-
export { parseInputOptions, processOutput, readPromptFile, setOptions
|
|
7
|
+
export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
|
package/dist/cmd/lib/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { marked } from "../../agent.js";
|
|
1
2
|
import { formatMode, initFilepaths, inputMode, outputMode, promptfilePath } from "../../state/state.js";
|
|
2
3
|
import { modes } from "../clicmds/modes.js";
|
|
3
4
|
import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
|
|
4
5
|
import { readFile } from "../sys/read.js";
|
|
5
|
-
import { marked } from "../../agent.js";
|
|
6
6
|
async function setOptions(args = [], options) {
|
|
7
7
|
for (const k of Object.keys(options)) {
|
|
8
8
|
let opt;
|
|
@@ -71,4 +71,4 @@ function formatStats(stats) {
|
|
|
71
71
|
buf.push(`${stats.inferenceTimeSeconds}s inference)`);
|
|
72
72
|
return buf.join(" ");
|
|
73
73
|
}
|
|
74
|
-
export { parseInputOptions, processOutput, readPromptFile, setOptions
|
|
74
|
+
export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
|
|
@@ -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
|
@@ -8,7 +8,7 @@ import { initAgent } from "./agent.js";
|
|
|
8
8
|
import { initState, pluginDataDir } from "./state/state.js";
|
|
9
9
|
import { usePerfTimer } from "./primitives/perf.js";
|
|
10
10
|
import { parseArgs } from "./primitives/args.js";
|
|
11
|
-
import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
|
|
12
11
|
import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
|
|
13
12
|
import { extractToolDoc } from "./cmd/lib/tools.js";
|
|
14
|
-
|
|
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
|
@@ -8,6 +8,6 @@ import { initAgent } from "./agent.js";
|
|
|
8
8
|
import { initState, pluginDataDir } from "./state/state.js";
|
|
9
9
|
import { usePerfTimer } from "./primitives/perf.js";
|
|
10
10
|
import { parseArgs } from "./primitives/args.js";
|
|
11
|
-
import { parseTaskVars } from "./cmd/lib/tasks/conf.js";
|
|
12
11
|
import { extractToolDoc } from "./cmd/lib/tools.js";
|
|
13
|
-
|
|
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, };
|
package/dist/primitives/args.js
CHANGED
|
@@ -1,36 +1,79 @@
|
|
|
1
|
-
function parseArgs(
|
|
2
|
-
|
|
1
|
+
function parseArgs(params) {
|
|
2
|
+
switch (Array.isArray(params)) {
|
|
3
|
+
case true:
|
|
4
|
+
return parseArrayArgs(params);
|
|
5
|
+
default:
|
|
6
|
+
return { ...parseObjectArgs(params), args: [] };
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function parseObjectArgs(params) {
|
|
10
|
+
const conf = { inferParams: {}, modelname: "", templateName: "" };
|
|
11
|
+
if (!params?.prompt) {
|
|
12
|
+
throw new Error(`Error initializing task params: provide a prompt`);
|
|
13
|
+
}
|
|
14
|
+
if (params?.images) {
|
|
15
|
+
conf.inferParams.images = params.images;
|
|
16
|
+
delete params.images;
|
|
17
|
+
}
|
|
18
|
+
if (params?.modelname) {
|
|
19
|
+
conf.modelname = params.modelname;
|
|
20
|
+
delete params.modelname;
|
|
21
|
+
}
|
|
22
|
+
if (params?.template) {
|
|
23
|
+
conf.templateName = params.templateName;
|
|
24
|
+
delete params.templateName;
|
|
25
|
+
}
|
|
26
|
+
if (params?.m) {
|
|
27
|
+
if (params.m.includes("/")) {
|
|
28
|
+
const _s = params.m.split("/");
|
|
29
|
+
conf.modelname = _s[0];
|
|
30
|
+
conf.templateName = _s[1];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
conf.modelname = params.m;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (params?.ip) {
|
|
37
|
+
conf.inferParams = params.ip;
|
|
38
|
+
}
|
|
39
|
+
const res = { conf: conf, vars: params };
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
function parseArrayArgs(args) {
|
|
43
|
+
const _vars = {};
|
|
44
|
+
const _conf = { inferParams: {} };
|
|
3
45
|
const _nargs = new Array();
|
|
4
46
|
args.forEach((a) => {
|
|
5
47
|
if (a.includes("=")) {
|
|
6
|
-
const t = a.split("=");
|
|
48
|
+
const t = a.split("=", 2);
|
|
7
49
|
const k = t[0];
|
|
8
50
|
const v = t[1];
|
|
9
51
|
switch (k) {
|
|
10
52
|
case "m":
|
|
11
53
|
if (v.includes("/")) {
|
|
12
54
|
const _s = v.split("/");
|
|
13
|
-
|
|
14
|
-
|
|
55
|
+
_conf.modelname = _s[0];
|
|
56
|
+
_conf.templateName = _s[1];
|
|
15
57
|
}
|
|
16
58
|
else {
|
|
17
|
-
|
|
59
|
+
_conf.modelname = v;
|
|
18
60
|
}
|
|
19
61
|
break;
|
|
20
62
|
case "ip":
|
|
21
63
|
v.split(",").forEach((p) => {
|
|
22
64
|
const s = p.split(":");
|
|
23
|
-
|
|
65
|
+
_conf.inferParams[s[0]] = parseFloat(s[1]);
|
|
24
66
|
});
|
|
25
67
|
break;
|
|
26
68
|
default:
|
|
27
69
|
_vars[k] = v;
|
|
70
|
+
break;
|
|
28
71
|
}
|
|
29
72
|
}
|
|
30
73
|
else {
|
|
31
74
|
_nargs.push(a);
|
|
32
75
|
}
|
|
33
76
|
});
|
|
34
|
-
return { vars: _vars, args: _nargs };
|
|
77
|
+
return { conf: _conf, vars: _vars, args: _nargs };
|
|
35
78
|
}
|
|
36
79
|
export { parseArgs, };
|
package/dist/state/state.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ declare const isVerbose: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
|
11
11
|
declare const isShowTokens: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
12
12
|
declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
|
|
13
13
|
declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
|
|
14
|
-
declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
15
14
|
declare const lastCmd: {
|
|
16
15
|
name: string;
|
|
17
16
|
args: Array<string>;
|
|
@@ -19,4 +18,4 @@ declare const lastCmd: {
|
|
|
19
18
|
declare function initFilepaths(): void;
|
|
20
19
|
declare function initState(): Promise<void>;
|
|
21
20
|
declare function pluginDataDir(pluginName: string): string;
|
|
22
|
-
export { inputMode, outputMode, isChatMode, isShowTokens,
|
|
21
|
+
export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
|
package/dist/state/state.js
CHANGED
|
@@ -51,4 +51,4 @@ function pluginDataDir(pluginName) {
|
|
|
51
51
|
createDirectoryIfNotExists(pluginDatapath);
|
|
52
52
|
return pluginDatapath;
|
|
53
53
|
}
|
|
54
|
-
export { inputMode, outputMode, isChatMode, isShowTokens,
|
|
54
|
+
export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
|
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.58",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|