@agent-smith/cli 0.0.91 → 0.0.92
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.js +19 -0
- package/dist/cmd/lib/actions/cmd.js +3 -1
- package/dist/cmd/lib/adaptaters/cmd.js +3 -1
- package/dist/cmd/lib/tasks/cmd.js +1 -4
- package/dist/cmd/lib/workflows/cmd.js +4 -2
- package/dist/cmd/lib/workflows/read.js +7 -3
- package/dist/cmd/sys/read_cmds.js +3 -1
- package/dist/index.js +2 -4
- package/dist/state/state.d.ts +3 -1
- package/dist/state/state.js +10 -2
- package/package.json +1 -1
package/dist/cmd/cmds.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
import { toRaw } from "@vue/reactivity";
|
|
1
3
|
import { Command } from "commander";
|
|
4
|
+
import { query } from "../cli.js";
|
|
2
5
|
import { readAliases, readFeatures } from "../db/read.js";
|
|
6
|
+
import { chatInferenceParams } from "../state/chat.js";
|
|
7
|
+
import { agent, isChatMode, runMode } from "../state/state.js";
|
|
3
8
|
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
4
9
|
import { initBaseCommands } from "./clicmds/base.js";
|
|
5
10
|
import { initUserCmds } from "./clicmds/cmds.js";
|
|
6
11
|
const program = new Command();
|
|
7
12
|
async function chat(program) {
|
|
13
|
+
const data = { message: '>', default: "" };
|
|
14
|
+
const prompt = await input(data);
|
|
15
|
+
if (prompt == "/q") {
|
|
16
|
+
isChatMode.value = false;
|
|
17
|
+
if (runMode.value == "cmd") {
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await query(program);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
await agent.lm.infer(prompt, toRaw(chatInferenceParams));
|
|
25
|
+
console.log();
|
|
26
|
+
await chat(program);
|
|
8
27
|
}
|
|
9
28
|
async function buildCmds() {
|
|
10
29
|
initBaseCommands(program);
|
|
@@ -8,6 +8,7 @@ import { runtimeError } from "../../../utils/user_msgs.js";
|
|
|
8
8
|
import { readClipboard } from "../../sys/clipboard.js";
|
|
9
9
|
import { processOutput, readPromptFile } from "../utils.js";
|
|
10
10
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
11
|
+
import { pathToFileURL } from 'url';
|
|
11
12
|
async function executeAction(name, payload, options, quiet = false) {
|
|
12
13
|
let run;
|
|
13
14
|
const { found, path, ext } = getFeatureSpec(name, "action");
|
|
@@ -16,7 +17,8 @@ async function executeAction(name, payload, options, quiet = false) {
|
|
|
16
17
|
}
|
|
17
18
|
switch (ext) {
|
|
18
19
|
case "js":
|
|
19
|
-
const
|
|
20
|
+
const url = pathToFileURL(path).href;
|
|
21
|
+
const mjsa = await import(url);
|
|
20
22
|
run = createJsAction(mjsa.action);
|
|
21
23
|
break;
|
|
22
24
|
case "yml":
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { getFeatureSpec } from "../../../state/features.js";
|
|
2
2
|
import { createJsAction } from "../actions/read.js";
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
3
4
|
async function executeAdaptater(name, params, options) {
|
|
4
5
|
const { found, path } = getFeatureSpec(name, "adaptater");
|
|
5
6
|
if (!found) {
|
|
6
7
|
throw new Error(`adaptater ${name} not found`);
|
|
7
8
|
}
|
|
8
9
|
let run;
|
|
9
|
-
const
|
|
10
|
+
const url = pathToFileURL(path).href;
|
|
11
|
+
const jsa = await import(url);
|
|
10
12
|
run = createJsAction(jsa.action);
|
|
11
13
|
let res;
|
|
12
14
|
try {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Agent } from "@agent-smith/agent";
|
|
2
1
|
import { input } from "@inquirer/prompts";
|
|
3
2
|
import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
|
|
4
3
|
import { default as color, default as colors } from "ansi-colors";
|
|
@@ -7,15 +6,13 @@ import ora from 'ora';
|
|
|
7
6
|
import { query } from "../../../cli.js";
|
|
8
7
|
import { readClipboard } from "../../../cmd/sys/clipboard.js";
|
|
9
8
|
import { usePerfTimer } from "../../../main.js";
|
|
10
|
-
import {
|
|
11
|
-
import { isChatMode, runMode } from "../../../state/state.js";
|
|
9
|
+
import { isChatMode, runMode, agent } from "../../../state/state.js";
|
|
12
10
|
import { program } from "../../cmds.js";
|
|
13
11
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
14
12
|
import { runtimeDataError, runtimeWarning } from "../user_msgs.js";
|
|
15
13
|
import { formatStats, processOutput, readPromptFile } from "../utils.js";
|
|
16
14
|
import { readTask } from "./read.js";
|
|
17
15
|
async function executeTask(name, payload, options, quiet) {
|
|
18
|
-
const agent = new Agent(backend.value);
|
|
19
16
|
if (options?.debug) {
|
|
20
17
|
console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
|
|
21
18
|
}
|
|
@@ -34,7 +34,8 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
34
34
|
break;
|
|
35
35
|
case "action":
|
|
36
36
|
try {
|
|
37
|
-
const
|
|
37
|
+
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
38
|
+
const ares = await executeAction(name, actArgs, options, true);
|
|
38
39
|
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
39
40
|
taskRes.args = ares;
|
|
40
41
|
}
|
|
@@ -51,7 +52,8 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
51
52
|
break;
|
|
52
53
|
case "adaptater":
|
|
53
54
|
try {
|
|
54
|
-
const
|
|
55
|
+
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
56
|
+
const adres = await executeAdaptater(name, actArgs, options);
|
|
55
57
|
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
56
58
|
taskRes.args = adres;
|
|
57
59
|
}
|
|
@@ -7,6 +7,7 @@ import { getFeatureSpec } from '../../../state/features.js';
|
|
|
7
7
|
import { readTask } from "../../sys/read_task.js";
|
|
8
8
|
import { pythonAction, systemAction } from '../actions/cmd.js';
|
|
9
9
|
import { createJsAction } from '../actions/read.js';
|
|
10
|
+
import { pathToFileURL } from 'url';
|
|
10
11
|
async function _createWorkflowFromSpec(spec) {
|
|
11
12
|
const steps = {};
|
|
12
13
|
for (const step of spec.steps) {
|
|
@@ -26,7 +27,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
26
27
|
}
|
|
27
28
|
switch (ext) {
|
|
28
29
|
case "js":
|
|
29
|
-
const
|
|
30
|
+
const url = pathToFileURL(path).href;
|
|
31
|
+
const { action } = await import(url);
|
|
30
32
|
const at = action;
|
|
31
33
|
const wf = {
|
|
32
34
|
type: "action",
|
|
@@ -35,7 +37,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
35
37
|
steps[name] = wf;
|
|
36
38
|
break;
|
|
37
39
|
case "mjs":
|
|
38
|
-
const
|
|
40
|
+
const url2 = pathToFileURL(path).href;
|
|
41
|
+
const mjsa = await import(url2);
|
|
39
42
|
const act = createJsAction(mjsa.action);
|
|
40
43
|
const wf2 = {
|
|
41
44
|
type: "action",
|
|
@@ -68,7 +71,8 @@ async function _createWorkflowFromSpec(spec) {
|
|
|
68
71
|
if (!found) {
|
|
69
72
|
throw new Error(`Adaptater ${name} not found`);
|
|
70
73
|
}
|
|
71
|
-
const
|
|
74
|
+
const url = pathToFileURL(path).href;
|
|
75
|
+
const jsa = await import(url);
|
|
72
76
|
const act = createJsAction(jsa.action);
|
|
73
77
|
const wf = {
|
|
74
78
|
type: "adaptater",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { default as fs } from "fs";
|
|
2
2
|
import { default as path } from "path";
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
3
4
|
function _readCmdsDir(dir) {
|
|
4
5
|
const fileNames = new Array;
|
|
5
6
|
fs.readdirSync(dir).forEach((filename) => {
|
|
@@ -18,7 +19,8 @@ async function readCmds(dir) {
|
|
|
18
19
|
const cmds = new Array();
|
|
19
20
|
const fileNames = _readCmdsDir(dir);
|
|
20
21
|
for (const name of fileNames) {
|
|
21
|
-
const
|
|
22
|
+
const url = pathToFileURL(path.join(dir, name + ".js")).href;
|
|
23
|
+
const { cmd } = await import(url);
|
|
22
24
|
if (!cmd) {
|
|
23
25
|
throw new Error(`command ${name} not found in ${dir}`);
|
|
24
26
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { argv } from 'process';
|
|
3
3
|
import { query } from "./cli.js";
|
|
4
4
|
import { buildCmds, parseCmd } from './cmd/cmds.js';
|
|
5
|
-
import { formatMode,
|
|
5
|
+
import { formatMode, init, inputMode, isChatMode, outputMode, runMode } from './state/state.js';
|
|
6
6
|
import { updateConfCmd } from './cmd/clicmds/update.js';
|
|
7
|
-
import { initBackends } from './state/backends.js';
|
|
8
7
|
async function main() {
|
|
9
8
|
const nargs = argv.length;
|
|
10
9
|
if (nargs == 2) {
|
|
@@ -16,8 +15,7 @@ async function main() {
|
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
await
|
|
20
|
-
await initBackends();
|
|
18
|
+
await init();
|
|
21
19
|
const program = await buildCmds();
|
|
22
20
|
program.hook('preAction', async (thisCommand, actionCommand) => {
|
|
23
21
|
const options = actionCommand.opts();
|
package/dist/state/state.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PythonShell } from 'python-shell';
|
|
2
2
|
import { InputMode, RunMode, FormatMode, OutputMode } from "../interfaces.js";
|
|
3
|
+
import { Agent } from "@agent-smith/agent";
|
|
3
4
|
declare let pyShell: PythonShell;
|
|
4
5
|
declare const inputMode: import("@vue/reactivity").Ref<InputMode, InputMode>;
|
|
5
6
|
declare const outputMode: import("@vue/reactivity").Ref<OutputMode, OutputMode>;
|
|
@@ -9,6 +10,7 @@ declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
|
9
10
|
declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
|
|
10
11
|
declare const dataDirPath: import("@vue/reactivity").Ref<string, string>;
|
|
11
12
|
declare const isStateReady: import("@vue/reactivity").Ref<boolean, boolean>;
|
|
13
|
+
declare let agent: Agent;
|
|
12
14
|
declare const lastCmd: {
|
|
13
15
|
name: string;
|
|
14
16
|
args: Array<string>;
|
|
@@ -17,4 +19,4 @@ declare function initFilepaths(): void;
|
|
|
17
19
|
declare function init(): Promise<void>;
|
|
18
20
|
declare function initState(): Promise<void>;
|
|
19
21
|
declare function pluginDataDir(pluginName: string): string;
|
|
20
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, };
|
|
22
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, agent, };
|
package/dist/state/state.js
CHANGED
|
@@ -3,7 +3,9 @@ import { initDb } from "../db/db.js";
|
|
|
3
3
|
import { readFilePaths } from "../db/read.js";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { createDirectoryIfNotExists } from "../cmd/sys/dirs.js";
|
|
6
|
-
import { initBackends } from "./backends.js";
|
|
6
|
+
import { backend, initBackends } from "./backends.js";
|
|
7
|
+
import { Agent } from "@agent-smith/agent";
|
|
8
|
+
import { runtimeDataError } from "../utils/user_msgs.js";
|
|
7
9
|
let pyShell;
|
|
8
10
|
const inputMode = ref("manual");
|
|
9
11
|
const outputMode = ref("txt");
|
|
@@ -13,6 +15,7 @@ const isChatMode = ref(false);
|
|
|
13
15
|
const promptfilePath = ref("");
|
|
14
16
|
const dataDirPath = ref("");
|
|
15
17
|
const isStateReady = ref(false);
|
|
18
|
+
let agent;
|
|
16
19
|
const lastCmd = reactive({
|
|
17
20
|
name: "",
|
|
18
21
|
args: [],
|
|
@@ -32,6 +35,11 @@ function initFilepaths() {
|
|
|
32
35
|
async function init() {
|
|
33
36
|
await initState();
|
|
34
37
|
await initBackends();
|
|
38
|
+
if (!backend.value) {
|
|
39
|
+
runtimeDataError("No backend found, can not initialize agent");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
agent = new Agent(backend.value);
|
|
35
43
|
}
|
|
36
44
|
async function initState() {
|
|
37
45
|
if (isStateReady.value) {
|
|
@@ -53,4 +61,4 @@ function pluginDataDir(pluginName) {
|
|
|
53
61
|
createDirectoryIfNotExists(pluginDatapath);
|
|
54
62
|
return pluginDatapath;
|
|
55
63
|
}
|
|
56
|
-
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, };
|
|
64
|
+
export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, promptfilePath, dataDirPath, isStateReady, pluginDataDir, initState, initFilepaths, init, pyShell, agent, };
|
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.92",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"buildrl": "rm -rf dist/* && rollup -c",
|
|
8
8
|
"build": "rm -rf dist/* && tsc",
|