@agent-smith/cli 0.0.39 → 0.0.40

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.
Files changed (47) hide show
  1. package/dist/cmd/clicmds/cmds.js +19 -41
  2. package/dist/cmd/clicmds/modes.js +14 -5
  3. package/dist/cmd/cmds.d.ts +1 -1
  4. package/dist/cmd/cmds.js +2 -2
  5. package/dist/cmd/lib/{execute_action.d.ts → actions/cmd.d.ts} +4 -4
  6. package/dist/cmd/lib/{execute_action.js → actions/cmd.js} +14 -23
  7. package/dist/cmd/lib/actions/read.d.ts +4 -0
  8. package/dist/cmd/lib/actions/read.js +18 -0
  9. package/dist/cmd/lib/adaptaters/cmd.d.ts +2 -0
  10. package/dist/cmd/lib/adaptaters/cmd.js +37 -0
  11. package/dist/cmd/lib/tasks/cmd.d.ts +3 -0
  12. package/dist/cmd/lib/tasks/cmd.js +144 -0
  13. package/dist/cmd/lib/tools.d.ts +6 -0
  14. package/dist/cmd/lib/tools.js +76 -0
  15. package/dist/cmd/lib/utils.d.ts +2 -10
  16. package/dist/cmd/lib/utils.js +18 -60
  17. package/dist/cmd/lib/workflows/cmd.d.ts +1 -2
  18. package/dist/cmd/lib/workflows/cmd.js +20 -9
  19. package/dist/cmd/lib/workflows/read.d.ts +2 -2
  20. package/dist/cmd/lib/workflows/read.js +15 -4
  21. package/dist/cmd/sys/read.d.ts +2 -0
  22. package/dist/cmd/sys/read.js +10 -0
  23. package/dist/cmd/sys/read_features.js +10 -10
  24. package/dist/cmd/sys/read_task.d.ts +6 -0
  25. package/dist/cmd/sys/read_task.js +23 -0
  26. package/dist/cmd/sys/reset.d.ts +2 -0
  27. package/dist/cmd/sys/reset.js +10 -0
  28. package/dist/cmd/sys/run_python.js +5 -2
  29. package/dist/db/db.d.ts +2 -1
  30. package/dist/db/db.js +1 -1
  31. package/dist/db/read.d.ts +9 -3
  32. package/dist/db/read.js +19 -4
  33. package/dist/db/schemas.js +34 -12
  34. package/dist/db/write.js +32 -6
  35. package/dist/index.js +0 -0
  36. package/dist/interfaces.d.ts +21 -13
  37. package/dist/main.d.ts +3 -4
  38. package/dist/main.js +3 -4
  39. package/dist/state/chat.d.ts +1 -1
  40. package/dist/state/features.js +2 -2
  41. package/dist/state/state.d.ts +3 -2
  42. package/dist/state/state.js +5 -4
  43. package/package.json +13 -12
  44. package/dist/cmd/lib/execute_job.d.ts +0 -6
  45. package/dist/cmd/lib/execute_job.js +0 -273
  46. package/dist/cmd/lib/execute_task.d.ts +0 -4
  47. package/dist/cmd/lib/execute_task.js +0 -106
@@ -14,11 +14,6 @@ interface Features {
14
14
  path: string;
15
15
  ext: TaskExtension;
16
16
  }>;
17
- job: Array<{
18
- name: string;
19
- path: string;
20
- ext: JobExtension;
21
- }>;
22
17
  cmd: Array<{
23
18
  name: string;
24
19
  path: string;
@@ -34,27 +29,40 @@ interface Features {
34
29
  path: string;
35
30
  ext: WorkflowExtension;
36
31
  }>;
32
+ adaptater: Array<{
33
+ name: string;
34
+ path: string;
35
+ ext: AdaptaterExtension;
36
+ }>;
37
37
  }
38
38
  interface ConfigFile {
39
39
  promptfile?: string;
40
40
  features?: Array<string>;
41
41
  plugins?: Array<string>;
42
42
  }
