@agent-smith/cli 0.0.95 → 0.0.97
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/cli.js +1 -1
- package/dist/cmd/clicmds/base.js +14 -60
- package/dist/cmd/clicmds/cmds.d.ts +5 -1
- package/dist/cmd/clicmds/cmds.js +81 -1
- package/dist/cmd/clicmds/update.js +0 -2
- package/dist/cmd/cmds.d.ts +3 -2
- package/dist/cmd/cmds.js +6 -6
- package/dist/cmd/lib/actions/read.js +1 -1
- package/dist/cmd/lib/tasks/cmd.js +59 -39
- package/dist/cmd/lib/tasks/read.js +1 -0
- package/dist/cmd/lib/tasks/utils.d.ts +2 -1
- package/dist/cmd/lib/tasks/utils.js +23 -1
- package/dist/cmd/lib/workflows/cmd.d.ts +1 -1
- package/dist/cmd/lib/workflows/cmd.js +31 -9
- package/dist/cmd/lib/workflows/read.d.ts +1 -1
- package/dist/cmd/lib/workflows/read.js +19 -17
- package/dist/cmd/sys/read_features.js +0 -15
- package/dist/conf.js +12 -1
- package/dist/db/read.d.ts +5 -6
- package/dist/db/read.js +11 -32
- package/dist/db/schemas.js +15 -15
- package/dist/db/write.d.ts +5 -3
- package/dist/db/write.js +113 -31
- package/dist/interfaces.d.ts +17 -9
- package/dist/state/chat.d.ts +7 -27
- package/dist/state/chat.js +10 -3
- package/dist/state/features.js +0 -2
- package/dist/state/tasks.d.ts +5 -0
- package/dist/state/tasks.js +21 -0
- package/package.json +13 -14
- package/dist/cmd/lib/models.d.ts +0 -3
- package/dist/cmd/lib/models.js +0 -53
- package/dist/cmd/sys/read_modelfile.d.ts +0 -8
- package/dist/cmd/sys/read_modelfile.js +0 -21
package/dist/cli.js
CHANGED
package/dist/cmd/clicmds/base.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { readFeaturePaths, readFeaturesType } from "../../db/read.js";
|
|
4
|
-
import { cleanupFeaturePaths, updateAliases, updateFeatures } from "../../db/write.js";
|
|
5
|
-
import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
|
|
6
|
-
import { readPluginsPaths } from "../../state/plugins.js";
|
|
7
|
-
import { runMode } from "../../state/state.js";
|
|
8
|
-
import { showModelsCmd } from "../lib/models.js";
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { listBackends, setBackend } from "../../state/backends.js";
|
|
9
3
|
import { parseCommandArgs } from "../lib/options_parsers.js";
|
|
10
|
-
import {
|
|
11
|
-
import { readTask } from "../sys/read_task.js";
|
|
4
|
+
import { processTaskCmd, processTasksCmd, resetDbCmd, updateFeaturesCmd } from "./cmds.js";
|
|
12
5
|
import { updateConfCmd } from "./update.js";
|
|
13
|
-
import {
|
|
6
|
+
import { inferenceOptions } from "../options.js";
|
|
14
7
|
function initBaseCommands(program) {
|
|
15
8
|
program.command("exit")
|
|
16
9
|
.description("exit the cli")
|
|
17
10
|
.action(() => process.exit(0));
|
|
18
|
-
program.command("tasks")
|
|
11
|
+
const tasksCmd = program.command("tasks")
|
|
19
12
|
.description("list all the tasks")
|
|
20
13
|
.action(async (...args) => {
|
|
21
|
-
const ts = Object.keys(readFeaturesType("task")).sort();
|
|
22
|
-
console.table(ts);
|
|
23
|
-
});
|
|
24
|
-
program.command("task <task>")
|
|
25
|
-
.description("read a task")
|
|
26
|
-
.action(async (...args) => {
|
|
27
14
|
const ca = parseCommandArgs(args);
|
|
28
|
-
await
|
|
15
|
+
await processTasksCmd(ca.args, ca.options);
|
|
29
16
|
});
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
tasksCmd.addOption(new Option("-c, --conf", "output the tasks config"));
|
|
18
|
+
const taskCmd = program.command("task <task>")
|
|
19
|
+
.description("read a task")
|
|
32
20
|
.action(async (...args) => {
|
|
33
21
|
const ca = parseCommandArgs(args);
|
|
34
|
-
await
|
|
22
|
+
await processTaskCmd(ca.args, ca.options);
|
|
35
23
|
});
|
|
24
|
+
inferenceOptions.forEach(o => taskCmd.addOption(o));
|
|
25
|
+
taskCmd.addOption(new Option("--reset", "reset the task config to the original"));
|
|
36
26
|
program.command("backend <name>")
|
|
37
27
|
.description("set the default backend")
|
|
38
28
|
.action(async (...args) => {
|
|
@@ -47,7 +37,7 @@ function initBaseCommands(program) {
|
|
|
47
37
|
program.command("update")
|
|
48
38
|
.description("update the available features: run this after adding a new feature")
|
|
49
39
|
.action(async (...args) => {
|
|
50
|
-
await
|
|
40
|
+
await updateFeaturesCmd();
|
|
51
41
|
});
|
|
52
42
|
program.command("conf <path>")
|
|
53
43
|
.description("process config file")
|
|
@@ -58,44 +48,8 @@ function initBaseCommands(program) {
|
|
|
58
48
|
program.command("reset")
|
|
59
49
|
.description("reset the config database")
|
|
60
50
|
.action(async (...args) => {
|
|
61
|
-
await
|
|
51
|
+
await resetDbCmd();
|
|
62
52
|
});
|
|
63
53
|
return program;
|
|
64
54
|
}
|
|
65
|
-
async function _resetDbCmd() {
|
|
66
|
-
if (runMode.value == "cli") {
|
|
67
|
-
console.log("This command can not be run in cli mode");
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
deleteFileIfExists(dbPath);
|
|
71
|
-
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
72
|
-
}
|
|
73
|
-
async function _updateFeatures() {
|
|
74
|
-
const fp = readFeaturePaths();
|
|
75
|
-
const pp = await readPluginsPaths();
|
|
76
|
-
const paths = [...fp, ...pp];
|
|
77
|
-
const feats = readFeaturesDirs(paths);
|
|
78
|
-
updateFeatures(feats);
|
|
79
|
-
updateAliases(feats);
|
|
80
|
-
const deleted = cleanupFeaturePaths(paths);
|
|
81
|
-
for (const el of deleted) {
|
|
82
|
-
console.log("- [feature path]", el);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function _readTaskCmd(args) {
|
|
86
|
-
if (args.length == 0) {
|
|
87
|
-
console.warn("Provide a task name");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const { found, path } = getFeatureSpec(args[0], "task");
|
|
91
|
-
if (!found) {
|
|
92
|
-
console.warn(`FeatureType ${args[0]} not found`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const res = readTask(path);
|
|
96
|
-
if (!res.found) {
|
|
97
|
-
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
98
|
-
}
|
|
99
|
-
console.log(YAML.stringify(res.ymlTask));
|
|
100
|
-
}
|
|
101
55
|
export { initBaseCommands };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { FeatureSpec } from '../../interfaces.js';
|
|
3
3
|
declare function initUserCmds(cmdFeats: Record<string, FeatureSpec>): Promise<Array<Command>>;
|
|
4
|
-
|
|
4
|
+
declare function resetDbCmd(): Promise<any>;
|
|
5
|
+
declare function updateFeaturesCmd(): Promise<any>;
|
|
6
|
+
declare function processTasksCmd(args: Array<string>, options: Record<string, any>): Promise<void>;
|
|
7
|
+
declare function processTaskCmd(args: Array<string>, options: Record<string, any>): Promise<any>;
|
|
8
|
+
export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
|
package/dist/cmd/clicmds/cmds.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { readCmds } from "../sys/read_cmds.js";
|
|
2
|
+
import YAML from 'yaml';
|
|
3
|
+
import colors from "ansi-colors";
|
|
4
|
+
import { dbPath } from "../../conf.js";
|
|
5
|
+
import { readFeaturePaths, readFeaturesType, readTaskSetting } from "../../db/read.js";
|
|
6
|
+
import { cleanupFeaturePaths, deleteTaskSetting, updateAliases, updateFeatures, upsertTaskSettings } from "../../db/write.js";
|
|
7
|
+
import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
|
|
8
|
+
import { readPluginsPaths } from "../../state/plugins.js";
|
|
9
|
+
import { runMode } from "../../state/state.js";
|
|
10
|
+
import { deleteFileIfExists } from "../sys/delete_file.js";
|
|
11
|
+
import { readTask } from "../sys/read_task.js";
|
|
12
|
+
import { isTaskSettingsInitialized, initTaskSettings, tasksSettings } from '../../state/tasks.js';
|
|
2
13
|
async function initUserCmds(cmdFeats) {
|
|
3
14
|
const paths = new Set();
|
|
4
15
|
const cmds = new Array();
|
|
@@ -12,4 +23,73 @@ async function initUserCmds(cmdFeats) {
|
|
|
12
23
|
}
|
|
13
24
|
return cmds;
|
|
14
25
|
}
|
|
15
|
-
|
|
26
|
+
async function resetDbCmd() {
|
|
27
|
+
if (runMode.value == "cli") {
|
|
28
|
+
console.log("This command can not be run in cli mode");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
deleteFileIfExists(dbPath);
|
|
32
|
+
console.log("Config database reset ok. Run the conf command to recreate it");
|
|
33
|
+
}
|
|
34
|
+
async function updateFeaturesCmd() {
|
|
35
|
+
const fp = readFeaturePaths();
|
|
36
|
+
const pp = await readPluginsPaths();
|
|
37
|
+
const paths = [...fp, ...pp];
|
|
38
|
+
const feats = readFeaturesDirs(paths);
|
|
39
|
+
updateFeatures(feats);
|
|
40
|
+
updateAliases(feats);
|
|
41
|
+
const deleted = cleanupFeaturePaths(paths);
|
|
42
|
+
for (const el of deleted) {
|
|
43
|
+
console.log("- [feature path]", el);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function processTasksCmd(args, options) {
|
|
47
|
+
if (options?.conf) {
|
|
48
|
+
if (!isTaskSettingsInitialized.value) {
|
|
49
|
+
initTaskSettings();
|
|
50
|
+
}
|
|
51
|
+
console.log(YAML.stringify({ "tasks": tasksSettings }));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const ts = Object.keys(readFeaturesType("task")).sort();
|
|
55
|
+
console.table(ts);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function processTaskCmd(args, options) {
|
|
59
|
+
if (args.length == 0) {
|
|
60
|
+
console.warn("Provide a task name");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { found, path } = getFeatureSpec(args[0], "task");
|
|
64
|
+
if (!found) {
|
|
65
|
+
console.warn(`Task ${args[0]} not found`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (options?.reset) {
|
|
69
|
+
deleteTaskSetting(args[0]);
|
|
70
|
+
console.log("Task", args[0], "reset ok");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const res = readTask(path);
|
|
74
|
+
if (!res.found) {
|
|
75
|
+
throw new Error(`Task ${args[0]}, ${path} not found`);
|
|
76
|
+
}
|
|
77
|
+
console.log(res.ymlTask);
|
|
78
|
+
if (Object.keys(options).length > 0) {
|
|
79
|
+
upsertTaskSettings(args[0], options);
|
|
80
|
+
}
|
|
81
|
+
const s = readTaskSetting(args[0]);
|
|
82
|
+
if (s.found) {
|
|
83
|
+
const sts = s.settings;
|
|
84
|
+
delete sts.id;
|
|
85
|
+
delete sts.name;
|
|
86
|
+
const display = {};
|
|
87
|
+
for (const [k, v] of Object.entries(sts)) {
|
|
88
|
+
if (v) {
|
|
89
|
+
display[k] = v;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
console.log(colors.dim("Settings") + ":", display);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export { initUserCmds, resetDbCmd, updateFeaturesCmd, processTaskCmd, processTasksCmd, };
|
|
@@ -4,7 +4,6 @@ import { readFilePath } from "../../db/read.js";
|
|
|
4
4
|
import { cleanupFeaturePaths, updateAliases, updateDataDirPath, updateFeatures, updatePromptfilePath, upsertFilePath } from "../../db/write.js";
|
|
5
5
|
import { readFeaturesDirs } from "../../state/features.js";
|
|
6
6
|
import { dataDirPath, promptfilePath } from "../../state/state.js";
|
|
7
|
-
import { updateAllModels } from '../lib/models.js';
|
|
8
7
|
import { runtimeDataError, runtimeInfo } from '../lib/user_msgs.js';
|
|
9
8
|
async function updateConfCmd(args) {
|
|
10
9
|
initDb(false, true);
|
|
@@ -37,7 +36,6 @@ async function updateConfCmd(args) {
|
|
|
37
36
|
const feats = readFeaturesDirs(paths);
|
|
38
37
|
updateFeatures(feats);
|
|
39
38
|
updateAliases(feats);
|
|
40
|
-
updateAllModels();
|
|
41
39
|
const deleted = cleanupFeaturePaths(paths);
|
|
42
40
|
for (const el of deleted) {
|
|
43
41
|
console.log("- [feature path]", el);
|
package/dist/cmd/cmds.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { InferenceOptions } from "@locallm/types/dist/inference.js";
|
|
1
2
|
import { Command } from "commander";
|
|
2
3
|
declare const program: Command;
|
|
3
|
-
declare function chat(program: Command): Promise<void>;
|
|
4
|
+
declare function chat(program: Command, options: InferenceOptions): Promise<void>;
|
|
4
5
|
declare function buildCmds(): Promise<Command>;
|
|
5
6
|
declare function parseCmd(program: Command): Promise<void>;
|
|
6
|
-
export {
|
|
7
|
+
export { buildCmds, chat, parseCmd, program };
|
package/dist/cmd/cmds.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { input } from "@inquirer/prompts";
|
|
2
|
-
import { toRaw } from "@vue/reactivity";
|
|
3
2
|
import { Command } from "commander";
|
|
4
3
|
import { query } from "../cli.js";
|
|
5
4
|
import { readAliases, readFeatures } from "../db/read.js";
|
|
6
|
-
import { chatInferenceParams } from "../state/chat.js";
|
|
5
|
+
import { chatInferenceParams, chatTemplate } from "../state/chat.js";
|
|
7
6
|
import { agent, isChatMode, runMode } from "../state/state.js";
|
|
8
7
|
import { initCommandsFromAliases } from "./clicmds/aliases.js";
|
|
9
8
|
import { initBaseCommands } from "./clicmds/base.js";
|
|
10
9
|
import { initUserCmds } from "./clicmds/cmds.js";
|
|
11
10
|
const program = new Command();
|
|
12
|
-
async function chat(program) {
|
|
11
|
+
async function chat(program, options) {
|
|
13
12
|
const data = { message: '>', default: "" };
|
|
14
13
|
const prompt = await input(data);
|
|
15
14
|
if (prompt == "/q") {
|
|
@@ -21,9 +20,10 @@ async function chat(program) {
|
|
|
21
20
|
await query(program);
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
options.history = undefined;
|
|
24
|
+
await agent.run(prompt, chatInferenceParams, options, chatTemplate ? chatTemplate : undefined);
|
|
25
25
|
console.log();
|
|
26
|
-
await chat(program);
|
|
26
|
+
await chat(program, options);
|
|
27
27
|
}
|
|
28
28
|
async function buildCmds() {
|
|
29
29
|
initBaseCommands(program);
|
|
@@ -41,4 +41,4 @@ async function parseCmd(program) {
|
|
|
41
41
|
program.description('Terminal agents toolkit');
|
|
42
42
|
await program.parseAsync();
|
|
43
43
|
}
|
|
44
|
-
export {
|
|
44
|
+
export { buildCmds, chat, parseCmd, program };
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
import { input } from "@inquirer/prompts";
|
|
2
1
|
import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
|
|
3
2
|
import { default as color, default as colors } from "ansi-colors";
|
|
4
3
|
import { PromptTemplate } from "modprompt";
|
|
5
4
|
import ora from 'ora';
|
|
6
|
-
import { query } from "../../../cli.js";
|
|
7
|
-
import { readClipboard } from "../../../cmd/sys/clipboard.js";
|
|
8
5
|
import { usePerfTimer } from "../../../main.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { backend, backends, listBackends } from "../../../state/backends.js";
|
|
7
|
+
import { setChatInferenceParams, setChatTemplate } from "../../../state/chat.js";
|
|
8
|
+
import { agent, isChatMode } from "../../../state/state.js";
|
|
9
|
+
import { initTaskSettings, isTaskSettingsInitialized, tasksSettings } from "../../../state/tasks.js";
|
|
10
|
+
import { chat, program } from "../../cmds.js";
|
|
11
11
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
12
12
|
import { runtimeDataError, runtimeError, runtimeWarning } from "../user_msgs.js";
|
|
13
|
-
import { formatStats, processOutput
|
|
13
|
+
import { formatStats, processOutput } from "../utils.js";
|
|
14
14
|
import { readTask } from "./read.js";
|
|
15
|
-
import {
|
|
15
|
+
import { getTaskPrompt } from "./utils.js";
|
|
16
16
|
async function executeTask(name, payload, options, quiet) {
|
|
17
|
+
if (!isTaskSettingsInitialized.value) {
|
|
18
|
+
initTaskSettings();
|
|
19
|
+
}
|
|
20
|
+
const hasSettings = Object.keys(tasksSettings).includes(name);
|
|
21
|
+
let settings = {};
|
|
22
|
+
if (hasSettings) {
|
|
23
|
+
settings = tasksSettings[name];
|
|
24
|
+
}
|
|
17
25
|
if (options?.backend) {
|
|
18
26
|
if (options.backend in backends) {
|
|
19
27
|
agent.lm = backends[options.backend];
|
|
@@ -23,10 +31,45 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
23
31
|
runtimeDataError(`The backend ${options.backend} is not registered in config. Available backends:\n`, bks);
|
|
24
32
|
}
|
|
25
33
|
}
|
|
34
|
+
else if (settings?.backend) {
|
|
35
|
+
agent.lm = backends[settings.backend];
|
|
36
|
+
}
|
|
26
37
|
if (options?.debug || options?.backend) {
|
|
27
38
|
console.log("Agent:", colors.bold(agent.lm.name), "( " + agent.lm.providerType + " backend type)");
|
|
28
39
|
}
|
|
29
40
|
const { task, model, conf, vars, mcpServers } = await readTask(name, payload, options, agent);
|
|
41
|
+
if (hasSettings) {
|
|
42
|
+
if (!model?.inferParams) {
|
|
43
|
+
model.inferParams = {};
|
|
44
|
+
}
|
|
45
|
+
if (settings?.model && !conf?.model?.name) {
|
|
46
|
+
model.name = settings.model;
|
|
47
|
+
}
|
|
48
|
+
if (settings?.template && !conf?.model?.template) {
|
|
49
|
+
model.template = settings.template;
|
|
50
|
+
}
|
|
51
|
+
if (settings?.ctx && !conf?.model?.ctx) {
|
|
52
|
+
model.ctx = settings.ctx;
|
|
53
|
+
}
|
|
54
|
+
if (settings?.max_tokens && !conf?.inferParams?.max_tokens) {
|
|
55
|
+
model.inferParams.max_tokens = settings.max_tokens;
|
|
56
|
+
}
|
|
57
|
+
if (settings?.top_k && !conf?.inferParams?.top_k) {
|
|
58
|
+
model.inferParams.top_k = settings.top_k;
|
|
59
|
+
}
|
|
60
|
+
if (settings?.top_p && !conf?.inferParams?.top_p) {
|
|
61
|
+
model.inferParams.top_p = settings.top_p;
|
|
62
|
+
}
|
|
63
|
+
if (settings?.min_p && !conf?.inferParams?.min_p) {
|
|
64
|
+
model.inferParams.min_p = settings.min_p;
|
|
65
|
+
}
|
|
66
|
+
if (settings?.temperature && !conf?.inferParams?.temperature) {
|
|
67
|
+
model.inferParams.temperature = settings.temperature;
|
|
68
|
+
}
|
|
69
|
+
if (settings?.repeat_penalty && !conf?.inferParams?.repeat_penalty) {
|
|
70
|
+
model.inferParams.repeat_penalty = settings.repeat_penalty;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
30
73
|
if (model?.inferParams?.tsGrammar) {
|
|
31
74
|
model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
|
|
32
75
|
delete model.inferParams.tsGrammar;
|
|
@@ -150,6 +193,8 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
150
193
|
onToolCallEnd: onToolCallEnd,
|
|
151
194
|
...conf,
|
|
152
195
|
};
|
|
196
|
+
const initialInferParams = Object.assign({}, conf.inferParams);
|
|
197
|
+
initialInferParams.model = tconf.model;
|
|
153
198
|
let out;
|
|
154
199
|
try {
|
|
155
200
|
out = await task.run({ prompt: payload.prompt, ...vars }, tconf);
|
|
@@ -181,20 +226,11 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
181
226
|
mcpServers.forEach(async (s) => await s.stop());
|
|
182
227
|
await processOutput(out);
|
|
183
228
|
if (isChatMode.value) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (prompt == "/q") {
|
|
187
|
-
isChatMode.value = false;
|
|
188
|
-
if (runMode.value == "cmd") {
|
|
189
|
-
process.exit(0);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
await query(program);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
await executeTask(name, { ...vars, prompt: prompt }, options, quiet);
|
|
229
|
+
if (tpl) {
|
|
230
|
+
setChatTemplate(tpl);
|
|
197
231
|
}
|
|
232
|
+
setChatInferenceParams(initialInferParams);
|
|
233
|
+
await chat(program, options);
|
|
198
234
|
}
|
|
199
235
|
if (options?.debug === true || options?.verbose === true) {
|
|
200
236
|
try {
|
|
@@ -213,24 +249,8 @@ async function executeTask(name, payload, options, quiet) {
|
|
|
213
249
|
return out;
|
|
214
250
|
}
|
|
215
251
|
async function executeTaskCmd(name, targs = []) {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
pr = await readClipboard();
|
|
220
|
-
}
|
|
221
|
-
else if (options?.inputFile === true) {
|
|
222
|
-
pr = readPromptFile();
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
if (args[0] !== undefined) {
|
|
226
|
-
pr = args[0];
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
runtimeDataError("task", name, "provide a prompt or use input options");
|
|
230
|
-
throw new Error();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const params = { args: args, prompt: pr };
|
|
234
|
-
return await executeTask(name, params, options);
|
|
252
|
+
const ca = parseCommandArgs(targs);
|
|
253
|
+
const prompt = await getTaskPrompt(name, ca.args, ca.options);
|
|
254
|
+
return await executeTask(name, { prompt: prompt }, ca.options);
|
|
235
255
|
}
|
|
236
256
|
export { executeTask, executeTaskCmd };
|
|
@@ -92,6 +92,7 @@ async function readTask(name, payload, options, agent) {
|
|
|
92
92
|
}
|
|
93
93
|
;
|
|
94
94
|
const task = new Task(agent, taskSpec);
|
|
95
|
+
task.addTools(taskSpec.tools);
|
|
95
96
|
if (model?.inferParams?.tsGrammar) {
|
|
96
97
|
model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
|
|
97
98
|
delete model.inferParams.tsGrammar;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { LmTaskFileSpec } from "../../../interfaces.js";
|
|
2
2
|
declare function openTaskSpec(name: string): LmTaskFileSpec;
|
|
3
|
-
|
|
3
|
+
declare function getTaskPrompt(name: string, args: Array<string>, options: Record<string, any>): Promise<string>;
|
|
4
|
+
export { openTaskSpec, getTaskPrompt, };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import YAML from 'yaml';
|
|
2
2
|
import { readTask } from "../../../cmd/sys/read_task.js";
|
|
3
3
|
import { getFeatureSpec } from "../../../state/features.js";
|
|
4
|
+
import { readClipboard } from '../../../cmd/sys/clipboard.js';
|
|
5
|
+
import { readPromptFile } from '../utils.js';
|
|
6
|
+
import { runtimeDataError } from '../user_msgs.js';
|
|
4
7
|
function openTaskSpec(name) {
|
|
5
8
|
const { found, path } = getFeatureSpec(name, "task");
|
|
6
9
|
if (!found) {
|
|
@@ -14,4 +17,23 @@ function openTaskSpec(name) {
|
|
|
14
17
|
taskFileSpec.name = name;
|
|
15
18
|
return taskFileSpec;
|
|
16
19
|
}
|
|
17
|
-
|
|
20
|
+
async function getTaskPrompt(name, args, options) {
|
|
21
|
+
let pr;
|
|
22
|
+
if (options?.clipboardInput === true) {
|
|
23
|
+
pr = await readClipboard();
|
|
24
|
+
}
|
|
25
|
+
else if (options?.inputFile === true) {
|
|
26
|
+
pr = readPromptFile();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (args[0] !== undefined) {
|
|
30
|
+
pr = args[0];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
runtimeDataError("task", name, "provide a prompt or use input options");
|
|
34
|
+
throw new Error();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return pr;
|
|
38
|
+
}
|
|
39
|
+
export { openTaskSpec, getTaskPrompt, };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function executeWorkflow(
|
|
1
|
+
declare function executeWorkflow(wname: string, args: any, options?: Record<string, any>): Promise<any>;
|
|
2
2
|
declare function executeWorkflowCmd(name: string, wargs: Array<any>): Promise<any>;
|
|
3
3
|
export { executeWorkflow, executeWorkflowCmd, };
|
|
@@ -2,30 +2,51 @@ import { executeAction } from "../actions/cmd.js";
|
|
|
2
2
|
import { executeAdaptater } from "../adaptaters/cmd.js";
|
|
3
3
|
import { parseCommandArgs } from "../options_parsers.js";
|
|
4
4
|
import { executeTask } from "../tasks/cmd.js";
|
|
5
|
+
import { getTaskPrompt } from "../tasks/utils.js";
|
|
5
6
|
import { readWorkflow } from "./read.js";
|
|
6
7
|
import colors from "ansi-colors";
|
|
7
|
-
async function executeWorkflow(
|
|
8
|
-
const { workflow, found } = await readWorkflow(
|
|
8
|
+
async function executeWorkflow(wname, args, options = {}) {
|
|
9
|
+
const { workflow, found } = await readWorkflow(wname);
|
|
9
10
|
if (!found) {
|
|
10
|
-
throw new Error(`Workflow ${
|
|
11
|
+
throw new Error(`Workflow ${wname} not found`);
|
|
11
12
|
}
|
|
12
13
|
const isDebug = options?.debug === true;
|
|
13
14
|
const isVerbose = options?.verbose === true;
|
|
14
15
|
const stepNames = Object.keys(workflow);
|
|
15
16
|
if (isDebug || isVerbose) {
|
|
16
|
-
console.log("Running workflow",
|
|
17
|
+
console.log("Running workflow", wname, stepNames.length, "steps");
|
|
17
18
|
}
|
|
18
19
|
let i = 0;
|
|
19
20
|
const finalTaskIndex = stepNames.length - 1;
|
|
20
21
|
let taskRes = { cmdArgs: args };
|
|
21
|
-
|
|
22
|
+
let prevStepType = null;
|
|
23
|
+
for (const step of workflow) {
|
|
22
24
|
if (isDebug || isVerbose) {
|
|
23
|
-
console.log(i + 1, name, colors.dim(step.type));
|
|
25
|
+
console.log(i + 1, step.name, colors.dim(step.type));
|
|
24
26
|
}
|
|
25
27
|
switch (step.type) {
|
|
26
28
|
case "task":
|
|
27
29
|
try {
|
|
28
|
-
|
|
30
|
+
let pr = null;
|
|
31
|
+
if (i == 0) {
|
|
32
|
+
pr = await getTaskPrompt(step.name, taskRes.cmdArgs, options);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (prevStepType) {
|
|
36
|
+
if (prevStepType == "task") {
|
|
37
|
+
pr = taskRes.answer.text;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!pr) {
|
|
41
|
+
if (taskRes?.prompt) {
|
|
42
|
+
pr = taskRes.prompt;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!pr) {
|
|
47
|
+
throw new Error(`Workflow ${wname} step ${i + 1}: provide a prompt for the task ${name}`);
|
|
48
|
+
}
|
|
49
|
+
const tr = await executeTask(step.name, { prompt: pr }, options, true);
|
|
29
50
|
taskRes = { ...tr, ...taskRes };
|
|
30
51
|
}
|
|
31
52
|
catch (e) {
|
|
@@ -35,7 +56,7 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
35
56
|
case "action":
|
|
36
57
|
try {
|
|
37
58
|
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
38
|
-
const ares = await executeAction(name, actArgs, options, true);
|
|
59
|
+
const ares = await executeAction(step.name, actArgs, options, true);
|
|
39
60
|
if (typeof ares == "string" || Array.isArray(ares)) {
|
|
40
61
|
taskRes.args = ares;
|
|
41
62
|
}
|
|
@@ -53,7 +74,7 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
53
74
|
case "adaptater":
|
|
54
75
|
try {
|
|
55
76
|
const actArgs = i == 0 ? taskRes.cmdArgs : taskRes;
|
|
56
|
-
const adres = await executeAdaptater(name, actArgs, options);
|
|
77
|
+
const adres = await executeAdaptater(step.name, actArgs, options);
|
|
57
78
|
if (typeof adres == "string" || Array.isArray(adres)) {
|
|
58
79
|
taskRes.args = adres;
|
|
59
80
|
}
|
|
@@ -71,6 +92,7 @@ async function executeWorkflow(name, args, options = {}) {
|
|
|
71
92
|
default:
|
|
72
93
|
throw new Error(`unknown task type ${step.type} in workflow ${name}`);
|
|
73
94
|
}
|
|
95
|
+
prevStepType = step.type;
|
|
74
96
|
++i;
|
|
75
97
|
}
|
|
76
98
|
return taskRes;
|