@agent-smith/cli 0.0.62 → 0.0.64

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 (54) hide show
  1. package/dist/cli.d.ts +2 -1
  2. package/dist/cli.js +7 -48
  3. package/dist/cmd/clicmds/aliases.d.ts +7 -0
  4. package/dist/cmd/clicmds/aliases.js +43 -0
  5. package/dist/cmd/clicmds/base.d.ts +3 -0
  6. package/dist/cmd/clicmds/base.js +94 -0
  7. package/dist/cmd/clicmds/cmds.d.ts +4 -7
  8. package/dist/cmd/clicmds/cmds.js +6 -184
  9. package/dist/cmd/clicmds/update.d.ts +2 -0
  10. package/dist/cmd/clicmds/update.js +46 -0
  11. package/dist/cmd/cmds.d.ts +3 -5
  12. package/dist/cmd/cmds.js +19 -53
  13. package/dist/cmd/lib/actions/cmd.d.ts +3 -2
  14. package/dist/cmd/lib/actions/cmd.js +71 -49
  15. package/dist/cmd/lib/actions/read.js +2 -2
  16. package/dist/cmd/lib/adaptaters/cmd.d.ts +2 -2
  17. package/dist/cmd/lib/adaptaters/cmd.js +3 -15
  18. package/dist/cmd/lib/models.d.ts +1 -1
  19. package/dist/cmd/lib/models.js +8 -6
  20. package/dist/cmd/lib/options_parsers.d.ts +7 -0
  21. package/dist/cmd/lib/options_parsers.js +41 -0
  22. package/dist/cmd/lib/tasks/cmd.d.ts +3 -2
  23. package/dist/cmd/lib/tasks/cmd.js +83 -62
  24. package/dist/cmd/lib/tools.d.ts +8 -1
  25. package/dist/cmd/lib/tools.js +31 -1
  26. package/dist/cmd/lib/utils.d.ts +1 -2
  27. package/dist/cmd/lib/utils.js +1 -23
  28. package/dist/cmd/lib/workflows/cmd.d.ts +3 -2
  29. package/dist/cmd/lib/workflows/cmd.js +21 -27
  30. package/dist/cmd/options.d.ts +8 -0
  31. package/dist/cmd/options.js +62 -0
  32. package/dist/cmd/sys/read_cmds.d.ts +2 -2
  33. package/dist/cmd/sys/read_cmds.js +2 -2
  34. package/dist/db/db.d.ts +1 -1
  35. package/dist/db/db.js +3 -2
  36. package/dist/db/read.d.ts +3 -2
  37. package/dist/db/read.js +18 -12
  38. package/dist/db/schemas.js +12 -6
  39. package/dist/db/write.js +30 -13
  40. package/dist/index.js +14 -8
  41. package/dist/interfaces.d.ts +5 -6
  42. package/dist/main.d.ts +6 -6
  43. package/dist/main.js +6 -6
  44. package/dist/state/state.d.ts +2 -7
  45. package/dist/state/state.js +3 -11
  46. package/dist/utils/perf.d.ts +1 -1
  47. package/dist/utils/perf.js +6 -6
  48. package/dist/utils/user_msgs.d.ts +5 -0
  49. package/dist/utils/user_msgs.js +17 -0
  50. package/package.json +10 -11
  51. package/dist/cmd/clicmds/modes.d.ts +0 -3
  52. package/dist/cmd/clicmds/modes.js +0 -95
  53. package/dist/utils/args.d.ts +0 -7
  54. package/dist/utils/args.js +0 -85
@@ -5,24 +5,74 @@ import { execute } from "../../sys/execute.js";
5
5
  import { runPyScript } from "../../sys/run_python.js";
6
6
  import { pyShell } from "../../../state/state.js";
7
7
  import { createJsAction } from "./read.js";
