@agent-smith/cli 0.0.36 → 0.0.37

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.
@@ -1,4 +1,4 @@
1
- import { formatMode, isChatMode, promptfile } from "../../state/state.js";
1
+ import { formatMode, isChatMode, isDebug, promptfile } from "../../state/state.js";
2
2
  import { getFeatureSpec, readFeaturesDirs } from "../../state/features.js";
3
3
  import { readAliases, readFeatures } from "../../db/read.js";
4
4
  import { cleanupFeaturePaths, updateAliases, updateFeatures, updatePromptfilePath } from "../../db/write.js";
@@ -86,7 +86,7 @@ async function initCmds() {
86
86
  return cmds;
87
87
  }
88
88
  async function pingCmd(args = [], options) {
89
- const isUp = await initAgent(true);
89
+ const isUp = await initAgent(isDebug.value);
90
90
  return isUp;
91
91
  }
92
92
  async function _updateConfCmd(args = [], options) {
@@ -120,13 +120,13 @@ async function _executeTaskCmd(args = [], options) {
120
120
  console.warn("Provide a task name");
121
121
  return;
122
122
  }
123
- const { ok, data, conf, error } = await executeTaskCmd(args, options);
124
- if (!ok) {
123
+ const { data, error } = await executeTaskCmd(args, options);
124
+ if (error) {
125
125
  console.warn(error);
126
126
  }
127
127
  if (formatMode.value == "markdown") {
128
128
  console.log("\n------------------\n");
129
- console.log(marked.parse(data).trim());
129
+ console.log(marked.parse(data.text).trim());
130
130
  }
131
131
  else {
132
132
  console.log();
@@ -1,6 +1,6 @@
1
1
  import { AgentTask } from "@agent-smith/jobs";
2
- import { FeatureType } from "../../interfaces.js";
3
- declare function systemAction(path: string): AgentTask<FeatureType>;
4
- declare function pythonAction(path: string): AgentTask<FeatureType>;
5
- declare function executeActionCmd(args?: Array<string>, options?: any, quiet?: boolean): Promise<any>;
2
+ import { FeatureType, NodeReturnType } from "../../interfaces.js";
3
+ declare function systemAction(path: string): AgentTask<FeatureType, Array<string>, NodeReturnType<string>>;
4
+ declare function pythonAction(path: string): AgentTask<FeatureType, any, NodeReturnType<string | Record<string, any> | Array<any>>>;
5
+ declare function executeActionCmd(args?: Array<string>, options?: any, quiet?: boolean): Promise<NodeReturnType<any>>;
6
6
  export { executeActionCmd, systemAction, pythonAction };
@@ -15,7 +15,7 @@ function systemAction(path) {
15
15
  actionSpec.data.args = [];
16
16
  }
17
17
  const out = await execute(actionSpec.data.cmd, [...actionSpec.data.args, ...args]);
18
- return { data: out.trim(), error: "", ok: true };
18
+ return { data: out.trim() };
19
19
  }
20
20
  });
21
21
  return action;
@@ -25,13 +25,17 @@ function pythonAction(path) {
25
25
  id: "python_action",
26
26
  title: "",
27
27
  run: async (args) => {
28
- const out = await runPyScript(pyShell, "python3", path, args);
29
- const txt = out.join("\n");
30
- let data = txt;
28
+ const { data, error } = await runPyScript(pyShell, "python3", path, args);
29
+ if (error) {
30
+ return { data: {}, error: error };
31
+ }
32
+ const txt = data.join("\n");
33
+ let final = txt;
31
34
  if (txt.startsWith("{") || txt.startsWith("[")) {
32
- data = JSON.parse(data);
35
+ final = JSON.parse(final);
33
36
  }
34
- return { data: data, error: "", ok: true };
37
+ const res = { data: final };
38
+ return res;
35
39
  }
36
40
  });
37
41
  return action;
@@ -40,7 +44,7 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
40
44
  const name = args.shift();
41
45
  const { found, path, ext } = getFeatureSpec(name, "action");
