@agent-smith/cli 0.0.39 → 0.0.41

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} +15 -25
  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
@@ -1,17 +1,18 @@
1
- import { formatMode, isChatMode, isDebug, promptfile } from "../../state/state.js";
1
+ import { formatMode, isChatMode, isDebug, promptfilePath, runMode } 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";
5
5
  import { processConfPath } from "../../conf.js";
6
- import { executeActionCmd } from "../lib/execute_action.js";
6
+ import { executeActionCmd } from "../lib/actions/cmd.js";
7
7
  import { initAgent, marked, taskBuilder } from "../../agent.js";
8
- import { executeJobCmd, readJob } from "../lib/execute_job.js";
9
- import { executeTaskCmd } from "../lib/execute_task.js";
8
+ import { executeTaskCmd } from "../lib/tasks/cmd.js";
10
9
  import { readCmds } from "../sys/read_cmds.js";
11
- import { readTask } from "../lib/utils.js";
12
10
  import { executeWorkflowCmd } from "../lib/workflows/cmd.js";
11
+ import { readTask } from "../sys/read_task.js";
12
+ import { deleteFileIfExists } from "../sys/reset.js";
13
+ import { dbPath } from "../../db/db.js";
13
14
  let cmds = {
14
- q: {
15
+ exit: {
15
16
  cmd: async () => process.exit(0),
16
17
  description: "exit the cli"
17
18
  },
@@ -28,20 +29,10 @@ let cmds = {
28
29
  description: "read a task",
29
30
  args: "arguments: \n-task (required): the task name"
30
31
  },
31
- rj: {
32
- cmd: _readJobCmd,
33
- description: "read a job",
34
- args: "arguments: \n-job (required): the job name"
35
- },
36
32
  t: {
37
33
  cmd: _executeTaskCmd,
38
34
  description: "execute a task",
39
35
  },
40
- j: {
41
- cmd: _executeJobCmd,
42
- description: "execute a job",
43
- args: "arguments: \n-job (required): the job name\n-args: arguments if any for the job"
44
- },
45
36
  w: {
46
37
  cmd: _executeWorkflowCmd,
47
38
  description: "execute a workflow",
@@ -57,6 +48,10 @@ let cmds = {
57
48
  description: "process config file",
58
49
  args: "arguments: \n-path (required): the path to the config.yml file"
59
50
  },
51
+ reset: {
52
+ cmd: _resetDbCmd,
53
+ description: "reset the config database",
54
+ },
60
55
  };
61
56
  function initAliases() {
62
57
  const aliases = readAliases();
@@ -75,11 +70,6 @@ function initAliases() {
75
70
  description: "action: " + alias.name,
76
71
  };
77
72
  break;
78
- case "job":
79
- _cmds[alias.name] = {
80
- cmd: (args = [], options) => _executeJobCmd([alias.name, ...args], options),
81
- description: "job: " + alias.name,
82
- };
83
73
  case "workflow":
84
74
  _cmds[alias.name] = {
85
75
  cmd: (args = [], options) => _executeWorkflowCmd([alias.name, ...args], options),
@@ -108,7 +98,7 @@ async function _updateConfCmd(args = [], options) {
108
98
  const { paths, pf } = await processConfPath(args[0]);
109
99
  if (pf.length > 0) {
110
100
  updatePromptfilePath(pf);
111
- promptfile.value = pf;
101
+ promptfilePath.value = pf;
112
102
  }
113
103
  const feats = readFeaturesDirs(paths);
114
104
  updateFeatures(feats);
@@ -118,41 +108,29 @@ async function _updateConfCmd(args = [], options) {
118
108
  console.log("- [feature path]", el);
119
109
  }
120
110
  }
121
- async function _readJobCmd(args = [], options) {
122
- if (args.length == 0) {
123
- console.warn("Provide a job name");
111
+ async function _resetDbCmd(args = [], options) {
112
+ if (runMode.value == "cli") {
113
+ console.log("This command can not be run in cli mode");
124
114
  return;
125
115
  }
126
- const t = await readJob(args[0]);
127
- console.log(t.data);
116
+ deleteFileIfExists(dbPath);
117
+ console.log("Config database reset ok. Run the conf command to recreate it");
128
118
  }
129
119
  async function _executeTaskCmd(args = [], options) {
130
120
  if (args.length == 0) {
131
121
  console.warn("Provide a task name");
132
122
  return;
133
123
  }
134
- const { data, error } = await executeTaskCmd(args, options);
135
- if (error) {
136
- console.warn(error);
137
- }
124
+ const res = await executeTaskCmd(args, options);
138
125
  if (formatMode.value == "markdown") {
139
126
  console.log("\n------------------\n");
140
- console.log(marked.parse(data.text).trim());
127
+ console.log(marked.parse(res.answer.text).trim());
141
128
  }
142
129
  else {
143
130
  console.log();
144
131
  }
145
132
  if (isChatMode.value) {
146
133
  }
147
- return data;
148
- }
149
- async function _executeJobCmd(args = [], options) {
150
- if (args.length == 0) {
151
- console.warn("Provide a job name");
152
- return;
153
- }
154
- const name = args.shift();
155
- const res = await executeJobCmd(name, args, options);
156
134
  return res;
157
135
  }
158
136
  async function _executeWorkflowCmd(args = [], options) {
@@ -1,4 +1,4 @@
1
- import { formatMode, inputMode, isChatMode, isDebug, isVerbose, outputMode, runMode } from "../../state/state.js";
1
+ import { formatMode, inputMode, isChatMode, isDebug, isShowTokens, isVerbose, outputMode, runMode } from "../../state/state.js";
2
2
  const modes = {
3
3
  "-d": {
4
4
  cmd: async () => {
@@ -9,20 +9,29 @@ const modes = {
9
9
  },
10
10
  description: "use debug mode",
11
11
  },
12
+ "-t": {
13
+ cmd: async () => {
14
+ isShowTokens.value = !isShowTokens.value;
15
+ if (runMode.value == "cli") {
16
+ console.log("Show tokens mode is", isShowTokens.value ? "on" : "off");
17
+ }
18
+ },
19
+ description: "use verbose mode",
20
+ },
12
21
  "-v": {
13
22
  cmd: async () => {
14
- isVerbose.value = true;
23
+ isVerbose.value = !isVerbose.value;
15
24
  if (runMode.value == "cli") {
16
- console.log("Verbose mode is on");
25
+ console.log("Verbose mode is", isVerbose.value ? "on" : "off");
17
26
  }
18
27
  },
19
28
  description: "use verbose mode",
20
29
  },
21
30
  "-c": {
22
31
  cmd: async () => {
23
- isChatMode.value = true;
32
+ isChatMode.value = !isChatMode;
24
33
  if (runMode.value == "cli") {
25
- console.log("Chat mode is on");
34
+ console.log("Chat mode is", isChatMode.value ? "on" : "off");
26
35
  }
27
36
  },
28
37
  description: "use chat mode for tasks",
@@ -1,7 +1,7 @@
1
1
  import { Command } from "commander";
2
2
  declare function chat(): Promise<void>;
3
3
  declare function initCliCmds(): Promise<void>;
4
- declare function runCmd(cmdName: string, args?: Array<string>): Promise<void>;
4
+ declare function runCmd(cmdName: string, args?: Array<string>, options?: any): Promise<void>;
5
5
  declare function buildCmds(): Promise<Command>;
6
6
  declare function parseCmd(): Promise<void>;
7
7
  export { buildCmds, chat, initCliCmds, parseCmd, runCmd };
package/dist/cmd/cmds.js CHANGED
@@ -30,13 +30,13 @@ async function initCliCmds() {
30
30
  const _alias = initAliases();
31
31
  cliCmds = { ..._cmds, ..._alias };
32
32
  }
33
- async function runCmd(cmdName, args = []) {
33
+ async function runCmd(cmdName, args = [], options = {}) {
34
34
  if (!(cmdName in cliCmds)) {
35
35
  console.log(`Command ${cmdName} not found`);
36
36
  return;
37
37
  }
38
38
  const cmd = cliCmds[cmdName].cmd;
39
- await cmd(args, {});
39
+ await cmd(args, options);
40
40
  lastCmd.name = cmdName;
41
41
  lastCmd.args = args;
42
42
  }
@@ -1,6 +1,6 @@
1
1
  import { AgentTask } from "@agent-smith/jobs";
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, Array<string>, NodeReturnType<string | Record<string, any> | Array<any>>>;
5
- declare function executeActionCmd(args?: Array<string> | Record<string, any>, options?: any, quiet?: boolean): Promise<NodeReturnType<any>>;
2
+ import { FeatureType } from "../../../interfaces.js";
3
+ declare function systemAction(path: string): AgentTask<FeatureType, Array<string>, any>;
4
+ declare function pythonAction(path: string): AgentTask<FeatureType, Array<string>>;
5
+ declare function executeActionCmd(args?: Array<string> | Record<string, any>, options?: any, quiet?: boolean): Promise<any>;
6
6
  export { executeActionCmd, systemAction, pythonAction };
@@ -1,10 +1,11 @@
1
1
  import { useAgentTask } from "@agent-smith/jobs";
2
- import { getFeatureSpec } from '../../state/features.js';
3
- import { readYmlAction } from "../sys/read_yml_action.js";
4
- import { execute } from "../sys/execute.js";
5
- import { runPyScript } from "../sys/run_python.js";
6
- import { pyShell } from "../../state/state.js";
7
- import { createJsAction, parseInputOptions, processOutput } from "./utils.js";
2
+ import { getFeatureSpec } from '../../../state/features.js';
3
+ import { readYmlAction } from "../../sys/read_yml_action.js";
4
+ import { execute } from "../../sys/execute.js";
5
+ import { runPyScript } from "../../sys/run_python.js";
6
+ import { pyShell } from "../../../state/state.js";
7
+ import { processOutput } from "../utils.js";
8
+ import { createJsAction } from "./read.js";
8
9
  function systemAction(path) {
9
10
  const action = useAgentTask({
10
11
  id: "system_action",
@@ -27,15 +28,17 @@ function pythonAction(path) {
27
28
  run: async (args) => {
28
29
  const { data, error } = await runPyScript(pyShell, "python3", path, args);
29
30
  if (error) {
30
- return { data: {}, error: error };
31
+ throw new Error(`python error: ${error}`);
31
32
  }
32
33
  const txt = data.join("\n");
33
34
  let final = txt;
34
35
  if (txt.startsWith("{") || txt.startsWith("[")) {
35
- final = JSON.parse(final);
36
+ try {
37
+ final = JSON.parse(txt);
38
+ }
39
+ catch (e) { }
36
40
  }
37
- const res = { data: final };
38
- return res;
41
+ return final;
39
42
  }
40
43
  });
41
44
  return action;
@@ -58,17 +61,8 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
58
61
  throw new Error("Action not found");
59
62
  }
60
63
  let act;
61
- if (!["js", "mjs"].includes(ext)) {
62
- if (isWorkflow) {
63
- throw new Error(`Action ${name} param error: ${typeof args}, ${args}`);
64
- }
65
- }
66
64
  switch (ext) {
67
65
  case "js":
68
- const { action } = await import(path);
69
- act = action;
70
- break;
71
- case "mjs":
72
66
  const mjsa = await import(path);
73
67
  act = createJsAction(mjsa.action);
74
68
  break;
@@ -81,18 +75,14 @@ async function executeActionCmd(args = [], options = {}, quiet = false) {
81
75
  default:
82
76
  throw new Error(`Action ext ${ext} not implemented`);
83
77
  }
84
- const input = await parseInputOptions(options);
85
- if (input) {
86
- args.push(input);
87
- }
88
78
  const res = await act.run(args, options);
89
79
  if (res?.error) {
90
80
  throw res.error;
91
81
  }
92
82
  if (!quiet) {
93
- console.log(res.data);
83
+ console.log(res);
94
84
  }
95
85
  await processOutput(res);
96
- return { data: res.data };
86
+ return res;
97
87
  }
98
88
  export { executeActionCmd, systemAction, pythonAction };
@@ -0,0 +1,4 @@
1
+ import { FeatureType } from "../../../interfaces.js";
2
+ import { AgentTask } from "@agent-smith/jobs";
3
+ declare function createJsAction(action: CallableFunction): AgentTask<FeatureType, any, any>;
4
+ export { createJsAction };
@@ -0,0 +1,18 @@
1
+ import { useAgentTask } from "@agent-smith/jobs";
2
+ function createJsAction(action) {
3
+ const task = useAgentTask({
4
+ id: "",
5
+ title: "",
6
+ run: async (args) => {
7
+ try {
8
+ const res = await action(args);
9
+ return res;
10
+ }
11
+ catch (e) {
12
+ throw new Error(`executing action:${e}`);
13
+ }
14
+ }
15
+ });
16
+ return task;
17
+ }
18
+ export { createJsAction };
@@ -0,0 +1,2 @@
1
+ declare function executeAdaptaterCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<any>;
2
+ export { executeAdaptaterCmd, };
@@ -0,0 +1,37 @@
1
+ import { getFeatureSpec } from "../../../state/features.js";
2
+ import { processOutput } from "../utils.js";
3
+ import { createJsAction } from "../actions/read.js";
4
+ async function executeAdaptaterCmd(args = [], options = {}) {
5
+ const isWorkflow = !Array.isArray(args);
6
+ let name;
7
+ if (!isWorkflow) {
8
+ name = args.shift();
9
+ }
10
+ else {
11
+ if (!args.name) {
12
+ throw new Error("provide an adaptater name param");
13
+ }
14
+ name = args.name;
15
+ delete args.name;
16
+ }
17
+ const { found, path } = getFeatureSpec(name, "adaptater");
18
+ if (!found) {
19
+ throw new Error(`adaptater ${name} not found`);
20
+ }
21
+ let act;
22
+ const jsa = await import(path);
23
+ act = createJsAction(jsa.action);
24
+ let res;
25
+ try {
26
+ res = await act.run(args, options);
27
+ }
28
+ catch (e) {
29
+ throw new Error(`adaptater ${name}: ${e}`);
30
+ }
31
+ if (res?.error) {
32
+ throw res.error;
33
+ }
34
+ await processOutput(res);
35
+ return res;
36
+ }
37
+ export { executeAdaptaterCmd, };
@@ -0,0 +1,3 @@
1
+ import { LmTaskOutput } from "@agent-smith/lmtask";
2
+ declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<LmTaskOutput>;
3
+ export { executeTaskCmd };
@@ -0,0 +1,144 @@
1
+ import { brain, initAgent, taskBuilder } from "../../../agent.js";
2
+ import { getFeatureSpec } from "../../../state/features.js";
3
+ import { isChatMode, isDebug, isShowTokens, isVerbose } from "../../../state/state.js";
4
+ import { initTaskConf, initTaskParams, initTaskVars, parseInputOptions } from "../utils.js";
5
+ import { readTask } from "../../sys/read_task.js";
6
+ import { readTool } from "../../../db/read.js";
7
+ import { executeActionCmd, } from "../actions/cmd.js";
8
+ import { executeWorkflowCmd } from "../workflows/cmd.js";
9
+ async function executeTaskCmd(args = [], options = {}) {
10
+ await initAgent();
11
+ if (isDebug.value) {
12
+ console.log("Task args:", args);
13
+ console.log("Task options:", options);
14
+ }
15
+ const isWorkflow = !Array.isArray(args);
16
+ let name;
17
+ let pr;
18
+ if (!isWorkflow) {
19
+ name = args.shift();
20
+ const _pr = await parseInputOptions(options);
21
+ if (!_pr) {
22
+ const p = args.shift();
23
+ if (p) {
24
+ pr = p;
25
+ }
26
+ else {
27
+ throw new Error("Please provide a prompt");
28
+ }
29
+ }
30
+ else {
31
+ pr = _pr;
32
+ }
33
+ }
34
+ else {
35
+ if (!(args?.name)) {
36
+ throw new Error("Provide a task name param");
37
+ }
38
+ if (!(args?.prompt)) {
39
+ throw new Error("Provide a task prompt param");
40
+ }
41
+ name = args.name;
42
+ delete args.name;
43
+ pr = args.prompt;
44
+ delete args.prompt;
45
+ }
46
+ const { found, path } = getFeatureSpec(name, "task");
47
+ if (!found) {
48
+ throw new Error(`Task ${name} not found`);
49
+ }
50
+ const res = readTask(path);
51
+ if (!res.found) {
52
+ throw new Error(`Task ${name}, ${path} not found`);
53
+ }
54
+ const taskSpec = taskBuilder.readFromYaml(res.ymlTask);
55
+ if (taskSpec.toolsList) {
56
+ taskSpec.tools = [];
57
+ for (const toolName of taskSpec.toolsList) {
58
+ const { found, tool, type } = readTool(toolName);
59
+ const lmTool = {
60
+ ...tool,
61
+ execute: async (name, args) => {
62
+ switch (type) {
63
+ case "action":
64
+ const res = await executeActionCmd([name, ...Object.values(args)], options, true);
65
+ return res;
66
+ case "task":
67
+ const tres = await executeTaskCmd([name, args], options);
68
+ return tres;
69
+ case "workflow":
70
+ const wres = await executeWorkflowCmd(name, ...Object.values(args), options);
71
+ return wres;
72
+ default:
73
+ throw new Error(`unknown tool execution function type: ${type}`);
74
+ }
75
+ }
76
+ };
77
+ if (!found) {
78
+ console.warn(`Problem: tool ${toolName} not found for task ${taskSpec.name}`);
79
+ continue;
80
+ }
81
+ taskSpec.tools.push(lmTool);
82
+ }
83
+ delete taskSpec.toolsList;
84
+ }
85
+ ;
86
+ const task = taskBuilder.init(taskSpec);
87
+ let conf = {};
88
+ let vars = {};
89
+ if (!isWorkflow) {
90
+ const tv = initTaskVars(args, taskSpec?.inferParams ? taskSpec.inferParams : {});
91
+ conf = tv.conf;
92
+ vars = tv.vars;
93
+ }
94
+ else {
95
+ const tv = initTaskParams({ name: name, prompt: pr, ...args }, taskSpec?.inferParams ? taskSpec.inferParams : {});
96
+ conf = tv.conf;
97
+ vars = tv.vars;
98
+ }
99
+ conf = initTaskConf(conf, taskSpec);
100
+ if (isDebug.value) {
101
+ console.log("Task conf:", conf);
102
+ console.log("Task vars:", vars);
103
+ }
104
+ const ex = brain.getOrCreateExpertForModel(conf.model.name, conf.model.template);
105
+ if (!ex) {
106
+ throw new Error("No expert found for model " + conf.model.name);
107
+ }
108
+ ex.checkStatus();
109
+ let i = 0;
110
+ let c = false;
111
+ ex.backend.setOnToken((t) => {
112
+ let txt = t;
113
+ if (isShowTokens.value) {
114
+ txt = c ? t : `\x1b[100m${t}\x1b[0m`;
115
+ }
116
+ process.stdout.write(txt);
117
+ ++i;
118
+ c = !c;
119
+ });
120
+ conf.expert = ex;
121
+ if (isDebug.value || isVerbose.value) {
122
+ conf.debug = true;
123
+ }
124
+ let out;
125
+ try {
126
+ out = await task.run({ prompt: pr, ...vars }, conf);
127
+ console.log();
128
+ }
129
+ catch (err) {
130
+ throw new Error(`Error executing task: ${name} ${err}`);
131
+ }
132
+ conf.prompt = pr;
133
+ if (isChatMode.value) {
134
+ if (brain.ex.name != ex.name) {
135
+ brain.setDefaultExpert(ex);
136
+ }
137
+ brain.ex.template.pushToHistory({ user: pr, assistant: out.answer.text });
138
+ }
139
+ if (isDebug.value) {
140
+ console.log("\n", out.answer.stats);
141
+ }
142
+ return out;
143
+ }
144
+ export { executeTaskCmd };
@@ -0,0 +1,6 @@
1
+ import { FeatureExtension } from '../../interfaces.js';
2
+ declare function extractToolDoc(name: string, ext: FeatureExtension, dirPath: string): {
3
+ found: boolean;
4
+ toolDoc: string;
5
+ };
6
+ export { extractToolDoc, };
@@ -0,0 +1,76 @@
1
+ import YAML from 'yaml';
2
+ import * as fs from 'fs';
3
+ function _extractToolDoc(filePath, startComment, endComment) {
4
+ try {
5
+ const fileContent = fs.readFileSync(filePath, 'utf-8');
6
+ const startMarker = startComment + '\n# tool';
7
+ if (!fileContent.startsWith(startMarker)) {
8
+ return { found: false, doc: "" };
9
+ }
10
+ const endMarker = endComment;
11
+ const startIndex = fileContent.indexOf(startMarker) + startMarker.length;
12
+ const endIndex = fileContent.indexOf(endMarker, startIndex);
13
+ if (endIndex === -1) {
14
+ throw new Error(`Markers not found in the file: ${filePath}`);
15
+ }
16
+ const extractedContent = fileContent.substring(startIndex, endIndex).trim();
17
+ return { found: true, doc: extractedContent };
18
+ }
19
+ catch (error) {
20
+ if (error instanceof Error) {
21
+ if (error.message.includes('ENOENT')) {
22
+ throw new Error(`File not found: ${filePath}`);
23
+ }
24
+ else {
25
+ throw new Error(`Error processing the file: ${filePath}. ${error.message}`);
26
+ }
27
+ }
28
+ else {
29
+ throw new Error(`An unexpected error occurred: ${error}`);
30
+ }
31
+ }
32
+ }
33
+ function _extractPyToolDoc(filePath) {
34
+ return _extractToolDoc(filePath, '"""', '"""');
35
+ }
36
+ function _extractJsToolDoc(filePath) {
37
+ return _extractToolDoc(filePath, '/*', '*/');
38
+ }
39
+ function _parseToolDoc(rawTxt, name) {
40
+ try {
41
+ const res = YAML.parse(rawTxt);
42
+ res["name"] = name;
43
+ return res;
44
+ }
45
+ catch (e) {
46
+ throw new Error(`Error parsing tool ${name}: data:\n${rawTxt}\n`);
47
+ }
48
+ }
49
+ function extractToolDoc(name, ext, dirPath) {
50
+ let spec;
51
+ let found = false;
52
+ let doc;
53
+ switch (ext) {
54
+ case "py":
55
+ let res = _extractPyToolDoc(dirPath + "/" + name + "." + ext);
56
+ found = res.found;
57
+ doc = res.doc;
58
+ break;
59
+ case "js":
60
+ let res2 = _extractJsToolDoc(dirPath + "/" + name + "." + ext);
61
+ found = res2.found;
62
+ doc = res2.doc;
63
+ break;
64
+ default:
65
+ return { found: false, toolDoc: "" };
66
+ }
67
+ if (found) {
68
+ const ts = _parseToolDoc(doc, name);
69
+ spec = JSON.stringify(ts, null, " ");
70
+ }
71
+ else {
72
+ return { found: false, toolDoc: "" };
73
+ }
74
+ return { found: true, toolDoc: spec };
75
+ }
76
+ export { extractToolDoc, };
@@ -1,14 +1,7 @@
1
- import { AgentTask } from "@agent-smith/jobs";
2
- import { LmTask } from "@agent-smith/lmtask";
3
- import { FeatureType, NodeReturnType } from "../../interfaces.js";
1
+ import { LmTask } from "../../../../lmtask/dist/interfaces.js";
4
2
  declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
5
3
  declare function readPromptFile(): string;
6
4
  declare function processOutput(res: any): Promise<void>;
7
- declare function readTask(taskpath: string): {
8
- found: boolean;
9
- ymlTask: string;
10
- };
11
- declare function readTasksDir(dir: string): Array<string>;
12
5
  declare function initTaskConf(conf: Record<string, any>, taskSpec: LmTask): Record<string, any>;
13
6
  declare function initTaskParams(params: Record<string, any>, inferParams: Record<string, any>): {
14
7
  conf: Record<string, any>;
@@ -20,5 +13,4 @@ declare function initTaskVars(args: Array<any>, inferParams: Record<string, any>
20
13
  vars: Record<string, any>;
21
14
  };
22
15
  declare function parseInputOptions(options: any): Promise<string | null>;
23
- declare function createJsAction(action: CallableFunction): AgentTask<FeatureType, any, NodeReturnType<any>>;
24
- export { createJsAction, initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, readTask, readTasksDir, setOptions };
16
+ export { initTaskConf, initTaskParams, initTaskVars, initActionVars, parseInputOptions, processOutput, readPromptFile, setOptions };