43
- interface NodeReturnType<T = Record<string, any>> {
44
- data: T;
45
- error?: Error;
43
+ interface Settings {
44
+ name: string;
45
+ inputmode: InputMode;
46
+ outputmode: OutputMode;
47
+ runmode: RunMode;
48
+ formatmode: FormatMode;
49
+ ischatMode: boolean;
50
+ isdebug: boolean;
51
+ isverbose: boolean;
52
+ promptfile: string;
46
53
  }
47
54
  type CmdExecutor = (args: Array<string>, options: any) => Promise<any>;
48
55
  type InputMode = "manual" | "promptfile" | "clipboard";
49
56
  type OutputMode = "txt" | "clipboard";
50
57
  type RunMode = "cli" | "cmd";
51
58
  type FormatMode = "text" | "markdown";
52
- type FeatureType = "task" | "job" | "action" | "cmd" | "workflow";
59
+ type FeatureType = "task" | "action" | "cmd" | "workflow" | "adaptater";
60
+ type ToolType = "task" | "action" | "cmd" | "workflow";
53
61
  type ActionExtension = "js" | "mjs" | "py" | "yml";
54
62
  type TaskExtension = "yml";
63
+ type AdaptaterExtension = "js";
55
64
  type WorkflowExtension = "yml";
56
- type JobExtension = "yml";
57
65
  type CmdExtension = "js";
58
- type FeatureExtension = TaskExtension | JobExtension | CmdExtension | ActionExtension | WorkflowExtension;
59
- type AliasType = "task" | "action" | "job" | "workflow";
60
- export { Cmd, CmdExecutor, NodeReturnType, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, JobExtension, WorkflowExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, };
66
+ type FeatureExtension = TaskExtension | CmdExtension | ActionExtension | WorkflowExtension;
67
+ type AliasType = "task" | "action" | "workflow";
68
+ export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, WorkflowExtension, AdaptaterExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, ToolType, Settings, };
package/dist/main.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
- import { executeJobCmd } from "./cmd/lib/execute_job.js";
3
- import { executeActionCmd } from "./cmd/lib/execute_action.js";
4
- import { executeTaskCmd } from "./cmd/lib/execute_task.js";
2
+ import { executeActionCmd } from "./cmd/lib/actions/cmd.js";
3
+ import { executeTaskCmd } from "./cmd/lib/tasks/cmd.js";
5
4
  import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
6
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
7
6
  import { pingCmd } from "./cmd/clicmds/cmds.js";
8
7
  import { initAgent } from "./agent.js";
9
- export { execute, run, pingCmd, executeJobCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, };
8
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, };
package/dist/main.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { execute, run } from "./cmd/sys/execute.js";
2
- import { executeJobCmd } from "./cmd/lib/execute_job.js";
3
- import { executeActionCmd } from "./cmd/lib/execute_action.js";
4
- import { executeTaskCmd } from "./cmd/lib/execute_task.js";
2
+ import { executeActionCmd } from "./cmd/lib/actions/cmd.js";
3
+ import { executeTaskCmd } from "./cmd/lib/tasks/cmd.js";
5
4
  import { executeWorkflowCmd } from "./cmd/lib/workflows/cmd.js";
6
5
  import { writeToClipboard } from "./cmd/sys/clipboard.js";
7
6
  import { pingCmd } from "./cmd/clicmds/cmds.js";
8
7
  import { initAgent } from "./agent.js";