42
46
  if (!found) {
43
- return { ok: false, data: {}, error: "Action not found" };
47
+ throw new Error("Action not found");
44
48
  }
45
49
  let act;
46
50
  switch (ext) {
@@ -66,10 +70,13 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
66
70
  args.push(input);
67
71
  }
68
72
  const res = await act.run(args, {});
73
+ if (res?.error) {
74
+ throw res.error;
75
+ }
69
76
  if (!quiet) {
70
77
  console.log(res.data);
71
78
  }
72
79
  await processOutput(res);
73
- return { ok: true, data: res.data, error: "" };
80
+ return { data: res.data };
74
81
  }
75
82
  export { executeActionCmd, systemAction, pythonAction };
@@ -12,8 +12,7 @@ async function executeJobCmd(name, args = [], options = {}) {
12
12
  console.log("Running job", name, Object.keys(job.tasks).length, "tasks");
13
13
  }
14
14
  if (!found) {
15
- console.log(`Job ${name} not found`);
16
- return { error: `Job ${name} not found` };
15
+ throw new Error(`Job ${name} not found`);
17
16
  }
18
17
  await job.start();
19
18
  let res = {};
@@ -26,7 +25,7 @@ async function executeJobCmd(name, args = [], options = {}) {
26
25
  const chain = task.properties?.chain;
27
26
  const { found, path } = getFeatureSpec(name, "task");
28
27
  if (!found) {
29
- return { ok: false, data: {}, error: `Task ${name} not found` };
28
+ throw new Error(`Task ${name} not found`);
30
29
  }
31
30
  const tres = readTask(path);
32
31
  if (!tres.found) {
@@ -154,6 +153,9 @@ async function executeJobCmd(name, args = [], options = {}) {
154
153
  }
155
154
  try {
156
155
  res = await job.runTask(name, _p, options);
156
+ if (res?.error) {
157
+ throw new Error(`Error executing job action ${res.error}`);
158
+ }
157
159
  }
158
160
  catch (e) {
159
161
  throw new Error(`Error executing job action ${e}`);
@@ -170,7 +172,7 @@ async function executeJobCmd(name, args = [], options = {}) {
170
172
  params = { ...res.data, ...nextParams };
171
173
  }
172
174
  catch (err) {
173
- return { error: `Error executing (${task.type}) task ${name}: ${err}` };
175
+ throw new Error(`Error executing (${task.type}) task ${name}: ${err}`);
174
176
  }
175
177
  }
176
178
  ++i;
@@ -248,7 +250,8 @@ async function _createJobFromSpec(spec) {
248
250
  if (t?.chain) {
249
251
  at.properties = { "chain": true };
250
252
  }
251
- tasks[t.name] = at;
253
+ const tsk = at;
254
+ tasks[t.name] = tsk;
252
255
  }
253
256
  }
254
257
  job.tasks = tasks;
@@ -1,2 +1,4 @@
1
- declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<any>;
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>>;
2
4
  export { executeTaskCmd };
@@ -37,11 +37,10 @@ async function executeTaskCmd(args = [], options = {}) {
37
37
  name = args.name;
38
38
  delete args.name;
39
39
  pr = args.prompt;
40
- delete args.prompt;
41
40
  }
42
41
  const { found, path } = getFeatureSpec(name, "task");
43
42
  if (!found) {
44
- return { ok: false, data: "", conf: {}, error: `Task ${name} not found` };
43
+ return { data: {}, error: new Error(`Task ${name} not found`) };
45
44
  }
46
45
  const res = readTask(path);
47
46
  if (!res.found) {
@@ -85,17 +84,21 @@ async function executeTaskCmd(args = [], options = {}) {
85
84
  if (isDebug.value) {
86
85
  conf.debug = true;
87
86
  }
88
- const data = await task.run({ prompt: pr, ...vars }, conf);
89
- if (data?.error) {
90
- return { ok: false, data: "", conf: conf, error: `Error executing task: ${name} ${data.error}` };
87
+ const fres = await task.run({ prompt: pr, ...vars }, conf);
88
+ if (fres.error) {
89
+ throw new Error(`Error executing task: ${name} ${fres.data.error}`);
91
90
  }
92
91
  conf.prompt = pr;
93
92
  if (isChatMode.value) {
94
93
  if (brain.ex.name != ex.name) {
95
94
  brain.setDefaultExpert(ex);
96
95
  }
97
- brain.ex.template.pushToHistory({ user: pr, assistant: data.text });
96
+ brain.ex.template.pushToHistory({ user: pr, assistant: fres.text });
98
97
  }
99
- return { ok: true, data: data.text, conf: conf, error: "" };
98
+ const ir = fres;
99
+ if (isDebug.value) {
100
+ console.log("\n", ir.stats);
101
+ }
102
+ return { data: ir };
100
103
  }
101
104
  export { executeTaskCmd };
@@ -1,6 +1,6 @@
1
- import { AgentTask } from "@agent-smith/jobs/dist/jobsinterfaces.js";
1
+ import { AgentTask } from "@agent-smith/jobs";
2
2
  import { LmTask } from "@agent-smith/lmtask";
3
- import { FeatureType } from "../../interfaces.js";
3
+ import { FeatureType, NodeReturnType } from "../../interfaces.js";
4
4
  declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
5
5
  declare function readPromptFile(): string;
6
6
  declare function processOutput(res: any): Promise<void>;
@@ -20,5 +20,5 @@ declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>
20
20
  vars: Record<string, any>;
21
21
  };
22
22
  declare function parseInputOptions(options: any): Promise<string | null>;
23
- declare function createJsAction(action: CallableFunction): AgentTask<FeatureType>;
23
+ declare function createJsAction(action: CallableFunction): AgentTask<FeatureType, any, NodeReturnType<any>>;
24
24
  export { createJsAction, initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
@@ -44,7 +44,6 @@ async function processOutput(res) {
44
44
  let hasOutput = false;
45
45
  if (res?.data) {
46
46
  data = res.data;
47
- 0;
48
47
  hasOutput = true;
49
48
  }
50
49
  if (res?.text) {
@@ -129,7 +128,7 @@ function initTaskConf(conf, taskSpec) {
129
128
  function initTaskParams(params, inferParams) {
130
129
  const conf = { inferParams: inferParams };
131
130
  if (!params?.prompt) {
132
- throw new Error(`Error initializing task variable: provide a prompt`);
131
+ throw new Error(`Error initializing task params: provide a prompt`);
133
132
  }
134
133
  if (params?.images) {
135
134
  conf.inferParams.images = params.images;
@@ -236,8 +235,14 @@ function createJsAction(action) {
236
235
  id: "",
237
236
  title: "",
238
237
  run: async (args) => {
239
- const res = await action(args);
240
- return { ok: true, data: res };
238
+ try {
239
+ const res = await action(args);
240
+ return { ok: true, data: res };
241
+ }
242
+ catch (e) {
243
+ const err = new Error(`Error executing action ${e}`);
244
+ return { ok: false, data: {}, error: err };
245
+ }
241
246
  }
242
247
  });
243
248
  return task;
@@ -1,3 +1,4 @@
1
+ import { NodeReturnType } from '../../interfaces.js';
1
2
  import { PythonShell } from 'python-shell';
2
- declare function runPyScript(rsShell: PythonShell, pythonPath: string, scriptPath: string, scriptArgs: Array<string>, handleOutputFrom?: "msg" | "stderr", onEmitLine?: CallableFunction): Promise<string[]>;
3
+ declare function runPyScript(rsShell: PythonShell, pythonPath: string, scriptPath: string, scriptArgs: Array<string>, onEmitLine?: CallableFunction): Promise<NodeReturnType<Array<string>>>;
3
4
  export { runPyScript };
@@ -1,5 +1,5 @@
1
1
  import { PythonShell } from 'python-shell';
2
- async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, handleOutputFrom = "msg", onEmitLine) {
2
+ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, onEmitLine) {
3
3
  const _options = {
4
4
  mode: "text",
5
5
  pythonPath: pythonPath,
@@ -9,35 +9,24 @@ async function runPyScript(rsShell, pythonPath, scriptPath, scriptArgs, handleOu
9
9
  let promiseResolve;
10
10
  let promise = new Promise((resolve) => promiseResolve = resolve);
11
11
  rsShell = new PythonShell(scriptPath, _options);
12
- const msgs = new Array();
12
+ const res = { data: new Array() };
13
13
  function handleLine(msg) {
14
14
  if (onEmitLine) {
15
15
  onEmitLine(msg);
16
16
  }
17
- msgs.push(msg);
17
+ res.data.push(msg);
18
18
  }
19
19
  rsShell.on('message', function (message) {
20
- if (handleOutputFrom == "msg") {
21
- handleLine(message);
22
- }
23
- });
24
- rsShell.on('stderr', function (err) {
25
- console.log("STDERR", err);
26
- if (handleOutputFrom == "stderr") {
27
- handleLine(err);
28
- }
29
- else {
30
- promiseResolve(true);
31
- }
20
+ handleLine(message);
32
21
  });
33
22
  rsShell.on('pythonError', function (err) {
34
23
  console.log("PYERR", `${err.message}, ${err.traceback}`);
35
- promiseResolve(true);
24
+ res.error = new Error(err.traceback.toString());
36
25
  });
37
26
  rsShell.end(function (err, code, signal) {
38
27
  promiseResolve(true);
39
28
  });
40
29
  await promise;
41
- return msgs;
30
+ return res;
42
31
  }
43
32
  export { runPyScript };
@@ -35,6 +35,10 @@ interface ConfigFile {
35
35
  features?: Array<string>;
36
36
  plugins?: Array<string>;
37
37
  }
38
+ interface NodeReturnType<T = Record<string, any>> {
39
+ data: T;
40
+ error?: Error;
41
+ }
38
42
  type CmdExecutor = (args: Array<string>, options: any) => Promise<any>;
39
43
  type InputMode = "manual" | "promptfile" | "clipboard";
40
44
  type OutputMode = "txt" | "clipboard";
@@ -47,4 +51,4 @@ type JobExtension = "yml";
47
51
  type CmdExtension = "js";
48
52
  type FeatureExtension = TaskExtension | JobExtension | CmdExtension | ActionExtension;
49
53
  type AliasType = "task" | "action" | "job";
50
- export { Cmd, CmdExecutor, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, JobExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, };
54
+ export { Cmd, CmdExecutor, NodeReturnType, InputMode, OutputMode, RunMode, FormatMode, FeatureType, ActionExtension, TaskExtension, JobExtension, CmdExtension, FeatureSpec, Features, ConfigFile, FeatureExtension, AliasType, };
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.36",
5
+ "version": "0.0.37",
6
6
  "scripts": {
7
7
  "buildrl": "rm -rf dist/* && rollup -c",
8
8
  "build": "rm -rf dist/* && tsc --noCheck",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@agent-smith/brain": "^0.0.38",
14
- "@agent-smith/jobs": "^0.0.12",
15
- "@agent-smith/lmtask": "^0.0.30",
14
+ "@agent-smith/jobs": "^0.0.13",
15
+ "@agent-smith/lmtask": "^0.0.31",
16
16
  "@agent-smith/tfm": "^0.1.1",
17
17
  "@inquirer/prompts": "^7.3.3",
18
18
  "@inquirer/select": "^4.0.10",
@@ -21,7 +21,7 @@
21
21
  "clipboardy": "^4.0.0",
22
22
  "commander": "^13.1.0",
23
23
  "marked-terminal": "^7.3.0",
24
- "modprompt": "^0.10.3",
24
+ "modprompt": "^0.10.4",
25
25
  "python-shell": "^5.0.0",
26
26
  "yaml": "^2.7.0"
27
27
  },