8
+ import { runtimeError } from "../../../utils/user_msgs.js";
9
+ import { readClipboard } from "../../sys/clipboard.js";
10
+ import { processOutput, readPromptFile } from "../utils.js";
11
+ import { parseCommandArgs } from "../options_parsers.js";
12
+ async function executeAction(name, payload, options, quiet = false) {
13
+ let act;
14
+ const { found, path, ext } = getFeatureSpec(name, "action");
15
+ if (!found) {
16
+ throw new Error(`Action ${name} not found at ${path}`);
17
+ }
18
+ switch (ext) {
19
+ case "js":
20
+ const mjsa = await import(path);
21
+ act = createJsAction(mjsa.action);
22
+ break;
23
+ case "yml":
24
+ act = systemAction(path);
25
+ break;
26
+ case "py":
27
+ act = pythonAction(path);
28
+ break;
29
+ default:
30
+ throw new Error(`Action ext ${ext} not implemented`);
31
+ }
32
+ const res = await act.run(payload, options);
33
+ if (!quiet) {
34
+ if (res) {
35
+ console.log(res);
36
+ }
37
+ }
38
+ await processOutput(res);
39
+ return res;
40
+ }
41
+ async function executeActionCmd(name, aargs, quiet = false) {
42
+ const { args, options } = parseCommandArgs(aargs);
43
+ const params = { args: args };
44
+ if (options?.clipBoardInput) {
45
+ params.args.push(await readClipboard());
46
+ }
47
+ else if (options?.inputFile) {
48
+ params.args.push(readPromptFile());
49
+ }
50
+ if (options?.debug) {
51
+ console.log("Action", name, "params", params);
52
+ }
53
+ return await executeAction(name, params, options, quiet);
54
+ }
8
55
  function systemAction(path) {
9
56
  const action = useAgentTask({
10
57
  id: "system_action",
11
58
  title: "",
12
- run: async (args) => {
59
+ run: async (params) => {
13
60
  let runArgs = new Array();
14
- if (!Array.isArray(args)) {
61
+ if (params?.args) {
62
+ runArgs = params.args;
63
+ }
64
+ else {
15
65
  try {
16
- runArgs = Object.values(args);
66
+ runArgs = Object.values(params);
17
67
  }
18
68
  catch (e) {
19
69
  throw new Error(`wrong system action args: ${e}`);
20
70
  }
21
71
  }
22
- else {
23
- runArgs = args;
24
- }
25
72
  const actionSpec = readYmlFile(path);
73
+ if (!actionSpec.found) {
74
+ runtimeError("System action yml file", path, "not found");
75
+ }
26
76
  if (!actionSpec.data?.args) {
27
77
  actionSpec.data.args = [];
28
78
  }
@@ -36,8 +86,20 @@ function pythonAction(path) {
36
86
  const action = useAgentTask({
37
87
  id: "python_action",
38
88
  title: "",
39
- run: async (args) => {
40
- const { data, error } = await runPyScript(pyShell, "python3", path, args);
89
+ run: async (params) => {
90
+ let runArgs = new Array();
91
+ if (params?.args) {
92
+ runArgs = params.args;
93
+ }
94
+ else {
95
+ try {
96
+ runArgs = Object.values(params);
97
+ }
98
+ catch (e) {
99
+ throw new Error(`wrong python action args: ${e}`);
100
+ }
101
+ }
102
+ const { data, error } = await runPyScript(pyShell, "python3", path, runArgs);
41
103
  if (error) {
42
104
  throw new Error(`python error: ${error}`);
43
105
  }
@@ -58,44 +120,4 @@ function pythonAction(path) {
58
120
  });
59
121
  return action;
60
122
  }
61
- async function executeActionCmd(args = [], options = {}, quiet = false) {
62
- const isWorkflow = !Array.isArray(args);
63
- let name;
64
- if (!isWorkflow) {
65
- name = args.shift();
66
- }
67
- else {
68
- if (!args.name) {
69
- throw new Error("Provide an action name param");
70
- }
71
- name = args.name;
72
- delete args.name;
73
- }
74
- const { found, path, ext } = getFeatureSpec(name, "action");
75
- if (!found) {
76
- throw new Error(`Action ${name} not found at ${path}`);
77
- }
78
- let act;
79
- switch (ext) {
80
- case "js":
81
- const mjsa = await import(path);
82
- act = createJsAction(mjsa.action);
83
- break;
84
- case "yml":
85
- act = systemAction(path);
86
- break;
87
- case "py":
88
- act = pythonAction(path);
89
- break;
90
- default:
91
- throw new Error(`Action ext ${ext} not implemented`);
92
- }
93
- const res = await act.run(args, options);
94
- if (!quiet) {
95
- if (res) {
96
- console.log("ARES", res);
97
- }
98
- }
99
- return res;
100
- }
101
- export { executeActionCmd, systemAction, pythonAction };
123
+ export { executeAction, executeActionCmd, systemAction, pythonAction, };
@@ -3,9 +3,9 @@ function createJsAction(action) {
3
3
  const task = useAgentTask({
4
4
  id: "",
5
5
  title: "",
6
- run: async (args) => {
6
+ run: async (args, options) => {
7
7
  try {
8
- const res = await action(args);
8
+ const res = await action(args, options);
9
9
  return res;
10
10
  }
11
11
  catch (e) {
@@ -1,2 +1,2 @@
1
- declare function executeAdaptaterCmd(args?: Array<string> | Record<string, any>, options?: any): Promise<any>;
2
- export { executeAdaptaterCmd, };
1
+ declare function executeAdaptater(name: string, argsOrParams: Record<string, any> | Array<any>, options: Record<string, any>): Promise<any>;
2
+ export { executeAdaptater, };
@@ -1,18 +1,6 @@
1
1
  import { getFeatureSpec } from "../../../state/features.js";
2
2
  import { createJsAction } from "../actions/read.js";
3
- async function executeAdaptaterCmd(args = [], options = {}) {
4
- const isWorkflow = !Array.isArray(args);
5
- let name;
6
- if (!isWorkflow) {
7
- name = args.shift();
8
- }
9
- else {
10
- if (!args.name) {
11
- throw new Error("provide an adaptater name param");
12
- }
13
- name = args.name;
14
- delete args.name;
15
- }
3
+ async function executeAdaptater(name, argsOrParams, options) {
16
4
  const { found, path } = getFeatureSpec(name, "adaptater");
17
5
  if (!found) {
18
6
  throw new Error(`adaptater ${name} not found`);
@@ -22,7 +10,7 @@ async function executeAdaptaterCmd(args = [], options = {}) {
22
10
  act = createJsAction(jsa.action);
23
11
  let res;
24
12
  try {
25
- res = await act.run(args, options);
13
+ res = await act.run(argsOrParams, options);
26
14
  }
27
15
  catch (e) {
28
16
  throw new Error(`adaptater ${name}: ${e}`);
@@ -32,4 +20,4 @@ async function executeAdaptaterCmd(args = [], options = {}) {
32
20
  }
33
21
  return res;
34
22
  }
35
- export { executeAdaptaterCmd, };
23
+ export { executeAdaptater, };
@@ -1,3 +1,3 @@
1
- declare function showModelsCmd(args: Array<string>, options: any): Promise<void>;
1
+ declare function showModelsCmd(args: Array<string>): Promise<void>;
2
2
  declare function updateAllModels(): void;
3
3
  export { updateAllModels, showModelsCmd, };
@@ -3,19 +3,21 @@ import { readModelfiles, readModels } from "../../db/read.js";
3
3
  import { readModelsFile } from "../sys/read_modelfile.js";
4
4
  import { updateModels as dbUpdateModels } from "../../db/write.js";
5
5
  import color from "ansi-colors";
6
- async function showModelsCmd(args, options) {
6
+ async function showModelsCmd(args) {
7
7
  let models = readModels();
8
8
  models.sort((a, b) => a.name.localeCompare(b.name));
9
+ let foundModels = new Array();
9
10
  if (args.length > 0) {
10
11
  args.forEach((a) => {
11
- models = models.filter((m) => m.shortname.includes(a) || m.name.includes(a));
12
+ const fm = models.filter((m) => m.shortname.includes(a) || m.name.includes(a));
13
+ foundModels.push(...fm);
12
14
  });
13
15
  }
14
- models.forEach((model) => {
16
+ else {
17
+ foundModels = models;
18
+ }
19
+ foundModels.forEach((model) => {
15
20
  const ips = model.data.inferParams;
16
- if (!ips?.max_tokens) {
17
- throw new Error(`no max tokens in ${model.shortname}`);
18
- }
19
21
  const mt = ips.max_tokens;
20
22
  delete ips.max_tokens;
21
23
  const vip = Object.keys(ips).length > 0 ? JSON.stringify(ips) : "";
@@ -0,0 +1,7 @@
1
+ import { LmTaskConfig } from "../../interfaces.js";
2
+ declare function parseCommandArgs(args: Array<any>): {
3
+ args: Array<any>;
4
+ options: Record<string, any>;
5
+ };
6
+ declare function parseTaskConfigOptions(options: Record<string, any>): LmTaskConfig;
7
+ export { parseCommandArgs, parseTaskConfigOptions, };
@@ -0,0 +1,41 @@
1
+ function parseCommandArgs(args) {
2
+ const res = {
3
+ args: new Array(),
4
+ options: {},
5
+ };
6
+ args.pop();
7
+ res.options = args.pop();
8
+ res.args = Array.isArray(args[0]) ? args[0] : args;
9
+ return res;
10
+ }
11
+ function parseTaskConfigOptions(options) {
12
+ const conf = { inferParams: {}, modelname: "", templateName: "" };
13
+ const optionsInferParams = {};
14
+ if (options?.temperature) {
15
+ optionsInferParams.temperature = options.temperature;
16
+ }
17
+ if (options?.top_k !== undefined) {
18
+ optionsInferParams.top_k = options.top_k;
19
+ }
20
+ if (options?.top_p !== undefined) {
21
+ optionsInferParams.top_p = options.top_p;
22
+ }
23
+ if (options?.min_p !== undefined) {
24
+ optionsInferParams.min_p = options.min_p;
25
+ }
26
+ if (options?.max_tokens !== undefined) {
27
+ optionsInferParams.max_tokens = options.max_tokens;
28
+ }
29
+ if (options?.repeat_penalty !== undefined) {
30
+ optionsInferParams.repeat_penalty = options.repeat_penalty;
31
+ }
32
+ if (options?.model !== undefined) {
33
+ conf.modelname = options.model;
34
+ }
35
+ if (options?.template !== undefined) {
36
+ conf.templateName = options.template;
37
+ }
38
+ conf.inferParams = optionsInferParams;
39
+ return conf;
40
+ }
41
+ export { parseCommandArgs, parseTaskConfigOptions, };
@@ -1,3 +1,4 @@
1
1
  import { LmTaskOutput } from "@agent-smith/lmtask";
2
- declare function executeTaskCmd(args?: Array<string> | Record<string, any>, options?: Record<string, any>): Promise<LmTaskOutput>;
3
- export { executeTaskCmd };
2
+ declare function executeTask(name: string, payload: Record<string, any>, options: Record<string, any>, quiet?: boolean): Promise<LmTaskOutput>;
3
+ declare function executeTaskCmd(name: string, targs?: Array<any>): Promise<LmTaskOutput>;
4
+ export { executeTask, executeTaskCmd };
@@ -1,55 +1,46 @@
1
1
  import { compile, serializeGrammar } from "@intrinsicai/gbnfgen";
2
+ import color from "ansi-colors";
2
3
  import ora from 'ora';
3
4
  import { brain, initAgent, taskBuilder } from "../../../agent.js";
5
+ import { readClipboard } from "../../../cmd/sys/clipboard.js";
4
6
  import { readTool } from "../../../db/read.js";
5
- import { isChatMode, isDebug, isQuiet, isShowTokens, isVerbose } from "../../../state/state.js";
6
- import { parseArgs } from "../../../utils/args.js";
7
- import { executeActionCmd, } from "../actions/cmd.js";
8
- import { formatStats, parseInputOptions } from "../utils.js";
9
- import { executeWorkflowCmd } from "../workflows/cmd.js";
10
- import { configureTaskModel, mergeConfOptions, mergeInferParams } from "./conf.js";
7
+ import { usePerfTimer } from "../../../main.js";
8
+ import { isChatMode } from "../../../state/state.js";
9
+ import { executeAction } from "../actions/cmd.js";
10
+ import { parseCommandArgs, parseTaskConfigOptions } from "../options_parsers.js";
11
+ import { runtimeDataError } from "../user_msgs.js";
12
+ import { formatStats, readPromptFile } from "../utils.js";
13
+ import { executeWorkflow } from "../workflows/cmd.js";
14
+ import { configureTaskModel, mergeInferParams } from "./conf.js";
11
15
  import { openTaskSpec } from "./utils.js";
12
- async function executeTaskCmd(args = [], options = {}) {
16
+ async function executeTask(name, payload, options, quiet = false) {
13
17
  await initAgent();
14
- if (isDebug.value) {
15
- console.log("Task args:", args);
18
+ if (options.debug) {
19
+ console.log("Payload:", payload);
16
20
  console.log("Task options:", options);
17
21
  }
18
- const isWorkflow = !Array.isArray(args);
19
- let name;
20
- let pr;
21
- if (!isWorkflow) {
22
- name = args.shift();
23
- const _pr = await parseInputOptions(options);
24
- if (!_pr) {
25
- const p = args.shift();
26
- if (p) {
27
- pr = p;
28
- }
29
- else {
30
- throw new Error("Please provide a prompt");
31
- }
32
- }
33
- else {
34
- pr = _pr;
35
- }
36
- }
37
- else {
38
- if (!(args?.name)) {
39
- throw new Error("Provide a task name param");
40
- }
41
- if (!(args?.prompt)) {
42
- throw new Error("Provide a task prompt param");
43
- }
44
- name = args.name;
45
- pr = args.prompt;
46
- }
47
22
  const taskFileSpec = openTaskSpec(name);
48
- let { conf, vars } = parseArgs(args, true);
49
- conf = mergeConfOptions(conf, options);
23
+ const conf = parseTaskConfigOptions(options);
24
+ if (options.debug) {
25
+ console.log("conf:", conf);
26
+ }
50
27
  conf.inferParams = mergeInferParams(conf.inferParams, taskFileSpec.inferParams ?? {});
51
28
  const model = configureTaskModel(conf, taskFileSpec);
29
+ if (options?.ctx) {
30
+ model.ctx = options.ctx;
31
+ }
52
32
  const taskSpec = taskFileSpec;
33
+ let vars = {};
34
+ taskSpec.variables?.optional?.forEach(k => {
35
+ if (k in options) {
36
+ vars[k] = options[k];
37
+ }
38
+ });
39
+ taskSpec.variables?.required?.forEach(k => {
40
+ if (k in options) {
41
+ vars[k] = options[k];
42
+ }
43
+ });
53
44
  if (taskSpec.toolsList) {
54
45
  taskSpec.tools = [];
55
46
  for (const toolName of taskSpec.toolsList) {
@@ -59,21 +50,17 @@ async function executeTaskCmd(args = [], options = {}) {
59
50
  }
60
51
  const lmTool = {
61
52
  ...tool,
62
- execute: async (args) => {
63
- const normalizedArgs = Array.isArray(args) ? [toolName, ...args] : {
64
- name: toolName,
65
- ...args,
66
- };
53
+ execute: async (params) => {
67
54
  switch (type) {
68
55
  case "action":
69
- const res = await executeActionCmd(normalizedArgs, conf, true);
56
+ const res = await executeAction(toolName, params, options, true);
70
57
  return res;
71
58
  case "task":
72
- conf.quiet = !isDebug.value;
73
- const tres = await executeTaskCmd(normalizedArgs, conf);
59
+ conf.quiet = !options?.debug;
60
+ const tres = await executeTask(name, params, options, true);
74
61
  return tres.answer.text;
75
62
  case "workflow":
76
- const wres = await executeWorkflowCmd(toolName, normalizedArgs, conf);
63
+ const wres = await executeWorkflow(toolName, params, options);
77
64
  return wres;
78
65
  default:
79
66
  throw new Error(`unknown tool execution function type: ${type} for ${toolName}`);
@@ -90,9 +77,8 @@ async function executeTaskCmd(args = [], options = {}) {
90
77
  model.inferParams.grammar = serializeGrammar(await compile(model.inferParams.tsGrammar, "Grammar"));
91
78
  delete model.inferParams.tsGrammar;
92
79
  }
93
- if (isDebug.value) {
80
+ if (options.debug) {
94
81
  console.log("Task model:", model);
95
- console.log("Task vars:", vars);
96
82
  }
97
83
  const ex = brain.getOrCreateExpertForModel(model.name, model.template);
98
84
  if (!ex) {
@@ -104,7 +90,7 @@ async function executeTaskCmd(args = [], options = {}) {
104
90
  const hasThink = ex.template?.tags?.think;
105
91
  const hasTools = ex.template?.tags?.toolCall;
106
92
  const printToken = (t) => {
107
- if (isShowTokens.value) {
93
+ if (options?.tokens === true) {
108
94
  let txt = t;
109
95
  txt = c ? t : `\x1b[100m${t}\x1b[0m`;
110
96
  process.stdout.write(txt);
@@ -116,12 +102,24 @@ async function executeTaskCmd(args = [], options = {}) {
116
102
  }
117
103
  };
118
104
  let processToken = printToken;
119
- if ((hasThink || hasTools) && !isDebug.value) {
105
+ if ((hasThink || hasTools) && !options?.debug) {
120
106
  let continueWrite = true;
121
107
  let skipNextEmptyLinesToken = false;
122
108
  const spinner = ora("Thinking ...");
109
+ const ts = "Thinking";
110
+ const te = color.dim("tokens");
111
+ const formatTokenCount = (i) => {
112
+ return `${ts} ${color.bold(i.toString())} ${te}`;
113
+ };
114
+ const perfTimer = usePerfTimer(false);
115
+ let i = 0;
123
116
  processToken = (t) => {
124
- if (isQuiet.value) {
117
+ if (i == 0) {
118
+ perfTimer.start();
119
+ }
120
+ ++i;
121
+ spinner.text = formatTokenCount(i);
122
+ if (!options?.verbose) {
125
123
  if (hasThink) {
126
124
  if (t == ex.template.tags.think?.start) {
127
125
  spinner.start();
@@ -131,7 +129,9 @@ async function executeTaskCmd(args = [], options = {}) {
131
129
  else if (t == ex.template.tags.think?.end) {
132
130
  continueWrite = true;
133
131
  skipNextEmptyLinesToken = true;
134
- spinner.stop();
132
+ let msg = color.dim("Thinking:") + ` ${i} ${color.dim("tokens")}`;
133
+ msg = msg + " " + color.dim(perfTimer.time());
134
+ spinner.info(msg);
135
135
  return;
136
136
  }
137
137
  }
@@ -142,7 +142,7 @@ async function executeTaskCmd(args = [], options = {}) {
142
142
  return;
143
143
  }
144
144
  else if (t == ex.template.tags.toolCall?.end) {
145
- if (isVerbose.value) {
145
+ if (options?.verbose === true) {
146
146
  skipNextEmptyLinesToken = true;
147
147
  continueWrite = true;
148
148
  }
@@ -162,7 +162,7 @@ async function executeTaskCmd(args = [], options = {}) {
162
162
  };
163
163
  }
164
164
  const onToolCall = (tc) => {
165
- console.log("⚒️ ", `Executing [${name}]`, tc.name, tc.arguments);
165
+ console.log("⚒️ ", color.bold(name), "=>", `${color.yellowBright(tc.name)}`, tc.arguments);
166
166
  };
167
167
  if (options?.onToken) {
168
168
  ex.backend.setOnToken(options.onToken);
@@ -173,14 +173,14 @@ async function executeTaskCmd(args = [], options = {}) {
173
173
  const tconf = {
174
174
  expert: ex,
175
175
  model: model,
176
- debug: isDebug.value,
176
+ debug: options.debug,
177
177
  onToolCall: onToolCall,
178
178
  ...conf,
179
179
  };
180
180
  tconf.expert = ex;
181
181
  let out;
182
182
  try {
183
- out = await task.run({ prompt: pr, ...vars }, tconf);
183
+ out = await task.run({ prompt: payload.prompt, ...vars }, tconf);
184
184
  if (!out.answer.text.endsWith("\n")) {
185
185
  console.log();
186
186
  }
@@ -192,11 +192,32 @@ async function executeTaskCmd(args = [], options = {}) {
192
192
  if (brain.ex.name != ex.name) {
193
193
  brain.setDefaultExpert(ex);
194
194
  }
195
- brain.ex.template.pushToHistory({ user: pr, assistant: out.answer.text });
195
+ brain.ex.template.pushToHistory({ user: payload.prompt, assistant: out.answer.text });
196
196
  }
197
- if (isDebug.value || isVerbose.value) {
197
+ if (options?.debug === true || options?.verbose === true) {
198
198
  console.log("\n", formatStats(out.answer.stats));
199
199
  }
200
200
  return out;
201
201
  }
202
- export { executeTaskCmd };
202
+ async function executeTaskCmd(name, targs = []) {
203
+ const { args, options } = parseCommandArgs(targs);
204
+ let pr;
205
+ if (options?.clipboardInput === true) {
206
+ pr = await readClipboard();
207
+ }
208
+ else if (options?.inputFile === true) {
209
+ pr = readPromptFile();
210
+ }
211
+ else {
212
+ if (args[0] !== undefined) {
213
+ pr = args[0];
214
+ }
215
+ else {
216
+ runtimeDataError("task", name, "provide a prompt or use input options");
217
+ throw new Error();
218
+ }
219
+ }
220
+ const params = { args: args, prompt: pr };
221
+ return await executeTask(name, params, options);
222
+ }
223
+ export { executeTask, executeTaskCmd };
@@ -1,6 +1,13 @@
1
1
  import { FeatureExtension } from '../../interfaces.js';
2
+ declare function extractTaskToolDocAndVariables(name: string, ext: FeatureExtension, dirPath: string): {
3
+ toolDoc: string;
4
+ variables: {
5
+ required: Array<string>;
6
+ optional: Array<string>;
7
+ };
8
+ };
2
9
  declare function extractToolDoc(name: string, ext: FeatureExtension, dirPath: string): {
3
10
  found: boolean;
4
11
  toolDoc: string;
5
12
  };
6
- export { extractToolDoc, };
13
+ export { extractToolDoc, extractTaskToolDocAndVariables, };
@@ -58,6 +58,36 @@ function _parseToolDoc(rawTxt, name) {
58
58
  throw new Error(`Error parsing tool ${name}: data:\n${rawTxt}\n`);
59
59
  }
60
60
  }
61
+ function _parseTaskVariables(data) {
62
+ const res = { required: new Array(), optional: new Array() };
63
+ if (data?.variables) {
64
+ if (data.variables?.required) {
65
+ res.required = data.variables.required;
66
+ }
67
+ if (data.variables?.optional) {
68
+ res.optional = data.variables.optional;
69
+ }
70
+ }
71
+ return res;
72
+ }
73
+ function extractTaskToolDocAndVariables(name, ext, dirPath) {
74
+ const fp = dirPath + "/" + name + "." + ext;
75
+ const { data, found } = readYmlFile(fp);
76
+ const res = { variables: { required: new Array(), optional: new Array() }, toolDoc: "" };
77
+ let tspec;
78
+ if (!found) {
79
+ throw new Error(`extractTaskToolDocAndVariables: file ${fp} not found`);
80
+ }
81
+ if (data.tool) {
82
+ data.tool.name = name;
83
+ tspec = data.tool;
84
+ res.toolDoc = JSON.stringify(tspec, null, " ");
85
+ }
86
+ const { required, optional } = _parseTaskVariables(data);
87
+ res.variables.required = required;
88
+ res.variables.optional = optional;
89
+ return res;
90
+ }
61
91
  function extractToolDoc(name, ext, dirPath) {
62
92
  let spec;
63
93
  let found = false;
@@ -97,4 +127,4 @@ function extractToolDoc(name, ext, dirPath) {
97
127
  }
98
128
  return { found: true, toolDoc: spec };
99
129
  }
100
- export { extractToolDoc, };
130
+ export { extractToolDoc, extractTaskToolDocAndVariables, };
@@ -1,7 +1,6 @@
1
1
  import { InferenceStats } from "@locallm/types";
2
- declare function setOptions(args: Array<string> | undefined, options: Record<string, any>): Promise<Array<string>>;
3
2
  declare function readPromptFile(): string;
4
3
  declare function processOutput(res: any): Promise<void>;
5
4
  declare function parseInputOptions(options: any): Promise<string | null>;
6
5
  declare function formatStats(stats: InferenceStats): string;
7
- export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
6
+ export { formatStats, parseInputOptions, processOutput, readPromptFile, };
@@ -1,30 +1,8 @@
1
1
  import { marked } from "../../agent.js";
2
2
  import { formatMode, initFilepaths, inputMode, outputMode, promptfilePath } from "../../state/state.js";
3
- import { modes } from "../clicmds/modes.js";
4
3
  import { readClipboard, writeToClipboard } from "../sys/clipboard.js";
5
4
  import { readFile } from "../sys/read.js";
6
5
  import { splitThinking } from "../../utils/text.js";
7
- async function setOptions(args = [], options) {
8
- for (const k of Object.keys(options)) {
9
- let opt;
10
- if (k.length == 1) {
11
- opt = modes["-" + k.toLowerCase()];
12
- }
13
- else {
14
- opt = modes["--" + k.toLowerCase()];
15
- }
16
- await opt.cmd([], undefined);
17
- }
18
- if (inputMode.value == "promptfile") {
19
- const p = readPromptFile();
20
- args.push(p);
21
- }
22
- else if (inputMode.value == "clipboard") {
23
- const p = await readClipboard();
24
- args.push(p);
25
- }
26
- return args;
27
- }
28
6
  function readPromptFile() {
29
7
  initFilepaths();
30
8
  return readFile(promptfilePath.value);
@@ -78,4 +56,4 @@ function formatStats(stats) {
78
56
  buf.push(`${stats.inferenceTimeSeconds}s inference)`);
79
57
  return buf.join(" ");
80
58
  }
81
- export { formatStats, parseInputOptions, processOutput, readPromptFile, setOptions };
59
+ export { formatStats, parseInputOptions, processOutput, readPromptFile, };
@@ -1,2 +1,3 @@
1
- declare function executeWorkflowCmd(name: string, args?: Array<any> | Record<string, any>, options?: any): Promise<any>;
2
- export { executeWorkflowCmd, };
1
+ declare function executeWorkflow(name: string, params: Record<string, any>, options: Record<string, any>): Promise<any>;
2
+ declare function executeWorkflowCmd(name: string, wargs: Array<any>): Promise<any>;
3
+ export { executeWorkflow, executeWorkflowCmd, };