@agent-smith/core 0.0.1
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/README.md +378 -0
- package/dist/actions/cmd.d.ts +5 -0
- package/dist/actions/cmd.js +135 -0
- package/dist/actions/read.d.ts +3 -0
- package/dist/actions/read.js +17 -0
- package/dist/adaptaters/cmd.d.ts +2 -0
- package/dist/adaptaters/cmd.js +39 -0
- package/dist/agents/cmd.d.ts +3 -0
- package/dist/agents/cmd.js +10 -0
- package/dist/agents/conf.d.ts +3 -0
- package/dist/agents/conf.js +9 -0
- package/dist/agents/files.d.ts +3 -0
- package/dist/agents/files.js +40 -0
- package/dist/agents/read.d.ts +11 -0
- package/dist/agents/read.js +241 -0
- package/dist/agents/useagent.d.ts +13 -0
- package/dist/agents/useagent.js +395 -0
- package/dist/conf.d.ts +14 -0
- package/dist/conf.js +160 -0
- package/dist/const.d.ts +3 -0
- package/dist/const.js +10 -0
- package/dist/db/db.d.ts +3 -0
- package/dist/db/db.js +24 -0
- package/dist/db/read.d.ts +45 -0
- package/dist/db/read.js +280 -0
- package/dist/db/schemas.d.ts +2 -0
- package/dist/db/schemas.js +141 -0
- package/dist/db/write.d.ts +23 -0
- package/dist/db/write.js +570 -0
- package/dist/features/actions/load-skill.d.ts +2 -0
- package/dist/features/actions/load-skill.js +37 -0
- package/dist/features/actions/notify-user.d.ts +2 -0
- package/dist/features/actions/notify-user.js +25 -0
- package/dist/features/actions/read-feature.d.ts +2 -0
- package/dist/features/actions/read-feature.js +25 -0
- package/dist/features/actions/run-agent.d.ts +2 -0
- package/dist/features/actions/run-agent.js +34 -0
- package/dist/features/actions/run-collaborator.d.ts +1 -0
- package/dist/features/actions/run-collaborator.js +42 -0
- package/dist/features/actions/run-worker.d.ts +2 -0
- package/dist/features/actions/run-worker.js +34 -0
- package/dist/features/adaptaters/agent-smith-db-getschema.d.ts +4 -0
- package/dist/features/adaptaters/agent-smith-db-getschema.js +62 -0
- package/dist/features/adaptaters/imgs2base64.d.ts +1 -0
- package/dist/features/adaptaters/imgs2base64.js +13 -0
- package/dist/features/adaptaters/prequery.d.ts +4 -0
- package/dist/features/adaptaters/prequery.js +5 -0
- package/dist/features/agents/agent-smith-colab.yml +37 -0
- package/dist/features/agents/agent-smith-doc.yml +50 -0
- package/dist/features/agents/agent-smith-help.yml +35 -0
- package/dist/features/agents/agent-smith-search.yml +41 -0
- package/dist/features/agents/agent-smith-sql.yml +31 -0
- package/dist/features/agents/agent-smith.yml +37 -0
- package/dist/features/agents/collaborator.yml +15 -0
- package/dist/features/agents/infer.yml +12 -0
- package/dist/features/fragments/ctx-helper-files.md +4 -0
- package/dist/features/fragments/workspace.txt +6 -0
- package/dist/features/skills/create-package-readme/SKILL.md +66 -0
- package/dist/features/skills/document-package/SKILL.md +83 -0
- package/dist/features/skills/t/SKILL.md +26 -0
- package/dist/features/skills/update-codebase-summary/SKILL.md +45 -0
- package/dist/features/skills/update-doc-map/SKILL.md +8 -0
- package/dist/features/skills/update-doc-map/scripts/generate-doc-map.mjs +196 -0
- package/dist/features/workflows/agent-smith-db.yml +9 -0
- package/dist/features/workflows/q.yml +3 -0
- package/dist/features/workflows/vision.yml +3 -0
- package/dist/main.d.ts +127 -0
- package/dist/main.js +80 -0
- package/dist/mcp.d.ts +16 -0
- package/dist/mcp.js +110 -0
- package/dist/state/backends.d.ts +7 -0
- package/dist/state/backends.js +96 -0
- package/dist/state/features.d.ts +10 -0
- package/dist/state/features.js +42 -0
- package/dist/state/plugins.d.ts +6 -0
- package/dist/state/plugins.js +27 -0
- package/dist/state/state.d.ts +18 -0
- package/dist/state/state.js +79 -0
- package/dist/state/tasks.d.ts +6 -0
- package/dist/state/tasks.js +33 -0
- package/dist/tools.d.ts +15 -0
- package/dist/tools.js +149 -0
- package/dist/updateconf.d.ts +5 -0
- package/dist/updateconf.js +124 -0
- package/dist/utils/io.d.ts +10 -0
- package/dist/utils/io.js +98 -0
- package/dist/utils/perf.d.ts +9 -0
- package/dist/utils/perf.js +63 -0
- package/dist/utils/sys/clipboard.d.ts +3 -0
- package/dist/utils/sys/clipboard.js +33 -0
- package/dist/utils/sys/delete_file.d.ts +2 -0
- package/dist/utils/sys/delete_file.js +10 -0
- package/dist/utils/sys/dirs.d.ts +2 -0
- package/dist/utils/sys/dirs.js +9 -0
- package/dist/utils/sys/execute.d.ts +13 -0
- package/dist/utils/sys/execute.js +48 -0
- package/dist/utils/sys/read.d.ts +3 -0
- package/dist/utils/sys/read.js +21 -0
- package/dist/utils/sys/read_agent.d.ts +6 -0
- package/dist/utils/sys/read_agent.js +23 -0
- package/dist/utils/sys/read_cmds.d.ts +7 -0
- package/dist/utils/sys/read_cmds.js +37 -0
- package/dist/utils/sys/read_conf.d.ts +6 -0
- package/dist/utils/sys/read_conf.js +12 -0
- package/dist/utils/sys/read_features.d.ts +3 -0
- package/dist/utils/sys/read_features.js +134 -0
- package/dist/utils/sys/read_yml_file.d.ts +5 -0
- package/dist/utils/sys/read_yml_file.js +11 -0
- package/dist/utils/sys/run_python.d.ts +6 -0
- package/dist/utils/sys/run_python.js +39 -0
- package/dist/utils/text.d.ts +2 -0
- package/dist/utils/text.js +28 -0
- package/dist/utils/user_msgs.d.ts +5 -0
- package/dist/utils/user_msgs.js +19 -0
- package/dist/workflows/cmd.d.ts +3 -0
- package/dist/workflows/cmd.js +189 -0
- package/dist/workflows/read.d.ts +6 -0
- package/dist/workflows/read.js +61 -0
- package/package.json +45 -0
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
//import { confirmToolUsage } from "./tools.js";
|
|
4
|
+
class McpClient {
|
|
5
|
+
name;
|
|
6
|
+
transport;
|
|
7
|
+
client;
|
|
8
|
+
authorizedTools = null;
|
|
9
|
+
askUserTools = null;
|
|
10
|
+
tools = {};
|
|
11
|
+
constructor(servername, command, args, authorizedTools = null, askUserTools = null) {
|
|
12
|
+
//console.log("MCP servername", servername);
|
|
13
|
+
//console.log("MCP command", command);
|
|
14
|
+
//console.log("MCP ARGS", typeof args, args);
|
|
15
|
+
this.name = servername;
|
|
16
|
+
const okargs = new Array();
|
|
17
|
+
for (const arg of args) {
|
|
18
|
+
let _arg = arg;
|
|
19
|
+
if (arg.startsWith("Authorization:")) {
|
|
20
|
+
const k = `MCP_${servername.toUpperCase()}_AUTH`;
|
|
21
|
+
const v = process.env[k];
|
|
22
|
+
if (!v) {
|
|
23
|
+
throw new Error(`Env variable ${k} not found for ${servername} mcp auth`);
|
|
24
|
+
}
|
|
25
|
+
_arg = arg.replace("$MCP_AUTH", v);
|
|
26
|
+
}
|
|
27
|
+
okargs.push(_arg);
|
|
28
|
+
}
|
|
29
|
+
this.transport = new StdioClientTransport({
|
|
30
|
+
command: command,
|
|
31
|
+
args: args
|
|
32
|
+
});
|
|
33
|
+
this.client = new Client({ name: "AgentSmith", version: "0.1.0" });
|
|
34
|
+
if (authorizedTools) {
|
|
35
|
+
this.authorizedTools = authorizedTools;
|
|
36
|
+
}
|
|
37
|
+
if (askUserTools) {
|
|
38
|
+
this.askUserTools = askUserTools;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async start() {
|
|
42
|
+
await this.client.connect(this.transport);
|
|
43
|
+
}
|
|
44
|
+
async stop() {
|
|
45
|
+
await this.client.close();
|
|
46
|
+
}
|
|
47
|
+
async extractTools(options) {
|
|
48
|
+
const toolSpecs = new Array();
|
|
49
|
+
const serverToolsList = await this.client.listTools();
|
|
50
|
+
for (const tool of serverToolsList.tools) {
|
|
51
|
+
if (this.authorizedTools) {
|
|
52
|
+
if (!this.authorizedTools.includes(tool.name)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const defargs = {};
|
|
57
|
+
const argsTypes = {};
|
|
58
|
+
if (tool.inputSchema.properties) {
|
|
59
|
+
for (const [k, v] of Object.entries(tool.inputSchema.properties)) {
|
|
60
|
+
const vv = v;
|
|
61
|
+
defargs[k] = { description: vv.description + " (" + vv.type + ")" };
|
|
62
|
+
argsTypes[k] = vv.type;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//console.log("MCP ARGS TYPES", argsTypes);
|
|
66
|
+
const exec = async (args) => {
|
|
67
|
+
//console.log("MCP EXEC ARGS", args);
|
|
68
|
+
const _iargs = args;
|
|
69
|
+
for (const [k, v] of Object.entries(_iargs)) {
|
|
70
|
+
if (argsTypes[k] == "array") {
|
|
71
|
+
try {
|
|
72
|
+
_iargs[k] = JSON.parse(v);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.warn("Error parsing array data from model for tool call", k, "Data:", v);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
;
|
|
80
|
+
const payload = {
|
|
81
|
+
name: tool.name,
|
|
82
|
+
arguments: _iargs,
|
|
83
|
+
};
|
|
84
|
+
//console.log("PAY", payload);
|
|
85
|
+
const res = await this.client.callTool(payload);
|
|
86
|
+
return res;
|
|
87
|
+
};
|
|
88
|
+
const t = {
|
|
89
|
+
type: "mcp",
|
|
90
|
+
name: tool.name,
|
|
91
|
+
description: tool.description ?? "",
|
|
92
|
+
arguments: defargs,
|
|
93
|
+
parallelCalls: true,
|
|
94
|
+
execute: exec
|
|
95
|
+
};
|
|
96
|
+
if (this.askUserTools) {
|
|
97
|
+
if (this.askUserTools.includes(tool.name)) {
|
|
98
|
+
if (!options?.confirmToolUsage) {
|
|
99
|
+
throw new Error("provide a tool usage confirm function");
|
|
100
|
+
}
|
|
101
|
+
t.canRun = options.confirmToolUsage;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.tools[tool.name] = t;
|
|
105
|
+
toolSpecs.push(t);
|
|
106
|
+
}
|
|
107
|
+
return toolSpecs;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export { McpClient, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Lm } from "@agent-smith/agent";
|
|
2
|
+
declare const backend: import("@vue/reactivity").Ref<Lm | undefined, Lm | undefined>;
|
|
3
|
+
declare const backends: Record<string, Lm>;
|
|
4
|
+
declare function initBackends(): Promise<void>;
|
|
5
|
+
declare function setBackend(name: string, isVerbose?: boolean): Promise<boolean>;
|
|
6
|
+
declare function listBackends(printResult?: boolean): Promise<string>;
|
|
7
|
+
export { backend, backends, initBackends, listBackends, setBackend };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Lm } from "@agent-smith/agent";
|
|
2
|
+
import { ref } from "@vue/reactivity";
|
|
3
|
+
import colors from "ansi-colors";
|
|
4
|
+
import { readBackends } from "../db/read.js";
|
|
5
|
+
import { setDefaultBackend } from "../db/write.js";
|
|
6
|
+
import { runtimeDataError } from "../utils/user_msgs.js";
|
|
7
|
+
const backend = ref();
|
|
8
|
+
const backends = {};
|
|
9
|
+
const isBackendUp = ref(false);
|
|
10
|
+
async function initBackends() {
|
|
11
|
+
const rmb = readBackends();
|
|
12
|
+
//console.log("Backends:", rmb)
|
|
13
|
+
let defaultBackendName = null;
|
|
14
|
+
for (const bk of Object.values(rmb)) {
|
|
15
|
+
//console.log("BK", bk.name);
|
|
16
|
+
let name = bk.name;
|
|
17
|
+
let apiKey = "";
|
|
18
|
+
if (bk?.apiKey) {
|
|
19
|
+
if (bk.apiKey.startsWith("$")) {
|
|
20
|
+
const apk = process.env[bk.apiKey.slice(1)];
|
|
21
|
+
if (apk === undefined) {
|
|
22
|
+
runtimeDataError(`No ${bk.apiKey} environment variable found, required for `, name);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
apiKey = apk;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
apiKey = bk.apiKey;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
const lm = new Lm({
|
|
33
|
+
name: name,
|
|
34
|
+
serverUrl: bk.url,
|
|
35
|
+
apiKey: apiKey.length > 0 ? apiKey : undefined,
|
|
36
|
+
});
|
|
37
|
+
lm.name = bk.name;
|
|
38
|
+
//console.log("ADD BK", lm);
|
|
39
|
+
backends[name] = lm;
|
|
40
|
+
if (bk.isDefault) {
|
|
41
|
+
defaultBackendName = bk.name;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (defaultBackendName !== null) {
|
|
45
|
+
backend.value = backends[defaultBackendName];
|
|
46
|
+
//console.log("Setting default backend", defaultBackendName, "/", backend.value.name)
|
|
47
|
+
/*isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
48
|
+
|
|
49
|
+
if (isBackendUp.value && backend.value.providerType == "ollama") {
|
|
50
|
+
await backend.value.modelsInfo();
|
|
51
|
+
}*/
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function setBackend(name, isVerbose = false) {
|
|
55
|
+
if (!(Object.keys(backends).includes(name))) {
|
|
56
|
+
runtimeDataError(`Backend ${name} not found. Available backends: ${Object.keys(backends)}`);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
backend.value = backends[name];
|
|
60
|
+
setDefaultBackend(name);
|
|
61
|
+
console.log("Default backend set to", name);
|
|
62
|
+
isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
63
|
+
return isBackendUp.value;
|
|
64
|
+
}
|
|
65
|
+
async function listBackends(printResult = true) {
|
|
66
|
+
//console.log("DEFB", backend.value?.name);
|
|
67
|
+
const allBk = new Array();
|
|
68
|
+
for (const [name, lm] of Object.entries(backends)) {
|
|
69
|
+
const bcn = (name == backend.value?.name) ? colors.bold(name) : name;
|
|
70
|
+
//const isUp = await probeBackend(lm, false);
|
|
71
|
+
const buf = new Array("-", bcn, colors.dim(lm.serverUrl));
|
|
72
|
+
const str = buf.join(" ");
|
|
73
|
+
if (printResult) {
|
|
74
|
+
console.log(str);
|
|
75
|
+
}
|
|
76
|
+
allBk.push(str);
|
|
77
|
+
}
|
|
78
|
+
return allBk.join(" ");
|
|
79
|
+
}
|
|
80
|
+
const probeBackend = async (lm, isVerbose) => {
|
|
81
|
+
let isUp = false;
|
|
82
|
+
try {
|
|
83
|
+
await lm.modelsInfo();
|
|
84
|
+
if (isVerbose) {
|
|
85
|
+
console.log(`Provider ${lm.name} up`);
|
|
86
|
+
}
|
|
87
|
+
isUp = true;
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
if (isVerbose) {
|
|
91
|
+
console.log(`Provider ${lm.name} down`, e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return isUp;
|
|
95
|
+
};
|
|
96
|
+
export { backend, backends, initBackends, listBackends, setBackend };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FeatureExtension, FeatureType, Features } from "@agent-smith/types";
|
|
2
|
+
declare function getBuiltinFeaturesDirPath(): string;
|
|
3
|
+
declare function readFeaturesDirs(featuresPaths: Array<string>, isverbose?: boolean): Features;
|
|
4
|
+
declare function getFeatureSpec(name: string, type: FeatureType): {
|
|
5
|
+
found: boolean;
|
|
6
|
+
path: string;
|
|
7
|
+
ext: FeatureExtension;
|
|
8
|
+
variables?: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
export { readFeaturesDirs, getFeatureSpec, getBuiltinFeaturesDirPath, };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { default as path } from "path";
|
|
2
|
+
import { readFeaturesDir } from "../utils/sys/read_features.js";
|
|
3
|
+
import { readFeature } from "../db/read.js";
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join } from 'path';
|
|
6
|
+
function getBuiltinFeaturesDirPath() {
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
return join(__dirname, "../features");
|
|
10
|
+
}
|
|
11
|
+
function readFeaturesDirs(featuresPaths, isverbose = false) {
|
|
12
|
+
const feats = {
|
|
13
|
+
action: [],
|
|
14
|
+
cmd: [],
|
|
15
|
+
workflow: [],
|
|
16
|
+
adaptater: [],
|
|
17
|
+
agent: [],
|
|
18
|
+
skill: [],
|
|
19
|
+
};
|
|
20
|
+
featuresPaths.forEach((dir) => {
|
|
21
|
+
if (isverbose) {
|
|
22
|
+
console.log("Reading feats in", dir);
|
|
23
|
+
}
|
|
24
|
+
const _f = readFeaturesDir(dir);
|
|
25
|
+
_f.agent.forEach((item) => feats.agent.push(item));
|
|
26
|
+
_f.action.forEach((item) => feats.action.push(item));
|
|
27
|
+
_f.cmd.forEach((item) => feats.cmd.push(item));
|
|
28
|
+
_f.workflow.forEach((item) => feats.workflow.push(item));
|
|
29
|
+
_f.adaptater.forEach((item) => feats.adaptater.push(item));
|
|
30
|
+
_f.skill.forEach((item) => feats.skill.push(item));
|
|
31
|
+
});
|
|
32
|
+
return feats;
|
|
33
|
+
}
|
|
34
|
+
function getFeatureSpec(name, type) {
|
|
35
|
+
const { found, feature } = readFeature(name, type);
|
|
36
|
+
if (!found) {
|
|
37
|
+
return { found: false, path: "", ext: "yml", variables: {} };
|
|
38
|
+
}
|
|
39
|
+
const f = path.join(feature.path, name + "." + feature.ext);
|
|
40
|
+
return { found: true, path: f, ext: feature.ext, variables: feature?.variables };
|
|
41
|
+
}
|
|
42
|
+
export { readFeaturesDirs, getFeatureSpec, getBuiltinFeaturesDirPath, };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { execute } from "../utils/sys/execute.js";
|
|
2
|
+
import { readPlugins } from "../db/read.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
async function buildPluginsPaths(names) {
|
|
5
|
+
const plugins = new Array();
|
|
6
|
+
const root = await execute("npm", ["root", "-g"]);
|
|
7
|
+
const rootPath = root.trim();
|
|
8
|
+
//console.log("PLUGINS", packs);
|
|
9
|
+
names.forEach((p) => {
|
|
10
|
+
plugins.push({
|
|
11
|
+
name: p,
|
|
12
|
+
path: path.join(rootPath, p, "dist")
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//console.log("PLUGINS PATHS", paths);
|
|
16
|
+
return plugins;
|
|
17
|
+
}
|
|
18
|
+
async function readPluginsPaths() {
|
|
19
|
+
const paths = new Array();
|
|
20
|
+
const plugins = readPlugins();
|
|
21
|
+
plugins.forEach((p) => {
|
|
22
|
+
paths.push(p.path);
|
|
23
|
+
});
|
|
24
|
+
//console.log("PLUGINS PATHS", paths);
|
|
25
|
+
return paths;
|
|
26
|
+
}
|
|
27
|
+
export { buildPluginsPaths, readPluginsPaths };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FormatMode, InputMode, OutputMode } from "@agent-smith/types";
|
|
2
|
+
import { PythonShell } from 'python-shell';
|
|
3
|
+
declare let pyShell: PythonShell;
|
|
4
|
+
declare const inputMode: import("@vue/reactivity").Ref<InputMode, InputMode>;
|
|
5
|
+
declare const outputMode: import("@vue/reactivity").Ref<OutputMode, OutputMode>;
|
|
6
|
+
declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
|
|
7
|
+
declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
|
|
8
|
+
declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
|
|
9
|
+
declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
10
|
+
declare const lastCmd: {
|
|
11
|
+
name: string;
|
|
12
|
+
args: Array<string>;
|
|
13
|
+
};
|
|
14
|
+
declare function initFilepaths(): void;
|
|
15
|
+
declare function init(): Promise<void>;
|
|
16
|
+
declare function initState(): Promise<void>;
|
|
17
|
+
declare function pluginDataDir(pluginName: string): string;
|
|
18
|
+
export { dataDirPath, formatMode, init, initFilepaths, initState, inputMode, isStateReady, lastCmd, outputMode, pluginDataDir, promptfilePath, pyShell };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { reactive, ref } from "@vue/reactivity";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createDirectoryIfNotExists } from "../utils/sys/dirs.js";
|
|
4
|
+
import { initDb } from "../db/db.js";
|
|
5
|
+
import { readFilePaths } from "../db/read.js";
|
|
6
|
+
import { runtimeDataError } from "../utils/user_msgs.js";
|
|
7
|
+
import { backend, initBackends } from "./backends.js";
|
|
8
|
+
//import { usePerfTimer } from "../main.js";
|
|
9
|
+
let pyShell;
|
|
10
|
+
const inputMode = ref("manual");
|
|
11
|
+
const outputMode = ref("txt");
|
|
12
|
+
const formatMode = ref("text");
|
|
13
|
+
//const verbosity = ref<VerbosityMode>("quiet");
|
|
14
|
+
const promptfilePath = ref("");
|
|
15
|
+
const dataDirPath = ref("");
|
|
16
|
+
const isStateReady = ref(false);
|
|
17
|
+
const isReady = ref(false);
|
|
18
|
+
const lastCmd = reactive({
|
|
19
|
+
name: "",
|
|
20
|
+
args: [],
|
|
21
|
+
});
|
|
22
|
+
function initFilepaths() {
|
|
23
|
+
const filePaths = readFilePaths();
|
|
24
|
+
//console.log("FP", filePaths);
|
|
25
|
+
for (const fp of filePaths) {
|
|
26
|
+
switch (fp.name) {
|
|
27
|
+
case "promptfile":
|
|
28
|
+
promptfilePath.value = fp.path;
|
|
29
|
+
break;
|
|
30
|
+
case "datadir":
|
|
31
|
+
dataDirPath.value = fp.path;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function init() {
|
|
36
|
+
if (isStateReady.value) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
//const perf = usePerfTimer();
|
|
40
|
+
await initState();
|
|
41
|
+
//perf.measure("initState");
|
|
42
|
+
if (!isReady.value) {
|
|
43
|
+
await initBackends();
|
|
44
|
+
}
|
|
45
|
+
//perf.measure("initBackends");
|
|
46
|
+
if (!backend.value) {
|
|
47
|
+
runtimeDataError("No backend found, can not initialize agent");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
isReady.value = true;
|
|
51
|
+
//perf.final("init")
|
|
52
|
+
//console.log("Agent", agent);
|
|
53
|
+
}
|
|
54
|
+
async function initState() {
|
|
55
|
+
if (isStateReady.value) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
//sconsole.log("INIT STATE");
|
|
59
|
+
initDb(false, false);
|
|
60
|
+
initFilepaths();
|
|
61
|
+
isStateReady.value = true;
|
|
62
|
+
//console.log("State ready, available features:", readFeatures())
|
|
63
|
+
}
|
|
64
|
+
function _getDataDirPath() {
|
|
65
|
+
if (dataDirPath.value.length == 0) {
|
|
66
|
+
throw new Error("datadir path is not configured: update your config file with 'datadir' and run conf");
|
|
67
|
+
}
|
|
68
|
+
return dataDirPath.value;
|
|
69
|
+
}
|
|
70
|
+
function pluginDataDir(pluginName) {
|
|
71
|
+
const dd = _getDataDirPath();
|
|
72
|
+
const pluginDatapath = path.join(dd, pluginName);
|
|
73
|
+
createDirectoryIfNotExists(pluginDatapath);
|
|
74
|
+
return pluginDatapath;
|
|
75
|
+
}
|
|
76
|
+
/*function setVerbosity(mode: VerbosityMode) {
|
|
77
|
+
verbosity.value = mode
|
|
78
|
+
}*/
|
|
79
|
+
export { dataDirPath, formatMode, init, initFilepaths, initState, inputMode, isStateReady, lastCmd, outputMode, pluginDataDir, promptfilePath, pyShell };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AgentSettings } from "@agent-smith/types";
|
|
2
|
+
declare const agentSettings: Record<string, AgentSettings>;
|
|
3
|
+
declare const isAgentSettingsInitialized: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
4
|
+
declare function initAgentSettings(): void;
|
|
5
|
+
declare function getAgentSettings(force?: boolean): Record<string, AgentSettings>;
|
|
6
|
+
export { agentSettings, isAgentSettingsInitialized, initAgentSettings, getAgentSettings };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ref } from "@vue/reactivity";
|
|
2
|
+
import { readAgentSettings } from "../db/read.js";
|
|
3
|
+
const agentSettings = {};
|
|
4
|
+
const isAgentSettingsInitialized = ref(false);
|
|
5
|
+
function initAgentSettings() {
|
|
6
|
+
const data = readAgentSettings();
|
|
7
|
+
//console.log("AGENT SETTINGS DATA", data);
|
|
8
|
+
data.forEach(row => {
|
|
9
|
+
const name = row.name;
|
|
10
|
+
delete row.name;
|
|
11
|
+
delete row.id;
|
|
12
|
+
const vals = {};
|
|
13
|
+
for (const [k, v] of Object.entries(row)) {
|
|
14
|
+
if (v !== null) {
|
|
15
|
+
let _v = v;
|
|
16
|
+
if (["props", "chat_template_kwargs"].includes(k)) {
|
|
17
|
+
_v = JSON.parse(v);
|
|
18
|
+
}
|
|
19
|
+
vals[k] = _v;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
agentSettings[name] = vals;
|
|
23
|
+
});
|
|
24
|
+
//console.log("AGENT SETTINGS", agentSettings);
|
|
25
|
+
isAgentSettingsInitialized.value = true;
|
|
26
|
+
}
|
|
27
|
+
function getAgentSettings(force = false) {
|
|
28
|
+
if (!isAgentSettingsInitialized.value === true || force) {
|
|
29
|
+
initAgentSettings();
|
|
30
|
+
}
|
|
31
|
+
return agentSettings;
|
|
32
|
+
}
|
|
33
|
+
export { agentSettings, isAgentSettingsInitialized, initAgentSettings, getAgentSettings };
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FeatureExtension } from '@agent-smith/types';
|
|
2
|
+
declare function extractAgentToolDocAndVariables(name: string, ext: FeatureExtension, dirPath: string): {
|
|
3
|
+
toolDoc: string;
|
|
4
|
+
variables: {
|
|
5
|
+
required: Array<string>;
|
|
6
|
+
optional: Array<string>;
|
|
7
|
+
};
|
|
8
|
+
type: string | null;
|
|
9
|
+
category: string | null;
|
|
10
|
+
};
|
|
11
|
+
declare function extractToolDoc(name: string, ext: FeatureExtension, dirPath: string): {
|
|
12
|
+
found: boolean;
|
|
13
|
+
toolDoc: string;
|
|
14
|
+
};
|
|
15
|
+
export { extractToolDoc, extractAgentToolDocAndVariables, };
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { readYmlFile } from './utils/sys/read_yml_file.js';
|
|
4
|
+
function _extractToolDoc(filePath, startComment, endComment) {
|
|
5
|
+
try {
|
|
6
|
+
//console.log("TD", filePath);
|
|
7
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
8
|
+
const startMarker = startComment + '\n# tool';
|
|
9
|
+
//console.log("TD 2", fileContent.startsWith(startMarker));
|
|
10
|
+
if (!fileContent.startsWith(startMarker)) {
|
|
11
|
+
//console.log("TD ERR", fileContent)
|
|
12
|
+
return { found: false, doc: "" };
|
|
13
|
+
}
|
|
14
|
+
const endMarker = endComment;
|
|
15
|
+
const startIndex = fileContent.indexOf(startMarker) + startMarker.length;
|
|
16
|
+
const endIndex = fileContent.indexOf(endMarker, startIndex);
|
|
17
|
+
if (endIndex === -1) {
|
|
18
|
+
throw new Error(`Markers not found in the file: ${filePath}`);
|
|
19
|
+
}
|
|
20
|
+
const extractedContent = fileContent.substring(startIndex, endIndex).trim();
|
|
21
|
+
//console.log("TD 3", fileContent.substring(startIndex, endIndex).trim());
|
|
22
|
+
//console.log("TD 4", extractedContent);
|
|
23
|
+
return { found: true, doc: extractedContent };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
if (error.message.includes('ENOENT')) {
|
|
28
|
+
throw new Error(`File not found: ${filePath}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error(`Error processing the file: ${filePath}. ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(`An unexpected error occurred: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _extractPyToolDoc(filePath) {
|
|
40
|
+
return _extractToolDoc(filePath, '"""', '"""');
|
|
41
|
+
}
|
|
42
|
+
function _extractJsToolDoc(filePath) {
|
|
43
|
+
return _extractToolDoc(filePath, '/*', '*/');
|
|
44
|
+
}
|
|
45
|
+
function _extractYamlToolDoc(filePath, name) {
|
|
46
|
+
const { data, found } = readYmlFile(filePath);
|
|
47
|
+
//console.log("_extractYamlToolDoc from", name, data?.tool);
|
|
48
|
+
if (!found) {
|
|
49
|
+
return { found: false, tspec: {} };
|
|
50
|
+
}
|
|
51
|
+
if (!data?.tool) {
|
|
52
|
+
return { found: false, tspec: {} };
|
|
53
|
+
}
|
|
54
|
+
data.tool.name = name;
|
|
55
|
+
return { found: true, tspec: data.tool };
|
|
56
|
+
}
|
|
57
|
+
function _parseToolDoc(rawTxt, name) {
|
|
58
|
+
try {
|
|
59
|
+
const res = YAML.parse(rawTxt);
|
|
60
|
+
res["name"] = name;
|
|
61
|
+
//console.log("PARSE TOOL DOC", res);
|
|
62
|
+
return res;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
throw new Error(`Error parsing tool ${name}: ${e} \nData:\n${rawTxt}\n`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function _parseAgentVariables(data) {
|
|
69
|
+
const res = { required: new Array(), optional: new Array() };
|
|
70
|
+
if (data?.variables) {
|
|
71
|
+
if (data.variables?.required) {
|
|
72
|
+
res.required = data.variables.required;
|
|
73
|
+
}
|
|
74
|
+
if (data.variables?.optional) {
|
|
75
|
+
res.optional = data.variables.optional;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return res;
|
|
79
|
+
}
|
|
80
|
+
function extractAgentToolDocAndVariables(name, ext, dirPath) {
|
|
81
|
+
const fp = dirPath + "/" + name + "." + ext;
|
|
82
|
+
const { data, found } = readYmlFile(fp);
|
|
83
|
+
const res = { variables: { required: new Array(), optional: new Array() }, toolDoc: "", type: null, category: null };
|
|
84
|
+
// tools
|
|
85
|
+
let tspec;
|
|
86
|
+
if (!found) {
|
|
87
|
+
throw new Error(`extractAgentToolDocAndVariables: file ${fp} not found`);
|
|
88
|
+
}
|
|
89
|
+
if (data?.tool) {
|
|
90
|
+
data.tool.name = name;
|
|
91
|
+
tspec = data.tool;
|
|
92
|
+
res.toolDoc = JSON.stringify(tspec, null, " ");
|
|
93
|
+
}
|
|
94
|
+
// variables
|
|
95
|
+
const { required, optional } = _parseAgentVariables(data);
|
|
96
|
+
res.variables.required = required;
|
|
97
|
+
res.variables.optional = optional;
|
|
98
|
+
// type
|
|
99
|
+
if (data?.type) {
|
|
100
|
+
res.type = data.type;
|
|
101
|
+
}
|
|
102
|
+
// category
|
|
103
|
+
if (data?.category) {
|
|
104
|
+
res.category = data.category;
|
|
105
|
+
}
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
function extractToolDoc(name, ext, dirPath) {
|
|
109
|
+
let spec;
|
|
110
|
+
let found = false;
|
|
111
|
+
let doc = "";
|
|
112
|
+
let docts = null;
|
|
113
|
+
switch (ext) {
|
|
114
|
+
case "py":
|
|
115
|
+
let res = _extractPyToolDoc(dirPath + "/" + name + "." + ext);
|
|
116
|
+
found = res.found;
|
|
117
|
+
doc = res.doc;
|
|
118
|
+
break;
|
|
119
|
+
case "js":
|
|
120
|
+
let res2 = _extractJsToolDoc(dirPath + "/" + name + "." + ext);
|
|
121
|
+
found = res2.found;
|
|
122
|
+
doc = res2.doc;
|
|
123
|
+
break;
|
|
124
|
+
case "yml":
|
|
125
|
+
let res3 = _extractYamlToolDoc(dirPath + "/" + name + "." + ext, name);
|
|
126
|
+
found = res3.found;
|
|
127
|
+
docts = res3.tspec;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
return { found: false, toolDoc: "" };
|
|
131
|
+
//throw new Error(`Unknown tool doc feature type`)
|
|
132
|
+
}
|
|
133
|
+
if (found) {
|
|
134
|
+
let ts;
|
|
135
|
+
if (docts) {
|
|
136
|
+
ts = docts;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
ts = _parseToolDoc(doc, name);
|
|
140
|
+
}
|
|
141
|
+
spec = JSON.stringify(ts, null, " ");
|
|
142
|
+
//console.log("PARSE TOOL", name, spec);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return { found: false, toolDoc: "" };
|
|
146
|
+
}
|
|
147
|
+
return { found: true, toolDoc: spec };
|
|
148
|
+
}
|
|
149
|
+
export { extractToolDoc, extractAgentToolDocAndVariables, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Features } from "@agent-smith/types";
|
|
2
|
+
declare function updateFeaturesCmd(options: Record<string, any>, userFeats?: Features): Promise<any>;
|
|
3
|
+
declare function recreateDbFromConf(): Promise<void>;
|
|
4
|
+
declare function updateConfCmd(args: Array<string>): Promise<any>;
|
|
5
|
+
export { updateConfCmd, updateFeaturesCmd, recreateDbFromConf, };
|