9
- export { execute, run, pingCmd, executeJobCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, };
8
+ export { execute, run, pingCmd, executeWorkflowCmd, executeActionCmd, executeTaskCmd, writeToClipboard, initAgent, };
@@ -2,7 +2,7 @@ declare const chatInferenceParams: {
2
2
  stream?: boolean | undefined;
3
3
  model?: {
4
4
  name: string;
5
- ctx: number;
5
+ ctx?: number | undefined;
6
6
  info?: {
7
7
  size: string;
8
8
  quant: string;
@@ -4,18 +4,18 @@ import { readFeature } from "../db/read.js";
4
4
  function readFeaturesDirs(featuresPaths) {
5
5
  const feats = {
6
6
  task: [],
7
- job: [],
8
7
  action: [],
9
8
  cmd: [],
10
9
  workflow: [],
10
+ adaptater: [],
11
11
  };
12
12
  featuresPaths.forEach((dir) => {
13
13
  const _f = readFeaturesDir(dir);
14
14
  _f.task.forEach((item) => feats.task.push(item));
15
- _f.job.forEach((item) => feats.job.push(item));
16
15
  _f.action.forEach((item) => feats.action.push(item));
17
16
  _f.cmd.forEach((item) => feats.cmd.push(item));
18
17
  _f.workflow.forEach((item) => feats.workflow.push(item));
18
+ _f.adaptater.forEach((item) => feats.adaptater.push(item));
19
19
  });
20
20
  return feats;
21
21
  }
@@ -8,11 +8,12 @@ declare const formatMode: import("@vue/reactivity").Ref<FormatMode, FormatMode>;
8
8
  declare const isChatMode: import("@vue/reactivity").Ref<boolean, boolean>;
9
9
  declare const isDebug: import("@vue/reactivity").Ref<boolean, boolean>;
10
10
  declare const isVerbose: import("@vue/reactivity").Ref<boolean, boolean>;
11
- declare const promptfile: import("@vue/reactivity").Ref<string, string>;
11
+ declare const isShowTokens: import("@vue/reactivity").Ref<boolean, boolean>;
12
+ declare const promptfilePath: import("@vue/reactivity").Ref<string, string>;
12
13
  declare const lastCmd: {
13
14
  name: string;
14
15
  args: Array<string>;
15
16
  };
16
17
  declare function initFeatures(): Promise<void>;
17
18
  declare function initState(): Promise<void>;
18
- export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfile, initState, initFeatures, pyShell, };
19
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, initState, initFeatures, pyShell, };
@@ -1,7 +1,7 @@
1
1
  import { reactive, ref } from "@vue/reactivity";
2
2
  import { createConfDirIfNotExists, confDir } from "../conf.js";
3
3
  import { initDb } from "../db/db.js";
4
- import { readFeaturePaths, readPromptFile } from "../db/read.js";
4
+ import { readFeaturePaths, readPromptFilePath } from "../db/read.js";
5
5
  import { updateAliases, updateFeatures } from "../db/write.js";
6
6
  import { readFeaturesDirs } from "./features.js";
7
7
  import { readPluginsPaths } from "./plugins.js";
@@ -13,7 +13,8 @@ const formatMode = ref("text");
13
13
  const isChatMode = ref(false);
14
14
  const isDebug = ref(false);
15
15
  const isVerbose = ref(false);
16
- const promptfile = ref("");
16
+ const isShowTokens = ref(false);
17
+ const promptfilePath = ref("");
17
18
  const lastCmd = reactive({
18
19
  name: "",
19
20
  args: [],
@@ -32,10 +33,10 @@ async function initFeatures() {
32
33
  const feats = readFeaturesDirs(p);
33
34
  updateFeatures(feats);
34
35
  updateAliases(feats);
35
- promptfile.value = readPromptFile();
36
+ promptfilePath.value = readPromptFilePath();
36
37
  }
37
38
  async function initState() {
38
39
  initConf();
39
40
  await initFeatures();
40
41
  }
41
- export { inputMode, outputMode, isChatMode, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfile, initState, initFeatures, pyShell, };
42
+ export { inputMode, outputMode, isChatMode, isShowTokens, runMode, formatMode, lastCmd, isDebug, isVerbose, promptfilePath, initState, initFeatures, pyShell, };
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.39",
5
+ "version": "0.0.40",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc --noCheck",
@@ -10,32 +10,33 @@
10
10
  "watch": "tsc --noCheck -p . -w"
11
11
  },
12
12
  "dependencies": {
13
- "@agent-smith/brain": "^0.0.38",
14
- "@agent-smith/jobs": "^0.0.13",
15
- "@agent-smith/lmtask": "^0.0.31",
16
- "@agent-smith/tfm": "^0.1.1",
17
- "@inquirer/prompts": "^7.3.3",
18
- "@inquirer/select": "^4.0.10",
13
+ "@agent-smith/brain": "^0.0.41",
14
+ "@agent-smith/jobs": "^0.0.14",
15
+ "@agent-smith/lmtask": "^0.0.33",
16
+ "@agent-smith/tfm": "^0.1.2",
17
+ "@inquirer/prompts": "^7.4.0",
18
+ "@inquirer/select": "^4.1.0",
19
19
  "@vue/reactivity": "^3.5.13",
20
- "better-sqlite3": "^11.9.0",
20
+ "@wllama/wllama": "^2.3.0",
21
+ "better-sqlite3": "^11.9.1",
21
22
  "clipboardy": "^4.0.0",
22
23
  "commander": "^13.1.0",
23
24
  "marked-terminal": "^7.3.0",
24
- "modprompt": "^0.10.4",
25
+ "modprompt": "^0.10.8",
25
26
  "python-shell": "^5.0.0",
26
27
  "yaml": "^2.7.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@agent-smith/tmem-jobs": "^0.0.4",
30
31
  "@commander-js/extra-typings": "^13.1.0",
31
- "@locallm/types": "^0.1.5",
32
+ "@locallm/types": "^0.1.6",
32
33
  "@rollup/plugin-node-resolve": "^16.0.1",
33
34
  "@rollup/plugin-typescript": "^12.1.2",
34
35
  "@types/better-sqlite3": "^7.6.12",
35
36
  "@types/marked-terminal": "^6.1.1",
36
- "@types/node": "^22.13.10",
37
+ "@types/node": "^22.13.11",
37
38
  "restmix": "^0.5.0",
38
- "rollup": "^4.35.0",
39
+ "rollup": "^4.36.0",
39
40
  "ts-node": "^10.9.2",
40
41
  "tslib": "2.8.1",
41
42
  "typescript": "^5.8.2"
@@ -1,6 +0,0 @@
1
- declare function executeJobCmd(name: string, args?: Array<any>, options?: any): Promise<Record<string, any>>;
2
- declare function readJob(name: string): Promise<{
3
- found: boolean;
4
- data: Record<string, any>;
5
- }>;
6
- export { readJob, executeJobCmd };
@@ -1,273 +0,0 @@
1
- import YAML from 'yaml';
2
- import { default as fs } from "fs";
3
- import { useAgentJob } from "@agent-smith/jobs";
4
- import { brain, marked, taskBuilder } from '../../agent.js';
5
- import { getFeatureSpec } from '../../state/features.js';
6
- import { formatMode, isDebug, isVerbose } from '../../state/state.js';
7
- import { createJsAction, initActionVars, initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from './utils.js';
8
- import { pythonAction, systemAction } from './execute_action.js';
9
- async function executeJobCmd(name, args = [], options = {}) {
10
- const { job, found } = await _dispatchReadJob(name);
11
- if (isDebug.value || isVerbose.value) {
12
- console.log("Running job", name, Object.keys(job.tasks).length, "tasks");
13
- }
14
- if (!found) {
15
- throw new Error(`Job ${name} not found`);
16
- }
17
- await job.start();
18
- let res = {};
19
- let params = {};
20
- brain.backendsForModelsInfo();
21
- let i = 0;
22
- const finalTaskIndex = Object.keys(job.tasks).length - 1;
23
- for (const [name, task] of Object.entries(job.tasks)) {
24
- if (task.type == "task") {
25
- const chain = task.properties?.chain;
26
- const { found, path } = getFeatureSpec(name, "task");
27
- if (!found) {
28
- throw new Error(`Task ${name} not found`);
29
- }
30
- const tres = readTask(path);
31
- if (!tres.found) {
32
- throw new Error(`Task ${name}, ${path} not found`);
33
- }
34
- const taskSpec = taskBuilder.readFromYaml(tres.ymlTask);
35
- if (params.data?.history?.length > 0) {
36
- const taskShots = taskSpec?.shots ?? [];
37
- taskSpec.shots = [...taskShots, ...params.data.history];
38
- }
39
- let conf = {};
40
- let vars = {};
41
- if (i == 0) {
42
- const vs = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
43
- conf = vs.conf;
44
- vars = vs.vars;
45
- const _pr = await parseInputOptions(options);
46
- if (_pr) {
47
- vars.prompt = _pr;
48
- }
49
- }
50
- else {
51
- if (!params?.prompt) {
52
- if (params?.text) {
53
- params.prompt = params.text;
54
- }
55
- else {
56
- throw new Error(`No prompt provided for task ${name}.\Params: ${JSON.stringify(params, null, 2)}`);
57
- }
58
- }
59
- const vs = initTaskParams(params, taskSpec?.inferParams ? taskSpec.inferParams : {});
60
- conf = vs.conf;
61
- vars = vs.vars;
62
- }
63
- const nextParams = {};
64
- for (const [k, v] of Object.entries(vars)) {
65
- if (taskSpec.variables?.required?.includes(k) || taskSpec.variables?.optional?.includes(k) || k == "prompt") {
66
- continue;
67
- }
68
- ;
69
- nextParams[k] = v;
70
- delete vars[k];
71
- }
72
- conf = initTaskConf(conf, taskSpec);
73
- if (isDebug.value) {
74
- console.log("Task conf:", conf);
75
- console.log("Task vars:", vars);
76
- console.log("Next params:", nextParams);
77
- }
78
- if (isVerbose.value || isDebug.value) {
79
- conf.verbose = true;
80
- }
81
- const ex = brain.getOrCreateExpertForModel(conf.model.name, conf.model.template);
82
- if (!ex) {
83
- throw new Error("No expert found for model " + conf.model.name);
84
- }
85
- ex.checkStatus();
86
- ex.backend.setOnToken((t) => {
87
- process.stdout.write(t);
88
- });
89
- brain.setDefaultExpert(ex);
90
- conf["expert"] = ex;
91
- try {
92
- if (isDebug.value || isVerbose.value) {
93
- console.log(i + 1, "Running task", name);
94
- }
95
- try {
96
- const invars = { ...params, ...vars };
97
- try {
98
- res = await job.runTask(name, invars, conf);
99
- console.log("");
100
- }
101
- catch (e) {
102
- throw new Error(`Error running task ${name}: ${e}`);
103
- }
104
- if (chain) {
105
- const turn = {
106
- user: vars["prompt"],
107
- assistant: res.text
108
- };
109
- if (res.data?.history) {
110
- res.data.history.push(turn);
111
- }
112
- else {
113
- res.data.history = [turn];
114
- }
115
- }
116
- else {
117
- if (res.data?.history) {
118
- res.data.history = [];
119
- }
120
- }
121
- }
122
- catch (e) {
123
- throw new Error(`Error running job task ${e}`);
124
- }
125
- if (res?.error) {
126
- return { ok: false, data: "", conf: conf, error: `Error executing job task ${name}: ${res.error}` };
127
- }
128
- if ("text" in res) {
129
- if (formatMode.value == "markdown") {
130
- console.log("\n\n------------------\n");
131
- console.log(marked.parse(res.text).trim());
132
- }
133
- }
134
- params = { ...res, ...nextParams };
135
- }
136
- catch (err) {
137
- return { error: `Error executing job task ${name}: ${err}` };
138
- }
139
- }
140
- else {
141
- try {
142
- const _p = i == 0 ? args : params;
143
- let nextParams = {};
144
- if (i == 0) {
145
- const { vars } = initActionVars(args);
146
- nextParams = vars;
147
- }
148
- if (isDebug.value) {
149
- console.log(i + 1, "Running action", name, _p);
150
- }
151
- else if (isVerbose.value) {
152
- console.log(i + 1, "Running action", name);
153
- }
154
- try {
155
- res = await job.runTask(name, _p, options);
156
- if (res?.error) {
157
- throw new Error(`Error executing job action ${res.error}`);
158
- }
159
- }
160
- catch (e) {
161
- throw new Error(`Error executing job action ${e}`);
162
- }
163
- if (!res.ok) {
164
- return { ok: false, data: "", conf: {}, error: `Error executing action ${name}: ${res?.error}` };
165
- }
166
- if (i == finalTaskIndex) {
167
- console.log(res.data);
168
- }
169
- else {
170
- params = res.data;
171
- }
172
- params = { ...res.data, ...nextParams };
173
- }
174
- catch (err) {
175
- throw new Error(`Error executing (${task.type}) task ${name}: ${err}`);
176
- }
177
- }
178
- ++i;
179
- }
180
- await job.finish(true);
181
- return res;
182
- }
183
- async function _dispatchReadJob(name) {
184
- const { found, path, ext } = getFeatureSpec(name, "job");
185
- if (!found) {
186
- return { found: false, job: {} };
187
- }
188
- let jb;
189
- switch (ext) {
190
- case "js":
191
- let { job } = await import(path);
192
- jb = job;
193
- break;
194
- case "yml":
195
- const { data } = await readJob(name);
196
- const res = await _createJobFromSpec(data);
197
- jb = res.job;
198
- break;
199
- default:
200
- throw new Error(`Job extension ${ext} not implemented`);
201
- }
202
- return { found: true, job: jb };
203
- }
204
- async function _createJobFromSpec(spec) {
205
- const job = useAgentJob({
206
- name: spec.name,
207
- title: spec.title,
208
- tasks: []
209
- });
210
- const tasks = {};
211
- for (const t of spec.tasks) {
212
- if (t.type == "action") {
213
- const { found, path, ext } = getFeatureSpec(t.name, "action");
214
- if (!found) {
215
- return { found: false, job: {} };
216
- }
217
- if (ext == "js") {
218
- const { action } = await import(path);
219
- const at = action;
220
- at.type = "action";
221
- tasks[t.name] = at;
222
- }
223
- else if (ext == "mjs") {
224
- const mjsa = await import(path);
225
- const act = createJsAction(mjsa.action);
226
- act.type = "action";
227
- tasks[t.name] = act;
228
- }
229
- else if (ext == "yml") {
230
- const _t = systemAction(path);
231
- _t.type = "action";
232
- tasks[t.name] = _t;
233
- }
234
- else if (ext == "py") {
235
- const _t = pythonAction(path);
236
- _t.type = "action";
237
- tasks[t.name] = _t;
238
- }
239
- }
240
- else {
241
- const { found, path } = getFeatureSpec(t.name, "task");
242
- if (!found) {
243
- return { found: false, job: {} };
244
- }
245
- const res = readTask(path);
246
- if (!res.found) {
247
- throw new Error(`Task ${t.name}, ${path} not found`);
248
- }
249
- const at = taskBuilder.fromYaml(res.ymlTask, "task");
250
- if (t?.chain) {
251
- at.properties = { "chain": true };
252
- }
253
- const tsk = at;
254
- tasks[t.name] = tsk;
255
- }
256
- }
257
- job.tasks = tasks;
258
- return { job: job, found: true };
259
- }
260
- async function readJob(name) {
261
- const { found, path, ext } = getFeatureSpec(name, "job");
262
- if (!found) {
263
- return { found: false, data: {} };
264
- }
265
- if (!fs.existsSync(path)) {
266
- return { data: {}, found: false };
267
- }
268
- const file = fs.readFileSync(path, 'utf8');
269
- const data = YAML.parse(file);
270
- data.name = name;
271
- return { data: data, found: true };
272
- }
273
- export { readJob, executeJobCmd };
@@ -1,4 +0,0 @@
1
- import { NodeReturnType } from "../../interfaces.js";
2
- import { InferenceResult } from "@locallm/types/dist/interfaces.js";
3
- declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<NodeReturnType<InferenceResult>>;
4
- export { executeTaskCmd };
@@ -1,106 +0,0 @@
1
- import { brain, initAgent, taskBuilder } from "../../agent.js";
2
- import { getFeatureSpec } from "../../state/features.js";
3
- import { isChatMode, isDebug, isVerbose } from "../../state/state.js";
4
- import { initTaskConf, initTaskParams, initTaskVars, parseInputOptions, readTask } from "./utils.js";
5
- async function executeTaskCmd(args = [], options = {}) {
6
- await initAgent();
7
- if (isDebug.value) {
8
- console.log("Task args:", args);
9
- console.log("Task options:", options);
10
- }
11
- const isWorkflow = !Array.isArray(args);
12
- let name;
13
- let pr;
14
- if (!isWorkflow) {
15
- name = args.shift();
16
- const _pr = await parseInputOptions(options);
17
- if (!_pr) {
18
- const p = args.shift();
19
- if (p) {
20
- pr = p;
21
- }
22
- else {
23
- throw new Error("Please provide a prompt");
24
- }
25
- }
26
- else {
27
- pr = _pr;
28
- }
29
- }
30
- else {
31
- if (!args.name) {
32
- throw new Error("Provide a task name param");
33
- }
34
- if (!args.prompt) {
35
- throw new Error("Provide a task prompt param");
36
- }
37
- name = args.name;
38
- delete args.name;
39
- pr = args.prompt;
40
- }
41
- const { found, path } = getFeatureSpec(name, "task");
42
- if (!found) {
43
- return { data: {}, error: new Error(`Task ${name} not found`) };
44
- }
45
- const res = readTask(path);
46
- if (!res.found) {
47
- throw new Error(`Task ${name}, ${path} not found`);
48
- }
49
- const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
50
- const task = taskBuilder.fromYaml(res.ymlTask);
51
- let conf = {};
52
- let vars = {};
53
- if (!isWorkflow) {
54
- const tv = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
55
- conf = tv.conf;
56
- vars = tv.vars;
57
- }
58
- else {
59
- const tv = initTaskParams(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
60
- conf = tv.conf;
61
- vars = tv.vars;
62
- }
63
- conf = initTaskConf(conf, taskSpec);
64
- if (isDebug.value) {
65
- console.log("Task conf:", conf);
66
- console.log("Task vars:", vars);
67
- }
68
- const ex = brain.getOrCreateExpertForModel(conf.model.name, conf.model.template);
69
- if (!ex) {
70
- throw new Error("No expert found for model " + conf.model.name);
71
- }
72
- ex.checkStatus();
73
- let i = 0;
74
- ex.backend.setOnToken((t) => {
75
- if (i == 0) {
76
- if (t == "\n\n") {
77
- return;
78
- }
79
- }
80
- ++i;
81
- process.stdout.write(t);
82
- });
83
- conf.expert = ex;
84
- if (isDebug.value || isVerbose.value) {
85
- conf.debug = true;
86
- }
87
- let ir;
88
- try {
89
- ir = await task.run({ prompt: pr, ...vars }, conf);
90
- }
91
- catch (err) {
92
- throw new Error(`Error executing task: ${name} ${err}`);
93
- }
94
- conf.prompt = pr;
95
- if (isChatMode.value) {
96
- if (brain.ex.name != ex.name) {
97
- brain.setDefaultExpert(ex);
98
- }
99
- brain.ex.template.pushToHistory({ user: pr, assistant: ir.text });
100
- }
101
- if (isDebug.value) {
102
- console.log("\n", ir.stats);
103
- }
104
- return { data: ir };
105
- }
106
- export { executeTaskCmd };