@agent-smith/cli 0.0.39 → 0.0.40
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/clicmds/cmds.js +19 -41
- package/dist/cmd/clicmds/modes.js +14 -5
- package/dist/cmd/cmds.d.ts +1 -1
- package/dist/cmd/cmds.js +2 -2
- package/dist/cmd/lib/{execute_action.d.ts → actions/cmd.d.ts} +4 -4
- package/dist/cmd/lib/{execute_action.js → actions/cmd.js} +14 -23
- package/dist/cmd/lib/actions/read.d.ts +4 -0
- package/dist/cmd/lib/actions/read.js +18 -0
- package/dist/cmd/lib/adaptaters/cmd.d.ts +2 -0
- package/dist/cmd/lib/adaptaters/cmd.js +37 -0
- package/dist/cmd/lib/tasks/cmd.d.ts +3 -0
- package/dist/cmd/lib/tasks/cmd.js +144 -0
- package/dist/cmd/lib/tools.d.ts +6 -0
- package/dist/cmd/lib/tools.js +76 -0
- package/dist/cmd/lib/utils.d.ts +2 -10
- package/dist/cmd/lib/utils.js +18 -60
- package/dist/cmd/lib/workflows/cmd.d.ts +1 -2
- package/dist/cmd/lib/workflows/cmd.js +20 -9
- package/dist/cmd/lib/workflows/read.d.ts +2 -2
- package/dist/cmd/lib/workflows/read.js +15 -4
- package/dist/cmd/sys/read.d.ts +2 -0
- package/dist/cmd/sys/read.js +10 -0
- package/dist/cmd/sys/read_features.js +10 -10
- package/dist/cmd/sys/read_task.d.ts +6 -0
- package/dist/cmd/sys/read_task.js +23 -0
- package/dist/cmd/sys/reset.d.ts +2 -0
- package/dist/cmd/sys/reset.js +10 -0
- package/dist/cmd/sys/run_python.js +5 -2
- package/dist/db/db.d.ts +2 -1
- package/dist/db/db.js +1 -1
- package/dist/db/read.d.ts +9 -3
- package/dist/db/read.js +19 -4
- package/dist/db/schemas.js +34 -12
- package/dist/db/write.js +32 -6
- package/dist/index.js +0 -0
- package/dist/interfaces.d.ts +21 -13
- package/dist/main.d.ts +3 -4
- package/dist/main.js +3 -4
- package/dist/state/chat.d.ts +1 -1
- package/dist/state/features.js +2 -2
- package/dist/state/state.d.ts +3 -2
- package/dist/state/state.js +5 -4
- package/package.json +13 -12
- package/dist/cmd/lib/execute_job.d.ts +0 -6
- package/dist/cmd/lib/execute_job.js +0 -273
- package/dist/cmd/lib/execute_task.d.ts +0 -4
- package/dist/cmd/lib/execute_task.js +0 -106
package/dist/cmd/lib/utils.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { useAgentTask } from "@agent-smith/jobs";
|
|
2
1
|
import { useTemplateForModel } from "@agent-smith/tfm";
|
|
3
|
-
import {
|
|
4
|
-
import { default as path } from "path";
|
|
5
|
-
import { inputMode, outputMode, promptfile } from "../../state/state.js";
|
|
2
|
+
import { inputMode, outputMode, promptfilePath } from "../../state/state.js";
|
|
6
3
|
import { modes } from "../clicmds/modes.js";
|
|
7
4
|
import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
|
|
5
|
+
import { readFile } from "../sys/read.js";
|
|
8
6
|
const tfm = useTemplateForModel();
|
|
9
7
|
async function setOptions(args = [], options) {
|
|
10
8
|
for (const k of Object.keys(options)) {
|
|
@@ -28,12 +26,7 @@ async function setOptions(args = [], options) {
|
|
|
28
26
|
return args;
|
|
29
27
|
}
|
|
30
28
|
function readPromptFile() {
|
|
31
|
-
|
|
32
|
-
return fs.readFileSync(promptfile.value, 'utf8');
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
29
|
+
return readFile(promptfilePath.value);
|
|
37
30
|
}
|
|
38
31
|
async function processOutput(res) {
|
|
39
32
|
if (!(outputMode.value == "clipboard")) {
|
|
@@ -41,17 +34,8 @@ async function processOutput(res) {
|
|
|
41
34
|
}
|
|
42
35
|
let data = "";
|
|
43
36
|
if (typeof res == "object") {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
data = res.data;
|
|
47
|
-
hasOutput = true;
|
|
48
|
-
}
|
|
49
|
-
if (res?.text) {
|
|
50
|
-
data = res.text;
|
|
51
|
-
hasOutput = true;
|
|
52
|
-
}
|
|
53
|
-
if (!hasOutput) {
|
|
54
|
-
throw new Error(`No data in res: ${JSON.stringify(res, null, " ")}`);
|
|
37
|
+
if (res?.answer && res?.stats) {
|
|
38
|
+
data = res.answer.text;
|
|
55
39
|
}
|
|
56
40
|
}
|
|
57
41
|
else {
|
|
@@ -64,26 +48,6 @@ async function processOutput(res) {
|
|
|
64
48
|
await writeToClipboard(data);
|
|
65
49
|
}
|
|
66
50
|
}
|
|
67
|
-
function readTask(taskpath) {
|
|
68
|
-
if (!fs.existsSync(taskpath)) {
|
|
69
|
-
return { ymlTask: "", found: false };
|
|
70
|
-
}
|
|
71
|
-
const data = fs.readFileSync(taskpath, 'utf8');
|
|
72
|
-
return { ymlTask: data, found: true };
|
|
73
|
-
}
|
|
74
|
-
function readTasksDir(dir) {
|
|
75
|
-
const tasks = new Array();
|
|
76
|
-
fs.readdirSync(dir).forEach((filename) => {
|
|
77
|
-
const filepath = path.join(dir, filename);
|
|
78
|
-
const isDir = fs.statSync(filepath).isDirectory();
|
|
79
|
-
if (!isDir) {
|
|
80
|
-
if (filename.endsWith(".yml")) {
|
|
81
|
-
tasks.push(filename);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
return tasks;
|
|
86
|
-
}
|
|
87
51
|
function initTaskConf(conf, taskSpec) {
|
|
88
52
|
const _conf = conf;
|
|
89
53
|
let m = taskSpec.model.name;
|
|
@@ -189,7 +153,18 @@ function initTaskVars(args, inferParams) {
|
|
|
189
153
|
const vars = {};
|
|
190
154
|
args.forEach((a) => {
|
|
191
155
|
if (a.includes("=")) {
|
|
192
|
-
const
|
|
156
|
+
const delimiter = "=";
|
|
157
|
+
const firstDelimiterIndex = a.indexOf(delimiter);
|
|
158
|
+
let t = new Array();
|
|
159
|
+
if (firstDelimiterIndex !== -1) {
|
|
160
|
+
t = [
|
|
161
|
+
a.slice(0, firstDelimiterIndex),
|
|
162
|
+
a.slice(firstDelimiterIndex + 1)
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
t = [a];
|
|
167
|
+
}
|
|
193
168
|
const k = t[0];
|
|
194
169
|
const v = t[1];
|
|
195
170
|
switch (k) {
|
|
@@ -230,21 +205,4 @@ async function parseInputOptions(options) {
|
|
|
230
205
|
}
|
|
231
206
|
return out;
|
|
232
207
|
}
|
|
233
|
-
|
|
234
|
-
const task = useAgentTask({
|
|
235
|
-
id: "",
|
|
236
|
-
title: "",
|
|
237
|
-
run: async (args) => {
|
|
238
|
-
try {
|
|
239
|
-
const res = await action(args);
|
|
240
|
-
return { ok: true, data: res };
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
const err = new Error(`Error executing action ${e}`);
|
|
244
|
-
return { ok: false, data: {}, error: err };
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
return task;
|
|
249
|
-
}
|
|
250
|
-
export { createJsAction, initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
|
|
208
|
+
export { initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, setOptions };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
declare function executeWorkflowCmd(name: string, args?: Array<any>, options?: any): Promise<NodeReturnType<any>>;
|
|
1
|
+
declare function executeWorkflowCmd(name: string, args?: Array<any>, options?: any): Promise<any>;
|
|
3
2
|
export { executeWorkflowCmd, };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isDebug, isVerbose } from "../../../state/state.js";
|
|
2
2
|
import { readWorkflow } from "./read.js";
|
|
3
|
-
import { executeTaskCmd } from "../
|
|
4
|
-
import { executeActionCmd } from "../
|
|
3
|
+
import { executeTaskCmd } from "../tasks/cmd.js";
|
|
4
|
+
import { executeActionCmd } from "../actions/cmd.js";
|
|
5
|
+
import { executeAdaptaterCmd } from "../adaptaters/cmd.js";
|
|
5
6
|
async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
6
7
|
const { workflow, found } = await readWorkflow(name);
|
|
7
8
|
if (!found) {
|
|
@@ -14,7 +15,7 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
|
14
15
|
let params = {};
|
|
15
16
|
let i = 0;
|
|
16
17
|
const finalTaskIndex = stepNames.length + 1;
|
|
17
|
-
let taskRes = {
|
|
18
|
+
let taskRes = {};
|
|
18
19
|
for (const [name, step] of Object.entries(workflow)) {
|
|
19
20
|
if (isDebug.value || isVerbose.value) {
|
|
20
21
|
console.log(`${i + 1}: ${step.type} ${name}`);
|
|
@@ -23,26 +24,36 @@ async function executeWorkflowCmd(name, args = [], options = {}) {
|
|
|
23
24
|
switch (step.type) {
|
|
24
25
|
case "task":
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
+
const tr = await executeTaskCmd(p, options);
|
|
28
|
+
taskRes = tr;
|
|
27
29
|
}
|
|
28
30
|
catch (e) {
|
|
29
|
-
throw new Error(`
|
|
31
|
+
throw new Error(`workflow task ${i + 1}: ${e}`);
|
|
30
32
|
}
|
|
31
33
|
break;
|
|
32
34
|
case "action":
|
|
33
35
|
try {
|
|
34
36
|
const ares = await executeActionCmd(p, options, true);
|
|
35
|
-
taskRes = ares
|
|
37
|
+
taskRes = ares;
|
|
36
38
|
if (i == finalTaskIndex) {
|
|
37
|
-
console.log(taskRes
|
|
39
|
+
console.log(taskRes);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
catch (e) {
|
|
41
|
-
throw new Error(`
|
|
43
|
+
throw new Error(`workflow action ${i + 1}: ${e}`);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case "adaptater":
|
|
47
|
+
try {
|
|
48
|
+
const ares = await executeAdaptaterCmd(p, options);
|
|
49
|
+
taskRes = ares;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new Error(`workflow adaptater ${i + 1}: ${e}`);
|
|
42
53
|
}
|
|
43
54
|
break;
|
|
44
55
|
default:
|
|
45
|
-
throw new Error(`
|
|
56
|
+
throw new Error(`unknown task type ${step.type} in workflow ${name}`);
|
|
46
57
|
}
|
|
47
58
|
params = taskRes;
|
|
48
59
|
++i;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentTask } from "@agent-smith/jobs";
|
|
2
|
-
import { FeatureType
|
|
2
|
+
import { FeatureType } from '../../../interfaces.js';
|
|
3
3
|
declare function readWorkflow(name: string): Promise<{
|
|
4
4
|
found: boolean;
|
|
5
|
-
workflow: Record<string, AgentTask<FeatureType, any,
|
|
5
|
+
workflow: Record<string, AgentTask<FeatureType, any, any, Record<string, any>>>;
|
|
6
6
|
}>;
|
|
7
7
|
export { readWorkflow, };
|
|
@@ -2,8 +2,9 @@ import YAML from 'yaml';
|
|
|
2
2
|
import { default as fs } from "fs";
|
|
3
3
|
import { taskBuilder } from '../../../agent.js';
|
|
4
4
|
import { getFeatureSpec } from '../../../state/features.js';
|
|
5
|
-
import {
|
|
6
|
-
import { pythonAction, systemAction } from '
|
|
5
|
+
import { readTask } from "../../sys/read_task.js";
|
|
6
|
+
import { pythonAction, systemAction } from '../actions/cmd.js';
|
|
7
|
+
import { createJsAction } from '../actions/read.js';
|
|
7
8
|
async function _createWorkflowFromSpec(spec) {
|
|
8
9
|
const steps = {};
|
|
9
10
|
for (const step of spec.steps) {
|
|
@@ -48,6 +49,16 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
48
49
|
throw new Error(`Unknown feature extension ${ext}`);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
else if (type == "adaptater") {
|
|
53
|
+
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
54
|
+
if (!found) {
|
|
55
|
+
throw new Error(`Adaptater ${name} not found`);
|
|
56
|
+
}
|
|
57
|
+
const jsa = await import(path);
|
|
58
|
+
const act = createJsAction(jsa.action);
|
|
59
|
+
act.type = "adaptater";
|
|
60
|
+
steps[name] = act;
|
|
61
|
+
}
|
|
51
62
|
else {
|
|
52
63
|
const { found, path } = getFeatureSpec(name, "task");
|
|
53
64
|
if (!found) {
|
|
@@ -93,11 +104,11 @@ async function readWorkflow(name) {
|
|
|
93
104
|
wf = workflow;
|
|
94
105
|
}
|
|
95
106
|
catch (e) {
|
|
96
|
-
throw new Error(`Workflow create error: ${e}`);
|
|
107
|
+
throw new Error(`Workflow ${name} create error: ${e}`);
|
|
97
108
|
}
|
|
98
109
|
break;
|
|
99
110
|
default:
|
|
100
|
-
throw new Error(`Workflow extension ${ext} not implemented`);
|
|
111
|
+
throw new Error(`Workflow ${name} extension ${ext} not implemented`);
|
|
101
112
|
}
|
|
102
113
|
return { found: true, workflow: wf };
|
|
103
114
|
}
|
|
@@ -18,10 +18,10 @@ function _readDir(dir, ext) {
|
|
|
18
18
|
function readFeaturesDir(dir) {
|
|
19
19
|
const feats = {
|
|
20
20
|
task: [],
|
|
21
|
-
job: [],
|
|
22
21
|
action: [],
|
|
23
22
|
cmd: [],
|
|
24
|
-
workflow: []
|
|
23
|
+
workflow: [],
|
|
24
|
+
adaptater: [],
|
|
25
25
|
};
|
|
26
26
|
let dirpath = path.join(dir, "tasks");
|
|
27
27
|
if (fs.existsSync(dirpath)) {
|
|
@@ -37,42 +37,42 @@ function readFeaturesDir(dir) {
|
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
dirpath = path.join(dir, "
|
|
40
|
+
dirpath = path.join(dir, "workflows");
|
|
41
41
|
if (fs.existsSync(dirpath)) {
|
|
42
42
|
const data = _readDir(dirpath, [".yml"]);
|
|
43
43
|
data.forEach((filename) => {
|
|
44
44
|
const parts = filename.split(".");
|
|
45
45
|
const ext = parts.pop();
|
|
46
46
|
const name = parts.join("");
|
|
47
|
-
feats.
|
|
47
|
+
feats.workflow.push({
|
|
48
48
|
name: name,
|
|
49
49
|
path: path.join(dirpath),
|
|
50
50
|
ext: ext,
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
dirpath = path.join(dir, "
|
|
54
|
+
dirpath = path.join(dir, "actions");
|
|
55
55
|
if (fs.existsSync(dirpath)) {
|
|
56
|
-
const data = _readDir(dirpath, ["
|
|
56
|
+
const data = _readDir(dirpath, ["yml", ".js", "mjs", ".py"]);
|
|
57
57
|
data.forEach((filename) => {
|
|
58
58
|
const parts = filename.split(".");
|
|
59
59
|
const ext = parts.pop();
|
|
60
60
|
const name = parts.join("");
|
|
61
|
-
feats.
|
|
61
|
+
feats.action.push({
|
|
62
62
|
name: name,
|
|
63
63
|
path: path.join(dirpath),
|
|
64
64
|
ext: ext,
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
dirpath = path.join(dir, "
|
|
68
|
+
dirpath = path.join(dir, "adaptaters");
|
|
69
69
|
if (fs.existsSync(dirpath)) {
|
|
70
|
-
const data = _readDir(dirpath, ["
|
|
70
|
+
const data = _readDir(dirpath, [".js"]);
|
|
71
71
|
data.forEach((filename) => {
|
|
72
72
|
const parts = filename.split(".");
|
|
73
73
|
const ext = parts.pop();
|
|
74
74
|
const name = parts.join("");
|
|
75
|
-
feats.
|
|
75
|
+
feats.adaptater.push({
|
|
76
76
|
name: name,
|
|
77
77
|
path: path.join(dirpath),
|
|
78
78
|
ext: ext,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { default as fs } from "fs";
|
|
2
|
+
import { default as path } from "path";
|
|
3
|
+
function readTask(taskpath) {
|
|
4
|
+
if (!fs.existsSync(taskpath)) {
|
|
5
|
+
return { ymlTask: "", found: false };
|
|
6
|
+
}
|
|
7
|
+
const data = fs.readFileSync(taskpath, 'utf8');
|
|
8
|
+
return { ymlTask: data, found: true };
|
|
9
|
+
}
|
|
10
|
+
function readTasksDir(dir) {
|
|
11
|
+
const tasks = new Array();
|
|
12
|
+
fs.readdirSync(dir).forEach((filename) => {
|
|
13
|
+
const filepath = path.join(dir, filename);
|
|
14
|
+
const isDir = fs.statSync(filepath).isDirectory();
|
|
15
|
+
if (!isDir) {
|
|
16
|
+
if (filename.endsWith(".yml")) {
|
|
17
|
+
tasks.push(filename);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return tasks;
|
|
22
|
+
}
|
|
23
|
+
export { readTask, readTasksDir, };
|
|
@@ -19,9 +19,12 @@ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, onEmitLi
|
|
|
19
19
|
rsShell.on('message', function (message) {
|
|
20
20
|
handleLine(message);
|
|
21
21
|
});
|
|
22
|
+
rsShell.on('stderr', function (err) {
|
|
23
|
+
console.log("STDERR", err);
|
|
24
|
+
});
|
|
22
25
|
rsShell.on('pythonError', function (err) {
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
res.error = new Error(`${err.traceback} ${err.message}`);
|
|
27
|
+
promiseResolve(true);
|
|
25
28
|
});
|
|
26
29
|
rsShell.end(function (err, code, signal) {
|
|
27
30
|
promiseResolve(true);
|
package/dist/db/db.d.ts
CHANGED
package/dist/db/db.js
CHANGED
package/dist/db/read.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToolSpec } from "modprompt";
|
|
2
|
+
import { AliasType, FeatureSpec, FeatureType, ToolType } from "../interfaces.js";
|
|
2
3
|
declare function readFeaturePaths(): Array<string>;
|
|
3
4
|
declare function readPlugins(): Array<Record<string, string>>;
|
|
4
5
|
declare function readFeatures(): Record<FeatureType, Record<string, string>>;
|
|
@@ -10,5 +11,10 @@ declare function readFeature(name: string, type: FeatureType): {
|
|
|
10
11
|
found: boolean;
|
|
11
12
|
feature: FeatureSpec;
|
|
12
13
|
};
|
|
13
|
-
declare function
|
|
14
|
-
|
|
14
|
+
declare function readTool(name: string): {
|
|
15
|
+
found: boolean;
|
|
16
|
+
tool: ToolSpec;
|
|
17
|
+
type: ToolType;
|
|
18
|
+
};
|
|
19
|
+
declare function readPromptFilePath(): string;
|
|
20
|
+
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFilePath, readTool, };
|
package/dist/db/read.js
CHANGED
|
@@ -27,12 +27,12 @@ function _readFeaturesType(type) {
|
|
|
27
27
|
return f;
|
|
28
28
|
}
|
|
29
29
|
function readFeatures() {
|
|
30
|
-
const feats = { task: {},
|
|
30
|
+
const feats = { task: {}, action: {}, cmd: {}, workflow: {}, adaptater: {} };
|
|
31
31
|
feats.task = _readFeaturesType("task");
|
|
32
|
-
feats.job = _readFeaturesType("job");
|
|
33
32
|
feats.action = _readFeaturesType("action");
|
|
34
33
|
feats.cmd = _readFeaturesType("cmd");
|
|
35
34
|
feats.workflow = _readFeaturesType("workflow");
|
|
35
|
+
feats.adaptater = _readFeaturesType("adaptater");
|
|
36
36
|
return feats;
|
|
37
37
|
}
|
|
38
38
|
function readAliases() {
|
|
@@ -60,7 +60,22 @@ function readFeature(name, type) {
|
|
|
60
60
|
}
|
|
61
61
|
return { found: false, feature: {} };
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function readTool(name) {
|
|
64
|
+
const q = `SELECT id, name, type, spec FROM tool WHERE name='${name}'`;
|
|
65
|
+
const stmt = db.prepare(q);
|
|
66
|
+
const result = stmt.get();
|
|
67
|
+
const tool = JSON.parse(result.spec);
|
|
68
|
+
tool["name"] = name;
|
|
69
|
+
if (result?.id) {
|
|
70
|
+
return {
|
|
71
|
+
found: true,
|
|
72
|
+
tool: tool,
|
|
73
|
+
type: result.type,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { found: false, tool: {}, type: "action" };
|
|
77
|
+
}
|
|
78
|
+
function readPromptFilePath() {
|
|
64
79
|
const stmt1 = db.prepare("SELECT * FROM filepath WHERE name = ?");
|
|
65
80
|
const result = stmt1.get("promptfile");
|
|
66
81
|
let res = "";
|
|
@@ -69,4 +84,4 @@ function readPromptFile() {
|
|
|
69
84
|
}
|
|
70
85
|
return res;
|
|
71
86
|
}
|
|
72
|
-
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases,
|
|
87
|
+
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readPromptFilePath, readTool, };
|
package/dist/db/schemas.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const filepath = `CREATE TABLE IF NOT EXISTS filepath (
|
|
2
2
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
3
3
|
name TEXT UNIQUE NOT NULL,
|
|
4
4
|
path TEXT NOT NULL
|
|
5
5
|
);`;
|
|
6
|
-
const
|
|
6
|
+
const featurespath = `CREATE TABLE IF NOT EXISTS featurespath (
|
|
7
7
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
8
8
|
path TEXT NOT NULL
|
|
9
9
|
);`;
|
|
10
|
-
const
|
|
10
|
+
const plugin = `CREATE TABLE IF NOT EXISTS plugin (
|
|
11
11
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12
12
|
name TEXT UNIQUE NOT NULL,
|
|
13
13
|
path TEXT NOT NULL
|
|
@@ -18,36 +18,58 @@ const tasks = `CREATE TABLE IF NOT EXISTS task (
|
|
|
18
18
|
path TEXT NOT NULL,
|
|
19
19
|
ext TEXT NOT NULL CHECK ( ext IN ('yml') )
|
|
20
20
|
);`;
|
|
21
|
-
const
|
|
21
|
+
const workflow = `CREATE TABLE IF NOT EXISTS workflow (
|
|
22
22
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
23
23
|
name TEXT UNIQUE NOT NULL,
|
|
24
24
|
path TEXT NOT NULL,
|
|
25
25
|
ext TEXT NOT NULL CHECK ( ext IN ('yml') )
|
|
26
26
|
);`;
|
|
27
|
-
const
|
|
27
|
+
const action = `CREATE TABLE IF NOT EXISTS action (
|
|
28
28
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
29
29
|
name TEXT UNIQUE NOT NULL,
|
|
30
30
|
path TEXT NOT NULL,
|
|
31
|
-
ext TEXT NOT NULL CHECK ( ext IN ('yml') )
|
|
31
|
+
ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py') )
|
|
32
32
|
);`;
|
|
33
|
-
const
|
|
33
|
+
const adaptater = `CREATE TABLE IF NOT EXISTS adaptater (
|
|
34
34
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
35
35
|
name TEXT UNIQUE NOT NULL,
|
|
36
36
|
path TEXT NOT NULL,
|
|
37
|
-
ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py'
|
|
37
|
+
ext TEXT NOT NULL CHECK ( ext IN ('yml', 'js', 'py') )
|
|
38
38
|
);`;
|
|
39
|
-
const
|
|
39
|
+
const tool = `CREATE TABLE IF NOT EXISTS tool (
|
|
40
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
41
|
+
name TEXT UNIQUE NOT NULL,
|
|
42
|
+
spec TEXT NOT NULL,
|
|
43
|
+
type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
|
|
44
|
+
);`;
|
|
45
|
+
const cmd = `CREATE TABLE IF NOT EXISTS cmd (
|
|
40
46
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
41
47
|
name TEXT UNIQUE NOT NULL,
|
|
42
48
|
path TEXT NOT NULL,
|
|
43
49
|
ext TEXT NOT NULL CHECK ( ext IN ('js') )
|
|
44
50
|
);`;
|
|
45
|
-
const
|
|
51
|
+
const alias = `CREATE TABLE IF NOT EXISTS aliases (
|
|
52
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
53
|
+
name TEXT UNIQUE NOT NULL,
|
|
54
|
+
type TEXT NOT NULL CHECK ( type IN ('task', 'action', 'workflow') )
|
|
55
|
+
);`;
|
|
56
|
+
const model = `CREATE TABLE IF NOT EXISTS model (
|
|
46
57
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
58
|
name TEXT UNIQUE NOT NULL,
|
|
48
|
-
|
|
59
|
+
ctx INTEGER NOT NULL,
|
|
60
|
+
template TEXT NOT NULL
|
|
49
61
|
);`;
|
|
50
62
|
const schemas = [
|
|
51
|
-
|
|
63
|
+
filepath,
|
|
64
|
+
featurespath,
|
|
65
|
+
tasks,
|
|
66
|
+
workflow,
|
|
67
|
+
action,
|
|
68
|
+
tool,
|
|
69
|
+
cmd,
|
|
70
|
+
plugin,
|
|
71
|
+
alias,
|
|
72
|
+
model,
|
|
73
|
+
adaptater,
|
|
52
74
|
];
|
|
53
75
|
export { schemas };
|
package/dist/db/write.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { extractToolDoc } from "../cmd/lib/tools.js";
|
|
1
2
|
import { db } from "./db.js";
|
|
2
3
|
function updatePromptfilePath(pf) {
|
|
3
|
-
const deleteStmt = db.prepare("DELETE FROM
|
|
4
|
+
const deleteStmt = db.prepare("DELETE FROM filepath WHERE name = ?");
|
|
4
5
|
deleteStmt.run("promptfile");
|
|
5
6
|
const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
|
|
6
7
|
stmt.run("promptfile", pf);
|
|
@@ -59,9 +60,6 @@ function updateAliases(feats) {
|
|
|
59
60
|
feats.action.forEach((feat) => {
|
|
60
61
|
existingAliases = _updateAlias(existingAliases, feat.name, "action");
|
|
61
62
|
});
|
|
62
|
-
feats.job.forEach((feat) => {
|
|
63
|
-
existingAliases = _updateAlias(existingAliases, feat.name, "job");
|
|
64
|
-
});
|
|
65
63
|
feats.workflow.forEach((feat) => {
|
|
66
64
|
existingAliases = _updateAlias(existingAliases, feat.name, "workflow");
|
|
67
65
|
});
|
|
@@ -71,11 +69,19 @@ function upsertAndCleanFeatures(feats, type) {
|
|
|
71
69
|
const rows = stmt.all();
|
|
72
70
|
const names = rows.map(row => row.name);
|
|
73
71
|
const availableFeatsNames = feats.map((f) => f.name);
|
|
72
|
+
const newFeatures = new Array();
|
|
74
73
|
names.forEach((name) => {
|
|
75
74
|
if (!availableFeatsNames.includes(name)) {
|
|
76
75
|
const deleteStmt = db.prepare(`DELETE FROM ${type} WHERE name = ?`);
|
|
77
76
|
deleteStmt.run(name);
|
|
78
77
|
console.log("-", "[" + type + "]", name);
|
|
78
|
+
const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
|
|
79
|
+
const result = stmt1.get(name);
|
|
80
|
+
if (result?.id) {
|
|
81
|
+
const deleteStmt = db.prepare("DELETE FROM featurespath WHERE id = ?");
|
|
82
|
+
deleteStmt.run(result.id);
|
|
83
|
+
console.log("-", "[tool] from", type, ":", name);
|
|
84
|
+
}
|
|
79
85
|
}
|
|
80
86
|
});
|
|
81
87
|
feats.forEach((feat) => {
|
|
@@ -83,14 +89,34 @@ function upsertAndCleanFeatures(feats, type) {
|
|
|
83
89
|
const insertStmt = db.prepare(`INSERT INTO ${type} (name, path, ext) VALUES (?, ?, ?)`);
|
|
84
90
|
insertStmt.run(feat.name, feat.path, feat.ext);
|
|
85
91
|
console.log("+", "[" + type + "]", feat.name, feat.path);
|
|
92
|
+
newFeatures.push(feat);
|
|
86
93
|
}
|
|
87
94
|
});
|
|
95
|
+
return newFeatures;
|
|
96
|
+
}
|
|
97
|
+
function upsertTool(name, type, toolDoc) {
|
|
98
|
+
const stmt1 = db.prepare("SELECT * FROM tool WHERE name = ?");
|
|
99
|
+
const result = stmt1.get(name);
|
|
100
|
+
if (result?.id) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const stmt = db.prepare("INSERT INTO tool (name, spec, type) VALUES (?,?,?)");
|
|
104
|
+
stmt.run(name, toolDoc, type);
|
|
105
|
+
console.log("+", "[tool] from", type, ":", name);
|
|
88
106
|
}
|
|
89
107
|
function updateFeatures(feats) {
|
|
90
108
|
upsertAndCleanFeatures(feats.task, "task");
|
|
91
|
-
upsertAndCleanFeatures(feats.
|
|
92
|
-
|
|
109
|
+
const newActions = upsertAndCleanFeatures(feats.action, "action");
|
|
110
|
+
if (newActions.length > 0) {
|
|
111
|
+
newActions.forEach((feat) => {
|
|
112
|
+
const { found, toolDoc } = extractToolDoc(feat.name, feat.ext, feat.path);
|
|
113
|
+
if (found) {
|
|
114
|
+
upsertTool(feat.name, "action", toolDoc);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
93
118
|
upsertAndCleanFeatures(feats.cmd, "cmd");
|
|
94
119
|
upsertAndCleanFeatures(feats.workflow, "workflow");
|
|
120
|
+
upsertAndCleanFeatures(feats.adaptater, "adaptater");
|
|
95
121
|
}
|
|
96
122
|
export { updatePromptfilePath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, };
|
package/dist/index.js
CHANGED
|
File without changes
|