@agent-smith/cli 0.0.64 → 0.0.66
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/cmds.d.ts +2 -1
- package/dist/cmd/cmds.js +2 -5
- package/dist/cmd/lib/tasks/cmd.d.ts +2 -1
- package/dist/cmd/lib/tasks/cmd.js +42 -8
- package/dist/cmd/lib/tasks/mcp.d.ts +13 -0
- package/dist/cmd/lib/tasks/mcp.js +57 -0
- package/dist/db/db.js +1 -1
- package/dist/interfaces.d.ts +19 -1
- package/package.json +5 -5
package/dist/cmd/cmds.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
declare const program: Command;
|
|
2
3
|
declare function chat(program: Command): Promise<void>;
|
|
3
4
|
declare function buildCmds(): Promise<Command>;
|
|
4
5
|
declare function parseCmd(program: Command): Promise<void>;
|
|
5
|
-
export { buildCmds, chat, parseCmd, };
|
|
6
|
+
export { program, buildCmds, chat, parseCmd, };
|
package/dist/cmd/cmds.js
CHANGED
|
@@ -9,6 +9,7 @@ import { isChatMode, runMode } from "../state/state.js";
|
|
|
9
9
|
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
10
10
|
import { initBaseCommands } from "./clicmds/base.js";
|
|
11
11
|
import { initUserCmds } from "./clicmds/cmds.js";
|
|
12
|
+
const program = new Command();
|
|
12
13
|
async function chat(program) {
|
|
13
14
|
const data = { message: '>', default: "" };
|
|
14
15
|
const prompt = await input(data);
|
|
@@ -26,7 +27,6 @@ async function chat(program) {
|
|
|
26
27
|
await chat(program);
|
|
27
28
|
}
|
|
28
29
|
async function buildCmds() {
|
|
29
|
-
const program = new Command();
|
|
30
30
|
initBaseCommands(program);
|
|
31
31
|
const aliases = readAliases();
|
|
32
32
|
const feats = readFeatures();
|
|
@@ -39,8 +39,5 @@ async function buildCmds() {
|
|
|
39
39
|
}
|
|
40
40
|
async function parseCmd(program) {
|
|
41
41
|
await program.parseAsync();
|
|
42
|
-
if (isChatMode.value) {
|
|
43
|
-
await chat(program);
|
|
44
|
-
}
|
|
45
42
|
}
|
|
46
|
-
export { buildCmds, chat, parseCmd, };
|
|
43
|
+
export { program, buildCmds, chat, parseCmd, };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LmTaskOutput } from "@agent-smith/lmtask";
|
|
2
|
-
|
|
2
|
+
import { LmExpert } from "@agent-smith/brain";
|
|
3
|
+
declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean, expert?: LmExpert): Promise<LmTaskOutput>;
|
|
3
4
|
declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<LmTaskOutput>;
|
|
4
5
|
export { executeTask, executeTaskCmd };
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
1
2
|
import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
|
|
2
3
|
import color from "ansi-colors";
|
|
3
4
|
import ora from 'ora';
|
|
4
5
|
import { brain, initAgent, taskBuilder } from "../../../agent.js";
|
|
6
|
+
import { query } from "../../../cli.js";
|
|
5
7
|
import { readClipboard } from "../../../cmd/sys/clipboard.js";
|
|
6
8
|
import { readTool } from "../../../db/read.js";
|
|
7
9
|
import { usePerfTimer } from "../../../main.js";
|
|
8
|
-
import { isChatMode } from "../../../state/state.js";
|
|
10
|
+
import { isChatMode, runMode } from "../../../state/state.js";
|
|
11
|
+
import { program } from "../../cmds.js";
|
|
9
12
|
import { executeAction } from "../actions/cmd.js";
|
|
10
13
|
import { parseCommandArgs, parseTaskConfigOptions } from "../options_parsers.js";
|
|
11
14
|
import { runtimeDataError } from "../user_msgs.js";
|
|
12
15
|
import { formatStats, readPromptFile } from "../utils.js";
|
|
13
16
|
import { executeWorkflow } from "../workflows/cmd.js";
|
|
14
17
|
import { configureTaskModel, mergeInferParams } from "./conf.js";
|
|
18
|
+
import { McpServer } from "./mcp.js";
|
|
15
19
|
import { openTaskSpec } from "./utils.js";
|
|
16
|
-
async function executeTask(name, payload, options, quiet
|
|
20
|
+
async function executeTask(name, payload, options, quiet, expert) {
|
|
17
21
|
await initAgent();
|
|
18
22
|
if (options.debug) {
|
|
19
23
|
console.log("Payload:", payload);
|
|
@@ -41,8 +45,21 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
41
45
|
vars[k] = options[k];
|
|
42
46
|
}
|
|
43
47
|
});
|
|
44
|
-
|
|
48
|
+
const mcpServers = new Array();
|
|
49
|
+
if (taskFileSpec?.mcp) {
|
|
45
50
|
taskSpec.tools = [];
|
|
51
|
+
for (const tool of Object.values(taskFileSpec.mcp)) {
|
|
52
|
+
const mcp = new McpServer(tool.command, tool.arguments, tool?.tools ?? null);
|
|
53
|
+
mcpServers.push(mcp);
|
|
54
|
+
await mcp.start();
|
|
55
|
+
const tools = await mcp.extractTools();
|
|
56
|
+
tools.forEach(t => taskSpec.tools?.push(t));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (taskSpec.toolsList) {
|
|
60
|
+
if (!taskSpec?.tools) {
|
|
61
|
+
taskSpec.tools = [];
|
|
62
|
+
}
|
|
46
63
|
for (const toolName of taskSpec.toolsList) {
|
|
47
64
|
const { found, tool, type } = readTool(toolName);
|
|
48
65
|
if (!found) {
|
|
@@ -80,7 +97,7 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
80
97
|
if (options.debug) {
|
|
81
98
|
console.log("Task model:", model);
|
|
82
99
|
}
|
|
83
|
-
const ex = brain.getOrCreateExpertForModel(model.name, model.template);
|
|
100
|
+
const ex = expert ?? brain.getOrCreateExpertForModel(model.name, model.template);
|
|
84
101
|
if (!ex) {
|
|
85
102
|
throw new Error("No expert found for model " + model.name);
|
|
86
103
|
}
|
|
@@ -117,7 +134,6 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
117
134
|
if (i == 0) {
|
|
118
135
|
perfTimer.start();
|
|
119
136
|
}
|
|
120
|
-
++i;
|
|
121
137
|
spinner.text = formatTokenCount(i);
|
|
122
138
|
if (!options?.verbose) {
|
|
123
139
|
if (hasThink) {
|
|
@@ -136,6 +152,13 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
}
|
|
155
|
+
else {
|
|
156
|
+
if (t == ex.template.tags.think?.end) {
|
|
157
|
+
let msg = color.dim("Thinking:") + ` ${i} ${color.dim("tokens")}`;
|
|
158
|
+
msg = msg + " " + color.dim(perfTimer.time());
|
|
159
|
+
console.log(msg);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
139
162
|
if (hasTools) {
|
|
140
163
|
if (t == ex.template.tags.toolCall?.start) {
|
|
141
164
|
continueWrite = false;
|
|
@@ -188,11 +211,22 @@ async function executeTask(name, payload, options, quiet = false) {
|
|
|
188
211
|
catch (err) {
|
|
189
212
|
throw new Error(`executing task: ${name} (${err})`);
|
|
190
213
|
}
|
|
214
|
+
mcpServers.forEach(async (s) => await s.stop());
|
|
191
215
|
if (isChatMode.value) {
|
|
192
|
-
|
|
193
|
-
|
|
216
|
+
const data = { message: '>', default: "" };
|
|
217
|
+
const prompt = await input(data);
|
|
218
|
+
if (prompt == "/q") {
|
|
219
|
+
isChatMode.value = false;
|
|
220
|
+
if (runMode.value == "cmd") {
|
|
221
|
+
process.exit(0);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
await query(program);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
await executeTask(name, { ...vars, prompt: prompt }, options, quiet, ex);
|
|
194
229
|
}
|
|
195
|
-
brain.ex.template.pushToHistory({ user: payload.prompt, assistant: out.answer.text });
|
|
196
230
|
}
|
|
197
231
|
if (options?.debug === true || options?.verbose === true) {
|
|
198
232
|
console.log("\n", formatStats(out.answer.stats));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { LmTaskToolSpec } from "@agent-smith/lmtask/dist/interfaces.js";
|
|
4
|
+
declare class McpServer {
|
|
5
|
+
transport: StdioClientTransport;
|
|
6
|
+
client: Client;
|
|
7
|
+
authorizedTools: Array<string> | null;
|
|
8
|
+
constructor(command: string, args: Array<string>, authorizedTools?: string[]);
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
extractTools(): Promise<Array<LmTaskToolSpec>>;
|
|
12
|
+
}
|
|
13
|
+
export { McpServer, };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
class McpServer {
|
|
4
|
+
transport;
|
|
5
|
+
client;
|
|
6
|
+
authorizedTools = null;
|
|
7
|
+
constructor(command, args, authorizedTools = new Array) {
|
|
8
|
+
this.transport = new StdioClientTransport({
|
|
9
|
+
command: command,
|
|
10
|
+
args: args
|
|
11
|
+
});
|
|
12
|
+
this.client = new Client({ name: "AgentSmith", version: "1.0.0" });
|
|
13
|
+
if (authorizedTools) {
|
|
14
|
+
this.authorizedTools = authorizedTools;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async start() {
|
|
18
|
+
await this.client.connect(this.transport);
|
|
19
|
+
}
|
|
20
|
+
async stop() {
|
|
21
|
+
await this.client.close();
|
|
22
|
+
}
|
|
23
|
+
async extractTools() {
|
|
24
|
+
const toolSpecs = new Array();
|
|
25
|
+
const serverToolsList = await this.client.listTools();
|
|
26
|
+
for (const tool of serverToolsList.tools) {
|
|
27
|
+
if (this.authorizedTools) {
|
|
28
|
+
if (!this.authorizedTools.includes(tool.name)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const args = {};
|
|
33
|
+
if (tool.inputSchema.properties) {
|
|
34
|
+
for (const [k, v] of Object.entries(tool.inputSchema.properties)) {
|
|
35
|
+
const vv = v;
|
|
36
|
+
args[k] = { description: vv.description + " (" + vv.type + ")" };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const exec = async (args) => {
|
|
40
|
+
const res = await this.client.callTool({
|
|
41
|
+
name: tool.name,
|
|
42
|
+
arguments: args,
|
|
43
|
+
});
|
|
44
|
+
return res;
|
|
45
|
+
};
|
|
46
|
+
const t = {
|
|
47
|
+
name: tool.name,
|
|
48
|
+
description: tool.description ?? "",
|
|
49
|
+
arguments: args,
|
|
50
|
+
execute: exec
|
|
51
|
+
};
|
|
52
|
+
toolSpecs.push(t);
|
|
53
|
+
}
|
|
54
|
+
return toolSpecs;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { McpServer, };
|
package/dist/db/db.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
|
|
|
5
5
|
const confDir = path.join(process.env.HOME ?? "~/", ".config/agent-smith/cli");
|
|
6
6
|
const dbPath = path.join(confDir, "config.db");
|
|
7
7
|
let db;
|
|
8
|
-
const debugDb =
|
|
8
|
+
const debugDb = false;
|
|
9
9
|
function initDb(isVerbose, execSchema) {
|
|
10
10
|
if (execSchema) {
|
|
11
11
|
createDirectoryIfNotExists(confDir, true);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ interface LmTaskFileSpec extends BaseLmTask {
|
|
|
79
79
|
ctx: number;
|
|
80
80
|
model?: ModelSpec;
|
|
81
81
|
modelpack?: ModelPack;
|
|
82
|
+
mcp?: McpServerSpec;
|
|
82
83
|
}
|
|
83
84
|
interface BaseLmTaskConfig {
|
|
84
85
|
templateName: string;
|
|
@@ -92,6 +93,23 @@ interface FinalLmTaskConfig {
|
|
|
92
93
|
model?: ModelSpec;
|
|
93
94
|
modelname?: string;
|
|
94
95
|
}
|
|
96
|
+
interface McpServerSpec {
|
|
97
|
+
command: string;
|
|
98
|
+
arguments: string[];
|
|
99
|
+
tools: string[];
|
|
100
|
+
}
|
|
101
|
+
interface McpServerTool {
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
inputSchema: {
|
|
105
|
+
type: string;
|
|
106
|
+
properties: Record<string, {
|
|
107
|
+
type: string;
|
|
108
|
+
description: string;
|
|
109
|
+
}>;
|
|
110
|
+
required: string[];
|
|
111
|
+
};
|
|
112
|
+
}
|
|
95
113
|
type InputMode = "manual" | "promptfile" | "clipboard";
|
|
96
114
|
type OutputMode = "txt" | "clipboard";
|
|
97
115
|
type RunMode = "cli" | "cmd";
|
|
@@ -107,4 +125,4 @@ type CmdExtension = "js";
|
|
|
107
125
|
type ModelFileExtension = "yml";
|
|
108
126
|
type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension | ModelFileExtension;
|
|
109
127
|
type AliasType = "task" | "action" | "workflow";
|
|
110
|
-
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, };
|
|
128
|
+
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, };
|
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.66",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@agent-smith/brain": "^0.0.43",
|
|
14
14
|
"@agent-smith/jobs": "^0.0.14",
|
|
15
|
-
"@agent-smith/lmtask": "^0.0.
|
|
15
|
+
"@agent-smith/lmtask": "^0.0.45",
|
|
16
16
|
"@agent-smith/tfm": "^0.1.2",
|
|
17
17
|
"@inquirer/prompts": "^7.5.3",
|
|
18
18
|
"@inquirer/select": "^4.2.3",
|
|
19
|
-
"@vue/reactivity": "^3.5.
|
|
19
|
+
"@vue/reactivity": "^3.5.16",
|
|
20
20
|
"ansi-colors": "^4.1.3",
|
|
21
21
|
"better-sqlite3": "^11.10.0",
|
|
22
22
|
"chalk": "^5.4.1",
|
|
23
23
|
"clipboardy": "^4.0.0",
|
|
24
24
|
"commander": "^14.0.0",
|
|
25
25
|
"marked-terminal": "^7.3.0",
|
|
26
|
-
"modprompt": "^0.11.
|
|
26
|
+
"modprompt": "^0.11.8",
|
|
27
27
|
"ora": "^8.2.0",
|
|
28
28
|
"python-shell": "^5.0.0",
|
|
29
29
|
"yaml": "^2.8.0"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
37
37
|
"@types/better-sqlite3": "^7.6.13",
|
|
38
38
|
"@types/marked-terminal": "^6.1.1",
|
|
39
|
-
"@types/node": "^22.15.
|
|
39
|
+
"@types/node": "^22.15.27",
|
|
40
40
|
"restmix": "^0.5.0",
|
|
41
41
|
"rollup": "^4.41.1",
|
|
42
42
|
"ts-node": "^10.9.2",
|