@agent-smith/cli 0.0.70 → 0.0.80
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/aliases.js +12 -6
- package/dist/cmd/clicmds/base.js +13 -6
- package/dist/cmd/clicmds/cmds.js +5 -0
- package/dist/cmd/cmds.js +0 -20
- package/dist/cmd/lib/actions/cmd.d.ts +3 -4
- package/dist/cmd/lib/actions/cmd.js +48 -64
- package/dist/cmd/lib/actions/read.d.ts +2 -3
- package/dist/cmd/lib/actions/read.js +9 -14
- package/dist/cmd/lib/adaptaters/cmd.d.ts +1 -1
- package/dist/cmd/lib/adaptaters/cmd.js +7 -4
- package/dist/cmd/lib/mcp.d.ts +3 -3
- package/dist/cmd/lib/options_parsers.js +1 -1
- package/dist/cmd/lib/tasks/cmd.d.ts +3 -4
- package/dist/cmd/lib/tasks/cmd.js +103 -153
- package/dist/cmd/lib/tasks/conf.js +14 -9
- package/dist/cmd/lib/tasks/read.d.ts +11 -0
- package/dist/cmd/lib/tasks/read.js +93 -0
- package/dist/cmd/lib/tools.js +2 -2
- package/dist/cmd/lib/utils.js +3 -1
- package/dist/cmd/lib/workflows/cmd.js +9 -6
- package/dist/cmd/lib/workflows/read.d.ts +3 -4
- package/dist/cmd/lib/workflows/read.js +37 -15
- package/dist/conf.js +49 -1
- package/dist/const.d.ts +3 -0
- package/dist/const.js +24 -0
- package/dist/db/read.d.ts +4 -3
- package/dist/db/read.js +10 -1
- package/dist/db/schemas.js +9 -0
- package/dist/db/write.d.ts +4 -2
- package/dist/db/write.js +38 -2
- package/dist/index.js +2 -2
- package/dist/interfaces.d.ts +23 -10
- package/dist/main.d.ts +3 -3
- package/dist/main.js +2 -2
- package/dist/state/backends.d.ts +7 -0
- package/dist/state/backends.js +128 -0
- package/dist/state/state.d.ts +2 -1
- package/dist/state/state.js +1 -1
- package/dist/utils/perf.js +1 -1
- package/dist/utils/user_msgs.js +5 -5
- package/package.json +19 -20
- package/dist/agent.d.ts +0 -7
- package/dist/agent.js +0 -27
package/dist/conf.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { readConf } from "./cmd/sys/read_conf.js";
|
|
3
|
-
import { insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
|
|
3
|
+
import { upsertBackends, insertFeaturesPathIfNotExists, insertPluginIfNotExists } from "./db/write.js";
|
|
4
4
|
import { buildPluginsPaths } from "./state/plugins.js";
|
|
5
5
|
import { runtimeError } from "./cmd/lib/user_msgs.js";
|
|
6
|
+
import { localBackends } from "./const.js";
|
|
6
7
|
const confDir = path.join(process.env.HOME, ".config/agent-smith/cli");
|
|
7
8
|
const dbPath = path.join(confDir, "config.db");
|
|
8
9
|
async function processConfPath(confPath) {
|
|
@@ -10,7 +11,54 @@ async function processConfPath(confPath) {
|
|
|
10
11
|
if (!found) {
|
|
11
12
|
runtimeError(`Config file ${confPath} not found`);
|
|
12
13
|
}
|
|
14
|
+
console.log(data);
|
|
13
15
|
const allPaths = new Array();
|
|
16
|
+
const backends = {};
|
|
17
|
+
let defaultBackendName = "";
|
|
18
|
+
if (data?.backends) {
|
|
19
|
+
for (const [name, val] of Object.entries(data.backends)) {
|
|
20
|
+
switch (name) {
|
|
21
|
+
case "local":
|
|
22
|
+
const bs = val;
|
|
23
|
+
bs.forEach(b => {
|
|
24
|
+
if (!["llamacpp", "koboldcpp", "ollama"].includes(b)) {
|
|
25
|
+
throw new Error(`Unknow backend default value: ${b}`);
|
|
26
|
+
}
|
|
27
|
+
const lb = localBackends[b];
|
|
28
|
+
backends[lb.name] = lb;
|
|
29
|
+
});
|
|
30
|
+
break;
|
|
31
|
+
case "default":
|
|
32
|
+
const v1 = val;
|
|
33
|
+
defaultBackendName = v1;
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
const v3 = val;
|
|
37
|
+
let apiKey = undefined;
|
|
38
|
+
if (v3?.apiKey) {
|
|
39
|
+
apiKey = v3.apiKey;
|
|
40
|
+
}
|
|
41
|
+
const ib = {
|
|
42
|
+
name: name,
|
|
43
|
+
type: v3.type,
|
|
44
|
+
url: v3.url,
|
|
45
|
+
isDefault: false,
|
|
46
|
+
};
|
|
47
|
+
if (apiKey) {
|
|
48
|
+
ib.apiKey = apiKey;
|
|
49
|
+
}
|
|
50
|
+
backends[name] = ib;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
console.log("Default backend:", defaultBackendName);
|
|
56
|
+
console.dir(backends, { depth: 4 });
|
|
57
|
+
if (!Object.keys(backends).includes(defaultBackendName)) {
|
|
58
|
+
throw new Error(`Undeclared default backend: ${defaultBackendName}`);
|
|
59
|
+
}
|
|
60
|
+
backends[defaultBackendName].isDefault = true;
|
|
61
|
+
upsertBackends(Object.values(backends));
|
|
14
62
|
if (data?.features) {
|
|
15
63
|
allPaths.push(...data.features);
|
|
16
64
|
const fts = new Array();
|
package/dist/const.d.ts
ADDED
package/dist/const.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const localBackends = {
|
|
2
|
+
llamacpp: {
|
|
3
|
+
name: "llamacpp",
|
|
4
|
+
type: "llamacpp",
|
|
5
|
+
url: "http://localhost:8080",
|
|
6
|
+
apiKey: "",
|
|
7
|
+
isDefault: false,
|
|
8
|
+
},
|
|
9
|
+
koboldcpp: {
|
|
10
|
+
name: "koboldcpp",
|
|
11
|
+
type: "koboldcpp",
|
|
12
|
+
url: "http://localhost:5001",
|
|
13
|
+
apiKey: "",
|
|
14
|
+
isDefault: false,
|
|
15
|
+
},
|
|
16
|
+
ollama: {
|
|
17
|
+
name: "ollama",
|
|
18
|
+
type: "ollama",
|
|
19
|
+
url: "http://localhost:11434",
|
|
20
|
+
apiKey: "",
|
|
21
|
+
isDefault: false,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export { localBackends };
|
package/dist/db/read.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ToolSpec } from "
|
|
2
|
-
import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType } from "../interfaces.js";
|
|
1
|
+
import { ToolSpec } from "@locallm/types";
|
|
2
|
+
import { AliasType, FeatureSpec, FeatureType, DbModelDef, ToolType, InferenceBackend } from "../interfaces.js";
|
|
3
3
|
declare function readFeaturePaths(): Array<string>;
|
|
4
|
+
declare function readBackends(): Record<string, InferenceBackend>;
|
|
4
5
|
declare function readPlugins(): Array<Record<string, string>>;
|
|
5
6
|
declare function readFeaturesType(type: FeatureType): Record<string, FeatureSpec>;
|
|
6
7
|
declare function readFeatures(): Record<FeatureType, Record<string, FeatureSpec>>;
|
|
@@ -31,4 +32,4 @@ declare function readModel(shortname: string): {
|
|
|
31
32
|
found: boolean;
|
|
32
33
|
modelData: Record<string, any>;
|
|
33
34
|
};
|
|
34
|
-
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, };
|
|
35
|
+
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, readBackends, };
|
package/dist/db/read.js
CHANGED
|
@@ -8,6 +8,15 @@ function readFeaturePaths() {
|
|
|
8
8
|
});
|
|
9
9
|
return f;
|
|
10
10
|
}
|
|
11
|
+
function readBackends() {
|
|
12
|
+
const stmt = db.prepare("SELECT name, type, url, apiKey, isdefault FROM backend");
|
|
13
|
+
const data = stmt.all();
|
|
14
|
+
const bks = {};
|
|
15
|
+
data.forEach((row) => {
|
|
16
|
+
bks[row.name] = { name: row.name, type: row.type, url: row.url, apiKey: row.apiKey, isDefault: row.isdefault === 1 };
|
|
17
|
+
});
|
|
18
|
+
return bks;
|
|
19
|
+
}
|
|
11
20
|
function readPlugins() {
|
|
12
21
|
const stmt = db.prepare("SELECT name, path FROM plugin");
|
|
13
22
|
const data = stmt.all();
|
|
@@ -135,4 +144,4 @@ function readModel(shortname) {
|
|
|
135
144
|
}
|
|
136
145
|
return { found: false, modelData: {} };
|
|
137
146
|
}
|
|
138
|
-
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, };
|
|
147
|
+
export { readFeatures, readFeaturePaths, readFeature, readPlugins, readAliases, readFilePath, readFilePaths, readTool, readModels, readModelfiles, readModel, readFeaturesType, readBackends, };
|
package/dist/db/schemas.js
CHANGED
|
@@ -71,6 +71,14 @@ const model = `CREATE TABLE IF NOT EXISTS model (
|
|
|
71
71
|
shortname TEXT UNIQUE NOT NULL,
|
|
72
72
|
data TEXT NOT NULL
|
|
73
73
|
);`;
|
|
74
|
+
const backend = `CREATE TABLE IF NOT EXISTS backend (
|
|
75
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
76
|
+
name TEXT UNIQUE NOT NULL,
|
|
77
|
+
type TEXT NOT NULL CHECK ( type IN ('llamacpp', 'koboldcpp', 'ollama', 'openai') ),
|
|
78
|
+
url TEXT NOT NULL,
|
|
79
|
+
isdefault INTEGER NOT NULL,
|
|
80
|
+
apiKey TEXT
|
|
81
|
+
);`;
|
|
74
82
|
const schemas = [
|
|
75
83
|
filepath,
|
|
76
84
|
featurespath,
|
|
@@ -84,5 +92,6 @@ const schemas = [
|
|
|
84
92
|
model,
|
|
85
93
|
modelfile,
|
|
86
94
|
adaptater,
|
|
95
|
+
backend,
|
|
87
96
|
];
|
|
88
97
|
export { schemas };
|
package/dist/db/write.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Features, DbModelDef } from "../interfaces.js";
|
|
1
|
+
import { Features, DbModelDef, InferenceBackend } from "../interfaces.js";
|
|
2
2
|
declare function updatePromptfilePath(pf: string): void;
|
|
3
3
|
declare function updateDataDirPath(dd: string): void;
|
|
4
|
+
declare function setDefaultBackend(name: string): void;
|
|
5
|
+
declare function upsertBackends(bdata: Array<InferenceBackend>): boolean;
|
|
4
6
|
declare function insertFeaturesPathIfNotExists(path: string): boolean;
|
|
5
7
|
declare function insertPluginIfNotExists(n: string, p: string): boolean;
|
|
6
8
|
declare function cleanupFeaturePaths(paths: Array<string>): Array<string>;
|
|
@@ -8,4 +10,4 @@ declare function updateAliases(feats: Features): void;
|
|
|
8
10
|
declare function updateModels(models: Array<DbModelDef>): void;
|
|
9
11
|
declare function updateFeatures(feats: Features): void;
|
|
10
12
|
declare function upsertFilePath(name: string, newPath: string): boolean;
|
|
11
|
-
export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
|
|
13
|
+
export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
|
package/dist/db/write.js
CHANGED
|
@@ -13,6 +13,42 @@ function updateDataDirPath(dd) {
|
|
|
13
13
|
const stmt = db.prepare("INSERT INTO filepath (name, path) VALUES (?, ?)");
|
|
14
14
|
stmt.run("datadir", dd);
|
|
15
15
|
}
|
|
16
|
+
function setDefaultBackend(name) {
|
|
17
|
+
const updateStmt = db.prepare("UPDATE backend SET isdefault = 0 WHERE isdefault = 1");
|
|
18
|
+
updateStmt.run();
|
|
19
|
+
const nupdStmt = db.prepare("UPDATE backend SET isdefault = 1 WHERE name = ?");
|
|
20
|
+
nupdStmt.run(name);
|
|
21
|
+
}
|
|
22
|
+
function upsertBackends(bdata) {
|
|
23
|
+
let hasUpdates = false;
|
|
24
|
+
const existingStmt = db.prepare("SELECT name FROM backend");
|
|
25
|
+
const existingBackends = existingStmt.all();
|
|
26
|
+
const existingNames = new Set(existingBackends.map(b => b.name));
|
|
27
|
+
const newNames = new Set(bdata.map(b => b.name));
|
|
28
|
+
const toDelete = Array.from(existingNames).filter(name => !newNames.has(name));
|
|
29
|
+
if (toDelete.length > 0) {
|
|
30
|
+
const deleteStmt = db.prepare("DELETE FROM backend WHERE name = ?");
|
|
31
|
+
for (const name of toDelete) {
|
|
32
|
+
deleteStmt.run(name);
|
|
33
|
+
}
|
|
34
|
+
hasUpdates = true;
|
|
35
|
+
}
|
|
36
|
+
for (const backend of bdata) {
|
|
37
|
+
const stmt1 = db.prepare("SELECT * FROM backend WHERE name = ?");
|
|
38
|
+
const result = stmt1.get(backend.name);
|
|
39
|
+
if (result?.id) {
|
|
40
|
+
const updateStmt = db.prepare("UPDATE backend SET type = ?, url = ?, apiKey = ?, isdefault = ? WHERE name = ?");
|
|
41
|
+
updateStmt.run(backend.type, backend.url, backend?.apiKey ?? "NULL", backend.isDefault ? 1 : 0, backend.name);
|
|
42
|
+
hasUpdates = true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const stmt = db.prepare("INSERT INTO backend (name,type,url,apiKey,isdefault) VALUES (?,?,?,?,?)");
|
|
46
|
+
stmt.run(backend.name, backend.type, backend.url, backend?.apiKey ?? "NULL", backend.isDefault ? 1 : 0);
|
|
47
|
+
hasUpdates = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return hasUpdates;
|
|
51
|
+
}
|
|
16
52
|
function insertFeaturesPathIfNotExists(path) {
|
|
17
53
|
const stmt1 = db.prepare("SELECT * FROM featurespath WHERE path = ?");
|
|
18
54
|
const result = stmt1.get(path);
|
|
@@ -157,7 +193,7 @@ function updateFeatures(feats) {
|
|
|
157
193
|
if (toolDoc.length > 0) {
|
|
158
194
|
upsertTool(feat.name, "task", toolDoc);
|
|
159
195
|
}
|
|
160
|
-
if (variables.required.length > 0 || variables.optional.length > 0) {
|
|
196
|
+
if (Object.keys(variables.required).length > 0 || Object.keys(variables.optional).length > 0) {
|
|
161
197
|
updateVariables(feat.name, JSON.stringify(variables, null, " "));
|
|
162
198
|
}
|
|
163
199
|
});
|
|
@@ -194,4 +230,4 @@ function upsertFilePath(name, newPath) {
|
|
|
194
230
|
return true;
|
|
195
231
|
}
|
|
196
232
|
}
|
|
197
|
-
export { updatePromptfilePath, updateDataDirPath, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
|
|
233
|
+
export { updatePromptfilePath, updateDataDirPath, upsertBackends, setDefaultBackend, insertFeaturesPathIfNotExists, insertPluginIfNotExists, updateFeatures, updateAliases, cleanupFeaturePaths, updateModels, upsertFilePath, };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { argv } from 'process';
|
|
3
|
-
import { initAgent } from './agent.js';
|
|
4
3
|
import { query } from "./cli.js";
|
|
5
4
|
import { buildCmds, parseCmd } from './cmd/cmds.js';
|
|
6
5
|
import { formatMode, initState, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
|
|
7
6
|
import { updateConfCmd } from './cmd/clicmds/update.js';
|
|
7
|
+
import { initBackends } from './state/backends.js';
|
|
8
8
|
async function main() {
|
|
9
9
|
const nargs = argv.length;
|
|
10
10
|
if (nargs == 2) {
|
|
@@ -17,7 +17,7 @@ async function main() {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
await initState();
|
|
20
|
-
await
|
|
20
|
+
await initBackends();
|
|
21
21
|
const program = await buildCmds();
|
|
22
22
|
program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
23
23
|
const options = actionCommand.opts();
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InferenceParams } from "@locallm/types";
|
|
3
|
-
interface FeatureVariables {
|
|
4
|
-
required: Array<string>;
|
|
5
|
-
optional: Array<string>;
|
|
6
|
-
}
|
|
1
|
+
import { TaskDef, ModelSpec, TaskVariables } from "@agent-smith/task";
|
|
2
|
+
import { InferenceParams, LmProviderType } from "@locallm/types";
|
|
7
3
|
interface FeatureSpec {
|
|
8
4
|
id?: number;
|
|
9
5
|
name: string;
|
|
10
6
|
path: string;
|
|
11
7
|
ext: FeatureExtension;
|
|
12
|
-
variables?:
|
|
8
|
+
variables?: TaskVariables;
|
|
13
9
|
}
|
|
14
10
|
interface Features {
|
|
15
11
|
task: Array<{
|
|
@@ -43,11 +39,24 @@ interface Features {
|
|
|
43
39
|
ext: ModelFileExtension;
|
|
44
40
|
}>;
|
|
45
41
|
}
|
|
42
|
+
interface ConfInferenceBackend {
|
|
43
|
+
type: LmProviderType;
|
|
44
|
+
url: string;
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
}
|
|
47
|
+
interface InferenceBackend extends ConfInferenceBackend {
|
|
48
|
+
name: string;
|
|
49
|
+
isDefault?: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface BackendEntries {
|
|
52
|
+
[key: string]: ConfInferenceBackend | string | Array<"llamacpp" | "koboldcpp" | "ollama">;
|
|
53
|
+
}
|
|
46
54
|
interface ConfigFile {
|
|
47
55
|
promptfile?: string;
|
|
48
56
|
datadir?: string;
|
|
49
57
|
features?: Array<string>;
|
|
50
58
|
plugins?: Array<string>;
|
|
59
|
+
backends?: BackendEntries;
|
|
51
60
|
}
|
|
52
61
|
interface Settings {
|
|
53
62
|
name: string;
|
|
@@ -75,9 +84,8 @@ interface ModelPack {
|
|
|
75
84
|
default: string;
|
|
76
85
|
recommended?: Array<string>;
|
|
77
86
|
}
|
|
78
|
-
interface LmTaskFileSpec extends
|
|
87
|
+
interface LmTaskFileSpec extends TaskDef {
|
|
79
88
|
ctx: number;
|
|
80
|
-
model?: ModelSpec;
|
|
81
89
|
modelpack?: ModelPack;
|
|
82
90
|
mcp?: McpServerSpec;
|
|
83
91
|
}
|
|
@@ -93,6 +101,10 @@ interface FinalLmTaskConfig {
|
|
|
93
101
|
model?: ModelSpec;
|
|
94
102
|
modelname?: string;
|
|
95
103
|
}
|
|
104
|
+
interface WorkflowStep {
|
|
105
|
+
type: string;
|
|
106
|
+
run: FeatureExecutor;
|
|
107
|
+
}
|
|
96
108
|
interface McpServerSpec {
|
|
97
109
|
command: string;
|
|
98
110
|
arguments: string[];
|
|
@@ -125,4 +137,5 @@ type CmdExtension = "js";
|
|
|
125
137
|
type ModelFileExtension = "yml";
|
|
126
138
|
type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
|
|
127
139
|
type AliasType = "task" | "action" | "workflow";
|
|
128
|
-
|
|
140
|
+
type FeatureExecutor<I = any, O = any> = (params: I, options: Record<string, any>) => Promise<O>;
|
|
141
|
+
export { InputMode, VerbosityMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, ModelFileExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, DbModelDef, ModelSpec, ModelfileSpec, ModelPack, LmTaskFileSpec, LmTaskConfig, FinalLmTaskConfig, McpServerSpec, McpServerTool, InferenceBackend, ConfInferenceBackend, FeatureExecutor, WorkflowStep, };
|
package/dist/main.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
|
|
|
3
3
|
import { executeAction } from "./cmd/lib/actions/cmd.js";
|
|
4
4
|
import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
|
|
5
5
|
import { writeToClipboard } from "./cmd/sys/clipboard.js";
|
|
6
|
-
import { initAgent } from "./agent.js";
|
|
7
6
|
import { initState, pluginDataDir } from "./state/state.js";
|
|
8
7
|
import { usePerfTimer } from "./utils/perf.js";
|
|
9
8
|
import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
|
|
10
|
-
import { LmTaskConf } from "@agent-smith/lmtask/dist/interfaces.js";
|
|
11
9
|
import { extractToolDoc } from "./cmd/lib/tools.js";
|
|
12
10
|
import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
|
|
13
11
|
import { extractBetweenTags, splitThinking } from "./utils/text.js";
|
|
14
12
|
import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
|
|
15
13
|
import { McpClient } from "./cmd/lib/mcp.js";
|
|
16
|
-
|
|
14
|
+
import { readTask } from "./cmd/lib/tasks/read.js";
|
|
15
|
+
import { FeatureType } from "./interfaces.js";
|
|
16
|
+
export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, FeatureType, };
|
package/dist/main.js
CHANGED
|
@@ -3,7 +3,6 @@ import { executeTask } from "./cmd/lib/tasks/cmd.js";
|
|
|
3
3
|
import { executeAction } from "./cmd/lib/actions/cmd.js";
|
|
4
4
|
import { executeWorkflow } from "./cmd/lib/workflows/cmd.js";
|
|
5
5
|
import { writeToClipboard } from "./cmd/sys/clipboard.js";
|
|
6
|
-
import { initAgent } from "./agent.js";
|
|
7
6
|
import { initState, pluginDataDir } from "./state/state.js";
|
|
8
7
|
import { usePerfTimer } from "./utils/perf.js";
|
|
9
8
|
import { parseCommandArgs } from "./cmd/lib/options_parsers.js";
|
|
@@ -12,4 +11,5 @@ import { openTaskSpec } from "./cmd/lib/tasks/utils.js";
|
|
|
12
11
|
import { extractBetweenTags, splitThinking } from "./utils/text.js";
|
|
13
12
|
import { displayOptions, ioOptions, inferenceOptions, allOptions } from "./cmd/options.js";
|
|
14
13
|
import { McpClient } from "./cmd/lib/mcp.js";
|
|
15
|
-
|
|
14
|
+
import { readTask } from "./cmd/lib/tasks/read.js";
|
|
15
|
+
export { execute, run, executeTask, executeAction, executeWorkflow, writeToClipboard, initState, pluginDataDir, usePerfTimer, parseCommandArgs, extractToolDoc, openTaskSpec, extractBetweenTags, splitThinking, displayOptions, ioOptions, inferenceOptions, allOptions, McpClient, readTask, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Lm } from "@locallm/api";
|
|
2
|
+
declare const backend: import("@vue/reactivity").Ref<Lm | undefined, Lm | undefined>;
|
|
3
|
+
declare const backends: Record<string, Lm>;
|
|
4
|
+
declare function initBackends(isVerbose?: boolean): Promise<void>;
|
|
5
|
+
declare function setBackend(name: string, isVerbose?: boolean): Promise<void>;
|
|
6
|
+
declare function listBackends(): Promise<void>;
|
|
7
|
+
export { backend, backends, initBackends, listBackends, setBackend };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Lm } from "@locallm/api";
|
|
2
|
+
import { reactive, 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 = reactive({});
|
|
9
|
+
const isBackendUp = ref(false);
|
|
10
|
+
async function initBackends(isVerbose = false) {
|
|
11
|
+
const rmb = readBackends();
|
|
12
|
+
let defaultBackendName = null;
|
|
13
|
+
for (const bk of Object.values(rmb)) {
|
|
14
|
+
const lm = new Lm({
|
|
15
|
+
providerType: bk.type,
|
|
16
|
+
serverUrl: bk.url,
|
|
17
|
+
});
|
|
18
|
+
lm.name = bk.name;
|
|
19
|
+
if (bk?.apiKey) {
|
|
20
|
+
lm.apiKey = bk.apiKey;
|
|
21
|
+
}
|
|
22
|
+
;
|
|
23
|
+
backends[bk.name] = lm;
|
|
24
|
+
if (bk.isDefault) {
|
|
25
|
+
defaultBackendName = bk.name;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (defaultBackendName !== null) {
|
|
29
|
+
backend.value = backends[defaultBackendName];
|
|
30
|
+
isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
31
|
+
if (isBackendUp.value && backend.value.providerType == "ollama") {
|
|
32
|
+
await backend.value.modelsInfo();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function setBackend(name, isVerbose = false) {
|
|
37
|
+
if (!(Object.keys(backends).includes(name))) {
|
|
38
|
+
runtimeDataError(`Backend ${name} not found. Available backends: ${Object.keys(backends)}`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
backend.value = backends[name];
|
|
42
|
+
setDefaultBackend(name);
|
|
43
|
+
console.log("Default backend set to", name);
|
|
44
|
+
isBackendUp.value = await probeBackend(backend.value, isVerbose);
|
|
45
|
+
}
|
|
46
|
+
async function listBackends() {
|
|
47
|
+
for (const [name, lm] of Object.entries(backends)) {
|
|
48
|
+
const bcn = name == backend.value?.name ? colors.bold(name) : name;
|
|
49
|
+
const buf = new Array("-", bcn, colors.dim("(" + lm.providerType + ") " + lm.serverUrl));
|
|
50
|
+
console.log(buf.join(" "));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const probeBackend = async (lm, isVerbose) => {
|
|
54
|
+
let isUp = false;
|
|
55
|
+
switch (lm.providerType) {
|
|
56
|
+
case "llamacpp":
|
|
57
|
+
try {
|
|
58
|
+
const info = await lm.info();
|
|
59
|
+
if (isVerbose) {
|
|
60
|
+
console.log(`Provider ${lm.name} up`, info);
|
|
61
|
+
}
|
|
62
|
+
isUp = true;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (isVerbose) {
|
|
66
|
+
console.log(`Provider ${lm.name} down`, e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case "koboldcpp":
|
|
71
|
+
try {
|
|
72
|
+
const info = await lm.info();
|
|
73
|
+
if (lm.model.name.length > 0) {
|
|
74
|
+
if (isVerbose) {
|
|
75
|
+
console.log(`Provider ${lm.name} up`, info);
|
|
76
|
+
}
|
|
77
|
+
isUp = true;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (isVerbose) {
|
|
81
|
+
console.log(`Provider ${lm.name} down`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
if (isVerbose) {
|
|
87
|
+
console.log(`Provider ${lm.name} down`, e);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case "ollama":
|
|
92
|
+
try {
|
|
93
|
+
await lm.modelsInfo();
|
|
94
|
+
if (isVerbose) {
|
|
95
|
+
console.log(`Provider ${lm.name} up`);
|
|
96
|
+
}
|
|
97
|
+
isUp = true;
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
if (isVerbose) {
|
|
101
|
+
console.log(`Provider ${lm.name} down`, e);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
case "openai":
|
|
106
|
+
try {
|
|
107
|
+
await lm.modelsInfo();
|
|
108
|
+
if (isVerbose) {
|
|
109
|
+
console.log(`Provider ${lm.name} up`);
|
|
110
|
+
}
|
|
111
|
+
isUp = true;
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
if (isVerbose) {
|
|
115
|
+
console.log(`Provider ${lm.name} down`, e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
case "browser":
|
|
120
|
+
await lm.modelsInfo();
|
|
121
|
+
isUp = true;
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
throw new Error("Unknown provider type");
|
|
125
|
+
}
|
|
126
|
+
return isUp;
|
|
127
|
+
};
|
|
128
|
+
export { backend, backends, initBackends, listBackends, setBackend };
|
package/dist/state/state.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
|
|
|
8
8
|
declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
9
9
|
declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
|
|
10
10
|
declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
|
|
11
|
+
declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
11
12
|
declare const lastCmd: {
|
|
12
13
|
name: string;
|
|
13
14
|
args: Array<string>;
|
|
@@ -15,4 +16,4 @@ declare const lastCmd: {
|
|
|
15
16
|
declare function initFilepaths(): void;
|
|
16
17
|
declare function initState(): Promise<void>;
|
|
17
18
|
declare function pluginDataDir(pluginName: string): string;
|
|
18
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
|
|
19
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, pyShell, };
|
package/dist/state/state.js
CHANGED
|
@@ -48,4 +48,4 @@ function pluginDataDir(pluginName) {
|
|
|
48
48
|
createDirectoryIfNotExists(pluginDatapath);
|
|
49
49
|
return pluginDatapath;
|
|
50
50
|
}
|
|
51
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, pluginDataDir, initState, initFilepaths, pyShell, };
|
|
51
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, pyShell, };
|
package/dist/utils/perf.js
CHANGED
|
@@ -26,7 +26,7 @@ const usePerfTimer = (startTimer = true) => {
|
|
|
26
26
|
return `${ms.toFixed(2)} milliseconds`;
|
|
27
27
|
if (seconds < 60)
|
|
28
28
|
return `${seconds.toFixed(1)} seconds`;
|
|
29
|
-
return `${minutes.toFixed(
|
|
29
|
+
return `${minutes.toFixed()} minutes ${(seconds % 60).toFixed()} seconds`;
|
|
30
30
|
};
|
|
31
31
|
return {
|
|
32
32
|
start,
|
package/dist/utils/user_msgs.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { exit } from "process";
|
|
2
|
-
import
|
|
2
|
+
import colors from "ansi-colors";
|
|
3
3
|
function runtimeError(...msg) {
|
|
4
|
-
console.warn("💥",
|
|
4
|
+
console.warn("💥", colors.dim("Runtime error:"), ...msg);
|
|
5
5
|
exit(1);
|
|
6
6
|
}
|
|
7
7
|
function runtimeWarning(...msg) {
|
|
8
|
-
console.warn("⚠️",
|
|
8
|
+
console.warn("⚠️", colors.dim("Runtime warning:"), ...msg);
|
|
9
9
|
}
|
|
10
10
|
function runtimeDataError(...msg) {
|
|
11
|
-
console.warn("❌",
|
|
11
|
+
console.warn("❌", colors.dim("Runtime data error:"), ...msg);
|
|
12
12
|
exit(1);
|
|
13
13
|
}
|
|
14
14
|
function runtimeInfo(...msg) {
|
|
15
|
-
console.log("📫",
|
|
15
|
+
console.log("📫", colors.dim("Info:"), ...msg);
|
|
16
16
|
}
|
|
17
17
|
export { runtimeError, runtimeWarning, runtimeDataError, runtimeInfo, };
|
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.80",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -10,39 +10,38 @@
|
|
|
10
10
|
"watch": "tsc --noCheck -p . -w"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/
|
|
14
|
-
"@agent-smith/
|
|
15
|
-
"@agent-smith/lmtask": "^0.0.46",
|
|
13
|
+
"@agent-smith/agent": "^0.0.4",
|
|
14
|
+
"@agent-smith/task": "^0.0.4",
|
|
16
15
|
"@agent-smith/tfm": "^0.1.2",
|
|
17
|
-
"@inquirer/prompts": "^7.
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
16
|
+
"@inquirer/prompts": "^7.8.6",
|
|
17
|
+
"@intrinsicai/gbnfgen": "0.12.0",
|
|
18
|
+
"@locallm/api": "0.4.2",
|
|
19
|
+
"@modelcontextprotocol/sdk": "^1.18.2",
|
|
20
|
+
"@vue/reactivity": "^3.5.22",
|
|
21
21
|
"ansi-colors": "^4.1.3",
|
|
22
|
-
"better-sqlite3": "^
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"commander": "^14.0.0",
|
|
22
|
+
"better-sqlite3": "^12.4.1",
|
|
23
|
+
"clipboardy": "^5.0.0",
|
|
24
|
+
"commander": "^14.0.1",
|
|
26
25
|
"marked-terminal": "^7.3.0",
|
|
27
|
-
"modprompt": "^0.
|
|
28
|
-
"ora": "^
|
|
26
|
+
"modprompt": "^0.12.0",
|
|
27
|
+
"ora": "^9.0.0",
|
|
29
28
|
"python-shell": "^5.0.0",
|
|
30
|
-
"yaml": "^2.8.
|
|
29
|
+
"yaml": "^2.8.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@agent-smith/tmem-jobs": "^0.0.4",
|
|
34
33
|
"@commander-js/extra-typings": "^14.0.0",
|
|
35
|
-
"@locallm/types": "^0.
|
|
34
|
+
"@locallm/types": "^0.4.2",
|
|
36
35
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
36
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
38
37
|
"@types/better-sqlite3": "^7.6.13",
|
|
39
38
|
"@types/marked-terminal": "^6.1.1",
|
|
40
|
-
"@types/node": "^24.0
|
|
39
|
+
"@types/node": "^24.6.0",
|
|
41
40
|
"restmix": "^0.5.0",
|
|
42
|
-
"rollup": "^4.
|
|
41
|
+
"rollup": "^4.52.3",
|
|
43
42
|
"ts-node": "^10.9.2",
|
|
44
43
|
"tslib": "2.8.1",
|
|
45
|
-
"typescript": "^5.
|
|
44
|
+
"typescript": "^5.9.2"
|
|
46
45
|
},
|
|
47
46
|
"type": "module",
|
|
48
47
|
"preferGlobal": true,
|
package/dist/agent.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { LmTaskBuilder } from "@agent-smith/lmtask";
|
|
2
|
-
import { marked } from 'marked';
|
|
3
|
-
import { FeatureType } from "./interfaces.js";
|
|
4
|
-
declare let brain: import("@agent-smith/brain").AgentBrain<Record<string, any>>;
|
|
5
|
-
declare const taskBuilder: LmTaskBuilder<FeatureType, Record<string, any>>;
|
|
6
|
-
declare function initAgent(): Promise<boolean>;
|
|
7
|
-
export { brain, initAgent, marked, taskBuilder };
|